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

其他行业

开发平台:

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. /// StockTable 的摘要说明。
  11. /// </summary>
  12. public class StockTable : System.Windows.Forms.Form
  13. {
  14. private LinkDataBase link = new LinkDataBase();
  15. private DataTable newTable;
  16. //保存从"商品信息维护"窗体中选择后传过来的数据,它们将被放入DataGrid的相应表格中
  17. public static string [] inputDataGridArray = new string [] {null,null,null};
  18. //保存从"供货商信息维护"窗体中选择后传过来的数据,它们将被赋值给供货商号和名称的控件Text属性
  19. //确定要赋的值为文本,故用空字符初始化
  20. public static string [] inputTextDataArray = new string [] {"",""};
  21. private DateTime gridMouseDownTime; //记录点击DataGrid时的时间
  22. private System.Windows.Forms.GroupBox groupBox1;
  23. private System.Windows.Forms.Label label4;
  24. private System.Windows.Forms.Label label5;
  25. private System.Windows.Forms.Label label6;
  26. private System.Windows.Forms.Label label7;
  27. private System.Windows.Forms.ToolBar toolBar1;
  28. private System.Windows.Forms.ToolBarButton tbarBtnSave;
  29. private System.Windows.Forms.ImageList imageList1;
  30. private System.Windows.Forms.ToolBarButton tbarBtnDelete;
  31. private System.Windows.Forms.ToolBarButton tbarBtnPrint;
  32. private System.Windows.Forms.DataGrid dgrd_StockTable;
  33. private System.Windows.Forms.TextBox txt_StockDate;
  34. private System.Windows.Forms.TextBox txt_Maker;
  35. private System.Windows.Forms.GroupBox groupBox2;
  36. private System.Windows.Forms.Label label8;
  37. private System.Windows.Forms.Label label9;
  38. private System.Windows.Forms.Label label10;
  39. private System.Windows.Forms.TextBox txt_NoTax;
  40. private System.Windows.Forms.TextBox txt_Tax;
  41. private System.Windows.Forms.ComboBox cmb_StokerID;
  42. private System.Windows.Forms.TextBox txt_StokerName;
  43. private System.Windows.Forms.TextBox txt_TotalCount;
  44. private System.Windows.Forms.ComboBox cmb_Oprater;
  45. private System.ComponentModel.IContainer components;
  46. public StockTable()
  47. {
  48. //
  49. // Windows 窗体设计器支持所必需的
  50. //
  51. InitializeComponent();
  52. //
  53. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  54. //
  55. this.selectDataBase();
  56. this.DataGridStateControl();
  57. this.cmb_StokerID.Items.Add("");
  58. }
  59. /// <summary>
  60. /// 清理所有正在使用的资源。
  61. /// </summary>
  62. protected override void Dispose( bool disposing )
  63. {
  64. if( disposing )
  65. {
  66. if(components != null)
  67. {
  68. components.Dispose();
  69. }
  70. }
  71. base.Dispose( disposing );
  72. }
  73. #region Windows 窗体设计器生成的代码
  74. /// <summary>
  75. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  76. /// 此方法的内容。
  77. /// </summary>
  78. private void InitializeComponent()
  79. {
  80. this.components = new System.ComponentModel.Container();
  81. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(StockTable));
  82. this.dgrd_StockTable = new System.Windows.Forms.DataGrid();
  83. this.groupBox1 = new System.Windows.Forms.GroupBox();
  84. this.cmb_Oprater = new System.Windows.Forms.ComboBox();
  85. this.cmb_StokerID = new System.Windows.Forms.ComboBox();
  86. this.txt_StockDate = new System.Windows.Forms.TextBox();
  87. this.txt_Maker = new System.Windows.Forms.TextBox();
  88. this.label4 = new System.Windows.Forms.Label();
  89. this.txt_StokerName = new System.Windows.Forms.TextBox();
  90. this.label5 = new System.Windows.Forms.Label();
  91. this.label6 = new System.Windows.Forms.Label();
  92. this.label7 = new System.Windows.Forms.Label();
  93. this.toolBar1 = new System.Windows.Forms.ToolBar();
  94. this.tbarBtnSave = new System.Windows.Forms.ToolBarButton();
  95. this.tbarBtnDelete = new System.Windows.Forms.ToolBarButton();
  96. this.tbarBtnPrint = new System.Windows.Forms.ToolBarButton();
  97. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  98. this.groupBox2 = new System.Windows.Forms.GroupBox();
  99. this.txt_TotalCount = new System.Windows.Forms.TextBox();
  100. this.label8 = new System.Windows.Forms.Label();
  101. this.label9 = new System.Windows.Forms.Label();
  102. this.txt_NoTax = new System.Windows.Forms.TextBox();
  103. this.label10 = new System.Windows.Forms.Label();
  104. this.txt_Tax = new System.Windows.Forms.TextBox();
  105. ((System.ComponentModel.ISupportInitialize)(this.dgrd_StockTable)).BeginInit();
  106. this.groupBox1.SuspendLayout();
  107. this.groupBox2.SuspendLayout();
  108. this.SuspendLayout();
  109. // 
  110. // dgrd_StockTable
  111. // 
  112. this.dgrd_StockTable.AllowSorting = false;
  113. this.dgrd_StockTable.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
  114. | System.Windows.Forms.AnchorStyles.Left) 
  115. | System.Windows.Forms.AnchorStyles.Right)));
  116. this.dgrd_StockTable.CaptionVisible = false;
  117. this.dgrd_StockTable.DataMember = "";
  118. this.dgrd_StockTable.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  119. this.dgrd_StockTable.Location = new System.Drawing.Point(0, 104);
  120. this.dgrd_StockTable.Name = "dgrd_StockTable";
  121. this.dgrd_StockTable.Size = new System.Drawing.Size(720, 264);
  122. this.dgrd_StockTable.TabIndex = 5;
  123. this.dgrd_StockTable.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dgrd_StockTable_MouseDown);
  124. this.dgrd_StockTable.DoubleClick += new System.EventHandler(this.dgrd_StockTable_DoubleClick);
  125. this.dgrd_StockTable.CurrentCellChanged += new System.EventHandler(this.dgrd_StockTable_CurrentCellChanged);
  126. // 
  127. // groupBox1
  128. // 
  129. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  130. | System.Windows.Forms.AnchorStyles.Right)));
  131. this.groupBox1.Controls.Add(this.cmb_Oprater);
  132. this.groupBox1.Controls.Add(this.cmb_StokerID);
  133. this.groupBox1.Controls.Add(this.txt_StockDate);
  134. this.groupBox1.Controls.Add(this.txt_Maker);
  135. this.groupBox1.Controls.Add(this.label4);
  136. this.groupBox1.Controls.Add(this.txt_StokerName);
  137. this.groupBox1.Controls.Add(this.label5);
  138. this.groupBox1.Controls.Add(this.label6);
  139. this.groupBox1.Controls.Add(this.label7);
  140. this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  141. this.groupBox1.Location = new System.Drawing.Point(0, 22);
  142. this.groupBox1.Name = "groupBox1";
  143. this.groupBox1.Size = new System.Drawing.Size(720, 82);
  144. this.groupBox1.TabIndex = 0;
  145. this.groupBox1.TabStop = false;
  146. // 
  147. // cmb_Oprater
  148. // 
  149. this.cmb_Oprater.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  150. this.cmb_Oprater.ItemHeight = 12;
  151. this.cmb_Oprater.Location = new System.Drawing.Point(524, 16);
  152. this.cmb_Oprater.Name = "cmb_Oprater";
  153. this.cmb_Oprater.Size = new System.Drawing.Size(121, 20);
  154. this.cmb_Oprater.Sorted = true;
  155. this.cmb_Oprater.TabIndex = 3;
  156. // 
  157. // cmb_StokerID
  158. // 
  159. this.cmb_StokerID.Location = new System.Drawing.Point(140, 51);
  160. this.cmb_StokerID.MaxDropDownItems = 1;
  161. this.cmb_StokerID.Name = "cmb_StokerID";
  162. this.cmb_StokerID.Size = new System.Drawing.Size(128, 20);
  163. this.cmb_StokerID.Sorted = true;
  164. this.cmb_StokerID.TabIndex = 4;
  165. this.cmb_StokerID.DropDown += new System.EventHandler(this.cmb_Stoker_DropDown);
  166. this.cmb_StokerID.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cmb_StokerID_KeyUp);
  167. // 
  168. // txt_StockDate
  169. // 
  170. this.txt_StockDate.Location = new System.Drawing.Point(140, 16);
  171. this.txt_StockDate.Name = "txt_StockDate";
  172. this.txt_StockDate.Size = new System.Drawing.Size(128, 21);
  173. this.txt_StockDate.TabIndex = 1;
  174. this.txt_StockDate.Text = "";
  175. // 
  176. // txt_Maker
  177. // 
  178. this.txt_Maker.Location = new System.Drawing.Point(343, 16);
  179. this.txt_Maker.Name = "txt_Maker";
  180. this.txt_Maker.TabIndex = 2;
  181. this.txt_Maker.Text = "sys";
  182. // 
  183. // label4
  184. // 
  185. this.label4.Location = new System.Drawing.Point(75, 55);
  186. this.label4.Name = "label4";
  187. this.label4.Size = new System.Drawing.Size(60, 16);
  188. this.label4.TabIndex = 19;
  189. this.label4.Text = "供货商号:";
  190. // 
  191. // txt_StokerName
  192. // 
  193. this.txt_StokerName.Location = new System.Drawing.Point(295, 51);
  194. this.txt_StokerName.Name = "txt_StokerName";
  195. this.txt_StokerName.ReadOnly = true;
  196. this.txt_StokerName.Size = new System.Drawing.Size(350, 21);
  197. this.txt_StokerName.TabIndex = 9;
  198. this.txt_StokerName.TabStop = false;
  199. this.txt_StokerName.Text = "";
  200. // 
  201. // label5
  202. // 
  203. this.label5.Location = new System.Drawing.Point(290, 22);
  204. this.label5.Name = "label5";
  205. this.label5.Size = new System.Drawing.Size(42, 16);
  206. this.label5.TabIndex = 17;
  207. this.label5.Text = "制单人:";
  208. // 
  209. // label6
  210. // 
  211. this.label6.Location = new System.Drawing.Point(468, 22);
  212. this.label6.Name = "label6";
  213. this.label6.Size = new System.Drawing.Size(48, 16);
  214. this.label6.TabIndex = 18;
  215. this.label6.Text = "业务员:";
  216. // 
  217. // label7
  218. // 
  219. this.label7.Location = new System.Drawing.Point(75, 22);
  220. this.label7.Name = "label7";
  221. this.label7.Size = new System.Drawing.Size(60, 16);
  222. this.label7.TabIndex = 16;
  223. this.label7.Text = "进货日期:";
  224. // 
  225. // toolBar1
  226. // 
  227. this.toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  228. this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
  229. this.tbarBtnSave,
  230. this.tbarBtnDelete,
  231. this.tbarBtnPrint});
  232. this.toolBar1.DropDownArrows = true;
  233. this.toolBar1.ImageList = this.imageList1;
  234. this.toolBar1.Location = new System.Drawing.Point(0, 0);
  235. this.toolBar1.Name = "toolBar1";
  236. this.toolBar1.ShowToolTips = true;
  237. this.toolBar1.Size = new System.Drawing.Size(720, 29);
  238. this.toolBar1.TabIndex = 7;
  239. this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
  240. // 
  241. // tbarBtnSave
  242. // 
  243. this.tbarBtnSave.ImageIndex = 0;
  244. this.tbarBtnSave.ToolTipText = "保存修改";
  245. // 
  246. // tbarBtnDelete
  247. // 
  248. this.tbarBtnDelete.ImageIndex = 1;
  249. this.tbarBtnDelete.ToolTipText = "删除数据";
  250. // 
  251. // tbarBtnPrint
  252. // 
  253. this.tbarBtnPrint.ImageIndex = 2;
  254. this.tbarBtnPrint.ToolTipText = "打印报表";
  255. // 
  256. // imageList1
  257. // 
  258. this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
  259. this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
  260. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  261. // 
  262. // groupBox2
  263. // 
  264. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
  265. | System.Windows.Forms.AnchorStyles.Right)));
  266. this.groupBox2.Controls.Add(this.txt_TotalCount);
  267. this.groupBox2.Controls.Add(this.label8);
  268. this.groupBox2.Controls.Add(this.label9);
  269. this.groupBox2.Controls.Add(this.txt_NoTax);
  270. this.groupBox2.Controls.Add(this.label10);
  271. this.groupBox2.Controls.Add(this.txt_Tax);
  272. this.groupBox2.Location = new System.Drawing.Point(-4, 375);
  273. this.groupBox2.Name = "groupBox2";
  274. this.groupBox2.Size = new System.Drawing.Size(728, 81);
  275. this.groupBox2.TabIndex = 38;
  276. this.groupBox2.TabStop = false;
  277. // 
  278. // txt_TotalCount
  279. // 
  280. this.txt_TotalCount.Location = new System.Drawing.Point(127, 13);
  281. this.txt_TotalCount.Name = "txt_TotalCount";
  282. this.txt_TotalCount.TabIndex = 6;
  283. this.txt_TotalCount.Text = "0.00";
  284. this.txt_TotalCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  285. // 
  286. // label8
  287. // 
  288. this.label8.Location = new System.Drawing.Point(63, 18);
  289. this.label8.Name = "label8";
  290. this.label8.Size = new System.Drawing.Size(64, 16);
  291. this.label8.TabIndex = 46;
  292. this.label8.Text = "合计金额:";
  293. // 
  294. // label9
  295. // 
  296. this.label9.Location = new System.Drawing.Point(287, 18);
  297. this.label9.Name = "label9";
  298. this.label9.Size = new System.Drawing.Size(72, 16);
  299. this.label9.TabIndex = 44;
  300. this.label9.Text = "不含税金额:";
  301. // 
  302. // txt_NoTax
  303. // 
  304. this.txt_NoTax.Location = new System.Drawing.Point(367, 13);
  305. this.txt_NoTax.Name = "txt_NoTax";
  306. this.txt_NoTax.TabIndex = 7;
  307. this.txt_NoTax.Text = "0.00";
  308. this.txt_NoTax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  309. // 
  310. // label10
  311. // 
  312. this.label10.Location = new System.Drawing.Point(519, 18);
  313. this.label10.Name = "label10";
  314. this.label10.Size = new System.Drawing.Size(40, 16);
  315. this.label10.TabIndex = 45;
  316. this.label10.Text = "税额:";
  317. // 
  318. // txt_Tax
  319. // 
  320. this.txt_Tax.Location = new System.Drawing.Point(566, 13);
  321. this.txt_Tax.Name = "txt_Tax";
  322. this.txt_Tax.TabIndex = 8;
  323. this.txt_Tax.Text = "0.00";
  324. this.txt_Tax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  325. // 
  326. // StockTable
  327. // 
  328. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  329. this.ClientSize = new System.Drawing.Size(720, 421);
  330. this.Controls.Add(this.groupBox2);
  331. this.Controls.Add(this.toolBar1);
  332. this.Controls.Add(this.groupBox1);
  333. this.Controls.Add(this.dgrd_StockTable);
  334. this.Name = "StockTable";
  335. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  336. this.Text = "【进货单】";
  337. ((System.ComponentModel.ISupportInitialize)(this.dgrd_StockTable)).EndInit();
  338. this.groupBox1.ResumeLayout(false);
  339. this.groupBox2.ResumeLayout(false);
  340. this.ResumeLayout(false);
  341. }
  342. #endregion
  343. //-------将双击选择得到的商品信息显示到进货单的表格中--------
  344. public void  setWareData()
  345. {
  346. dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,0] = inputDataGridArray[0];
  347. dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,4] = inputDataGridArray[1];
  348. dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,5] = inputDataGridArray[2];
  349. dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,7] = 17;
  350. }
  351. //-------将双击选择得到的供货商信息显示到窗体中--------
  352. private void setTextData()
  353. {
  354. this.cmb_StokerID.IntegralHeight = false;//使组合框不调整大小以显示其所有项
  355. this.cmb_StokerID.DroppedDown = false;//使组合框不显示其下拉部分
  356. this.cmb_StokerID.Items[0] = inputTextDataArray[0];
  357. this.cmb_StokerID.SelectedIndex = 0;
  358. this.txt_StokerName.Text = inputTextDataArray[1];
  359. this.cmb_StokerID.IntegralHeight = true;//恢复默认值
  360. }
  361. //-----设置【业务员】下拉列表框下拉选项------
  362. private void selectDataBase()
  363. {
  364. this.txt_StockDate.Text = System.DateTime.Today.ToShortDateString();
  365. string tempStrSQL = "select distinct 姓名 from 用户清单 ";
  366. DataTable tempDataTable = link.SelectDataBase(tempStrSQL);
  367. for (int i=0;i<tempDataTable.Rows.Count;i++)
  368. this.cmb_Oprater.Items.Add(tempDataTable.Rows[i][0]);
  369. this.cmb_Oprater.SelectedIndex = 0;
  370. }
  371. //----------绑定数据并设置表格各列的属性----------
  372. private void DataGridStateControl()
  373. {
  374. newTable = new DataTable();
  375. newTable.Columns.Add("货号(双击)",typeof(string));
  376. newTable.Columns.Add("数量",typeof(decimal));
  377. newTable.Columns.Add("单价",typeof(decimal));
  378. newTable.Columns.Add("仓库",typeof(string));
  379. newTable.Columns.Add("品名",typeof(string));
  380. newTable.Columns.Add("单位",typeof(string));
  381. newTable.Columns.Add("金额",typeof(decimal),"数量*单价"); //运用DataTable的表达式自动运算
  382. newTable.Columns.Add("税率",typeof(decimal));
  383. newTable.Columns.Add("不含税额",typeof(decimal),"金额/1.17");
  384. newTable.Columns.Add("税额",typeof(decimal),"金额-不含税额");
  385. this.dgrd_StockTable.DataSource = newTable;
  386. newTable.Rows.Add(newTable.NewRow());//向表中添加一行
  387. DataGridTableStyle ts = new DataGridTableStyle();//设置表格模式
  388. DataGridTextBoxColumn aColumnTextColumn;
  389. ts.AllowSorting = false;
  390. ts.AlternatingBackColor = Color.LightGray;
  391. ts.MappingName = newTable.TableName;
  392. int numCols = newTable.Columns.Count;
  393. for (int i = 0;i< numCols;i++)
  394. {
  395. aColumnTextColumn = new DataGridTextBoxColumn();
  396. if( i!=0 && i!=1 && i!=2 && i!=3)//表中只允许编辑【数量】和【单价】两个字段
  397. {
  398. aColumnTextColumn.ReadOnly=true;
  399. }
  400. if ( i == 0 )//当鼠标单击首列时允许响应
  401. {
  402. aColumnTextColumn.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
  403. }
  404. if ( i == 4 )
  405. {
  406. aColumnTextColumn.Width = 160;
  407. }
  408. if ( i == 3 )//设置仓库下拉列表框
  409. {
  410. string sendStrSQL = "select distinct 仓库 from 库存库 order by 仓库 ASC";
  411. DataTable tempTable = this.link.SelectDataBase(sendStrSQL);
  412. DataGridComboBoxColumn aComboBoxColumn = new DataGridComboBoxColumn(tempTable,0,0);
  413. aComboBoxColumn.MappingName = newTable.Columns[i].ColumnName;
  414. aComboBoxColumn.HeaderText = newTable.Columns[i].ColumnName;
  415. aComboBoxColumn.NullText = "";
  416. ts.GridColumnStyles.Add(aComboBoxColumn);
  417. }
  418. else
  419. {
  420. aColumnTextColumn.MappingName = newTable.Columns[i].ColumnName;
  421. aColumnTextColumn.HeaderText = newTable.Columns[i].ColumnName;
  422. aColumnTextColumn.NullText = "";
  423. aColumnTextColumn.Format = "N";//设置为数字格式显示
  424. ts.GridColumnStyles.Add(aColumnTextColumn);
  425. }
  426. }
  427. this.dgrd_StockTable.TableStyles.Add(ts);
  428. }
  429. //-----------处理保存修改,删除和存入历史等功能---------
  430. private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
  431. {
  432. if (e.Button.ToolTipText == "保存修改")
  433. {
  434. clickedSaveIcon();
  435. }
  436. else if(e.Button.ToolTipText == "删除数据")
  437. {
  438. try
  439. {
  440. if (newTable.Rows.Count > 0)
  441. {
  442. this.newTable.Rows.RemoveAt(this.dgrd_StockTable.CurrentCell.RowNumber);
  443. this.controlCalculate();
  444. }
  445. //加入空行保证newTable中不为空,否则删除所有数据行后保存数据和MouseUp函数将引发异常出错
  446. if (newTable.Rows.Count-1 <= 0)
  447. newTable.Rows.Add(newTable.NewRow());
  448. }
  449. catch
  450. {
  451. return;
  452. }
  453. }
  454. else if (e.Button.ToolTipText == "打印报表")
  455. {
  456. clickedPrintIcon();
  457. }
  458. }
  459. //----------创建窗体,共用户选择供货商----------
  460. private void cmb_Stoker_DropDown(object sender, System.EventArgs e)
  461. {
  462. StokerDataManage newFrm = new StokerDataManage(false);
  463. newFrm.setDataGridReadOnly();
  464. newFrm.ShowDialog();
  465. setTextData();
  466. SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
  467. }
  468. //--------将所选供货商的相关数据读入窗体---------
  469. private void cmb_StokerID_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
  470. {
  471. this.txt_StokerName.Text = "";
  472. string strSearchWord = this.cmb_StokerID.Text;
  473. string sendSQL = "select 供货商号,名称 from 供货商清单 where 供货商号 = '" + strSearchWord + "'";
  474. DataTable tempDataTable = this.link.SelectDataBase(sendSQL);
  475. if (tempDataTable.Rows.Count>0)
  476. {
  477. inputTextDataArray[0] = tempDataTable.Rows[0][0].ToString().Trim();
  478. inputTextDataArray[1] = tempDataTable.Rows[0][1].ToString().Trim();
  479. this.setTextData();
  480. SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
  481. }
  482. }
  483. //------------在表格中双击,创建窗体以供选择货物----------
  484. private void dgrd_StockTable_DoubleClick(object sender, System.EventArgs e)
  485. {
  486. if (this.dgrd_StockTable.CurrentCell.ColumnNumber == 0)
  487. {
  488. this.dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,3]  = "";
  489. WareDataManage newFrm = new WareDataManage(false);
  490. newFrm.setDataGridReadOnly(false);
  491. newFrm.ShowDialog();
  492. setWareData();
  493. SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件(此处为下一格)
  494. }
  495. }
  496. private void dgrd_StockTable_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  497. {
  498. DataGrid myGrid   = (DataGrid)sender;
  499. System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
  500. myHitTest = this.dgrd_StockTable.HitTest(e.X,e.Y);
  501. if ( myHitTest.Type == System.Windows.Forms.DataGrid.HitTestType.Cell )
  502. gridMouseDownTime = DateTime.Now;
  503. }
  504. //----------计算税率,总金额等信息----------
  505. private void dgrd_StockTable_CurrentCellChanged(object sender, System.EventArgs e)
  506. {
  507. this.selectWareMessage();
  508. this.controlCalculate();
  509. }
  510. //------------处理鼠标在dataGrid中的双击事件---------
  511. private void TextBoxMouseDownHandler(object sender, MouseEventArgs e )
  512. {
  513. //第一个判断条件:在单元格的textbox中的双击(即单击DataCell,使它获得焦点后,然后再响应该Cell中的双击事件)
  514. //第二个判断条件:DataGrid 的 DoubleClick(直接双击Cell就响应双击事件,无须先单击Cell,使它获得焦点,然后再响应双击事件)
  515.                                                       //判断时间间隔是否小于控制面板中所定义的双击间隔时间
  516. if( e.Button == MouseButtons.Left && e.Clicks == 2 || DateTime.Now < gridMouseDownTime.AddMilliseconds(SystemInformation.DoubleClickTime))
  517. {
  518. if (this.dgrd_StockTable.CurrentCell.ColumnNumber == 0)
  519. {
  520. this.dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,3]  = "";
  521. WareDataManage newFrm = new WareDataManage(false);
  522. newFrm.setDataGridReadOnly(false);
  523. newFrm.ShowDialog();
  524. setWareData();
  525. SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件(此处为下一格)
  526. }
  527. }
  528. }
  529. //---------提交修改--------
  530. private void clickedSaveIcon()
  531. {
  532. try
  533. {
  534. //注意:必须先删除进货单明细表中的数据,然后才能再删除进货单中的数据
  535. string sendSQL = "delete 进货单明细";
  536. this.link.UpdateDataBase(sendSQL); //删除进货单明细中的数据
  537. sendSQL = "delete 进货单";
  538. this.link.UpdateDataBase(sendSQL); //删除进货单中的数据
  539. //向进货单中写入数据
  540. int intMaxStockNumberID= 0;
  541. sendSQL = "select 编号 from 进货单历史";
  542. //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
  543. DataTable intNumberTable = this.link.SelectDataBase(sendSQL);
  544. for (int i=0;i<intNumberTable.Rows.Count;i++)
  545. {
  546. if (intMaxStockNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
  547. {
  548. intMaxStockNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
  549. }
  550. }
  551. sendSQL = "select 编号 from 进货单";
  552. //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
  553. intNumberTable = this.link.SelectDataBase(sendSQL);
  554. for (int i=0;i<intNumberTable.Rows.Count;i++)
  555. {
  556. if (intMaxStockNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
  557. {
  558. intMaxStockNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
  559. }
  560. }
  561. intMaxStockNumberID++;
  562. string strStokerID =this.cmb_StokerID.Items[0].ToString().Trim();
  563. string strStockDate =this.txt_StockDate.Text.Trim();
  564. string strOperator =this.cmb_Oprater.SelectedItem.ToString().Trim();
  565. string strMaker =this.txt_Maker.Text.Trim();
  566. decimal decTotalCount = Decimal.Parse(this.txt_TotalCount.Text.Trim());
  567. decimal decNoTax = Decimal.Parse(this.txt_NoTax.Text.Trim());
  568. decimal decTax = Decimal.Parse(this.txt_Tax.Text.Trim());
  569. string sendValues = "('" + intMaxStockNumberID +"','"+ strStokerID +"','"+ strStockDate +"','"+ strOperator +"','"+
  570. strMaker +"','"+ decTotalCount +"','"+ decNoTax +"','"+ decTax + "')";
  571. sendSQL = "insert 进货单 (编号,供货商号,进货日期,业务员,制单人,税价合计,不含税价,税额) values " + sendValues;
  572. this.link.UpdateDataBase(sendSQL);
  573. //向进货单明细中写入数据
  574. int intMaxNumberID = 0; 
  575. sendSQL = "select 编号 from 进货单明细历史";
  576. //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
  577. intNumberTable = this.link.SelectDataBase(sendSQL);
  578. for (int i=0;i<intNumberTable.Rows.Count;i++)
  579. {
  580. if (intMaxNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
  581. {
  582. intMaxNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
  583. }
  584. }
  585. sendSQL = "select 编号 from 进货单明细";
  586. //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
  587. intNumberTable = this.link.SelectDataBase(sendSQL);
  588. for (int i=0;i<intNumberTable.Rows.Count;i++)
  589. {
  590. if (intMaxNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
  591. {
  592. intMaxNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
  593. }
  594. }
  595. for (int row=0;row<this.newTable.Rows.Count;row++)
  596. {
  597. //首先判断表中的下一行数据是否为空,如果是则返回,以免因向数据库中写入空行而出错
  598. if(this.newTable.Rows[row][0].ToString() == "")
  599. {
  600. sendSQL = "delete from 进货单 where 编号 = '" + intMaxStockNumberID + "'";
  601. this.link.UpdateDataBase(sendSQL); //首先删除这次在进货单中加入的数据
  602. break;
  603. }
  604. else
  605. {
  606. intMaxNumberID++;
  607. string strWareID = this.dgrd_StockTable[row,0].ToString().Trim();
  608. string strWareCount = this.dgrd_StockTable[row,1].ToString().Trim();
  609. string strWarePrice = this.dgrd_StockTable[row,2].ToString().Trim();
  610. string strStorageID = this.dgrd_StockTable[row,3].ToString().Trim();
  611. decTotalCount = Decimal.Parse(this.dgrd_StockTable[row,6].ToString().Trim());
  612. decTax = Decimal.Parse(this.dgrd_StockTable[row,8].ToString().Trim());
  613. decNoTax = Decimal.Parse(this.dgrd_StockTable[row,9].ToString().Trim());
  614. sendValues = "('" + intMaxNumberID +"','"+intMaxStockNumberID +"','"+ strWareID +"','"+ strWareCount +"','"+ strWarePrice +"','"+
  615. decTotalCount +"','"+ 17 +"','"+ decNoTax +"','"+ decTax +"','"+ strStorageID + "')";
  616. sendSQL = "insert 进货单明细 (编号,进货单号,货号,进货数量,进价,税价合计,税率,不含税价,税额,仓库) values " + sendValues;
  617. this.link.UpdateDataBase(sendSQL); 
  618. }
  619. }
  620. MessageBox.Show("数据保存成功!","信息");
  621. }
  622. catch
  623. {
  624. MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!","提示");
  625. return;
  626. }
  627. }
  628. //----------打印报表----------
  629. private void clickedPrintIcon()
  630. {
  631. CrystalReport newCrystalReport_Stock = new CrystalReport();
  632. newCrystalReport_Stock.ShowDialog();
  633. Trash();
  634. }
  635. //----------保存历史记录并清除原数据----------
  636. private void Trash()
  637. {
  638. try
  639. {
  640. if (MessageBox.Show("要保存为历史记录吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
  641. {
  642. this.link.UpdateDataBase("exec sf_进货单"); //调用存储过程
  643. //清除供货商信息
  644. this.cmb_StokerID.Items[0] = "";
  645. this.txt_StokerName.Text = "";
  646. //清除底部金额及税款信息
  647. this.txt_TotalCount.Text = "0.00";
  648. this.txt_NoTax.Text = "0.00";
  649. this.txt_Tax.Text = "0.00";
  650. //清除当前DataGrid中的所有数据
  651. newTable.Clear();
  652. //加入空行保证newTable中不为空,否则删除所有数据行后保存数据和MouseUp函数将引发异常出错
  653. newTable.Rows.Add(newTable.NewRow());
  654. MessageBox.Show("数据成功存入历史表!","信息");
  655. }
  656. }
  657. catch
  658. {
  659. MessageBox.Show("数据存入历史表时出错,请检查数据库!","提示");
  660. }
  661. }
  662. //-------------将所选择的货物信息填入表格中---------------
  663. private void selectWareMessage()
  664. {
  665. int intCurrentRowNumber = this.dgrd_StockTable.CurrentCell.RowNumber;
  666. //判断何时需要检索数据库的商品清单,读取商品信息(以免操作数据库次数过多,影响程序性能)
  667. if (this.dgrd_StockTable[intCurrentRowNumber,0].ToString() != "")
  668. {
  669. string strSearchWord = this.dgrd_StockTable[intCurrentRowNumber,0].ToString().Trim();
  670. string sendSQL = "select 货号,品名,单位 from 商品清单 where 货号 = '" + strSearchWord + "'";
  671. DataTable tempDataTable = this.link.SelectDataBase(sendSQL);
  672. if (tempDataTable.Rows.Count>0)
  673. {
  674. inputDataGridArray[0] = tempDataTable.Rows[0][0].ToString().Trim();
  675. inputDataGridArray[1] = tempDataTable.Rows[0][1].ToString().Trim();
  676. inputDataGridArray[2] = tempDataTable.Rows[0][2].ToString().Trim();
  677. this.setWareData();
  678. }
  679. //如果从数据库中没有检索出任何数据
  680. else
  681. {
  682. //inputDataGridArray[0]赋值为当前输入的值,方便用户再次修改输入
  683. inputDataGridArray[0] = this.dgrd_StockTable[intCurrentRowNumber,0].ToString().Trim();
  684. inputDataGridArray[1] = "";
  685. inputDataGridArray[2] = "";
  686. this.setWareData();
  687. }
  688. }
  689. }
  690. //--------------总金额,税率等的计算------------
  691. private void controlCalculate()
  692. {
  693. int intCurrentRowNumber = this.dgrd_StockTable.CurrentCell.RowNumber;
  694. string strWareCount = this.dgrd_StockTable[intCurrentRowNumber,1].ToString();
  695. string strWarePrice = this.dgrd_StockTable[intCurrentRowNumber,2].ToString();
  696. string strTotalCounter = this.dgrd_StockTable[intCurrentRowNumber,6].ToString();
  697. //当销售价和销售数量不为空时则将当前光标移到下一行的开始处,以便DataTable依据表达式自动计算DataColumn的值
  698. if (strWareCount != "" && strWarePrice != "" && strTotalCounter=="")
  699. {
  700. this.dgrd_StockTable.CurrentCell = new DataGridCell(intCurrentRowNumber+1,0); 
  701. }
  702. //为底部三个文本框计算总金额
  703. decimal intTotalCount = 0;
  704. decimal intNoTax = 0;
  705. decimal intTax = 0;
  706. //首先判断列是否为空
  707. object obj = newTable.Compute("SUM (金额)","");
  708. if (obj.GetType().ToString() != "System.DBNull")
  709. {
  710. intTotalCount = (decimal)this.newTable.Compute("SUM (金额)","");
  711. intNoTax = (decimal)this.newTable.Compute("SUM (不含税额)","");
  712. intTax = (decimal)this.newTable.Compute("SUM (税额)","");
  713. }
  714. this.txt_TotalCount.Text = intTotalCount.ToString("N");
  715. this.txt_NoTax.Text = intNoTax.ToString("N");
  716. this.txt_Tax.Text = intTax.ToString("N");
  717. }
  718. }
  719. }