protected void btnSubmit_OnClick(object sender, EventArgs e) { string loginPwd = this.txtLoginPwd.Text.Trim(); string name = this.txtName.Text.Trim(); string notes = this.txtNotes.Text.Trim(); ADeeWu.HuoBi3J.Model.Admin_Users user = dalAdmin.GetEntity(userID); if (user == null) { ADeeWu.HuoBi3J.Libary.WebUtility.ShowMsg(this,"当前记录已被删除!", "list.aspx"); return; } if (loginPwd != "") //密码修改 { user.LoginPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(loginPwd, "md5"); } user.Name = name; user.Notes = notes; if (dalAdmin.Update(user) <= 0) { ADeeWu.HuoBi3J.Libary.WebUtility.ShowMsg(this, "修改失败!"); return; } //删除用户所有角色 dalUserInRoles.Delete("AdminID", userID); //授权新的角色 foreach (ListItem item in this.checkBoxListRoles.Items) { if (item.Selected) { ADeeWu.HuoBi3J.Model.Admin_UserInRoles entUserInRole = new ADeeWu.HuoBi3J.Model.Admin_UserInRoles(); entUserInRole.AdminID = userID; entUserInRole.RoleID = ADeeWu.HuoBi3J.Libary.Utility.GetInt(item.Value, 0); dalUserInRoles.Add(entUserInRole); } } //删除用户所有权限 dalUserPermissions.Delete("AdminID", userID); //授权新的权限 long[] alowPageID = ADeeWu.HuoBi3J.Libary.WebUtility.GetRequestLongGroups("alowPageID", 2); foreach (long pageID in alowPageID) { ADeeWu.HuoBi3J.Model.Admin_UserPermissions entUserPermission = new ADeeWu.HuoBi3J.Model.Admin_UserPermissions(); entUserPermission.AdminID = userID; entUserPermission.PageID = pageID; entUserPermission.CheckState = 0; dalUserPermissions.Add(entUserPermission); } long[] denyPageID = ADeeWu.HuoBi3J.Libary.WebUtility.GetRequestLongGroups("denyPageID", 2); foreach (long pageID in denyPageID) { ADeeWu.HuoBi3J.Model.Admin_UserPermissions entUserPermission = new ADeeWu.HuoBi3J.Model.Admin_UserPermissions(); entUserPermission.AdminID = userID; entUserPermission.PageID = pageID; entUserPermission.CheckState = 1; dalUserPermissions.Add(entUserPermission); } ADeeWu.HuoBi3J.Libary.WebUtility.ShowPageSelector(this, "修改成功!选择\"是\"继续操作!", "Edit.aspx?id=" + userID, "list.aspx"); }
public ADeeWu.HuoBi3J.Model.Admin_UserInRoles[] GetEntityList(string orderBy,string[] columns,params object[] values) { StringBuilder builder = new StringBuilder(); builder.Append("select * from [Admin_UserInRoles] where 1=1"); db.Parameters.Clear(); for(int i=0;i<columns.Length;i++) { builder.AppendFormat(" and [{0}]=@{0}", columns[i]); db.Parameters.Append("@"+columns[i],values[i]); } if (!string.IsNullOrEmpty(orderBy)) { builder.AppendFormat(" order by {0}", orderBy); } DataTable dt = db.Select(builder.ToString()); ADeeWu.HuoBi3J.Model.Admin_UserInRoles[] EntityList = new ADeeWu.HuoBi3J.Model.Admin_UserInRoles[dt.Rows.Count]; if (dt.Rows.Count == 0) return EntityList; for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; ADeeWu.HuoBi3J.Model.Admin_UserInRoles Entity = new ADeeWu.HuoBi3J.Model.Admin_UserInRoles(); Entity.ID = long.Parse(dr["ID"].ToString()); Entity.RoleID = dr["RoleID"] as long?; Entity.AdminID = dr["AdminID"] as long?; EntityList[i] = Entity; } return EntityList; }
public ADeeWu.HuoBi3J.Model.Admin_UserInRoles GetEntity(long ID) { db.Parameters.Clear(); db.Parameters.Append("@ID",ID); DataTable dt = db.Select("select * from [Admin_UserInRoles] where 1=1 and [ID]=@ID"); if(dt.Rows.Count==0) return null; DataRow dr = dt.Rows[0]; ADeeWu.HuoBi3J.Model.Admin_UserInRoles Entity = new ADeeWu.HuoBi3J.Model.Admin_UserInRoles(); Entity.ID = long.Parse(dr["ID"].ToString()); Entity.RoleID = dr["RoleID"] as long?; Entity.AdminID = dr["AdminID"] as long?; return Entity; }
public ADeeWu.HuoBi3J.Model.Admin_UserInRoles GetEntity(string where) { DataTable dt = this.Select(where,""); if(dt.Rows.Count==0) return null; DataRow dr = dt.Rows[0]; ADeeWu.HuoBi3J.Model.Admin_UserInRoles Entity = new ADeeWu.HuoBi3J.Model.Admin_UserInRoles(); Entity.ID = long.Parse(dr["ID"].ToString()); Entity.RoleID = dr["RoleID"] as long?; Entity.AdminID = dr["AdminID"] as long?; return Entity; }
protected void btnSubmit_OnClick(object sender, EventArgs e) { string loginName = this.txtLoginName.Text.Trim(); string loginPwd = this.txtLoginPwd.Text.Trim(); string loginPwd2 = this.txtLoginPwd2.Text.Trim(); string name = this.txtName.Text.Trim(); string notes = this.txtNotes.Text.Trim(); if (loginName == "") { ADeeWu.HuoBi3J.Libary.WebUtility.ShowMsg("用户帐号不能为空!"); return; } if (loginPwd == "") { ADeeWu.HuoBi3J.Libary.WebUtility.ShowMsg("登陆密码不能为空!"); return; } if (loginPwd != loginPwd2) { ADeeWu.HuoBi3J.Libary.WebUtility.ShowMsg("两次输入密码不一致!"); return; } ADeeWu.HuoBi3J.DAL.Admin_Users dal = new ADeeWu.HuoBi3J.DAL.Admin_Users(); if (dal.Exist("LoginName", loginName)) { ADeeWu.HuoBi3J.Libary.WebUtility.ShowMsg("帐号已存在!"); return; } ADeeWu.HuoBi3J.Model.Admin_Users user = new ADeeWu.HuoBi3J.Model.Admin_Users(); user.LoginName = loginName; user.Name = name; user.Notes = ADeeWu.HuoBi3J.Libary.WebUtility.GetTextAreaContent(notes); user.LoginPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(loginPwd, "md5"); user.LastLogin = DateTime.Now; user.RegTime = DateTime.Now; user.LoginTimes = 0; if (dal.Add(user) <= 0) { ADeeWu.HuoBi3J.Libary.WebUtility.ShowMsg(this, "注册失败!"); return; } //角色授权 foreach (ListItem item in checkBoxListRoles.Items) { if (item.Selected) { long roleID = ADeeWu.HuoBi3J.Libary.Utility.GetLong(item.Value, 0); if (roleID <= 0) continue; ADeeWu.HuoBi3J.Model.Admin_UserInRoles entUserInRoles = new ADeeWu.HuoBi3J.Model.Admin_UserInRoles(); entUserInRoles.AdminID = user.ID; entUserInRoles.RoleID = roleID; dalUserInRoles.Add(entUserInRoles); } } //特别权限授权 long[] alowPageIDGroup = ADeeWu.HuoBi3J.Libary.WebUtility.GetRequestLongGroups("alowPageID", 0); foreach (long pageID in alowPageIDGroup)//设置用户所拥有的权限 { if (pageID > 0) { ADeeWu.HuoBi3J.Model.Admin_UserPermissions entUserPermission = new ADeeWu.HuoBi3J.Model.Admin_UserPermissions(); entUserPermission.CheckState = 0; entUserPermission.PageID = pageID; entUserPermission.AdminID = user.ID; dalUserPermission.Add(entUserPermission); } } long[] denyPageIDGroup = ADeeWu.HuoBi3J.Libary.WebUtility.GetRequestLongGroups("denyPageID", 0); foreach (long pageID in denyPageIDGroup)//设置角色所拒绝的权限 { if (pageID > 0) { ADeeWu.HuoBi3J.Model.Admin_UserPermissions entUserPermission = new ADeeWu.HuoBi3J.Model.Admin_UserPermissions(); entUserPermission.CheckState = 1; entUserPermission.PageID = pageID; entUserPermission.AdminID = user.ID; dalUserPermission.Add(entUserPermission); } } ADeeWu.HuoBi3J.Libary.WebUtility.ShowPageSelector(this, "注册成功!选择\"是\"继续操作!", "add.aspx", "list.aspx"); }