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

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. /// modizh 的摘要说明。
  12. /// </summary>
  13. public class modizh : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Button button11;
  16. private System.Windows.Forms.Button button12;
  17. private System.Windows.Forms.Button button13;
  18. private System.Windows.Forms.Button button14;
  19. private System.Windows.Forms.Button button15;
  20. private System.Windows.Forms.Button button16;
  21. private System.Windows.Forms.Button button17;
  22. private System.Windows.Forms.Button button18;
  23. private System.Windows.Forms.Button button19;
  24. private BindingManagerBase MyBind;
  25. private System.Windows.Forms.GroupBox groupBox1;
  26. private System.Windows.Forms.TextBox textBox6;
  27. private System.Windows.Forms.TextBox textBox5;
  28. private System.Windows.Forms.TextBox textBox4;
  29. private System.Windows.Forms.TextBox textBox3;
  30. private System.Windows.Forms.TextBox textBox2;
  31. private System.Windows.Forms.TextBox textBox1;
  32. private System.Windows.Forms.Label label6;
  33. private System.Windows.Forms.Label label5;
  34. private System.Windows.Forms.Label label4;
  35. private System.Windows.Forms.Label label3;
  36. private System.Windows.Forms.Label label2;
  37. private System.Windows.Forms.Label label1;
  38. private System.Windows.Forms.TextBox textBox7;
  39. /// <summary>
  40. /// 必需的设计器变量。
  41. /// </summary>
  42. private System.ComponentModel.Container components = null;
  43. public modizh()
  44. {
  45. //
  46. // Windows 窗体设计器支持所必需的
  47. //
  48. InitializeComponent();
  49. //
  50. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  51. //
  52. }
  53. /// <summary>
  54. /// 清理所有正在使用的资源。
  55. /// </summary>
  56. protected override void Dispose( bool disposing )
  57. {
  58. if( disposing )
  59. {
  60. if(components != null)
  61. {
  62. components.Dispose();
  63. }
  64. }
  65. base.Dispose( disposing );
  66. }
  67. #region Windows 窗体设计器生成的代码
  68. /// <summary>
  69. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  70. /// 此方法的内容。
  71. /// </summary>
  72. private void InitializeComponent()
  73. {
  74. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(modizh));
  75. this.button11 = new System.Windows.Forms.Button();
  76. this.button12 = new System.Windows.Forms.Button();
  77. this.button13 = new System.Windows.Forms.Button();
  78. this.button14 = new System.Windows.Forms.Button();
  79. this.button15 = new System.Windows.Forms.Button();
  80. this.button16 = new System.Windows.Forms.Button();
  81. this.button17 = new System.Windows.Forms.Button();
  82. this.button18 = new System.Windows.Forms.Button();
  83. this.button19 = new System.Windows.Forms.Button();
  84. this.groupBox1 = new System.Windows.Forms.GroupBox();
  85. this.textBox6 = new System.Windows.Forms.TextBox();
  86. this.textBox5 = new System.Windows.Forms.TextBox();
  87. this.textBox4 = new System.Windows.Forms.TextBox();
  88. this.textBox3 = new System.Windows.Forms.TextBox();
  89. this.textBox2 = new System.Windows.Forms.TextBox();
  90. this.textBox1 = new System.Windows.Forms.TextBox();
  91. this.label6 = new System.Windows.Forms.Label();
  92. this.label5 = new System.Windows.Forms.Label();
  93. this.label4 = new System.Windows.Forms.Label();
  94. this.label3 = new System.Windows.Forms.Label();
  95. this.label2 = new System.Windows.Forms.Label();
  96. this.label1 = new System.Windows.Forms.Label();
  97. this.textBox7 = new System.Windows.Forms.TextBox();
  98. this.groupBox1.SuspendLayout();
  99. this.SuspendLayout();
  100. // 
  101. // button11
  102. // 
  103. this.button11.BackColor = System.Drawing.Color.Transparent;
  104. this.button11.Location = new System.Drawing.Point(416, 224);
  105. this.button11.Name = "button11";
  106. this.button11.Size = new System.Drawing.Size(75, 30);
  107. this.button11.TabIndex = 30;
  108. this.button11.Text = "关闭程序";
  109. this.button11.Click += new System.EventHandler(this.button11_Click);
  110. // 
  111. // button12
  112. // 
  113. this.button12.BackColor = System.Drawing.Color.Transparent;
  114. this.button12.Location = new System.Drawing.Point(232, 264);
  115. this.button12.Name = "button12";
  116. this.button12.Size = new System.Drawing.Size(75, 30);
  117. this.button12.TabIndex = 29;
  118. this.button12.Text = "修改记录";
  119. this.button12.Click += new System.EventHandler(this.button12_Click);
  120. // 
  121. // button13
  122. // 
  123. this.button13.BackColor = System.Drawing.Color.Transparent;
  124. this.button13.Location = new System.Drawing.Point(128, 264);
  125. this.button13.Name = "button13";
  126. this.button13.Size = new System.Drawing.Size(75, 30);
  127. this.button13.TabIndex = 28;
  128. this.button13.Text = "增加记录";
  129. this.button13.Click += new System.EventHandler(this.button13_Click);
  130. // 
  131. // button14
  132. // 
  133. this.button14.BackColor = System.Drawing.Color.Transparent;
  134. this.button14.Location = new System.Drawing.Point(32, 264);
  135. this.button14.Name = "button14";
  136. this.button14.Size = new System.Drawing.Size(75, 30);
  137. this.button14.TabIndex = 27;
  138. this.button14.Text = "新建记录";
  139. this.button14.Click += new System.EventHandler(this.button14_Click);
  140. // 
  141. // button15
  142. // 
  143. this.button15.BackColor = System.Drawing.Color.Transparent;
  144. this.button15.Location = new System.Drawing.Point(328, 224);
  145. this.button15.Name = "button15";
  146. this.button15.Size = new System.Drawing.Size(75, 30);
  147. this.button15.TabIndex = 26;
  148. this.button15.Text = "末一条记录";
  149. this.button15.Click += new System.EventHandler(this.button15_Click);
  150. // 
  151. // button16
  152. // 
  153. this.button16.BackColor = System.Drawing.Color.Transparent;
  154. this.button16.Location = new System.Drawing.Point(224, 224);
  155. this.button16.Name = "button16";
  156. this.button16.Size = new System.Drawing.Size(75, 30);
  157. this.button16.TabIndex = 25;
  158. this.button16.Text = "后一条记录";
  159. this.button16.Click += new System.EventHandler(this.button16_Click);
  160. // 
  161. // button17
  162. // 
  163. this.button17.BackColor = System.Drawing.Color.Transparent;
  164. this.button17.Location = new System.Drawing.Point(128, 224);
  165. this.button17.Name = "button17";
  166. this.button17.Size = new System.Drawing.Size(75, 30);
  167. this.button17.TabIndex = 23;
  168. this.button17.Text = "前一条记录";
  169. this.button17.Click += new System.EventHandler(this.button17_Click);
  170. // 
  171. // button18
  172. // 
  173. this.button18.BackColor = System.Drawing.Color.Transparent;
  174. this.button18.Location = new System.Drawing.Point(32, 224);
  175. this.button18.Name = "button18";
  176. this.button18.Size = new System.Drawing.Size(75, 30);
  177. this.button18.TabIndex = 22;
  178. this.button18.Text = "第一条记录";
  179. this.button18.Click += new System.EventHandler(this.button18_Click);
  180. // 
  181. // button19
  182. // 
  183. this.button19.BackColor = System.Drawing.Color.Transparent;
  184. this.button19.Location = new System.Drawing.Point(328, 264);
  185. this.button19.Name = "button19";
  186. this.button19.Size = new System.Drawing.Size(75, 30);
  187. this.button19.TabIndex = 24;
  188. this.button19.Text = "删除记录";
  189. this.button19.Click += new System.EventHandler(this.button19_Click);
  190. // 
  191. // groupBox1
  192. // 
  193. this.groupBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBox1.BackgroundImage")));
  194. this.groupBox1.Controls.Add(this.textBox6);
  195. this.groupBox1.Controls.Add(this.textBox5);
  196. this.groupBox1.Controls.Add(this.textBox4);
  197. this.groupBox1.Controls.Add(this.textBox3);
  198. this.groupBox1.Controls.Add(this.textBox2);
  199. this.groupBox1.Controls.Add(this.textBox1);
  200. this.groupBox1.Controls.Add(this.label6);
  201. this.groupBox1.Controls.Add(this.label5);
  202. this.groupBox1.Controls.Add(this.label4);
  203. this.groupBox1.Controls.Add(this.label3);
  204. this.groupBox1.Controls.Add(this.label2);
  205. this.groupBox1.Controls.Add(this.label1);
  206. this.groupBox1.Controls.Add(this.textBox7);
  207. this.groupBox1.Location = new System.Drawing.Point(24, 32);
  208. this.groupBox1.Name = "groupBox1";
  209. this.groupBox1.Size = new System.Drawing.Size(456, 176);
  210. this.groupBox1.TabIndex = 31;
  211. this.groupBox1.TabStop = false;
  212. this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
  213. // 
  214. // textBox6
  215. // 
  216. this.textBox6.Location = new System.Drawing.Point(320, 136);
  217. this.textBox6.Name = "textBox6";
  218. this.textBox6.Size = new System.Drawing.Size(128, 21);
  219. this.textBox6.TabIndex = 23;
  220. this.textBox6.Text = "";
  221. this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged);
  222. // 
  223. // textBox5
  224. // 
  225. this.textBox5.Location = new System.Drawing.Point(320, 80);
  226. this.textBox5.Name = "textBox5";
  227. this.textBox5.Size = new System.Drawing.Size(128, 21);
  228. this.textBox5.TabIndex = 22;
  229. this.textBox5.Text = "";
  230. this.textBox5.TextChanged += new System.EventHandler(this.textBox5_TextChanged);
  231. // 
  232. // textBox4
  233. // 
  234. this.textBox4.Location = new System.Drawing.Point(320, 32);
  235. this.textBox4.Name = "textBox4";
  236. this.textBox4.Size = new System.Drawing.Size(128, 21);
  237. this.textBox4.TabIndex = 21;
  238. this.textBox4.Text = "";
  239. this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);
  240. // 
  241. // textBox3
  242. // 
  243. this.textBox3.Location = new System.Drawing.Point(88, 136);
  244. this.textBox3.Name = "textBox3";
  245. this.textBox3.Size = new System.Drawing.Size(128, 21);
  246. this.textBox3.TabIndex = 20;
  247. this.textBox3.Text = "";
  248. // 
  249. // textBox2
  250. // 
  251. this.textBox2.Location = new System.Drawing.Point(88, 80);
  252. this.textBox2.Name = "textBox2";
  253. this.textBox2.Size = new System.Drawing.Size(128, 21);
  254. this.textBox2.TabIndex = 19;
  255. this.textBox2.Text = "";
  256. this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
  257. // 
  258. // textBox1
  259. // 
  260. this.textBox1.Location = new System.Drawing.Point(88, 32);
  261. this.textBox1.Name = "textBox1";
  262. this.textBox1.Size = new System.Drawing.Size(128, 21);
  263. this.textBox1.TabIndex = 18;
  264. this.textBox1.Text = "";
  265. this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  266. // 
  267. // label6
  268. // 
  269. this.label6.BackColor = System.Drawing.Color.Transparent;
  270. this.label6.Location = new System.Drawing.Point(256, 144);
  271. this.label6.Name = "label6";
  272. this.label6.Size = new System.Drawing.Size(56, 16);
  273. this.label6.TabIndex = 17;
  274. this.label6.Text = "备  注:";
  275. // 
  276. // label5
  277. // 
  278. this.label5.BackColor = System.Drawing.Color.Transparent;
  279. this.label5.Location = new System.Drawing.Point(264, 85);
  280. this.label5.Name = "label5";
  281. this.label5.Size = new System.Drawing.Size(56, 16);
  282. this.label5.TabIndex = 16;
  283. this.label5.Text = "电  话:";
  284. this.label5.Click += new System.EventHandler(this.label5_Click);
  285. // 
  286. // label4
  287. // 
  288. this.label4.BackColor = System.Drawing.Color.Transparent;
  289. this.label4.Location = new System.Drawing.Point(256, 37);
  290. this.label4.Name = "label4";
  291. this.label4.Size = new System.Drawing.Size(72, 16);
  292. this.label4.TabIndex = 15;
  293. this.label4.Text = "常住人口:";
  294. this.label4.Click += new System.EventHandler(this.label4_Click);
  295. // 
  296. // label3
  297. // 
  298. this.label3.BackColor = System.Drawing.Color.Transparent;
  299. this.label3.Location = new System.Drawing.Point(32, 141);
  300. this.label3.Name = "label3";
  301. this.label3.Size = new System.Drawing.Size(56, 16);
  302. this.label3.TabIndex = 14;
  303. this.label3.Text = "户  型:";
  304. this.label3.Click += new System.EventHandler(this.label3_Click);
  305. // 
  306. // label2
  307. // 
  308. this.label2.BackColor = System.Drawing.Color.Transparent;
  309. this.label2.Location = new System.Drawing.Point(32, 86);
  310. this.label2.Name = "label2";
  311. this.label2.Size = new System.Drawing.Size(56, 16);
  312. this.label2.TabIndex = 13;
  313. this.label2.Text = "户  主:";
  314. this.label2.Click += new System.EventHandler(this.label2_Click);
  315. // 
  316. // label1
  317. // 
  318. this.label1.BackColor = System.Drawing.Color.Transparent;
  319. this.label1.Location = new System.Drawing.Point(32, 38);
  320. this.label1.Name = "label1";
  321. this.label1.Size = new System.Drawing.Size(56, 18);
  322. this.label1.TabIndex = 12;
  323. this.label1.Text = "门牌号:";
  324. this.label1.Click += new System.EventHandler(this.label1_Click);
  325. // 
  326. // textBox7
  327. // 
  328. this.textBox7.Location = new System.Drawing.Point(88, 136);
  329. this.textBox7.Name = "textBox7";
  330. this.textBox7.Size = new System.Drawing.Size(128, 21);
  331. this.textBox7.TabIndex = 20;
  332. this.textBox7.Text = "textBox3";
  333. this.textBox7.TextChanged += new System.EventHandler(this.textBox7_TextChanged);
  334. // 
  335. // modizh
  336. // 
  337. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  338. this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
  339. this.ClientSize = new System.Drawing.Size(528, 312);
  340. this.Controls.Add(this.groupBox1);
  341. this.Controls.Add(this.button11);
  342. this.Controls.Add(this.button12);
  343. this.Controls.Add(this.button13);
  344. this.Controls.Add(this.button14);
  345. this.Controls.Add(this.button15);
  346. this.Controls.Add(this.button16);
  347. this.Controls.Add(this.button17);
  348. this.Controls.Add(this.button18);
  349. this.Controls.Add(this.button19);
  350. this.Name = "modizh";
  351. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  352. this.Text = "modizh";
  353. this.Load += new System.EventHandler(this.modizh_Load);
  354. this.groupBox1.ResumeLayout(false);
  355. this.ResumeLayout(false);
  356. }
  357. #endregion
  358. private void modizh_Load(object sender, System.EventArgs e)
  359. {
  360. string connstr,selectcmd;
  361. connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\xqwy.mdb";
  362. selectcmd="select * from zhb";
  363. OleDbConnection conn=new OleDbConnection(connstr);
  364. conn.Open();
  365. OleDbDataAdapter da=new OleDbDataAdapter(selectcmd,conn);
  366. //OleDbDataAdapter oleDbDataAdapter1=new OleDbDataAdapter(selectcmd,conn);
  367. DataSet ds=new DataSet();
  368. //DataSet dataSet1=new DataSet();
  369. da.Fill(ds);
  370. DataTable mytable=new DataTable();
  371. mytable=ds.Tables[0];
  372. MyBind=this.groupBox1.BindingContext[mytable];
  373. //oleDbDataAdapter1.Fill(dataSet1);
  374. //this.dataGrid1.DataSource=mytable;
  375. //conn.Close();
  376. try
  377. {
  378. //this.oleDbDataAdapter1.Fill(this.dataSet1,"user1");
  379. this.textBox1.DataBindings.Add("Text",mytable,"Mph");
  380. this.textBox2.DataBindings.Add("Text",mytable,"Hz");
  381. this.textBox3.DataBindings.Add("Text",mytable,"Hx");
  382. this.textBox4.DataBindings.Add("Text",mytable,"Czr");
  383. this.textBox5.DataBindings.Add("Text",mytable,"Dh");
  384. this.textBox6.DataBindings.Add("Text",mytable,"Bz");
  385. }
  386. catch(Exception Err)
  387. {
  388. MessageBox.Show("打开数据库表错误:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  389. return;
  390. }
  391. }
  392. private void button18_Click(object sender, System.EventArgs e)
  393. {
  394. this.MyBind.Position=0;
  395. }
  396. private void button17_Click(object sender, System.EventArgs e)
  397. {
  398. this.MyBind.Position--;
  399. }
  400. private void button16_Click(object sender, System.EventArgs e)
  401. {
  402. this.MyBind.Position++;
  403. }
  404. private void button15_Click(object sender, System.EventArgs e)
  405. {
  406. try
  407. {
  408. this.MyBind.Position=this.MyBind.Count-1;
  409. }
  410. catch(Exception Err)
  411. {
  412. MessageBox.Show("打开数据库表错误:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  413. return;
  414. }
  415. }
  416. private void button13_Click(object sender, System.EventArgs e)
  417. {
  418. //增加记录
  419. if(this.textBox2.Text.Length<1|this.textBox3.Text.Length<1)
  420. {
  421. MessageBox.Show("客户所有信息必须填写!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  422. return;
  423. }
  424. try
  425. {
  426. string connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\xqwy.mdb";
  427. OleDbConnection conn=new OleDbConnection(connstr);
  428. conn.Open();
  429. string StrSQL="INSERT INTO zhb (Mph,Hz,Hx,Czr,Dh,Bz)VALUES('"+this.textBox1.Text.Trim()+"','"+this.textBox2.Text.Trim()+"','"+this.textBox3.Text.Trim()+"','"+this.textBox4.Text.Trim()+"','"+this.textBox5.Text.Trim()+"','"+this.textBox6.Text.Trim()+"')";
  430. OleDbCommand cmd=new OleDbCommand(StrSQL,conn);
  431. cmd.ExecuteNonQuery();
  432. MessageBox.Show("增加数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  433. }
  434. catch(Exception Err)
  435. {
  436. MessageBox.Show("增加数据集记录操作失败:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  437. }
  438. }
  439. private void button19_Click(object sender, System.EventArgs e)
  440. {
  441. try
  442. {
  443. string connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\xqwy.mdb";
  444. OleDbConnection conn=new OleDbConnection(connstr);
  445. conn.Open();
  446. string StrSQL="DELETE FROM  zhb WHERE ";
  447. StrSQL+=" Mph='"+this.textBox1.Text+"'";
  448. OleDbCommand cmd=new OleDbCommand(StrSQL,conn);
  449. cmd.ExecuteNonQuery();
  450. MessageBox.Show("删除数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  451. }
  452. catch(Exception Err)
  453. {
  454. MessageBox.Show("删除数据集记录操作失败:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  455. }
  456. }
  457. private void button14_Click(object sender, System.EventArgs e)
  458. {
  459. this.textBox1.Text="";
  460. this.textBox2.Text="";
  461. this.textBox3.Text="";
  462. this.textBox4.Text="";
  463. this.textBox5.Text="";
  464. this.textBox6.Text="";
  465. }
  466. private void button12_Click(object sender, System.EventArgs e)
  467. {
  468. //修改记录
  469. try
  470. {
  471. OleDbConnection conn2=new OleDbConnection(@"provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+ "\xqwy.mdb");
  472. conn2.Open();
  473. string strsql="select * from zhb where Mph='"+this.textBox1.Text.Trim()+"' ";
  474. OleDbDataAdapter da=new OleDbDataAdapter(strsql,conn2);
  475. DataSet ds=new DataSet();
  476. da.Fill(ds);
  477. DataTable mytable=new DataTable();
  478. mytable=ds.Tables[0];
  479. DataRow row1;
  480. row1=mytable.Rows[0];
  481. row1[0]=this.textBox1.Text.Trim();
  482. row1[1]=this.textBox2.Text.Trim();
  483. row1[2]=this.textBox3.Text.Trim();
  484. row1[3]=this.textBox4.Text.Trim();
  485. row1[4]=this.textBox5.Text.Trim();
  486. row1[5]=this.textBox6.Text.Trim();
  487. OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);
  488. da.Update(mytable);
  489. MessageBox.Show("记录修改成功!");
  490. conn2.Close();
  491. }
  492. catch(Exception err)
  493. {
  494. MessageBox.Show(err.Message);
  495. }
  496. }
  497. private void button11_Click(object sender, System.EventArgs e)
  498. {
  499. this.Close();
  500. }
  501. private void label8_Click(object sender, System.EventArgs e)
  502. {
  503. }
  504. private void label7_Click(object sender, System.EventArgs e)
  505. {
  506. }
  507. private void textBox7_TextChanged(object sender, System.EventArgs e)
  508. {
  509. }
  510. private void textBox4_TextChanged(object sender, System.EventArgs e)
  511. {
  512. }
  513. private void textBox2_TextChanged(object sender, System.EventArgs e)
  514. {
  515. }
  516. private void textBox1_TextChanged(object sender, System.EventArgs e)
  517. {
  518. }
  519. private void label5_Click(object sender, System.EventArgs e)
  520. {
  521. }
  522. private void label4_Click(object sender, System.EventArgs e)
  523. {
  524. }
  525. private void label2_Click(object sender, System.EventArgs e)
  526. {
  527. }
  528. private void label1_Click(object sender, System.EventArgs e)
  529. {
  530. }
  531. private void groupBox1_Enter(object sender, System.EventArgs e)
  532. {
  533. }
  534. private void textBox6_TextChanged(object sender, System.EventArgs e)
  535. {
  536. }
  537. private void textBox5_TextChanged(object sender, System.EventArgs e)
  538. {
  539. }
  540. private void label3_Click(object sender, System.EventArgs e)
  541. {
  542. }
  543. }
  544. }