StorageSearch.cs
上传用户:ksd66jhda
上传日期:2013-04-03
资源大小:234k
文件大小:9k
源码类别:

其他行业

开发平台:

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. /// StorageSearch 的摘要说明。
  11. /// </summary>
  12. public class StorageSearch : System.Windows.Forms.Form
  13. {
  14. private DataSet ds = new DataSet();
  15. private DataView dv;
  16. private LinkDataBase link = new LinkDataBase();
  17. private string sendTableName = "库存商品";
  18. private string sendStrSQL = "select 库存库.货号,拼音编码,品名,单位,仓库,库存数量,库存单价,库存金额 " +
  19. "from 库存库,商品清单 where 库存库.货号 = 商品清单.货号";
  20. private System.Windows.Forms.Label label1;
  21. private System.Windows.Forms.Label label2;
  22. private System.Windows.Forms.Label label3;
  23. private System.Windows.Forms.GroupBox groupBox1;
  24. private System.Windows.Forms.Button btn_Search;
  25. private System.Windows.Forms.DataGrid dgrd_StorageSearch;
  26. private System.Windows.Forms.TextBox txt_WareWord;
  27. private System.Windows.Forms.TextBox txt_WareNum;
  28. private System.Windows.Forms.ComboBox cmb_Storage;
  29. /// <summary>
  30. /// 必需的设计器变量。
  31. /// </summary>
  32. private System.ComponentModel.Container components = null;
  33. public StorageSearch()
  34. {
  35. //
  36. // Windows 窗体设计器支持所必需的
  37. //
  38. InitializeComponent();
  39. //
  40. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  41. //
  42. this.selectDataBase();
  43. this.DataGridStateControl();
  44. }
  45. /// <summary>
  46. /// 清理所有正在使用的资源。
  47. /// </summary>
  48. protected override void Dispose( bool disposing )
  49. {
  50. if( disposing )
  51. {
  52. if(components != null)
  53. {
  54. components.Dispose();
  55. }
  56. }
  57. base.Dispose( disposing );
  58. }
  59. #region Windows 窗体设计器生成的代码
  60. /// <summary>
  61. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  62. /// 此方法的内容。
  63. /// </summary>
  64. private void InitializeComponent()
  65. {
  66. this.btn_Search = new System.Windows.Forms.Button();
  67. this.txt_WareWord = new System.Windows.Forms.TextBox();
  68. this.txt_WareNum = new System.Windows.Forms.TextBox();
  69. this.label1 = new System.Windows.Forms.Label();
  70. this.label2 = new System.Windows.Forms.Label();
  71. this.label3 = new System.Windows.Forms.Label();
  72. this.cmb_Storage = new System.Windows.Forms.ComboBox();
  73. this.groupBox1 = new System.Windows.Forms.GroupBox();
  74. this.dgrd_StorageSearch = new System.Windows.Forms.DataGrid();
  75. this.groupBox1.SuspendLayout();
  76. ((System.ComponentModel.ISupportInitialize)(this.dgrd_StorageSearch)).BeginInit();
  77. this.SuspendLayout();
  78. // 
  79. // btn_Search
  80. // 
  81. this.btn_Search.Location = new System.Drawing.Point(601, 13);
  82. this.btn_Search.Name = "btn_Search";
  83. this.btn_Search.Size = new System.Drawing.Size(48, 24);
  84. this.btn_Search.TabIndex = 4;
  85. this.btn_Search.Text = "查询";
  86. this.btn_Search.Click += new System.EventHandler(this.btn_Search_Click);
  87. // 
  88. // txt_WareWord
  89. // 
  90. this.txt_WareWord.Location = new System.Drawing.Point(301, 15);
  91. this.txt_WareWord.Name = "txt_WareWord";
  92. this.txt_WareWord.TabIndex = 2;
  93. this.txt_WareWord.Text = "";
  94. // 
  95. // txt_WareNum
  96. // 
  97. this.txt_WareNum.Location = new System.Drawing.Point(113, 15);
  98. this.txt_WareNum.Name = "txt_WareNum";
  99. this.txt_WareNum.TabIndex = 1;
  100. this.txt_WareNum.Text = "";
  101. // 
  102. // label1
  103. // 
  104. this.label1.Location = new System.Drawing.Point(71, 19);
  105. this.label1.Name = "label1";
  106. this.label1.Size = new System.Drawing.Size(40, 16);
  107. this.label1.TabIndex = 3;
  108. this.label1.Text = "货号:";
  109. // 
  110. // label2
  111. // 
  112. this.label2.Location = new System.Drawing.Point(228, 19);
  113. this.label2.Name = "label2";
  114. this.label2.Size = new System.Drawing.Size(64, 16);
  115. this.label2.TabIndex = 4;
  116. this.label2.Text = "商品拼音:";
  117. // 
  118. // label3
  119. // 
  120. this.label3.Location = new System.Drawing.Point(416, 19);
  121. this.label3.Name = "label3";
  122. this.label3.Size = new System.Drawing.Size(40, 16);
  123. this.label3.TabIndex = 5;
  124. this.label3.Text = "仓库:";
  125. // 
  126. // cmb_Storage
  127. // 
  128. this.cmb_Storage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  129. this.cmb_Storage.Location = new System.Drawing.Point(459, 15);
  130. this.cmb_Storage.Name = "cmb_Storage";
  131. this.cmb_Storage.Size = new System.Drawing.Size(121, 20);
  132. this.cmb_Storage.Sorted = true;
  133. this.cmb_Storage.TabIndex = 3;
  134. // 
  135. // groupBox1
  136. // 
  137. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  138. | System.Windows.Forms.AnchorStyles.Right)));
  139. this.groupBox1.Controls.Add(this.btn_Search);
  140. this.groupBox1.Controls.Add(this.label2);
  141. this.groupBox1.Controls.Add(this.cmb_Storage);
  142. this.groupBox1.Controls.Add(this.label3);
  143. this.groupBox1.Controls.Add(this.txt_WareNum);
  144. this.groupBox1.Controls.Add(this.label1);
  145. this.groupBox1.Controls.Add(this.txt_WareWord);
  146. this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  147. this.groupBox1.Location = new System.Drawing.Point(0, -2);
  148. this.groupBox1.Name = "groupBox1";
  149. this.groupBox1.Size = new System.Drawing.Size(720, 50);
  150. this.groupBox1.TabIndex = 7;
  151. this.groupBox1.TabStop = false;
  152. // 
  153. // dgrd_StorageSearch
  154. // 
  155. this.dgrd_StorageSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
  156. | System.Windows.Forms.AnchorStyles.Left) 
  157. | System.Windows.Forms.AnchorStyles.Right)));
  158. this.dgrd_StorageSearch.CaptionVisible = false;
  159. this.dgrd_StorageSearch.DataMember = "";
  160. this.dgrd_StorageSearch.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  161. this.dgrd_StorageSearch.Location = new System.Drawing.Point(0, 50);
  162. this.dgrd_StorageSearch.Name = "dgrd_StorageSearch";
  163. this.dgrd_StorageSearch.Size = new System.Drawing.Size(720, 326);
  164. this.dgrd_StorageSearch.TabIndex = 5;
  165. // 
  166. // StorageSearch
  167. // 
  168. this.AcceptButton = this.btn_Search;
  169. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  170. this.ClientSize = new System.Drawing.Size(720, 373);
  171. this.Controls.Add(this.dgrd_StorageSearch);
  172. this.Controls.Add(this.groupBox1);
  173. this.Name = "StorageSearch";
  174. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  175. this.Text = "【库存查询】";
  176. this.groupBox1.ResumeLayout(false);
  177. ((System.ComponentModel.ISupportInitialize)(this.dgrd_StorageSearch)).EndInit();
  178. this.ResumeLayout(false);
  179. }
  180. #endregion
  181. //---------------将查询得到的仓库信息添加到下拉列表框中---------------
  182. private void selectDataBase()
  183. {
  184. this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
  185. this.dv = new DataView(ds.Tables[0]);
  186. this.dgrd_StorageSearch.DataSource = dv;
  187. this.cmb_Storage.Items.Add(""); //首先加入一个空白,以用作查询全部仓库的库存货物
  188. //从库存库中读取所有仓库并排斥性的加入保存仓库号的组合框中
  189. for (int i=0;i<ds.Tables[0].Rows.Count;i++)//外循环是判断库存库中的有多少行
  190. {
  191. for (int j=0;j<this.cmb_Storage.Items.Count;j++)//内循环是判断当前要加进去的仓库号在组合框中是否已存在
  192. {
  193. if (ds.Tables[0].Rows[i][4].ToString().Trim() == this.cmb_Storage.Items[j].ToString())
  194. {
  195. goto END;//如果组合框中已存在当前要加入的仓库号,则转到END标识处,组合框中不加入该仓库号
  196. }
  197. }
  198. //如果组合框中尚不存在该仓库号,则将它加进去
  199. this.cmb_Storage.Items.Add(ds.Tables[0].Rows[i][4].ToString().Trim());
  200. END:{};
  201. }
  202. this.cmb_Storage.SelectedIndex = 0;
  203. }
  204. //--------------根据输入查询库存中商品信息--------------
  205. private void btn_Search_Click(object sender, System.EventArgs e)
  206. {
  207. string strRowFilter = "";
  208. string strWareNumFilter ="货号 like '" + txt_WareNum.Text.Trim() + "%'";
  209. string strWareWordFilter ="拼音编码 like '" + txt_WareWord.Text.Trim() + "%'";
  210. int selectedNum = cmb_Storage.SelectedIndex;
  211. string strStorageFilter ="仓库 = '" + cmb_Storage.Items[selectedNum].ToString().Trim()+ "'";
  212. if (txt_WareNum.Text.Trim() != "")
  213. strRowFilter += strWareNumFilter + " and ";
  214. if (txt_WareWord.Text.Trim() != "")
  215. strRowFilter += strWareWordFilter + " and ";
  216. if (cmb_Storage.Items[selectedNum].ToString().Trim() != "")
  217. strRowFilter += strStorageFilter + " and ";
  218. if (strRowFilter != "")  // 存在查询条件
  219. strRowFilter = strRowFilter.Substring(0,strRowFilter.Length-5);
  220. dv.RowFilter = strRowFilter;
  221. }
  222. //-----------设置表格状态--------------
  223. private void DataGridStateControl()
  224. {
  225. DataGridTableStyle ts = new DataGridTableStyle();
  226. DataGridNoActiveCellColumn aColumnTextColumn;
  227. ts.AlternatingBackColor = Color.LightGray;
  228. ts.MappingName = this.ds.Tables[0].TableName;
  229. int numCols = this.ds.Tables[0].Columns.Count;
  230. for (int i = 0;i< numCols;i++)
  231. {
  232. aColumnTextColumn = new DataGridNoActiveCellColumn();
  233. aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
  234. aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
  235. aColumnTextColumn.NullText = "";
  236. aColumnTextColumn.Format = "D";
  237. ts.GridColumnStyles.Add(aColumnTextColumn);
  238. }
  239. this.dgrd_StorageSearch.TableStyles.Add(ts);
  240. }
  241. }
  242. }