public M_AdminInfo GetModelFromReader(DbDataReader rdr) { M_AdminInfo model = new M_AdminInfo(); model.AdminId = Convert.ToInt32(rdr["AdminID"]); model.AdminName = rdr["AdminName"].ToString(); model.AdminPassword = rdr["AdminPassword"].ToString(); model.UserName = ConverToStr(rdr["UserName"]); model.EnableMultiLogin = ConverToBool(rdr["EnableMultiLogin"]); model.LoginTimes = ConvertToInt(rdr["LoginTimes"]); model.LastLoginIP = ConverToStr(rdr["LastLoginIP"]); model.LastLoginTime = ConvertToDate(rdr["LastLoginTime"]); model.LastLogoutTime = ConvertToDate(rdr["LastLogoutTime"]); model.LastModifyPasswordTime = ConvertToDate(rdr["LastModifyPwdTime"]); model.IsLock = ConverToBool(rdr["IsLock"]); model.EnableModifyPassword = ConverToBool(rdr["EnableModifyPassword"]); model.RoleList = ConverToStr(rdr["AdminRole"]); model.Theme = ConverToStr(rdr["Theme"]); model.RandNumber = ConverToStr(rdr["RandNumber"]); model.NodeRole = ConvertToInt(rdr["NodeRole"]); model.PubRole = ConvertToInt(rdr["PubRole"]); model.DefaultStart = ConvertToInt(rdr["DefaultStart"]); model.AdminType = ConvertToInt(rdr["AdminType"]); model.ManageNode = ConverToStr(rdr["ManageNode"]); model.AddUserID = ConvertToInt(rdr["AddUserID"]); model.AdminTrueName = ConverToStr(rdr["AdminTrueName"]); model.IsTable = ConverToBool(rdr["IsTable"]); model.StructureID = ConverToStr(rdr["StructureID"]); model.CDate = ConvertToDate(rdr["CDate"]); rdr.Close(); return(model); }
public override SqlParameter[] GetParameters() { M_AdminInfo model = this; EmptyDeal(model); SqlParameter[] sp = GetSP(); sp[0].Value = model.AdminId; sp[1].Value = SafeStr(model.AdminName); sp[2].Value = model.AdminPassword; sp[3].Value = model.UserName; sp[4].Value = model.EnableMultiLogin; sp[5].Value = model.LoginTimes; sp[6].Value = model.LastLoginIP; sp[7].Value = model.LastLoginTime; sp[8].Value = model.LastLogoutTime; sp[9].Value = model.LastModifyPasswordTime; sp[10].Value = model.IsLock; sp[11].Value = model.EnableModifyPassword; sp[12].Value = model.RoleList; sp[13].Value = model.Theme; sp[14].Value = model.RandNumber; sp[15].Value = model.NodeRole; sp[16].Value = model.PubRole; sp[17].Value = model.DefaultStart; sp[18].Value = model.AdminType; sp[19].Value = model.ManageNode; sp[20].Value = model.AddUserID; sp[21].Value = SafeStr(model.AdminTrueName); sp[22].Value = model.IsTable; sp[23].Value = model.StructureID; sp[24].Value = model.CDate; return(sp); }
/// <summary> /// 增加新的管理员到数据库中 /// </summary> /// <param name="administratorInfo">管理员数据模型</param> /// <returns>增加结果状态 成功为true 反之 false</returns> public bool Add(M_AdminInfo adminInfo) { string strSql = "PR_Manage_Add"; SqlParameter[] parameter = new SqlParameter[10]; parameter[0] = new SqlParameter("@AdminName", SqlDbType.NVarChar, 20); parameter[0].Value = adminInfo.AdminName; parameter[1] = new SqlParameter("@AdminPassword", SqlDbType.NVarChar, 255); parameter[1].Value = adminInfo.AdminPassword; parameter[2] = new SqlParameter("@UserName", SqlDbType.NVarChar, 20); parameter[2].Value = adminInfo.UserName; parameter[3] = new SqlParameter("@EnableMultiLogin", SqlDbType.Bit, 1); parameter[3].Value = adminInfo.EnableMultiLogin; parameter[4] = new SqlParameter("@LastLoginIp", SqlDbType.NVarChar, 50); parameter[4].Value = adminInfo.LastLoginIP; parameter[5] = new SqlParameter("@IsLock", SqlDbType.Bit, 1); parameter[5].Value = adminInfo.IsLock; parameter[6] = new SqlParameter("@EnableModifyPassword", SqlDbType.Bit, 1); parameter[6].Value = adminInfo.EnableModifyPassword; parameter[7] = new SqlParameter("@AdminRole", SqlDbType.NVarChar, 255); parameter[7].Value = adminInfo.RoleList; parameter[8] = new SqlParameter("@Theme", SqlDbType.NVarChar, 50); parameter[8].Value = adminInfo.Theme; parameter[9] = new SqlParameter("@RndPassword", SqlDbType.NVarChar, 10); parameter[9].Value = adminInfo.RandNumber; return SqlHelper.ExecuteProc(strSql, parameter); }
/// <summary> /// 重写管理员信息 /// </summary> /// <param name="ManagerName"></param> /// <param name="ManagerPwd"></param> /// <returns></returns> public static bool Add(string ManagerName, string ManagerPwd) { string strHostIP = ""; IPHostEntry oIPHost = Dns.GetHostEntry(Environment.MachineName); if (oIPHost.AddressList.Length > 0) strHostIP = oIPHost.AddressList[0].ToString(); M_AdminInfo madmin = new M_AdminInfo(); madmin.AdminName = ManagerName; madmin.AdminPassword= StringHelper.MD5(ManagerPwd); madmin.RoleList = "0"; madmin.UserName = ManagerName; madmin.LastLoginIP = strHostIP; madmin.Theme = ""; madmin.EnableModifyPassword = true; madmin.EnableMultiLogin = true; madmin.RandNumber = String.Empty; return (B_Admin.Add(madmin)); }
public void EmptyDeal(M_AdminInfo model) { if (model.LastLoginTime.Year < 1910) { model.LastLoginTime = DateTime.Now; } if (model.LastLogoutTime.Year < 1910) { model.LastLogoutTime = DateTime.Now; } if (model.LastModifyPasswordTime.Year < 1910) { model.LastModifyPasswordTime = DateTime.Now; } if (model.CDate <= DateTime.MinValue) { model.CDate = DateTime.Now; } }
/// <summary> /// 将管理员信息的各属性值传递到参数中 /// </summary> /// <param name="administratorInfo"></param> /// <returns></returns> private static SqlParameter[] GetParameters(M_AdminInfo adminInfo) { SqlParameter[] parameter=new SqlParameter[14]; parameter[0] = new SqlParameter("@AdminId", SqlDbType.Int, 4); parameter[0].Value = adminInfo.AdminId; parameter[1]=new SqlParameter("@AdminName", SqlDbType.NVarChar, 50); parameter[1].Value = adminInfo.AdminName; parameter[2]=new SqlParameter("@AdminPassword", SqlDbType.NVarChar, 100); parameter[2].Value = adminInfo.AdminPassword; parameter[3]=new SqlParameter("@UserName", SqlDbType.NVarChar, 50); parameter[3].Value = adminInfo.UserName; parameter[4]=new SqlParameter("@EnableMultiLogin", SqlDbType.Bit, 1); parameter[4].Value = adminInfo.EnableMultiLogin; parameter[5]=new SqlParameter("@LoginTimes", SqlDbType.Int, 4); parameter[5].Value = adminInfo.LoginTimes; parameter[6]=new SqlParameter("@LastLoginIp", SqlDbType.NVarChar, 50); parameter[6].Value = adminInfo.LastLoginIP; parameter[7]=new SqlParameter("@LastLoginTime", SqlDbType.DateTime); parameter[7].Value = adminInfo.LastLoginTime; parameter[8]=new SqlParameter("@LastLogoutTime", SqlDbType.DateTime); parameter[8].Value = adminInfo.LastLogoutTime; parameter[9]=new SqlParameter("@LastModifyPasswordTime", SqlDbType.DateTime); parameter[9].Value = adminInfo.LastModifyPasswordTime; parameter[10]=new SqlParameter("@IsLock", SqlDbType.Bit, 1); parameter[10].Value = adminInfo.IsLock; parameter[11]=new SqlParameter("@EnableModifyPassword", SqlDbType.Bit, 1); parameter[11].Value = adminInfo.EnableModifyPassword; parameter[12] = new SqlParameter("@RoleList", SqlDbType.NText); parameter[12].Value = adminInfo.RoleList; parameter[13]=new SqlParameter("@Theme", SqlDbType.NVarChar, 50); parameter[13].Value = adminInfo.Theme; return parameter; }
public bool Update2(M_AdminInfo adminInfo) { string strSql = "UPDATE ZL_Manager SET AdminName=@AdminName,AdminPassword=@AdminPassword,UserName=@UserName,EnableMultilogin=@EnableMultilogin,"; strSql += "RoleList=@RoleList,IsLock=@IsLock,EnableModifyPassword=@EnableModifyPassword WHERE AdminId=@AdminId"; SqlParameter[] cmdParams = GetParameters(adminInfo); return SqlHelper.ExecuteSql(strSql, cmdParams); }
/// <summary> /// 从DataReader中读取管理员记录 /// </summary> /// <param name="rdr">DataReader</param> /// <returns>M_AdminInfo 管理员信息</returns> private static M_AdminInfo GetAdminInfoFromReader(SqlDataReader rdr) { M_AdminInfo info = new M_AdminInfo(); info.AdminId = DataConverter.CLng(rdr["AdminID"]); info.AdminName = rdr["AdminName"].ToString(); info.AdminPassword = rdr["AdminPassword"].ToString(); info.UserName = rdr["UserName"].ToString(); info.EnableMultiLogin = DataConverter.CBool(rdr["EnableMultiLogin"].ToString()); info.LoginTimes = DataConverter.CLng(rdr["LoginTimes"]); info.LastLoginIP = rdr["LastLoginIP"].ToString(); info.LastLoginTime = DataConverter.CDate(rdr["LastLoginTime"]); info.LastLogoutTime = DataConverter.CDate(rdr["LastLogoutTime"]); info.LastModifyPasswordTime = DataConverter.CDate(rdr["LastModifyPwdTime"]); info.IsLock = DataConverter.CBool(rdr["IsLock"].ToString()); info.EnableModifyPassword = DataConverter.CBool(rdr["EnableModifyPassword"].ToString()); info.RoleList = rdr["AdminRole"].ToString(); info.Theme = rdr["Theme"].ToString(); //info.RandNumber = rdr["RandNumber"].ToString(); rdr.Close(); return info; }
protected void btnCancel_Click(object sender, EventArgs e) { switch (this.lbTitle.Text) { case ("添加管理员"): this.tbdName.Text = ""; this.tbPwd1.Text = ""; this.tbPwd.Text = ""; for (int m = 0; m < cblRoleList.Items.Count; m++) { this.cblRoleList.Items[m].Selected = false; } this.cb3.Checked = false; this.cb2.Checked = false; this.cb1.Checked = false; break; case ("修改管理员"): admin = B_Admin.GetAdminByAdminId(DataConverter.CLng(ViewState["AdminID"])); this.tbdName.Text = admin.AdminName; this.tbPwd.Text = ""; this.tbPwd1.Text = ""; //string[] roleID = admin.RoleList.Split(); for (int m = 0; m < cblRoleList.Items.Count; m++) { this.cblRoleList.Items[m].Selected = false; } for (int i = 0; i < admin.RoleList.Length; i++) { for (int j = 0; j < this.cblRoleList.Items.Count; j++) { if (this.cblRoleList.Items[j].Value == admin.RoleList[i].ToString()) { this.cblRoleList.Items[j].Selected = true; } else { this.cblRoleList.Items[j].Selected = false; } } } //单选框设置 if (admin.EnableMultiLogin) { this.cb1.Checked = true; } else { this.cb1.Checked = false; } if (admin.EnableModifyPassword) { this.cb2.Checked = true; } else { this.cb2.Checked = false; } if (admin.IsLock) { this.cb3.Checked = true; } else { this.cb3.Checked = false; } break; } }
/// <summary> /// 将管理员信息更新到数据库中 /// </summary> /// <param name="administratorInfo">M_AdminInfo 管理员信息</param> /// <returns></returns> public bool Update(M_AdminInfo administratorInfo) { string strSql = "PR_Manage_Update"; SqlParameter[] cmdParams = GetParameters(administratorInfo); return SqlHelper.ExecuteProc(strSql, cmdParams); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.bll.CheckMulitLogin(); if (!bll.ChkPermissions("AdminEdit")) { function.WriteErrMsg("没有权限进行此项操作"); } Bind(); //验证操作员身份,暂略,是否为超级管理员或普通管理员是否有添加权限。 ViewState["AdminID"] = Request.QueryString["id"]; //判断当前管理员是否存在 if (B_Admin.IsExist(DataConverter.CLng(ViewState["AdminID"]))) { this.lbTitle.Text = "修改管理员"; admin = B_Admin.GetAdminByAdminId(DataConverter.CLng(ViewState["AdminID"])); this.tbdName.Text = admin.AdminName; this.tbdName.Enabled = false; this.HdnPwd.Value = admin.AdminPassword; this.tbPwd.Text = ""; //string[] roleID = admin.RoleList.Split(); for (int m = 0; m < cblRoleList.Items.Count; m++) { this.cblRoleList.Items[m].Selected = false; } for (int i = 0; i < admin.RoleList.Length; i++) { for (int j = 0; j < this.cblRoleList.Items.Count; j++) { if (this.cblRoleList.Items[j].Value == admin.RoleList[i].ToString()) { this.cblRoleList.Items[j].Selected = true; } else { this.cblRoleList.Items[j].Selected = false; } } } //单选框设置 if (admin.EnableMultiLogin) { this.cb1.Checked = true; } else { this.cb1.Checked = false; } if (admin.EnableModifyPassword) { this.cb2.Checked = true; } else { this.cb2.Checked = false; } if (admin.IsLock) { this.cb3.Checked = true; } else { this.cb3.Checked = false; } } else { this.lbTitle.Text = "添加管理员"; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { switch (this.lbTitle.Text) { case ("添加管理员"): if (!Manager_Validator()) { function.WriteErrMsg("管理员名或前台用户名重复!"); } admin.AdminName = this.tbdName.Text; string errmsg=""; if (string.IsNullOrEmpty(this.tbPwd.Text.Trim())) { errmsg = "密码不能为空"; } else { string pwd = this.tbPwd.Text.Trim(); if (pwd.Length < 6) errmsg = "密码长度不能少于6位"; } if (!string.IsNullOrEmpty(errmsg)) { function.WriteErrMsg(errmsg); } admin.AdminPassword = StringHelper.MD5(this.tbPwd.Text); admin.UserName = this.tbdName.Text; //获取管理员角色 StringBuilder sb = new StringBuilder(); foreach (ListItem item in cblRoleList.Items) { if (item.Selected) { string append = item.Value; StringHelper.AppendString(sb, append); } } admin.RoleList = sb.ToString(); admin.EnableMultiLogin = this.cb1.Checked; admin.EnableModifyPassword = this.cb2.Checked; admin.IsLock = this.cb3.Checked; admin.LastLoginIP = ""; admin.LastLoginTime = DateTime.Now; admin.LastLogoutTime = DateTime.Now; admin.LastModifyPasswordTime = DateTime.Now; admin.LoginTimes = 0; admin.RandNumber = ""; admin.Theme = ""; B_Admin.Add(admin); Response.Write("<script type=\"text/javascript\">alert(\"添加成功!\")</script>"); Response.Redirect("AdminManage.aspx"); break; case ("修改管理员"): admin = B_Admin.GetAdminByAdminId(DataConverter.CLng(ViewState["AdminID"])); if (!string.IsNullOrEmpty(this.tbPwd.Text.Trim())) { admin.AdminPassword = StringHelper.MD5(this.tbPwd.Text.Trim()); } //获取管理员角色 StringBuilder sb1 = new StringBuilder(); foreach (ListItem item in cblRoleList.Items) { if (item.Selected) { string append = cblRoleList.SelectedValue; StringHelper.AppendString(sb1, append); } } string role = sb1.ToString(); if (admin.IsSuperAdmin) role = "0," + role; admin.RoleList = role; admin.EnableMultiLogin = this.cb1.Checked; admin.EnableModifyPassword = this.cb2.Checked; admin.IsLock = this.cb3.Checked; B_Admin.Update(admin); Response.Write("<script type=\"text/javascript\">alert(\"修改成功!\")</script>"); Response.Redirect("AdminManage.aspx"); break; } } }
public static bool Add(M_AdminInfo adminInfo) { return dal.Add(adminInfo); }
public static bool Update2(M_AdminInfo adminInfo) { return dal.Update2(adminInfo); }
/// <summary> /// 设定登录状态 /// </summary> /// <param name="model"></param> public static void SetLoginState(M_AdminInfo model) { HttpContext.Current.Response.Cookies["ManageState"]["ManageId"] = model.AdminId.ToString(); HttpContext.Current.Response.Cookies["ManageState"]["LoginName"] = model.AdminName; HttpContext.Current.Response.Cookies["UserState"]["LoginName"] = model.UserName; HttpContext.Current.Response.Cookies["UserState"]["Password"] = model.AdminPassword; HttpContext.Current.Response.Cookies["ManageState"]["Password"] = model.AdminPassword; HttpContext.Current.Response.Cookies["ManageState"]["Role"] = model.RoleList; //HttpContext.Current.Response.Cookies["ManageState"].Expires = DateTime.Now.AddDays(30);//30天有效期 HttpContext.Current.Response.Redirect("~/Manage/Index.aspx"); }