public void SaveFunction() { try { AdvancePaymentBll bllAdvancePayment = new AdvancePaymentBll(); AdvancePaymentInfo infoAdvancepayment = new AdvancePaymentInfo(); LedgerPostingBll BllLedgerPosting = new LedgerPostingBll(); MonthlySalaryVoucherBll BllMonthlySalary = new MonthlySalaryVoucherBll(); if (CheckAdvanceAmount()) { if (!BllMonthlySalary.CheckSalaryAlreadyPaidOrNotForAdvancePayment(Convert.ToDecimal(cmbEmployee.SelectedValue.ToString()), dtpSalaryMonth.Value)) { if (!bllAdvancePayment.CheckSalaryAlreadyPaidOrNot(Convert.ToDecimal(cmbEmployee.SelectedValue.ToString()), dtpSalaryMonth.Value)) { if (isAutomatic == true) { infoAdvancepayment.VoucherNo = strVoucherNo; } else { infoAdvancepayment.VoucherNo = txtAdvanceVoucherNo.Text.Trim(); } infoAdvancepayment.EmployeeId = Convert.ToDecimal(cmbEmployee.SelectedValue.ToString()); infoAdvancepayment.SalaryMonth = Convert.ToDateTime(dtpSalaryMonth.Text.ToString()); infoAdvancepayment.Chequenumber = txtCheckNo.Text.ToString(); infoAdvancepayment.Date = Convert.ToDateTime(txtDate.Text.ToString()); infoAdvancepayment.Amount = Convert.ToDecimal(txtAmount.Text.ToString()); if (isAutomatic) { infoAdvancepayment.InvoiceNo = strInvoiceNo; } else { infoAdvancepayment.InvoiceNo = txtAdvanceVoucherNo.Text.Trim(); } infoAdvancepayment.LedgerId = Convert.ToDecimal(cmbCashOrBank.SelectedValue.ToString()); infoAdvancepayment.ChequeDate = Convert.ToDateTime(txtChequeDate.Text.ToString()); infoAdvancepayment.Narration = txtNarration.Text.Trim(); infoAdvancepayment.ExtraDate = Convert.ToDateTime(DateTime.Now.ToString()); infoAdvancepayment.Extra1 = string.Empty; infoAdvancepayment.Extra2 = string.Empty; infoAdvancepayment.VoucherTypeId = decPaymentVoucherTypeId; infoAdvancepayment.SuffixPrefixId = decPaymentSuffixPrefixId; infoAdvancepayment.FinancialYearId = PublicVariables._decCurrentFinancialYearId; if (btnAdvancePaymentSave.Text == "Save") { if (decAdvancePaymentsId != -1) { List<DataTable> ListObj = new List<DataTable>(); ListObj = bllAdvancePayment.AdvancePaymentAddWithIdentity(infoAdvancepayment, isAutomatic); foreach (DataRow dr in ListObj[0].Rows) { decAdvancePaymentId = Convert.ToDecimal(dr.ItemArray[0].ToString()); strUpdatedVoucherNumber = dr.ItemArray[1].ToString(); strUpdatedInvoiceNumber = dr.ItemArray[2].ToString(); } if (!isAutomatic) { strVoucherNo = txtAdvanceVoucherNo.Text.Trim(); } if (isAutomatic) { if (Convert.ToDecimal(strUpdatedVoucherNumber) != Convert.ToDecimal(strVoucherNo)) { Messages.InformationMessage("Voucher number changed from " + strInvoiceNo + " to " + strUpdatedInvoiceNumber); strVoucherNo = strUpdatedVoucherNumber.ToString(); strInvoiceNo = strUpdatedInvoiceNumber; } } txtAdvanceVoucherNo.Focus(); } LedgerPosting(Convert.ToDecimal(cmbCashOrBank.SelectedValue.ToString()), decAdvancePaymentId); Messages.SavedMessage(); Clear(); } } else { Messages.InformationMessage(" Advance already paid for this month"); dtpSalaryMonth.Focus(); } } else { Messages.InformationMessage("Cant pay advance for this month,Salary already paid"); dtpSalaryMonth.Focus(); } } } catch (Exception ex) { MessageBox.Show("AP1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }