FormChangePassWord.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using ProjectBase.Util;
  12. using SIMDP.BLL;
  13. using System.Collections;
  14. using ProjectBase.Data.Encrypt;
  15. using ProjectBase.Data.Logs;
  16. using SIMDP.Model;
  17. using ProjectBase.Data.BaseDAL;
  18. namespace SIMDP.View
  19. {
  20. public partial class FormChangePassWord : DevExpress.XtraEditors.XtraForm
  21. {
  22. //BlAuthoryUser blUser = new BlAuthoryUser();
  23. public FormChangePassWord()
  24. {
  25. InitializeComponent();
  26. InitControls();
  27. }
  28. private void InitControls()
  29. {
  30. if (!string.IsNullOrEmpty(SysEnvironment.CurrentLoginID))
  31. {
  32. this.txt_Account.Text = SysEnvironment.CurrentLoginID;
  33. }
  34. //if (string.IsNullOrEmpty(SysEnvironment.passWordMD5))
  35. //{
  36. // this.txt_OldPassWord.Text = "000000";
  37. //}
  38. }
  39. private void btn_Cancel_Click(object sender, EventArgs e)
  40. {
  41. this.Close();
  42. }
  43. private void btn_Rest_Click(object sender, EventArgs e)
  44. {
  45. if (DevExpress.XtraEditors.XtraMessageBox.Show("您确定要重置密码吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
  46. {
  47. return;
  48. }
  49. if (string.IsNullOrEmpty(txt_Account.Text))
  50. {
  51. DevExpress.XtraEditors.XtraMessageBox.Show("请输入账号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  52. return;
  53. }
  54. try
  55. {
  56. MoAuthoryUser user = BLLFactory<BlAuthoryUser>.Instance.FindByID(txt_Account.Text);
  57. if (user == null)
  58. {
  59. DevExpress.XtraEditors.XtraMessageBox.Show("该账号不存在,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  60. return;
  61. }
  62. Hashtable hash = new Hashtable();
  63. hash.Add("login_passwd", EncodeHelper.EncryptString("000000"));
  64. bool flag = BLLFactory<BlAuthoryUser>.Instance.Update(txt_Account.Text, hash, "authory_user", null);
  65. if (flag)
  66. {
  67. if (SysEnvironment.CurrentLoginID == null)
  68. {
  69. MoLogLogIn moLogIn = new MoLogLogIn
  70. {
  71. Account = user.LoginAccount,
  72. Name = user.UserName,
  73. GroupId = user.GroupId,
  74. Description = "用户重置登录密码!",
  75. Ip = SysEnvironment.Ip,
  76. Mac = SysEnvironment.Mac,
  77. Time = DateTime.Now
  78. };
  79. BLLFactory<BlLogLogIn>.Instance.Insert(moLogIn);
  80. }
  81. else
  82. {
  83. MoLogLogIn moLogIn = new MoLogLogIn
  84. {
  85. Account = SysEnvironment.CurrentLoginID,
  86. Name = SysEnvironment.CurrentLoginName,
  87. GroupId = SysEnvironment.CurrentLoginGroupId,
  88. Description = SysEnvironment.CurrentLoginName + "重置用户【" + user.UserName + "】的登录密码!",
  89. Ip = SysEnvironment.Ip,
  90. Mac = SysEnvironment.Mac,
  91. Time = DateTime.Now
  92. };
  93. BLLFactory<BlLogLogIn>.Instance.Insert(moLogIn);
  94. }
  95. DevExpress.XtraEditors.XtraMessageBox.Show("重置密码成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  96. this.DialogResult = DialogResult.OK;
  97. this.Close();
  98. }
  99. else
  100. {
  101. DevExpress.XtraEditors.XtraMessageBox.Show("重置密码失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. DevExpress.XtraEditors.XtraMessageBox.Show("重置密码失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  107. LogHelper.log.Error(string.Format("修改数据库authory_user出现错误:{0}", ex.ToString()));
  108. }
  109. }
  110. private void btn_Ok_Click(object sender, EventArgs e)
  111. {
  112. if (string.IsNullOrEmpty(txt_Account.Text))
  113. {
  114. DevExpress.XtraEditors.XtraMessageBox.Show("请输入账号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  115. return;
  116. }
  117. if (string.IsNullOrEmpty(txt_OldPassWord.Text))
  118. {
  119. DevExpress.XtraEditors.XtraMessageBox.Show("请输入原密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  120. return;
  121. }
  122. if (string.IsNullOrEmpty(txt_NewPassWord.Text))
  123. {
  124. DevExpress.XtraEditors.XtraMessageBox.Show("请输入新密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  125. return;
  126. }
  127. if (string.IsNullOrEmpty(txt_ConfirmPassWord.Text))
  128. {
  129. DevExpress.XtraEditors.XtraMessageBox.Show("请输入确认新密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  130. return;
  131. }
  132. if (txt_OldPassWord.Text == txt_NewPassWord.Text)
  133. {
  134. DevExpress.XtraEditors.XtraMessageBox.Show("输入的原密码与新密码相同,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  135. return;
  136. }
  137. if (txt_ConfirmPassWord.Text != txt_NewPassWord.Text)
  138. {
  139. DevExpress.XtraEditors.XtraMessageBox.Show("确认新密码与新密码不一致,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  140. return;
  141. }
  142. try
  143. {
  144. MoAuthoryUser user = BLLFactory<BlAuthoryUser>.Instance.FindByID(txt_Account.Text);
  145. if (user == null)
  146. {
  147. DevExpress.XtraEditors.XtraMessageBox.Show("该账号不存在,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  148. return;
  149. }
  150. if (EncodeHelper.DecryptString(user.LoginPasswd,true) != txt_OldPassWord.Text)
  151. {
  152. DevExpress.XtraEditors.XtraMessageBox.Show("原密码不正确,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  153. return;
  154. }
  155. Hashtable hash = new Hashtable();
  156. hash.Add("login_passwd", EncodeHelper.EncryptString(txt_ConfirmPassWord.Text));
  157. bool flag = BLLFactory<BlAuthoryUser>.Instance.Update(txt_Account.Text, hash, "authory_user", null);
  158. if (flag)
  159. {
  160. if (SysEnvironment.CurrentLoginID == null)
  161. {
  162. MoLogLogIn moLogIn = new MoLogLogIn
  163. {
  164. Account = user.LoginAccount,
  165. Name = user.UserName,
  166. GroupId = user.GroupId,
  167. Description = "用户修改登录密码!",
  168. Ip = SysEnvironment.Ip,
  169. Mac = SysEnvironment.Mac,
  170. Time = DateTime.Now
  171. };
  172. BLLFactory<BlLogLogIn>.Instance.Insert(moLogIn);
  173. }
  174. else
  175. {
  176. MoLogLogIn moLogIn = new MoLogLogIn
  177. {
  178. Account = SysEnvironment.CurrentLoginID,
  179. Name = SysEnvironment.CurrentLoginName,
  180. GroupId = SysEnvironment.CurrentLoginGroupId,
  181. Description = SysEnvironment.CurrentLoginName + "修改用户【" + user.UserName + "】的登录密码!",
  182. Ip = SysEnvironment.Ip,
  183. Mac = SysEnvironment.Mac,
  184. Time = DateTime.Now
  185. };
  186. BLLFactory<BlLogLogIn>.Instance.Insert(moLogIn);
  187. }
  188. DevExpress.XtraEditors.XtraMessageBox.Show("修改密码成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  189. this.DialogResult = DialogResult.OK;
  190. this.Close();
  191. }
  192. else
  193. {
  194. DevExpress.XtraEditors.XtraMessageBox.Show("修改密码失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  195. }
  196. }
  197. catch (Exception ex)
  198. {
  199. DevExpress.XtraEditors.XtraMessageBox.Show("修改密码失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  200. LogHelper.log.Error(string.Format("修改数据库authory_user出现错误:{0}", ex.ToString()));
  201. }
  202. }
  203. }
  204. }