BatchModifyServices.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.Entities;
  7. using EMIS.ViewModel;
  8. using EMIS.Utility;
  9. namespace EMIS.CommonLogic.SystemServices
  10. {
  11. class BatchModifyServices : BaseServices, IBatchModifyServices
  12. {
  13. public BatchModifyRepository batchModifyRepository { get; set; }
  14. public BatchModifyEventsRepository batchModifyEventsRepository { get; set; }
  15. public BatchModifyExpandRepository batchModifyExpandRepository { get; set; }
  16. /// <summary>
  17. /// 根据mnuID(页面ID)获取设置信息
  18. /// </summary>
  19. /// <param name="mnuID">页面ID</param>
  20. /// <returns></returns>
  21. public List<Entities.Sys_BatchModify> GetBatchModifyList(string mnuID)
  22. {
  23. //查询条件
  24. System.Linq.Expressions.Expression<Func<Sys_BatchModify, bool>> expression = (x => true);
  25. if (!string.IsNullOrEmpty(mnuID))
  26. expression = (x => x.MNUID == mnuID);
  27. return batchModifyRepository.GetList(expression).OrderBy(x => x.OrderNo).ToList();
  28. }
  29. /// <summary>
  30. /// 获取配置扩展表
  31. /// </summary>
  32. /// <param name="BatchModifyID"></param>
  33. /// <returns></returns>
  34. public List<Sys_BatchModifyExpand> GetBatchModifyExpandList(Guid? BatchModifyID)
  35. {
  36. //查询条件
  37. System.Linq.Expressions.Expression<Func<Sys_BatchModifyExpand, bool>> expression = (x => true);
  38. expression = (x => x.BatchModifyID == BatchModifyID);
  39. return batchModifyExpandRepository.GetList(expression).ToList();
  40. }
  41. /// <summary>
  42. /// 批量修改
  43. /// </summary>
  44. /// <param name="tableName">表名</param>
  45. /// <param name="columnName">修改的列名</param>
  46. /// <param name="value">修改的值</param>
  47. /// <param name="list">要修改的数据ID</param>
  48. /// <returns></returns>
  49. public bool BatchUpdate(string tableName, string columnName, object value, List<Guid> list)
  50. {
  51. try
  52. {
  53. //UnitOfWork.PostUpdate += new Action<object>(UnitOfWork_PostUpdate);
  54. UnitOfWork.BatchUpdate(tableName, columnName, value, list);
  55. //UnitOfWork.Commit();
  56. return true;
  57. }
  58. catch (Exception ex)
  59. {
  60. throw;
  61. }
  62. }
  63. /// <summary>
  64. /// 批量修改(修改前后需执行特定方法)
  65. /// </summary>
  66. /// <param name="tableName">表名</param>
  67. /// <param name="columnName">修改的列名</param>
  68. /// <param name="value">修改的值</param>
  69. /// <param name="list">要修改的数据ID</param>
  70. /// <returns></returns>
  71. public bool BatchUpdate(string mnuID, string tableName, string columnName, object value, List<Guid> list)//WithOnBeforeOrOnAfter
  72. {
  73. try
  74. {
  75. //UnitOfWork.PostUpdate += new Action<object>(UnitOfWork_PostUpdate);
  76. Dictionary<string,string> functionstring = this.GetBatchModifyEvents(mnuID, tableName, columnName);
  77. string onBefore = functionstring["onBefore"];
  78. if (onBefore != null && onBefore != "")
  79. {
  80. ReflectorHelper.RunMethod(onBefore, list);
  81. }
  82. UnitOfWork.BatchUpdate(tableName, columnName, value, list);
  83. string onAfter = functionstring["onAfter"];
  84. if (onAfter != null && onAfter != "")
  85. {
  86. ReflectorHelper.RunMethod(onAfter, list);
  87. }
  88. //UnitOfWork.Commit();
  89. return true;
  90. }
  91. catch (Exception ex)
  92. {
  93. throw;
  94. }
  95. }
  96. //void UnitOfWork_PostUpdate(object obj)
  97. //{
  98. // var entity = obj as EM_StudentReport;
  99. // if (entity != null)
  100. // {
  101. // if (entity.ReportStatusID != (int)CF_ReportStatus.Toreportto)
  102. // {
  103. // entity.ReportTime = DateTime.Now; //报到时间
  104. // }
  105. // else
  106. // {
  107. // entity.ReportTime = null;
  108. // }
  109. // SetModifyStatus(entity);
  110. // }
  111. //}
  112. public Dictionary<string, string> GetBatchModifyEvents(string mnuID, string munClass, string columnName)
  113. {
  114. Dictionary<string, string> functionName = new Dictionary<string, string>();
  115. string onBefore = "";
  116. string onAfter = "";
  117. var dbbatchModifyEvents = batchModifyEventsRepository.GetList(x => x.MNUID == mnuID);
  118. //List<Sys_BatchModifyEvents> dbbatchModifyEvents = BatchModifyServices.GetBatchModifyEvents(BatchModify.MNUID).ToList();
  119. List<Sys_BatchModifyEvents> batchModifyEvents = new List<Sys_BatchModifyEvents>();
  120. foreach (Sys_BatchModifyEvents batchModifyEvent in dbbatchModifyEvents)
  121. {
  122. if (batchModifyEvent.MUNClass != null && batchModifyEvent.MUNClass == munClass)
  123. {
  124. if (batchModifyEvent.ColumnName != null && batchModifyEvent.ColumnName == columnName)
  125. {
  126. batchModifyEvents.Add(batchModifyEvent);
  127. }
  128. else
  129. {
  130. batchModifyEvents.Add(batchModifyEvent);
  131. }
  132. }
  133. }
  134. if (batchModifyEvents.Count > 0)
  135. {
  136. onBefore = batchModifyEvents.FirstOrDefault().OnBefore;
  137. onAfter = batchModifyEvents.FirstOrDefault().OnAfter;
  138. }
  139. else if (dbbatchModifyEvents.Count() > 0)
  140. {
  141. onBefore = dbbatchModifyEvents.FirstOrDefault().OnBefore;
  142. onAfter = dbbatchModifyEvents.FirstOrDefault().OnAfter;
  143. }
  144. functionName.Add("onBefore",onBefore);
  145. functionName.Add("onAfter",onAfter);
  146. // && x.MUNClass == mnuClass && x.ColumnName == columnName
  147. return functionName;
  148. }
  149. }
  150. }