系统管理模块
1、实体类
public partial class T_Role { public string RoleId { get; set; } public string RoleName { get; set; } public string CommentAry { get; set; } public string CodeNo { get; set; } public string CustomNo { get; set; } public string SpellNo { get; set; } public string StrokeNo { get; set; } }
public partial class T_Role_Privilege { public string RoleId { get; set; } public string Privid { get; set; } public string BarCaption { get; set; } public Nullable<int> BarOrder { get; set; } public string IsEndNode { get; set; } public Nullable<int> IsToolBar { get; set; } public string NodeID { get; set; } public string ParentNode { get; set; } public int Id { get; set; } }
public partial class T_Operator { public string OperatorID { get; set; } public string DepID { get; set; } public string OperatorName { get; set; } public string Passwrod { get; set; } public string RoleID { get; set; } public string UserID { get; set; } public string CellPhone { get; set; } public string Emial { get; set; } public Nullable<int> LoginCount { get; set; } public string LastLoginTime { get; set; } public Nullable<int> State { get; set; } public string BuildMan { get; set; } public Nullable<System.DateTime> BuildDate { get; set; } public string EditMan { get; set; } public Nullable<System.DateTime> EditDate { get; set; } }
public partial class T_Operator_Privilege { public string BarCaption { get; set; } public Nullable<int> BarOrder { get; set; } public string IsEndNode { get; set; } public Nullable<int> IsToolBar { get; set; } public string NodeId { get; set; } public string OperatorID { get; set; } public string ParentNode { get; set; } public string PrivId { get; set; } public int Id { get; set; } }
public partial class T_Organization { public string F_OrgID { get; set; } public string F_OrgName { get; set; } public string F_OrgManager { get; set; } public Nullable<System.DateTime> F_BuildDate { get; set; } public string F_BuildMan { get; set; } public string F_TellPhoneNum { get; set; } public string F_Address { get; set; } public Nullable<bool> F_State { get; set; } public string F_ParentID { get; set; } }
public partial class T_WholeMenu { public string NodeId { get; set; } public string NodeName { get; set; } public string ParentNode { get; set; } public string IsEndNode { get; set; } public string PluginId { get; set; } public string CommentAry { get; set; } public string Disporder { get; set; } public Nullable<int> Type { get; set; } public string GroupByName { get; set; } public string ImageIco { get; set; } public Nullable<int> TypeShow { get; set; } public Nullable<bool> IsStartUp { get; set; } }
public partial class Sys_Buttons { public int KeyId { get; set; } public string ButtonCaption { get; set; } public int Sortnum { get; set; } public string IconCls { get; set; } public string IconUrl { get; set; } public string ButtonTag { get; set; } public string Remark { get; set; } public string ButtonHtml { get; set; } public string BuggonGroup { get; set; } public int State { get; set; } public string ToolTip { get; set; } }
public partial class Sys_Button_Privilege { public int SysId { get; set; } public Nullable<int> ButtonId { get; set; } public string OperatorId { get; set; } public string RoleId { get; set; } public string NodeId { get; set; } }
public partial class Sys_WholeMenuButtons { public int KeyId { get; set; } public string MenuId { get; set; } public Nullable<int> ButtonId { get; set; } public Nullable<int> Sortnum { get; set; } public string ButtonName { get; set; } }
2、服务器契约
服务契约代码
[ServiceContract(Namespace = "www.kubim.com/OperatorSerivce")] public interface IOperationpurviewService {
#region 操作人员管理 //添加人员 [OperationContract(IsInitiating = true)] bool InsertOperatorInfo(T_Operator operatorEntity); ///<summary> ///修改操作T_Operator /// </summary> [OperationContract(IsInitiating = true)] bool UpdateT_Operator(T_Operator model); ///<summary> ///修改操作T_Operator /// </summary> [OperationContract(IsInitiating = true)] T_Operator T_OperatorById(string operatorid); ///<summary> ///删除操作T_Operator /// </summary> [OperationContract(IsInitiating = true)] bool DeleteT_Operator(String id); //获取最大人员编号 [OperationContract(IsInitiating = true)] int GetMaxOperatorId(); //获取所有人员 [OperationContract(IsInitiating = true)] IQueryable<T_Operator> GetOperatorAllList(); //根据用户登录的ID查询 [OperationContract(IsInitiating = true)] List<FindMenuRigthByOperator> GetRightOperatorByOperatorId(string operatorid); //根据用户登录的ID查询 [OperationContract(IsInitiating = true)] List<FindMenuRigthByOperator> GetRightOperatorByRoleId(string roleid); /// <summary> /// 用户登录 /// </summary> /// <param name="loginUserName">登录名称</param> /// <param name="loginPassword">登录密码</param> /// <returns></returns> [OperationContract(IsInitiating = true)] bool LoginUser(string loginUserName, string loginPassword); /// <summary> /// 用户登录 /// </summary> /// <param name="loginUserName">登录名称</param> /// <param name="loginPassword">登录密码</param> /// <param name="log">登录其它信息</param> /// <returns>返回字符串信息</returns> [OperationContract(IsInitiating = true)] string Login(string loginUserName, string loginPassword, params string[] log); /// <summary> /// 用户登陆 /// </summary> /// <param name="loginUserName">Name of the login user.</param> /// <param name="loginPassword">The login password.</param> /// <param name="log">The log.</param> /// <returns>用户信息.</returns> [OperationContract(IsInitiating = true)] T_Operator LoginOperator(string loginUserName, string loginPassword, params string[] log); /// <summary> /// 用户登录次数添加 /// </summary> /// <param name="operatorId">操作员ID</param> [OperationContract(IsInitiating = true)] bool OperatorAddLoginCount(T_Operator operatorId); /// <summary> /// 获取人员信息 /// </summary> /// <param name="departId">以部门编号</param> [OperationContract(IsInitiating = true)] List<T_Operator> GetOperatorListByDepartId(string departId); /// <summary> /// 判斷用戶登陸名稱是否存在 /// Determines whether [is existe login user name] [the specified login user name]. /// </summary> /// <param name="loginUserName">Name of the login user.</param> /// <returns><c>true</c> if [is existe login user name] [the specified login user name]; otherwise, <c>false</c>.</returns> [OperationContract(IsInitiating = true)] bool IsExisteLoginUserName(string loginUserName); #endregion
#region 用户角色管理 //新增用户角色 [OperationContract(IsInitiating = true)] bool InsertRoleInfo(T_Role roleEntity); /// <summary> /// 获取用户角色 /// </summary> /// <param name="roleid">获取用户信息</param> /// <returns></returns> [OperationContract(IsInitiating = true)] T_Role T_RoleById(string roleid); ///<summary> ///修改操作T_Role /// </summary> [OperationContract(IsInitiating = true)] bool UpdateT_Role(T_Role model); ///<summary> ///删除操作T_Role /// </summary> [OperationContract(IsInitiating = true)] bool DeleteT_Role(String id); //获取用户角色人员信息 [OperationContract(IsInitiating = true)] List<FindRoleRigthByRole> GetRoleRigthByRoleCode(string roleCode); //获取所有角色 [OperationContract(IsInitiating = true)] List<T_Role> GetRoleAllList(); //获取最大角色编号 [OperationContract(IsInitiating = true)] int GetMaxRoleId(); /// <summary> /// 修改用户密码 /// </summary> /// <param name="oldPwd">旧的用户密码</param> /// <param name="newPwd">新的用户密码</param> /// <param name="userid">用户人员编号</param> /// <returns></returns> [OperationContract(IsInitiating = true)] string ChangeUserPwd(string oldPwd, string newPwd, string userid); #endregion
#region 用户授权管理 //新增用户权限信息 [OperationContract(IsInitiating = true)] void InsertOperatorPrivilegeInfo(T_Operator_Privilege operatorEntity); //删除用户权限信息 [OperationContract(IsInitiating = true)] void DeleteOperatorPrivilegeInfoByOperatorId(string operatorid); #endregion
#region 角色授权管理 //新增角色权限 [OperationContract(IsInitiating = true)] void InsertTRolePrivilege(T_Role_Privilege roleEntity); //删除角色权限 [OperationContract(IsInitiating = true)] void DeleteRolePrivilegeByRoleId(string roleid); /// <summary> /// 添加项目权限 /// </summary> /// <param name="projectLimitses">项目权限信息</param> /// <param name="typeinfo">操作员/角色 Operator/Role</param> /// <param name="typeid">角色编号/用户编号</param> /// <returns>bool</returns> [OperationContract(IsInitiating = true)] bool AddProjectLimits(List<T_ProjectLimits> projectLimitses, string typeinfo, string typeid); /// <summary> /// 添加机构数据权限 /// </summary> /// <param name="organizationPrivileges">项目权限信息</param> /// <param name="typeinfo">操作员/角色 Operator/Role</param> /// <param name="typeid">角色编号/用户编号</param> /// <returns>bool</returns> [OperationContract(IsInitiating = true)] bool AddOrgizationLimits(List<T_Organization_Privilege> organizationPrivileges, string typeinfo, string typeid); /// <summary> /// 添加项目权限 /// </summary> /// <param name="organizationPrivileges">项目权限信息</param> /// <param name="typeinfo">操作员/角色 Operator/Role</param> /// <param name="typeid">角色编号/用户编号</param> /// <returns>bool</returns> [OperationContract(IsInitiating = true)] bool AddLineMileageLimits(List<LineMileage_Privilege> organizationPrivileges, string typeinfo, string typeid); #endregion
#region 菜单管理 //添加菜单 [OperationContract(IsInitiating = true)] void InsertTWholemenu(T_WholeMenu menuEntity); //修改菜单 [OperationContract(IsInitiating = true)] bool UpdateTWholeMenu(T_WholeMenu menuEntity); //获取所有菜单 [OperationContract(IsInitiating = true)] List<T_WholeMenu> GetAllWholeMenuList(); //获取父菜单的ID [OperationContract(IsInitiating = true)] int GetTwholeMenuNodeId(); //获取子菜单的ID [OperationContract(IsInitiating = true)] int GetTWholeMenuNodeChildrenId(); //获取最大的菜单 [OperationContract(IsInitiating = true)] int GetMaxWholeMenuId(string parentnode); //删除父节点下所有菜单 [OperationContract(IsInitiating = true)] void DeleteWholeMenu(string parentid); //根据菜单编号删除下面所有信息 [OperationContract(IsInitiating = true)] void DeleteWholeMenuNode(string nodeid); //保存用户权限 [OperationContract(IsInitiating = true)] bool AddUserRight(DataTable dt, string type, string typeid); #endregion
#region 系统字典管理 //添加字典信息 [OperationContract(IsInitiating = true)] bool InsertDectionary(T_DictionaryInfo tInfo); //修改字典信息 [OperationContract(IsInitiating = true)] bool UpdateDectionary(T_DictionaryInfo tInfo); //获取所有字典信息 [OperationContract(IsInitiating = true)] List<T_DictionaryInfo> GetAllDictonaryList(); //根据字典类型 [OperationContract(IsInitiating = true)] List<T_DictionaryInfo> SearchDictionaryOfType(string fDictonaryType); //根据字典类型 [OperationContract()] List<T_DictionaryInfo> SearchDictionaryOfTypeCode(string typeCode); //获取父菜单的编号 [OperationContract(IsInitiating = true)] int GetMaxDictionaryParentCode(); //获取子菜单的编号 [OperationContract(IsInitiating = true)] int GetDictionaryNodeChildrenCode(); //获取最大的菜单 [OperationContract(IsInitiating = true)] int GetMaxDictionaryCode(string parentCode); //删除子菜单 [OperationContract(IsInitiating = true)] bool DeleteDictionaryChildrenCode(string dictonaryCode); //删除父菜和下面的所有的子菜单 bool DeleteDictonaryCode(string parnentdictonaryCode); //数据库名称 [OperationContract(IsInitiating = true)] DataTable GetAllTableNameByDb(string dataBaseName); //获取父节点下的子节点的Count [OperationContract(IsInitiating = true)] int GetDictionaryCountByParentCode(string parentCode); //根据字典编号获取明细信息 [OperationContract(IsInitiating = true)] T_DictionaryInfo GetTDictonaryInfo(string dictonaryCode); #endregion
#region 组织机构 /// <summary> /// 新增操作T_Organization /// </summary> /// <param name="model">The model.</param> /// <param name="operatorid">The operatorid.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> [OperationContract(IsInitiating = true)] bool InsertT_Organization(T_Organization model,string operatorid); ///<summary> ///修改操作T_Organization /// </summary> [OperationContract(IsInitiating = true)] bool UpdateT_Organization(T_Organization model); ///<summary> ///删除操作T_Organization /// </summary> [OperationContract(IsInitiating = true)] bool DeleteT_Organization(String id); ///<summary> ///获取所有数据T_Organization /// </summary> [OperationContract(IsInitiating = true)] List<T_Organization> GetT_OrganizationListData(); /// <summary> /// 根据用户判断当前组织机构信息 </summary> /// <param name="operatorId"></param> /// <returns></returns> [OperationContract(IsInitiating = true)] IQueryable<T_Organization> GetT_OrganizationBy(string operatorId); #endregion
#region 机构权限 /// <summary> ///根据SQL语句查询返回IQueryableT_Organization_Privilege /// <param name="sql">T_Organization_PrivilegeSQL语句</param> /// </summary> [OperationContract] IQueryable<T_Organization_Privilege> GetT_Organization_PrivilegeBySql(string sql, params object[] obj); /// <summary> ///获取实体T_Organization_Privilege /// <param name="id">主键编号</param> /// </summary> [OperationContract] List<T_Organization_Privilege> GetT_Organization_PrivilegeById(string id); /// <summary> ///修改实体T_Organization_Privilege /// <param name="entity">T_Organization_Privilege实体</param> /// </summary> [OperationContract] bool UpdateT_Organization_Privilege(List<T_Organization_Privilege> entity); /// <summary> ///新增实体T_Organization_Privilege /// <param name="entity">T_Organization_Privilege实体</param> /// </summary> [OperationContract] bool CreateT_Organization_Privilege(List<T_Organization_Privilege> entity, string operatorId); /// <summary> ///新增实体T_Organization_Privilege /// <param name="entity">T_Organization_Privilege实体</param> /// </summary> [OperationContract] bool CreateT_Organization_PrivilegeEntity(T_Organization_Privilege entity); /// <summary> ///删除T_Organization_Privilege /// <param name="id">主键编号</param> /// </summary> [OperationContract] bool DeleteT_Organization_Privilege(List<int> id); /// <summary> ///获取实体LineMileage_Privilege /// <param name="id">主键编号</param> /// </summary> [OperationContract] LineMileage_Privilege GetLineMileage_PrivilegeById(string id); /// <summary> ///修改实体LineMileage_Privilege /// <param name="entity">LineMileage_Privilege实体</param> /// </summary> [OperationContract] bool UpdateLineMileage_Privilege(LineMileage_Privilege entity); /// <summary> ///新增实体LineMileage_Privilege /// <param name="entity">LineMileage_Privilege实体</param> /// </summary> [OperationContract] bool CreateLineMileage_Privilege(List<LineMileage_Privilege> entity, string operatorId); /// <summary> ///删除LineMileage_Privilege /// <param name="id">主键编号</param> /// </summary> [OperationContract] bool DeleteLineMileage_Privilege(string id); /// <summary> /// 获取线路里程权限信息 /// </summary> /// <param name="strsql">sql</param> /// <param name="obj">参数</param> /// <returns>IQueryable</returns> [OperationContract] IQueryable<T_ProjectLimits> GetT_ProjectLimitsBySql(string strsql, params object[] obj); /// <summary> ///根据SQL语句查询返回IQueryableLineMileage_Privilege /// <param name="sql">LineMileage_PrivilegeSQL语句</param> /// </summary> [OperationContract] IQueryable<LineMileage_Privilege> GetLineMileage_PrivilegeBySql(string sql, params CmdParameter[] obj); /// <summary> ///新增实体T_ProjectLimits /// <param name="entity">T_ProjectLimits实体</param> /// </summary> [OperationContract] bool CreateT_ProjectLimits_Privilege(List<T_ProjectLimits> entity, string operatorId); /// <summary> /// 获取当前用户的信息 /// </summary> /// <param name="operatorid"></param> /// <returns></returns> [OperationContract] IQueryable<T_ProjectLimits> GetT_ProjectLimitsByOperator(string operatorid); #endregion
#region 系统菜单按钮 /// <summary> ///获取实体Sys_Buttons /// <param name="id">主键编号</param> /// </summary> [OperationContract] Sys_Buttons GetSys_ButtonsById(int id); /// <summary> ///修改实体Sys_Buttons /// <param name="entity">Sys_Buttons实体</param> /// </summary> [OperationContract] bool UpdateSys_Buttons(Sys_Buttons entity); /// <summary> ///新增实体Sys_Buttons /// <param name="entity">Sys_Buttons实体</param> /// </summary> [OperationContract] bool CreateSys_Buttons(Sys_Buttons entity); /// <summary> ///删除Sys_Buttons /// <param name="id">主键编号</param> /// </summary> [OperationContract] bool DeleteSys_Buttons(int id); [OperationContract] IQueryable<Sys_WholeMenuButtons> GetSys_WholeMenuButtonsBySql(string sql, params CmdParameter[] obj); /// <summary> ///根据SQL语句查询返回IQueryableSys_Buttons /// <param name="sql">Sys_ButtonsSQL语句</param> /// </summary> [OperationContract] IQueryable<Sys_Buttons> GetSys_ButtonsBySql(string sql, params CmdParameter[] obj); /// <summary> /// 返回菜单的按钮 /// </summary> /// <param name="menuId">菜单编号</param> /// <returns></returns> [OperationContract] List<TWholeMenuButton> GetTWholeMenuButtons(string menuId); /// <summary> /// 返回所有的菜单信息 /// </summary> /// <returns></returns> [OperationContract] List<TWholeMenuButton> GetTWholeMenuButtonsAllList(); /// <summary> /// 获取对应的权限 /// </summary> /// <param name="operatorId">操作员ID</param> /// <returns></returns> [OperationContract] List<TWholeMenuButton> GetButtonLimitsAlList(string operatorId); /// <summary> /// 获取对应的权限 /// </summary> /// <param name="roleId">角色ID</param> /// <returns></returns> [OperationContract] List<TWholeMenuButton> GetButtonLimitstRoleAllList(string roleId); /// <summary> ///新增实体Sys_WholeMenuButtons /// <param name="entity">Sys_WholeMenuButtons实体</param> /// </summary> [OperationContract] bool CreateSys_WholeMenuButtons(List<Sys_WholeMenuButtons> entity); /// <summary> ///删除Sys_WholeMenuButtons /// <param name="nodeid">主键编号</param> /// </summary> [OperationContract] bool DeleteSys_WholeMenuButtons(string nodeid); /// <summary> /// 根据用户获取项目权限 /// </summary> /// <param name="operatorId">操作员编号</param> /// <returns></returns> [OperationContract] IQueryable<ProjectsLimits> GetProjectsLimitsesByOperator(string operatorId); /// <summary> /// 根据用户编号获取对应的线程里程信息 /// </summary> /// <param name="operatorId">操作员编号</param> /// <param name="projectKey">项目编号</param> /// <returns></returns> [OperationContract] IEnumerable<LineMileageLimits> GetLineMileageLimitsesByOperator(string operatorId, string projectKey); #endregion
}
3、服务契约实现
服务类代码
//服务 /// <summary> /// Class OperationService. /// </summary> [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class OperationService : IOperationpurviewService, IDisposable { private readonly RBIM5D_PROJECTContext _dbContext; public OperationService() { _dbContext = new RBIM5D_PROJECTEntities(); }
#region 操作人员管理 public bool InsertOperatorInfo(T_Operator operatorEntity) { try { _dbContext.Set<T_Operator>().Attach(operatorEntity); _dbContext.Set<T_Operator>().Add(operatorEntity); _dbContext.SaveChanges(); } catch (DbEntityValidationException ex) { throw ex.InnerException; } catch (DbException ee) { throw ee.InnerException; } return true; } /// <summary> /// 修改操作T_Operator /// </summary> /// <param name="model">The model.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public bool UpdateT_Operator(T_Operator model) { try { var category = _dbContext.T_Operator.FirstOrDefault(o => o.OperatorID == model.OperatorID); if (category != null) { category.OperatorID = model.OperatorID; category.DepID = model.DepID; category.OperatorName = model.OperatorName; category.Passwrod = model.Passwrod; category.RoleID = model.RoleID; category.UserID = model.UserID; category.CellPhone = model.CellPhone; category.Emial = model.Emial; category.State = model.State; category.EditMan = model.EditMan; category.EditDate = model.EditDate; } _dbContext.SaveChanges(); } catch (EntityException) { return false; } catch (Exception) { return false; } return true; } /// <summary> /// 修改操作T_Operator /// </summary> /// <param name="operatorid">The operatorid.</param> /// <returns>T_Operator.</returns> public T_Operator T_OperatorById(string operatorid) { try { return _dbContext.Set<T_Operator>().FirstOrDefault(o => o.OperatorID == operatorid && o.State == 0); } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> /// 删除操作T_Operator /// </summary> /// <param name="id">The identifier.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public bool DeleteT_Operator(string id) { try { T_Operator category = _dbContext.T_Operator.First(o => o.OperatorID == id); return LU.DAL.BaseDAL<T_Operator>.ManagerContent(_dbContext).Del(category); } catch (EntityException) { return false; } catch (Exception) { return false; } } /// <summary> /// Gets the maximum operator identifier. /// </summary> /// <returns>System.Int32.</returns> public int GetMaxOperatorId() { try { const string strsql = "select max(Convert(int,OperatorID)) from T_Operator"; return _dbContext.Database.SqlQuery<int>(strsql).First(); } catch (Exception ee) { throw ee.InnerException; } } public IQueryable<T_Operator> GetOperatorAllList() { try { return _dbContext.T_Operator.Where(o => o.State == 0); } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> /// Gets the right operator by operator identifier. /// </summary> /// <param name="operatorid">The operatorid.</param> /// <returns>List<FindMenuRigthByOperator>.</returns> public List<FindMenuRigthByOperator> GetRightOperatorByOperatorId(string operatorid) { try { var list = new List<FindMenuRigthByOperator>(); { var query = from a in _dbContext.T_Operator_Privilege join b in _dbContext.T_WholeMenu on a.NodeId equals b.NodeId where a.OperatorID == operatorid select new { a.OperatorID, ParentNode1 = a.ParentNode, a.NodeId, a.IsEndNode, a.PrivId, a.IsToolBar, a.BarOrder, a.BarCaption, b.NodeName, b.ParentNode, b.PluginId, b.CommentAry, b.Disporder, b.Type, b.GroupByName, b.ImageIco, b.TypeShow, b.IsStartUp }; if (query.Any()) { list.AddRange(query.ToList().Select(item => new FindMenuRigthByOperator { BarCaption = item.BarCaption, BarOrder = item.BarOrder, CommentAry = item.CommentAry, IsEndNode = item.IsEndNode, IsToolBar = item.IsToolBar, NodeId = item.NodeId, NodeName = item.NodeName, ParentNode1 = item.ParentNode1, ParentNode = item.ParentNode, PluginId = item.PluginId, PrivId = item.PrivId, GroupByName = item.GroupByName, ImageIco = item.ImageIco, TypeShow = item.TypeShow, IsStartUp = item.IsStartUp, })); } } return list; } catch (EntityException e) { throw e.InnerException; } } /// <summary> /// Gets the right operator by role identifier. /// </summary> /// <param name="roleid">The roleid.</param> /// <returns>List<FindMenuRigthByOperator>.</returns> public List<FindMenuRigthByOperator> GetRightOperatorByRoleId(string roleid) { try { var list = new List<FindMenuRigthByOperator>(); { var query = from a in _dbContext.T_Role_Privilege join b in _dbContext.T_WholeMenu on a.NodeID equals b.NodeId where a.RoleId == roleid select new { a.RoleId, ParentNode1 = a.ParentNode, a.NodeID, a.IsEndNode, a.Privid, a.IsToolBar, a.BarOrder, a.BarCaption, b.NodeName, b.ParentNode, b.PluginId, b.CommentAry, b.Disporder, b.Type, b.GroupByName, b.ImageIco, b.TypeShow, b.IsStartUp }; if (query.Any()) { list.AddRange(query.ToList().Select(item => new FindMenuRigthByOperator { BarCaption = item.BarCaption, BarOrder = item.BarOrder, CommentAry = item.CommentAry, IsEndNode = item.IsEndNode, IsToolBar = item.IsToolBar, NodeId = item.NodeID, NodeName = item.NodeName, ParentNode1 = item.ParentNode1, ParentNode = item.ParentNode, PluginId = item.PluginId, PrivId = item.Privid, GroupByName = item.GroupByName, ImageIco = item.ImageIco, TypeShow = item.TypeShow, IsStartUp = item.IsStartUp })); } } return list; } catch (EntityException e) { throw e.InnerException; } } /// <summary> /// 用户登录 /// </summary> /// <param name="loginUserName">登录名称</param> /// <param name="loginPassword">登录密码</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public bool LoginUser(string loginUserName, string loginPassword) { if (string.IsNullOrEmpty(loginUserName) || string.IsNullOrEmpty(loginPassword)) return false; try { // ReSharper disable ImplicitlyCapturedClosure var queryExits = _dbContext.T_Operator.Where(o => o.OperatorID == loginUserName); // ReSharper restore ImplicitlyCapturedClosure if (queryExits.Any()) { string password = EncodeHelper.DesEncrypt(loginPassword); var queryLogin = _dbContext.T_Operator.Where(o => o.OperatorID == loginUserName && o.Passwrod == password); if (queryLogin.Any()) { var firstOrDefault = queryLogin.FirstOrDefault(); if (firstOrDefault != null) OperatorAddLoginCount(firstOrDefault); return true; } return false; } } catch (EntityException) { return false; } return false; } /// <summary> /// 用户登录 /// </summary> /// <param name="loginUserName">登录名称</param> /// <param name="loginPassword">登录密码</param> /// <param name="log">登录其它信息</param> /// <returns>返回字符串信息</returns> public string Login(string loginUserName, string loginPassword, params string[] log) { if (string.IsNullOrEmpty(loginUserName) || string.IsNullOrEmpty(loginPassword)) return "用户或密码不能为空!谢谢"; try { T_Operator queryExits = _dbContext.T_Operator.FirstOrDefault(o => o.OperatorID == loginUserName); if (queryExits != null) { if (queryExits.State == 0) { string password = EncodeHelper.DesEncrypt(loginPassword); var queryLogin = _dbContext.T_Operator.FirstOrDefault(o => o.OperatorID == loginUserName && o.Passwrod == password); if (queryLogin != null) { OperatorAddLoginCount(queryLogin); return "success"; } return "密码与当前用户不匹配!请从新尝试!"; } return "尊敬的用户您好!您的账户已经锁定或无效!请联系系统管理员!谢谢"; } return "系统中没有查找到该用户!请查看用户名称是否正确!谢谢"; } catch (EntityException ex) { LogHelper.Info("用户登录", ex); return "服务端数据库打开无法连接!请联系系统管理!谢谢"; } catch (Exception ex) { LogHelper.Info("用户登录", ex); return "登录失败!"; } } /// <summary> /// 用户登陆 /// </summary> /// <param name="loginUserName">Name of the login user.</param> /// <param name="loginPassword">The login password.</param> /// <param name="log">The log.</param> /// <returns>用户信息.</returns> public T_Operator LoginOperator(string loginUserName, string loginPassword, params string[] log) { if (string.IsNullOrEmpty(loginUserName) || string.IsNullOrEmpty(loginPassword)) return null; try { string loginUser = loginUserName.ToLower(); T_Operator queryExits = _dbContext.T_Operator.FirstOrDefault(o => o.OperatorID.ToLower() == loginUser || o.UserID.ToLower() == loginUser); if (queryExits != null) { if (queryExits.State == 0) { string password = EncodeHelper.DesEncrypt(loginPassword); if (queryExits.Passwrod == password) { OperatorAddLoginCount(queryExits); return queryExits; } } } return null; } catch (EntityException ex) { LogHelper.Info("用户登录", ex); throw ex; } catch (Exception ex) { LogHelper.Info("用户登录", ex); throw ex; } } /// <summary> /// 用户登录次数添加 /// </summary> /// <param name="operatorId">操作员ID</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public bool OperatorAddLoginCount(T_Operator operatorId) { if (operatorId != null) { _dbContext.Sys_logs.Add(new Sys_logs { BusinessName = "用户登录", OperationIp = operatorId.OperatorID, OperationTime = DateTime.Now }); operatorId.LoginCount = operatorId.LoginCount == null ? 0 : operatorId.LoginCount + 1; operatorId.LastLoginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } _dbContext.SaveChanges(); return false; } /// <summary> /// 获取人员信息 /// </summary> /// <param name="departId">以部门编号</param> /// <returns>List<T_Operator>.</returns> public List<T_Operator> GetOperatorListByDepartId(string departId) { try { return _dbContext.Set<T_Operator>().Where(@operator => @operator.DepID == departId).ToList(); } catch (EntityException e) { throw e.InnerException; } } /// <summary> /// 判斷用戶登陸名稱是否存在 /// Determines whether [is existe login user name] [the specified login user name]. /// </summary> /// <param name="loginUserName">Name of the login user.</param> /// <returns><c>true</c> if [is existe login user name] [the specified login user name]; otherwise, <c>false</c>.</returns> public bool IsExisteLoginUserName(string loginUserName) { T_Operator tOperator = _dbContext.T_Operator.FirstOrDefault(o => o.UserID == loginUserName); if (tOperator != null) return true; return false; } /// <summary> /// Gets the toperators by role identifier. /// </summary> /// <param name="roleid">The roleid.</param> /// <returns>List<T_Operator>.</returns> List<T_Operator> GetToperatorsByRoleId(string roleid) { try { return _dbContext.Set<T_Operator>().Where(o => o.RoleID == roleid).ToList(); } catch (SqlException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> /// 修改用户密码 /// </summary> /// <param name="oldPwd">旧的用户密码</param> /// <param name="newPwd">新的用户密码</param> /// <param name="userid">用户人员编号</param> /// <returns>System.String.</returns> public string ChangeUserPwd(string oldPwd, string newPwd, string userid) { string password = EncodeHelper.DesEncrypt(oldPwd); var istrue = _dbContext.T_Operator.FirstOrDefault(o => o.OperatorID == userid && o.Passwrod == password); if (istrue != null) { istrue.Passwrod = EncodeHelper.DesEncrypt(newPwd); _dbContext.SaveChanges(); } else { return "当前的用户密码不正确!"; } return "成功"; } #endregion
#region 用户权限管理 public void InsertOperatorPrivilegeInfo(T_Operator_Privilege operatorEntity) { try { // _enity.Attach(operatorEntity); _dbContext.Set<T_Operator_Privilege>().Add(operatorEntity); // _enity.ObjectStateManager.ChangeObjectState(operatorEntity, EntityState.Added); _dbContext.SaveChanges(); } catch (Exception ee) { throw ee.InnerException; } } public void DeleteOperatorPrivilegeInfoByOperatorId(string operatorid) { try { // _enity.ExecuteStoreCommand("delete from T_Operator_Privilege where Operatorid=@operatorids", new SqlParameter("@operatorids", operatorid)); var rsult = from fx in _dbContext.T_Operator_Privilege where fx.OperatorID == operatorid select fx; if (rsult.Any()) { foreach (var privilege in rsult) { _dbContext.T_Operator_Privilege.Remove(privilege); } _dbContext.SaveChanges(); } } catch (Exception ee) { throw ee.InnerException; } } #endregion
#region 用户角色 //新增角色 public bool InsertRoleInfo(T_Role roleEntity) { try { _dbContext.T_Role.Add(roleEntity); _dbContext.SaveChanges(); return true; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public T_Role T_RoleById(string roleid) { try { return _dbContext.Set<T_Role>().FirstOrDefault(o => o.RoleId == roleid && o.CodeNo == "有效"); } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } ///<summary> ///修改操作T_Role /// </summary> public bool UpdateT_Role(T_Role model) { try { var category = _dbContext.T_Role.FirstOrDefault(o => o.RoleId == model.RoleId); if (category != null) { category.RoleId = model.RoleId; category.RoleName = model.RoleName; category.CommentAry = model.CommentAry; category.CodeNo = model.CodeNo; category.CustomNo = model.CustomNo; category.SpellNo = model.SpellNo; category.StrokeNo = model.StrokeNo; } _dbContext.SaveChanges(); } catch (EntityException) { return false; } catch (Exception) { return false; } return true; } ///<summary> ///删除操作T_Role /// </summary> public bool DeleteT_Role(string model) { try { var category = _dbContext.T_Role.Where(o => o.RoleId == model); if (category.Any()) { foreach (var item in category) { _dbContext.Set<T_Role>().Attach(item); _dbContext.Set<T_Role>().Remove(item); } _dbContext.SaveChanges(); } } catch (EntityException) { return false; } catch (Exception) { return false; } return true; } //返回角色权限信息 public List<FindRoleRigthByRole> GetRoleRigthByRoleCode(string roleCode) { var list = new List<FindRoleRigthByRole>(); var query = from a in _dbContext.T_Role_Privilege join b in _dbContext.T_WholeMenu on a.NodeID equals b.NodeId where a.RoleId == roleCode select new { a.RoleId, ParentNode1 = a.ParentNode, a.NodeID, a.IsEndNode, a.Privid, a.IsToolBar, a.BarOrder, a.BarCaption, b.NodeName, b.ParentNode, b.PluginId, b.CommentAry, b.Disporder, b.Type, b.GroupByName, b.ImageIco, b.TypeShow }; if (query.Any()) { list.AddRange(query.ToList().Select(item => new FindRoleRigthByRole { BarCaption = item.BarCaption, BarOrder = item.BarOrder, CommentAry = item.CommentAry, IsEndNode = item.IsEndNode, IsToolBar = item.IsToolBar, NodeID = item.NodeID, NodeName = item.NodeName, ParentNode1 = item.ParentNode1, ParentNode = item.ParentNode, PluginId = item.PluginId, Privid = item.Privid, GroupByName = item.GroupByName, ImageIco = item.ImageIco, TypeShow = item.TypeShow, Disporder = item.Disporder })); } return list; } public List<T_Role> GetRoleAllList() { try { return (from fx in _dbContext.T_Role select fx).ToList(); } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public int GetMaxRoleId() { try { const string strsql = "select max(Convert(int,Roleid)) from T_Role"; return _dbContext.Database.SqlQuery<int>(strsql).FirstOrDefault(); } catch (Exception ee) { throw ee.InnerException; } } #endregion
#region 用户角色权限管理 public void InsertTRolePrivilege(T_Role_Privilege roleEntity) { // _enity.Attach(roleEntity); try { _dbContext.T_Role_Privilege.Add(roleEntity); // _enity.ObjectStateManager.ChangeObjectState(roleEntity, EntityState.Added); _dbContext.SaveChanges(); } catch (Exception ee) { throw ee.InnerException; } } public void DeleteRolePrivilegeByRoleId(string roleid) { try { _dbContext.Database.ExecuteSqlCommand("delete from T_Role_Privilege where roleid=@roleid", new SqlParameter("@roleid", roleid)); } catch (Exception ee) { throw ee.InnerException; } } public bool AddProjectLimits(List<T_ProjectLimits> projectLimitses, string typeinfo, string typeid) { try { switch (typeinfo) { case "Operator": string strsql = "delete from T_ProjectLimits where F_OperatorID=@Opid"; SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@Opid", typeid) }; _dbContext.Database.ExecuteSqlCommand(strsql, parms); _dbContext.Set<T_ProjectLimits>().AddRange(projectLimitses); break; case "Role": string sqlrole = "delete from T_ProjectLimits where F_RoleId=@Opid"; SqlParameter[] parmsrole = new SqlParameter[] { new SqlParameter("@Opid", typeid) }; _dbContext.Database.ExecuteSqlCommand(sqlrole, parmsrole); //获取该角色的操作员 DataTable opDt = Untity.ListToDataTable(GetToperatorsByRoleId(typeid)); if (opDt.Rows.Count > 0) { foreach (DataRow rows in opDt.Rows) { string strsqloperator = "delete from T_ProjectLimits where F_OperatorID=@optUser"; SqlParameter[] parmsoperator = new SqlParameter[] { new SqlParameter("@optUser", rows["OperatorId"]) }; _dbContext.Database.ExecuteSqlCommand(strsqloperator, parmsoperator); } } foreach (var item in projectLimitses) { //添加角色信息 item.F_RoleId = typeid; item.F_OperatorID = ""; _dbContext.Set<T_ProjectLimits>().Add(item); foreach (DataRow rows in opDt.Rows) { T_ProjectLimits tp=new T_ProjectLimits() { F_ItemKey = item.F_ItemKey, F_ItemText = item.F_ItemText, F_OperatorID = rows["OperatorId"].ToString(), F_RoleId = typeid, F_SortId = item.F_SortId }; _dbContext.Set<T_ProjectLimits>().Add(tp); } } break; } _dbContext.SaveChanges(); return true; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException exception) { throw exception.InnerException; } } public bool AddOrgizationLimits(List<T_Organization_Privilege> organizationPrivileges, string typeinfo, string typeid) { try { switch (typeinfo) { case "Operator": string strsql = "delete from T_Organization_Privilege where F_OperatorId=@Opid"; SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@Opid", typeid) }; _dbContext.Database.ExecuteSqlCommand(strsql, parms); _dbContext.Set<T_Organization_Privilege>().AddRange(organizationPrivileges); break; case "Role": string sqlrole = "delete from T_Organization_Privilege where F_RoleId=@Opid"; SqlParameter[] parmsrole = new SqlParameter[] { new SqlParameter("@Opid", typeid) }; _dbContext.Database.ExecuteSqlCommand(sqlrole, parmsrole); //获取该角色的操作员 DataTable opDt = Untity.ListToDataTable(GetToperatorsByRoleId(typeid)); if (opDt.Rows.Count > 0) { foreach (DataRow rows in opDt.Rows) { string strsqloperator = "delete from T_Organization_Privilege where F_OperatorId=@optUser"; SqlParameter[] parmsoperator = new SqlParameter[] { new SqlParameter("@optUser", rows["OperatorId"]) }; _dbContext.Database.ExecuteSqlCommand(strsqloperator, parmsoperator); } } foreach (var item in organizationPrivileges) { //添加角色信息 item.F_OperatorId = ""; item.F_RoleId = typeid; _dbContext.Set<T_Organization_Privilege>().Add(item); foreach (DataRow rows in opDt.Rows) { T_Organization_Privilege tOrg=new T_Organization_Privilege() { F_KeyId = item.F_KeyId, F_OperatorId = rows["OperatorId"].ToString(), F_OrgID = item.F_OrgID, F_OrgName = item.F_OrgName, F_RoleId = typeid, F_ParentId = item.F_ParentId }; _dbContext.Set<T_Organization_Privilege>().Add(tOrg); } } break; } _dbContext.SaveChanges(); return true; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException exception) { throw exception.InnerException; } } public bool AddLineMileageLimits(List<LineMileage_Privilege> organizationPrivileges, string typeinfo, string typeid) { try { switch (typeinfo) { case "Operator": string strsql = "delete from LineMileage_Privilege where OperatorId=@Opid"; SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@Opid", typeid) }; _dbContext.Database.ExecuteSqlCommand(strsql, parms); _dbContext.Set<LineMileage_Privilege>().AddRange(organizationPrivileges); _dbContext.SaveChanges(); break; case "Role": string sqlrole = "delete from LineMileage_Privilege where RoleId=@Opid"; SqlParameter[] parmsrole = new SqlParameter[] { new SqlParameter("@Opid", typeid) }; _dbContext.Database.ExecuteSqlCommand(sqlrole, parmsrole); //获取该角色的操作员 DataTable opDt = Untity.ListToDataTable(GetToperatorsByRoleId(typeid)); if (opDt.Rows.Count > 0) { foreach (DataRow rows in opDt.Rows) { string strsqloperator = "delete from LineMileage_Privilege where OperatorId=@optUser"; SqlParameter[] parmsoperator = new SqlParameter[] { new SqlParameter("@optUser", rows["OperatorId"]) }; _dbContext.Database.ExecuteSqlCommand(strsqloperator, parmsoperator); } } foreach (var item in organizationPrivileges) { //添加角色信息 item.RoleId = typeid; item.OperatorId = ""; _dbContext.Set<LineMileage_Privilege>().Add(item); foreach (DataRow rows in opDt.Rows) { LineMileage_Privilege line = new LineMileage_Privilege() { MileageId = item.MileageId, MileageName = item.MileageName, NodeId = item.NodeId, OperatorId = rows["OperatorId"].ToString(), RoleId = typeid }; _dbContext.Set<LineMileage_Privilege>().Add(line); } } _dbContext.SaveChanges(); break; } return true; } catch (DbEntityValidationException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException exception) { throw exception.InnerException; } } #endregion
#region 菜单管理 public void InsertTWholemenu(T_WholeMenu menuEntity) { try { _dbContext.Set<T_WholeMenu>().Add(menuEntity); _dbContext.SaveChanges(); } catch (Exception ee) { throw ee.InnerException; } } public bool UpdateTWholeMenu(T_WholeMenu menuEntity) { try { var category = _dbContext.T_WholeMenu.FirstOrDefault(o => o.NodeId == menuEntity.NodeId); if (category != null) { category.NodeId = menuEntity.NodeId; category.NodeName = menuEntity.NodeName; category.ParentNode = menuEntity.ParentNode; category.IsEndNode = menuEntity.IsEndNode; category.PluginId = menuEntity.PluginId; category.CommentAry = menuEntity.CommentAry; category.Disporder = menuEntity.Disporder; category.Type = menuEntity.Type; category.GroupByName = menuEntity.GroupByName; category.ImageIco = menuEntity.ImageIco; category.TypeShow = menuEntity.TypeShow; category.IsStartUp = menuEntity.IsStartUp; } _dbContext.SaveChanges(); } catch (Exception ee) { throw ee.InnerException; } return true; } public List<T_WholeMenu> GetAllWholeMenuList() { try { var query = from fx in _dbContext.T_WholeMenu select fx; return query.ToList(); } catch (EntityException ex) { LogHelper.Error("GetAllWholeMenuList",ex); throw ex.InnerException; } } public int GetTwholeMenuNodeId() { try { var category = _dbContext.T_WholeMenu.Where(o => o.NodeId.Length == 2).Max(o => o.NodeId); return Convert.ToInt32(category); } catch (EntityException ex) { LogHelper.Error("GetTwholeMenuNodeId", ex); throw ex.InnerException; } } public int GetTWholeMenuNodeChildrenId() { try { var category = _dbContext.T_WholeMenu.Where(o => o.NodeId.Length > 3).Max(o => o.NodeId); return Convert.ToInt32(category); } catch (EntityException ex) { LogHelper.Error("GetTWholeMenuNodeChildrenId", ex); throw ex.InnerException; } } public int GetMaxWholeMenuId(string parentnode) { try { var category = _dbContext.T_WholeMenu.Where (o => o.ParentNode == parentnode).Max(o => o.NodeId); return Convert.ToInt32(category); } catch (EntityException ex) { LogHelper.Error("GetMaxWholeMenuId", ex); throw ex.InnerException; } } //多级菜单删除 public void DeleteWholeMenu(string parentid) { try { var catetory = _dbContext.T_WholeMenu.Where(o => o.ParentNode == parentid); if (catetory.Any()) { foreach (var item in catetory) { T_WholeMenu itemTwhole = item; var queryReslut = _dbContext.T_WholeMenu.Where(o => o.ParentNode == itemTwhole.NodeId);//查询该菜单下面是否有子菜单 if (queryReslut.Any()) { foreach (var wholeMenu in queryReslut) { T_WholeMenu menu = wholeMenu; var queryRm = _dbContext.T_WholeMenu.Where(o => o.ParentNode == menu.NodeId); if (queryRm.Any()) { foreach (var itemMenu in queryRm) { _dbContext.T_WholeMenu.Remove(itemMenu); } } _dbContext.T_WholeMenu.Remove(wholeMenu); } } _dbContext.T_WholeMenu.Remove(item); } _dbContext.SaveChanges(); } } catch (InvalidOperationException e) { Console.WriteLine(e); } catch (Exception ee) { throw ee.InnerException; } } public void DeleteWholeMenuNode(string nodeid) { try { var catetory = _dbContext.T_WholeMenu.Where(o => o.NodeId == nodeid); if (catetory.Any()) { foreach (var item in catetory) { _dbContext.Set<T_WholeMenu>().Attach(item); _dbContext.Set<T_WholeMenu>().Remove(item); } _dbContext.SaveChanges(); } } catch (InvalidOperationException e) { Console.WriteLine(e); } catch (Exception ee) { throw ee.InnerException; } } /// <summary> /// 保存用户权限 /// </summary> /// <param name="dt">DataTable 数据源</param> /// <param name="type">类型</param> /// <param name="typeid">RoleId或OperatorId</param> /// <returns></returns> public bool AddUserRight(DataTable dt, string type, string typeid) { try { switch (type) { #region Role case "Role": //删除该角色所有的权限 DeleteRolePrivilegeByRoleId(typeid); _dbContext.Sys_Button_Privilege.RemoveRange(_dbContext.Sys_Button_Privilege.Where(o => o.RoleId == typeid)); _dbContext.SaveChanges(); //获取该角色的操作员 DataTable opDt = Untity.ListToDataTable(GetToperatorsByRoleId(typeid)); if (opDt.Rows.Count > 0) { foreach (DataRow row in opDt.Rows) { //删除该角色对应操作员权限信息 DeleteOperatorPrivilegeInfoByOperatorId(row["OperatorId"].ToString()); RemoveSysButtonsPrivilege(row); } } foreach (DataRow roleRow in dt.Select(" Isendnode='menu'")) { if (roleRow.RowState == DataRowState.Deleted) continue; //创建对象 var roleData = new T_Role_Privilege { BarCaption = roleRow["NodeName"].ToString(), BarOrder = 0, IsEndNode = roleRow["IsendNode"].ToString(), NodeID = roleRow["NodeId"].ToString(), ParentNode = roleRow["ParentNode"].ToString(), Privid = roleRow["NodeId"].ToString(), RoleId = typeid, IsToolBar = 0 }; //插入新的角色权限信息 // rolePrivilege.InsertTRolePrivilege(roleData); InsertTRolePrivilege(roleData); foreach (DataRow opRow in opDt.Rows) { var operData = new T_Operator_Privilege { BarCaption = roleRow["NodeName"].ToString(), BarOrder = 0, IsEndNode = roleRow["IsendNode"].ToString(), NodeId = roleRow["NodeId"].ToString(), ParentNode = roleRow["ParentNode"].ToString(), PrivId = roleRow["NodeId"].ToString(), OperatorID = opRow["Operatorid"].ToString(), IsToolBar = 0 }; //插入新的该角色操作员权限信息 InsertOperatorPrivilegeInfo(operData); } } foreach (DataRow rows in dt.Select(" Isendnode='button'")) { if (rows.RowState == DataRowState.Deleted) continue; //newRow["Nodeid"] = rowbutton.KeyId; //newRow["ParentNode"] = rowbutton.MenuId; //newRow["NodeName"] = rowbutton.ButtonCaption; //newRow["Isendnode"] = "button"; //newRow["Disporder"] = rowbutton.ButtonId; var opData = new Sys_Button_Privilege(); if (rows["Disporder"] != null) { opData.ButtonId = Convert.ToInt32(rows["Disporder"]); } opData.RoleId = typeid; string nodeid = rows["Nodeid"].ToString(); if (nodeid.Length == 1) { nodeid = nodeid.PadLeft(2, '0'); } opData.NodeId = nodeid; _dbContext.Set<Sys_Button_Privilege>().Add(opData); foreach (DataRow opRow in opDt.Rows) { var opData2 = new Sys_Button_Privilege(); if (rows["Disporder"] != null) { opData2.ButtonId = Convert.ToInt32(rows["Disporder"]); } opData2.RoleId = typeid; opData2.OperatorId = opRow["OperatorId"].ToString(); opData2.NodeId = nodeid; _dbContext.Set<Sys_Button_Privilege>().Add(opData2); } } _dbContext.SaveChanges(); break; #endregion #region Operator case "Operator": //删除该操作员权限信息 try { DeleteOperatorPrivilegeInfoByOperatorId(typeid); _dbContext.Sys_Button_Privilege.RemoveRange( _dbContext.Sys_Button_Privilege.Where(o => o.OperatorId == typeid)); _dbContext.SaveChanges(); } catch (Exception) { return false; } foreach (DataRow rows in dt.Select(" Isendnode='menu'")) { if (rows.RowState == DataRowState.Deleted) continue; var opData = new T_Operator_Privilege { BarCaption = rows["NodeName"].ToString(), BarOrder = 0, IsEndNode = rows["Isendnode"].ToString(), IsToolBar = 0, NodeId = rows["Nodeid"].ToString(), ParentNode = rows["Parentnode"].ToString(), PrivId = rows["Nodeid"].ToString(), OperatorID = typeid }; //插入该操作员权限信息 InsertOperatorPrivilegeInfo(opData); } foreach (DataRow rows in dt.Select(" Isendnode='button'")) { if (rows.RowState == DataRowState.Deleted) continue; //newRow["Nodeid"] = rowbutton.KeyId; //newRow["ParentNode"] = rowbutton.MenuId; //newRow["NodeName"] = rowbutton.ButtonCaption; //newRow["Isendnode"] = "button"; //newRow["Disporder"] = rowbutton.ButtonId; var opData = new Sys_Button_Privilege(); if (rows["Disporder"] != null) { opData.ButtonId = Convert.ToInt32(rows["Disporder"]); } opData.OperatorId = typeid; string nodeid = rows["Nodeid"].ToString(); if (nodeid.Length == 1) { nodeid = nodeid.PadLeft(2, '0'); } opData.NodeId = nodeid; _dbContext.Set<Sys_Button_Privilege>().Add(opData); } _dbContext.SaveChanges(); break; #endregion } } catch (EntitySqlException) { return false; } catch (InvalidOperationException) { return false; } catch (EntityException) { return false; } catch (Exception ee) { throw ee.InnerException; } return true; } private void RemoveSysButtonsPrivilege(DataRow row) { try { string operatorId = row["OperatorId"].ToString(); var query = _dbContext.Sys_Button_Privilege.Where(o => o.OperatorId == operatorId); if (query.Any()) { _dbContext.Sys_Button_Privilege.RemoveRange(query); _dbContext.SaveChanges(); } } catch (EntityException ex) { LogHelper.Error("RemoveSysButtonsPrivilege", ex); throw ex.InnerException; } } #endregion
#region 系统字典 public bool InsertDectionary(T_DictionaryInfo tInfo) { try { if (!_dbContext.Set<T_DictionaryInfo>().Any(o => o.F_DictonaryCode == tInfo.F_DictonaryCode)) { _dbContext.Set<T_DictionaryInfo>().Add(tInfo); _dbContext.SaveChanges(); return true; } } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } return false; } public bool UpdateDectionary(T_DictionaryInfo tInfo) { try { var catetory = _dbContext.T_DictionaryInfo.First(o => o.F_DictonaryCode == tInfo.F_DictonaryCode); catetory.F_DictonaryCode = tInfo.F_DictonaryCode; catetory.F_DictonaryCoding = tInfo.F_DictonaryCoding; catetory.F_DictonaryName = tInfo.F_DictonaryName; catetory.F_DictonaryType = tInfo.F_DictonaryType; catetory.F_ParentDictonaryCode = tInfo.F_ParentDictonaryCode; catetory.F_Remark = tInfo.F_Remark; _dbContext.SaveChanges(); } catch (UpdateException exception) { throw exception.InnerException; } catch (EntityException exception) { throw exception.InnerException; } catch (Exception exception) { throw exception.InnerException; } return true; } public List<T_DictionaryInfo> GetAllDictonaryList() { try { List<T_DictionaryInfo> list = (from dictionaryInfo in _dbContext.T_DictionaryInfo select dictionaryInfo).ToList(); return list; } catch (Exception ee) { throw ee.InnerException; } } public List<T_DictionaryInfo> SearchDictionaryOfType(string fDictonaryCode) { var list = new List<T_DictionaryInfo>(); try { if (!string.IsNullOrEmpty(fDictonaryCode)) { list = (from dictionaryInfo in _dbContext.T_DictionaryInfo where dictionaryInfo.F_ParentDictonaryCode == fDictonaryCode select dictionaryInfo).ToList(); return list; } } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } return list; } public List<T_DictionaryInfo> SearchDictionaryOfTypeCode(string typeCode) { List<T_DictionaryInfo> list=new List<T_DictionaryInfo>(); try { if (!string.IsNullOrEmpty(typeCode)) { T_DictionaryInfo tDictionaryInfo= _dbContext.T_DictionaryInfo.FirstOrDefault(o=>o.F_DictonaryType==typeCode); if (tDictionaryInfo != null) { list = SearchDictionaryOfType(tDictionaryInfo.F_DictonaryCode); } } } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } return list; } public int GetMaxDictionaryParentCode() { try { var category = _dbContext.T_DictionaryInfo.Where(o => o.F_DictonaryCode.Length == 2).Max(o => o.F_DictonaryCode); return Convert.ToInt32(category); } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } } public int GetDictionaryNodeChildrenCode() { try { var category = _dbContext.T_DictionaryInfo.Where(o => o.F_DictonaryCode.Length > 3).Max(o => o.F_DictonaryCode); return Convert.ToInt32(category); } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } } public int GetMaxDictionaryCode(string parentCode) { try { var category = _dbContext.T_DictionaryInfo.Where (o => o.F_ParentDictonaryCode == parentCode).Max(o => o.F_DictonaryCode); return Convert.ToInt32(category); } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } } public bool DeleteDictionaryChildrenCode(string dictonaryCode) { try { var catetory = _dbContext.T_DictionaryInfo.Where(o => o.F_DictonaryCode == dictonaryCode); if (catetory.Any()) { foreach (var item in catetory) { _dbContext.Set<T_DictionaryInfo>().Attach(item); _dbContext.Set<T_DictionaryInfo>().Remove(item); } _dbContext.SaveChanges(); } } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } return true; } public bool DeleteDictonaryCode(string parnentdictonaryCode) { try { var catetory = _dbContext.T_DictionaryInfo.Where(o => o.F_ParentDictonaryCode == parnentdictonaryCode); if (catetory.Any()) { foreach (var item in catetory) { _dbContext.Set<T_DictionaryInfo>().Attach(item); _dbContext.Set<T_DictionaryInfo>().Remove(item); } _dbContext.SaveChanges(); } } catch (UpdateException) { return false; } catch (EntityException) { return false; } catch (Exception) { return false; } return true; } public DataTable GetAllTableNameByDb(string dataBaseName) { try { var retVal = new DataTable(); var sqlConn = (SqlConnection)_dbContext.Database.Connection; var cmdReport = new SqlCommand(string.Format("SELECT Name FROM {0}..SysObjects Where XType='U' ORDER BY Name", dataBaseName), sqlConn); var daReport = new SqlDataAdapter(cmdReport); using (cmdReport) { daReport.Fill(retVal); } retVal.TableName = "SystemTableName"; return retVal; } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } } public int GetDictionaryCountByParentCode(string parentCode) { try { var category = _dbContext.T_DictionaryInfo.Count(o => o.F_ParentDictonaryCode == parentCode); return Convert.ToInt32(category); } catch (UpdateException e) { throw e.InnerException; } catch (Exception ee) { throw ee.InnerException; } } public T_DictionaryInfo GetTDictonaryInfo(string dictonaryCode) { var query = (from fx in _dbContext.T_DictionaryInfo where fx.F_DictonaryCode.Equals(dictonaryCode) select fx).FirstOrDefault(); return query; } #endregion
#region 机构 ///<summary> ///新增操作T_Organization /// </summary> public bool InsertT_Organization(T_Organization model,string operatorId) { try { _dbContext.Set<T_Organization>().Add(model); //插入权限 _dbContext.Set<T_Organization_Privilege>().Add(new T_Organization_Privilege() { F_OperatorId =operatorId, F_OrgID = model.F_OrgID, F_OrgName = model.F_OrgName, F_ParentId = model.F_ParentID }); if (operatorId != "10000") { //插入超级管理员的权限 _dbContext.Set<T_Organization_Privilege>().Add(new T_Organization_Privilege() { F_OperatorId = "10000", F_OrgID = model.F_OrgID, F_OrgName = model.F_OrgName, F_ParentId = model.F_ParentID }); } _dbContext.SaveChanges(); } catch (EntityException) { return false; } catch (Exception) { return false; } return true; } ///<summary> ///修改操作T_Organization /// </summary> public bool UpdateT_Organization(T_Organization model) { try { var category = _dbContext.T_Organization.FirstOrDefault(o => o.F_OrgID == model.F_OrgID); if (category != null) { category.F_OrgID = model.F_OrgID; category.F_OrgName = model.F_OrgName; category.F_OrgManager = model.F_OrgManager; category.F_BuildDate = model.F_BuildDate; category.F_BuildMan = model.F_BuildMan; category.F_TellPhoneNum = model.F_TellPhoneNum; category.F_Address = model.F_Address; category.F_ParentID = model.F_ParentID; category.F_State = model.F_State; } // _enity.Entry(.State = EntityState.Modified; _dbContext.Entry(category).State = EntityState.Modified; //修改权限表 var privialeages = _dbContext.T_Organization_Privilege.Where(o => o.F_OrgID == model.F_OrgID); if (privialeages.Any()) { foreach (T_Organization_Privilege privialeage in privialeages) { privialeage.F_OrgName = model.F_OrgName; } } _dbContext.SaveChanges(); } catch (EntityException) { return false; } catch (Exception) { return false; } return true; } ///<summary> ///删除操作T_Organization /// </summary> public bool DeleteT_Organization(string modelCode) { try { var category = _dbContext.T_Organization.Where(o => o.F_OrgID == modelCode); if (category.Any()) { foreach (T_Organization item in category) { _dbContext.Set<T_Organization>().Attach(item); _dbContext.Set<T_Organization>().Remove(item); } _dbContext.SaveChanges(); } //删除权限表里面的信息 var privleages = _dbContext.T_Organization_Privilege.Where(o => o.F_OrgID == modelCode); if (privleages.Any()) { foreach (T_Organization_Privilege organization in privleages) { _dbContext.Set<T_Organization_Privilege>().Attach(organization); _dbContext.Set<T_Organization_Privilege>().Remove(organization); } _dbContext.SaveChanges(); } } catch (EntityException) { return false; } catch (Exception) { return false; } return true; } ///<summary> ///获取所有数据T_Organization /// </summary> public List<T_Organization> GetT_OrganizationListData() { try { return _dbContext.T_Organization.ToList(); } catch (EntityException exception) { throw exception.InnerException; } catch (Exception exception) { throw exception.InnerException; } } public IQueryable<T_Organization> GetT_OrganizationBy(string operatorId) { try { var query = _dbContext.T_Organization.Where(o => o.F_OrgID == operatorId); return query; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } #endregion
#region 机构数据权限 /// <summary> ///根据SQL语句查询返回IQueryableT_Organization_Privilege /// <param name="strsql">T_Organization_PrivilegeSQL语句</param> /// </summary> public IQueryable<T_Organization_Privilege> GetT_Organization_PrivilegeBySql(string strsql, params object[] obj) { try { IQueryable<T_Organization_Privilege> iQueryable = _dbContext.Database.SqlQuery<T_Organization_Privilege>(strsql, obj).AsQueryable(); return iQueryable; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public List<T_Organization_Privilege> GetT_Organization_PrivilegeById(string id) { try { return _dbContext.Set<T_Organization_Privilege>().Where(o => o.F_OperatorId == id).ToList(); } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException exception) { LogHelper.Error(exception.Message); throw exception.InnerException; } } public bool UpdateT_Organization_Privilege(List<T_Organization_Privilege> entity) { try { foreach (var operatorOrgPrivilege in entity) { new BaseDAL<T_Organization_Privilege>(_dbContext).Modify(operatorOrgPrivilege); } return true; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException exception) { throw exception.InnerException; } } public bool CreateT_Organization_Privilege(List<T_Organization_Privilege> entity, string operatorId) { try { string strsql = "delete from T_Organization_Privilege where F_OperatorId=@Opid"; SqlParameter[] parms = new SqlParameter[]{ new SqlParameter("@Opid",operatorId) }; _dbContext.Database.ExecuteSqlCommand(strsql, parms); foreach (var operatorOrgPrivilege in entity) { _dbContext.Set<T_Organization_Privilege>().Add(operatorOrgPrivilege); } _dbContext.SaveChanges(); return true; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException exception) { throw exception.InnerException; } } public bool CreateT_Organization_PrivilegeEntity(T_Organization_Privilege entity) { try { _dbContext.Set<T_Organization_Privilege>().Add(entity); _dbContext.SaveChanges(); return true; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException exception) { throw exception.InnerException; } } public bool DeleteT_Organization_Privilege(List<int> id) { try { foreach (var i in id) { new BaseDAL<T_Organization_Privilege>(_dbContext).DelBy(o => o.F_KeyId == i); } return true; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException exception) { throw exception.InnerException; } } /// <summary> ///获取实体LineMileage_Privilege /// <param name="id">主键编号</param> /// </summary> public LineMileage_Privilege GetLineMileage_PrivilegeById(string id) { try { return _dbContext.LineMileage_Privilege.FirstOrDefault(o => o.SysId == int.Parse(id)); } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> ///修改实体LineMileage_Privilege /// <param name="entity">LineMileage_Privilege实体</param> /// </summary> public bool UpdateLineMileage_Privilege(LineMileage_Privilege entity) { try { var category = _dbContext.LineMileage_Privilege.FirstOrDefault(o => o.SysId == entity.SysId); if (category != null) { category.SysId = entity.SysId; category.NodeId = entity.NodeId; category.OperatorId = entity.OperatorId; category.MileageId = entity.MileageId; _dbContext.SaveChanges(); } } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } return true; } /// <summary> ///新增实体LineMileage_Privilege /// <param name="entity">LineMileage_Privilege实体</param> /// </summary> public bool CreateLineMileage_Privilege(List<LineMileage_Privilege> entity, string operatorid) { try { string strsql = "delete from LineMileage_Privilege where Operatorid=@Opid"; SqlParameter[] parms = new SqlParameter[]{ new SqlParameter("@Opid",operatorid) }; _dbContext.Database.ExecuteSqlCommand(strsql, parms); foreach (var item in entity) { _dbContext.Set<LineMileage_Privilege>().Add(item); _dbContext.SaveChanges(); } return true; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> ///删除LineMileage_Privilege /// <param name="id">主键编号SysId</param> /// </summary> public bool DeleteLineMileage_Privilege(string id) { try { var category = _dbContext.LineMileage_Privilege.FirstOrDefault(o => o.SysId == int.Parse(id)); if (category != null) { _dbContext.Set<LineMileage_Privilege>().Attach(category); _dbContext.Set<LineMileage_Privilege>().Remove(category); _dbContext.SaveChanges(); } } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } return true; } public IQueryable<T_ProjectLimits> GetT_ProjectLimitsBySql(string strsql, params object[] obj) { try { IQueryable<T_ProjectLimits> iQueryable = _dbContext.Database.SqlQuery<T_ProjectLimits>(strsql, obj).AsQueryable(); return iQueryable; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> ///根据SQL语句查询返回IQueryableLineMileage_Privilege /// <param name="strsql">LineMileage_PrivilegeSQL语句</param> /// </summary> public IQueryable<LineMileage_Privilege> GetLineMileage_PrivilegeBySql(string strsql, params CmdParameter[] obj) { try { DbParameter[] parameters = new DbParameter[obj.Length]; for (int i = 0; i < obj.Length; i++) { DbParameter sqlPram = new SqlParameter(obj[i].ParameterName, obj[i].Value); parameters[i] = sqlPram; } IQueryable<LineMileage_Privilege> iQueryable = _dbContext.Database.SqlQuery<LineMileage_Privilege>(strsql, parameters).AsQueryable(); return iQueryable; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public bool CreateT_ProjectLimits_Privilege(List<T_ProjectLimits> entity, string operatorId) { try { string strsql = "delete from T_ProjectLimits where F_OperatorID=@Opid"; SqlParameter[] parms = new SqlParameter[]{ new SqlParameter("@Opid",operatorId) }; _dbContext.Database.ExecuteSqlCommand(strsql, parms); foreach (var item in entity) { _dbContext.Set<T_ProjectLimits>().Add(item); } _dbContext.SaveChanges(); return true; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public IQueryable<T_ProjectLimits> GetT_ProjectLimitsByOperator(string operatorid) { try { var query=_dbContext.T_ProjectLimits.Where(o => o.F_OperatorID == operatorid); return query; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } #endregion bn
#region 按钮服务 /// <summary> ///获取实体Sys_Buttons /// <param name="id">主键编号</param> /// </summary> public Sys_Buttons GetSys_ButtonsById(int id) { try { return _dbContext.Sys_Buttons.FirstOrDefault(o => o.KeyId == id); } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> ///修改实体Sys_Buttons /// <param name="entity">Sys_Buttons实体</param> /// </summary> public bool UpdateSys_Buttons(Sys_Buttons entity) { try { var category = _dbContext.Sys_Buttons.FirstOrDefault(o => o.KeyId == entity.KeyId); if (category != null) { category.KeyId = entity.KeyId; category.ButtonCaption = entity.ButtonCaption; category.Sortnum = entity.Sortnum; category.IconCls = entity.IconCls; category.IconUrl = entity.IconUrl; category.ButtonTag = entity.ButtonTag; category.Remark = entity.Remark; category.ButtonHtml = entity.ButtonHtml; category.BuggonGroup = entity.BuggonGroup; category.State = entity.State; category.ToolTip = entity.ToolTip; _dbContext.SaveChanges(); } } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } return true; } /// <summary> ///新增实体Sys_Buttons /// <param name="entity">Sys_Buttons实体</param> /// </summary> public bool CreateSys_Buttons(Sys_Buttons entity) { try { _dbContext.Set<Sys_Buttons>().Add(entity); _dbContext.SaveChanges(); return true; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> ///删除Sys_Buttons /// <param name="id">主键编号KeyId</param> /// </summary> public bool DeleteSys_Buttons(int id) { try { var category = _dbContext.Sys_Buttons.FirstOrDefault(o => o.KeyId == id); if (category != null) { _dbContext.Set<Sys_Buttons>().Attach(category); _dbContext.Set<Sys_Buttons>().Remove(category); _dbContext.SaveChanges(); } } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } return true; } public IQueryable<Sys_WholeMenuButtons> GetSys_WholeMenuButtonsBySql(string sql, params CmdParameter[] obj) { try { DbParameter[] parameters = new DbParameter[obj.Length]; for (int i = 0; i < obj.Length; i++) { DbParameter sqlPram = new SqlParameter(obj[i].ParameterName, obj[i].Value); parameters[i] = sqlPram; } IQueryable<Sys_WholeMenuButtons> iQueryable = _dbContext.Database.SqlQuery<Sys_WholeMenuButtons>(sql, parameters).AsQueryable(); return iQueryable; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> ///根据SQL语句查询返回IQueryableSys_Buttons /// <param name="sql">Sys_ButtonsSQL语句</param> /// </summary> public IQueryable<Sys_Buttons> GetSys_ButtonsBySql(string strsql, params CmdParameter[] obj) { try { DbParameter[] parameters = new DbParameter[obj.Length]; for (int i = 0; i < obj.Length; i++) { DbParameter sqlPram = new SqlParameter(obj[i].ParameterName, obj[i].Value); parameters[i] = sqlPram; } IQueryable<Sys_Buttons> iQueryable = _dbContext.Database.SqlQuery<Sys_Buttons>(strsql, parameters).AsQueryable(); return iQueryable; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public List<TWholeMenuButton> GetTWholeMenuButtons(string menuId) { try { var query = (from fx in _dbContext.Sys_WholeMenuButtons join fb in _dbContext.Sys_Buttons on fx.ButtonId equals fb.KeyId where fx.MenuId == menuId select new TWholeMenuButton { KeyId = fx.KeyId, MenuId = fx.MenuId, Sortnum = fx.Sortnum, ButtonCaption = fb.ButtonCaption, IconCls = fb.IconCls }).ToList(); return query; } catch (FormatException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public List<TWholeMenuButton> GetTWholeMenuButtonsAllList() { try { var queryResult = (from fx in _dbContext.Sys_Buttons join dx in _dbContext.Sys_WholeMenuButtons on fx.KeyId equals dx.ButtonId select new TWholeMenuButton() { KeyId = dx.KeyId, ButtonCaption = fx.ButtonCaption, ButtonId = fx.KeyId, IconCls = fx.IconCls, MenuId = dx.MenuId, Sortnum = dx.Sortnum }).ToList(); return queryResult; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public List<TWholeMenuButton> GetButtonLimitsAlList(string operatorId) { try { var queryResult = (from db in _dbContext.Sys_Buttons join fx in _dbContext.Sys_Button_Privilege on db.KeyId equals fx.ButtonId where fx.OperatorId == operatorId select new TWholeMenuButton() { KeyId = db.KeyId, ButtonId = db.KeyId, MenuId = fx.NodeId, ButtonCaption = db.ButtonCaption, OperatorId = operatorId }).ToList(); return queryResult; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public List<TWholeMenuButton> GetButtonLimitstRoleAllList(string roleId) { try { var queryResult = (from db in _dbContext.Sys_Buttons join fx in _dbContext.Sys_Button_Privilege on db.KeyId equals fx.ButtonId where fx.RoleId == roleId && fx.OperatorId == null || fx.OperatorId == "" select new TWholeMenuButton() { KeyId = db.KeyId, ButtonId = db.KeyId, MenuId = fx.NodeId, ButtonCaption = db.ButtonCaption, RoleId = roleId }).ToList(); return queryResult; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> ///新增实体Sys_WholeMenuButtons /// <param name="entity">Sys_WholeMenuButtons实体</param> /// </summary> public bool CreateSys_WholeMenuButtons(List<Sys_WholeMenuButtons> entity) { try { foreach (var item in entity) { _dbContext.Set<Sys_WholeMenuButtons>().Add(item); } _dbContext.SaveChanges(); return true; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } /// <summary> ///删除Sys_WholeMenuButtons /// <param name="nodeid">主键编号KeyId</param> /// </summary> public bool DeleteSys_WholeMenuButtons(string nodeid) { try { var category = _dbContext.Sys_WholeMenuButtons.Where(o => o.MenuId == nodeid); if (category.Any()) { foreach (var item in category) { _dbContext.Set<Sys_WholeMenuButtons>().Attach(item); _dbContext.Set<Sys_WholeMenuButtons>().Remove(item); } } _dbContext.SaveChanges(); } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } return true; } public IQueryable<ProjectsLimits> GetProjectsLimitsesByOperator(string operatorId) { try { var category = (from fx in _dbContext.T_ProjectLimits join db in _dbContext.RbimProject on fx.F_ItemKey equals db.ItemKey where fx.F_OperatorID == operatorId select new ProjectsLimits() { ProjectCode = db.ProjectCode, ItemKey = db.ItemKey, ItemText = fx.F_ItemText, OperatorId = operatorId, ProjectLocation = db.ProjectLocation, ProjectRemark = db.ProjectRemark, ProjectUrl = db.ProjectUrl, RoleId = fx.F_RoleId, SortId = fx.F_SortId }).AsQueryable(); return category; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } public IEnumerable<LineMileageLimits> GetLineMileageLimitsesByOperator(string operatorId, string projectKey) { try { var category = (from fx in _dbContext.LineMileage_Privilege join db in _dbContext.LineMileages on fx.MileageId equals db.MileageID.ToString() where fx.NodeId == projectKey && fx.OperatorId==operatorId select new LineMileageLimits() { SysId = fx.SysId, MileageId = fx.MileageId, MileageName = fx.MileageName, ProjectKey = fx.NodeId, ModelSizes = db.ModelSizes, ModelType = db.ModelType, NodeType = db.NodeType, OperatorId = fx.OperatorId, ParentMileageId = db.ParentMileageID, PlanPath = db.PlanPath, SortId = db.SortId, RelationModel = db.RelationModel, SOidModelFile = db.SOidModelFile }).AsEnumerable(); return category; } catch (EntityException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } catch (DbException ex) { LogHelper.Error(ex.Message); throw ex.InnerException; } } #endregion
public void Dispose() { var dispose = _dbContext as IDisposable; if (dispose != null) { _dbContext.Dispose(); } } }
4、WCF服务启动
public void ServiceStart() { try { string serviceport = ConfigurationManager.AppSettings["port"];// "8007"; string serviceIp = ConfigurationManager.AppSettings["serviceIp"];// "127.0.0.1"; string serviceAddress = string.Format("net.tcp://{0}:{1}", serviceIp, serviceport); var sevtypes = new Dictionary<Type, Type> { {typeof (IOperationpurviewService), typeof (OperationService)} }; foreach (var item in sevtypes) { string tName = item.Key.Name.Substring(1); string endpointAddress = serviceAddress + tName; if (!serviceAddress.EndsWith("/")) endpointAddress = string.Format("{0}/{1}", serviceAddress, tName); var serviceHost = new ServiceHost(item.Value, new Uri(endpointAddress)); //加载元数据结点 var smb = new ServiceMetadataBehavior(); serviceHost.Description.Behaviors.Add(smb); // serviceHost.Description.Behaviors.Add(new ServiceDebugBehavior(){IncludeExceptionDetailInFaults = true}); serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); //加载NetTcpBinding结点 var netTcpBinding = new NetTcpBinding { Security = { Mode = SecurityMode.None }, ReceiveTimeout = TimeSpan.Parse("10:59:00"), CloseTimeout = TimeSpan.Parse("10:59:00"), OpenTimeout = TimeSpan.Parse("10:59:00"), SendTimeout = TimeSpan.Parse("10:59:00"), MaxBufferPoolSize = long.MaxValue - 1, MaxBufferSize = int.MaxValue - 1, MaxReceivedMessageSize = int.MaxValue - 1, //MaxConnections = 1000, ReaderQuotas = { MaxDepth = int.MaxValue - 1, MaxStringContentLength = int.MaxValue - 1, MaxArrayLength = int.MaxValue - 1, MaxBytesPerRead = int.MaxValue - 1, MaxNameTableCharCount = int.MaxValue - 1 } // ,PortSharingEnabled = true //端口共享 }; serviceHost.AddServiceEndpoint(item.Key, netTcpBinding, endpointAddress); string address = endpointAddress; serviceHost.Opened += delegate { LoadPluginNameSpace.Add(new ServiceInfo() { Address = address + "/mex", Id = 0, State = "启动" }); }; serviceHost.Open(); ServiceHosts.Add(serviceHost); } } catch (ConfigurationException e) { Console.WriteLine(e); } catch (Exception ex) { throw ex; } }
5、WCF 注册Windows服务
internal class OperatorService : ServiceBase { private IContainer components = null; public ServiceHost serviceHost; public OperatorService() { this.InitializeComponent(); base.ServiceName= "LU.ServiceModule.OperationService"; } protected override void Dispose(bool disposing) { if (disposing && (this.components != null)) { this.components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { this.components = new Container(); base.ServiceName = "LU.ServiceModule.OperationService"; } protected override void OnStart(string[] args) { this.serviceHost = new ServiceHost(typeof(OperationService)); ServiceMetadataBehavior item = new ServiceMetadataBehavior(); this.serviceHost.Description.Behaviors.Add(item); this.serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); this.serviceHost.Opened += (param0, param1) => LogHelper.Info("OperationService is Starting!!!"); this.serviceHost.Open(); } protected override void OnStop() { if (this.serviceHost != null) { this.serviceHost.Abort(); } } }