/// <summary> /// Edit Function /// </summary> /// <param name="decMasterId"></param> public void Edit(decimal decMasterId) { try { int inRowCount = dgvPaymentVoucher.RowCount; int inTableRowCount = dtblPartyBalance.Rows.Count; int inB = 0; PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo(); //PaymentMasterSP SpPaymentMaster = new PaymentMasterSP(); PaymentDetailsInfo InfoPaymentDetails = new PaymentDetailsInfo(); //PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP(); PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll(); LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); LedgerPostingInfo InfoLegerPosting = new LedgerPostingInfo(); PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo(); PartyBalanceBll BllPartyBalance = new PartyBalanceBll(); BankReconciliationBll BllBankReconcilation = new BankReconciliationBll(); InfoPaymentMaster.Date = dtpDate.Value; InfoPaymentMaster.PaymentMasterId = decMasterId; InfoPaymentMaster.Extra1 = string.Empty; InfoPaymentMaster.Extra2 = string.Empty; InfoPaymentMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId; InfoPaymentMaster.InvoiceNo = txtVoucherNo.Text.Trim(); InfoPaymentMaster.LedgerId = Convert.ToDecimal(cmbBankorCash.SelectedValue.ToString()); InfoPaymentMaster.Narration = txtNarration.Text.Trim(); InfoPaymentMaster.SuffixPrefixId = decDailySuffixPrefixId; decimal decTotalAmount = TotalAmountCalculation(); InfoPaymentMaster.TotalAmount = decTotalAmount; InfoPaymentMaster.UserId = PublicVariables._decCurrentUserId; InfoPaymentMaster.VoucherNo = strVoucherNo; InfoPaymentMaster.VoucherTypeId = decPaymentVoucherTypeId; decimal decPaymentMasterId = BllPaymentVoucher.PaymentMasterEdit(InfoPaymentMaster); if (decPaymentmasterId != 0) { MasterLedgerPostingEdit(); } foreach (object obj in arrlstOfRemove) { string str = Convert.ToString(obj); BllPaymentVoucher.PaymentDetailsDelete(Convert.ToDecimal(str)); BllLedgerPosting.LedgerPostDeleteByDetailsId(Convert.ToDecimal(str), strVoucherNo, decPaymentVoucherTypeId); } BllLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decPaymentVoucherTypeId, 12); decimal decPaymentDetailsId1 = 0; for (int inI = 0; inI < inRowCount - 1; inI++) { InfoPaymentDetails.Amount = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString()); InfoPaymentDetails.ExchangeRateId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString()); InfoPaymentDetails.Extra1 = string.Empty; InfoPaymentDetails.Extra2 = string.Empty; if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty) { InfoPaymentDetails.LedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString()); } if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty) { InfoPaymentDetails.ChequeNo = dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString(); if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty) { InfoPaymentDetails.ChequeDate = Convert.ToDateTime(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value); } else { InfoPaymentDetails.ChequeDate = DateTime.Now; } } else { InfoPaymentDetails.ChequeNo = string.Empty; InfoPaymentDetails.ChequeDate = DateTime.Now; } InfoPaymentDetails.PaymentMasterId = decPaymentMasterId; if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].FormattedValue.ToString() == "0")//if new rows are added { if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")//add new rows added which are completed { decimal decPaymentDetailsId = BllPaymentVoucher.PaymentDetailsAdd(InfoPaymentDetails);//to add new rows in payment details if (decPaymentDetailsId != 0) { for (int inJ = 0; inJ < inTableRowCount; inJ++) { if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString()) { PartyBalanceAddOrEdit(inJ); } } inB++; DetailsLedgerPosting(inI, decPaymentDetailsId);//to add new ledger posting } } } else { if (dgvPaymentVoucher.Rows[inI].HeaderCell.Value != null && dgvPaymentVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")//add new rows updated which are completed { InfoPaymentDetails.PaymentDetailsId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value.ToString()); decimal decPaymentDetailsId = BllPaymentVoucher.PaymentDetailsEdit(InfoPaymentDetails);//to edit rows if (decPaymentDetailsId != 0) { for (int inJ = 0; inJ < inTableRowCount; inJ++) { if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString()) { PartyBalanceAddOrEdit(inJ); } } inB++; decPaymentDetailsId1 = InfoPaymentDetails.PaymentDetailsId; decimal decLedgerPostId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value.ToString()); DetailsLedgerPostingEdit(inI, decLedgerPostId, decPaymentDetailsId1); } } else { decimal decDetailsId = Convert.ToDecimal(dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value.ToString()); BllPaymentVoucher.PaymentDetailsDelete(decDetailsId); BllLedgerPosting.LedgerPostDeleteByDetailsId(decDetailsId, strVoucherNo, decPaymentVoucherTypeId); for (int inJ = 0; inJ < dtblPartyBalance.Rows.Count; inJ++) { if (dtblPartyBalance.Rows.Count == inJ) { break; } if (dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty) { if (dtblPartyBalance.Rows[inJ]["LedgerId"].ToString() == dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString()) { if (dtblPartyBalance.Rows[inJ]["PartyBalanceId"].ToString() != "0") { arrlstOfDeletedPartyBalanceRow.Add(dtblPartyBalance.Rows[inJ]["PartyBalanceId"]); } } } } } } } DeletePartyBalanceOfRemovedRow(); isUpdated = true; Messages.UpdatedMessage(); if (cbxPrintafterSave.Checked) { if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix") { PrintForDotMatrix(decPaymentmasterId); } else { Print(decPaymentMasterId); } } if (frmPaymentRegisterObj != null) { this.Close(); frmPaymentRegisterObj.CallFromPaymentVoucher(this); } if (frmPaymentReportObj != null) { this.Close(); frmPaymentReportObj.CallFromPaymentVoucher(this); } if (frmDayBookObj != null) { this.Close(); } if (frmBillallocationObj != null) { this.Close(); } this.Close(); } catch (Exception ex) { MessageBox.Show("PV18:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }