password.cs
上传用户:fuyouda
上传日期:2021-03-17
资源大小:8619k
文件大小:9k
源码类别:

Windows编程

开发平台:

C/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.OleDb;
  8. namespace WindowsApplication1
  9. {
  10. /// <summary>
  11. /// password 的摘要说明。
  12. /// </summary>
  13. public class password : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Label label1;
  16. private System.Windows.Forms.TextBox textBox1;
  17. private System.Windows.Forms.Label label2;
  18. private System.Windows.Forms.TextBox textBox2;
  19. private System.Windows.Forms.Label label3;
  20. private System.Windows.Forms.TextBox textBox3;
  21. private System.Windows.Forms.Button button1;
  22. private System.Windows.Forms.Button button2;
  23. private System.Windows.Forms.Label label4;
  24. private System.Windows.Forms.TextBox textBox4;
  25. /// <summary>
  26. /// 必需的设计器变量。
  27. /// </summary>
  28. private System.ComponentModel.Container components = null;
  29. public password()
  30. {
  31. //
  32. // Windows 窗体设计器支持所必需的
  33. //
  34. InitializeComponent();
  35. //
  36. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  37. //
  38. }
  39. /// <summary>
  40. /// 清理所有正在使用的资源。
  41. /// </summary>
  42. protected override void Dispose( bool disposing )
  43. {
  44. if( disposing )
  45. {
  46. if(components != null)
  47. {
  48. components.Dispose();
  49. }
  50. }
  51. base.Dispose( disposing );
  52. }
  53. #region Windows 窗体设计器生成的代码
  54. /// <summary>
  55. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  56. /// 此方法的内容。
  57. /// </summary>
  58. private void InitializeComponent()
  59. {
  60. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(password));
  61. this.label2 = new System.Windows.Forms.Label();
  62. this.textBox2 = new System.Windows.Forms.TextBox();
  63. this.label3 = new System.Windows.Forms.Label();
  64. this.textBox3 = new System.Windows.Forms.TextBox();
  65. this.button1 = new System.Windows.Forms.Button();
  66. this.button2 = new System.Windows.Forms.Button();
  67. this.label1 = new System.Windows.Forms.Label();
  68. this.textBox1 = new System.Windows.Forms.TextBox();
  69. this.textBox4 = new System.Windows.Forms.TextBox();
  70. this.label4 = new System.Windows.Forms.Label();
  71. this.SuspendLayout();
  72. // 
  73. // label2
  74. // 
  75. this.label2.BackColor = System.Drawing.Color.Transparent;
  76. this.label2.ForeColor = System.Drawing.Color.Red;
  77. this.label2.Location = new System.Drawing.Point(56, 128);
  78. this.label2.Name = "label2";
  79. this.label2.Size = new System.Drawing.Size(152, 16);
  80. this.label2.TabIndex = 2;
  81. this.label2.Text = "新密码(3-20个字符):";
  82. // 
  83. // textBox2
  84. // 
  85. this.textBox2.Location = new System.Drawing.Point(56, 152);
  86. this.textBox2.Name = "textBox2";
  87. this.textBox2.Size = new System.Drawing.Size(152, 21);
  88. this.textBox2.TabIndex = 3;
  89. this.textBox2.Text = "";
  90. // 
  91. // label3
  92. // 
  93. this.label3.BackColor = System.Drawing.Color.Transparent;
  94. this.label3.ForeColor = System.Drawing.Color.Red;
  95. this.label3.Location = new System.Drawing.Point(56, 192);
  96. this.label3.Name = "label3";
  97. this.label3.Size = new System.Drawing.Size(160, 16);
  98. this.label3.TabIndex = 4;
  99. this.label3.Text = "确认密码(3-20个字符):";
  100. // 
  101. // textBox3
  102. // 
  103. this.textBox3.Location = new System.Drawing.Point(56, 216);
  104. this.textBox3.Name = "textBox3";
  105. this.textBox3.Size = new System.Drawing.Size(152, 21);
  106. this.textBox3.TabIndex = 5;
  107. this.textBox3.Text = "";
  108. // 
  109. // button1
  110. // 
  111. this.button1.BackColor = System.Drawing.Color.Transparent;
  112. this.button1.ForeColor = System.Drawing.Color.Red;
  113. this.button1.Location = new System.Drawing.Point(48, 256);
  114. this.button1.Name = "button1";
  115. this.button1.Size = new System.Drawing.Size(64, 32);
  116. this.button1.TabIndex = 6;
  117. this.button1.Text = "确认";
  118. this.button1.Click += new System.EventHandler(this.button1_Click);
  119. // 
  120. // button2
  121. // 
  122. this.button2.BackColor = System.Drawing.Color.Transparent;
  123. this.button2.ForeColor = System.Drawing.Color.Red;
  124. this.button2.Location = new System.Drawing.Point(152, 256);
  125. this.button2.Name = "button2";
  126. this.button2.Size = new System.Drawing.Size(64, 32);
  127. this.button2.TabIndex = 7;
  128. this.button2.Text = "取消";
  129. // 
  130. // label1
  131. // 
  132. this.label1.BackColor = System.Drawing.Color.Transparent;
  133. this.label1.ForeColor = System.Drawing.Color.Red;
  134. this.label1.Location = new System.Drawing.Point(56, 72);
  135. this.label1.Name = "label1";
  136. this.label1.Size = new System.Drawing.Size(56, 16);
  137. this.label1.TabIndex = 0;
  138. this.label1.Text = "原密码:";
  139. // 
  140. // textBox1
  141. // 
  142. this.textBox1.Location = new System.Drawing.Point(56, 88);
  143. this.textBox1.Name = "textBox1";
  144. this.textBox1.Size = new System.Drawing.Size(152, 21);
  145. this.textBox1.TabIndex = 1;
  146. this.textBox1.Text = "";
  147. this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  148. // 
  149. // textBox4
  150. // 
  151. this.textBox4.Location = new System.Drawing.Point(56, 40);
  152. this.textBox4.Name = "textBox4";
  153. this.textBox4.Size = new System.Drawing.Size(152, 21);
  154. this.textBox4.TabIndex = 9;
  155. this.textBox4.Text = "";
  156. // 
  157. // label4
  158. // 
  159. this.label4.BackColor = System.Drawing.Color.Transparent;
  160. this.label4.ForeColor = System.Drawing.Color.Red;
  161. this.label4.Location = new System.Drawing.Point(56, 16);
  162. this.label4.Name = "label4";
  163. this.label4.Size = new System.Drawing.Size(56, 16);
  164. this.label4.TabIndex = 8;
  165. this.label4.Text = "用户名:";
  166. // 
  167. // password
  168. // 
  169. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  170. this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
  171. this.ClientSize = new System.Drawing.Size(272, 304);
  172. this.Controls.Add(this.textBox4);
  173. this.Controls.Add(this.label4);
  174. this.Controls.Add(this.button2);
  175. this.Controls.Add(this.button1);
  176. this.Controls.Add(this.textBox3);
  177. this.Controls.Add(this.label3);
  178. this.Controls.Add(this.textBox2);
  179. this.Controls.Add(this.label2);
  180. this.Controls.Add(this.textBox1);
  181. this.Controls.Add(this.label1);
  182. this.ForeColor = System.Drawing.Color.Red;
  183. this.Name = "password";
  184. this.Text = "修改密码";
  185. this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_TextChanged);
  186. this.Load += new System.EventHandler(this.password_Load);
  187. this.ResumeLayout(false);
  188. }
  189. #endregion
  190. private void password_Load(object sender, System.EventArgs e)
  191. {
  192. this.textBox2.Enabled=false;
  193. this.textBox3.Enabled=false;
  194. }
  195. private void button1_Click(object sender, System.EventArgs e)
  196. {
  197. /*OleDbConnection conn2=new OleDbConnection(@"provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+ "\xqwy.mdb");
  198. conn2.Open();
  199. OleDbDataAdapter da=new OleDbDataAdapter("select * from user1",conn2);
  200. DataSet ds=new DataSet();
  201. da.Fill(ds);
  202. DataTable dt=new DataTable();
  203. dt=ds.Tables[0];
  204. DataRow dr=dt.NewRow();
  205. if(this.textBox1.Text==dr[1].ToString())
  206. if(this.textBox4.Text==dr[0].ToString())
  207. {
  208. dr.Delete();
  209. MessageBox.Show("删除成功");
  210. }*/
  211. try
  212. {
  213. OleDbConnection conn2=new OleDbConnection(@"provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+ "\xqwy.mdb");
  214. conn2.Open();
  215. string strsql="select * from user1 where name='"+this.textBox4.Text.Trim()+"' and passwd='"+this.textBox1.Text.Trim()+"'";
  216. OleDbDataAdapter da=new OleDbDataAdapter(strsql,conn2);
  217. DataSet ds=new DataSet();
  218. da.Fill(ds);
  219. DataTable mytable=new DataTable();
  220. mytable=ds.Tables[0];
  221. if(this.button1.Text=="确认")
  222. {
  223. if(mytable.Rows.Count==1)
  224. {
  225. this.textBox2.Enabled=true;
  226. this.textBox3.Enabled=true;
  227. this.button1.Text="修改";
  228. }
  229. else
  230. {
  231. this.textBox2.Enabled=false;
  232. this.textBox3.Enabled=false;
  233. this.button1.Text="确认";
  234. }
  235. }
  236. else
  237. {
  238. DataRow row1;
  239. row1=mytable.Rows[0];
  240. row1[1]=this.textBox3.Text.Trim();
  241. OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);
  242. da.Update(mytable);
  243. MessageBox.Show("密码修改成功!");
  244. //string strsql2="update user1 set passwd='"+this.textBox3.Text.Trim()+"'";
  245. }
  246. conn2.Close();
  247. }
  248. catch(Exception err)
  249. {
  250. MessageBox.Show(err.Message);
  251. }
  252. }
  253. private void textBox1_TextChanged(object sender, System.EventArgs e)
  254. {
  255. }
  256. private void textBox1_TextChanged(object sender, System.Windows.Forms.KeyEventArgs e)
  257. {
  258. }
  259. }
  260. }