/// <summary>
        /// When doubleclicking on the grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvReport_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            decimal decVouchertypeId = 0;
            string strVoucherNo = string.Empty;
            try
            {
                if (dgvReport.CurrentRow.Index == e.RowIndex)
                {
                    if ((dgvReport.CurrentRow.Cells["voucherTypeId"].Value != null && dgvReport.CurrentRow.Cells["voucherTypeId"].Value.ToString() != string.Empty))
                    {
                        int inI = dgvReport.CurrentCell.RowIndex;
                        foreach (DataGridViewRow dgv in dgvReport.Rows)
                        {
                            if (dgv.Cells["VoucherNo"].Value != null && dgv.Cells["VoucherNo"].Value.ToString() != string.Empty &&
                                   dgv.Cells["voucherTypeId"].Value != null && dgv.Cells["voucherTypeId"].Value.ToString() != string.Empty)
                            {
                                strVoucherType = dgv.Cells["VoucherType"].Value.ToString();
                                decVouchertypeId = Convert.ToDecimal(dgv.Cells["voucherTypeId"].Value.ToString());
                                strVoucherNo = dgv.Cells["VoucherNo"].Value.ToString();
                            }
                            else
                            {
                                if (dgv.Cells["ledgerId"].Value.ToString() != string.Empty)
                                {
                                    decledgerId = decimal.Parse(dgv.Cells["ledgerId"].Value.ToString());
                                    strVoucherType = dgv.Cells["Account Ledger"].Value.ToString();
                                    frmLedgerDetails frmLedger = new frmLedgerDetails();
                                    frmLedger = Application.OpenForms["frmLedgerDetails"] as frmLedgerDetails;
                                    if (frmLedger == null)
                                    {
                                        frmLedger = new frmLedgerDetails();
                                        frmLedger.MdiParent = formMDI.MDIObj;
                                        frmLedger.callFromAgeing(this, decledgerId);
                                        this.Enabled = false;
                                    }
                                }

                            }
                            if (dgv.Index == inI)
                            {
                                break;
                            }
                        }
                        if (strVoucherType == "Payment Voucher")
                        {
                            PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
                            decMasterId = BllPaymentVoucher.paymentMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPaymentVoucher frmPaymentVoucher = new frmPaymentVoucher();
                            frmPaymentVoucher = Application.OpenForms["frmPaymentVoucher"] as frmPaymentVoucher;
                            if (frmPaymentVoucher == null)
                            {
                                frmPaymentVoucher = new frmPaymentVoucher();
                                frmPaymentVoucher.MdiParent = formMDI.MDIObj;
                                frmPaymentVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Receipt Voucher")
                        {
                            RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();
                            //ReceiptMasterSP spRecieptMaster = new ReceiptMasterSP();
                            decMasterId = bllRecieptVoucher.ReceiptMasterIdView(decVouchertypeId, strVoucherNo);
                            frmReceiptVoucher frmReceiptVoucher = new frmReceiptVoucher();
                            frmReceiptVoucher = Application.OpenForms["frmReceiptVoucher"] as frmReceiptVoucher;
                            if (frmReceiptVoucher == null)
                            {
                                frmReceiptVoucher = new frmReceiptVoucher();
                                frmReceiptVoucher.MdiParent = formMDI.MDIObj;
                                frmReceiptVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Journal Voucher")
                        {
                            JournalVoucherBll bllJournalMaster = new JournalVoucherBll();
                            decMasterId = bllJournalMaster.JournalMasterIdView(decVouchertypeId, strVoucherNo);
                            frmJournalVoucher frmJournalVoucher = new frmJournalVoucher();
                            frmJournalVoucher = Application.OpenForms["frmJournalVoucher"] as frmJournalVoucher;
                            if (frmJournalVoucher == null)
                            {
                                frmJournalVoucher = new frmJournalVoucher();
                                frmJournalVoucher.MdiParent = formMDI.MDIObj;
                                frmJournalVoucher.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "PDC Receivable")
                        {
                            PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
                            decMasterId = BllPDCReciveble.PdcReceivableMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPdcReceivable frmPdcReceivable = new frmPdcReceivable();
                            frmPdcReceivable = Application.OpenForms["frmPdcReceivable"] as frmPdcReceivable;
                            if (frmPdcReceivable == null)
                            {
                                frmPdcReceivable = new frmPdcReceivable();
                                frmPdcReceivable.MdiParent = formMDI.MDIObj;
                                frmPdcReceivable.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "PDC Payable")
                        {
                            PDCPayableBll BllPDCPayable = new PDCPayableBll();
                            decMasterId = BllPDCPayable.PdcPayableMasterIdView(decVouchertypeId, strVoucherNo);
                            frmPdcPayable frmPdcPayable = new frmPdcPayable();
                            frmPdcPayable = Application.OpenForms["frmPdcPayable"] as frmPdcPayable;
                            if (frmPdcPayable == null)
                            {
                                frmPdcPayable = new frmPdcPayable();
                                frmPdcPayable.MdiParent = formMDI.MDIObj;
                                frmPdcPayable.callFromAgeing(this, decMasterId);
                                this.Enabled = false;
                            }
                        }
                        else if (strVoucherType == "Sales Invoice")
                        {
                            //SalesMasterSP spMaster = new SalesMasterSP();
                            SalesInvoiceBll BllSalesInvoice = new SalesInvoiceBll();
                            decMasterId = BllSalesInvoice.SalesMasterIdViewByvoucherNoAndVoucherType(decVouchertypeId, strVoucherNo);
                            //SalesMasterSP spSalesMaster = new SalesMasterSP();
                            bool blPOS = BllSalesInvoice.DayBookSalesInvoiceOrPOS(decMasterId, decVouchertypeId);
                            frmSalesInvoice frmSalesInvoice = new frmSalesInvoice();
                            frmPOS frmPOS = new frmPOS();
                            if (blPOS == true)
                            {
                                frmPOS = Application.OpenForms["frmPOS"] as frmPOS;
                                if (frmPOS == null)
                                {
                                    frmPOS = new frmPOS();
                                    frmPOS.MdiParent = formMDI.MDIObj;
                                    frmPOS.callFromAgeing(this, decMasterId);
                                    this.Enabled = false;
                                }
                            }
                            else
                            {
                                frmSalesInvoice = Application.OpenForms["frmSalesInvoice"] as frmSalesInvoice;
                                if (frmSalesInvoice == null)
                                {
                                    frmSalesInvoice = new frmSalesInvoice();
                                    frmSalesInvoice.MdiParent = formMDI.MDIObj;
                                    frmSalesInvoice.callFromAgeing(this, decMasterId);
                                    this.Enabled = false;
                                }
                            }
                        }
                        else if (strVoucherType == "Purchase Invoice")
                        {
                            PurchaseInvoiceBll BllPurchaseInvoice = new PurchaseInvoiceBll();
                            decMasterId = BllPurchaseInvoice.PurchaseMasterIdViewByvoucherNoAndVoucherType(decVouchertypeId, strVoucherNo);
                            frmPurchaseInvoice objpurchase = new frmPurchaseInvoice();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                        else if (strVoucherType == "Credit Note")
                        {
                            CreditNoteBll BllCreditNoteMaster = new CreditNoteBll();
                            decMasterId = BllCreditNoteMaster.CreditNoteMasterIdView(decVouchertypeId, strVoucherNo);
                            frmCreditNote objpurchase = new frmCreditNote();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                        else if (strVoucherType == "Debit Note")
                        {
                            //DebitNoteMasterSP spDebitNote = new DebitNoteMasterSP();
                            DebitNoteBll bllDebitNote = new DebitNoteBll();
                            decMasterId = bllDebitNote.DebitNoteMasterIdView(decVouchertypeId, strVoucherNo);
                            frmDebitNote objpurchase = new frmDebitNote();
                            objpurchase.WindowState = FormWindowState.Normal;
                            objpurchase.MdiParent = formMDI.MDIObj;
                            objpurchase.callFromAgeing(this, decMasterId);
                            this.Enabled = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("AR17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Edit function
        /// </summary>
        /// <param name="decMasterId"></param>
        public void Edit(decimal decMasterId)
        {
            try
            {
                int inRowCount = dgvReceiptVoucher.RowCount;
                int inTableRowCount = dtblPartyBalance.Rows.Count;
                int inB = 0;
                ReceiptMasterInfo InfoReceiptMaster = new ReceiptMasterInfo();
                ReceiptDetailsInfo InfoReceiptDetails = new ReceiptDetailsInfo();
                RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();

                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                LedgerPostingInfo InfoLegerPosting = new LedgerPostingInfo();
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                BankReconciliationBll BllBankReconciliation = new BankReconciliationBll();
                InfoReceiptMaster.Date = dtpDate.Value;
                InfoReceiptMaster.ReceiptMasterId = decMasterId;
                InfoReceiptMaster.Extra1 = string.Empty;
                InfoReceiptMaster.Extra2 = string.Empty;
                InfoReceiptMaster.ExtraDate = DateTime.Now;
                InfoReceiptMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                InfoReceiptMaster.LedgerId = Convert.ToDecimal(cmbCashOrBank.SelectedValue.ToString());
                InfoReceiptMaster.Narration = txtNarration.Text.Trim();
                decimal decTotalAmount = TotalAmountCalculation();
                InfoReceiptMaster.TotalAmount = decTotalAmount;
                InfoReceiptMaster.UserId = PublicVariables._decCurrentUserId;
                if (!isAutomatic)
                {
                    InfoReceiptMaster.VoucherNo = txtVoucherNo.Text.Trim();
                    InfoReceiptMaster.InvoiceNo = txtVoucherNo.Text.Trim();
                    InfoReceiptMaster.SuffixPrefixId = 0;
                }
                else
                {
                    InfoReceiptMaster.VoucherNo = strVoucherNo;
                    InfoReceiptMaster.InvoiceNo = strInvoiceNo;
                    InfoReceiptMaster.SuffixPrefixId = decDailySuffixPrefixId;
                }
                InfoReceiptMaster.VoucherTypeId = decReceiptVoucherTypeId;
                decimal decEffectRow = bllRecieptVoucher.ReceiptMasterEdit(InfoReceiptMaster);
                if (decEffectRow != 0)
                {
                    MasterLedgerPostingEdit();
                }
                foreach (object obj in arrlstOfRemove)
                {
                    string str = Convert.ToString(obj);
                    bllRecieptVoucher.ReceiptDetailsDelete(Convert.ToDecimal(str));
                    BllLedgerPosting.LedgerPostDeleteByDetailsId(Convert.ToDecimal(str), strVoucherNo, decReceiptVoucherTypeId);
                }
                decimal decReceiptDetailsId1 = 0;
                BllLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decReceiptVoucherTypeId, 12);
                for (int inI = 0; inI < inRowCount - 1; inI++)
                {
                    InfoReceiptDetails.Amount = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                    InfoReceiptDetails.ExchangeRateId = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                    InfoReceiptDetails.Extra1 = string.Empty;
                    InfoReceiptDetails.Extra2 = string.Empty;
                    InfoReceiptDetails.ReceiptMasterId = InfoReceiptMaster.ReceiptMasterId;
                    if (dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                    {
                        InfoReceiptDetails.LedgerId = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                    }
                    if (dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                    {
                        InfoReceiptDetails.ChequeNo = dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();
                        if (dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                        {
                            InfoReceiptDetails.ChequeDate = Convert.ToDateTime(dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value);
                        }
                        else
                        {
                            InfoReceiptDetails.ChequeDate = DateTime.Now;
                        }
                    }
                    else
                    {
                        InfoReceiptDetails.ChequeNo = string.Empty;
                        InfoReceiptDetails.ChequeDate = DateTime.Now;
                    }
                    if (dgvReceiptVoucher.Rows[inI].Cells["dgvtxtReceiptDetailsId"].Value == null || dgvReceiptVoucher.Rows[inI].Cells["dgvtxtReceiptDetailsId"].Value.ToString() == string.Empty)//if new rows are added
                    {
                        if (dgvReceiptVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")
                        {
                            decimal decReceiptDetailsId = bllRecieptVoucher .ReceiptDetailsAdd(InfoReceiptDetails);
                            if (decReceiptDetailsId != 0)
                            {
                                for (int inJ = 0; inJ < inTableRowCount; inJ++)
                                {
                                    if (dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                    {
                                        PartyBalanceAddOrEdit(inJ);
                                    }
                                }
                                inB++;
                                DetailsLedgerPosting(inI, decReceiptDetailsId);
                            }
                        }
                    }
                    else
                    {
                        if (dgvReceiptVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")
                        {
                            InfoReceiptDetails.ReceiptDetailsId = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvtxtreceiptDetailsId"].Value.ToString());
                            decimal decReceiptDetailsId = bllRecieptVoucher.ReceiptDetailsEdit(InfoReceiptDetails);
                            if (decReceiptDetailsId != 0)
                            {
                                for (int inJ = 0; inJ < inTableRowCount; inJ++)
                                {
                                    if (dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                    {
                                        PartyBalanceAddOrEdit(inJ);
                                    }
                                }
                                inB++;
                                decReceiptDetailsId = InfoReceiptDetails.ReceiptDetailsId;
                                decimal decLedgerPostId = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value.ToString());
                                DetailsLedgerPostingEdit(inI, decLedgerPostId, decReceiptDetailsId1);
                            }
                        }
                        else
                        {
                            decimal decDetailsId = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvtxtreceiptDetailsId"].Value.ToString());
                            bllRecieptVoucher.ReceiptDetailsDelete(decDetailsId);
                            BllLedgerPosting.LedgerPostDeleteByDetailsId(decDetailsId, strVoucherNo, decReceiptVoucherTypeId);
                            for (int inJ = 0; inJ < dtblPartyBalance.Rows.Count; inJ++)
                            {
                                if (dtblPartyBalance.Rows.Count == inJ)
                                {
                                    break;
                                }
                                if (dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                                {
                                    if (dtblPartyBalance.Rows[inJ]["LedgerId"].ToString() == dgvReceiptVoucher.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(InfoReceiptMaster.ReceiptMasterId);
                    }
                    else
                    {
                        Print(InfoReceiptMaster.ReceiptMasterId);
                    }
                }
                if (frmReceiptRegisterObj != null)
                {
                    this.Close();
                    frmReceiptRegisterObj.CallFromReceiptVoucher(this);
                }
                if (frmReceiptReportObj != null)
                {
                    this.Close();
                    frmReceiptReportObj.CallFromReceiptVoucher(this);
                }
                if (frmDayBookObj != null)
                {
                    this.Close();
                }
                if (frmBillallocationObj != null)
                {
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("RV13:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// On double clicking the cell in grid, it loads the corresponding Voucher to update or delete the entries
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvBillAllocation_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1)
                {
                    decVoucherTypeId = Convert.ToDecimal(dgvBillAllocation.CurrentRow.Cells["voucherTypeId"].Value.ToString());

                    strTypeOfVoucher = dgvBillAllocation.CurrentRow.Cells["typeOfVoucher"].Value.ToString();
                    strVoucherNo = dgvBillAllocation.CurrentRow.Cells["voucherNo"].Value.ToString();
                    if (strTypeOfVoucher == "PDC Payable")
                    {
                        PDCPayableBll BllPDCPayable = new PDCPayableBll();
                        decimal decMasterId = BllPDCPayable.PdcPayableMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmPdcPayable frmpdcPayableObj = new frmPdcPayable();
                        frmpdcPayableObj = Application.OpenForms["frmPdcPayable"] as frmPdcPayable;

                        if (frmpdcPayableObj == null)
                        {
                            frmpdcPayableObj = new frmPdcPayable();
                            frmpdcPayableObj.MdiParent = formMDI.MDIObj;

                            frmpdcPayableObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "PDC Receivable")
                    {
                        PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
                        decimal decMasterId = BllPDCReciveble.PdcReceivableMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmPdcReceivable frmPdcReceivableObj = new frmPdcReceivable();
                        frmPdcReceivableObj = Application.OpenForms["frmPdcReceivable"] as frmPdcReceivable;
                        if (frmPdcReceivableObj == null)
                        {
                            frmPdcReceivableObj = new frmPdcReceivable();
                            frmPdcReceivableObj.MdiParent = formMDI.MDIObj;
                            frmPdcReceivableObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Payment Voucher")
                    {
                        PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
                        decimal decMasterId = BllPaymentVoucher.paymentMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmPaymentVoucher frmPaymentVoucherObj = new frmPaymentVoucher();
                        frmPaymentVoucherObj = Application.OpenForms["frmPaymentVoucher"] as frmPaymentVoucher;
                        if (frmPaymentVoucherObj == null)
                        {
                            frmPaymentVoucherObj = new frmPaymentVoucher();
                            frmPaymentVoucherObj.MdiParent = formMDI.MDIObj;

                            frmPaymentVoucherObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Receipt Voucher")
                    {

                        RecieptVoucherBll bllRecieptVoucherBll = new RecieptVoucherBll();
                        decimal decMasterId = bllRecieptVoucherBll.ReceiptMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmReceiptVoucher frmReceiptVoucherObj = new frmReceiptVoucher();
                        frmReceiptVoucherObj = Application.OpenForms["frmReceiptVoucher"] as frmReceiptVoucher;
                        if (frmReceiptVoucherObj == null)
                        {
                            frmReceiptVoucherObj = new frmReceiptVoucher();
                            frmReceiptVoucherObj.MdiParent = formMDI.MDIObj;

                            frmReceiptVoucherObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Journal Voucher")
                    {
                        JournalVoucherBll JournalVoucherbll = new JournalVoucherBll();
                        decimal decMasterId = JournalVoucherbll.JournalMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmJournalVoucher frmJournalVoucherObj = new frmJournalVoucher();
                        frmJournalVoucherObj = Application.OpenForms["frmJournalVoucher"] as frmJournalVoucher;
                        if (frmJournalVoucherObj == null)
                        {
                            frmJournalVoucherObj = new frmJournalVoucher();
                            frmJournalVoucherObj.MdiParent = formMDI.MDIObj;

                            frmJournalVoucherObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Credit Note")
                    {
                        CreditNoteBll BllCreditNoteMaster = new CreditNoteBll();
                        decimal decMasterId = BllCreditNoteMaster.CreditNoteMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmCreditNote frmCreditNoteObj = new frmCreditNote();
                        frmCreditNoteObj = Application.OpenForms["frmCreditNote"] as frmCreditNote;
                        if (frmCreditNoteObj == null)
                        {
                            frmCreditNoteObj = new frmCreditNote();
                            frmCreditNoteObj.MdiParent = formMDI.MDIObj;

                            frmCreditNoteObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                    if (strTypeOfVoucher == "Debit Note")
                    {
                        //DebitNoteMasterSP sp = new DebitNoteMasterSP();
                        DebitNoteBll bll = new DebitNoteBll();
                        decimal decMasterId = bll.DebitNoteMasterIdView(decVoucherTypeId, strVoucherNo);

                        frmDebitNote frmDebitNoteObj = new frmDebitNote();
                        frmDebitNoteObj = Application.OpenForms["frmDebitNote"] as frmDebitNote;
                        if (frmDebitNoteObj == null)
                        {
                            frmDebitNoteObj = new frmDebitNote();
                            frmDebitNoteObj.MdiParent = formMDI.MDIObj;

                            frmDebitNoteObj.CallFromBillAllocation(this, decMasterId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("BA:15" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Clear function
        /// </summary>
        public void Clear()
        {
            try
            {
                RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();
                TransactionsGeneralFillBll obj = new TransactionsGeneralFillBll();
                if (btnSave.Text == "Update")
                {
                    if (frmReceiptRegisterObj != null)
                    {
                        frmReceiptRegisterObj.Close();
                    }
                }
                if (isAutomatic == true)
                {
                    SalaryVoucherBll BllSalaryVoucher = new SalaryVoucherBll();
                 //   ReceiptMasterSP SpReceiptMaster = new ReceiptMasterSP();

                    if (strVoucherNo == string.Empty)
                    {
                        strVoucherNo = "0";
                    }
                    strVoucherNo = obj.VoucherNumberAutomaicGeneration(decReceiptVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
                    if (Convert.ToDecimal(strVoucherNo) != bllRecieptVoucher.ReceiptMasterGetMax(decReceiptVoucherTypeId) + 1)
                    {
                        strVoucherNo = bllRecieptVoucher.ReceiptMasterGetMax(decReceiptVoucherTypeId).ToString();
                        strVoucherNo = obj.VoucherNumberAutomaicGeneration(decReceiptVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
                        if (bllRecieptVoucher.ReceiptMasterGetMax(decReceiptVoucherTypeId) == 0)
                        {
                            strVoucherNo = "0";
                            strVoucherNo = obj.VoucherNumberAutomaicGeneration(decReceiptVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpDate.Value, tableName);
                        }
                    }
                    SuffixPrefixSettingsBll BllSuffixPrefixSettings = new SuffixPrefixSettingsBll();

                    SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
                    infoSuffixPrefix = BllSuffixPrefixSettings.GetSuffixPrefixDetails(decReceiptVoucherTypeId, dtpDate.Value);
                    strPrefix = infoSuffixPrefix.Prefix;
                    strSuffix = infoSuffixPrefix.Suffix;
                    strInvoiceNo = strPrefix + strVoucherNo + strSuffix;
                    txtVoucherNo.Text = strInvoiceNo;
                    txtVoucherNo.ReadOnly = true;
                }
                else
                {
                    txtVoucherNo.Text = string.Empty;
                    txtVoucherNo.ReadOnly = false;
                }
                dtpDate.MinDate = PublicVariables._dtFromDate;
                dtpDate.MaxDate = PublicVariables._dtToDate;
                dtpDate.Value = PublicVariables._dtCurrentDate;
                cmbCashOrBank.SelectedIndex = -1;
                txtNarration.Text = string.Empty;
                txtTotal.Text = string.Empty;
                dgvReceiptVoucher.ClearSelection();
                dgvReceiptVoucher.Rows.Clear();
                btnDelete.Enabled = false;
                btnSave.Text = "Save";
                cbxPrintafterSave.Checked = false;
                dtblPartyBalance.Clear();
                if (isAutomatic)
                {
                    txtDate.Select();
                }
                else
                {
                    txtVoucherNo.Focus();
                }
                SettingsBll BllSettings = new SettingsBll();
                if (BllSettings.SettingsStatusCheck("TickPrintAfterSave") == "Yes")
                {
                    cbxPrintafterSave.Checked = true;
                }
                else
                {
                    cbxPrintafterSave.Checked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("RV6:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Delete Function
        /// </summary>
        /// <param name="decMasterId"></param>
        public void Delete(decimal decMasterId)
        {
            try
            {
                RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();

                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                if (!BllPartyBalance.PartyBalanceCheckReference(decReceiptVoucherTypeId, strVoucherNo))
                {
                    bllRecieptVoucher.ReceiptVoucherDelete(decRecieptmasterId, decReceiptVoucherTypeId, strVoucherNo);
                    Messages.DeletedMessage();
                    if (frmReceiptRegisterObj != null)
                    {
                        this.Close();
                        frmReceiptRegisterObj.CallFromReceiptVoucher(this);
                    }
                    else if (frmReceiptReportObj != null)
                    {
                        this.Close();
                        frmReceiptReportObj.CallFromReceiptVoucher(this);
                    }
                    else if (frmLedgerDetailsObj != null)
                    {
                        this.Close();
                    }
                    else if (frmVoucherSearch != null)
                    {
                        this.Close();
                        frmVoucherSearch.GridFill();
                    }
                    if (frmDayBookObj != null)
                    {
                        this.Close();
                    }
                    if (frmBillallocationObj != null)
                    {
                        this.Close();
                    }
                }
                else
                {
                    Messages.InformationMessage("Reference exist. Cannot delete");
                    txtDate.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("RV5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Save function
        /// </summary>
        public void Save()
        {
            try
            {
                int inGridRowCount = dgvReceiptVoucher.RowCount;
                int inTableRowCount = dtblPartyBalance.Rows.Count;
                int inB = 0;
                ReceiptMasterInfo InfoReceiptMaster = new ReceiptMasterInfo();
                RecieptVoucherBll bllRecieptVoucher=new RecieptVoucherBll();
               // ReceiptMasterSP SpReceiptMaster = new ReceiptMasterSP();
                ReceiptDetailsInfo InfoReceiptDetails = new ReceiptDetailsInfo();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                PartyBalanceInfo InfopartyBalance = new PartyBalanceInfo();
                InfoReceiptMaster.Date = dtpDate.Value;
                InfoReceiptMaster.Extra1 = string.Empty;
                InfoReceiptMaster.Extra2 = string.Empty;
                InfoReceiptMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                InfoReceiptMaster.LedgerId = Convert.ToDecimal(cmbCashOrBank.SelectedValue.ToString());
                InfoReceiptMaster.Narration = txtNarration.Text;
                decimal decTotalAmount = TotalAmountCalculation();
                InfoReceiptMaster.TotalAmount = decTotalAmount;
                InfoReceiptMaster.UserId = PublicVariables._decCurrentUserId;
                if (!isAutomatic)
                {
                    InfoReceiptMaster.VoucherNo = txtVoucherNo.Text.Trim();
                    InfoReceiptMaster.InvoiceNo = txtVoucherNo.Text.Trim();
                    InfoReceiptMaster.SuffixPrefixId = 0;
                }
                else
                {
                    InfoReceiptMaster.VoucherNo = strVoucherNo;
                    InfoReceiptMaster.InvoiceNo = strInvoiceNo;
                    InfoReceiptMaster.SuffixPrefixId = decDailySuffixPrefixId;
                }
                InfoReceiptMaster.VoucherTypeId = decReceiptVoucherTypeId;
                decimal decReceiptMasterId = bllRecieptVoucher.ReceiptMasterAdd(InfoReceiptMaster);
                if (decReceiptMasterId != 0)
                {
                    MasterLedgerPosting();
                }
                for (int inI = 0; inI < inGridRowCount - 1; inI++)
                {
                    if (dgvReceiptVoucher.Rows[inI].HeaderCell.Value.ToString() != "X")
                    {
                        InfoReceiptDetails.Amount = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                        InfoReceiptDetails.ExchangeRateId = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value.ToString());
                        InfoReceiptDetails.Extra1 = string.Empty;
                        InfoReceiptDetails.Extra2 = string.Empty;
                        InfoReceiptDetails.LedgerId = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                        InfoReceiptDetails.ReceiptMasterId = decReceiptMasterId;
                        if (dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value != null && dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                        {
                            InfoReceiptDetails.LedgerId = Convert.ToDecimal(dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString());
                        }
                        if (dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
                        {
                            InfoReceiptDetails.ChequeNo = dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString();
                            if (dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value != null && dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value.ToString() != string.Empty)
                            {
                                InfoReceiptDetails.ChequeDate = Convert.ToDateTime(dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value);
                            }
                            else
                            {
                                InfoReceiptDetails.ChequeDate = DateTime.Now;
                            }
                        }
                        else
                        {
                            InfoReceiptDetails.ChequeNo = string.Empty;
                            InfoReceiptDetails.ChequeDate = DateTime.Now;
                        }
                        decimal decReceiptDetailsId = bllRecieptVoucher.ReceiptDetailsAdd(InfoReceiptDetails);
                        if (decReceiptDetailsId != 0)
                        {
                            for (int inJ = 0; inJ < inTableRowCount; inJ++)
                            {
                                if (dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value.ToString() == dtblPartyBalance.Rows[inJ]["LedgerId"].ToString())
                                {
                                    PartyBalanceAddOrEdit(inJ);
                                }
                            }
                            inB++;
                            DetailsLedgerPosting(inI, decReceiptDetailsId);
                        }
                    }
                }

                Messages.SavedMessage();
                if (cbxPrintafterSave.Checked)
                {
                    if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decReceiptMasterId);
                    }
                    else
                    {
                        Print(decReceiptMasterId);
                    }
                }
                Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("RV12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Save or edit function and checking the invalid entries
        /// </summary>
        public void SaveOrEdit()
        {
            try
            {
                RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();

                //ReceiptMasterSP SpReceiptMaster = new ReceiptMasterSP();
                int inIfGridColumnMissing = 0;
                int inRowCount = dgvReceiptVoucher.RowCount;
                ArrayList arrLst = new ArrayList();
                string output = string.Empty;
                if (txtVoucherNo.Text == string.Empty)
                {
                    Messages.InformationMessage("Enter voucher number.");
                    txtVoucherNo.Focus();
                    inIfGridColumnMissing = 1;
                }
                else if (cmbCashOrBank.SelectedIndex == -1)
                {
                    Messages.InformationMessage("Select any bank or cash.");
                    cmbCashOrBank.Focus();
                    inIfGridColumnMissing = 1;
                }
                else if (inRowCount == 1)
                {
                    Messages.InformationMessage("Can't save without atleat one complete details");
                    dgvReceiptVoucher.Focus();
                    inIfGridColumnMissing = 1;
                }
                else if (Convert.ToDecimal(txtTotal.Text) == 0)
                {
                    Messages.InformationMessage("Can't save total amount as Zero");
                    dgvReceiptVoucher.Focus();
                }
                else
                {
                    int inJ = 0;
                    for (int inI = 0; inI < inRowCount - 1; inI++)
                    {
                        if (dgvReceiptVoucher.Rows[inI].HeaderCell.Value.ToString() == "X")
                        {
                            arrLst.Add(Convert.ToString(inI + 1));
                            inIfGridColumnMissing = 1;
                            inJ++;
                        }
                    }
                    if (inJ != 0)
                    {
                        if (inJ == inRowCount - 1)
                        {
                            Messages.InformationMessage("Can't save without atleat one complete details");
                            inIfGridColumnMissing = 1;
                        }
                        else
                        {
                            foreach (object obj in arrLst)
                            {
                                string str = Convert.ToString(obj);
                                if (str != null)
                                {
                                    output += str + ",";
                                }
                                else
                                {
                                    break;
                                }
                            }
                            bool isOk = Messages.UpdateMessageCustom("Row No " + output + " not completed.Do you want to continue?");
                            if (isOk == true)
                            {
                                inIfGridColumnMissing = 0;
                            }
                            else
                            {
                                inIfGridColumnMissing = 1;
                            }
                        }
                    }
                    if (inIfGridColumnMissing == 0)
                    {
                        if (btnSave.Text == "Save")
                        {
                            if (!isAutomatic)
                            {
                                if (bllRecieptVoucher.ReceiptVoucherCheckExistence(txtVoucherNo.Text.Trim(), decReceiptVoucherTypeId, 0))
                                {
                                    Messages.InformationMessage("Voucher number already exist");
                                }
                                else
                                {
                                    if (PublicVariables.isMessageAdd)
                                    {
                                        if (Messages.SaveMessage())
                                        {
                                            Save();
                                        }
                                    }
                                    else
                                    {
                                        Save();
                                    }
                                }
                            }
                            else
                            {
                                if (PublicVariables.isMessageAdd)
                                {
                                    if (Messages.SaveMessage())
                                    {
                                        Save();
                                    }
                                }
                                else
                                {
                                    Save();
                                }
                            }
                        }
                        else if (btnSave.Text == "Update")
                        {
                            if (!isAutomatic)
                            {
                                if (bllRecieptVoucher.ReceiptVoucherCheckExistence(txtVoucherNo.Text.Trim(), decReceiptVoucherTypeId, decRecieptmasterId))
                                {
                                    Messages.InformationMessage("Voucher number already exist");
                                    txtVoucherNo.Focus();
                                }
                                else
                                {
                                    if (PublicVariables.isMessageEdit)
                                    {
                                        if (Messages.UpdateMessage())
                                        {
                                            Edit(decRecieptmasterId);
                                        }
                                    }
                                    else
                                    {
                                        Edit(decRecieptmasterId);
                                    }
                                }
                            }
                            else
                            {
                                if (PublicVariables.isMessageEdit)
                                {
                                    if (Messages.UpdateMessage())
                                    {
                                        Edit(decRecieptmasterId);
                                    }
                                }
                                else
                                {
                                    Edit(decRecieptmasterId);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("RV27:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Print function 
        /// </summary>
        /// <param name="decReceiptMasterId"></param>
        public void Print(decimal decReceiptMasterId)
        {
            try
            {
                RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();

                DataSet dsReceiptVoucher = bllRecieptVoucher.ReceiptVoucherPrinting(decReceiptMasterId);// PublicVariables._decCurrentCompanyId);
                frmReport frmReport = new frmReport();
                frmReport.MdiParent = formMDI.MDIObj;
                frmReport.ReceiptVoucherPrinting(dsReceiptVoucher);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Rv14:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Fill function for updation
        /// </summary>
        public void FillFunction()
        {
            try
            {
                isValueChange = false;
                ReceiptMasterInfo InfoReceiptMaster = new ReceiptMasterInfo();

                ReceiptDetailsInfo InfoReceiptDetails = new ReceiptDetailsInfo();
                RecieptVoucherBll bllRecieptVoucherBll = new RecieptVoucherBll();

                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                VoucherTypeBll BllVoucherType = new VoucherTypeBll();
                AccountGroupBll BllAccountGroup = new AccountGroupBll();
                AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                InfoReceiptMaster = bllRecieptVoucherBll.ReceiptMasterViewByMasterId(decRecieptmasterId);
                isAutomatic = BllVoucherType.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;
                List<DataTable> listobj = new List<DataTable>();
                listobj = bllRecieptVoucherBll.ReceiptDetailsViewByMasterId(decRecieptmasterId);
                for (int inI = 0; inI < listobj[0].Rows.Count; inI++)
                {
                    dgvReceiptVoucher.Rows.Add();
                    dgvReceiptVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value = Convert.ToDecimal(listobj[0].Rows[inI]["ledgerId"].ToString());
                    dgvReceiptVoucher.Rows[inI].Cells["dgvtxtreceiptMasterId"].Value = listobj[0].Rows[inI]["receiptMasterId"].ToString();
                    dgvReceiptVoucher.Rows[inI].Cells["dgvtxtreceiptDetailsId"].Value = listobj[0].Rows[inI]["receiptDetailsId"].ToString();
                    dgvReceiptVoucher.Rows[inI].Cells["dgvtxtAmount"].Value = listobj[0].Rows[inI]["amount"].ToString();
                    dgvReceiptVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(listobj[0].Rows[inI]["exchangeRateId"].ToString());
                    decimal decDetailsId1 = Convert.ToDecimal(listobj[0].Rows[inI]["receiptDetailsId"].ToString());
                    decimal decLedgerPostingId = BllLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, decReceiptVoucherTypeId);
                    dgvReceiptVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString();
                    decimal decLedgerId = Convert.ToDecimal(listobj[0].Rows[inI]["ledgerId"].ToString());
                    bool IsBankAccount = BllAccountGroup.AccountGroupwithLedgerId(decLedgerId);
                    decimal decI = Convert.ToDecimal(bllAccountLedger.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 (listobj[0].Rows[inI]["chequeNo"].ToString() != string.Empty)
                    {
                        dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value = listobj[0].Rows[inI]["chequeNo"].ToString();
                        dgvReceiptVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value = Convert.ToDateTime(listobj[0].Rows[inI]["chequeDate"].ToString()).ToString("dd-MMM-yyyy");
                    }
                    dgvReceiptVoucher.Rows[inI].HeaderCell.Value = string.Empty;
                }
                List<DataTable> listObj = new List<DataTable>();
                listObj = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decReceiptVoucherTypeId, strVoucherNo, InfoReceiptMaster.Date);
                dtblPartyBalance = listObj[0];
                isValueChange = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("RV34:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to print the details
        /// </summary>
        public void Print()
        {
            try
            {
                RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();

                DataSet dsReceiptReport = bllRecieptVoucher.ReceiptReportPrinting(Convert.ToDateTime(dtpFromDate.Value.ToString()), Convert.ToDateTime(dtpToDate.Value.ToString()), Convert.ToDecimal(cmbLedger.SelectedValue), Convert.ToDecimal(cmbVoucherType.SelectedValue), Convert.ToDecimal(cmbCashOrBank.SelectedValue), 1);
                frmReport frmReport = new frmReport();
                frmReport.MdiParent = formMDI.MDIObj;
                frmReport.ReceiptReportPrinting(dsReceiptReport);
            }
            catch (Exception ex)
            {
                MessageBox.Show("RRP1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to fill the grid based on the Search condition
        /// </summary>
        public void GridFill()
        {
            try
            {
                RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();

                List<DataTable> list= new List<DataTable>();
                if (cmbLedger.Items.Count != 0 && cmbVoucherType.Items.Count != 0 && cmbCashOrBank.Items.Count != 0)
                {
                    if ((cmbLedger.SelectedValue.ToString() != "System.Data.DataRowView") && (cmbVoucherType.SelectedValue.ToString() != "System.Data.DataRowView") && (cmbCashOrBank.SelectedValue.ToString() != "System.Data.DataRowView"))
                    {
                        if (txtFromDate.Text.Trim() != string.Empty && txtToDate.Text.Trim() != string.Empty)
                        {
                            list = bllRecieptVoucher.ReceiptReportSearch(Convert.ToDateTime(dtpFromDate.Value.ToString()), Convert.ToDateTime(dtpToDate.Value.ToString()), Convert.ToDecimal(cmbLedger.SelectedValue), Convert.ToDecimal(cmbVoucherType.SelectedValue), Convert.ToDecimal(cmbCashOrBank.SelectedValue));
                            dgvReceiptReport.DataSource = list[0];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("RRP5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to fill datagridview
 /// </summary>
 public void gridfill()
 {
     try
     {
         RecieptVoucherBll bllRecieptVoucher = new RecieptVoucherBll();
         List<DataTable> listObj = new List<DataTable>();
         if (cmbAccountLedger.SelectedValue.ToString() != "System.Data.DataRowView")
         {
             if (txtFromDate.Text.Trim() != string.Empty && txtToDate.Text.Trim() != string.Empty)
             {
                 listObj = bllRecieptVoucher.ReceiptMasterSearch(Convert.ToDateTime(dtpFromDate.Value.ToString()), Convert.ToDateTime(dtpToDate.Value.ToString()), Convert.ToDecimal(cmbAccountLedger.SelectedValue), txtVoucherNo.Text);
                 dgvReceiptRegister.DataSource = listObj[0];
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("RR4:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }