using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Repositories; using EMIS.Entities; using EMIS.ViewModel; using EMIS.Utility; namespace EMIS.CommonLogic.SystemServices { class BatchModifyServices : BaseServices, IBatchModifyServices { public BatchModifyRepository batchModifyRepository { get; set; } public BatchModifyEventsRepository batchModifyEventsRepository { get; set; } public BatchModifyExpandRepository batchModifyExpandRepository { get; set; } /// /// 根据mnuID(页面ID)获取设置信息 /// /// 页面ID /// public List GetBatchModifyList(string mnuID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => true); if (!string.IsNullOrEmpty(mnuID)) expression = (x => x.MNUID == mnuID); return batchModifyRepository.GetList(expression).OrderBy(x => x.OrderNo).ToList(); } /// /// 获取配置扩展表 /// /// /// public List GetBatchModifyExpandList(Guid? BatchModifyID) { //查询条件 System.Linq.Expressions.Expression> expression = (x => true); expression = (x => x.BatchModifyID == BatchModifyID); return batchModifyExpandRepository.GetList(expression).ToList(); } /// /// 批量修改 /// /// 表名 /// 修改的列名 /// 修改的值 /// 要修改的数据ID /// public bool BatchUpdate(string tableName, string columnName, object value, List list) { try { //UnitOfWork.PostUpdate += new Action(UnitOfWork_PostUpdate); UnitOfWork.BatchUpdate(tableName, columnName, value, list); //UnitOfWork.Commit(); return true; } catch (Exception ex) { throw; } } /// /// 批量修改(修改前后需执行特定方法) /// /// 表名 /// 修改的列名 /// 修改的值 /// 要修改的数据ID /// public bool BatchUpdate(string mnuID, string tableName, string columnName, object value, List list)//WithOnBeforeOrOnAfter { try { //UnitOfWork.PostUpdate += new Action(UnitOfWork_PostUpdate); Dictionary functionstring = this.GetBatchModifyEvents(mnuID, tableName, columnName); string onBefore = functionstring["onBefore"]; if (onBefore != null && onBefore != "") { ReflectorHelper.RunMethod(onBefore, list); } UnitOfWork.BatchUpdate(tableName, columnName, value, list); string onAfter = functionstring["onAfter"]; if (onAfter != null && onAfter != "") { ReflectorHelper.RunMethod(onAfter, list); } //UnitOfWork.Commit(); return true; } catch (Exception ex) { throw; } } //void UnitOfWork_PostUpdate(object obj) //{ // var entity = obj as EM_StudentReport; // if (entity != null) // { // if (entity.ReportStatusID != (int)CF_ReportStatus.Toreportto) // { // entity.ReportTime = DateTime.Now; //报到时间 // } // else // { // entity.ReportTime = null; // } // SetModifyStatus(entity); // } //} public Dictionary GetBatchModifyEvents(string mnuID, string munClass, string columnName) { Dictionary functionName = new Dictionary(); string onBefore = ""; string onAfter = ""; var dbbatchModifyEvents = batchModifyEventsRepository.GetList(x => x.MNUID == mnuID); //List dbbatchModifyEvents = BatchModifyServices.GetBatchModifyEvents(BatchModify.MNUID).ToList(); List batchModifyEvents = new List(); foreach (Sys_BatchModifyEvents batchModifyEvent in dbbatchModifyEvents) { if (batchModifyEvent.MUNClass != null && batchModifyEvent.MUNClass == munClass) { if (batchModifyEvent.ColumnName != null && batchModifyEvent.ColumnName == columnName) { batchModifyEvents.Add(batchModifyEvent); } else { batchModifyEvents.Add(batchModifyEvent); } } } if (batchModifyEvents.Count > 0) { onBefore = batchModifyEvents.FirstOrDefault().OnBefore; onAfter = batchModifyEvents.FirstOrDefault().OnAfter; } else if (dbbatchModifyEvents.Count() > 0) { onBefore = dbbatchModifyEvents.FirstOrDefault().OnBefore; onAfter = dbbatchModifyEvents.FirstOrDefault().OnAfter; } functionName.Add("onBefore",onBefore); functionName.Add("onAfter",onAfter); // && x.MUNClass == mnuClass && x.ColumnName == columnName return functionName; } } }