/// <summary> /// Gridview cell value changed , doing basic calculations and checking invalid entries /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvPaymentVoucher_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex != -1 && e.ColumnIndex != -1) { TotalAmount(); if (dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty) { if (dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value == null || dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value.ToString() == string.Empty) { dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(1); } } AccountGroupSP spAccountGroup = new AccountGroupSP(); AccountLedgerSP SpAccountLedger = new AccountLedgerSP(); if (dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value.ToString().Trim() != string.Empty) { if (dgvPaymentVoucher.CurrentCell.ColumnIndex == dgvPaymentVoucher.CurrentRow.Cells["dgvcmbAccountLedger"].ColumnIndex) { /*************Remove partybalance while changing the ledger ************/ if (inUpdatingRowIndexForPartyRemove != -1) { int inTableRowCount = dtblPartyBalance.Rows.Count; for (int inJ = 0; inJ < inTableRowCount; inJ++) { if (dtblPartyBalance.Rows.Count == inJ) { break; } if (Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["ledgerId"].ToString()) == decUpdatingLedgerForPartyremove) { if (dtblPartyBalance.Rows[inJ]["PartyBalanceId"].ToString() != "0") { arrlstOfDeletedPartyBalanceRow.Add(dtblPartyBalance.Rows[inJ]["PartyBalanceId"]); } dtblPartyBalance.Rows.RemoveAt(inJ); inJ--; } } dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty; decUpdatingLedgerForPartyremove = 0; inUpdatingRowIndexForPartyRemove = -1; } /*************************************************************************/ decimal decLedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value.ToString()); bool IsBankAccount = spAccountGroup.AccountGroupwithLedgerId(decLedgerId); decimal decI = Convert.ToDecimal(SpAccountLedger.AccountGroupIdCheck(dgvPaymentVoucher.CurrentRow.Cells["dgvcmbAccountLedger"].FormattedValue.ToString())); if (decI > 0)//to make amount and currency read only when party is choosen as ledger { dgvPaymentVoucher.CurrentRow.Cells["dgvtxtAmount"].ReadOnly = true; dgvPaymentVoucher.CurrentRow.Cells["dgvtxtAmount"].Value = string.Empty; dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(1); dgvPaymentVoucher.CurrentRow.Cells["dgvcmbCurrency"].ReadOnly = true; } else { dgvPaymentVoucher.CurrentRow.Cells["dgvtxtAmount"].ReadOnly = false; SettingsSP spSettings = new SettingsSP(); if (spSettings.SettingsStatusCheck("MultiCurrency") == "Yes") { dgvcmbCurrency.ReadOnly = false; } else { dgvcmbCurrency.ReadOnly = true; } } } } CheckColumnMissing(); DateValidation objVal = new DateValidation(); TextBox txtDate1 = new TextBox(); if (dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value != null) { txtDate1.Text = dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value.ToString(); bool isDate = objVal.DateValidationFunction(txtDate1); if (isDate) { dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = txtDate1.Text; } else { dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = PublicVariables._dtCurrentDate.ToString("dd-MMM-yyyy"); } } } } catch (Exception ex) { MessageBox.Show("PV48:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Call the totalamount,SlNo,InvalidEntry functions to do the all are the process even if change one value of the grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvContraVoucher_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { AccountGroupSP spAccountGroup = new AccountGroupSP(); if (e.RowIndex != -1 && e.ColumnIndex != -1) { if (dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbBankorCashAccount"].Value != null && dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbBankorCashAccount"].Value.ToString() != "") { if (dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value == null || dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value.ToString() == "") { dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(1);//PublicVariables._decCurrencyId; } } TotalAmount(); SlNo(); if (dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbBankorCashAccount"].Value != null) { decimal decLedger = Convert.ToDecimal(dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbBankorCashAccount"].Value.ToString()); isBankAcocunt = spAccountGroup.AccountGroupwithLedgerId(decLedger); if (isBankAcocunt) { dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].ReadOnly = false; dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeNo"].ReadOnly = false; } else { dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].ReadOnly = true; dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeNo"].ReadOnly = true; dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = string.Empty; dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeNo"].Value = string.Empty; } } CheckColumnMissing(e); if (!dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].ReadOnly) { DateValidation objVal = new DateValidation(); TextBox txtDate = new TextBox(); if (dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value != null) { txtDate.Text = dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value.ToString(); bool isDate = objVal.DateValidationFunction(txtDate); if (isDate) { dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = txtDate.Text; } else { dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = PublicVariables._dtCurrentDate.ToString("dd-MMM-yyyy"); } } } } } catch (Exception ex) { MessageBox.Show("CV:42" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Grid Fill function while coming from other form to update or delete /// </summary> public void FillFunction() { try { PaymentMasterSP SpPaymentMaster = new PaymentMasterSP(); PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo(); PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP(); PartyBalanceSP SpPartyBalance = new PartyBalanceSP(); LedgerPostingSP SpLedgerPosting = new LedgerPostingSP(); VoucherTypeSP SpVoucherType = new VoucherTypeSP(); AccountGroupSP spAccountGroup = new AccountGroupSP(); AccountLedgerSP SpAccountLedger = new AccountLedgerSP(); InfoPaymentMaster = SpPaymentMaster.PaymentMasterViewByMasterId(decPaymentmasterId);//view master details isAutomatic = SpVoucherType.CheckMethodOfVoucherNumbering(InfoPaymentMaster.VoucherTypeId); if (isAutomatic) { txtVoucherNo.ReadOnly = true; txtVoucherNo.Text = InfoPaymentMaster.InvoiceNo; txtDate.Focus(); } else { txtVoucherNo.ReadOnly = false; txtVoucherNo.Text = InfoPaymentMaster.InvoiceNo; txtVoucherNo.Focus(); } dtpDate.Text = InfoPaymentMaster.Date.ToString(); cmbBankorCash.SelectedValue = InfoPaymentMaster.LedgerId; txtNarration.Text = InfoPaymentMaster.Narration; txtTotal.Text = InfoPaymentMaster.TotalAmount.ToString(); decDailySuffixPrefixId = InfoPaymentMaster.SuffixPrefixId; decPaymentVoucherTypeId = InfoPaymentMaster.VoucherTypeId; strVoucherNo = InfoPaymentMaster.VoucherNo; strInvoiceNo = InfoPaymentMaster.InvoiceNo; DataTable dtbl = new DataTable(); dtbl = SpPaymentDetails.PaymentDetailsViewByMasterId(decPaymentmasterId);//view details details for (int inI = 0; inI < dtbl.Rows.Count; inI++) { dgvPaymentVoucher.Rows.Add(); dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value = Convert.ToDecimal(dtbl.Rows[inI]["ledgerId"].ToString()); dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentMasterId"].Value = dtbl.Rows[inI]["paymentMasterId"].ToString(); dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value = dtbl.Rows[inI]["paymentDetailsId"].ToString(); dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value = dtbl.Rows[inI]["amount"].ToString(); dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(dtbl.Rows[inI]["exchangeRateId"].ToString()); decimal decDetailsId1 = Convert.ToDecimal(dtbl.Rows[inI]["paymentDetailsId"].ToString()); decimal decLedgerPostingId = SpLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, decPaymentVoucherTypeId); dgvPaymentVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString(); decimal decLedgerId = Convert.ToDecimal(dtbl.Rows[inI]["ledgerId"].ToString()); bool IsBankAccount = spAccountGroup.AccountGroupwithLedgerId(decLedgerId); decimal decI = Convert.ToDecimal(SpAccountLedger.AccountGroupIdCheck(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].FormattedValue.ToString())); if (decI > 0)//to make amount and currency read only when party is choosen as ledger { dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = true; dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = true; } else { dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = false; dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = false; } dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value = dtbl.Rows[inI]["ChequeNo"].ToString(); if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty) { dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value = Convert.ToDateTime(dtbl.Rows[inI]["ChequeDate"].ToString()).ToString("dd-MMM-yyyy"); } } DataTable dtbl1 = new DataTable(); dtbl1 = SpPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decPaymentVoucherTypeId, strVoucherNo, InfoPaymentMaster.Date); dtblPartyBalance = dtbl1; } catch (Exception ex) { MessageBox.Show("PV36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Fill function for updation /// </summary> public void FillFunction() { try { isValueChange = false; ReceiptMasterInfo InfoReceiptMaster = new ReceiptMasterInfo(); ReceiptMasterSP SpReceiptMaster = new ReceiptMasterSP(); ReceiptDetailsInfo InfoReceiptDetails = new ReceiptDetailsInfo(); ReceiptDetailsSP SpReceiptDetails = new ReceiptDetailsSP(); PartyBalanceSP SpPartyBalance = new PartyBalanceSP(); LedgerPostingSP SpLedgerPosting = new LedgerPostingSP(); VoucherTypeSP SpVoucherType = new VoucherTypeSP(); AccountGroupSP spAccountGroup = new AccountGroupSP(); AccountLedgerSP SpAccountLedger = new AccountLedgerSP(); InfoReceiptMaster = SpReceiptMaster.ReceiptMasterViewByMasterId(decRecieptmasterId); isAutomatic = SpVoucherType.CheckMethodOfVoucherNumbering(InfoReceiptMaster.VoucherTypeId); if (isAutomatic) { txtVoucherNo.ReadOnly = true; txtVoucherNo.Text = InfoReceiptMaster.InvoiceNo; } else { txtVoucherNo.ReadOnly = false; txtVoucherNo.Text = InfoReceiptMaster.VoucherNo; } dtpDate.Value = InfoReceiptMaster.Date; cmbCashOrBank.SelectedValue = InfoReceiptMaster.LedgerId; txtNarration.Text = InfoReceiptMaster.Narration; txtTotal.Text = InfoReceiptMaster.TotalAmount.ToString(); decDailySuffixPrefixId = InfoReceiptMaster.SuffixPrefixId; decReceiptVoucherTypeId = InfoReceiptMaster.VoucherTypeId; strVoucherNo = InfoReceiptMaster.VoucherNo; strInvoiceNo = InfoReceiptMaster.InvoiceNo; DataTable dtbl = new DataTable(); dtbl = SpReceiptDetails.ReceiptDetailsViewByMasterId(decRecieptmasterId); for (int inI = 0; inI < dtbl.Rows.Count; inI++) { dgvReceiptVoucher.Rows.Add(); dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value = Convert.ToDecimal(dtbl.Rows[inI]["ledgerId"].ToString()); dgvReceiptVoucher.Rows[inI].Cells["dgvtxtreceiptMasterId"].Value = dtbl.Rows[inI]["receiptMasterId"].ToString(); dgvReceiptVoucher.Rows[inI].Cells["dgvtxtreceiptDetailsId"].Value = dtbl.Rows[inI]["receiptDetailsId"].ToString(); dgvReceiptVoucher.Rows[inI].Cells["dgvtxtAmount"].Value = dtbl.Rows[inI]["amount"].ToString(); dgvReceiptVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(dtbl.Rows[inI]["exchangeRateId"].ToString()); decimal decDetailsId1 = Convert.ToDecimal(dtbl.Rows[inI]["receiptDetailsId"].ToString()); decimal decLedgerPostingId = SpLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, decReceiptVoucherTypeId); dgvReceiptVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString(); decimal decLedgerId = Convert.ToDecimal(dtbl.Rows[inI]["ledgerId"].ToString()); bool IsBankAccount = spAccountGroup.AccountGroupwithLedgerId(decLedgerId); decimal decI = Convert.ToDecimal(SpAccountLedger.AccountGroupIdCheck(dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].FormattedValue.ToString())); if (decI > 0) { dgvReceiptVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = true; dgvReceiptVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = true; } else { dgvReceiptVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = false; dgvReceiptVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = false; } if (dtbl.Rows[inI]["chequeNo"].ToString() != string.Empty) { dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value = dtbl.Rows[inI]["chequeNo"].ToString(); dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value = Convert.ToDateTime(dtbl.Rows[inI]["chequeDate"].ToString()).ToString("dd-MMM-yyyy"); } dgvReceiptVoucher.Rows[inI].HeaderCell.Value = string.Empty; } DataTable dtbl1 = new DataTable(); dtbl1 = SpPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decReceiptVoucherTypeId, strVoucherNo, InfoReceiptMaster.Date); dtblPartyBalance = dtbl1; isValueChange = true; } catch (Exception ex) { MessageBox.Show("RV34:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }