private void ToolBar1_ButtonClick(System.Object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { switch (ToolBar1.Buttons.IndexOf(e.Button)) { case 0: //新建单据 NewOutBill(); break; case 1: //添加物品 if (TextBox1.Enabled && TextBox1.Text == "") { MessageBox.Show("单据号不能为空!"); TextBox1.Focus(); TextBox1.SelectAll(); return; } if (cbVendor.Enabled && cbVendor.Text == "") { MessageBox.Show("供应商不能为空!"); cbVendor.Focus(); cbVendor.SelectAll(); return; } if (cbInStorageDept.Enabled && cbInStorageDept.Text == "") { MessageBox.Show("仓库不能为空!"); cbInStorageDept.Focus(); cbInStorageDept.SelectAll(); return; } if (cbDepartment.Enabled && cbDepartment.Text == "") { MessageBox.Show("部门不能为空!"); cbDepartment.Focus(); cbDepartment.SelectAll(); return; } switch (CurrentOutBillTypeCode) { case "A": case "D": case "H": case "F": case "B": case "G": //向 领料单 ,直拨单,部门退仓库,部门退供应商,仓库退供应商 添加物品 if (! CheckBox1.Checked) { frmSelMaterial frmselmtrl = new frmSelMaterial(); frmselmtrl.CurrentStorageDeptName = cbInStorageDept.Text; frmselmtrl.CreateSelectedMaterialsTable(); frmselmtrl.BillTypeCode = CurrentOutBillTypeCode; frmselmtrl.ShowDialog(); if (frmselmtrl.DialogResult == DialogResult.OK) { if (frmselmtrl.dgSelMaterials.VisibleRowCount > 0) { DataRowCollection rc; DataRow myNewRow; object[] rowVals = new object[6]; for (int i = 0; i <= frmselmtrl.SelectedMaterials.Rows.Count - 1; i++) { rc = SelectedMaterials.Rows; rowVals[0] = frmselmtrl.SelectedMaterials.Rows[i][0]; rowVals[1] = frmselmtrl.SelectedMaterials.Rows[i][1]; rowVals[2] = frmselmtrl.SelectedMaterials.Rows[i][2]; rowVals[3] = Convert.ToDecimal(frmselmtrl.SelectedMaterials.Rows[i][3]); rowVals[4] = frmselmtrl.SelectedMaterials.Rows[i][4] == "" ? 0 : Convert.ToDecimal(frmselmtrl.SelectedMaterials.Rows[i][4]); rowVals[5] = Convert.ToDecimal(frmselmtrl.SelectedMaterials.Rows[i][5]); myNewRow = rc.Add(rowVals); } dgMaterials.DataSource = SelectedMaterials; } } } else { MessageBox.Show("已审核单据不能添加物品"); } break; } break; case 2: //保存当前单据 if (TextBox1.Enabled && TextBox1.Text == "") { MessageBox.Show("单据号不能为空!"); TextBox1.Focus(); TextBox1.SelectAll(); return; } if (cbVendor.Enabled && cbVendor.Text == "") { MessageBox.Show("供应商不能为空!"); cbVendor.Focus(); cbVendor.SelectAll(); return; } if (cbInStorageDept.Enabled && cbInStorageDept.Text == "") { MessageBox.Show("仓库不能为空!"); cbInStorageDept.Focus(); cbInStorageDept.SelectAll(); return; } if (cbDepartment.Enabled && cbDepartment.Text == "") { MessageBox.Show("部门不能为空!"); cbDepartment.Focus(); cbDepartment.SelectAll(); return; } if (dgMaterials.VisibleRowCount > 0) { if (! CheckBox1.Checked) { if (SaveBill(TextBox1.Text, CurrentOutBillTypeCode, DateTimePicker1.Value.ToString(), "", rms_var.GetDeptCode(cbDepartment.Text), rms_var.GetDeptCode(cbInStorageDept.Text), Label9.Text, false, TextBox2.Text)) { //添加单据物品列表 if (SaveBillsMaterials(TextBox1.Text)) { LoadCurrentMonthBill(CurrentOutBillTypeCode); CurrentBillRecNo = BillCount; MessageBox.Show("单据保存成功"); } } } else { MessageBox.Show("已审核单据不能进行修改"); } } else { MessageBox.Show("物品列表为空,请添加物品"); } break; case 4: //删单据 if (TextBox1.Text != "") { if (! CheckBox1.Checked) { if (MessageBox.Show("确定要删除当前单据吗?" +"\r\n"+ "注意:删除单据将会影响部门成本的核算!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (DeleteBill(TextBox1.Text)) { MessageBox.Show("删除成功"); LoadCurrentMonthBill(CurrentOutBillTypeCode); CurrentBillRecNo = BillCount; switch (CurrentOutBillTypeCode) { case "A": NewOutBill(); break; } } } } else { MessageBox.Show("已审核单据不能删除"); } } break; case 5: //删物品 if (dgMaterials.VisibleRowCount > 0) { if (! CheckBox1.Checked) { if (MessageBox.Show("确定要删除单据中的当前物品吗?" +"\r\n"+ "注意:删除单据将会影响部门成本的核算!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (DeleteBillsMaterial(TextBox1.Text, dgMaterials[dgMaterials.CurrentRowIndex, 0].ToString())) { MessageBox.Show("删除成功"); //获取物品记录 SelectedMaterials = LoadCurrentBillMaterials(TextBox1.Text); dgMaterials.DataSource = SelectedMaterials; RefreshTotalPrice(); } } } else { MessageBox.Show("已审核单据不能删除"); } } break; case 7: //审核 if (CurrentBillRecNo != -1 && CurrentBillRecNo != BillCount) { if (dgMaterials.VisibleRowCount > 0) { if (CheckBox1.Checked == false) { if (rms_var.AllowAudit()) { if (MessageBox.Show("确定要审核当前单据吗?" +"\r\n"+ "注意:经审核过的单据将不能再进行修改!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { CheckBox1.Checked = true; //更新审核标志 if (UpdateAuditSign(TextBox1.Text)) { LoadCurrentMonthBill(CurrentOutBillTypeCode); MessageBox.Show("审核成功"); } } } else { MessageBox.Show("您没有审核权。"); return; } } else { MessageBox.Show("已经审核了"); } } } break; case 9: //前一单据 if (CurrentBillRecNo == 0) { return; } CurrentBillRecNo--; if (CurrentBillRecNo != -1) { TextBox1.Enabled = false; TextBox1.Text = BillList.Rows[CurrentBillRecNo][0].ToString(); TextBox3.Text = rms_var.GetStorageBillType(BillList.Rows[CurrentBillRecNo][1].ToString()); DateTimePicker1.Text = BillList.Rows[CurrentBillRecNo][2].ToString(); cbInStorageDept.Text = rms_var.GetDeptName(BillList.Rows[CurrentBillRecNo][3].ToString()); cbVendor.Text = rms_var.GetVendorName(BillList.Rows[CurrentBillRecNo][4].ToString()); Label9.Text = BillList.Rows[CurrentBillRecNo][8].ToString(); TextBox2.Text = BillList.Rows[CurrentBillRecNo][9].ToString(); cbDepartment.Text = rms_var.GetDeptName(BillList.Rows[CurrentBillRecNo][3].ToString()); CheckBox1.Checked = BillList.Rows[CurrentBillRecNo][11]=="1"?true:false; //获取物品记录 SelectedMaterials = LoadCurrentBillMaterials(TextBox1.Text); dgMaterials.DataSource = SelectedMaterials; RefreshTotalPrice(); } else { CurrentBillRecNo = 0; } break; case 10: //后一单据 if (CurrentBillRecNo >= BillCount - 1) { return; } CurrentBillRecNo++; if (CurrentBillRecNo < BillCount) { TextBox1.Enabled = false; TextBox1.Text = BillList.Rows[CurrentBillRecNo][0].ToString(); TextBox3.Text = rms_var.GetStorageBillType(BillList.Rows[CurrentBillRecNo][1].ToString()); DateTimePicker1.Text = BillList.Rows[CurrentBillRecNo][2].ToString(); cbInStorageDept.Text = rms_var.GetDeptName(BillList.Rows[CurrentBillRecNo][3].ToString()); cbVendor.Text = rms_var.GetVendorName(BillList.Rows[CurrentBillRecNo][4].ToString()); Label9.Text = BillList.Rows[CurrentBillRecNo][8].ToString(); TextBox2.Text = BillList.Rows[CurrentBillRecNo][9].ToString(); cbDepartment.Text = rms_var.GetDeptName(BillList.Rows[CurrentBillRecNo][3].ToString()); CheckBox1.Checked =BillList.Rows[CurrentBillRecNo][11]=="1"?true:false; //获取物品记录 SelectedMaterials = LoadCurrentBillMaterials(TextBox1.Text); dgMaterials.DataSource = SelectedMaterials; RefreshTotalPrice(); } break; case 12: if (dgMaterials.VisibleRowCount > 0) { if (MessageBox.Show("确定要打印当前单据吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (! PrintReport("SELECT MaterialCode,MaterialName,Unit,Quantity,Price,name,quantity*price as totalprice FROM view_OutStorageMaterials where billno='" + TextBox1.Text + "'")) { MessageBox.Show("打印失败!如果问题依然存在请联系系统管理员。"); } } } else { MessageBox.Show("单据没有保存,请首先添加物品并保存单据后再进行打印操作。"); } break; case 14: this.Close(); break; } }
private void ToolBar1_ButtonClick(System.Object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { switch (ToolBar1.Buttons.IndexOf(e.Button)) { case 0: //新建单据 if (CurrentInBillTypeCode == "I") //采购入库 { NewIncomeBill(); } else if (CurrentInBillTypeCode == "M") //仓库报溢 { NewOverFlowBill(); } break; case 1: //添加物品 if (CurrentInBillTypeCode == "I") { if (TextBox1.Text == "") { MessageBox.Show("单据号不能为空!"); TextBox1.Focus(); TextBox1.SelectAll(); return; } if (cbVendor.Text == "") { MessageBox.Show("供应商不能为空!"); cbVendor.Focus(); cbVendor.SelectAll(); return; } if (cbPurchase.Text == "") { MessageBox.Show("采购人不能为空!"); cbPurchase.Focus(); cbPurchase.SelectAll(); return; } } else if (CurrentInBillTypeCode == "M") { if (TextBox1.Text == "") { MessageBox.Show("单据号不能为空!"); TextBox1.Focus(); TextBox1.SelectAll(); return; } } if (! CheckBox1.Checked) { frmSelMaterial frmselmtrl = new frmSelMaterial(); frmselmtrl.CurrentStorageDeptName = cbInStorageDept.Text; frmselmtrl.CreateSelectedMaterialsTable(); frmselmtrl.BillTypeCode = CurrentInBillTypeCode; frmselmtrl.ShowDialog(); if (frmselmtrl.DialogResult == DialogResult.OK) { if (frmselmtrl.dgSelMaterials.VisibleRowCount > 0) { DataRowCollection rc; DataRow myNewRow; object[] rowVals = new object[6]; for (int i = 0; i <= frmselmtrl.SelectedMaterials.Rows.Count - 1; i++) { rc = SelectedMaterials.Rows; rowVals[0] = frmselmtrl.SelectedMaterials.Rows[i][0]; rowVals[1] = frmselmtrl.SelectedMaterials.Rows[i][1]; rowVals[2] = frmselmtrl.SelectedMaterials.Rows[i][2]; rowVals[3] = frmselmtrl.SelectedMaterials.Rows[i][3]; rowVals[4] = frmselmtrl.SelectedMaterials.Rows[i][4]; rowVals[5] = frmselmtrl.SelectedMaterials.Rows[i][5]; myNewRow = rc.Add(rowVals); } dgMaterials.DataSource = SelectedMaterials; //刷新物品价格 RefreshTotalPrice(); } } } else { MessageBox.Show("已审核单据不能添加物品"); } break; case 2: //保存当前单据 if (CurrentInBillTypeCode == "I") { if (TextBox1.Text == "") { MessageBox.Show("单据号不能为空!"); TextBox1.Focus(); TextBox1.SelectAll(); return; } if (cbVendor.Text == "") { MessageBox.Show("供应商不能为空!"); cbVendor.Focus(); cbVendor.SelectAll(); return; } if (cbPurchase.Text == "") { MessageBox.Show("采购人不能为空!"); cbPurchase.Focus(); cbPurchase.SelectAll(); return; } } else if (CurrentInBillTypeCode == "M") { if (TextBox1.Text == "") { MessageBox.Show("单据号不能为空!"); TextBox1.Focus(); TextBox1.SelectAll(); return; } } if (dgMaterials.VisibleRowCount > 0) { if (! CheckBox1.Checked) { if (SaveBill(TextBox1.Text, CurrentInBillTypeCode, DateTimePicker1.Value.ToString(), rms_var.GetVendorCode(cbVendor.Text), rms_var.GetEmployeeID(cbPurchase.Text), Label9.Text, rms_var.GetDeptCode(cbInStorageDept.Text), false, TextBox2.Text)) { //添加单据物品列表 if (SaveBillsMaterials(TextBox1.Text)) { LoadCurrentMonthBill(CurrentInBillTypeCode); CurrentBillRecNo = BillCount; MessageBox.Show("单据保存成功"); } } } else { MessageBox.Show("已审核单据不能进行修改"); } } else { MessageBox.Show("入库物品列表为空,请添加物品"); } break; case 4: //删单据 if (TextBox1.Text != "") { if (! CheckBox1.Checked) { if (MessageBox.Show("确定要删除当前单据吗?" +"\r\n"+ "注意:删除单据将会影响菜品成本以及部门成本的核算!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (DeleteBill(TextBox1.Text)) { MessageBox.Show("删除成功"); LoadCurrentMonthBill(CurrentInBillTypeCode); CurrentBillRecNo = BillCount; if (CurrentInBillTypeCode == "I") { NewIncomeBill(); } else { NewOverFlowBill(); } } } } else { MessageBox.Show("已审核单据不能删除"); } } break; case 5: //删物品 if (dgMaterials.VisibleRowCount > 0) { if (! CheckBox1.Checked) { if (MessageBox.Show("确定要删除单据中的当前物品吗?" +"\r\n"+ "注意:删除单据将会影响菜品成本以及部门成本的核算!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (DeleteBillsMaterial(TextBox1.Text, dgMaterials[dgMaterials.CurrentRowIndex, 0].ToString())) { MessageBox.Show("删除成功"); //获取物品记录 SelectedMaterials = LoadCurrentBillMaterials(TextBox1.Text); dgMaterials.DataSource = SelectedMaterials; RefreshTotalPrice(); } } } else { MessageBox.Show("已审核单据不能删除"); } } break; case 7: //审核 //If CurrentBillRecNo <> -1 And CurrentBillRecNo <> BillCount Then if (CurrentBillRecNo != -1) { if (dgMaterials.VisibleRowCount > 0) { if (CheckBox1.Checked == false) { //检测有无审核权 if (rms_var.AllowAudit()) { if (MessageBox.Show("确定要审核当前单据吗?" +"\r\n"+ "注意:经审核过的单据将不能再进行修改!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { CheckBox1.Checked = true; //更新审核标志 if (UpdateAuditSign(TextBox1.Text)) { LoadCurrentMonthBill(CurrentInBillTypeCode); MessageBox.Show("审核成功"); } } } else { MessageBox.Show("您没有审核权。"); return; } } else { MessageBox.Show("已经审核了"); } } } break; case 9: //前一单据 try { if (CurrentBillRecNo == 0) { return; } CurrentBillRecNo--; if (CurrentBillRecNo != -1) { TextBox1.Enabled = false; //billno,storagebilltypecode,indate,depcode,vendorcode,processman,operator,note,audited TextBox1.Text = BillList.Rows[CurrentBillRecNo][0].ToString(); TextBox3.Text = rms_var.GetStorageBillType(BillList.Rows[CurrentBillRecNo][1].ToString()); DateTimePicker1.Text = BillList.Rows[CurrentBillRecNo][2].ToString(); cbInStorageDept.Text = rms_var.GetDeptName(BillList.Rows[CurrentBillRecNo][3].ToString()); cbVendor.Text = rms_var.GetVendorName(BillList.Rows[CurrentBillRecNo][4].ToString()); cbPurchase.Text = rms_var.GetEmployeeName(BillList.Rows[CurrentBillRecNo][5].ToString()); Label9.Text = BillList.Rows[CurrentBillRecNo][6].ToString(); TextBox2.Text = BillList.Rows[CurrentBillRecNo][7].ToString(); CheckBox1.Checked =BillList.Rows[CurrentBillRecNo][8].ToString().Trim()=="1"?true:false; //获取物品记录 SelectedMaterials = LoadCurrentBillMaterials(TextBox1.Text); dgMaterials.DataSource = SelectedMaterials; RefreshTotalPrice(); } else { CurrentBillRecNo = 0; } } catch(Exception err){} break; case 10: //后一单据 if (CurrentBillRecNo >= BillCount - 1) { return; } CurrentBillRecNo++; if (CurrentBillRecNo < BillCount) { TextBox1.Enabled = false; //billno,storagebilltypecode,indate,depcode,vendorcode,processman,operator,note,audited TextBox1.Text = BillList.Rows[CurrentBillRecNo][0].ToString(); TextBox3.Text = rms_var.GetStorageBillType(BillList.Rows[CurrentBillRecNo][1].ToString()); DateTimePicker1.Text = BillList.Rows[CurrentBillRecNo][2].ToString(); cbInStorageDept.Text = rms_var.GetDeptName(BillList.Rows[CurrentBillRecNo][3].ToString()); cbVendor.Text = rms_var.GetVendorName(BillList.Rows[CurrentBillRecNo][4].ToString()); cbPurchase.Text = rms_var.GetEmployeeName(BillList.Rows[CurrentBillRecNo][5].ToString()); Label9.Text = BillList.Rows[CurrentBillRecNo][6].ToString(); TextBox2.Text = BillList.Rows[CurrentBillRecNo][7].ToString(); CheckBox1.Checked =BillList.Rows[CurrentBillRecNo][8].ToString().Trim()=="1"?true:false; //获取物品记录 SelectedMaterials = LoadCurrentBillMaterials(TextBox1.Text); dgMaterials.DataSource = SelectedMaterials; RefreshTotalPrice(); } break; case 12: if (dgMaterials.VisibleRowCount > 0) { if (MessageBox.Show("确定要打印当前单据吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (! PrintReport("SELECT MaterialCode,MaterialName,Unit,name,Quantity,Price,quantity*price as totalprice FROM view_InStorageMaterials where billno='" + TextBox1.Text + "'")) { MessageBox.Show("打印失败!如果问题依然存在请联系系统管理员。"); } } } else { MessageBox.Show("单据没有保存,请首先添加物品并保存单据后再进行打印操作。"); } break; case 14: this.Close(); break; } }
private void ToolBar1_ButtonClick(System.Object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { switch (ToolBar1.Buttons.IndexOf(e.Button)) { case 0: frmSelMaterial frmselmtrl = new frmSelMaterial(); frmselmtrl.CurrentStorageDeptName = CurrentStorageDeptName; frmselmtrl.CreateSelectedMaterialsTable(); frmselmtrl.ShowDialog(); if (frmselmtrl.DialogResult == DialogResult.OK) { if (frmselmtrl.dgSelMaterials.VisibleRowCount > 0) { DataRowCollection rc; DataRow myNewRow; object[] rowVals = new object[6]; for (int i = 0; i <= frmselmtrl.SelectedMaterials.Rows.Count - 1; i++) { rc = SelectedMaterials.Rows; rowVals[0] = frmselmtrl.SelectedMaterials.Rows[i][0]; rowVals[1] = frmselmtrl.SelectedMaterials.Rows[i][1]; rowVals[2] = frmselmtrl.SelectedMaterials.Rows[i][2]; rowVals[3] = frmselmtrl.SelectedMaterials.Rows[i][3]; rowVals[4] = frmselmtrl.SelectedMaterials.Rows[i][4]; rowVals[5] = frmselmtrl.SelectedMaterials.Rows[i][5]; myNewRow = rc.Add(rowVals); } dgMaterials.DataSource = SelectedMaterials; } } break; case 1: if (dgMaterials.VisibleRowCount > 0) { if (MessageBox.Show("确定要删除当前选中的物品吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { if (DeleteMaterial(dgMaterials[dgMaterials.CurrentRowIndex, 0].ToString())) { MessageBox.Show("删除成功"); //获取物品记录 SelectedMaterials = LoadMaterialsInventory(); dgMaterials.DataSource = SelectedMaterials; } } } break; case 2: if (dgMaterials.VisibleRowCount > 0) { if (SaveMaterials(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString())) { MessageBox.Show("单据保存成功"); } } break; case 6: this.Close(); break; } }