using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Lskj.Control; using Lskj.Core; using Lskj.Data; using Lskj.Util; namespace Lskj.GetSecretKey { public partial class FrmPsdChange : BaseForm { public string oldUserName; public string oldPassWord; public string passWord { get { return this.passWordEidt.Text; } set { this.passWordEidt.Text = value; } } public string userName { get { return this.userNameEdit.Text; } set { this.userNameEdit.Text = value; } } public FrmPsdChange() { InitializeComponent(); this.checkBtn.Click += new EventHandler(OnCheckBtn_Click); this.cancelBtn.Click += new EventHandler(OnCancelBtn_Click); this.passWordEidt.KeyDown += new KeyEventHandler(OnPassWordEidt_KeyDown); } void OnPassWordEidt_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.OnCheckBtn_Click(sender, e); } } void OnCancelBtn_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.No; this.Close(); } void OnCheckBtn_Click(object sender, EventArgs e) { DialogResult result = MessageUtil.Show("是否确认修改?", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { if (string.IsNullOrEmpty(this.passWordEidt.Text)) { MessageUtil.Show("密码不能为空"); return; } if (string.IsNullOrEmpty(this.passWordEidt.Text)) { MessageUtil.Show("用户名不能为空"); return; } try { string sqlNameStr = "ALTER LOGIN {0} WITH NAME = {1}"; sqlNameStr = string.Format(sqlNameStr, oldUserName, userName); string Connection = "Server={0};Database={1};Persist Security Info=True;User ID=" + oldUserName + ";Password=" + oldPassWord + ";Connection Timeout=5;MultipleActiveResultSets=true"; Connection = AESUtil.Encrypt(Connection); SqlHelper._connection = null; if (DBConfig.Instance.CreateConnection(Connection)) { SqlHelper.ExecuteNonQuery(sqlNameStr); this.oldUserName = this.userName; } string sqlPsdStr = "ALTER LOGIN {0} WITH PASSWORD = '{1}'"; sqlPsdStr = string.Format(sqlPsdStr, userName, passWord); string nConnection = "Server={0};Database={1};Persist Security Info=True;User ID=" + userName + ";Password=" + oldPassWord + ";Connection Timeout=5;MultipleActiveResultSets=true"; nConnection = AESUtil.Encrypt(nConnection); SqlHelper._connection = null; if (DBConfig.Instance.CreateConnection(nConnection)) { SqlHelper.ExecuteNonQuery(sqlPsdStr); this.oldPassWord = passWord; } } catch (Exception ex) { MessageUtil.Show(ex.Message); return; } this.DialogResult = DialogResult.OK; this.Close(); } } } }