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

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. /// wgsf 的摘要说明。
  12. /// </summary>
  13. public class wgsf : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.DataGrid dataGrid1;
  16. private System.Windows.Forms.StatusBar statusBar1;
  17. private System.Windows.Forms.StatusBarPanel statusBarPanel1;
  18. private System.Windows.Forms.StatusBarPanel statusBarPanel2;
  19. private System.Windows.Forms.StatusBarPanel statusBarPanel3;
  20. private System.Windows.Forms.StatusBarPanel statusBarPanel4;
  21. private System.Windows.Forms.StatusBarPanel statusBarPanel5;
  22. private System.Windows.Forms.StatusBarPanel statusBarPanel6;
  23. private System.Windows.Forms.Label label2;
  24. private System.Windows.Forms.ComboBox comboBox1;
  25. private System.Windows.Forms.Label label1;
  26. private System.Windows.Forms.Button button1;
  27. private System.Windows.Forms.ComboBox comboBox2;
  28. private BindingManagerBase MyBind;
  29. /// <summary>
  30. /// 必需的设计器变量。
  31. /// </summary>
  32. private System.ComponentModel.Container components = null;
  33. public wgsf()
  34. {
  35. //
  36. // Windows 窗体设计器支持所必需的
  37. //
  38. InitializeComponent();
  39. //
  40. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  41. //
  42. }
  43. /// <summary>
  44. /// 清理所有正在使用的资源。
  45. /// </summary>
  46. protected override void Dispose( bool disposing )
  47. {
  48. if( disposing )
  49. {
  50. if(components != null)
  51. {
  52. components.Dispose();
  53. }
  54. }
  55. base.Dispose( disposing );
  56. }
  57. #region Windows 窗体设计器生成的代码
  58. /// <summary>
  59. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  60. /// 此方法的内容。
  61. /// </summary>
  62. private void InitializeComponent()
  63. {
  64. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(wgsf));
  65. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  66. this.statusBar1 = new System.Windows.Forms.StatusBar();
  67. this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
  68. this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
  69. this.statusBarPanel3 = new System.Windows.Forms.StatusBarPanel();
  70. this.statusBarPanel4 = new System.Windows.Forms.StatusBarPanel();
  71. this.statusBarPanel5 = new System.Windows.Forms.StatusBarPanel();
  72. this.statusBarPanel6 = new System.Windows.Forms.StatusBarPanel();
  73. this.label2 = new System.Windows.Forms.Label();
  74. this.comboBox1 = new System.Windows.Forms.ComboBox();
  75. this.label1 = new System.Windows.Forms.Label();
  76. this.button1 = new System.Windows.Forms.Button();
  77. this.comboBox2 = new System.Windows.Forms.ComboBox();
  78. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  79. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
  80. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
  81. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).BeginInit();
  82. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).BeginInit();
  83. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel5)).BeginInit();
  84. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel6)).BeginInit();
  85. this.SuspendLayout();
  86. // 
  87. // dataGrid1
  88. // 
  89. this.dataGrid1.DataMember = "";
  90. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  91. this.dataGrid1.Location = new System.Drawing.Point(32, 48);
  92. this.dataGrid1.Name = "dataGrid1";
  93. this.dataGrid1.Size = new System.Drawing.Size(432, 320);
  94. this.dataGrid1.TabIndex = 4;
  95. // 
  96. // statusBar1
  97. // 
  98. this.statusBar1.Location = new System.Drawing.Point(0, 392);
  99. this.statusBar1.Name = "statusBar1";
  100. this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
  101.   this.statusBarPanel1,
  102.   this.statusBarPanel2,
  103.   this.statusBarPanel3,
  104.   this.statusBarPanel4,
  105.   this.statusBarPanel5,
  106.   this.statusBarPanel6});
  107. this.statusBar1.ShowPanels = true;
  108. this.statusBar1.Size = new System.Drawing.Size(504, 24);
  109. this.statusBar1.TabIndex = 5;
  110. this.statusBar1.Text = "statusBar1";
  111. // 
  112. // statusBarPanel1
  113. // 
  114. this.statusBarPanel1.Text = "水费";
  115. // 
  116. // statusBarPanel2
  117. // 
  118. this.statusBarPanel2.Text = "电费";
  119. // 
  120. // statusBarPanel3
  121. // 
  122. this.statusBarPanel3.Text = "气费";
  123. // 
  124. // statusBarPanel4
  125. // 
  126. this.statusBarPanel4.Text = "物管费";
  127. // 
  128. // statusBarPanel5
  129. // 
  130. this.statusBarPanel5.Text = "其他费";
  131. // 
  132. // statusBarPanel6
  133. // 
  134. this.statusBarPanel6.Text = "合计";
  135. // 
  136. // label2
  137. // 
  138. this.label2.BackColor = System.Drawing.Color.Transparent;
  139. this.label2.Location = new System.Drawing.Point(232, 8);
  140. this.label2.Name = "label2";
  141. this.label2.Size = new System.Drawing.Size(96, 16);
  142. this.label2.TabIndex = 9;
  143. this.label2.Text = "设置查询时间:";
  144. // 
  145. // comboBox1
  146. // 
  147. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  148. this.comboBox1.Items.AddRange(new object[] {
  149.    "Bh"});
  150. this.comboBox1.Location = new System.Drawing.Point(48, 24);
  151. this.comboBox1.Name = "comboBox1";
  152. this.comboBox1.Size = new System.Drawing.Size(88, 20);
  153. this.comboBox1.TabIndex = 8;
  154. // 
  155. // label1
  156. // 
  157. this.label1.BackColor = System.Drawing.Color.Transparent;
  158. this.label1.Location = new System.Drawing.Point(40, 8);
  159. this.label1.Name = "label1";
  160. this.label1.Size = new System.Drawing.Size(96, 16);
  161. this.label1.TabIndex = 7;
  162. this.label1.Text = "选择查询条件:";
  163. this.label1.Click += new System.EventHandler(this.label1_Click);
  164. // 
  165. // button1
  166. // 
  167. this.button1.BackColor = System.Drawing.Color.Transparent;
  168. this.button1.Location = new System.Drawing.Point(416, 16);
  169. this.button1.Name = "button1";
  170. this.button1.Size = new System.Drawing.Size(75, 24);
  171. this.button1.TabIndex = 6;
  172. this.button1.Text = "开始查询";
  173. this.button1.Click += new System.EventHandler(this.button1_Click);
  174. // 
  175. // comboBox2
  176. // 
  177. this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  178. this.comboBox2.Location = new System.Drawing.Point(232, 24);
  179. this.comboBox2.Name = "comboBox2";
  180. this.comboBox2.Size = new System.Drawing.Size(136, 20);
  181. this.comboBox2.TabIndex = 10;
  182. // 
  183. // wgsf
  184. // 
  185. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  186. this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
  187. this.ClientSize = new System.Drawing.Size(504, 416);
  188. this.Controls.Add(this.comboBox2);
  189. this.Controls.Add(this.label2);
  190. this.Controls.Add(this.comboBox1);
  191. this.Controls.Add(this.label1);
  192. this.Controls.Add(this.button1);
  193. this.Controls.Add(this.statusBar1);
  194. this.Controls.Add(this.dataGrid1);
  195. this.Name = "wgsf";
  196. this.Load += new System.EventHandler(this.wgsf_Load);
  197. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  198. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
  199. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
  200. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
  201. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).EndInit();
  202. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel5)).EndInit();
  203. ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel6)).EndInit();
  204. this.ResumeLayout(false);
  205. }
  206. #endregion
  207. private void wgsf_Load(object sender, System.EventArgs e)
  208. {
  209. string connstr,selectcmd;
  210. connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\xqwy.mdb";
  211. selectcmd="select * from sfb";
  212. OleDbConnection conn=new OleDbConnection(connstr);
  213. conn.Open();
  214. OleDbDataAdapter da=new OleDbDataAdapter(selectcmd,conn);
  215. //OleDbDataAdapter oleDbDataAdapter1=new OleDbDataAdapter(selectcmd,conn);
  216. DataSet ds=new DataSet();
  217. //DataSet dataSet1=new DataSet();
  218. da.Fill(ds,"sfb");
  219. DataTable mytable=new DataTable();
  220. mytable=ds.Tables[0];
  221. this.dataGrid1.DataSource=mytable;
  222. this.comboBox2.DataBindings.Add("Text",mytable,"Sfsj");
  223. zairu();
  224. }
  225. public void zairu()
  226. {
  227. string sqlstr;
  228. string  connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\xqwy.mdb";
  229. sqlstr="select Bh from sfb";
  230. OleDbConnection conn=new OleDbConnection(connstr);
  231. conn.Open();
  232. OleDbDataAdapter da=new OleDbDataAdapter(sqlstr,conn);
  233. DataSet ds=new DataSet();
  234. da.Fill(ds,"sfb");
  235. DataTable mytable=new DataTable();
  236. mytable=ds.Tables[0];
  237. DataRow myrow;
  238. for(int i=0;i<mytable.Rows.Count;i++)
  239. {
  240. myrow=mytable.Rows[i];
  241. this.comboBox2.Items.Add(myrow[0]);
  242. }
  243. }
  244. public void button1_Click(object sender, System.EventArgs e)
  245. {
  246. try
  247. {
  248. string connstr,StrSQL;
  249. connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\xqwy.mdb";
  250. if(this.comboBox1.Text=="所有记录")
  251. StrSQL="SELECT * FROM Sfb";
  252. StrSQL="SELECT * FROM Sfb WHERE "+this.comboBox1.Text+"='"+this.comboBox2.Text.Trim()+"'";
  253. OleDbConnection conn=new OleDbConnection(connstr);
  254. conn.Open();
  255. OleDbDataAdapter da=new OleDbDataAdapter(StrSQL,conn);
  256. DataSet ds=new DataSet();
  257. da.Fill(ds,"sfb");
  258. DataTable mytable=new DataTable();
  259. mytable=ds.Tables[0];
  260. this.dataGrid1.DataSource=mytable;
  261. //OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);
  262. //da.Update(mytable);
  263. }
  264. catch(Exception Err)
  265. {
  266. MessageBox.Show("查询数据集记录操作失败:"+Err.Message,"信息提示",
  267. MessageBoxButtons.OK,MessageBoxIcon.Information);
  268. }
  269. }
  270. private void label1_Click(object sender, System.EventArgs e)
  271. {
  272. }
  273. }
  274. }