public bool UpdateRole(AddRoleServiceForm form) { if (string.IsNullOrEmpty(form.ID)) { throw new Exception("更新角色时没有ID"); } ISqlMapper mapper = Common.GetMapperFromSession(); RoleDao dao = new RoleDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); rmadao.Delete(new Role_Module_ActionQueryForm { RoleID = form.ID }); AddRoleAuth(mapper, form, form.ID); return(dao.Update(new RoleUpdateForm { Entity = new Role { LastUpdator = form.LastUpdator, Name = form.Name, ParentID = form.ParentID, Remark = form.Remark, DataAccessType = form.DataAccessType, }, RoleQueryForm = new RoleQueryForm { ID = form.ID }, })); }
/// <summary> /// 新增角色权限 /// </summary> /// <param name="items"></param> /// <param name="roleid"></param> /// <param name="dao"></param> private void AddAuth(List <AuthorityItem> items, string roleid, Role_Module_ActionDao dao) { foreach (var a in items) { dao.Add(new Role_Module_Action { ActionID = a.ActionID, ModuleID = a.ModuleID, RoleID = roleid }); } }
public bool DeleteRole(string id) { if (string.IsNullOrEmpty(id)) throw new Exception("删除角色时没有ID"); ISqlMapper mapper = MapperHelper.GetMapper(); RoleDao dao = new RoleDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); rmadao.Delete(new Role_Module_ActionQueryForm { RoleID = id }); Role currentrole = dao.Query(new RoleQueryForm { ID = id }).FirstOrDefault(); return dao.Delete(new RoleQueryForm { ID = id }); }
public int CheckAuth(List <Role> roles) { //验证有没有权限访问 var attr = ServiceSession.Current.Method.GetCustomAttribute <BaseActionAttribute>(true); if (attr != null) { ISqlMapper mapper = Common.GetMapperFromSession(); string actionName = attr.Action; var servicelayer = ServiceSession.Current.Method.DeclaringType.GetCustomAttribute <ServiceLayer>(true); if (servicelayer != null) { string moduleName = servicelayer.Module; var modules = TableCacheHelper.GetDataFromCache <Module>(typeof(ModuleDao)); var actions = TableCacheHelper.GetDataFromCache <RiskMgr.Model.Action>(typeof(ActionDao)); Role_Module_ActionDao dao = new Role_Module_ActionDao(mapper); var module = modules.Find(t => t.Name == moduleName); var action = actions.Find(t => t.Name == actionName); if (module == null || action == null) { return(-1); } string actionID = action.ID; string moduleID = module.ID; Role_Module_ActionQueryForm query = new Role_Module_ActionQueryForm { ActionID = actionID, ModuleID = moduleID }; //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "action id:" + actionID + ";module id:" + moduleID }, SOAFramework.Library.CacheEnum.FormMonitor); var role_module_action = dao.Query(query); bool hasRight = false; foreach (var item in role_module_action) { if (roles != null && roles.Exists(t => t.ID == item.RoleID)) { hasRight = true; break; } } if (!hasRight) { return(4); } } } return(-1); }
/// <summary> /// 查询角色 /// </summary> /// <param name="form"></param> /// <returns></returns> public List <FullRoleInfo> Query(RoleQueryForm form) { ISqlMapper mapper = Common.GetMapperFromSession(); RoleDao dao = new RoleDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); List <FullRoleInfo> result = new List <FullRoleInfo>(); form.IsDeleted = 0; var roles = dao.Query(form); var roleids = (from r in roles select r.ID).ToList(); var rmas = rmadao.Query(new Role_Module_ActionQueryForm { RoleIDs = roleids }); AuthorityMapping mapping = XMLHelper.DeserializeFromFile <AuthorityMapping>(Common.AuthorityMappingFile); foreach (var role in roles) { var data = role.ConvertTo <FullRoleInfo>(); var parentrole = roles.Find(t => t.ID == role.ParentID); if (parentrole != null) { data.ParentRoleName = parentrole.Name; } #region 查询权限 var role_rmas = rmas.FindAll(t => t.RoleID.Equals(role.ID)); data.Authority = new List <AuthorityNodeForCheck>(); foreach (var auth in mapping.AuthNode) { auth.Checked = (from au in auth.Item from r in role_rmas where au.ModuleID == r.ModuleID && au.ActionID == r.ActionID select au).Count() == auth.Item.Count; data.Authority.Add(new AuthorityNodeForCheck { ID = auth.ID, Checked = auth.Checked, Name = auth.Name }); } #endregion result.Add(data); } return(result); }
public bool DeleteRole(string id) { if (string.IsNullOrEmpty(id)) { throw new Exception("删除角色时没有ID"); } ISqlMapper mapper = Common.GetMapperFromSession(); RoleDao dao = new RoleDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); rmadao.Delete(new Role_Module_ActionQueryForm { RoleID = id }); Role currentrole = dao.Query(new RoleQueryForm { ID = id }).FirstOrDefault(); return(dao.Delete(new RoleQueryForm { ID = id })); }
private void AddRoleAuth(ISqlMapper mapper, AddRoleServiceForm form, string roleid) { #region 权限新增 //权限操作 Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); List <Module> modules = TableCacheHelper.GetDataFromCache <Module>(typeof(ModuleDao)); List <Model.Action> actions = TableCacheHelper.GetDataFromCache <Model.Action>(typeof(ActionDao)); AuthorityMapping mapping = XMLHelper.DeserializeFromFile <AuthorityMapping>(Common.AuthorityMappingFile); foreach (var auth in form.Authority) { if (!auth.Checked) { continue; } var authonode = mapping.AuthNode.Find(t => t.ID.Equals(auth.ID)); if (authonode == null) { continue; } AddAuth(authonode.Item, roleid, rmadao); } #endregion }
private void button21_Click(object sender, EventArgs e) { Workflow wf = new Workflow(); //RoleBLL bll = new RoleBLL(); //bll.AddRole(new AddRoleServiceForm //{ // Name = "testrole", // ParentID = "2", // CanManageEmployeeAndAuth = true, // CanApply = true, // CanManageAsset = true, //}); //var roles = bll.Query(new RoleQueryForm { Name = "testrole" }); RoleBLL rolebll = new RoleBLL(); var roles = rolebll.Query(new RoleQueryForm { ID = "14" }).ToList <Role>(); Role_Module_ActionDao dao = new Role_Module_ActionDao(); string actionID = "3"; string moduleID = "4"; Role_Module_ActionQueryForm query = new Role_Module_ActionQueryForm { ActionID = actionID, ModuleID = moduleID }; var role_module_action = dao.Query(query); bool hasRight = false; foreach (var item in role_module_action) { if (roles != null && roles.Exists(t => t.ID == item.RoleID)) { hasRight = true; break; } } }
public List <InitApprovalResultForm> Query(List <string> projectids, List <string> taskids, string currentuserid) { #region init dao List <InitApprovalResultForm> result = new List <InitApprovalResultForm>(); if (projectids == null || projectids.Count == 0) { return(new List <InitApprovalResultForm>()); } ISqlMapper mapper = Common.GetMapperFromSession(); ProjectDao dao = new ProjectDao(mapper); Customer_ProjectDao cpdao = new Customer_ProjectDao(mapper); Customer_AssetDao cadao = new Customer_AssetDao(mapper); Asset_ProjectDao apdao = new Asset_ProjectDao(mapper); WorkflowDao workflowdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); ApprovalDao appvoraldao = new ApprovalDao(mapper); TaskDao taskdao = new TaskDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); TrackingChangeOwnerDao tcodao = new TrackingChangeOwnerDao(mapper); TrackingMortgageDao tmdao = new TrackingMortgageDao(mapper); LinkDao linkdao = new LinkDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); ReturnBackConfirmDao rbcdao = new ReturnBackConfirmDao(mapper); CreditReceiverInfoDao cridao = new CreditReceiverInfoDao(mapper); #endregion #region 查询数据 List <Customer_Project> cps = new List <Customer_Project>(); List <Customer_Asset> cas = new List <Customer_Asset>(); List <Asset_Project> aps = new List <Asset_Project>(); List <Activity> activities = new List <Activity>(); List <Approval> approvals = new List <Approval>(); List <Task> tasks = new List <Task>(); List <TrackingChangeOwner> tco = new List <TrackingChangeOwner>(); List <TrackingMortgage> tm = new List <TrackingMortgage>(); List <string> projectidlist = new List <string>(); List <string> workflowids = new List <string>(); List <CreditReceiverInfo> criList = new List <CreditReceiverInfo>(); List <Link> links = new List <Link>(); List <ReturnBackConfirm> returnBackMoneyInfo = new List <ReturnBackConfirm>(); List <Workflow> workflows = null; List <Project> list = null; var rma = rmadao.Query(new Role_Module_ActionQueryForm { }); if (taskids != null && taskids.Count > 0) { tasks = taskdao.Query(new TaskQueryForm { IDs = taskids }); workflowids = (from t in tasks select t.WorkflowID).Distinct().ToList(); workflows = workflowdao.Query(new WorkflowQueryForm { IDs = workflowids }); activities = activitydao.Query(new ActivityQueryForm { WorkflowIDs = workflowids }); approvals = appvoraldao.Query(new ApprovalQueryForm { WorkflowIDs = workflowids }); projectidlist = (from w in workflows select w.ProcessID).ToList(); list = dao.Query(new ProjectQueryForm { IDs = projectidlist }); } else if (projectids != null && projectids.Count > 0) { list = dao.Query(new ProjectQueryForm { IDs = projectids }); projectidlist = (from p in list select p.ID).ToList(); workflows = workflowdao.Query(new WorkflowQueryForm { ProcessIDs = projectidlist }); workflowids = (from w in workflows select w.ID).ToList(); if (workflowids.Count > 0) { activities = activitydao.Query(new ActivityQueryForm { WorkflowIDs = workflowids }); approvals = appvoraldao.Query(new ApprovalQueryForm { WorkflowIDs = workflowids }); tasks = taskdao.Query(new TaskQueryForm { WorkflowIDs = workflowids }); } } else { return(result); } if (projectidlist.Count > 0) { cps = cpdao.Query(new Customer_ProjectQueryForm { ProjectIDs = projectidlist }); cas = cadao.Query(new Customer_AssetQueryForm { ProjectIDs = projectidlist }); aps = apdao.Query(new Asset_ProjectQueryForm { ProjectIDs = projectidlist }); } var users = uidao.Query(new UserInfoQueryForm { }); var userroles = urdao.Query(new User_RoleQueryForm { }); criList = cridao.Query(new CreditReceiverInfoQueryForm { ProjectIDs = projectids }); tco = tcodao.Query(new TrackingChangeOwnerQueryForm { ProjectIDs = projectidlist }); tm = tmdao.Query(new TrackingMortgageQueryForm { ProjectIDs = projectidlist }); returnBackMoneyInfo = rbcdao.Query(new ReturnBackConfirmQueryForm { ProjectIDs = projectidlist }); //从缓存中取得 var customers = TableCacheHelper.GetDataFromCache <Customer>(typeof(CustomerDao)); var assets = TableCacheHelper.GetDataFromCache <Asset>(typeof(AssetDao)); #endregion #region 处理废单权限 //处理废单权限 var hasDisplayDiscard = (from ur in userroles join r in rma on ur.RoleID equals r.RoleID where r.ModuleID == "4" && r.ActionID == "4" && ur.UserID == currentuserid select r).FirstOrDefault(); #endregion foreach (Project project in list) { var data = QueryDetail(project, customers, assets, cps, cas, aps, workflows, activities, approvals, tasks, users, userroles, tco, tm, returnBackMoneyInfo, criList, currentuserid); if (hasDisplayDiscard != null) { data.DisplayDiscard = true; } result.Add(data); } return(result); }
public int CheckAuth(List<Role> roles) { //验证有没有权限访问 var attr = ServiceSession.Current.Method.GetCustomAttribute<BaseActionAttribute>(true); if (attr != null) { ISqlMapper mapper = MapperHelper.GetMapper(); string actionName = attr.Action; var servicelayer = ServiceSession.Current.Method.DeclaringType.GetCustomAttribute<ServiceLayer>(true); if (servicelayer != null) { string moduleName = servicelayer.Module; var modules = TableCacheHelper.GetDataFromCache<Module>(typeof(ModuleDao)); var actions = TableCacheHelper.GetDataFromCache<Model.Action>(typeof(ActionDao)); Role_Module_ActionDao dao = new Role_Module_ActionDao(mapper); var module = modules.Find(t => t.Name == moduleName); var action = actions.Find(t => t.Name == actionName); if (module == null || action == null) return -1; string actionID = action.ID; string moduleID = module.ID; Role_Module_ActionQueryForm query = new Role_Module_ActionQueryForm { ActionID = actionID, ModuleID = moduleID }; //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "action id:" + actionID + ";module id:" + moduleID }, SOAFramework.Library.CacheEnum.FormMonitor); var role_module_action = dao.Query(query); bool hasRight = false; foreach (var item in role_module_action) { if (roles != null && roles.Exists(t => t.ID == item.RoleID)) { hasRight = true; break; } } if (!hasRight) return 4; } } return -1; }
private void button21_Click(object sender, EventArgs e) { Workflow wf = new Workflow(); //RoleBLL bll = new RoleBLL(); //bll.AddRole(new AddRoleServiceForm //{ // Name = "testrole", // ParentID = "2", // CanManageEmployeeAndAuth = true, // CanApply = true, // CanManageAsset = true, //}); //var roles = bll.Query(new RoleQueryForm { Name = "testrole" }); RoleBLL rolebll = new RoleBLL(); var roles = rolebll.Query(new RoleQueryForm { ID="14" }).ToList<Role>(); Role_Module_ActionDao dao = new Role_Module_ActionDao(); string actionID = "3"; string moduleID = "4"; Role_Module_ActionQueryForm query = new Role_Module_ActionQueryForm { ActionID = actionID, ModuleID = moduleID }; var role_module_action = dao.Query(query); bool hasRight = false; foreach (var item in role_module_action) { if (roles != null && roles.Exists(t => t.ID == item.RoleID)) { hasRight = true; break; } } }
private void AddRoleAuth(ISqlMapper mapper, AddRoleServiceForm form, string roleid) { #region 权限新增 //权限操作 Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); List<Module> modules = TableCacheHelper.GetDataFromCache<Module>(typeof(ModuleDao)); List<Model.Action> actions = TableCacheHelper.GetDataFromCache<Model.Action>(typeof(ActionDao)); AuthorityMapping mapping = XMLHelper.DeserializeFromFile<AuthorityMapping>(Common.AuthorityMappingFile); foreach (var auth in form.Authority) { if (!auth.Checked) continue; var authonode = mapping.AuthNode.Find(t => t.ID.Equals(auth.ID)); if (authonode == null) continue; AddAuth(authonode.Item, roleid, rmadao); } #endregion }
/// <summary> /// 新增角色权限 /// </summary> /// <param name="items"></param> /// <param name="roleid"></param> /// <param name="dao"></param> private void AddAuth(List<AuthorityItem> items, string roleid, Role_Module_ActionDao dao) { foreach (var a in items) dao.Add(new Role_Module_Action { ActionID = a.ActionID, ModuleID = a.ModuleID, RoleID = roleid }); }
public bool UpdateRole(AddRoleServiceForm form) { if (string.IsNullOrEmpty(form.ID)) throw new Exception("更新角色时没有ID"); ISqlMapper mapper = MapperHelper.GetMapper(); RoleDao dao = new RoleDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); Menu_RoleDao mrdao = new Menu_RoleDao(mapper); rmadao.Delete(new Role_Module_ActionQueryForm { RoleID = form.ID }); AddRoleAuth(mapper, form, form.ID); mrdao.Delete(new Menu_RoleQueryForm { RoleID = form.ID }); if (form.Menus != null) { foreach (var menu in form.Menus) { mrdao.Add(new Menu_Role { RoleID = form.ID, MenuID = menu.ID }); } } return dao.Update(new RoleUpdateForm { Entity = new Role { LastUpdator = form.LastUpdator, Name = form.Name, ParentID = form.ParentID, Remark = form.Remark, DataAccessType = form.DataAccessType, }, RoleQueryForm = new RoleQueryForm { ID = form.ID }, }); }
/// <summary> /// 查询角色 /// </summary> /// <param name="form"></param> /// <returns></returns> public List<FullRoleInfo> QueryFullRole(RoleQueryForm form) { ISqlMapper mapper = MapperHelper.GetMapper(); RoleDao dao = new RoleDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); Menu_RoleDao mrdao = new Menu_RoleDao(mapper); MenuDao menudao = new MenuDao(mapper); List<FullRoleInfo> result = new List<FullRoleInfo>(); form.IsDeleted = 0; var roles = dao.Query(form); var roleids = (from r in roles select r.ID).ToList(); var rmas = rmadao.Query(new Role_Module_ActionQueryForm { RoleIDs = roleids }); var mrs = mrdao.Query(new Menu_RoleQueryForm { RoleIDs = roleids }); var menuids = (from mr in mrs select mr.MenuID).Distinct().ToList(); var menus = menudao.Query(new MenuQueryForm { IDs = menuids, Enabled = 1 }); AuthorityMapping mapping = XMLHelper.DeserializeFromFile<AuthorityMapping>(Common.AuthorityMappingFile); foreach (var role in roles) { var data = role.ConvertTo<FullRoleInfo>(); var parentrole = roles.Find(t => t.ID == role.ParentID); if (parentrole != null) data.ParentRoleName = parentrole.Name; #region 查询权限 var role_rmas = rmas.FindAll(t => t.RoleID.Equals(role.ID)); data.Authority = new List<AuthorityNodeForCheck>(); foreach (var auth in mapping.AuthNode) { auth.Checked = (from au in auth.Item from r in role_rmas where au.ModuleID == r.ModuleID && au.ActionID == r.ActionID select au).Count() == auth.Item.Count; data.Authority.Add(new AuthorityNodeForCheck { ID = auth.ID, Checked = auth.Checked, Name = auth.Name }); } #endregion #region 查询菜单 data.Menus = (from mr in mrs join m in menus on mr.MenuID equals m.ID where mr.RoleID.Equals(role.ID) select m).ToList(); #endregion result.Add(data); } return result; }
public bool UpdateRole(AddRoleServiceForm form) { if (string.IsNullOrEmpty(form.ID)) { throw new Exception("更新角色时没有ID"); } ISqlMapper mapper = Common.GetMapperFromSession(); RoleDao dao = new RoleDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); rmadao.Delete(new Role_Module_ActionQueryForm { RoleID = form.ID }); AddRoleAuth(mapper, form, form.ID); return dao.Update(new RoleUpdateForm { Entity = new Role { LastUpdator = form.LastUpdator, Name = form.Name, ParentID = form.ParentID, Remark = form.Remark, DataAccessType = form.DataAccessType, }, RoleQueryForm = new RoleQueryForm { ID = form.ID }, }); }