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

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. /// zhgl 的摘要说明。
  12. /// </summary>
  13. public class zhgl : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Panel panel1;
  16. private System.Windows.Forms.DataGrid dataGrid1;
  17. private System.Windows.Forms.TextBox textBox1;
  18. private System.Windows.Forms.Label label2;
  19. private System.Windows.Forms.ComboBox comboBox1;
  20. private System.Windows.Forms.Label label1;
  21. private System.Windows.Forms.Button button1;
  22. private System.Windows.Forms.Button button2;
  23. /// <summary>
  24. /// 必需的设计器变量。
  25. /// </summary>
  26. private System.ComponentModel.Container components = null;
  27. public zhgl()
  28. {
  29. //
  30. // Windows 窗体设计器支持所必需的
  31. //
  32. InitializeComponent();
  33. //
  34. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  35. //
  36. }
  37. /// <summary>
  38. /// 清理所有正在使用的资源。
  39. /// </summary>
  40. protected override void Dispose( bool disposing )
  41. {
  42. if( disposing )
  43. {
  44. if(components != null)
  45. {
  46. components.Dispose();
  47. }
  48. }
  49. base.Dispose( disposing );
  50. }
  51. #region Windows 窗体设计器生成的代码
  52. /// <summary>
  53. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  54. /// 此方法的内容。
  55. /// </summary>
  56. private void InitializeComponent()
  57. {
  58. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(zhgl));
  59. this.panel1 = new System.Windows.Forms.Panel();
  60. this.button2 = new System.Windows.Forms.Button();
  61. this.textBox1 = new System.Windows.Forms.TextBox();
  62. this.label2 = new System.Windows.Forms.Label();
  63. this.comboBox1 = new System.Windows.Forms.ComboBox();
  64. this.label1 = new System.Windows.Forms.Label();
  65. this.button1 = new System.Windows.Forms.Button();
  66. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  67. this.panel1.SuspendLayout();
  68. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  69. this.SuspendLayout();
  70. // 
  71. // panel1
  72. // 
  73. this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage")));
  74. this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  75. this.panel1.Controls.Add(this.button2);
  76. this.panel1.Controls.Add(this.textBox1);
  77. this.panel1.Controls.Add(this.label2);
  78. this.panel1.Controls.Add(this.comboBox1);
  79. this.panel1.Controls.Add(this.label1);
  80. this.panel1.Controls.Add(this.button1);
  81. this.panel1.Location = new System.Drawing.Point(0, 0);
  82. this.panel1.Name = "panel1";
  83. this.panel1.Size = new System.Drawing.Size(584, 64);
  84. this.panel1.TabIndex = 0;
  85. this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
  86. // 
  87. // button2
  88. // 
  89. this.button2.BackColor = System.Drawing.Color.Transparent;
  90. this.button2.Location = new System.Drawing.Point(448, 16);
  91. this.button2.Name = "button2";
  92. this.button2.TabIndex = 10;
  93. this.button2.Text = "修改住户信息";
  94. this.button2.Click += new System.EventHandler(this.button2_Click);
  95. // 
  96. // textBox1
  97. // 
  98. this.textBox1.Location = new System.Drawing.Point(256, 16);
  99. this.textBox1.Name = "textBox1";
  100. this.textBox1.Size = new System.Drawing.Size(64, 21);
  101. this.textBox1.TabIndex = 9;
  102. this.textBox1.Text = "";
  103. // 
  104. // label2
  105. // 
  106. this.label2.BackColor = System.Drawing.Color.Transparent;
  107. this.label2.Location = new System.Drawing.Point(184, 22);
  108. this.label2.Name = "label2";
  109. this.label2.Size = new System.Drawing.Size(80, 16);
  110. this.label2.TabIndex = 8;
  111. this.label2.Text = "设置查询值:";
  112. // 
  113. // comboBox1
  114. // 
  115. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  116. this.comboBox1.Items.AddRange(new object[] {
  117.    "Mph",
  118.    "Hz"});
  119. this.comboBox1.Location = new System.Drawing.Point(96, 16);
  120. this.comboBox1.Name = "comboBox1";
  121. this.comboBox1.Size = new System.Drawing.Size(88, 20);
  122. this.comboBox1.TabIndex = 7;
  123. // 
  124. // label1
  125. // 
  126. this.label1.BackColor = System.Drawing.Color.Transparent;
  127. this.label1.Location = new System.Drawing.Point(8, 22);
  128. this.label1.Name = "label1";
  129. this.label1.Size = new System.Drawing.Size(96, 16);
  130. this.label1.TabIndex = 6;
  131. this.label1.Text = "选择查询条件:";
  132. // 
  133. // button1
  134. // 
  135. this.button1.BackColor = System.Drawing.Color.Transparent;
  136. this.button1.Location = new System.Drawing.Point(328, 16);
  137. this.button1.Name = "button1";
  138. this.button1.TabIndex = 5;
  139. this.button1.Text = "开始查询";
  140. this.button1.Click += new System.EventHandler(this.button1_Click);
  141. // 
  142. // dataGrid1
  143. // 
  144. this.dataGrid1.DataMember = "";
  145. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  146. this.dataGrid1.Location = new System.Drawing.Point(0, 56);
  147. this.dataGrid1.Name = "dataGrid1";
  148. this.dataGrid1.Size = new System.Drawing.Size(568, 280);
  149. this.dataGrid1.TabIndex = 1;
  150. // 
  151. // zhgl
  152. // 
  153. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  154. this.ClientSize = new System.Drawing.Size(568, 336);
  155. this.Controls.Add(this.dataGrid1);
  156. this.Controls.Add(this.panel1);
  157. this.Name = "zhgl";
  158. this.Text = "住户信息管理";
  159. this.panel1.ResumeLayout(false);
  160. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  161. this.ResumeLayout(false);
  162. }
  163. #endregion
  164. private void button2_Click(object sender, System.EventArgs e)
  165. {
  166. modizh mymodizh=new modizh();
  167. mymodizh.Show();
  168. }
  169. private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  170. {
  171. string connstr,selectcmd;
  172. connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\xqwy.mdb";
  173. selectcmd="select * from zhb";
  174. OleDbConnection conn=new OleDbConnection(connstr);
  175. conn.Open();
  176. OleDbDataAdapter da=new OleDbDataAdapter(selectcmd,conn);
  177. DataSet ds=new DataSet();
  178. da.Fill(ds);
  179. DataTable mytable=new DataTable();
  180. mytable=ds.Tables[0];
  181. this.dataGrid1.DataSource=mytable;
  182. }
  183. private void button1_Click(object sender, System.EventArgs e)
  184. {
  185. //查询记录
  186. try
  187. {
  188. string connstr,StrSQL;
  189. connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\xqwy.mdb";
  190. if(this.comboBox1.Text=="所有记录")
  191. StrSQL="SELECT * FROM zhb";
  192. StrSQL="SELECT * FROM zhb WHERE ";
  193. StrSQL+=this.comboBox1.Text+" LIKE  '";
  194. StrSQL+=this.textBox1.Text+"'";
  195. OleDbConnection conn=new OleDbConnection(connstr);
  196. conn.Open();
  197. OleDbDataAdapter da=new OleDbDataAdapter(StrSQL,conn);
  198. DataSet ds=new DataSet();
  199. da.Fill(ds);
  200. DataTable mytable=new DataTable();
  201. mytable=ds.Tables[0];
  202. this.dataGrid1.DataSource=mytable;
  203. OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);
  204. da.Update(mytable);
  205. }
  206. catch(Exception Err)
  207. {
  208. MessageBox.Show("查询数据集记录操作失败:"+Err.Message,"信息提示",
  209. MessageBoxButtons.OK,MessageBoxIcon.Information);
  210. }
  211. }
  212. }
  213. }