DetailQuery.cs
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:10k
源码类别:

企业管理

开发平台:

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. namespace 财务管理系统
  8. {
  9. /// <summary>
  10. /// DetailQuery 的摘要说明。
  11. /// </summary>
  12. public class DetailQuery : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.DataGrid dataGrid1;
  15. private System.Windows.Forms.GroupBox groupBox1;
  16. private System.Windows.Forms.Button btnSearch;
  17. private System.Windows.Forms.TextBox txt1;
  18. private System.Windows.Forms.Label label2;
  19. private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
  20. private 财务管理系统.DataSet1 dataSet11;
  21. private System.Data.DataView dataView1;
  22. private System.Windows.Forms.GroupBox groupBox2;
  23. private System.Windows.Forms.ComboBox comboBox1;
  24. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  25. private System.Data.SqlClient.SqlConnection sqlConnection1;
  26. /// <summary>
  27. /// 必需的设计器变量。
  28. /// </summary>
  29. private System.ComponentModel.Container components = null;
  30. public DetailQuery()
  31. {
  32. //
  33. // Windows 窗体设计器支持所必需的
  34. //
  35. InitializeComponent();
  36. //
  37. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  38. //
  39. }
  40. /// <summary>
  41. /// 清理所有正在使用的资源。
  42. /// </summary>
  43. protected override void Dispose( bool disposing )
  44. {
  45. if( disposing )
  46. {
  47. if(components != null)
  48. {
  49. components.Dispose();
  50. }
  51. }
  52. base.Dispose( disposing );
  53. }
  54. #region Windows 窗体设计器生成的代码
  55. /// <summary>
  56. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  57. /// 此方法的内容。
  58. /// </summary>
  59. private void InitializeComponent()
  60. {
  61. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DetailQuery));
  62. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  63. this.dataView1 = new System.Data.DataView();
  64. this.dataSet11 = new 财务管理系统.DataSet1();
  65. this.groupBox1 = new System.Windows.Forms.GroupBox();
  66. this.btnSearch = new System.Windows.Forms.Button();
  67. this.txt1 = new System.Windows.Forms.TextBox();
  68. this.label2 = new System.Windows.Forms.Label();
  69. this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
  70. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  71. this.groupBox2 = new System.Windows.Forms.GroupBox();
  72. this.comboBox1 = new System.Windows.Forms.ComboBox();
  73. this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
  74. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  75. ((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
  76. ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
  77. this.groupBox1.SuspendLayout();
  78. this.groupBox2.SuspendLayout();
  79. this.SuspendLayout();
  80. // 
  81. // dataGrid1
  82. // 
  83. this.dataGrid1.CaptionVisible = false;
  84. this.dataGrid1.DataMember = "";
  85. this.dataGrid1.DataSource = this.dataView1;
  86. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  87. this.dataGrid1.Location = new System.Drawing.Point(-8, 69);
  88. this.dataGrid1.Name = "dataGrid1";
  89. this.dataGrid1.ReadOnly = true;
  90. this.dataGrid1.Size = new System.Drawing.Size(720, 416);
  91. this.dataGrid1.TabIndex = 33;
  92. // 
  93. // dataView1
  94. // 
  95. this.dataView1.Table = this.dataSet11.本期明细账簿;
  96. // 
  97. // dataSet11
  98. // 
  99. this.dataSet11.DataSetName = "DataSet1";
  100. this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
  101. // 
  102. // groupBox1
  103. // 
  104. this.groupBox1.Controls.Add(this.btnSearch);
  105. this.groupBox1.Controls.Add(this.txt1);
  106. this.groupBox1.Controls.Add(this.label2);
  107. this.groupBox1.Location = new System.Drawing.Point(0, 2);
  108. this.groupBox1.Name = "groupBox1";
  109. this.groupBox1.Size = new System.Drawing.Size(360, 64);
  110. this.groupBox1.TabIndex = 32;
  111. this.groupBox1.TabStop = false;
  112. // 
  113. // btnSearch
  114. // 
  115. this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
  116. this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  117. this.btnSearch.Location = new System.Drawing.Point(40, 28);
  118. this.btnSearch.Name = "btnSearch";
  119. this.btnSearch.Size = new System.Drawing.Size(72, 23);
  120. this.btnSearch.TabIndex = 6;
  121. this.btnSearch.Text = " 搜索";
  122. this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
  123. // 
  124. // txt1
  125. // 
  126. this.txt1.Location = new System.Drawing.Point(224, 28);
  127. this.txt1.Name = "txt1";
  128. this.txt1.TabIndex = 8;
  129. this.txt1.Text = "";
  130. // 
  131. // label2
  132. // 
  133. this.label2.Location = new System.Drawing.Point(144, 32);
  134. this.label2.Name = "label2";
  135. this.label2.Size = new System.Drawing.Size(56, 16);
  136. this.label2.TabIndex = 7;
  137. this.label2.Text = "科目代码";
  138. // 
  139. // sqlDataAdapter1
  140. // 
  141. this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
  142. this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  143.   new System.Data.Common.DataTableMapping("Table", "本期明细账簿", new System.Data.Common.DataColumnMapping[] {
  144. new System.Data.Common.DataColumnMapping("科目名称", "科目名称"),
  145. new System.Data.Common.DataColumnMapping("会计期间", "会计期间"),
  146. new System.Data.Common.DataColumnMapping("凭证字号", "凭证字号"),
  147. new System.Data.Common.DataColumnMapping("凭证编号", "凭证编号"),
  148. new System.Data.Common.DataColumnMapping("科目代码", "科目代码"),
  149. new System.Data.Common.DataColumnMapping("借方", "借方"),
  150. new System.Data.Common.DataColumnMapping("贷方", "贷方"),
  151. new System.Data.Common.DataColumnMapping("余额方向", "余额方向"),
  152. new System.Data.Common.DataColumnMapping("余额", "余额")})});
  153. // 
  154. // sqlSelectCommand1
  155. // 
  156. this.sqlSelectCommand1.CommandText = "SELECT b.科目名称, a.会计期间, a.凭证字号, a.凭证编号, a.科目代码, a.借方, a.贷方, a.余额方向, a.余额 FROM 本期明细" +
  157. "账簿 a INNER JOIN 科目表 b ON a.科目代码 = b.科目代码 WHERE (a.科目代码 LIKE @Param2)";
  158. this.sqlSelectCommand1.Connection = this.sqlConnection1;
  159. this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 20, "科目代码"));
  160. // 
  161. // groupBox2
  162. // 
  163. this.groupBox2.Controls.Add(this.comboBox1);
  164. this.groupBox2.Location = new System.Drawing.Point(360, 1);
  165. this.groupBox2.Name = "groupBox2";
  166. this.groupBox2.Size = new System.Drawing.Size(344, 63);
  167. this.groupBox2.TabIndex = 34;
  168. this.groupBox2.TabStop = false;
  169. this.groupBox2.Text = "选择要显示在表中的项目";
  170. // 
  171. // comboBox1
  172. // 
  173. this.comboBox1.Location = new System.Drawing.Point(120, 32);
  174. this.comboBox1.Name = "comboBox1";
  175. this.comboBox1.Size = new System.Drawing.Size(121, 20);
  176. this.comboBox1.TabIndex = 0;
  177. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  178. // 
  179. // sqlConnection1
  180. // 
  181. this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo" +
  182. "g=caiwubook;persist security info=False";
  183. // 
  184. // DetailQuery
  185. // 
  186. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  187. this.ClientSize = new System.Drawing.Size(704, 485);
  188. this.Controls.Add(this.groupBox2);
  189. this.Controls.Add(this.dataGrid1);
  190. this.Controls.Add(this.groupBox1);
  191. this.Name = "DetailQuery";
  192. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  193. this.Text = "【明细帐查询】";
  194. this.Load += new System.EventHandler(this.DetailQuery_Load);
  195. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  196. ((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
  197. ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
  198. this.groupBox1.ResumeLayout(false);
  199. this.groupBox2.ResumeLayout(false);
  200. this.ResumeLayout(false);
  201. }
  202. #endregion
  203. //----------显示窗口时读入全部数据--------------
  204. private void DetailQuery_Load(object sender, System.EventArgs e)
  205. {
  206. sqlDataAdapter1.SelectCommand.Parameters[0].Value="%%";
  207. sqlDataAdapter1.Fill(dataSet11);
  208. comboBox1.Items.Add("全部数据");//添加选择显示全部数据的选项
  209. foreach(DataRow aRow in dataSet11.本期明细账簿.Rows)//根据明细表中的科目名称,设置下拉字典
  210. {
  211. string newStr=aRow["科目名称"].ToString().Trim();
  212. comboBox1.Items.Add(newStr);
  213. }
  214. }
  215. //------------根据科目代码选择数据------------
  216. private void btnSearch_Click(object sender, System.EventArgs e)
  217. {
  218. sqlDataAdapter1.SelectCommand.Parameters[0].Value="%%";
  219. if(txt1.Text.Trim()!=null)
  220. {
  221. sqlDataAdapter1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%";
  222. dataSet11.Clear();
  223. sqlDataAdapter1.Fill(dataSet11);
  224. //重新设置下拉选项
  225. comboBox1.Items.Clear();
  226. comboBox1.Items.Add("全部数据");
  227. foreach(DataRow aRow in dataSet11.本期明细账簿.Rows)
  228. {
  229. string newStr=aRow["科目名称"].ToString().Trim();
  230. comboBox1.Items.Add(newStr);
  231. }
  232. }
  233. }
  234. //------------筛选在表中显示的项目------------
  235. private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
  236. {
  237. if(comboBox1.SelectedIndex==0)//若选中显示全部数据则全部显示
  238. {
  239. dataView1.RowFilter="";
  240. }
  241. else
  242. {
  243. dataView1.RowFilter="科目名称='"+comboBox1.Text+"'";//否则根据选中的科目名称进行选择
  244. }
  245. }
  246. }
  247. }