Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

388 rader
16 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. using Learun.Application.AppMagager;
  10. using Learun.Application.Base.SystemModule;
  11. using Learun.Application.Excel;
  12. using Learun.Application.TwoDevelopment.EducationalAdministration;
  13. using Learun.Application.TwoDevelopment.LR_Desktop;
  14. using Learun.Application.WorkFlow;
  15. using Learun.DataBase;
  16. using Learun.DataBase.Repository;
  17. using Learun.Util;
  18. namespace Quanjiang.DigitalScholl.DataSync
  19. {
  20. public class MainService : RepositoryFactory
  21. {
  22. public async Task<(bool result, string errormessage)> CheckConnection(string connstring)
  23. {
  24. (bool result, string errormessage) objValueTuple = (false, "");
  25. try
  26. {
  27. var db = BaseRepository(connstring, DatabaseType.SqlServer);
  28. db.getDbConnection().Open();
  29. objValueTuple.result = true;
  30. }
  31. catch (Exception e)
  32. {
  33. objValueTuple.result = false;
  34. objValueTuple.errormessage = e.Message;
  35. }
  36. return objValueTuple;
  37. }
  38. public string BeginSync(List<FileInfo> list)
  39. {
  40. StringBuilder str = new StringBuilder();
  41. var stuList = this.BaseRepository("target").FindList<StuEnrollEntity>().ToList();
  42. foreach (var fileInfo in list)
  43. {
  44. foreach (var stuenroll in stuList)
  45. {
  46. if (fileInfo.Name.Contains(stuenroll.IDCard) && fileInfo.Name.Contains(stuenroll.StuName))
  47. {
  48. stuenroll.Photo = Guid.NewGuid().ToString();
  49. string filepath = $"D:/智慧校园系统/Publish20191031/Resource/System/{DateTime.Now.ToString("yyyyMMdd")}/{stuenroll.Photo}.jpg";
  50. FileInfo fi = new FileInfo(fileInfo.FullName); //xx/xx/aa.rar
  51. fi.MoveTo(filepath);
  52. AnnexesFileEntity entity = new AnnexesFileEntity
  53. {
  54. F_Id = stuenroll.Photo,
  55. F_FolderId = stuenroll.Photo,
  56. F_FileName = stuenroll.Photo + ".jpg",
  57. F_FilePath = filepath,
  58. F_FileExtensions = ".jpg",
  59. F_FileType = "jpg",
  60. };
  61. entity.Create();
  62. this.BaseRepository("source").Insert(entity);
  63. this.BaseRepository("target").Update(stuenroll);
  64. }
  65. }
  66. }
  67. return str.ToString();
  68. }
  69. public string BeginSyncXiChang(List<FileInfo> list)
  70. {
  71. StringBuilder str = new StringBuilder();
  72. var stuList = this.BaseRepository("target").FindList<StuInfoFreshEntity>().ToList();
  73. foreach (var fileInfo in list)
  74. {
  75. foreach (var stuenroll in stuList)
  76. {
  77. if (fileInfo.Name.Substring(0, 14).Equals(stuenroll.ksh))
  78. {
  79. stuenroll.Photo = Guid.NewGuid().ToString();
  80. string filepath = $"D:/智慧校园系统/Publish1/Resource/System/{DateTime.Now.ToString("yyyyMMdd")}/{stuenroll.Photo}.jpg";
  81. FileInfo fi = new FileInfo(fileInfo.FullName); //xx/xx/aa.rar
  82. fi.MoveTo(filepath);
  83. AnnexesFileEntity entity = new AnnexesFileEntity
  84. {
  85. F_Id = stuenroll.Photo,
  86. F_FolderId = stuenroll.Photo,
  87. F_FileName = stuenroll.Photo + ".jpg",
  88. F_FilePath = filepath,
  89. F_FileExtensions = ".jpg",
  90. F_FileType = "jpg",
  91. };
  92. entity.Create();
  93. this.BaseRepository("source").Insert(entity);
  94. this.BaseRepository("target").Update(stuenroll);
  95. }
  96. }
  97. }
  98. return str.ToString();
  99. }
  100. public async Task<bool> BeginSync(CheckedListBox.CheckedItemCollection ciItemCollection)
  101. {
  102. var sourcedb = BaseRepository("source").BeginTrans();
  103. var targetdb = BaseRepository("target").BeginTrans();
  104. try
  105. {
  106. if (ciItemCollection.Contains("数据字典"))
  107. {
  108. //字典
  109. var sourcedic = sourcedb.FindList<DataItemEntity>();
  110. var targetdic = targetdb.FindList<DataItemEntity>();
  111. foreach (var tItemEntity in sourcedic)
  112. {
  113. if (!targetdic.Any(m => m.F_ItemId == tItemEntity.F_ItemId))
  114. {
  115. targetdb.Insert<DataItemEntity>(tItemEntity);
  116. }
  117. }
  118. //字典项
  119. var sourcedicitem = sourcedb.FindList<DataItemDetailEntity>();
  120. var targetdicitem = targetdb.FindList<DataItemDetailEntity>();
  121. foreach (var tItemEntity in sourcedicitem)
  122. {
  123. if (!targetdicitem.Any(m => m.F_ItemDetailId == tItemEntity.F_ItemDetailId))
  124. {
  125. targetdb.Insert<DataItemDetailEntity>(tItemEntity);
  126. }
  127. }
  128. }
  129. if (ciItemCollection.Contains("数据源"))
  130. {
  131. //数据源
  132. var sourceds = sourcedb.FindList<DataSourceEntity>();
  133. var targetds = targetdb.FindList<DataSourceEntity>();
  134. foreach (var tItemEntity in sourceds)
  135. {
  136. if (!targetds.Any(m => m.F_Id == tItemEntity.F_Id))
  137. {
  138. targetdb.Insert<DataSourceEntity>(tItemEntity);
  139. }
  140. }
  141. }
  142. if (ciItemCollection.Contains("菜单"))
  143. {
  144. //菜单
  145. var sourcemenu = sourcedb.FindList<ModuleEntity>();
  146. var targetmenu = targetdb.FindList<ModuleEntity>();
  147. foreach (var tItemEntity in sourcemenu)
  148. {
  149. if (!targetmenu.Any(m => m.F_ModuleId == tItemEntity.F_ModuleId))
  150. {
  151. targetdb.Insert<ModuleEntity>(tItemEntity);
  152. }
  153. }
  154. //按钮
  155. var sourcebutton = sourcedb.FindList<ModuleButtonEntity>();
  156. var targetbutton = targetdb.FindList<ModuleButtonEntity>();
  157. foreach (var tItemEntity in sourcebutton)
  158. {
  159. if (!targetbutton.Any(m => m.F_ModuleButtonId == tItemEntity.F_ModuleButtonId))
  160. {
  161. targetdb.Insert<ModuleButtonEntity>(tItemEntity);
  162. }
  163. }
  164. //列
  165. var sourcecolumn = sourcedb.FindList<ModuleColumnEntity>();
  166. var targetcolumn = targetdb.FindList<ModuleColumnEntity>();
  167. foreach (var tItemEntity in sourcecolumn)
  168. {
  169. if (!targetcolumn.Any(m => m.F_ModuleColumnId == tItemEntity.F_ModuleColumnId))
  170. {
  171. targetdb.Insert<ModuleColumnEntity>(tItemEntity);
  172. }
  173. }
  174. //form字段
  175. var sourceform = sourcedb.FindList<ModuleFormEntity>();
  176. var targetform = targetdb.FindList<ModuleFormEntity>();
  177. foreach (var tItemEntity in sourceform)
  178. {
  179. if (!targetform.Any(m => m.F_ModuleFormId == tItemEntity.F_ModuleFormId))
  180. {
  181. targetdb.Insert<ModuleFormEntity>(tItemEntity);
  182. }
  183. }
  184. }
  185. if (ciItemCollection.Contains("工作流"))
  186. {
  187. //工作流
  188. var sourceflowinfo = sourcedb.FindList<NWFSchemeInfoEntity>();
  189. var targetflowinfo = targetdb.FindList<NWFSchemeInfoEntity>();
  190. foreach (var tItemEntity in sourceflowinfo)
  191. {
  192. if (!targetflowinfo.Any(m => m.F_Id == tItemEntity.F_Id))
  193. {
  194. targetdb.Insert<NWFSchemeInfoEntity>(tItemEntity);
  195. }
  196. }
  197. var sourceflow = sourcedb.FindList<NWFSchemeEntity>();
  198. var targetflow = targetdb.FindList<NWFSchemeEntity>();
  199. foreach (var tItemEntity in sourceflow)
  200. {
  201. if (!targetflow.Any(m => m.F_Id == tItemEntity.F_Id))
  202. {
  203. targetdb.Insert<NWFSchemeEntity>(tItemEntity);
  204. }
  205. }
  206. var sourceflowauth = sourcedb.FindList<NWFSchemeAuthEntity>();
  207. var targetflowauth = targetdb.FindList<NWFSchemeAuthEntity>();
  208. foreach (var tItemEntity in sourceflowauth)
  209. {
  210. if (!targetflowauth.Any(m => m.F_Id == tItemEntity.F_Id))
  211. {
  212. targetdb.Insert<NWFSchemeAuthEntity>(tItemEntity);
  213. }
  214. }
  215. }
  216. if (ciItemCollection.Contains("数据权限"))
  217. {
  218. //LR_Base_Interface
  219. var sourceinter = sourcedb.FindList<InterfaceEntity>();
  220. var targetinter = targetdb.FindList<InterfaceEntity>();
  221. foreach (var tItemEntity in sourceinter)
  222. {
  223. if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id))
  224. {
  225. targetdb.Insert<InterfaceEntity>(tItemEntity);
  226. }
  227. }
  228. }
  229. if (ciItemCollection.Contains("app菜单"))
  230. {
  231. var sourceinter = sourcedb.FindList<FunctionEntity>();
  232. var targetinter = targetdb.FindList<FunctionEntity>();
  233. foreach (var tItemEntity in sourceinter)
  234. {
  235. if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id))
  236. {
  237. targetdb.Insert<FunctionEntity>(tItemEntity);
  238. }
  239. }
  240. }
  241. if (ciItemCollection.Contains("桌面主题"))
  242. {
  243. //主题色块
  244. var sourceinter = sourcedb.FindList<LR_Base_ThematicManagementEntity>();
  245. var targetinter = targetdb.FindList<LR_Base_ThematicManagementEntity>();
  246. foreach (var tItemEntity in sourceinter)
  247. {
  248. if (!targetinter.Any(m => m.ID == tItemEntity.ID))
  249. {
  250. targetdb.Insert<LR_Base_ThematicManagementEntity>(tItemEntity);
  251. }
  252. }
  253. //登陆页配置
  254. var sourceinter2 = sourcedb.FindList<LoginModelEntity>();
  255. var targetinter2 = targetdb.FindList<LoginModelEntity>();
  256. foreach (var tItemEntity in sourceinter2)
  257. {
  258. if (!targetinter2.Any(m => m.ID == tItemEntity.ID))
  259. {
  260. targetdb.Insert<LoginModelEntity>(tItemEntity);
  261. }
  262. }
  263. }
  264. if (ciItemCollection.Contains("开关显示控制"))
  265. {
  266. var sourceinter = sourcedb.FindList<TeachSwitchEntity>();
  267. var targetinter = targetdb.FindList<TeachSwitchEntity>();
  268. foreach (var tItemEntity in sourceinter)
  269. {
  270. if (!targetinter.Any(m => m.ID == tItemEntity.ID))
  271. {
  272. targetdb.Insert<TeachSwitchEntity>(tItemEntity);
  273. }
  274. }
  275. }
  276. if (ciItemCollection.Contains("导入导出"))
  277. {
  278. var sourceinter = sourcedb.FindList<ExcelExportEntity>();
  279. var targetinter = targetdb.FindList<ExcelExportEntity>();
  280. foreach (var tItemEntity in sourceinter)
  281. {
  282. if (!targetinter.Any(m => m.F_Id == tItemEntity.F_Id))
  283. {
  284. targetdb.Insert<ExcelExportEntity>(tItemEntity);
  285. }
  286. }
  287. var sourceinter1 = sourcedb.FindList<ExcelImportEntity>();
  288. var targetinter1 = targetdb.FindList<ExcelImportEntity>();
  289. foreach (var tItemEntity in sourceinter1)
  290. {
  291. if (!targetinter1.Any(m => m.F_Id == tItemEntity.F_Id))
  292. {
  293. targetdb.Insert<ExcelImportEntity>(tItemEntity);
  294. }
  295. var sourceinter2 = sourcedb.FindList<ExcelImportFieldEntity>(m => m.F_ImportId == tItemEntity.F_Id);
  296. var targetinter2 = targetdb.FindList<ExcelImportFieldEntity>(m => m.F_ImportId == tItemEntity.F_Id);
  297. if (targetinter2 != null)
  298. {
  299. foreach (var sourcEntity in sourceinter2)
  300. {
  301. if (!targetinter2.Any(m => m.F_Id == sourcEntity.F_Id || m.F_ColName == sourcEntity.F_ColName))
  302. {
  303. targetdb.Insert<ExcelImportFieldEntity>(sourcEntity);
  304. }
  305. }
  306. }
  307. }
  308. }
  309. targetdb.Commit();
  310. return true;
  311. }
  312. catch (Exception e)
  313. {
  314. targetdb.Rollback();
  315. MessageBox.Show(e.Message);
  316. return false;
  317. }
  318. }
  319. /// <summary>
  320. ///根据传入的name返回Repository
  321. /// </summary>
  322. /// <param name="name"></param>
  323. /// <returns></returns>
  324. public IRepository GetDataRepository(string name)
  325. {
  326. return BaseRepository(name);
  327. }
  328. /// <summary>
  329. /// 根据传入的dbstring和sql语句返回DataTable
  330. /// </summary>
  331. /// <param name="dbstring"></param>
  332. /// <param name="sql"></param>
  333. /// <returns></returns>
  334. public DataTable GetDataTableResult(string dbstring, string sql)
  335. {
  336. try
  337. {
  338. var db = BaseRepository(dbstring).BeginTrans();
  339. return db.FindTable(sql);
  340. }
  341. catch (Exception e)
  342. {
  343. throw e;
  344. }
  345. }
  346. /// <summary>
  347. /// 根据传入的dbstring和sql执行
  348. /// </summary>
  349. /// <param name="dbstring"></param>
  350. /// <param name="sql"></param>
  351. /// <returns></returns>
  352. public int Execute(string dbstring, string sql)
  353. {
  354. try
  355. {
  356. var db = BaseRepository(dbstring).BeginTrans();
  357. return db.ExecuteBySql(sql);
  358. }
  359. catch (Exception e)
  360. {
  361. throw e;
  362. }
  363. }
  364. }
  365. }