using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Learun.Application.AppMagager; using Learun.Application.Base.SystemModule; using Learun.Application.Excel; using Learun.Application.TwoDevelopment.EducationalAdministration; using Learun.Application.TwoDevelopment.LR_Desktop; using Learun.Application.WorkFlow; using Learun.DataBase; using Learun.DataBase.Repository; using Learun.Util; namespace Quanjiang.DigitalScholl.DataSync { public class MainService : RepositoryFactory { public async Task<(bool result, string errormessage)> CheckConnection(string connstring) { (bool result, string errormessage) objValueTuple = (false, ""); try { var db = BaseRepository(connstring, DatabaseType.SqlServer); db.getDbConnection().Open(); objValueTuple.result = true; } catch (Exception e) { objValueTuple.result = false; objValueTuple.errormessage = e.Message; } return objValueTuple; } public string BeginSync(List list) { StringBuilder str = new StringBuilder(); var stuList = this.BaseRepository("target").FindList().ToList(); foreach (var fileInfo in list) { foreach (var stuenroll in stuList) { if (fileInfo.Name.Contains(stuenroll.IDCard) && fileInfo.Name.Contains(stuenroll.StuName)) { stuenroll.Photo = Guid.NewGuid().ToString(); string filepath = $"D:/智慧校园系统/Publish20191031/Resource/System/{DateTime.Now.ToString("yyyyMMdd")}/{stuenroll.Photo}.jpg"; FileInfo fi = new FileInfo(fileInfo.FullName); //xx/xx/aa.rar fi.MoveTo(filepath); AnnexesFileEntity entity = new AnnexesFileEntity { F_Id = stuenroll.Photo, F_FolderId = stuenroll.Photo, F_FileName = stuenroll.Photo + ".jpg", F_FilePath = filepath, F_FileExtensions = ".jpg", F_FileType = "jpg", }; entity.Create(); this.BaseRepository("source").Insert(entity); this.BaseRepository("target").Update(stuenroll); } } } return str.ToString(); } public string BeginSyncXiChang(List list) { StringBuilder str = new StringBuilder(); var stuList = this.BaseRepository("target").FindList().ToList(); foreach (var fileInfo in list) { foreach (var stuenroll in stuList) { if (fileInfo.Name.Substring(0, 14).Equals(stuenroll.ksh)) { stuenroll.Photo = Guid.NewGuid().ToString(); string filepath = $"D:/智慧校园系统/Publish1/Resource/System/{DateTime.Now.ToString("yyyyMMdd")}/{stuenroll.Photo}.jpg"; FileInfo fi = new FileInfo(fileInfo.FullName); //xx/xx/aa.rar fi.MoveTo(filepath); AnnexesFileEntity entity = new AnnexesFileEntity { F_Id = stuenroll.Photo, F_FolderId = stuenroll.Photo, F_FileName = stuenroll.Photo + ".jpg", F_FilePath = filepath, F_FileExtensions = ".jpg", F_FileType = "jpg", }; entity.Create(); this.BaseRepository("source").Insert(entity); this.BaseRepository("target").Update(stuenroll); } } } return str.ToString(); } public async Task BeginSync(CheckedListBox.CheckedItemCollection ciItemCollection) { var sourcedb = BaseRepository("source").BeginTrans(); var targetdb = BaseRepository("target").BeginTrans(); try { if (ciItemCollection.Contains("数据字典")) { //字典 var sourcedic = sourcedb.FindList(); var targetdic = targetdb.FindList(); foreach (var tItemEntity in sourcedic) { if (!targetdic.Any(m => m.F_ItemId == tItemEntity.F_ItemId)) { targetdb.Insert(tItemEntity); } } //字典项 var sourcedicitem = sourcedb.FindList(); var targetdicitem = targetdb.FindList(); foreach (var tItemEntity in sourcedicitem) { if (!targetdicitem.Any(m => m.F_ItemDetailId == tItemEntity.F_ItemDetailId)) { targetdb.Insert(tItemEntity); } } } if (ciItemCollection.Contains("数据源")) { //数据源 var sourceds = sourcedb.FindList(); var targetds = targetdb.FindList(); foreach (var tItemEntity in sourceds) { if (!targetds.Any(m => m.F_Id == tItemEntity.F_Id)) { targetdb.Insert(tItemEntity); } } } if (ciItemCollection.Contains("菜单")) { //菜单 var sourcemenu = sourcedb.FindList(); var targetmenu = targetdb.FindList(); foreach (var tItemEntity in sourcemenu) { if (!targetmenu.Any(m => m.F_ModuleId == tItemEntity.F_ModuleId)) { targetdb.Insert(tItemEntity); } } //按钮 var sourcebutton = sourcedb.FindList(); var targetbutton = targetdb.FindList(); foreach (var tItemEntity in sourcebutton) { if (!targetbutton.Any(m => m.F_ModuleButtonId == tItemEntity.F_ModuleButtonId)) { targetdb.Insert(tItemEntity); } } //列 var sourcecolumn = sourcedb.FindList(); var targetcolumn = targetdb.FindList(); foreach (var tItemEntity in sourcecolumn) { if (!targetcolumn.Any(m => m.F_ModuleColumnId == tItemEntity.F_ModuleColumnId)) { targetdb.Insert(tItemEntity); } } //form字段 var sourceform = sourcedb.FindList(); var targetform = targetdb.FindList(); foreach (var tItemEntity in sourceform) { if (!targetform.Any(m => m.F_ModuleFormId == tItemEntity.F_ModuleFormId)) { targetdb.Insert(tItemEntity); } } } if (ciItemCollection.Contains("工作流")) { //工作流 var sourceflowinfo = sourcedb.FindList(); var targetflowinfo = targetdb.FindList(); foreach (var tItemEntity in sourceflowinfo) { if (!targetflowinfo.Any(m => m.F_Id == tItemEntity.F_Id)) { targetdb.Insert(tItemEntity); } } var sourceflow = sourcedb.FindList(); var targetflow = targetdb.FindList(); foreach (var tItemEntity in sourceflow) { if (!targetflow.Any(m => m.F_Id == tItemEntity.F_Id)) { targetdb.Insert(tItemEntity); } } var sourceflowauth = sourcedb.FindList(); var targetflowauth = targetdb.FindList(); foreach (var tItemEntity in sourceflowauth) { if (!targetflowauth.Any(m => m.F_Id == tItemEntity.F_Id)) { targetdb.Insert(tItemEntity); } } } if (ciItemCollection.Contains("数据权限")) { //LR_Base_Interface var sourceinter = sourcedb.FindList(); var targetinter = targetdb.FindList(); foreach (var tItemEntity in sourceinter) { if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id)) { targetdb.Insert(tItemEntity); } } } if (ciItemCollection.Contains("app菜单")) { var sourceinter = sourcedb.FindList(); var targetinter = targetdb.FindList(); foreach (var tItemEntity in sourceinter) { if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id)) { targetdb.Insert(tItemEntity); } } } if (ciItemCollection.Contains("桌面主题")) { //主题色块 var sourceinter = sourcedb.FindList(); var targetinter = targetdb.FindList(); foreach (var tItemEntity in sourceinter) { if (!targetinter.Any(m => m.ID == tItemEntity.ID)) { targetdb.Insert(tItemEntity); } } //登陆页配置 var sourceinter2 = sourcedb.FindList(); var targetinter2 = targetdb.FindList(); foreach (var tItemEntity in sourceinter2) { if (!targetinter2.Any(m => m.ID == tItemEntity.ID)) { targetdb.Insert(tItemEntity); } } } if (ciItemCollection.Contains("开关显示控制")) { var sourceinter = sourcedb.FindList(); var targetinter = targetdb.FindList(); foreach (var tItemEntity in sourceinter) { if (!targetinter.Any(m => m.ID == tItemEntity.ID)) { targetdb.Insert(tItemEntity); } } } if (ciItemCollection.Contains("导入导出")) { var sourceinter = sourcedb.FindList(); var targetinter = targetdb.FindList(); foreach (var tItemEntity in sourceinter) { if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id)) { targetdb.Insert(tItemEntity); } } var sourceinter1 = sourcedb.FindList(); var targetinter1 = targetdb.FindList(); foreach (var tItemEntity in sourceinter1) { if (!targetinter1.Any(m => m.F_Id == tItemEntity.F_Id)) { targetdb.Insert(tItemEntity); } var sourceinter2 = sourcedb.FindList(m => m.F_ImportId == tItemEntity.F_Id); var targetinter2 = targetdb.FindList(m => m.F_ImportId == tItemEntity.F_Id); if (targetinter2 != null) { foreach (var sourcEntity in sourceinter2) { if (!targetinter2.Any(m => m.F_Id == sourcEntity.F_Id || m.F_ColName == sourcEntity.F_ColName)) { targetdb.Insert(sourcEntity); } } } } } targetdb.Commit(); return true; } catch (Exception e) { targetdb.Rollback(); MessageBox.Show(e.Message); return false; } } /// ///根据传入的name返回Repository /// /// /// public IRepository GetDataRepository(string name) { return BaseRepository(name); } /// /// 根据传入的dbstring和sql语句返回DataTable /// /// /// /// public DataTable GetDataTableResult(string dbstring, string sql) { try { var db = BaseRepository(dbstring).BeginTrans(); return db.FindTable(sql); } catch (Exception e) { throw e; } } /// /// 根据传入的dbstring和sql执行 /// /// /// /// public int Execute(string dbstring, string sql) { try { var db = BaseRepository(dbstring).BeginTrans(); return db.ExecuteBySql(sql); } catch (Exception e) { throw e; } } } }