using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; using SIMDP.Util; using SIMDP.BLL; using System.Collections; using ProjectBase.Data.Encrypt; using ProjectBase.Data.Logs; using SIMDP.Model; using ProjectBase.Data.BaseDAL; namespace SIMDP { public partial class FormChangePassWord : DevExpress.XtraEditors.XtraForm { //BlAuthoryUser blUser = new BlAuthoryUser(); public FormChangePassWord() { InitializeComponent(); InitControls(); } private void InitControls() { if (!string.IsNullOrEmpty(SysEnvironment.CurrentLoginID)) { this.txt_Account.Text = SysEnvironment.CurrentLoginID; } //if (string.IsNullOrEmpty(SysEnvironment.passWordMD5)) //{ // this.txt_OldPassWord.Text = "000000"; //} } private void btn_Cancel_Click(object sender, EventArgs e) { this.Close(); } private void btn_Rest_Click(object sender, EventArgs e) { if (DevExpress.XtraEditors.XtraMessageBox.Show("您确定要重置密码吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) { return; } if (string.IsNullOrEmpty(txt_Account.Text)) { DevExpress.XtraEditors.XtraMessageBox.Show("请输入账号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { MoAuthoryUser user = BLLFactory.Instance.FindByID(txt_Account.Text); if (user == null) { DevExpress.XtraEditors.XtraMessageBox.Show("该账号不存在,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Hashtable hash = new Hashtable(); hash.Add("login_passwd", EncodeHelper.EncryptString("000000")); bool flag = BLLFactory.Instance.Update(txt_Account.Text, hash, "authory_user", null); if (flag) { if (SysEnvironment.CurrentLoginID == null) { MoLogLogIn moLogIn = new MoLogLogIn { Account = user.LoginAccount, Name = user.UserName, GroupId = user.GroupId, Description = "用户重置登录密码!", Ip = SysEnvironment.Ip, Mac = SysEnvironment.Mac, Time = DateTime.Now }; BLLFactory.Instance.Insert(moLogIn); } else { MoLogLogIn moLogIn = new MoLogLogIn { Account = SysEnvironment.CurrentLoginID, Name = SysEnvironment.CurrentLoginName, GroupId = SysEnvironment.CurrentLoginGroupId, Description = SysEnvironment.CurrentLoginName + "重置用户【" + user.UserName + "】的登录密码!", Ip = SysEnvironment.Ip, Mac = SysEnvironment.Mac, Time = DateTime.Now }; BLLFactory.Instance.Insert(moLogIn); } DevExpress.XtraEditors.XtraMessageBox.Show("重置密码成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; this.Close(); } else { DevExpress.XtraEditors.XtraMessageBox.Show("重置密码失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show("重置密码失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); LogHelper.log.Error(string.Format("修改数据库authory_user出现错误:{0}", ex.ToString())); } } private void btn_Ok_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txt_Account.Text)) { DevExpress.XtraEditors.XtraMessageBox.Show("请输入账号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txt_OldPassWord.Text)) { DevExpress.XtraEditors.XtraMessageBox.Show("请输入原密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txt_NewPassWord.Text)) { DevExpress.XtraEditors.XtraMessageBox.Show("请输入新密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(txt_ConfirmPassWord.Text)) { DevExpress.XtraEditors.XtraMessageBox.Show("请输入确认新密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txt_OldPassWord.Text == txt_NewPassWord.Text) { DevExpress.XtraEditors.XtraMessageBox.Show("输入的原密码与新密码相同,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txt_ConfirmPassWord.Text != txt_NewPassWord.Text) { DevExpress.XtraEditors.XtraMessageBox.Show("确认新密码与新密码不一致,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { MoAuthoryUser user = BLLFactory.Instance.FindByID(txt_Account.Text); if (user == null) { DevExpress.XtraEditors.XtraMessageBox.Show("该账号不存在,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (EncodeHelper.DecryptString(user.LoginPasswd,true) != txt_OldPassWord.Text) { DevExpress.XtraEditors.XtraMessageBox.Show("原密码不正确,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Hashtable hash = new Hashtable(); hash.Add("login_passwd", EncodeHelper.EncryptString(txt_ConfirmPassWord.Text)); bool flag = BLLFactory.Instance.Update(txt_Account.Text, hash, "authory_user", null); if (flag) { if (SysEnvironment.CurrentLoginID == null) { MoLogLogIn moLogIn = new MoLogLogIn { Account = user.LoginAccount, Name = user.UserName, GroupId = user.GroupId, Description = "用户修改登录密码!", Ip = SysEnvironment.Ip, Mac = SysEnvironment.Mac, Time = DateTime.Now }; BLLFactory.Instance.Insert(moLogIn); } else { MoLogLogIn moLogIn = new MoLogLogIn { Account = SysEnvironment.CurrentLoginID, Name = SysEnvironment.CurrentLoginName, GroupId = SysEnvironment.CurrentLoginGroupId, Description = SysEnvironment.CurrentLoginName + "修改用户【" + user.UserName + "】的登录密码!", Ip = SysEnvironment.Ip, Mac = SysEnvironment.Mac, Time = DateTime.Now }; BLLFactory.Instance.Insert(moLogIn); } DevExpress.XtraEditors.XtraMessageBox.Show("修改密码成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; this.Close(); } else { DevExpress.XtraEditors.XtraMessageBox.Show("修改密码失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show("修改密码失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); LogHelper.log.Error(string.Format("修改数据库authory_user出现错误:{0}", ex.ToString())); } } } }