/// <summary> /// Checking invalid entries for save or update and call its curresponding function /// </summary> public void SaveOrEditFuction() { try { decimal decCalcAmount = 0; decimal decBalance = 0; string strStatus = string.Empty; //ContraMasterSP spContraMaster = new ContraMasterSP(); ContraVoucherDetailsBll bllContraVoucherDetails = new ContraVoucherDetailsBll(); AccountLedgerBll bllAccountLedger = new AccountLedgerBll(); SettingsBll BllSettings = new SettingsBll(); if (txtVoucherNo.Text == string.Empty) { Messages.InformationMessage("Enter voucher number"); txtVoucherNo.Focus(); } else if (cmbBankAccount.SelectedIndex == -1) { Messages.InformationMessage("Select cash or bank account"); cmbBankAccount.Focus(); } else { if (RemoveIncompleteRowsFromGrid()) { if (dtpContraVoucherDate.Value.ToString() != string.Empty) { strStatus = BllSettings.SettingsStatusCheck("NegativeCashTransaction"); if (rbtnWithdrawal.Checked) { decBalance = bllAccountLedger.CheckLedgerBalance(Convert.ToDecimal(cmbBankAccount.SelectedValue.ToString())); decCalcAmount = decBalance - Convert.ToDecimal(txtTotal.Text); if (decCalcAmount < 0) { if (strStatus == "Warn") { if (MessageBox.Show("Negative balance exists,Do you want to Continue", "Openmiracle", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { SaveOrEdit(); } } else if (strStatus == "Block") { MessageBox.Show("Cannot continue ,due to negative balance", "Openmiracle", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { SaveOrEdit(); } } else { SaveOrEdit(); } } else { bool isNegativeLedger = false; int inRowCount = dgvContraVoucher.RowCount; for (int i = 0; i < inRowCount - 1; i++) { decCalcAmount = 0; decimal decledgerId = 0; if (dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value != null && dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString() != "") { decledgerId = Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvcmbBankorCashAccount"].Value.ToString()); } decBalance = bllAccountLedger.CheckLedgerBalance(decledgerId); decCalcAmount = decBalance - Convert.ToDecimal(dgvContraVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString()); if (decCalcAmount < 0) { isNegativeLedger = true; break; } } if (isNegativeLedger) { if (strStatus == "Warn") { if (MessageBox.Show("Negative balance exists,Do you want to Continue", "Openmiracle", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { SaveOrEdit(); } } else if (strStatus == "Block") { MessageBox.Show("Cannot continue ,due to negative balance", "Openmiracle", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { SaveOrEdit(); } } else { SaveOrEdit(); } } } } } } catch (Exception ex) { MessageBox.Show("CV:15" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to call the SaveOrEditFunction after checking negative balance /// </summary> public void SaveOrEdit() { try { if (CheckUserPrivilege.PrivilegeCheck(PublicVariables._decCurrentUserId, this.Name, btnSave.Text)) { JournalVoucherBll bllJournalMaster = new JournalVoucherBll(); //===================================================== SettingsBll BllSettings = new SettingsBll(); string strStatus = BllSettings.SettingsStatusCheck("NegativeCashTransaction"); decimal decBalance = 0; decimal decCalcAmount = 0; AccountLedgerBll bllAccountLedger = new AccountLedgerBll(); bool isNegativeLedger = false; int inRowCount = dgvJournalVoucher.RowCount; for (int i = 0; i < inRowCount - 1; i++) { decimal decledgerId = 0; if (dgvJournalVoucher.Rows[i].Cells["dgvcmbAccountLedger"].Value != null && dgvJournalVoucher.Rows[i].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty) { decledgerId = Convert.ToDecimal(dgvJournalVoucher.Rows[i].Cells["dgvcmbAccountLedger"].Value.ToString()); decBalance = bllAccountLedger.CheckLedgerBalance(decledgerId); if (dgvJournalVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvJournalVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty) { decCalcAmount = decBalance - Convert.ToDecimal(dgvJournalVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString()); } if (decCalcAmount < 0) { isNegativeLedger = true; break; } } } //========================================= if (isNegativeLedger) { if (strStatus == "Warn") { if (MessageBox.Show("Negative balance exists,Do you want to Continue", "Open miracle", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { SaveOrEditFunction(); } } else if (strStatus == "Block") { MessageBox.Show("Cannot continue ,due to negative balance", "Open miracle", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { SaveOrEditFunction(); } } else { SaveOrEditFunction(); } } else { Messages.NoPrivillageMessage(); } } catch (Exception ex) { MessageBox.Show("JV18:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }