using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autofac; using System.Reflection; using System.Data.Entity; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.Cache; using Bowin.Common.Cache; using EMIS.Utility; using EMIS.Utility.FormValidate; using EMIS.ViewModel.SystemView; using EMIS.DataLogic.SystemSetting; namespace EMIS.CommonLogic.SystemServices { public class ControlItemServices : BaseServices, IControlItemServices { public ControlItemDAL ControlItemDAL { get; set; } /// /// 刷新对应的菜单项 /// public void RefreshCache() { var key = "ControlItem_MenuNoList"; var result = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.ContextMnuNo == null) .Select(x => x.MenuNo).Distinct().ToList(); CacheHelper.Remove(key); CacheHelper.Add(key, result); key = "ControlItem_ContextMenuNoList"; var contextMenuResult = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.ContextMnuNo != null) .Select(x => new ContextMenuNoView { MenuNo = x.MenuNo, ContextMenuNo = x.ContextMnuNo }) .Distinct().ToList(); CacheHelper.Remove(key); CacheHelper.Add(key, contextMenuResult); } /// /// 获取需要进行逻辑控制的菜单 /// /// public List GetNeedControlMenuNo() { var key = "ControlItem_MenuNoList"; var cachedValue = CacheHelper.Get(key); if (cachedValue == null) { var result = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.ContextMnuNo == null) .Select(x => x.MenuNo).Distinct().ToList(); CacheHelper.Add(key, result); return result; } else { return (List)cachedValue; } } /// /// 控制菜单,如果不能通过将抛出异常,否则就算通过 /// /// public void CheckControlItems(string menuNo) { var user = CustomPrincipal.Current; var controlItemList = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.MenuNo == menuNo && x.ContextMnuNo == null).ToList(); var messageList = new List(); foreach (var controlItem in controlItemList) { if (!string.IsNullOrEmpty(controlItem.Sys_ControlItem.ClassName)) { try { var retValue = ReflectorHelper.RunMethod(controlItem.Sys_ControlItem.ClassName, user.UserID); if (retValue.GetType() == typeof(bool) && (bool)retValue == false) { messageList.Add(controlItem.Sys_ControlItem.Message); } } catch (Exception ex) { throw ex; } } } if (messageList.Count > 0) { throw new Exception(string.Join("", messageList)); } } /// /// 获取需要进行逻辑控制的菜单 /// /// public List GetNeedControlContextMenuNo() { var key = "ControlItem_ContextMenuNoList"; var cachedValue = CacheHelper.Get(key); if (cachedValue == null) { var result = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.ContextMnuNo != null) .Select(x => new ContextMenuNoView { MenuNo = x.MenuNo, ContextMenuNo = x.ContextMnuNo }) .Distinct().ToList(); CacheHelper.Add(key, result); return result; } else { return (List)cachedValue; } } /// /// 控制按钮,如果不能通过将抛出异常,否则就算通过 /// /// public void CheckControlItems(ContextMenuNoView contextMenuNoView) { var user = CustomPrincipal.Current; var controlItemList = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.MenuNo == contextMenuNoView.MenuNo && x.ContextMnuNo == contextMenuNoView.ContextMenuNo).ToList(); var messageList = new List(); foreach (var controlItem in controlItemList) { if (!string.IsNullOrEmpty(controlItem.Sys_ControlItem.ClassName)) { try { var retValue = ReflectorHelper.RunMethod(controlItem.Sys_ControlItem.ClassName, user.UserID); if (retValue.GetType() == typeof(bool) && (bool)retValue == false) { messageList.Add(controlItem.Sys_ControlItem.Message); } } catch (Exception ex) { throw ex; } } } if (messageList.Count > 0) { throw new Exception(string.Join("", messageList)); } } /// /// 查询相应控制类型的控制信息List /// /// /// public IList GetControlItemList(ViewModel.SYS_ControlItemType controlItemType) { return ControlItemDAL.GetControlItemList(x => x.ControlItemTypeID == (int)controlItemType).ToList(); } /// /// 查询登录控制类型的控制信息List /// /// public IList GetLoginControlItemList() { return ControlItemDAL.GetControlItemList(x => x.IsLoginControl == true && x.IsEnable == true).ToList(); } /// /// 查询相应用户ID的登录控制信息 /// /// public void CheckLoginControlItems(Guid userID) { var controlItemList = this.GetLoginControlItemList(); var messageList = new List(); foreach (var controlItem in controlItemList) { if (!string.IsNullOrEmpty(controlItem.ClassName)) { try { var retValue = ReflectorHelper.RunMethod(controlItem.ClassName, userID); if (retValue.GetType() == typeof(bool) && (bool)retValue == false) { messageList.Add(controlItem.Message); } } catch (Exception ex) { throw ex; } } } if (messageList.Count > 0) { throw new Exception(string.Join("\n", messageList)); } } } }