private void cboBookType_SelectedIndexChanged(object sender, EventArgs e) { prepared = false; DBGrid.DataSource = null; switch (cboBookType.SelectedIndex) { case 0: dalCustomerList dalCust = new dalCustomerList(); BindingCollection <modCustomerSimpleList> listCust = dalCust.GetSimpleList(out Util.emsg); DBGrid.DataSource = listCust; if (listCust != null) { for (int i = 2; i < DBGrid.ColumnCount; i++) { DBGrid.Columns[i].Visible = false; } DBGrid.Columns[0].Width = 90; DBGrid.Columns[1].Width = DBGrid.Width - 140; } break; case 1: dalVendorList dalVendor = new dalVendorList(); BindingCollection <modVendorList> listVendor = dalVendor.GetIList("1", string.Empty, out Util.emsg); DBGrid.DataSource = listVendor; if (listVendor != null) { for (int i = 1; i < DBGrid.ColumnCount; i++) { DBGrid.Columns[i].Visible = false; } DBGrid.Columns[0].Width = DBGrid.Width - 50; } break; case 2: dalOtherReceivableObject dalORec = new dalOtherReceivableObject(); BindingCollection <modOtherReceivableObject> listORec = dalORec.GetIList(true, out Util.emsg); DBGrid.DataSource = listORec; if (listORec != null) { for (int i = 1; i < DBGrid.ColumnCount; i++) { DBGrid.Columns[i].Visible = false; } DBGrid.Columns[0].Width = DBGrid.Width - 50; } break; case 3: dalOtherPayableObject dalOPay = new dalOtherPayableObject(); BindingCollection <modOtherPayableObject> listOPay = dalOPay.GetIList(true, out Util.emsg); DBGrid.DataSource = listOPay; if (listOPay != null) { for (int i = 1; i < DBGrid.ColumnCount; i++) { DBGrid.Columns[i].Visible = false; } DBGrid.Columns[0].Width = DBGrid.Width - 50; } break; case 4: dalAccBankAccount dalCash = new dalAccBankAccount(); BindingCollection <modAccBankAccount> listCash = dalCash.GetIList(out Util.emsg); DBGrid.DataSource = listCash; if (listCash != null) { for (int i = 2; i < DBGrid.ColumnCount; i++) { DBGrid.Columns[i].Visible = false; } DBGrid.Columns[0].Width = 90; DBGrid.Columns[1].Width = DBGrid.Width - 140; } break; } prepared = true; }
private void toolSave_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; DBGrid.EndEdit(); if (dtpFormDate.Value < Util.modperiod.StartDate) { MessageBox.Show("该日期的数据已锁定,不能更新数据!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); dtpFormDate.Focus(); return; } if (string.IsNullOrEmpty(txtCheckId.Text.Trim())) { MessageBox.Show(clsTranslate.TranslateString("Check Id") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCheckId.Focus(); return; } if (DBGrid.RowCount == 0) { MessageBox.Show("没有明细数据", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } for (int i = 0; i < DBGrid.RowCount; i++) { switch (DBGrid.Rows[i].Cells[0].Value.ToString().Trim()) { case "1055": //应收帐款 dalCustomerList dalcust = new dalCustomerList(); if (!dalcust.Exists(DBGrid.Rows[i].Cells["DetailId"].Value.ToString().Trim(), out Util.emsg)) { MessageBox.Show("应收帐款明细不正确!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } break; case "5145": //应付帐款 dalVendorList dalvendor = new dalVendorList(); if (!dalvendor.Exists(DBGrid.Rows[i].Cells["DetailId"].Value.ToString().Trim(), out Util.emsg)) { MessageBox.Show("应付帐款明细不正确!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } break; case "1060": //其它应收款 dalOtherReceivableObject dalrec = new dalOtherReceivableObject(); if (!dalrec.Exists(DBGrid.Rows[i].Cells["DetailId"].Value.ToString().Trim(), out Util.emsg)) { MessageBox.Show("其它应收款明细不正确!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } break; case "5155": //其它应付款 dalOtherReceivableObject dalpay = new dalOtherReceivableObject(); if (!dalpay.Exists(DBGrid.Rows[i].Cells["DetailId"].Value.ToString().Trim(), out Util.emsg)) { MessageBox.Show("其它应付款明细不正确!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } break; case "1075": //应收票据 case "5125": //应付票据 if (DBGrid.Rows[i].Cells[7].Value == null || string.IsNullOrEmpty(DBGrid.Rows[i].Cells[7].Value.ToString())) { MessageBox.Show(clsTranslate.TranslateString("Check No") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (DBGrid.Rows[i].Cells[8].Value == null || string.IsNullOrEmpty(DBGrid.Rows[i].Cells[8].Value.ToString())) { MessageBox.Show(clsTranslate.TranslateString("Check Type") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (DBGrid.Rows[i].Cells[9].Value == null || string.IsNullOrEmpty(DBGrid.Rows[i].Cells[9].Value.ToString())) { MessageBox.Show(clsTranslate.TranslateString("Bank Name") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (DBGrid.Rows[i].Cells[10].Value == null || string.IsNullOrEmpty(DBGrid.Rows[i].Cells[10].Value.ToString())) { MessageBox.Show(clsTranslate.TranslateString("Promise Date") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } break; } } if (Math.Abs(Convert.ToDecimal(txtMny.Text) - GetDetailSum()) > Convert.ToDecimal("0.001")) { MessageBox.Show("金额不平衡!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } modAccCheckForm mod = new modAccCheckForm(); mod.FormId = txtFormId.Text.Trim(); mod.FormDate = dtpFormDate.Value; mod.CheckId = Convert.ToInt32(txtCheckId.Text); mod.Remark = txtRemark.Text.Trim(); mod.UpdateUser = Util.UserId; mod.Status = 0; string detaillist = string.Empty; BindingCollection <modAccCheckFormDetail> list = new BindingCollection <modAccCheckFormDetail>(); for (int i = 0; i < DBGrid.RowCount; i++) { modAccCheckFormDetail modd = new modAccCheckFormDetail(); modd.Seq = i + 1; modd.SubjectId = DBGrid.Rows[i].Cells[0].Value.ToString(); modd.SubjectName = DBGrid.Rows[i].Cells[1].Value.ToString(); modd.DetailId = DBGrid.Rows[i].Cells[2].Value == null ? string.Empty : DBGrid.Rows[i].Cells[2].Value.ToString(); modd.DetailName = DBGrid.Rows[i].Cells[3].Value.ToString(); modd.Currency = DBGrid.Rows[i].Cells[4].Value == null ? string.Empty : DBGrid.Rows[i].Cells[4].Value.ToString(); modd.Mny = Convert.ToDecimal(DBGrid.Rows[i].Cells[5].Value.ToString()); modd.ExchangeRate = Convert.ToDecimal(DBGrid.Rows[i].Cells[6].Value.ToString()); modd.CheckNo = DBGrid.Rows[i].Cells[7].Value == null ? string.Empty : DBGrid.Rows[i].Cells[7].Value.ToString(); modd.CheckType = DBGrid.Rows[i].Cells[8].Value == null ? string.Empty : DBGrid.Rows[i].Cells[8].Value.ToString(); modd.BankName = DBGrid.Rows[i].Cells[9].Value == null ? string.Empty : DBGrid.Rows[i].Cells[9].Value.ToString(); modd.PromiseDate = Convert.ToDateTime(DBGrid.Rows[i].Cells[10].Value); modd.Remark = DBGrid.Rows[i].Cells[11].Value == null ? string.Empty : DBGrid.Rows[i].Cells[11].Value.ToString(); list.Add(modd); } bool ret = _dal.Save(_action, mod, list, out Util.emsg); if (ret) { this.DialogResult = DialogResult.OK; this.Dispose(); } else { MessageBox.Show(Util.emsg, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } finally { this.Cursor = Cursors.Default; } }