protected void btnLogin_Click(object sender, EventArgs e) { string strMsgError = ""; string strUsername = tbUsername.Value.ToString().Trim(); if ("".Equals(strUsername)) { strMsgError += "用户名不能为空!\n"; } string strPassword = tbPassword.Value.ToString(); if ("".Equals(strPassword)) { strMsgError += "密码不能为空!\n"; } if (!"".Equals(strMsgError)) { HelperUtility.showAlert(strMsgError, "login.aspx"); } // 验证完毕,提交数据 strPassword = HelperCrypto.encode(strPassword, "DES"); int intAdminID; string strPurviews; int intEnabled; int intIsDeleted; BllAdmin.login(strUsername, strPassword, out intAdminID, out strPurviews, out intEnabled, out intIsDeleted); if (intAdminID > 0) { if (intEnabled == 1 && intIsDeleted == 0) { // 用户名密码验证正确,保存到cookie里 string strCKName = "AdminLogin"; if (cbRememberMe.Checked) { string strCKKey = "username"; string strCKValue = strUsername; HelperCookie.setCookie(strCKName, strCKKey, strCKValue, 7 * 24 * 60); strCKKey = "password"; strCKValue = strPassword; HelperCookie.setCookie(strCKName, strCKKey, strCKValue, 7 * 24 * 60); } else { // 如果没有勾选记住我复选框,就要清除cookie里的登录数据 // 将过期时间设置为-1即可清除保存的值 HelperCookie.removeCookie(strCKName); } // 保存到Session里 Session["AdminID"] = intAdminID; Session["Purviews"] = strPurviews; Response.Redirect("home.aspx"); } else { string strOPMsg = "<script>"; strOPMsg += "alert('登录失败!此用户已暂停使用!请联系网络管理员!');"; strOPMsg += "location='login.aspx';</script>"; Response.Write(strOPMsg); } } else { string strOPMsg = "<script>"; strOPMsg += "alert('登录失败!用户名密码不正确,请重新输入!');"; strOPMsg += "location='login.aspx';</script>"; Response.Write(strOPMsg); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (!HelperUtility.hasPurviewOP("SysAdmin_add")) { string strUrl = "/BackManager/home.aspx"; HelperUtility.showAlert("没有操作权限", strUrl); } string strMsgError = ""; string strUsername = tbUsername.Value.ToString().Trim(); if ("".Equals(strUsername)) { strMsgError += "用户名不能为空!\n"; } if (strUsername.Length < 4 || strUsername.Length > 12) { strMsgError += "用户名长度必须在4 ~ 12之间!\n"; } if (BllAdmin.hasUsername(strUsername)) { strMsgError += "用户名已存在,请取过!\n"; } string strPassword = tbPassword.Value.ToString(); if ("".Equals(strPassword)) { strMsgError += "密码不能为空!\n"; } if (strPassword.Length < 4 || strPassword.Length > 12) { strMsgError += "密码长度必须在4 ~ 12之间!\n"; } string strPassword2 = tbPassword2.Value.ToString(); if ("".Equals(strPassword2)) { strMsgError += "确认密码不能为空!\n"; } if (!strPassword.Equals(strPassword2)) { strMsgError += "两次输入的密码必须相同!\n"; } strPassword = HelperCrypto.encode(strPassword, "DES"); string strRealName = tbRealName.Value.ToString().Trim(); if (strRealName.Length > 6) { strMsgError += "真实姓名长度不能大于6个字符!\n"; } string strMobilePhone = tbMobilePhone.Value.ToString().Trim(); if (!HelperUtility.isMobilePhone(strMobilePhone)) { strMsgError += "手机号码格式不正确!\n"; } if (!"".Equals(strMsgError)) { HelperUtility.showAlert(strMsgError, "add.aspx"); } // 验证完毕,提交数据 ModelAdmin model = new ModelAdmin(); model.username = strUsername; model.password = strPassword; model.real_name = strRealName; model.mobile_phone = strMobilePhone; model.purviews = getSelectedCheckBox(); int intId = BllAdmin.add(model); if (intId > 0) { string strUrl = "list.aspx"; HelperUtility.showAlert("添加成功!", strUrl); } else { string strUrl = "add.aspx"; HelperUtility.showAlert("添加失败,请联系管理员!", strUrl); } }
protected void btnEdit_Click(object sender, EventArgs e) { if (!HelperUtility.hasPurviewOP("SysAdmin_update")) { string strUrl = "edit.aspx?id=" + ViewState["id"] + "&page=" + ViewState["page"]; HelperUtility.showAlert("没有操作权限", strUrl); } int intId = Convert.ToInt32(ViewState["id"]); int intPage = Convert.ToInt32(ViewState["page"]); string strMsgError = ""; string strPassword = tbPassword.Value.ToString(); if (!"".Equals(strPassword)) { if (strPassword.Length < 4 || strPassword.Length > 12) { strMsgError += "密码长度必须在4 ~ 12之间!\n"; } string strPassword2 = tbPassword2.Value.ToString(); if ("".Equals(strPassword2)) { strMsgError += "确认密码不能为空!\n"; } if (!strPassword.Equals(strPassword2)) { strMsgError += "两次输入的密码必须相同!\n"; } strPassword = HelperCrypto.encode(strPassword, "DES"); } string strRealName = tbRealName.Value.ToString().Trim(); if (strRealName.Length > 6) { strMsgError += "真实姓名长度不能大于6个字符!\n"; } string strMobilePhone = tbMobilePhone.Value.ToString().Trim(); if (!HelperUtility.isMobilePhone(strMobilePhone)) { strMsgError += "手机号码格式不正确!\n"; } if (!"".Equals(strMsgError)) { HelperUtility.showAlert(strMsgError, "edit.aspx?id=" + intId + "&page=" + intPage); } // 开始更新 ModelAdmin model = BllAdmin.getById(intId); if (!"".Equals(strPassword)) { model.password = strPassword; } model.real_name = strRealName; model.mobile_phone = strMobilePhone; if (!(model.username == "rush" || model.username == "wumin")) { model.purviews = getSelectedCheckBox(); } BllAdmin.update(model); Response.Redirect("/BackManager/admin/list.aspx?page=" + intPage); }