|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- 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<FileInfo> list)
- {
-
- StringBuilder str = new StringBuilder();
- var stuList = this.BaseRepository("target").FindList<StuEnrollEntity>().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<FileInfo> list)
- {
-
- StringBuilder str = new StringBuilder();
- var stuList = this.BaseRepository("target").FindList<StuInfoFreshEntity>().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<bool> BeginSync(CheckedListBox.CheckedItemCollection ciItemCollection)
- {
- var sourcedb = BaseRepository("source").BeginTrans();
- var targetdb = BaseRepository("target").BeginTrans();
- try
- {
- if (ciItemCollection.Contains("数据字典"))
- {
- //字典
- var sourcedic = sourcedb.FindList<DataItemEntity>();
- var targetdic = targetdb.FindList<DataItemEntity>();
- foreach (var tItemEntity in sourcedic)
- {
- if (!targetdic.Any(m => m.F_ItemId == tItemEntity.F_ItemId))
- {
- targetdb.Insert<DataItemEntity>(tItemEntity);
- }
- }
- //字典项
- var sourcedicitem = sourcedb.FindList<DataItemDetailEntity>();
- var targetdicitem = targetdb.FindList<DataItemDetailEntity>();
- foreach (var tItemEntity in sourcedicitem)
- {
- if (!targetdicitem.Any(m => m.F_ItemDetailId == tItemEntity.F_ItemDetailId))
- {
- targetdb.Insert<DataItemDetailEntity>(tItemEntity);
- }
- }
- }
- if (ciItemCollection.Contains("数据源"))
- {
- //数据源
- var sourceds = sourcedb.FindList<DataSourceEntity>();
- var targetds = targetdb.FindList<DataSourceEntity>();
- foreach (var tItemEntity in sourceds)
- {
- if (!targetds.Any(m => m.F_Id == tItemEntity.F_Id))
- {
- targetdb.Insert<DataSourceEntity>(tItemEntity);
- }
- }
- }
- if (ciItemCollection.Contains("菜单"))
- {
- //菜单
- var sourcemenu = sourcedb.FindList<ModuleEntity>();
- var targetmenu = targetdb.FindList<ModuleEntity>();
- foreach (var tItemEntity in sourcemenu)
- {
- if (!targetmenu.Any(m => m.F_ModuleId == tItemEntity.F_ModuleId))
- {
- targetdb.Insert<ModuleEntity>(tItemEntity);
- }
- }
- //按钮
- var sourcebutton = sourcedb.FindList<ModuleButtonEntity>();
- var targetbutton = targetdb.FindList<ModuleButtonEntity>();
- foreach (var tItemEntity in sourcebutton)
- {
- if (!targetbutton.Any(m => m.F_ModuleButtonId == tItemEntity.F_ModuleButtonId))
- {
- targetdb.Insert<ModuleButtonEntity>(tItemEntity);
- }
- }
- //列
- var sourcecolumn = sourcedb.FindList<ModuleColumnEntity>();
- var targetcolumn = targetdb.FindList<ModuleColumnEntity>();
- foreach (var tItemEntity in sourcecolumn)
- {
- if (!targetcolumn.Any(m => m.F_ModuleColumnId == tItemEntity.F_ModuleColumnId))
- {
- targetdb.Insert<ModuleColumnEntity>(tItemEntity);
- }
- }
- //form字段
- var sourceform = sourcedb.FindList<ModuleFormEntity>();
- var targetform = targetdb.FindList<ModuleFormEntity>();
- foreach (var tItemEntity in sourceform)
- {
- if (!targetform.Any(m => m.F_ModuleFormId == tItemEntity.F_ModuleFormId))
- {
- targetdb.Insert<ModuleFormEntity>(tItemEntity);
- }
- }
- }
- if (ciItemCollection.Contains("工作流"))
- {
- //工作流
- var sourceflowinfo = sourcedb.FindList<NWFSchemeInfoEntity>();
- var targetflowinfo = targetdb.FindList<NWFSchemeInfoEntity>();
- foreach (var tItemEntity in sourceflowinfo)
- {
- if (!targetflowinfo.Any(m => m.F_Id == tItemEntity.F_Id))
- {
- targetdb.Insert<NWFSchemeInfoEntity>(tItemEntity);
- }
- }
- var sourceflow = sourcedb.FindList<NWFSchemeEntity>();
- var targetflow = targetdb.FindList<NWFSchemeEntity>();
- foreach (var tItemEntity in sourceflow)
- {
- if (!targetflow.Any(m => m.F_Id == tItemEntity.F_Id))
- {
- targetdb.Insert<NWFSchemeEntity>(tItemEntity);
- }
- }
- var sourceflowauth = sourcedb.FindList<NWFSchemeAuthEntity>();
- var targetflowauth = targetdb.FindList<NWFSchemeAuthEntity>();
- foreach (var tItemEntity in sourceflowauth)
- {
- if (!targetflowauth.Any(m => m.F_Id == tItemEntity.F_Id))
- {
- targetdb.Insert<NWFSchemeAuthEntity>(tItemEntity);
- }
- }
- }
- if (ciItemCollection.Contains("数据权限"))
- {
- //LR_Base_Interface
- var sourceinter = sourcedb.FindList<InterfaceEntity>();
- var targetinter = targetdb.FindList<InterfaceEntity>();
- foreach (var tItemEntity in sourceinter)
- {
- if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id))
- {
- targetdb.Insert<InterfaceEntity>(tItemEntity);
- }
- }
- }
- if (ciItemCollection.Contains("app菜单"))
- {
- var sourceinter = sourcedb.FindList<FunctionEntity>();
- var targetinter = targetdb.FindList<FunctionEntity>();
- foreach (var tItemEntity in sourceinter)
- {
- if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id))
- {
- targetdb.Insert<FunctionEntity>(tItemEntity);
- }
- }
- }
- if (ciItemCollection.Contains("桌面主题"))
- {
- //主题色块
- var sourceinter = sourcedb.FindList<LR_Base_ThematicManagementEntity>();
- var targetinter = targetdb.FindList<LR_Base_ThematicManagementEntity>();
- foreach (var tItemEntity in sourceinter)
- {
- if (!targetinter.Any(m => m.ID == tItemEntity.ID))
- {
- targetdb.Insert<LR_Base_ThematicManagementEntity>(tItemEntity);
- }
- }
- //登陆页配置
- var sourceinter2 = sourcedb.FindList<LoginModelEntity>();
- var targetinter2 = targetdb.FindList<LoginModelEntity>();
- foreach (var tItemEntity in sourceinter2)
- {
- if (!targetinter2.Any(m => m.ID == tItemEntity.ID))
- {
- targetdb.Insert<LoginModelEntity>(tItemEntity);
- }
- }
- }
- if (ciItemCollection.Contains("开关显示控制"))
- {
- var sourceinter = sourcedb.FindList<TeachSwitchEntity>();
- var targetinter = targetdb.FindList<TeachSwitchEntity>();
- foreach (var tItemEntity in sourceinter)
- {
- if (!targetinter.Any(m => m.ID == tItemEntity.ID))
- {
- targetdb.Insert<TeachSwitchEntity>(tItemEntity);
- }
- }
- }
- if (ciItemCollection.Contains("导入导出"))
- {
- var sourceinter = sourcedb.FindList<ExcelExportEntity>();
- var targetinter = targetdb.FindList<ExcelExportEntity>();
- foreach (var tItemEntity in sourceinter)
- {
- if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id))
- {
- targetdb.Insert<ExcelExportEntity>(tItemEntity);
- }
- }
- var sourceinter1 = sourcedb.FindList<ExcelImportEntity>();
- var targetinter1 = targetdb.FindList<ExcelImportEntity>();
- foreach (var tItemEntity in sourceinter1)
- {
- if (!targetinter1.Any(m => m.F_Id == tItemEntity.F_Id))
- {
- targetdb.Insert<ExcelImportEntity>(tItemEntity);
- }
- var sourceinter2 = sourcedb.FindList<ExcelImportFieldEntity>(m => m.F_ImportId == tItemEntity.F_Id);
- var targetinter2 = targetdb.FindList<ExcelImportFieldEntity>(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<ExcelImportFieldEntity>(sourcEntity);
- }
- }
- }
- }
- }
- targetdb.Commit();
- return true;
- }
-
- catch (Exception e)
- {
- targetdb.Rollback();
- MessageBox.Show(e.Message);
- return false;
- }
-
- }
-
- /// <summary>
- ///根据传入的name返回Repository
- /// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
- public IRepository GetDataRepository(string name)
- {
- return BaseRepository(name);
- }
-
- /// <summary>
- /// 根据传入的dbstring和sql语句返回DataTable
- /// </summary>
- /// <param name="dbstring"></param>
- /// <param name="sql"></param>
- /// <returns></returns>
- public DataTable GetDataTableResult(string dbstring, string sql)
- {
- try
- {
- var db = BaseRepository(dbstring).BeginTrans();
- return db.FindTable(sql);
- }
- catch (Exception e)
- {
- throw e;
- }
- }
-
- /// <summary>
- /// 根据传入的dbstring和sql执行
- /// </summary>
- /// <param name="dbstring"></param>
- /// <param name="sql"></param>
- /// <returns></returns>
- public int Execute(string dbstring, string sql)
- {
- try
- {
- var db = BaseRepository(dbstring).BeginTrans();
- return db.ExecuteBySql(sql);
- }
- catch (Exception e)
- {
- throw e;
- }
- }
- }
- }
|