/// <summary> /// 删除事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridUser_DeleteCommand(object sender, GridCommandEventArgs e) { //获取Grid的主键值 string GridKey = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserID"].ToString(); UserBLL UserBLLs = new UserBLL(); string strGetuserID = HttpContext.Current.User.Identity.Name; if (strGetuserID == GridKey) { //当前用户不能删除! 警告 string strInfo = GetGlobalResourceObject("en_US", "UserManagerForm_lblDesc_DeleteInfo").ToString(); RadWindowManager1.RadAlert(strInfo, 300, 100, "Warn", ""); return; } if (GridKey != string.Empty) { tblUser UserObjs; UserObjs = UserBLLs.GetByID(GridKey); if (UserObjs.UserName == "admin") { //管理员不能删除! 警告Admin Can't delete! string strInfo = GetGlobalResourceObject("en_US", "UserManagerForm_lblDesc_DeleteInfoAdmin").ToString(); RadWindowManager1.RadAlert(strInfo, 300, 100, "Warn", ""); return; } UserBLLs.Delete(GridKey); RoleUserBLL Role_UserBLLs = new RoleUserBLL(); //删除关系表 Role_UserBLLs.Delete(GridKey); } this.GridViewData(); }
/// <summary> /// GridView绑定数据 /// </summary> public void GridViewData() { //实例化EntityDataSourceModel 属性类 EntityDataSourceModel eModel = new EntityDataSourceModel(); UserBLL UserBLLs = new UserBLL(); eModel = UserBLLs.GetEModel(); EntityDataSourceGridUser.EntitySetName = eModel.EntitySetName; if (!string.IsNullOrEmpty(eModel.Where)) { EntityDataSourceGridUser.Where = eModel.Where; } if (!string.IsNullOrEmpty(eModel.OrderBy)) { EntityDataSourceGridUser.OrderBy = eModel.OrderBy; } EntityDataSourceGridUser.DefaultContainerName = eModel.DefaultContainerName; EntityDataSourceGridUser.ConnectionString = eModel.ConnectionString; }
/// <summary> /// GridView的InsertCommand事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridUser_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { GridEditableItem edittedItem = e.Item.OwnerTableView.GetInsertItem(); //获取控件 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; RadTextBox textLoginPwd = edittedItem.FindControl("textLoginPwd") as RadTextBox; RadComboBox ComBoxState = edittedItem.FindControl("ComBoxState") as RadComboBox; RadComboBox ComBoxRole = edittedItem.FindControl("ComBoxRole") as RadComboBox; System.Guid gTemp = System.Guid.NewGuid(); UserBLL UserBLLs = new UserBLL(); if (UserBLLs.ExistsLogName(textLoginName.Text)) { //The user already exists //该用户已存在 RadWindowManager1.RadAlert("The user already exists!", 300, 100, "Info", ""); return; } //实例化Entity实体 tblUser UserObj = new tblUser(); UserObj.UserName = textUserName.Text; UserObj.LoginName = textLoginName.Text; UserObj.LoginPwd = textLoginPwd.Text; UserObj.UserCode = textUserCode.Text; UserObj.State = Convert.ToBoolean(ComBoxState.SelectedItem.Value); UserObj.Email = textEmail.Text; UserObj.Desc = textDesc.Text; UserObj.UserID = gTemp; UserBLLs.Add(UserObj); //创建目录文件夹 Directory.CreateDirectory(Request.PhysicalApplicationPath + "FileUpLoad/" + gTemp); //*************************************************给用户配置角色 RoleUserBLL Role_UserBLLs = new RoleUserBLL(); if (ComBoxRole.SelectedItem.Value != string.Empty) { tblRole_User tblRole_UserObj = new tblRole_User(); System.Guid gUserID = gTemp; System.Guid gRoleID = new Guid(ComBoxRole.SelectedItem.Value); tblRole_UserObj.UserID = gUserID; tblRole_UserObj.RoleID = gRoleID; Role_UserBLLs.Add(tblRole_UserObj); } //*************************************************给用户配置角色 this.GridViewData(); }
/// <summary> /// GridView 的UpdateCommand 事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridUser_UpdateCommand(object sender, GridCommandEventArgs e) { GridEditableItem edittedItem = e.Item as GridEditableItem; //获取控件 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; //*************************************************给用户配置角色 RoleUserBLL Role_UserBLLs = new RoleUserBLL(); if (ComBoxRole.SelectedItem.Value != string.Empty) { //删除关系表 Role_UserBLLs.Delete(this.strKeyID); tblRole_User tblRole_UserObj = new tblRole_User(); System.Guid gUserID = new Guid(this.strKeyID); System.Guid gRoleID = new Guid(ComBoxRole.SelectedItem.Value); tblRole_UserObj.UserID = gUserID; tblRole_UserObj.RoleID = gRoleID; Role_UserBLLs.Add(tblRole_UserObj); } //*************************************************给用户配置角色 //实例化Entity实体 UserBLL UserBLLs = new UserBLL(); tblUser UserObjs; UserObjs = UserBLLs.GetByID(this.strKeyID); UserObjs.UserName = textUserName.Text; UserObjs.LoginName = textLoginName.Text; UserObjs.UserCode = textUserCode.Text; if (ComBoxState.SelectedItem.Value == "True") { UserObjs.State = true; } else { UserObjs.State = false; } UserObjs.Email = textEmail.Text; UserObjs.Desc = textDesc.Text; UserBLLs.Update(UserObjs); this.GridViewData(); }
protected void Page_Load(object sender, EventArgs e) { //判断用户是否已经登录 string LoginID = HttpContext.Current.User.Identity.Name; if (string.IsNullOrEmpty(LoginID) || string.IsNullOrWhiteSpace(LoginID)) { FormsAuthentication.RedirectToLoginPage(); return; } else { BLL_User = new UserBLL(); string strGetuser = BLL_User.GetLoginUserName(); if (strGetuser != string.Empty) { lbl_Welcome.Text = "Welcome," + strGetuser; RadMenuBing(); } } }