StockTable.cs
资源名称:VCSDB.rar [点击查看]
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:29k
源码类别:
企业管理
开发平台:
C#
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- namespace 进销存管理系统
- {
- /// <summary>
- /// StockTable 的摘要说明。
- /// </summary>
- public class StockTable : System.Windows.Forms.Form
- {
- private LinkDataBase link = new LinkDataBase();
- private DataTable newTable;
- //保存从"商品信息维护"窗体中选择后传过来的数据,它们将被放入DataGrid的相应表格中
- public static string [] inputDataGridArray = new string [] {null,null,null};
- //保存从"供货商信息维护"窗体中选择后传过来的数据,它们将被赋值给供货商号和名称的控件Text属性
- //确定要赋的值为文本,故用空字符初始化
- public static string [] inputTextDataArray = new string [] {"",""};
- private DateTime gridMouseDownTime; //记录点击DataGrid时的时间
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.Label label6;
- private System.Windows.Forms.Label label7;
- private System.Windows.Forms.ToolBar toolBar1;
- private System.Windows.Forms.ToolBarButton tbarBtnSave;
- private System.Windows.Forms.ImageList imageList1;
- private System.Windows.Forms.ToolBarButton tbarBtnDelete;
- private System.Windows.Forms.ToolBarButton tbarBtnPrint;
- private System.Windows.Forms.DataGrid dgrd_StockTable;
- private System.Windows.Forms.TextBox txt_StockDate;
- private System.Windows.Forms.TextBox txt_Maker;
- private System.Windows.Forms.GroupBox groupBox2;
- private System.Windows.Forms.Label label8;
- private System.Windows.Forms.Label label9;
- private System.Windows.Forms.Label label10;
- private System.Windows.Forms.TextBox txt_NoTax;
- private System.Windows.Forms.TextBox txt_Tax;
- private System.Windows.Forms.ComboBox cmb_StokerID;
- private System.Windows.Forms.TextBox txt_StokerName;
- private System.Windows.Forms.TextBox txt_TotalCount;
- private System.Windows.Forms.ComboBox cmb_Oprater;
- private System.ComponentModel.IContainer components;
- public StockTable()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- this.selectDataBase();
- this.DataGridStateControl();
- this.cmb_StokerID.Items.Add("");
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(StockTable));
- this.dgrd_StockTable = new System.Windows.Forms.DataGrid();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.cmb_Oprater = new System.Windows.Forms.ComboBox();
- this.cmb_StokerID = new System.Windows.Forms.ComboBox();
- this.txt_StockDate = new System.Windows.Forms.TextBox();
- this.txt_Maker = new System.Windows.Forms.TextBox();
- this.label4 = new System.Windows.Forms.Label();
- this.txt_StokerName = new System.Windows.Forms.TextBox();
- this.label5 = new System.Windows.Forms.Label();
- this.label6 = new System.Windows.Forms.Label();
- this.label7 = new System.Windows.Forms.Label();
- this.toolBar1 = new System.Windows.Forms.ToolBar();
- this.tbarBtnSave = new System.Windows.Forms.ToolBarButton();
- this.tbarBtnDelete = new System.Windows.Forms.ToolBarButton();
- this.tbarBtnPrint = new System.Windows.Forms.ToolBarButton();
- this.imageList1 = new System.Windows.Forms.ImageList(this.components);
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.txt_TotalCount = new System.Windows.Forms.TextBox();
- this.label8 = new System.Windows.Forms.Label();
- this.label9 = new System.Windows.Forms.Label();
- this.txt_NoTax = new System.Windows.Forms.TextBox();
- this.label10 = new System.Windows.Forms.Label();
- this.txt_Tax = new System.Windows.Forms.TextBox();
- ((System.ComponentModel.ISupportInitialize)(this.dgrd_StockTable)).BeginInit();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- this.SuspendLayout();
- //
- // dgrd_StockTable
- //
- this.dgrd_StockTable.AllowSorting = false;
- this.dgrd_StockTable.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.dgrd_StockTable.CaptionVisible = false;
- this.dgrd_StockTable.DataMember = "";
- this.dgrd_StockTable.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dgrd_StockTable.Location = new System.Drawing.Point(0, 104);
- this.dgrd_StockTable.Name = "dgrd_StockTable";
- this.dgrd_StockTable.Size = new System.Drawing.Size(720, 264);
- this.dgrd_StockTable.TabIndex = 5;
- this.dgrd_StockTable.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dgrd_StockTable_MouseDown);
- this.dgrd_StockTable.DoubleClick += new System.EventHandler(this.dgrd_StockTable_DoubleClick);
- this.dgrd_StockTable.CurrentCellChanged += new System.EventHandler(this.dgrd_StockTable_CurrentCellChanged);
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Controls.Add(this.cmb_Oprater);
- this.groupBox1.Controls.Add(this.cmb_StokerID);
- this.groupBox1.Controls.Add(this.txt_StockDate);
- this.groupBox1.Controls.Add(this.txt_Maker);
- this.groupBox1.Controls.Add(this.label4);
- this.groupBox1.Controls.Add(this.txt_StokerName);
- this.groupBox1.Controls.Add(this.label5);
- this.groupBox1.Controls.Add(this.label6);
- this.groupBox1.Controls.Add(this.label7);
- this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
- this.groupBox1.Location = new System.Drawing.Point(0, 22);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(720, 82);
- this.groupBox1.TabIndex = 0;
- this.groupBox1.TabStop = false;
- //
- // cmb_Oprater
- //
- this.cmb_Oprater.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.cmb_Oprater.ItemHeight = 12;
- this.cmb_Oprater.Location = new System.Drawing.Point(524, 16);
- this.cmb_Oprater.Name = "cmb_Oprater";
- this.cmb_Oprater.Size = new System.Drawing.Size(121, 20);
- this.cmb_Oprater.Sorted = true;
- this.cmb_Oprater.TabIndex = 3;
- //
- // cmb_StokerID
- //
- this.cmb_StokerID.Location = new System.Drawing.Point(140, 51);
- this.cmb_StokerID.MaxDropDownItems = 1;
- this.cmb_StokerID.Name = "cmb_StokerID";
- this.cmb_StokerID.Size = new System.Drawing.Size(128, 20);
- this.cmb_StokerID.Sorted = true;
- this.cmb_StokerID.TabIndex = 4;
- this.cmb_StokerID.DropDown += new System.EventHandler(this.cmb_Stoker_DropDown);
- this.cmb_StokerID.KeyUp += new System.Windows.Forms.KeyEventHandler(this.cmb_StokerID_KeyUp);
- //
- // txt_StockDate
- //
- this.txt_StockDate.Location = new System.Drawing.Point(140, 16);
- this.txt_StockDate.Name = "txt_StockDate";
- this.txt_StockDate.Size = new System.Drawing.Size(128, 21);
- this.txt_StockDate.TabIndex = 1;
- this.txt_StockDate.Text = "";
- //
- // txt_Maker
- //
- this.txt_Maker.Location = new System.Drawing.Point(343, 16);
- this.txt_Maker.Name = "txt_Maker";
- this.txt_Maker.TabIndex = 2;
- this.txt_Maker.Text = "sys";
- //
- // label4
- //
- this.label4.Location = new System.Drawing.Point(75, 55);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(60, 16);
- this.label4.TabIndex = 19;
- this.label4.Text = "供货商号:";
- //
- // txt_StokerName
- //
- this.txt_StokerName.Location = new System.Drawing.Point(295, 51);
- this.txt_StokerName.Name = "txt_StokerName";
- this.txt_StokerName.ReadOnly = true;
- this.txt_StokerName.Size = new System.Drawing.Size(350, 21);
- this.txt_StokerName.TabIndex = 9;
- this.txt_StokerName.TabStop = false;
- this.txt_StokerName.Text = "";
- //
- // label5
- //
- this.label5.Location = new System.Drawing.Point(290, 22);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(42, 16);
- this.label5.TabIndex = 17;
- this.label5.Text = "制单人:";
- //
- // label6
- //
- this.label6.Location = new System.Drawing.Point(468, 22);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(48, 16);
- this.label6.TabIndex = 18;
- this.label6.Text = "业务员:";
- //
- // label7
- //
- this.label7.Location = new System.Drawing.Point(75, 22);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(60, 16);
- this.label7.TabIndex = 16;
- this.label7.Text = "进货日期:";
- //
- // toolBar1
- //
- this.toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
- this.tbarBtnSave,
- this.tbarBtnDelete,
- this.tbarBtnPrint});
- this.toolBar1.DropDownArrows = true;
- this.toolBar1.ImageList = this.imageList1;
- this.toolBar1.Location = new System.Drawing.Point(0, 0);
- this.toolBar1.Name = "toolBar1";
- this.toolBar1.ShowToolTips = true;
- this.toolBar1.Size = new System.Drawing.Size(720, 29);
- this.toolBar1.TabIndex = 7;
- this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
- //
- // tbarBtnSave
- //
- this.tbarBtnSave.ImageIndex = 0;
- this.tbarBtnSave.ToolTipText = "保存修改";
- //
- // tbarBtnDelete
- //
- this.tbarBtnDelete.ImageIndex = 1;
- this.tbarBtnDelete.ToolTipText = "删除数据";
- //
- // tbarBtnPrint
- //
- this.tbarBtnPrint.ImageIndex = 2;
- this.tbarBtnPrint.ToolTipText = "打印报表";
- //
- // imageList1
- //
- this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
- this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
- this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
- //
- // groupBox2
- //
- this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox2.Controls.Add(this.txt_TotalCount);
- this.groupBox2.Controls.Add(this.label8);
- this.groupBox2.Controls.Add(this.label9);
- this.groupBox2.Controls.Add(this.txt_NoTax);
- this.groupBox2.Controls.Add(this.label10);
- this.groupBox2.Controls.Add(this.txt_Tax);
- this.groupBox2.Location = new System.Drawing.Point(-4, 375);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(728, 81);
- this.groupBox2.TabIndex = 38;
- this.groupBox2.TabStop = false;
- //
- // txt_TotalCount
- //
- this.txt_TotalCount.Location = new System.Drawing.Point(127, 13);
- this.txt_TotalCount.Name = "txt_TotalCount";
- this.txt_TotalCount.TabIndex = 6;
- this.txt_TotalCount.Text = "0.00";
- this.txt_TotalCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
- //
- // label8
- //
- this.label8.Location = new System.Drawing.Point(63, 18);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(64, 16);
- this.label8.TabIndex = 46;
- this.label8.Text = "合计金额:";
- //
- // label9
- //
- this.label9.Location = new System.Drawing.Point(287, 18);
- this.label9.Name = "label9";
- this.label9.Size = new System.Drawing.Size(72, 16);
- this.label9.TabIndex = 44;
- this.label9.Text = "不含税金额:";
- //
- // txt_NoTax
- //
- this.txt_NoTax.Location = new System.Drawing.Point(367, 13);
- this.txt_NoTax.Name = "txt_NoTax";
- this.txt_NoTax.TabIndex = 7;
- this.txt_NoTax.Text = "0.00";
- this.txt_NoTax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
- //
- // label10
- //
- this.label10.Location = new System.Drawing.Point(519, 18);
- this.label10.Name = "label10";
- this.label10.Size = new System.Drawing.Size(40, 16);
- this.label10.TabIndex = 45;
- this.label10.Text = "税额:";
- //
- // txt_Tax
- //
- this.txt_Tax.Location = new System.Drawing.Point(566, 13);
- this.txt_Tax.Name = "txt_Tax";
- this.txt_Tax.TabIndex = 8;
- this.txt_Tax.Text = "0.00";
- this.txt_Tax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
- //
- // StockTable
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(720, 421);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.toolBar1);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.dgrd_StockTable);
- this.Name = "StockTable";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "【进货单】";
- ((System.ComponentModel.ISupportInitialize)(this.dgrd_StockTable)).EndInit();
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- //-------将双击选择得到的商品信息显示到进货单的表格中--------
- public void setWareData()
- {
- dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,0] = inputDataGridArray[0];
- dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,4] = inputDataGridArray[1];
- dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,5] = inputDataGridArray[2];
- dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,7] = 17;
- }
- //-------将双击选择得到的供货商信息显示到窗体中--------
- private void setTextData()
- {
- this.cmb_StokerID.IntegralHeight = false;//使组合框不调整大小以显示其所有项
- this.cmb_StokerID.DroppedDown = false;//使组合框不显示其下拉部分
- this.cmb_StokerID.Items[0] = inputTextDataArray[0];
- this.cmb_StokerID.SelectedIndex = 0;
- this.txt_StokerName.Text = inputTextDataArray[1];
- this.cmb_StokerID.IntegralHeight = true;//恢复默认值
- }
- //-----设置【业务员】下拉列表框下拉选项------
- private void selectDataBase()
- {
- this.txt_StockDate.Text = System.DateTime.Today.ToShortDateString();
- string tempStrSQL = "select distinct 姓名 from 用户清单 ";
- DataTable tempDataTable = link.SelectDataBase(tempStrSQL);
- for (int i=0;i<tempDataTable.Rows.Count;i++)
- this.cmb_Oprater.Items.Add(tempDataTable.Rows[i][0]);
- this.cmb_Oprater.SelectedIndex = 0;
- }
- //----------绑定数据并设置表格各列的属性----------
- private void DataGridStateControl()
- {
- newTable = new DataTable();
- newTable.Columns.Add("货号(双击)",typeof(string));
- newTable.Columns.Add("数量",typeof(decimal));
- newTable.Columns.Add("单价",typeof(decimal));
- newTable.Columns.Add("仓库",typeof(string));
- newTable.Columns.Add("品名",typeof(string));
- newTable.Columns.Add("单位",typeof(string));
- newTable.Columns.Add("金额",typeof(decimal),"数量*单价"); //运用DataTable的表达式自动运算
- newTable.Columns.Add("税率",typeof(decimal));
- newTable.Columns.Add("不含税额",typeof(decimal),"金额/1.17");
- newTable.Columns.Add("税额",typeof(decimal),"金额-不含税额");
- this.dgrd_StockTable.DataSource = newTable;
- newTable.Rows.Add(newTable.NewRow());//向表中添加一行
- DataGridTableStyle ts = new DataGridTableStyle();//设置表格模式
- DataGridTextBoxColumn aColumnTextColumn;
- ts.AllowSorting = false;
- ts.AlternatingBackColor = Color.LightGray;
- ts.MappingName = newTable.TableName;
- int numCols = newTable.Columns.Count;
- for (int i = 0;i< numCols;i++)
- {
- aColumnTextColumn = new DataGridTextBoxColumn();
- if( i!=0 && i!=1 && i!=2 && i!=3)//表中只允许编辑【数量】和【单价】两个字段
- {
- aColumnTextColumn.ReadOnly=true;
- }
- if ( i == 0 )//当鼠标单击首列时允许响应
- {
- aColumnTextColumn.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
- }
- if ( i == 4 )
- {
- aColumnTextColumn.Width = 160;
- }
- if ( i == 3 )//设置仓库下拉列表框
- {
- string sendStrSQL = "select distinct 仓库 from 库存库 order by 仓库 ASC";
- DataTable tempTable = this.link.SelectDataBase(sendStrSQL);
- DataGridComboBoxColumn aComboBoxColumn = new DataGridComboBoxColumn(tempTable,0,0);
- aComboBoxColumn.MappingName = newTable.Columns[i].ColumnName;
- aComboBoxColumn.HeaderText = newTable.Columns[i].ColumnName;
- aComboBoxColumn.NullText = "";
- ts.GridColumnStyles.Add(aComboBoxColumn);
- }
- else
- {
- aColumnTextColumn.MappingName = newTable.Columns[i].ColumnName;
- aColumnTextColumn.HeaderText = newTable.Columns[i].ColumnName;
- aColumnTextColumn.NullText = "";
- aColumnTextColumn.Format = "N";//设置为数字格式显示
- ts.GridColumnStyles.Add(aColumnTextColumn);
- }
- }
- this.dgrd_StockTable.TableStyles.Add(ts);
- }
- //-----------处理保存修改,删除和存入历史等功能---------
- private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
- {
- if (e.Button.ToolTipText == "保存修改")
- {
- clickedSaveIcon();
- }
- else if(e.Button.ToolTipText == "删除数据")
- {
- try
- {
- if (newTable.Rows.Count > 0)
- {
- this.newTable.Rows.RemoveAt(this.dgrd_StockTable.CurrentCell.RowNumber);
- this.controlCalculate();
- }
- //加入空行保证newTable中不为空,否则删除所有数据行后保存数据和MouseUp函数将引发异常出错
- if (newTable.Rows.Count-1 <= 0)
- newTable.Rows.Add(newTable.NewRow());
- }
- catch
- {
- return;
- }
- }
- else if (e.Button.ToolTipText == "打印报表")
- {
- clickedPrintIcon();
- }
- }
- //----------创建窗体,共用户选择供货商----------
- private void cmb_Stoker_DropDown(object sender, System.EventArgs e)
- {
- StokerDataManage newFrm = new StokerDataManage(false);
- newFrm.setDataGridReadOnly();
- newFrm.ShowDialog();
- setTextData();
- SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
- }
- //--------将所选供货商的相关数据读入窗体---------
- private void cmb_StokerID_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
- {
- this.txt_StokerName.Text = "";
- string strSearchWord = this.cmb_StokerID.Text;
- string sendSQL = "select 供货商号,名称 from 供货商清单 where 供货商号 = '" + strSearchWord + "'";
- DataTable tempDataTable = this.link.SelectDataBase(sendSQL);
- if (tempDataTable.Rows.Count>0)
- {
- inputTextDataArray[0] = tempDataTable.Rows[0][0].ToString().Trim();
- inputTextDataArray[1] = tempDataTable.Rows[0][1].ToString().Trim();
- this.setTextData();
- SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
- }
- }
- //------------在表格中双击,创建窗体以供选择货物----------
- private void dgrd_StockTable_DoubleClick(object sender, System.EventArgs e)
- {
- if (this.dgrd_StockTable.CurrentCell.ColumnNumber == 0)
- {
- this.dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,3] = "";
- WareDataManage newFrm = new WareDataManage(false);
- newFrm.setDataGridReadOnly(false);
- newFrm.ShowDialog();
- setWareData();
- SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件(此处为下一格)
- }
- }
- private void dgrd_StockTable_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- DataGrid myGrid = (DataGrid)sender;
- System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
- myHitTest = this.dgrd_StockTable.HitTest(e.X,e.Y);
- if ( myHitTest.Type == System.Windows.Forms.DataGrid.HitTestType.Cell )
- gridMouseDownTime = DateTime.Now;
- }
- //----------计算税率,总金额等信息----------
- private void dgrd_StockTable_CurrentCellChanged(object sender, System.EventArgs e)
- {
- this.selectWareMessage();
- this.controlCalculate();
- }
- //------------处理鼠标在dataGrid中的双击事件---------
- private void TextBoxMouseDownHandler(object sender, MouseEventArgs e )
- {
- //第一个判断条件:在单元格的textbox中的双击(即单击DataCell,使它获得焦点后,然后再响应该Cell中的双击事件)
- //第二个判断条件:DataGrid 的 DoubleClick(直接双击Cell就响应双击事件,无须先单击Cell,使它获得焦点,然后再响应双击事件)
- //判断时间间隔是否小于控制面板中所定义的双击间隔时间
- if( e.Button == MouseButtons.Left && e.Clicks == 2 || DateTime.Now < gridMouseDownTime.AddMilliseconds(SystemInformation.DoubleClickTime))
- {
- if (this.dgrd_StockTable.CurrentCell.ColumnNumber == 0)
- {
- this.dgrd_StockTable[dgrd_StockTable.CurrentCell.RowNumber,3] = "";
- WareDataManage newFrm = new WareDataManage(false);
- newFrm.setDataGridReadOnly(false);
- newFrm.ShowDialog();
- setWareData();
- SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件(此处为下一格)
- }
- }
- }
- //---------提交修改--------
- private void clickedSaveIcon()
- {
- try
- {
- //注意:必须先删除进货单明细表中的数据,然后才能再删除进货单中的数据
- string sendSQL = "delete 进货单明细";
- this.link.UpdateDataBase(sendSQL); //删除进货单明细中的数据
- sendSQL = "delete 进货单";
- this.link.UpdateDataBase(sendSQL); //删除进货单中的数据
- //向进货单中写入数据
- int intMaxStockNumberID= 0;
- sendSQL = "select 编号 from 进货单历史";
- //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
- DataTable intNumberTable = this.link.SelectDataBase(sendSQL);
- for (int i=0;i<intNumberTable.Rows.Count;i++)
- {
- if (intMaxStockNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
- {
- intMaxStockNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
- }
- }
- sendSQL = "select 编号 from 进货单";
- //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
- intNumberTable = this.link.SelectDataBase(sendSQL);
- for (int i=0;i<intNumberTable.Rows.Count;i++)
- {
- if (intMaxStockNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
- {
- intMaxStockNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
- }
- }
- intMaxStockNumberID++;
- string strStokerID =this.cmb_StokerID.Items[0].ToString().Trim();
- string strStockDate =this.txt_StockDate.Text.Trim();
- string strOperator =this.cmb_Oprater.SelectedItem.ToString().Trim();
- string strMaker =this.txt_Maker.Text.Trim();
- decimal decTotalCount = Decimal.Parse(this.txt_TotalCount.Text.Trim());
- decimal decNoTax = Decimal.Parse(this.txt_NoTax.Text.Trim());
- decimal decTax = Decimal.Parse(this.txt_Tax.Text.Trim());
- string sendValues = "('" + intMaxStockNumberID +"','"+ strStokerID +"','"+ strStockDate +"','"+ strOperator +"','"+
- strMaker +"','"+ decTotalCount +"','"+ decNoTax +"','"+ decTax + "')";
- sendSQL = "insert 进货单 (编号,供货商号,进货日期,业务员,制单人,税价合计,不含税价,税额) values " + sendValues;
- this.link.UpdateDataBase(sendSQL);
- //向进货单明细中写入数据
- int intMaxNumberID = 0;
- sendSQL = "select 编号 from 进货单明细历史";
- //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
- intNumberTable = this.link.SelectDataBase(sendSQL);
- for (int i=0;i<intNumberTable.Rows.Count;i++)
- {
- if (intMaxNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
- {
- intMaxNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
- }
- }
- sendSQL = "select 编号 from 进货单明细";
- //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
- intNumberTable = this.link.SelectDataBase(sendSQL);
- for (int i=0;i<intNumberTable.Rows.Count;i++)
- {
- if (intMaxNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
- {
- intMaxNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
- }
- }
- for (int row=0;row<this.newTable.Rows.Count;row++)
- {
- //首先判断表中的下一行数据是否为空,如果是则返回,以免因向数据库中写入空行而出错
- if(this.newTable.Rows[row][0].ToString() == "")
- {
- sendSQL = "delete from 进货单 where 编号 = '" + intMaxStockNumberID + "'";
- this.link.UpdateDataBase(sendSQL); //首先删除这次在进货单中加入的数据
- break;
- }
- else
- {
- intMaxNumberID++;
- string strWareID = this.dgrd_StockTable[row,0].ToString().Trim();
- string strWareCount = this.dgrd_StockTable[row,1].ToString().Trim();
- string strWarePrice = this.dgrd_StockTable[row,2].ToString().Trim();
- string strStorageID = this.dgrd_StockTable[row,3].ToString().Trim();
- decTotalCount = Decimal.Parse(this.dgrd_StockTable[row,6].ToString().Trim());
- decTax = Decimal.Parse(this.dgrd_StockTable[row,8].ToString().Trim());
- decNoTax = Decimal.Parse(this.dgrd_StockTable[row,9].ToString().Trim());
- sendValues = "('" + intMaxNumberID +"','"+intMaxStockNumberID +"','"+ strWareID +"','"+ strWareCount +"','"+ strWarePrice +"','"+
- decTotalCount +"','"+ 17 +"','"+ decNoTax +"','"+ decTax +"','"+ strStorageID + "')";
- sendSQL = "insert 进货单明细 (编号,进货单号,货号,进货数量,进价,税价合计,税率,不含税价,税额,仓库) values " + sendValues;
- this.link.UpdateDataBase(sendSQL);
- }
- }
- MessageBox.Show("数据保存成功!","信息");
- }
- catch
- {
- MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!","提示");
- return;
- }
- }
- //----------打印报表----------
- private void clickedPrintIcon()
- {
- CrystalReport newCrystalReport_Stock = new CrystalReport();
- newCrystalReport_Stock.ShowDialog();
- Trash();
- }
- //----------保存历史记录并清除原数据----------
- private void Trash()
- {
- try
- {
- if (MessageBox.Show("要保存为历史记录吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- this.link.UpdateDataBase("exec sf_进货单"); //调用存储过程
- //清除供货商信息
- this.cmb_StokerID.Items[0] = "";
- this.txt_StokerName.Text = "";
- //清除底部金额及税款信息
- this.txt_TotalCount.Text = "0.00";
- this.txt_NoTax.Text = "0.00";
- this.txt_Tax.Text = "0.00";
- //清除当前DataGrid中的所有数据
- newTable.Clear();
- //加入空行保证newTable中不为空,否则删除所有数据行后保存数据和MouseUp函数将引发异常出错
- newTable.Rows.Add(newTable.NewRow());
- MessageBox.Show("数据成功存入历史表!","信息");
- }
- }
- catch
- {
- MessageBox.Show("数据存入历史表时出错,请检查数据库!","提示");
- }
- }
- //-------------将所选择的货物信息填入表格中---------------
- private void selectWareMessage()
- {
- int intCurrentRowNumber = this.dgrd_StockTable.CurrentCell.RowNumber;
- //判断何时需要检索数据库的商品清单,读取商品信息(以免操作数据库次数过多,影响程序性能)
- if (this.dgrd_StockTable[intCurrentRowNumber,0].ToString() != "")
- {
- string strSearchWord = this.dgrd_StockTable[intCurrentRowNumber,0].ToString().Trim();
- string sendSQL = "select 货号,品名,单位 from 商品清单 where 货号 = '" + strSearchWord + "'";
- DataTable tempDataTable = this.link.SelectDataBase(sendSQL);
- if (tempDataTable.Rows.Count>0)
- {
- inputDataGridArray[0] = tempDataTable.Rows[0][0].ToString().Trim();
- inputDataGridArray[1] = tempDataTable.Rows[0][1].ToString().Trim();
- inputDataGridArray[2] = tempDataTable.Rows[0][2].ToString().Trim();
- this.setWareData();
- }
- //如果从数据库中没有检索出任何数据
- else
- {
- //inputDataGridArray[0]赋值为当前输入的值,方便用户再次修改输入
- inputDataGridArray[0] = this.dgrd_StockTable[intCurrentRowNumber,0].ToString().Trim();
- inputDataGridArray[1] = "";
- inputDataGridArray[2] = "";
- this.setWareData();
- }
- }
- }
- //--------------总金额,税率等的计算------------
- private void controlCalculate()
- {
- int intCurrentRowNumber = this.dgrd_StockTable.CurrentCell.RowNumber;
- string strWareCount = this.dgrd_StockTable[intCurrentRowNumber,1].ToString();
- string strWarePrice = this.dgrd_StockTable[intCurrentRowNumber,2].ToString();
- string strTotalCounter = this.dgrd_StockTable[intCurrentRowNumber,6].ToString();
- //当销售价和销售数量不为空时则将当前光标移到下一行的开始处,以便DataTable依据表达式自动计算DataColumn的值
- if (strWareCount != "" && strWarePrice != "" && strTotalCounter=="")
- {
- this.dgrd_StockTable.CurrentCell = new DataGridCell(intCurrentRowNumber+1,0);
- }
- //为底部三个文本框计算总金额
- decimal intTotalCount = 0;
- decimal intNoTax = 0;
- decimal intTax = 0;
- //首先判断列是否为空
- object obj = newTable.Compute("SUM (金额)","");
- if (obj.GetType().ToString() != "System.DBNull")
- {
- intTotalCount = (decimal)this.newTable.Compute("SUM (金额)","");
- intNoTax = (decimal)this.newTable.Compute("SUM (不含税额)","");
- intTax = (decimal)this.newTable.Compute("SUM (税额)","");
- }
- this.txt_TotalCount.Text = intTotalCount.ToString("N");
- this.txt_NoTax.Text = intNoTax.ToString("N");
- this.txt_Tax.Text = intTax.ToString("N");
- }
- }
- }