private void tsb审核通过_Click(object sender, EventArgs e) { //确认 if (MessageBox.Show("是否确认审核通过?", "提示", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } dgvResult.EndEdit();//结束dgv的编辑状态,防止选择状态为改变 //判断是否选择记录 int count = 0; try { foreach (DataGridViewRow mRow in dgvResult.Rows) { if (Convert.ToBoolean(mRow.Cells["ColumnChecked"].Value) == true) { int expenseId = Convert.ToInt32(mRow.Cells["编号"].Value); var daExpense = Mydb.DaExpenses.SingleOrDefault(a => a.IntID == expenseId); if (daExpense != null) { daExpense.IntStatus = 3; //插入一条操作记录 var daExpenseAuditLog = new DaExpenseAuditLog() { IntOperationID = 3, IntExpenseID = expenseId, IntUserID = Classes.PubClass.UserId }; Mydb.DaExpenseAuditLogs.Add(daExpenseAuditLog); count++; } } } if (count < 1) { MessageBox.Show("请勾选要审核的行"); return; } int ret = Mydb.SaveChanges(); if (ret > 0) { MessageBox.Show("审核成功"); SearchData(); return; } else { MessageBox.Show("审核失败"); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void SaveApproved(int mType) { try { dgvDaPurchaseContract.EndEdit();//结束dgv的编辑状态,防止选择状态为改变 int count = 0; foreach (DataGridViewRow mRow in dgvDaPurchaseContract.Rows) { if (Convert.ToBoolean(mRow.Cells[dpc选择.Index].Value) == true) { //获取合同ID var obj = mRow.Cells["编号"].Value; if (obj == null) { return; } int mContractId = Convert.ToInt32(obj); var mDaPurchaseContract = mydb.DaPurchaseContracts.SingleOrDefault(a => a.IntID == mContractId); if (mDaPurchaseContract != null) { mDaPurchaseContract.IntStatus = mType; mydb.DaPurchaseContractAuditLogs.Add(new DaPurchaseContractAuditLog() { IntOperationID = mType, IntPurchaseContractID = mContractId, IntUserID = Classes.PubClass.UserId }); count++; } } } if (count < 1) { MessageBox.Show("没有选择行"); return; } int ret = mydb.SaveChanges(); if (ret > 0) { MessageBox.Show("审批完成"); //刷新 数据 InitPurchaseContract(); return; } else { MessageBox.Show("审批失败"); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
private void btnExpense_Click(object sender, EventArgs e) { if (expenseTable.Rows.Count < 1) { MessageBox.Show("请选择要报销的物品"); return; } //添加 合同物品明细 foreach (DataRow mRow in expenseTable.Rows) { var mdcg = new DaExpense() { IntContractGoodsID = Convert.ToInt32(mRow["IntContractGoodsId"]), IntGoodsID = Convert.ToInt32(mRow["IntID"]), IntEmpNum = Classes.PubClass.UserId, MonPrice = Convert.ToDecimal(mRow["单价"]), NumCount = Convert.ToInt32(mRow["数量"]), MonSum = Convert.ToDecimal(mRow["金额"]), IntStatus = 1 }; mydb.DaExpenses.Add(mdcg); } int ret = mydb.SaveChanges(); if (ret > 0) { MessageBox.Show(@"保存成功"); DialogResult = DialogResult.OK; } else { MessageBox.Show(@"保存失败"); } }
private void btnSave_Click(object sender, EventArgs e) { try { //判断入库数量是否超过合同数量 decimal mContractNum = myEntity.DaContractGoods.Where(d => d.IntID == MContractGoodsId && d.IntGoodsID == _mInvoice.IntGoodsID).Sum(d => d.NumCount); //decimal mHasStockInNum = myEntity.DaInvoices.Where(d => d.IntContractID == mContractID).Sum(d => d.NumCount) ?? 0; if (_mInvoice.NumCount < 1) { MessageBox.Show("入库数量必须大于0"); return; } if (_mInvoice.NumCount > mContractNum) { MessageBox.Show(@"发票数量大于合同数量,不能提交"); return; } if (Convert.ToDecimal(txtNoTaxPrice.Text) > Convert.ToDecimal(txtPriceTax.Text)) { MessageBox.Show(@"不含税单价不能大于含税单价!"); return; } if (MInvoiceId > 0) { //修改 } else { //新增 myEntity.DaInvoices.Add(_mInvoice); } int mRet = myEntity.SaveChanges(); if (mRet > 0) { MessageBox.Show(@"保存成功"); DialogResult = DialogResult.OK; } else { MessageBox.Show(@"保存失败"); } } catch (DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors) { foreach (var item2 in item.ValidationErrors) { //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage)); } } } }
private void llSelectSupplier_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (dgvDaGoods.SelectedRows.Count < 1) { MessageBox.Show("请选择采购物品"); return; } using (择供应商 mForm = new 择供应商()) { mForm.MultiSelect = true; mForm.mDaGoodsID = ((DaGoods)DaGoodsBindingSource[dgvDaGoods.SelectedRows[0].Index]).IntID; //mForm.myEntity = myEntity;// = ((DaSupplier)DaSupplierBindingSource.Current).IntID; if (mForm.ShowDialog() == DialogResult.OK) { //((System.Data.Entity.Infrastructure.IObjectContextAdapter)myEntity).ObjectContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, myEntity.DaSupplierContacts); //((System.Data.Entity.Infrastructure.IObjectContextAdapter)myEntity).ObjectContext.AcceptAllChanges(); try { foreach (int suppilerId in mForm.mDaSupplierID) { DaGoodsSupplier mDaGoodsSupplier = new DaGoodsSupplier { IntGoodsID = mForm.mDaGoodsID, IntSuppilerID = suppilerId }; myEntity.DaGoodsSuppliers.Add(mDaGoodsSupplier); } int ret = myEntity.SaveChanges(); if (ret > 0) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); return; } InitDaGoodsSupplier(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors) { foreach (var item2 in item.ValidationErrors) { //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage)); } } } } } }
private void btnSave_Click(object sender, EventArgs e) { try { //判断入库数量是否超过合同数量 decimal mContractNum = Convert.ToDecimal(txtContractCount.Text); decimal mHasStockInNum = Convert.ToDecimal(txtHasStockInCount.Text); if (_mDaStockIn.NumCount + mHasStockInNum > mContractNum) { MessageBox.Show("入库数量大于合同数量,不能提交"); return; } if (_mDaStockIn.NumCount < 1) { MessageBox.Show("到货数量必须大于0"); return; } if (MDaStockInId > 0) { } else { myEntity.DaStockIns.Add(_mDaStockIn); } int mRet = myEntity.SaveChanges(); if (mRet > 0) { MessageBox.Show("保存成功"); DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("保存失败"); return; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors) { foreach (var item2 in item.ValidationErrors) { //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage)); } } } }
private void btnSave_Click(object sender, EventArgs e) { //mDaGoods.IntUnit = ((ZdGoodsUnit)cmbUnit.SelectedItem).ID; if (mDaGoodsID > 0) { //修改 } else { mDaGoods.IntEmpNum = Classes.PubClass.UserId; //增加 myEntity.DaGoods1.Add(mDaGoods); } try { rbCaiGou_CheckedChanged(sender, e); int ret = myEntity.SaveChanges(); { if (ret > 0) { MessageBox.Show("保存成功"); DialogResult = System.Windows.Forms.DialogResult.OK; btnSave.Enabled = false; } else { MessageBox.Show("保存失败"); } } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors) { foreach (var item2 in item.ValidationErrors) { //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage)); } } } }
private void btnSave_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(txtMoney.Text)) { MessageBox.Show("请输入借款金额"); return; } if (Convert.ToDecimal(txtMoney.Text) <= 0) { MessageBox.Show("借款金额需大于0"); return; } if (_daLoan != null) { mydb.DaLoans.Add(_daLoan); } int ret = mydb.SaveChanges(); if (ret > 0) { MessageBox.Show("保存成功"); DialogResult = DialogResult.OK; } else { MessageBox.Show("保存失败"); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors) { foreach (var item2 in item.ValidationErrors) { //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage)); } } } }
private void btnWriteOff_Click(object sender, EventArgs e) { if (dgvLoan.SelectedRows.Count < 1) { MessageBox.Show("请选择要冲销的借款记录"); return; } try { //冲销 //判断状态是否为已借款 //获取借款编号 var daLoanId = Convert.ToInt32(dgvLoan.SelectedRows[0].Cells["编号"].Value); var daLoan = Mydb.DaLoans.SingleOrDefault(a => a.IntID == daLoanId); if (daLoan == null) { return; } if (daLoan.IntStatus == 2) { return; } daLoan.IntStatus = 2; int ret = Mydb.SaveChanges(); if (ret > 0) { MessageBox.Show("冲销完成"); InitData(); return; } else { MessageBox.Show("冲销失败"); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { if (DaContactID > 0) { //修改 } else { //增加 myEntity.DaSupplierContacts.Add(mDaSuppContact); } try { int ret = myEntity.SaveChanges(); { if (ret > 0) { MessageBox.Show("保存成功"); DialogResult = System.Windows.Forms.DialogResult.OK; btnSave.Enabled = false; } else { MessageBox.Show("保存失败"); } } } catch (DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors) { foreach (var item2 in item.ValidationErrors) { //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage)); } } } }
private void dgvStockIn_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } object obj = dgvStockIn.Rows[e.RowIndex].Cells["编号"]; if (obj == null) { return; } //获取到货ID int daStockInId = Convert.ToInt32(dgvStockIn.Rows[e.RowIndex].Cells["编号"].Value); if (e.ColumnIndex == dsi检验通过.Index) { //审核通过 if ( MessageBox.Show( string.Format("确认采购物品:{0}检验通过?", dgvStockIn.Rows[e.RowIndex].Cells["物品名称"].Value), "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { //获取到货ID var daStockIn = mydb.DaStockIns.SingleOrDefault(a => a.IntID == daStockInId); if (daStockIn != null) { daStockIn.IntStatus = 2; int ret = mydb.SaveChanges(); if (ret > 0) { MessageBox.Show("保存成功!"); //刷新 SearchData(); } } } } if (e.ColumnIndex == dsi检验不通过.Index) { //审核不通过 if ( MessageBox.Show( string.Format("确认采购物品:{0}检验不通过?", dgvStockIn.Rows[e.RowIndex].Cells["物品名称"].Value), "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { var daStockIn = mydb.DaStockIns.SingleOrDefault(a => a.IntID == daStockInId); if (daStockIn != null) { daStockIn.IntStatus = 3; int ret = mydb.SaveChanges(); if (ret > 0) { MessageBox.Show("保存成功!"); //刷新 SearchData(); } } } } }
private void btnSave_Click(object sender, EventArgs e) { try { if (DaSupplierID == 0) { mDaSupplier = new DaSupplier() { VcName = txtName.Text.Trim(), VcRegCapital = txtRegCapital.Text.Trim(), VcLegalRep = txtLegalRep.Text.Trim(), VcTaxID = txtTaxID.Text.Trim(), VcOpeningBank = txtOpeningBank.Text.Trim(), VcBankAccount = txtBankAccount.Text.Trim(), VcAddress = txtAddress.Text.Trim(), VcWebsite = txtWebsite.Text.Trim(), VcTel = txtTel.Text.Trim(), VcFax = txtFax.Text.Trim(), VcPostCode = txtPostCode.Text.Trim(), VcRemark = txtRemark.Text.Trim(), IntEmpNum = Classes.PubClass.UserId, VcNum = txtDaSupplierNum.Text.Trim(), IntStatus = 1 }; string maxNum = myEntity.DaSuppliers.Select(a => a.VcNum).Max(); //获取最新供应商编号 maxNum = !string.IsNullOrEmpty(maxNum) ? (Convert.ToInt64(maxNum) + 1).ToString() : "1000001"; mDaSupplier.VcNum = maxNum; //mDaSupplier.VcName = txtName.Text.Trim(); //mDaSupplier.VcRegCapital = txtRegCapital.Text.Trim(); //mDaSupplier.VcLegalRep = txtLegalRep.Text.Trim(); //mDaSupplier.VcTaxID = txtTaxID.Text.Trim(); //mDaSupplier.VcOpeningBank = txtOpeningBank.Text.Trim(); //mDaSupplier.VcBankAccount = txtBankAccount.Text.Trim(); //mDaSupplier.VcAddress = txtAddress.Text.Trim(); //mDaSupplier.VcWebsite = txtWebsite.Text.Trim(); //mDaSupplier.VcTel = txtTel.Text.Trim(); //mDaSupplier.VcFax = txtFax.Text.Trim(); //mDaSupplier.VcPostCode = txtPostCode.Text.Trim(); //mDaSupplier.VcRemark = txtRemark.Text.Trim(); //mDaSupplier.IntEmpNum = Classes.PubClass.UserId; //mDaSupplier.VcNum = "1000001"; //DbEntityEntry<DaSupplier> entry = myEntity.Entry<DaSupplier>(mDaSupplier); //entry.State = EntityState.Added; myEntity.DaSuppliers.Add(mDaSupplier); //myEntity.SaveChanges(); } else { mDaSupplier.VcName = txtName.Text.Trim(); mDaSupplier.VcRegCapital = txtRegCapital.Text.Trim(); mDaSupplier.VcLegalRep = txtLegalRep.Text.Trim(); mDaSupplier.VcTaxID = txtTaxID.Text.Trim(); mDaSupplier.VcOpeningBank = txtOpeningBank.Text.Trim(); mDaSupplier.VcBankAccount = txtBankAccount.Text.Trim(); mDaSupplier.VcAddress = txtAddress.Text.Trim(); mDaSupplier.VcWebsite = txtWebsite.Text.Trim(); mDaSupplier.VcTel = txtTel.Text.Trim(); mDaSupplier.VcFax = txtFax.Text.Trim(); mDaSupplier.VcPostCode = txtPostCode.Text.Trim(); mDaSupplier.VcRemark = txtRemark.Text.Trim(); DbEntityEntry <DaSupplier> entry = myEntity.Entry <DaSupplier>(mDaSupplier); entry.State = EntityState.Unchanged; entry.Property(a => a.VcName).IsModified = true; entry.Property(a => a.VcRegCapital).IsModified = true; entry.Property(a => a.VcLegalRep).IsModified = true; entry.Property(a => a.VcTaxID).IsModified = true; entry.Property(a => a.VcOpeningBank).IsModified = true; entry.Property(a => a.VcBankAccount).IsModified = true; entry.Property(a => a.VcAddress).IsModified = true; entry.Property(a => a.VcWebsite).IsModified = true; entry.Property(a => a.VcTel).IsModified = true; entry.Property(a => a.VcFax).IsModified = true; entry.Property(a => a.VcPostCode).IsModified = true; entry.Property(a => a.VcRemark).IsModified = true; //myEntity.SaveChanges(); } //if (myEntity.Database.Connection.State == ConnectionState.Closed) // myEntity.Database.Connection.Open(); //using (var mTrans = myEntity.Database.Connection.BeginTransaction()) using (TransactionScope mTrans = new TransactionScope()) { int ret = myEntity.SaveChanges(); if (ret > 0) { //MessageBox.Show("保存成功"); //return; } else { MessageBox.Show("保存失败"); return; } if (DaGoodsID > 0) { mDaGoodsSupplier = new DaGoodsSupplier() { IntGoodsID = DaGoodsID, IntSuppilerID = mDaSupplier.IntID }; myEntity.DaGoodsSuppliers.Add(mDaGoodsSupplier); ret = myEntity.SaveChanges(); } if (ret > 0) { mTrans.Complete(); MessageBox.Show("保存成功"); DialogResult = System.Windows.Forms.DialogResult.OK; btnSave.Enabled = false; return; } else { MessageBox.Show("保存失败"); return; } } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors) { foreach (var item2 in item.ValidationErrors) { //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage)); } item.ValidationErrors.Clear(); } } }
private void btnSave_Click(object sender, EventArgs e) { try { if (mDaPurchaseContractID != 0) { //修改 if (mDaPurchaseContract.IntStatus == 2 || mDaPurchaseContract.IntStatus == 4) { mDaPurchaseContract.IntStatus = 1; } } else { //新增 //mDaPurchaseContract.IntGoodsID = mDaGoods.IntID; //获取最新合同号 string strDateMonth = DateTime.Now.ToString("yyyyMMdd"); string mMaxNum = myEntity.DaPurchaseContracts.Where(d => d.VcNum.Contains(strDateMonth)).Max(d => d.VcNum); mMaxNum = string.IsNullOrEmpty(mMaxNum) ? strDateMonth + "001" : (Convert.ToInt64(mMaxNum) + 1).ToString(); txtContractNum.Text = mMaxNum; mDaPurchaseContract.VcNum = mMaxNum; mDaPurchaseContract.IntSupplierID = mDaSupplierId; myEntity.DaPurchaseContracts.Add(mDaPurchaseContract); } //mDaPurchaseContract.IntGoodsID = mDaGoods.IntID; using (var mTrans = new TransactionScope()) { int ret = myEntity.SaveChanges(); if (ret > 0) { //添加 合同物品明细 foreach (DataRow mRow in goodsTable.Rows) { var mdcg = new DaContractGood() { IntContractID = mDaPurchaseContract.IntID, IntGoodsID = Convert.ToInt32(mRow["IntID"]), IntEmpNum = Classes.PubClass.UserId, MonPrice = Convert.ToDecimal(mRow["MonPrice"]), NumCount = Convert.ToInt32(mRow["NumCount"]), MonSum = Convert.ToDecimal(mRow["MonSum"]) }; myEntity.DaContractGoods.Add(mdcg); } ret = myEntity.SaveChanges(); if (ret > 0) { mTrans.Complete(); MessageBox.Show(@"保存成功"); DialogResult = DialogResult.OK; } else { MessageBox.Show(@"保存失败"); } } else { MessageBox.Show(@"保存失败"); } } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors) { foreach (var item2 in item.ValidationErrors) { //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage)); MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage)); } } } }