protected void newSubmit_Click(object sender, EventArgs e) { if (IsValid) { using (LandRoverDBDataContext ctx = new LandRoverDBDataContext()) { var admin = from u in ctx.L_Administrators where u.Username == newUser.Text.Trim() select u.ID; if (admin.Count() > 0) { Alert.ShowAlert(Page, "该登录名已存在,请重新输入!", Alert.AlertState.Nothing, string.Empty); return; } L_Administrators ent = new L_Administrators(); ent.AddTime = DateTime.Now; ent.DealerID = 0; ent.DisplayName = newName.Text.Trim(); ent.Email = newEmail.Text.Trim(); ent.LastIP = Request.UserHostAddress; ent.LastLogin = DateTime.Now; ent.Username = newUser.Text.Trim(); ent.Password = Helper.GetPasswordString(ent.Username, newPass1.Text.Trim()); ent.RoleID = int.Parse(newRole.SelectedValue); ent.Status = 1; ctx.L_Administrators.InsertOnSubmit(ent); ctx.SubmitChanges(); } Alert.ShowAlert(HttpContext.Current, "添加成功!", Alert.AlertState.OpenInThisWindow, Request.Url.ToString()); } }
protected void edtSubmit_Click(object sender, EventArgs e) { if (IsValid) { int uid; if (!int.TryParse(Request.QueryString["id"], out uid)) { if (Request.QueryString["m"] == "profile") { uid = (int)Session["lr_admin_id"]; } else { Alert.ShowAlert(Page, "参数非法!", Alert.AlertState.OpenInThisWindow, "AdminMgmt.aspx"); return; } } using (LandRoverDBDataContext ctx = new LandRoverDBDataContext()) { L_Administrators admin; if (lineAuth.Visible) { string oldpass = Helper.GetPasswordString((string)Session["lr_admin_user"], edtPass.Text.Trim()); admin = (from a in ctx.L_Administrators where a.ID == uid && a.Password == oldpass select a).SingleOrDefault(); if (admin == null) { Alert.ShowAlert(Page, "密码错误,请重试!", Alert.AlertState.Nothing, string.Empty); return; } } else { admin = (from u in ctx.L_Administrators where u.ID == uid select u).Single(); } admin.DisplayName = edtName.Text.Trim(); if ((int)Session["lr_admin_id"] == uid && !string.IsNullOrEmpty(edtPass1.Text)) { admin.Password = Helper.GetPasswordString(admin.Username, edtPass1.Text.Trim()); } admin.Email = edtEmail.Text.Trim(); admin.RoleID = int.Parse(edtRole.SelectedValue); ctx.SubmitChanges(); } Alert.ShowAlert(HttpContext.Current, "修改成功!", Alert.AlertState.OpenInThisWindow, Request.Url.ToString()); } }
private void ResetPasswordAction() { int uid; if (!int.TryParse(Request.QueryString["id"], out uid)) { Alert.ShowAlert(Page, "参数非法!", Alert.AlertState.OpenInThisWindow, "AdminMgmt.aspx"); return; } string newpass = Helper.GetRandString(8); using (LandRoverDBDataContext ctx = new LandRoverDBDataContext()) { var admin = (from u in ctx.L_Administrators where u.ID == uid select u).Single(); Session["lr_admin_reset"] = new string[] { admin.Username, newpass }; admin.Password = Helper.GetPasswordString(admin.Username, newpass); ctx.SubmitChanges(); } Response.Redirect(string.Format("~/AdminMgmt.aspx?m=reset&id={0}", uid)); }
protected void toggleUserStatus(object sender, EventArgs e) { int uid; if (!int.TryParse(Request.QueryString["id"], out uid)) { Alert.ShowAlert(Page, "参数非法!", Alert.AlertState.OpenInThisWindow, "AdminMgmt.aspx"); return; } using (LandRoverDBDataContext ctx = new LandRoverDBDataContext()) { var user = (from a in ctx.L_Administrators where a.ID == uid && a.Status != (byte)UserStatus.Deleted select a).Single(); if (user.Status == 1) user.Status = 2; else if (user.Status == 2) user.Status = 1; ctx.SubmitChanges(); } Alert.ShowAlert(Page, "操作成功!", Alert.AlertState.OpenInThisWindow, Request.Url.ToString()); }
protected void btnGo_Click(object sender, EventArgs e) { if (IsValid) { if (tbCode.Text.Trim().ToUpper() != (string)Session[Helper.CaptchaKey]) { //Alert.ShowAlert(Page, "验证码错误。", Alert.AlertState.Nothing, string.Empty); msgError.Text = "验证码错误。"; return; } string passStr = Helper.GetPasswordString(tbName.Text, tbPass.Text); using (LandRoverDBDataContext ctx = new LandRoverDBDataContext()) { var admin = (from a in ctx.L_Administrators where a.Username == tbName.Text && a.Password == passStr select a).SingleOrDefault(); if (admin != null) { switch (admin.Status) { case 1: admin.LastIP = Request.UserHostAddress; admin.LastLogin = DateTime.Now; ctx.SubmitChanges(); Session[Helper.UserKey] = admin.Username; Session["lr_admin_id"] = admin.ID; Session["lr_admin_user"] = admin.Username; Session["lr_admin_name"] = admin.DisplayName; Session["lr_admin_role"] = admin.RoleID; string redirect = Request.QueryString["rt"]; if (string.IsNullOrEmpty(redirect)) { Response.Redirect("~/KeepMeInformed.aspx"); } else { Response.Redirect(redirect); } break; case 2: //Alert.ShowAlert(Page, "帐号被禁用,请联系管理员。", Alert.AlertState.Nothing, string.Empty); msgError.Text = "帐号被禁用,请联系管理员。"; break; default: break; } } else { //Alert.ShowAlert(Page, "用户名或密码错误。", Alert.AlertState.Nothing, string.Empty); msgError.Text = "用户名或密码错误。"; return; } } } }