123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- 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.CacheManage;
- 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; }
- /// <summary>
- /// 刷新对应的菜单项
- /// </summary>
- 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);
- }
- /// <summary>
- /// 获取需要进行逻辑控制的菜单
- /// </summary>
- /// <returns></returns>
- public List<string> 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<string>)cachedValue;
- }
- }
- /// <summary>
- /// 控制菜单,如果不能通过将抛出异常,否则就算通过
- /// </summary>
- /// <param name="menuNo"></param>
- 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<string>();
- 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));
- }
- }
- /// <summary>
- /// 获取需要进行逻辑控制的菜单
- /// </summary>
- /// <returns></returns>
- public List<ContextMenuNoView> 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<ContextMenuNoView>)cachedValue;
- }
- }
- /// <summary>
- /// 控制按钮,如果不能通过将抛出异常,否则就算通过
- /// </summary>
- /// <param name="contextMenuNoView"></param>
- 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<string>();
- 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));
- }
- }
- /// <summary>
- /// 查询相应控制类型的控制信息List
- /// </summary>
- /// <param name="controlItemType"></param>
- /// <returns></returns>
- public IList<Entities.Sys_ControlItem> GetControlItemList(ViewModel.SYS_ControlItemType controlItemType)
- {
- return ControlItemDAL.GetControlItemList(x => x.ControlItemTypeID == (int)controlItemType).ToList();
- }
- /// <summary>
- /// 查询登录控制类型的控制信息List
- /// </summary>
- /// <returns></returns>
- public IList<Entities.Sys_ControlItem> GetLoginControlItemList()
- {
- return ControlItemDAL.GetControlItemList(x => x.IsLoginControl == true && x.IsEnable == true).ToList();
- }
- /// <summary>
- /// 查询相应用户ID的登录控制信息
- /// </summary>
- /// <param name="userID"></param>
- public void CheckLoginControlItems(Guid userID)
- {
- var messageList = new List<string>();
- var controlItemList = this.GetLoginControlItemList();
- 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));
- }
- }
- }
- }
|