/// <summary> /// 新增数据 /// </summary> /// <param name="RoleObj"></param> /// <returns></returns> public bool Add(tblMenu_Permission_Role tblMenu_Permission_RoleObj) { tblMenu_Permission_RoleObj.ID = System.Guid.NewGuid(); string userHostAddress = HttpContext.Current.Request.UserHostAddress; int counts = 0; //插入数据 try { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { MWDB.tblMenu_Permission_Role.AddObject(tblMenu_Permission_RoleObj); counts = MWDB.SaveChanges(); if (counts > 0) { DbLoggerBLL.SysLogger.Info("Increase menu and the role relationship successfully! ID: '" + tblMenu_Permission_RoleObj.ID + "'. User host address: '"+ userHostAddress + "'"); return true; } } } catch (Exception ex) { DbLoggerBLL.SysLogger.Error("Increase menu and the role relationship failed! ID: '" + tblMenu_Permission_RoleObj.ID + "'. User host address: '" + userHostAddress + "' . Exception info" + ex.Message); return false; } return false; }
/// <summary> /// 新增数据 /// </summary> /// <param name="RoleObj"></param> /// <returns></returns> public bool Add(tblRole_User Role_UserObj) { Role_UserObj.ID = System.Guid.NewGuid(); int counts = 0; //插入数据 try { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { MWDB.tblRole_User.AddObject(Role_UserObj); counts = MWDB.SaveChanges(); if (counts > 0) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Info("Increase user and role relationship successfully! User and role relationship ID: '" + Role_UserObj.ID + "'. User host address: '" + userHostAddress + "' . "); return true; } } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Increase user and role relationship failed! User and role relationship ID: '" + Role_UserObj.ID + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message); return false; } return false; }
/// <summary> /// RadTreeView 绑定数据 /// </summary> public void RadTreeData() { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { var objtbl = MWDB.tblMenuRight.Where<tblMenuRight>(m => m.MenuID != null).OrderBy(rr => rr.Seq); RadTreeView_Rigth.DataSource = objtbl; RadTreeView_Rigth.DataTextField = "MenuName"; RadTreeView_Rigth.DataValueField = "MenuID"; RadTreeView_Rigth.DataFieldID = "MenuID"; RadTreeView_Rigth.DataFieldParentID = "ParentNode"; RadTreeView_Rigth.DataBind(); } }
/// <summary> /// 新增数据 /// </summary> /// <param name="RoleObj"></param> /// <returns></returns> public bool Add(tblUser RoleObj) { //RoleObj.UserID = System.Guid.NewGuid(); //获取当前登录用户的ID(Cookies) string strUserID = HttpContext.Current.User.Identity.Name; if (strUserID == string.Empty || strUserID == null) { return false; } System.Guid guidUserID = new Guid(strUserID); RoleObj.SendEmail = true; RoleObj.LastModifiedByID = guidUserID; RoleObj.CreatedByID = guidUserID; RoleObj.OwnerID = guidUserID; RoleObj.CreatedDate = Convert.ToDateTime(System.DateTime.Now); RoleObj.LastModifiedDate = Convert.ToDateTime(System.DateTime.Now); RoleObj.SystemModstamp = Convert.ToDateTime(System.DateTime.Now); RoleObj.IsDeleted = false; RoleObj.Avatar = this.GetImageIo(); int counts = 0; //插入数据 try { MWDatabaseEntities MWDB = new MWDatabaseEntities(); MWDB.tblUser.AddObject(RoleObj); counts = MWDB.SaveChanges(); if (counts > 0) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Info("Increase user successfully! User id: '" + RoleObj.UserID + "'. User host address: '" + userHostAddress + "'. "); return true; } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Increase user failed! User id: '" + RoleObj.UserID + "'. User host address: '" + userHostAddress + "'. Exception info:" + ex.Message); return false; } return false; }
/// <summary> /// 新增数据 /// </summary> /// <param name="RoleObj"></param> /// <returns></returns> public bool Add(tblRole RoleObj) { //获取当前登录用户的ID(Cookies) string strUserID = HttpContext.Current.User.Identity.Name; if (string.IsNullOrEmpty(strUserID)) { FormsAuthentication.RedirectToLoginPage(); return false; } System.Guid guidUserID = new Guid(strUserID); RoleObj.RoleID = System.Guid.NewGuid(); RoleObj.LastModifiedByID = guidUserID; RoleObj.CreatedByID = guidUserID; RoleObj.OwnerID = guidUserID; RoleObj.CreatedDate = Convert.ToDateTime(System.DateTime.Now); RoleObj.LastModifiedDate = Convert.ToDateTime(System.DateTime.Now); RoleObj.SystemModstamp = Convert.ToDateTime(System.DateTime.Now); RoleObj.IsDeleted = false; int counts = 0; //插入数据 try { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { MWDB.tblRole.AddObject(RoleObj); counts = MWDB.SaveChanges(); if (counts > 0) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Info("Increase role info successfully! Role ID: '" + RoleObj.RoleID + "'. User host address: '" + userHostAddress + "'"); return true; } } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Increase role info failed! Role ID: '" + RoleObj.RoleID + "'. User host address: '" + userHostAddress + "' . Exception info:"+ ex.Message); return false; } return false; }
public void Resume(string strRoleID) { if (strRoleID != string.Empty) { IList<RadTreeNode> nodeCollection = RadTreeView_Rigth.CheckedNodes; //循环所有节点把CheckBox设为 false foreach (RadTreeNode node in nodeCollection) { node.Checked = false; } using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { //根据选中ListBox的值查询tblRole表 System.Guid gu = new Guid(strRoleID); tblRole objRole = MWDB.tblRole.First(r => r.RoleID == gu); if (objRole != null) { //必须调用 Load方法,把数据先加载上去 ObjectQuery<tblMenu_Permission_Role> tblMenu_Permission_Roles = MWDB.tblMenu_Permission_Role.Where(" it.RoleID=Guid '" + strRoleID + "'"); foreach (tblMenu_Permission_Role item in tblMenu_Permission_Roles) { RadListBoxItem objItem = new RadListBoxItem(); item.tblMenuRightReference.Load(); objItem.Text = item.RoleID.ToString(); tblMenuRight objMenut = MWDB.tblMenuRight.First(m => m.MenuID == item.MenuID); if (objMenut != null) { RadTreeNode node = RadTreeView_Rigth.FindNodeByValue(item.MenuID.ToString()); if (node != null) { //判断是否有子节点如果有返回True ,否则返回False //如果有子节点就不能选中当前的节点,如果选中的话他会自动选中所有子节点 if (!node.HasControls()) { node.Checked = true; } } } } } } } }
/// <summary> /// 逻辑删除 /// </summary> /// <param name="KeyId">需要删除对象的ID</param> /// <returns>返回受影响的行数</returns> public bool Delete(string strKeyId) { //影响行数标记 int counts = 0; //转换成Guid类型 System.Guid KeyIdGuid = new Guid(strKeyId); //需要跟新的对象 tblRole_User tblRole_Users; try { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { tblRole_Users = MWDB.tblRole_User.FirstOrDefault(t => t.UserID == KeyIdGuid); if (tblRole_Users != null) { MWDB.DeleteObject(tblRole_Users); counts = MWDB.SaveChanges(); } if (counts > 0) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Info("Delete user and role relationship successfully! User and role relationship ID: '" + strKeyId + "'. User host address: '" + userHostAddress + "' . "); return true; } } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Increase user and role relationship failed! User and role relationship ID: '" + strKeyId + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message); return false; } return false; }
/// <summary> /// 删除一条数据 /// </summary> public int DeleteT(string ID) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; int count = 0; using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { try { System.Guid gu = new Guid(ID); tblRole objRole = MWDB.tblRole.First(r => r.RoleID == gu); if (objRole != null) { List<tblMenu_Permission_Role> list = MWDB.tblMenu_Permission_Role.Where<tblMenu_Permission_Role>(m => m.RoleID == gu).ToList(); if (list.Count > 0) { foreach (var lists in list) { tblMenu_Permission_Role tblMenu_Permission_RoleObj; tblMenu_Permission_RoleObj = MWDB.tblMenu_Permission_Role.First(m => m.RoleID == lists.RoleID); MWDB.DeleteObject(tblMenu_Permission_RoleObj); count = MWDB.SaveChanges(); if (count>0) { DbLoggerBLL.SysLogger.Info("Delete menu and the role relationship successfully! ID: '" + tblMenu_Permission_RoleObj.ID + "'. User host address: '" + userHostAddress + "'"); } } } } } catch (Exception ex) { DbLoggerBLL.SysLogger.Error("Delete menu and the role relationship failed! ID: '" + ID + "'. User host address: '" + userHostAddress + "' . Exception info" + ex.Message); } } return count; }
/// <summary> /// 判断用户是否合法 /// </summary> /// <param name="UserName">用户名</param> /// <param name="Password">密码</param> /// <returns>用户的GUID</returns> public virtual string Verify(string UserName, string Password) { tblUser objUTPUser; using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; try { objUTPUser = MWDB.tblUser.FirstOrDefault<tblUser>(u => u.LoginName == UserName && u.State == true && u.IsDeleted == false); if (objUTPUser!=null&&objUTPUser.LoginPwd.CompareTo(Password) == 0) { string roleId=GetRoleIdByUserId(objUTPUser.UserID); if (!string.IsNullOrEmpty(roleId)) { DbLoggerBLL.FileLoger.Info("'" + objUTPUser.UserName + "' login successfully! User host address: '" + userHostAddress + "'"); //核对密码正确,且角色可用 return objUTPUser.UserID.ToString(); }else { DbLoggerBLL.FileLoger.Warn("'" + UserName + "' login failed! Role has been forbidden! User host address: '" + userHostAddress + "'"); return null; } } else { DbLoggerBLL.FileLoger.Warn("'" + UserName + "' login failed! Password does not match! User host address: '" + userHostAddress + "'"); return null; } } catch (Exception ex) { DbLoggerBLL.FileLoger.Error("'" + UserName + "' login failed! Maybe connecte data server failed! User host address: '" + userHostAddress + "' Exception info : " + ex.Message); //此处编写错误处理日志 return null; } } }
/// <summary> /// 更新数据 /// </summary> /// <param name="RoleObj"></param> /// <returns></returns> public bool Update(tblUser UserNew) { tblUser UserOld; int counts = 0;//影响行数标记 using (MWDatabaseEntities MWDB =new MWDatabaseEntities()) { try { UserOld = MWDB.tblUser.FirstOrDefault(t => t.UserID == UserNew.UserID); //更新数据字段 UserOld.UserName = UserNew.UserName; UserOld.LoginName = UserNew.LoginName; UserOld.LoginPwd = UserNew.LoginPwd; UserOld.UserCode = UserNew.UserCode; UserOld.State = UserNew.State; UserOld.Email = UserNew.Email; UserOld.Desc = UserNew.Desc; UserOld.Avatar = UserNew.Avatar; //获取当前登录用户的ID(Cookies) string strUserID = HttpContext.Current.User.Identity.Name; if (string.IsNullOrEmpty(strUserID)) { FormsAuthentication.RedirectToLoginPage(); return false; } UserOld.LastModifiedByID = new Guid(strUserID); DateTime dates = System.DateTime.Now; UserOld.LastModifiedDate = dates; UserOld.SystemModstamp = dates; ObjectStateEntry ose = MWDB.ObjectStateManager.GetObjectStateEntry(UserOld); IEnumerable<string> list = ose.GetModifiedProperties(); string logBody = string.Empty; foreach (string pr in list) { string strs = pr;//更新实体的属性名 string strNew = ose.CurrentValues[strs].ToString(); string strOld = ose.OriginalValues[strs].ToString(); if (strNew != strOld) { strNew = string.IsNullOrEmpty(strNew) ? "null" : strNew;//如果字符串为空,则将null赋给字符串 strOld = string.IsNullOrEmpty(strOld) ? "null" : strOld; switch (strs) { case "LastModifiedByID": //系统字段不进行发送 break; case "LastModifiedDate": //系统字段不进行发送 break; case "SystemModstamp": //系统字段不进行发送 break; default: logBody += ", " + strs + ": '" + strOld + "'" + " had been changed '" + strNew + "'"; break; } } } counts = MWDB.SaveChanges(); if (counts > 0) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Info("Update user info failed! User update log: '" + logBody + "'. User host address: '" + userHostAddress + "' ."); return true; } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Update user info failed! User id: '" + UserNew.UserID + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message); return false; } } return false; }
/// <summary> /// 查询用户名 /// </summary> /// <param name="userId">用户ID</param> /// <returns></returns> public virtual string GetUserNameById(Guid userId) { tblUser userObj; using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { try { userObj = MWDB.tblUser.First(it => it.UserID == userId&&it.IsDeleted==false); } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Find user failed! User id: '" + userId + "'. User host address: '" + userHostAddress +"'. Exception info:" + ex.Message); return null; } } return userObj.UserName; }
/// <summary> /// 返回Role数据集合 /// </summary> /// <param name="SearchStr">查询条件,可以为空 ( and it.name='aa')</param> /// <param name="strOrderby">排序方式,不可以为空,(it.name desc )</param> /// <returns></returns> public List<View_Role> GetAll(string strSearch, string strOrderby) { List<View_Role> query = null; using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { string strWhere = " it.IsDeleted==false " + strSearch; try { query = MWDB.View_Role.Where(strWhere).OrderBy(strOrderby).ToList(); } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Find role view failed! Inquires the conditions: '" + strWhere + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message); return null; } } return query; }
/// <summary> /// 判断登陆名是否重复 /// </summary> /// <param name="userId">登陆名称</param> /// <returns></returns> public bool ExistsLogName(string strLoginName) { tblUser userObj; using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { try { userObj = MWDB.tblUser.First(it => it.LoginName == strLoginName); if (userObj!=null) { return true; } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Find user failed! User login name: '" + strLoginName + "'. User host address: '" + userHostAddress + "' . Exception info" + ex.Message); return false; } } return false; }
protected void GridUser_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormItem && e.Item.IsInEditMode) { //插入状态 if (e.Item.OwnerTableView.IsItemInserted) { //***********************************Role 下拉列表加载数据 RoleBLL RoleBLLs = new RoleBLL(); List<View_Role> query = null; query = RoleBLLs.GetAll("", " it.RoleName desc"); if (query != null && query.Count() > 0) { GridEditFormItem edittedItem = (GridEditFormItem)e.Item; RadComboBox ComBoxRole = edittedItem.FindControl("ComBoxRole") as RadComboBox; ComBoxRole.DataSource = query; ComBoxRole.DataTextField = "RoleName"; ComBoxRole.DataValueField = "RoleID"; ComBoxRole.DataBind(); } //***********************************Role 下拉列表加载数据 } //编辑状态 else { //获取Grid的主键值 this.strKeyID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserID"].ToString(); //判断主键是否为空 if (this.strKeyID != string.Empty) { //装换Guid类型 System.Guid Guid = new Guid(this.strKeyID); //实例化Entity实体 using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { //通过主键查询数据表获取外键字段 control tblUser tblUsers = MWDB.tblUser.FirstOrDefault(d => d.UserID == Guid); if (tblUsers != null) { //加载d_DicType GridEditFormItem edittedItem = (GridEditFormItem)e.Item; //获取控件 RadTextBox textUserName = edittedItem.FindControl("textUserName") as RadTextBox; RadTextBox textLoginName = edittedItem.FindControl("textLoginName") as RadTextBox; RadTextBox textUserCode = edittedItem.FindControl("textUserCode") as RadTextBox; RadTextBox textEmail = edittedItem.FindControl("textEmail") as RadTextBox; RadTextBox textDesc = edittedItem.FindControl("textDesc") as RadTextBox; RadComboBox ComBoxState = edittedItem.FindControl("ComBoxState") as RadComboBox; RadComboBox ComBoxRole = edittedItem.FindControl("ComBoxRole") as RadComboBox; RoleBLL RoleBLLs = new RoleBLL(); //***********************************Role 下拉列表加载数据 List<View_Role> query = null; query = RoleBLLs.GetAll("", " it.RoleName desc"); if (query != null && query.Count() > 0) { ComBoxRole.DataSource = query; ComBoxRole.DataTextField = "RoleName"; ComBoxRole.DataValueField = "RoleID"; ComBoxRole.DataBind(); } //***********************************Role 下拉列表加载数据 RoleUserBLL Role_UserBLLs = new RoleUserBLL(); tblRole_User tblRole_UserObj = null; tblRole_UserObj = Role_UserBLLs.GetByID(this.strKeyID); if (tblRole_UserObj != null) { ComBoxRole.SelectedIndex = ComBoxRole.Items.IndexOf(ComBoxRole.Items.FindItemByValue(tblRole_UserObj.RoleID.ToString(), true)); } //为控件赋值 textUserName.Text = tblUsers.UserName; textLoginName.Text = tblUsers.LoginName; textUserCode.Text = tblUsers.UserCode; textEmail.Text = tblUsers.Email; textDesc.Text = tblUsers.Desc; //下拉列表编辑时选择 ComBoxState.SelectedIndex = ComBoxState.Items.IndexOf(ComBoxState.Items.FindItemByValue(tblUsers.State.ToString())); } } } } } }
/// <summary> /// 绑定RadMenu1数据, 横向菜单 /// </summary> public void RadMenuBing() { string UserID = string.Empty; string RoleID = string.Empty; //获取登陆ID UserID = HttpContext.Current.User.Identity.Name; // UserID = "806858E6-034F-4DE5-A57F-7A3089BFC480"; using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { if (!string.IsNullOrEmpty(UserID) && !string.IsNullOrWhiteSpace(UserID)) { //转换成Guid类型 System.Guid UserID_Gu = new Guid(UserID); //查询 tblUser表数据 tblUser tblUser = MWDB.tblUser.FirstOrDefault(u => u.UserID == UserID_Gu); if (tblUser != null) { //加载tblRole_User的数据 tblUser.tblRole_User.Load(); foreach (tblRole_User item in tblUser.tblRole_User) { item.tblRoleReference.Load(); //得到登陆用户对应的角色id RoleID = item.tblRole.RoleID.ToString(); } } System.Guid UserID_G = new Guid(RoleID); string NodeLevel = "1"; //通过获取的角色id查询绑定横向菜单 var objtbl = MWDB.View_Menu_Permission_Role.Where<View_Menu_Permission_Role> (r => r.RoleID == UserID_G && r.NodeLevel == NodeLevel).Distinct().OrderBy(rr => rr.Seq); if (objtbl != null) { List<MenuDataItem> CurrMenuData = GetMenuData((ObjectQuery)objtbl); //初始化数据绑定字段 RadMenuMain.DataTextField = "Text"; RadMenuMain.DataFieldID = "ID"; RadMenuMain.DataValueField = "ID"; RadMenuMain.DataFieldParentID = "ParentID"; RadMenuMain.DataNavigateUrlField = "Url"; //绑定数据 RadMenuMain.DataSource = CurrMenuData; RadMenuMain.DataBind(); //设置分隔线 foreach (MenuDataItem it in CurrMenuData) { if (it.IsSeparator == "True") { RadMenuItem mi = RadMenuMain.FindItemByValue(it.ID.ToString()); mi.IsSeparator = true; } } } } else { FormsAuthentication.RedirectToLoginPage(); return; } } }
/// <summary> /// 逻辑删除 /// </summary> /// <param name="KeyId">需要删除对象的ID</param> /// <returns>返回受影响的行数</returns> public bool Delete(string strKeyId) { //影响行数标记 int counts = 0; //转换成Guid类型 System.Guid KeyIdGuid = new Guid(strKeyId); //需要跟新的对象 tblRole tblRoles; try { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { tblRoles = MWDB.tblRole.First(t => t.RoleID == KeyIdGuid); tblRoles.IsDeleted = true; counts = MWDB.SaveChanges(); if (counts > 0) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Info("Delete role successfully! Role ID: '" + strKeyId + "'. User host address: '" + userHostAddress + "' . "); return true; } } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Delete role failed! Role ID: '" + strKeyId + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message); return false; } return false; }
protected void Save(string strRoleID) { if (strRoleID != string.Empty) { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { System.Guid gu = new Guid(strRoleID); tblRole objRole = MWDB.tblRole.First(r => r.RoleID == gu); if (objRole != null) { MenuPermissionRoleBLL Menu_Permission_RoleBLLs = new MenuPermissionRoleBLL(); Menu_Permission_RoleBLLs.DeleteT(strRoleID); IList<RadTreeNode> nodeCollection = RadTreeView_Rigth.CheckedNodes; //删除 //循环选中的节点并获取值 foreach (RadTreeNode node in nodeCollection) { if (node.Value != string.Empty) { tblMenu_Permission_Role tblp = new tblMenu_Permission_Role(); System.Guid guMenuID = new Guid(node.Value); tblp.MenuID = guMenuID; tblp.RoleID = gu; Menu_Permission_RoleBLLs.Add(tblp); } } } } } }
/// <summary> /// 通过ID查询 返回数据 /// </summary> /// <param name="strKeyID">主键值</param> /// <returns></returns> public tblUser GetByID(string strKeyID) { tblUser tblUserObj; System.Guid KeyIdGuid = new Guid(strKeyID); try { using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { tblUserObj = MWDB.tblUser.First(t => t.UserID == KeyIdGuid); } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Find user failed! User id: '" + strKeyID + "'. User host address: '" + userHostAddress + "'. Exception info:" + ex.Message); return null; } return tblUserObj; }
/// <summary> /// 返回角色ID /// </summary> /// <param name="userId"></param> /// <returns></returns> public virtual string GetRoleIdByUserId(Guid userId) { View_RoleAndUser objRoleAndUser; using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { try { objRoleAndUser = MWDB.View_RoleAndUser.First(it => it.UserID == userId && it.State == 1 && it.IsDeleted == false);//1为可用 if (objRoleAndUser != null) { return objRoleAndUser.RoleID.ToString(); } else { return null; } } catch (Exception ex) { string userHostAddress = HttpContext.Current.Request.UserHostAddress; DbLoggerBLL.SysLogger.Error("Find user and the role relationship failed! user id: '" + userId + "'. User host address: '" + userHostAddress + "' . Exception info" + ex.Message); return null; } } }
protected void GridRole_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormItem && e.Item.IsInEditMode) { //编辑状态 if (!e.Item.OwnerTableView.IsItemInserted) { //获取Grid的主键值 this.strKeyID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["RoleID"].ToString(); //判断主键是否为空 if (this.strKeyID != string.Empty) { //装换Guid类型 System.Guid Guid = new Guid(this.strKeyID); //实例化Entity实体 using (MWDatabaseEntities MWDB = new MWDatabaseEntities()) { //通过主键查询数据表获取外键字段 tblRole tblRoles = MWDB.tblRole.FirstOrDefault(d => d.RoleID == Guid); if (tblRoles != null) { //加载d_DicType //tbldicinfo.d_DicTypeReference.Load(); GridEditFormItem formItem = (GridEditFormItem)e.Item; //string StrDicTypeID = tblRoles.RoleName; //获取控件 RadTextBox textRoleName = formItem.FindControl("txtRoleName") as RadTextBox; RadTextBox textRoleCode = formItem.FindControl("textRoleCode") as RadTextBox; RadTextBox textDesc = formItem.FindControl("textDesc") as RadTextBox; RadComboBox ComBoxState = formItem.FindControl("ComBoxState") as RadComboBox; //为控件赋值 textRoleName.Text = tblRoles.RoleName; textRoleCode.Text = tblRoles.RoleCode; textDesc.Text = tblRoles.Desc; //下拉列表编辑时选择 ComBoxState.SelectedIndex = ComBoxState.Items.IndexOf(ComBoxState.Items.FindItemByValue(tblRoles.State.ToString())); } } } } } }