123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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; }
- /// <summary>
- /// 根据mnuID(页面ID)获取设置信息
- /// </summary>
- /// <param name="mnuID">页面ID</param>
- /// <returns></returns>
- public List<Entities.Sys_BatchModify> GetBatchModifyList(string mnuID)
- {
- //查询条件
- System.Linq.Expressions.Expression<Func<Sys_BatchModify, bool>> expression = (x => true);
- if (!string.IsNullOrEmpty(mnuID))
- expression = (x => x.MNUID == mnuID);
- return batchModifyRepository.GetList(expression).OrderBy(x => x.OrderNo).ToList();
- }
- /// <summary>
- /// 获取配置扩展表
- /// </summary>
- /// <param name="BatchModifyID"></param>
- /// <returns></returns>
- public List<Sys_BatchModifyExpand> GetBatchModifyExpandList(Guid? BatchModifyID)
- {
- //查询条件
- System.Linq.Expressions.Expression<Func<Sys_BatchModifyExpand, bool>> expression = (x => true);
- expression = (x => x.BatchModifyID == BatchModifyID);
- return batchModifyExpandRepository.GetList(expression).ToList();
- }
- /// <summary>
- /// 批量修改
- /// </summary>
- /// <param name="tableName">表名</param>
- /// <param name="columnName">修改的列名</param>
- /// <param name="value">修改的值</param>
- /// <param name="list">要修改的数据ID</param>
- /// <returns></returns>
- public bool BatchUpdate(string tableName, string columnName, object value, List<Guid> list)
- {
- try
- {
- //UnitOfWork.PostUpdate += new Action<object>(UnitOfWork_PostUpdate);
- UnitOfWork.BatchUpdate(tableName, columnName, value, list);
- //UnitOfWork.Commit();
- return true;
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- /// <summary>
- /// 批量修改(修改前后需执行特定方法)
- /// </summary>
- /// <param name="tableName">表名</param>
- /// <param name="columnName">修改的列名</param>
- /// <param name="value">修改的值</param>
- /// <param name="list">要修改的数据ID</param>
- /// <returns></returns>
- public bool BatchUpdate(string mnuID, string tableName, string columnName, object value, List<Guid> list)//WithOnBeforeOrOnAfter
- {
- try
- {
- //UnitOfWork.PostUpdate += new Action<object>(UnitOfWork_PostUpdate);
- Dictionary<string,string> 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<string, string> GetBatchModifyEvents(string mnuID, string munClass, string columnName)
- {
- Dictionary<string, string> functionName = new Dictionary<string, string>();
- string onBefore = "";
- string onAfter = "";
- var dbbatchModifyEvents = batchModifyEventsRepository.GetList(x => x.MNUID == mnuID);
- //List<Sys_BatchModifyEvents> dbbatchModifyEvents = BatchModifyServices.GetBatchModifyEvents(BatchModify.MNUID).ToList();
- List<Sys_BatchModifyEvents> batchModifyEvents = new List<Sys_BatchModifyEvents>();
- 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;
- }
- }
- }
|