/// <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>
 /// Fill function to updation
 /// </summary>
 public void FillFunction()
 {
     try
     {
         PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
         PDCReceivableMasterInfo infopdcrecivable = new PDCReceivableMasterInfo();
         infopdcrecivable = BllPdcRecieveble.PDCReceivableMasterView(decPDCReceivableEditId);
         txtVoucherNo.ReadOnly = false;
         strVoucherNo = infopdcrecivable.VoucherNo;
         strInvoiceNo = infopdcrecivable.InvoiceNo;
         txtVoucherNo.Text = strInvoiceNo;
         decSufixprefixPdcReceivableID = infopdcrecivable.SuffixPrefixId;
         decPDCReceivableVoucherTypeId = infopdcrecivable.VoucherTypeId;
         VoucherTypeBll BllVoucherType = new VoucherTypeBll();
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(decPDCReceivableVoucherTypeId);
         if (isAutomatic)
         {
             txtVoucherNo.ReadOnly = true;
         }
         else
         {
             txtVoucherNo.ReadOnly = false;
             lblVoucherNoManualValidator.Visible = false;
         }
         if (infopdcrecivable.PdcReceivableMasterId != 0)
         {
             txtVoucherNo.Text = infopdcrecivable.InvoiceNo;
             dtpVoucherDate.Value = infopdcrecivable.Date;
             txtVoucherDate.Text = dtpVoucherDate.Value.ToString("dd-MMM-yyyy");
             txtNarration.Text = infopdcrecivable.Narration;
             cmbAccountLedger.SelectedValue = infopdcrecivable.LedgerId;
             txtAmount.Text = infopdcrecivable.Amount.ToString();
             if (infopdcrecivable.BankId != 0)
                 cmbBank.SelectedValue = infopdcrecivable.BankId;
             else
                 cmbBank.SelectedValue = string.Empty;
             txtcheckNo.Text = infopdcrecivable.ChequeNo;
             txtCheckDate.Text = infopdcrecivable.ChequeDate.ToString("dd-MMM-yyyy");
             btnSave.Text = "Update";
             PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
             List<DataTable> listObj = new List<DataTable>();
             listObj = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decPDCReceivableVoucherTypeId, strVoucherNo, infopdcrecivable.Date);
             dtblPartyBalance = listObj[0];
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PP24:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Ledger Posting edit function
        /// </summary>
        /// <param name="decpdcMasterId"></param>
        public void LedgerPostingEdit(decimal decpdcMasterId)
        {
            PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
            List<DataTable> listObjLedgerPostingId = new List<DataTable>();
            LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
            LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
            ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
            decimal decOldExchange = 0;
            decimal decNewExchangeRate = 0;
            decimal decNewExchangeRateId = 0;
            decimal decSelectedCurrencyRate = 0;
            decimal decAmount = 0;
            decimal decConvertRate = 0;
            string strReferenceType = string.Empty;
            decimal decOldExchangeId = 0;
            try
            {

                listObjLedgerPostingId = BllPdcRecieveble.LedgerPostingIdByPDCReceivableId(decpdcMasterId);
                decimal decledgerpostingId1 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[0]["ledgerPostingId"].ToString());
                decimal decLedgerPostingId2 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[1]["ledgerPostingId"].ToString());
                if (!btnAgainRef.Enabled)
                {
                    infoLedgerPosting.LedgerPostingId = decledgerpostingId1;
                    infoLedgerPosting.VoucherTypeId = decPDCReceivableVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim();
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Debit = 0;
                    infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text);
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtCheckDate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting);

                }
                else
                {
                    infoLedgerPosting.LedgerPostingId = decledgerpostingId1;
                    infoLedgerPosting.VoucherTypeId = decPDCReceivableVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim();
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Debit = 0;
                    foreach (DataRow dr in dtblPartyBalance.Rows)
                    {
                        if (infoLedgerPosting.LedgerId == Convert.ToDecimal(dr["LedgerId"].ToString()))
                        {
                            decOldExchange = Convert.ToDecimal(dr["OldExchangeRate"].ToString());
                            decNewExchangeRateId = Convert.ToDecimal(dr["CurrencyId"].ToString());
                            decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(decOldExchange);
                            decAmount = Convert.ToDecimal(dr["Amount"].ToString());
                            decConvertRate = decConvertRate + (decAmount * decSelectedCurrencyRate);

                        }
                    }
                    infoLedgerPosting.Credit = decConvertRate;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtCheckDate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting);

                    infoLedgerPosting.LedgerId = 12;
                    foreach (DataRow dr in dtblPartyBalance.Rows)
                    {
                        if (Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString()) == Convert.ToDecimal(dr["LedgerId"].ToString()))
                        {
                            if (dr["ReferenceType"].ToString() == "Against")
                            {
                                decNewExchangeRateId = Convert.ToDecimal(dr["CurrencyId"].ToString());
                                decNewExchangeRate = BllExchangeRate.GetExchangeRateByExchangeRateId(decNewExchangeRateId);
                                decOldExchangeId = Convert.ToDecimal(dr["OldExchangeRate"].ToString());
                                decOldExchange = BllExchangeRate.GetExchangeRateByExchangeRateId(decOldExchangeId);
                                decAmount = Convert.ToDecimal(dr["Amount"].ToString());
                                decimal decForexAmount = (decAmount * decNewExchangeRate) - (decAmount * decOldExchange);
                                if (decForexAmount >= 0)
                                {

                                    infoLedgerPosting.Credit = decForexAmount;
                                    infoLedgerPosting.Debit = 0;
                                }
                                else
                                {
                                    infoLedgerPosting.Debit = -1 * decForexAmount;
                                    infoLedgerPosting.Credit = 0;
                                }
                                BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                            }
                        }

                    }
                }

                infoLedgerPosting.LedgerPostingId = decLedgerPostingId2;
                infoLedgerPosting.VoucherNo = strVoucherNo;
                infoLedgerPosting.InvoiceNo = txtVoucherNo.Text.Trim();
                infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                infoLedgerPosting.LedgerId = 7;
                infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                infoLedgerPosting.Debit = Convert.ToDecimal(txtAmount.Text);
                infoLedgerPosting.Credit = 0;
                infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtCheckDate.Text);
                infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                infoLedgerPosting.Extra1 = string.Empty;
                infoLedgerPosting.Extra2 = string.Empty;
                BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting);
            }
            catch (Exception ex)
            {
                MessageBox.Show("PR10:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Delete button click, Checking the user privilage and checking the references
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
         if (CheckUserPrivilege.PrivilegeCheck(PublicVariables._decCurrentUserId, this.Name, btnDelete.Text))
         {
             if (PublicVariables.isMessageDelete)
             {
                 if (Messages.DeleteMessage())
                 {
                     if (isInEditMode && BllPdcRecieveble.PDCReceivableReferenceCheck(decPDCReceivableEditId))
                     {
                         Messages.ReferenceExistsMessage();
                     }
                     else
                     {
                         DeleteFunction(decPDCReceivableEditId);
                         txtVoucherNo.Focus();
                     }
                 }
             }
             else
             {
                 if (isInEditMode && BllPdcRecieveble.PDCReceivableReferenceCheck(decPDCReceivableEditId))
                 {
                     Messages.ReferenceExistsMessage();
                 }
                 DeleteFunction(decPDCReceivableEditId);
                 txtVoucherNo.Focus();
             }
         }
         else
         {
             Messages.NoPrivillageMessage();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR37:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Delete Function, Checking the References and Check other forms are opend or not
 /// </summary>
 /// <param name="decPDCReceivableMasterId"></param>
 public void DeleteFunction(decimal decPDCReceivableMasterId)
 {
     try
     {
         PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         if (!BllPartyBalance.PartyBalanceCheckReference(decPDCReceivableVoucherTypeId, strVoucherNo))
         {
             BllPdcRecieveble.PDCReceivableDeleteMaster(decPDCReceivableMasterId, decPDCReceivableVoucherTypeId, strVoucherNo);
             Messages.DeletedMessage();
         }
         else
         {
             Messages.InformationMessage("Reference exist. Cannot delete");
             txtVoucherDate.Focus();
         }
         if (PDCReceivableRegisterObj != null)
         {
             this.Close();
             PDCReceivableRegisterObj.Show();
         }
         else if (PDCReceivableReportObj != null)
         {
             this.Close();
             PDCReceivableReportObj.Show();
         }
         else if (frmLedgerDetailsObj != null)
         {
             this.Close();
             frmLedgerDetailsObj.Show();
         }
         else if (objVoucherSearch != null)
         {
             this.Close();
             objVoucherSearch.GridFill();
         }
         else
         {
             ClearFunction();
         }
         if (frmDayBookObj != null)
         {
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR20:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Save or edit function, Checking all invalid entrys to save or edit
 /// </summary>
 public void SaveOrEditFunction()
 {
     try
     {
         txtVoucherDate.Text = txtVoucherDate.Text.Trim();
         cmbAccountLedger.Text = cmbAccountLedger.Text.Trim();
         txtAmount.Text = txtAmount.Text.Trim();
         cmbBank.Text = cmbBank.Text.Trim();
         txtCheckDate.Text = txtCheckDate.Text.Trim();
         txtcheckNo.Text = txtcheckNo.Text.Trim();
         txtNarration.Text = txtNarration.Text.Trim();
         bool isOk = true;
         bool isAmountOk = false;
         try
         {
             if (Convert.ToDecimal(txtAmount.Text) > 0)
                 isAmountOk = true;
         }
         catch
         {
             txtAmount.Text = string.Empty;
         }
         if (isOk)
         {
             if (txtVoucherNo.Text == string.Empty)
             {
                 Messages.InformationMessage("Enter voucher no");
                 txtVoucherNo.Focus();
             }
             else if (txtVoucherDate.Text == string.Empty)
             {
                 Messages.InformationMessage("Select date");
                 txtVoucherDate.Focus();
             }
             else if (cmbAccountLedger.SelectedValue == null)
             {
                 Messages.InformationMessage("Select account ledger");
                 cmbAccountLedger.Focus();
             }
             else if (!isAmountOk)
             {
                 Messages.InformationMessage("Select amount");
                 txtAmount.Focus();
             }
             else if (cmbBank.SelectedValue == null)
             {
                 Messages.InformationMessage("Select bank ");
                 cmbBank.Focus();
             }
             else if (txtcheckNo.Text == string.Empty)
             {
                 Messages.InformationMessage("Enter cheque no");
                 txtcheckNo.Focus();
             }
             else if (txtCheckDate.Text == string.Empty)
             {
                 Messages.InformationMessage("Select cheque date");
                 txtCheckDate.Focus();
             }
             else
             {
                 if (PublicVariables.isMessageAdd)
                 {
                     isOk = false;
                     PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
                     if (!isInEditMode)
                     {
                         if (Messages.SaveMessage())
                             if (!BllPdcRecieveble.PDCReceivableCheckExistence(txtVoucherNo.Text.Trim(), decPDCReceivableVoucherTypeId, 0))
                             {
                                 SaveFunction();
                             }
                             else
                             {
                                 Messages.InformationMessage("Voucher number already exist");
                             }
                     }
                     else
                     {
                         if (Messages.UpdateMessage())
                             if (isInEditMode && BllPdcRecieveble.PDCReceivableVoucherCheckRreferenceUpdating(decPDCReceivableEditId, decPDCReceivableVoucherTypeId))
                             {
                                 MessageBox.Show("Can't update,reference exist", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                             else
                             {
                                 SaveFunction();
                             }
                     }
                 }
                 if (isOk)
                 {
                     if (CheckUserPrivilege.PrivilegeCheck(PublicVariables._decCurrentUserId, this.Name, btnSave.Text))
                     {
                         PDCRecivebleBll BllPdcreceivable = new PDCRecivebleBll();
                         if (isInEditMode && BllPdcreceivable.PDCReceivableVoucherCheckRreferenceUpdating(decPDCReceivableEditId, decPDCReceivableVoucherTypeId))
                         {
                             MessageBox.Show("Can't update,reference exist", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         }
                         else
                         {
                             SaveFunction();
                         }
                     }
                     else
                     {
                         Messages.NoPrivillageMessage();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Voucher no generation function based on the settings
 /// </summary>
 public void VoucherNumberGeneration()
 {
     try
     {
         TransactionsGeneralFillBll obj = new TransactionsGeneralFillBll();
         PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
         if (strVoucherNo == string.Empty)
         {
             strVoucherNo = "0";
         }
         strVoucherNo = obj.VoucherNumberAutomaicGeneration(decPDCReceivableVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, strtableName);
         if (Convert.ToDecimal(strVoucherNo) != BllPdcRecieveble.PDCReceivableMaxUnderVoucherTypePlusOne(decPDCReceivableVoucherTypeId))
         {
             strVoucherNo = BllPdcRecieveble.PDCReceivableMaxUnderVoucherType(decPDCReceivableVoucherTypeId).ToString();
             strVoucherNo = obj.VoucherNumberAutomaicGeneration(decPDCReceivableVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, strtableName);
             if (BllPdcRecieveble.PDCReceivableMaxUnderVoucherType(decPDCReceivableVoucherTypeId).ToString() == "0")
             {
                 strVoucherNo = "0";
                 strVoucherNo = obj.VoucherNumberAutomaicGeneration(decPDCReceivableVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, strtableName);
             }
         }
         if (isAutomatic)
         {
             SuffixPrefixSettingsBll BllSuffixPrefixSettings = new SuffixPrefixSettingsBll();
             SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
             infoSuffixPrefix = BllSuffixPrefixSettings.GetSuffixPrefixDetails(decPDCReceivableVoucherTypeId, dtpVoucherDate.Value);
             strPrefix = infoSuffixPrefix.Prefix;
             strSuffix = infoSuffixPrefix.Suffix;
             decSufixprefixPdcReceivableID = infoSuffixPrefix.SuffixprefixId;
             strInvoiceNo = strPrefix + strVoucherNo + strSuffix;
             txtVoucherNo.Text = strInvoiceNo;
             txtVoucherNo.ReadOnly = true;
             txtVoucherNo.Enabled = false;
             lblVoucherNoManualValidator.Visible = false;
         }
         else
         {
             txtVoucherNo.ReadOnly = false;
             txtVoucherNo.Text = string.Empty;
             lblVoucherNoManualValidator.Visible = true;
             strInvoiceNo = txtVoucherNo.Text.Trim();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Print function
 /// </summary>
 /// <param name="decMasterId"></param>
 public void Print(decimal decMasterId)
 {
     try
     {
         DataSet dsPdcReceivable = new DataSet();
         PDCRecivebleBll BllPdcRecieveble = new PDCRecivebleBll();
         dsPdcReceivable = BllPdcRecieveble.PDCReceivableVoucherPrinting(decMasterId, 1);
         frmReport frmreport = new frmReport();
         frmreport.MdiParent = formMDI.MDIObj;
         frmreport.PDCreceivableVoucherPrinting(dsPdcReceivable);
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR21:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Save function
        /// </summary>
        public void SaveFunction()
        {
            try
            {
                DateValidation Objdatevalidation = new DateValidation();
                OtherDateValidationFunction ObjotherdateValidation = new OtherDateValidationFunction();
                Objdatevalidation.DateValidationFunction(txtVoucherDate);
                ObjotherdateValidation.DateValidationFunction(txtCheckDate, false);
                DataTable dtblMaster = new DataTable();
                SettingsBll BllSettings = new SettingsBll();
                PDCRecivebleBll BllPdcreceivable = new PDCRecivebleBll();
                PDCReceivableMasterInfo InfopdcRecivable = new PDCReceivableMasterInfo();
                PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                InfopdcRecivable.VoucherNo = strVoucherNo;
                InfopdcRecivable.InvoiceNo = txtVoucherNo.Text.Trim();
                InfopdcRecivable.Date = DateTime.Parse(txtVoucherDate.Text);
                InfopdcRecivable.LedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
                InfopdcRecivable.Amount = decimal.Parse(txtAmount.Text);
                InfopdcRecivable.Narration = txtNarration.Text;
                if (txtcheckNo.Text != string.Empty)
                    InfopdcRecivable.ChequeNo = txtcheckNo.Text;
                else
                    InfopdcRecivable.ChequeNo = string.Empty;
                if (txtCheckDate.Text != string.Empty)
                    InfopdcRecivable.ChequeDate = Convert.ToDateTime(txtCheckDate.Text);
                else
                    InfopdcRecivable.ChequeDate = DateTime.Now;
                InfopdcRecivable.UserId = PublicVariables._decCurrentUserId;
                InfopdcRecivable.VoucherTypeId = decPDCReceivableVoucherTypeId;
                if (cmbBank.SelectedValue != null && cmbBank.SelectedValue.ToString() != string.Empty)
                {
                    InfopdcRecivable.BankId = Convert.ToDecimal(cmbBank.SelectedValue.ToString());
                }
                else
                    InfopdcRecivable.BankId = 0;
                InfopdcRecivable.ExtraDate = DateTime.Now;
                InfopdcRecivable.Extra1 = string.Empty;
                InfopdcRecivable.Extra2 = string.Empty;
                if (!isInEditMode)
                {
                    decimal decIdentity = BllPdcreceivable.PDCReceivableMasterAdd(InfopdcRecivable);
                    LedgerPosting();
                    PartyBalanceAddOrEdit();
                    Messages.SavedMessage();
                    if (cbxPrint.Checked)
                    {
                        if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decIdentity);
                        }
                        else
                        {
                            Print(decIdentity);
                        }
                    }
                    ClearFunction();
                }
                else
                {

                    decimal decIdentity = decPDCReceivableEditId;
                    InfopdcRecivable.PdcReceivableMasterId = decPDCReceivableEditId;
                    BllPdcreceivable.PDCReceivableMasterEdit(InfopdcRecivable);

                    LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                    BllLedgerPosting.LedgerPostingDeleteByVoucherNoVoucherTypeIdAndLedgerId(strVoucherNo, decPDCReceivableVoucherTypeId, 12);
                    BllPartyBalance.PartyBalanceDeleteByVoucherTypeAndVoucherNo(decPDCReceivableVoucherTypeId, strVoucherNo);
                    PartyBalanceAddOrEdit();
                    LedgerPostingEdit(decPDCReceivableEditId);
                    Messages.UpdatedMessage();
                    if (cbxPrint.Checked)
                    {
                        if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                        {
                            PrintForDotMatrix(decIdentity);
                        }
                        else
                        {
                            Print(decIdentity);
                        }
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PR9:" + 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>
 /// Function to fill Datagridview
 /// </summary>
 public void GridSearchRegister()
 {
     try
     {
         if (txtDate.Text != string.Empty && txtToDate.Text != string.Empty)
         {
             if (Convert.ToDateTime(txtToDate.Text) < Convert.ToDateTime(txtDate.Text))
             {
                 MessageBox.Show("Todate should be greater than fromdate", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 SetDate();
             }
         }
         else if (txtDate.Text == string.Empty)
         {
             SetDate();
         }
         if (cmbAccountLedger.Text.Trim() == string.Empty)
         {
             cmbAccountLedger.Text = "ALL";
         }
         List<DataTable> ListObj = new List<DataTable>();
         PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
         ListObj = BllPDCReciveble.PDCReceivableRegisterSearch(Convert.ToDateTime(dtpDate.Value.ToString()), Convert.ToDateTime(dtpTodate.Value.ToString()), txtvoucherNo.Text.Trim(), cmbAccountLedger.Text.ToString());
         DgvPdCreceivable.DataSource = ListObj[0];
         if (cmbAccountLedger.Text == "ALL")
         {
             cmbAccountLedger.Text = string.Empty;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PRREG5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Ledger Posting Function, here saving the curresponding details into the ledger
        /// </summary>
        public void LedgerPostingAdd()
        {
            try
            {
                string strstatus = cmbStatus.Text.ToString();
                LedgerPostingInfo InfoPosting = new LedgerPostingInfo();
                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
                PDCClearanceBll BllPdcClearance = new PDCClearanceBll();
                PDCPayableMasterInfo infoPDCPayable = new PDCPayableMasterInfo();
                PDCPayableBll BllPDCPayable = new PDCPayableBll();
                PDCReceivableMasterInfo infoPDCReceivable = new PDCReceivableMasterInfo();
                PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
                strVoucherType = BllPdcClearance.TypeOfVoucherReturnUnderVoucherName(cmbvouchertype.Text.ToString());
                if (strVoucherType == "PDC Payable")
                {
                    infoPDCPayable = BllPDCPayable.PDCPayableMasterView(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = Convert.ToDateTime(txtVoucherDate.Text.ToString());
                    infoLedgerPosting.VoucherTypeId = decPDCclearanceVoucherTypeId;
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtcheckdate.Text.ToString());
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    if (strstatus == "Cleared")
                    {

                        infoLedgerPosting.LedgerId = infoPDCPayable.BankId;
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
                    }
                    else if (strstatus == "Bounced")
                    {
                        infoLedgerPosting.LedgerId = infoPDCPayable.LedgerId;
                        infoLedgerPosting.Debit = 0;
                        infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
                    }
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    infoLedgerPosting.VoucherTypeId = decPDCclearanceVoucherTypeId;
                    infoLedgerPosting.VoucherNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = Convert.ToDateTime(txtVoucherDate.Text.ToString());
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtcheckdate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.LedgerId = 6;
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtAmount.Text.ToString());
                    infoLedgerPosting.Credit = 0;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                }
                else if (strVoucherType == "PDC Receivable")
                {
                    infoPDCReceivable = BllPDCReciveble.PDCReceivableMasterView(Convert.ToDecimal(cmbInvoiceNo.SelectedValue.ToString()));
                    infoLedgerPosting.VoucherTypeId = decPDCclearanceVoucherTypeId;
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.LedgerId = 7;
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Debit = 0;
                    infoLedgerPosting.Credit = Convert.ToDecimal(txtAmount.Text.ToString());
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtcheckdate.Text.ToString());
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                    infoLedgerPosting.VoucherTypeId = decPDCclearanceVoucherTypeId;
                    infoLedgerPosting.Date = PublicVariables._dtCurrentDate;
                    if (strstatus == "Cleared")
                    {
                        infoLedgerPosting.LedgerId = infoPDCReceivable.BankId;
                    }
                    else if (strstatus == "Bounced")
                    {
                        infoLedgerPosting.LedgerId = infoPDCReceivable.LedgerId;
                    }
                    infoLedgerPosting.VoucherNo = strVoucherNo;
                    infoLedgerPosting.InvoiceNo = txtvoucherNo.Text.Trim();
                    infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                    infoLedgerPosting.Debit = Convert.ToDecimal(txtAmount.Text.ToString());
                    infoLedgerPosting.Credit = 0;
                    infoLedgerPosting.ChequeDate = Convert.ToDateTime(txtcheckdate.Text);
                    infoLedgerPosting.ChequeNo = txtcheckNo.Text.Trim();
                    infoLedgerPosting.ExtraDate = PublicVariables._dtCurrentDate;
                    infoLedgerPosting.Extra1 = string.Empty;
                    infoLedgerPosting.Extra2 = string.Empty;
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PC12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to search based on the condition
 /// </summary>
 public void Search()
 {
     try
     {
         if (cmbAccountLedger.Text.Trim() == string.Empty)
         {
             cmbAccountLedger.Text = "All";
         }
         else if (cmbVouchertype.Text.Trim() == string.Empty)
         {
             cmbVouchertype.Text = "All";
         }
         else if (cmbStatus.Text.Trim() == string.Empty)
         {
             cmbStatus.Text = "All";
         }
         List<DataTable> ListPDCReport = new List<DataTable>();
         PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
         ListPDCReport = BllPDCReciveble.PdcReceivableReportSearch(Convert.ToDateTime(dtpFrmDate.Value.ToString()), Convert.ToDateTime(dtpToDate.Value.ToString()), cmbVouchertype.Text.ToString(), cmbAccountLedger.Text.ToString(), Convert.ToDateTime(dtpCheckDateFrom.Value.ToString()), Convert.ToDateTime(dtpCheckDateTo.Value.ToString()), txtCheckNo.Text.Trim(), txtVoucherNo.Text.Trim(), cmbStatus.Text.Trim());
         dgvPdcReceivableSearch.DataSource = ListPDCReport[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("PRREP5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to print the form
 /// </summary>
 public void Print()
 {
     try
     {
         string strFromDate = txtFromDate.Text.ToString();
         string strToDate = txtToDate.ToString();
         decimal decVoucherTypeId = Convert.ToDecimal(cmbVouchertype.SelectedValue.ToString());
         decimal decLedgerId = Convert.ToDecimal(cmbAccountLedger.SelectedValue.ToString());
         PDCRecivebleBll BllPDCReciveble = new PDCRecivebleBll();
         DataSet dsPdcReceivableReport = BllPDCReciveble.PdcreceivableReportPrinting(Convert.ToDateTime(dtpFrmDate.Value.ToString()), Convert.ToDateTime(dtpToDate.Value.ToString()), cmbVouchertype.Text.ToString(), cmbAccountLedger.Text.ToString(), Convert.ToDateTime(dtpCheckDateFrom.Value.ToString()), Convert.ToDateTime(dtpCheckDateTo.Value.ToString()), txtCheckNo.Text.Trim(), txtVoucherNo.Text.Trim(), cmbStatus.Text.Trim(), 1);
         frmReport frmReport = new frmReport();
         frmReport.MdiParent = formMDI.MDIObj;
         frmReport.PdcreceivablereportReportPrinting(dsPdcReceivableReport);
     }
     catch (Exception ex)
     {
         MessageBox.Show("PRREP6:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }