protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { var admin = this.Session["LoginAdmin"] as Model.Admin; if (admin == null) { this.Response.Write(common.Common.GetJSMsgBox("对不起,获取当前用户错误。")); return; } if (admin.ID == -100) { this.Response.Write(common.Common.GetJSMsgBox("对不起,超级用户账号不允许修改密码。")); return; } var pwd = this.Request.Form["txtPwd"]; var newPwd = this.Request.Form["txtNewPwd"]; var cpwd = this.Request.Form["txtConfirmPwd"]; if (PubFunc.Md5(pwd.ToString()) != admin.Password) { this.Response.Write(common.Common.GetJSMsgBox("对不起,原密码不正确。")); return; } if (newPwd.ToString() != cpwd.ToString()) { this.Response.Write(common.Common.GetJSMsgBox("对不起,新密码不一致。")); return; } var ctx = new DataContext(); var bll = new BLLBase(); ctx.BeginTransaction(); try { bll.Update(ctx, new Admin() { ID = admin.ID, Password = PubFunc.Md5(newPwd) }); ctx.CommitTransaction(); this.Response.Write(common.Common.GetJSMsgBox("修改成功")); } catch (Exception exception) { ctx.RollBackTransaction(); this.Response.Write(common.Common.GetJSMsgBox("对不起,修改密码发生错误,错误:" + exception.Message)); } finally { ctx.CloseConnection(); } } }
private AjaxResult ResetPwd(int id) { BLL.BLLBase bll = new BLLBase(); AjaxResult re = null; this.ctx.BeginTransaction(); try { bll.Update(this.ctx, new Admin() { ID = id, Password = PubFunc.Md5("123456") }); this.ctx.CommitTransaction(); re = new AjaxResult() { Success = 1 }; } catch (Exception ex) { this.ctx.RollBackTransaction(); re = new AjaxResult() { Success = 0, Message = "操作失败,原因:" + ex.Message }; } finally { this.ctx.CloseConnection(); } return(re); }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { AjaxResult response = null; var txtLgName = Request.Form["txtLgName"]; var txtPwd = Request.Form["txtPwd"]; var txtName = Request.Form["txtName"]; var txtEmail = Request.Form["txtMail"]; var txtQQ = Request.Form["txtQQ"]; var txtMob = Request.Form["txtMob"]; var txtRemark = Request.Form["txtRemark"]; if (string.IsNullOrEmpty(txtLgName)) { response = new AjaxResult() { Success = 0, Message = "登录名不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } if (string.IsNullOrEmpty(txtPwd)) { response = new AjaxResult() { Success = 0, Message = "密码不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } if (string.IsNullOrEmpty(txtName)) { response = new AjaxResult() { Success = 0, Message = "用户名不能为空。" }; this.Response.Write(common.Common.GetJSMsgBox(response.Message)); return; } var dt = new Model.Admin() { CreateDate = DateTime.Now, Email = txtEmail, LoginName = txtLgName, ModifyDate = DateTime.Now, Name = txtName, Password = PubFunc.Md5(txtPwd), QQ = txtQQ, Mob = txtMob, Remark = txtRemark }; DataContext dc = new DataContext(); dc.BeginTransaction(); try { var bll = new BLL.BLLBase(); var id = bll.Add(dc, dt); dc.CommitTransaction(); response = new AjaxResult() { Success = 1, Message = "操作成功", Data = id }; } catch (Exception exception) { dc.RollBackTransaction(); response = new AjaxResult() { Success = 0, Message = "操作失败:" + exception.Message, Data = 0 }; } finally { dc.CloseConnection(); } this.Response.Write(common.Common.GetJSMsgBox(response.Message)); } }