pwd.cs
上传用户:chizxy
上传日期:2014-11-29
资源大小:407k
文件大小:8k
源码类别:

其他行业

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. namespace MKIms3
  9. {
  10. /// <summary>
  11. /// pwd 的摘要说明。
  12. /// </summary>
  13. public class pwd : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Label label1;
  16. private System.Windows.Forms.Label label2;
  17. private System.Windows.Forms.Label label3;
  18. private System.Windows.Forms.TextBox txt_old_pwd;
  19. private System.Windows.Forms.TextBox txt_new_pwd;
  20. private System.Windows.Forms.TextBox txt_same_pwd;
  21. private System.Windows.Forms.Button btn_ok;
  22. private System.Windows.Forms.Button btn_esc;
  23. private System.Windows.Forms.PictureBox pictureBox1;
  24. /// <summary>
  25. /// 必需的设计器变量。
  26. /// </summary>
  27. private System.ComponentModel.Container components = null;
  28. public pwd()
  29. {
  30. //
  31. // Windows 窗体设计器支持所必需的
  32. //
  33. InitializeComponent();
  34. //
  35. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  36. //
  37. }
  38. /// <summary>
  39. /// 清理所有正在使用的资源。
  40. /// </summary>
  41. protected override void Dispose( bool disposing )
  42. {
  43. if( disposing )
  44. {
  45. if(components != null)
  46. {
  47. components.Dispose();
  48. }
  49. }
  50. base.Dispose( disposing );
  51. }
  52. #region Windows 窗体设计器生成的代码
  53. /// <summary>
  54. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  55. /// 此方法的内容。
  56. /// </summary>
  57. private void InitializeComponent()
  58. {
  59. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(pwd));
  60. this.label1 = new System.Windows.Forms.Label();
  61. this.label2 = new System.Windows.Forms.Label();
  62. this.label3 = new System.Windows.Forms.Label();
  63. this.txt_old_pwd = new System.Windows.Forms.TextBox();
  64. this.txt_new_pwd = new System.Windows.Forms.TextBox();
  65. this.txt_same_pwd = new System.Windows.Forms.TextBox();
  66. this.btn_ok = new System.Windows.Forms.Button();
  67. this.btn_esc = new System.Windows.Forms.Button();
  68. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  69. this.SuspendLayout();
  70. // 
  71. // label1
  72. // 
  73. this.label1.Location = new System.Drawing.Point(144, 16);
  74. this.label1.Name = "label1";
  75. this.label1.Size = new System.Drawing.Size(56, 23);
  76. this.label1.TabIndex = 0;
  77. this.label1.Text = "旧密码";
  78. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  79. // 
  80. // label2
  81. // 
  82. this.label2.Location = new System.Drawing.Point(144, 48);
  83. this.label2.Name = "label2";
  84. this.label2.Size = new System.Drawing.Size(56, 23);
  85. this.label2.TabIndex = 1;
  86. this.label2.Text = "新密码";
  87. this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  88. // 
  89. // label3
  90. // 
  91. this.label3.Location = new System.Drawing.Point(144, 80);
  92. this.label3.Name = "label3";
  93. this.label3.Size = new System.Drawing.Size(56, 23);
  94. this.label3.TabIndex = 2;
  95. this.label3.Text = "确认密码";
  96. this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  97. // 
  98. // txt_old_pwd
  99. // 
  100. this.txt_old_pwd.Location = new System.Drawing.Point(208, 16);
  101. this.txt_old_pwd.Name = "txt_old_pwd";
  102. this.txt_old_pwd.PasswordChar = '*';
  103. this.txt_old_pwd.Size = new System.Drawing.Size(112, 21);
  104. this.txt_old_pwd.TabIndex = 3;
  105. this.txt_old_pwd.Text = "";
  106. // 
  107. // txt_new_pwd
  108. // 
  109. this.txt_new_pwd.Location = new System.Drawing.Point(208, 48);
  110. this.txt_new_pwd.Name = "txt_new_pwd";
  111. this.txt_new_pwd.PasswordChar = '*';
  112. this.txt_new_pwd.Size = new System.Drawing.Size(112, 21);
  113. this.txt_new_pwd.TabIndex = 4;
  114. this.txt_new_pwd.Text = "";
  115. // 
  116. // txt_same_pwd
  117. // 
  118. this.txt_same_pwd.Location = new System.Drawing.Point(208, 80);
  119. this.txt_same_pwd.Name = "txt_same_pwd";
  120. this.txt_same_pwd.PasswordChar = '*';
  121. this.txt_same_pwd.Size = new System.Drawing.Size(112, 21);
  122. this.txt_same_pwd.TabIndex = 5;
  123. this.txt_same_pwd.Text = "";
  124. // 
  125. // btn_ok
  126. // 
  127. this.btn_ok.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  128. this.btn_ok.Location = new System.Drawing.Point(152, 120);
  129. this.btn_ok.Name = "btn_ok";
  130. this.btn_ok.Size = new System.Drawing.Size(56, 24);
  131. this.btn_ok.TabIndex = 6;
  132. this.btn_ok.Text = "确认";
  133. this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click);
  134. // 
  135. // btn_esc
  136. // 
  137. this.btn_esc.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  138. this.btn_esc.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  139. this.btn_esc.Location = new System.Drawing.Point(240, 120);
  140. this.btn_esc.Name = "btn_esc";
  141. this.btn_esc.Size = new System.Drawing.Size(56, 24);
  142. this.btn_esc.TabIndex = 7;
  143. this.btn_esc.Text = "退出";
  144. // 
  145. // pictureBox1
  146. // 
  147. this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  148. this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
  149. this.pictureBox1.Location = new System.Drawing.Point(8, 8);
  150. this.pictureBox1.Name = "pictureBox1";
  151. this.pictureBox1.Size = new System.Drawing.Size(128, 136);
  152. this.pictureBox1.TabIndex = 8;
  153. this.pictureBox1.TabStop = false;
  154. // 
  155. // pwd
  156. // 
  157. this.AcceptButton = this.btn_ok;
  158. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  159. this.CancelButton = this.btn_esc;
  160. this.ClientSize = new System.Drawing.Size(336, 157);
  161. this.Controls.Add(this.pictureBox1);
  162. this.Controls.Add(this.btn_esc);
  163. this.Controls.Add(this.btn_ok);
  164. this.Controls.Add(this.txt_same_pwd);
  165. this.Controls.Add(this.txt_new_pwd);
  166. this.Controls.Add(this.txt_old_pwd);
  167. this.Controls.Add(this.label3);
  168. this.Controls.Add(this.label2);
  169. this.Controls.Add(this.label1);
  170. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  171. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  172. this.Name = "pwd";
  173. this.ShowInTaskbar = false;
  174. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  175. this.Text = "用户密码修改";
  176. this.ResumeLayout(false);
  177. }
  178. #endregion
  179. private void btn_ok_Click(object sender, System.EventArgs e)
  180. {
  181. string pwd = this.txt_old_pwd.Text.Trim();
  182. string newpwd = this.txt_new_pwd.Text.Trim();
  183. string samepwd = this.txt_same_pwd.Text.Trim();
  184. if(pwd.Length==0 || newpwd.Length == 0 || samepwd.Length == 0)
  185. {
  186. MessageBox.Show("所有输入不能为空,请检查您的输入!","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
  187. }
  188. else
  189. {
  190. if(check_old_pwd(pwd))
  191. {
  192. change_pwd(newpwd, samepwd);
  193. }
  194. }
  195. }
  196. private bool check_old_pwd(string pwd)
  197. {
  198. DataBase myDB = new DataBase();
  199. SqlDataReader myReader = null;
  200. SqlParameter[] myParamers={new SqlParameter("@u_name",SqlDbType.Char,10)} ;
  201. myParamers[0].Value = App.u_name;
  202. myReader = myDB.RunProcedure("up_get_upass",myParamers);
  203. if(myReader!=null)
  204. {
  205. if(myReader.Read())
  206. {
  207. if(myReader["u_pass"].ToString().Trim()==pwd)
  208. {
  209. myReader.Close();
  210. //用户身份合法,可以修改密码
  211. return true;
  212. }
  213. else
  214. {
  215. MessageBox.Show("原始密码错误!","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
  216. return false;
  217. }
  218. }
  219. else
  220. {
  221. MessageBox.Show("当前用户信息已被删除,不能更改密码","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
  222. return false;
  223. }
  224. }
  225. else
  226. {
  227. return false;
  228. }
  229. }
  230. private void change_pwd(string newpwd,string samepwd)
  231. {
  232. if(newpwd == samepwd)
  233. {
  234. DataBase myDB = new DataBase();
  235. SqlParameter[] myParamers={new SqlParameter("@u_name",SqlDbType.Char,10),
  236.   new SqlParameter("@u_pass",SqlDbType.Char,10)
  237.   } ;
  238. myParamers[0].Value = App.u_name;
  239. myParamers[1].Value = newpwd;
  240. if(myDB.RunProcedure_Nr("up_change_pwd ",myParamers))
  241. {
  242. MessageBox.Show("密码修改成功,请保管好您的密码!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
  243. }
  244. else
  245. {
  246. MessageBox.Show("系统错误,密码修改不成功!","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
  247. }
  248. }
  249. else
  250. {
  251. MessageBox.Show("两次输入密码不一致!","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
  252. }
  253. }
  254. }
  255. }