/// <summary>
        /// Function to update values in ledgerposting table
        /// </summary>
        public void ledgerUpdate()
        {
            try
            {
                string strfinancialId;
                FinancialYearBll BllFinancialYear = new FinancialYearBll();
                FinancialYearInfo infoFinancialYear = new FinancialYearInfo();
                infoFinancialYear = BllFinancialYear.FinancialYearViewForAccountLedger(1);
                strfinancialId = infoFinancialYear.FromDate.ToString("dd-MMM-yyyy");
                decimal decLedgerPostingId = 0;
                if (txtOpeningBalance.Text.Trim() != string.Empty)
                {
                    decOpeningBlnc = Convert.ToDecimal(txtOpeningBalance.Text.Trim());
                }
                else
                {
                    decOpeningBlnc = 0;
                }

                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
                List<DataTable> dtbl = BllLedgerPosting.GetLedgerPostingIds(decLedgerIdForEdit.ToString(), 1);
                foreach (DataRow dr in dtbl[0].Rows)
                {
                    decLedgerPostingId = Convert.ToDecimal(dr.ItemArray[0].ToString());
                }
                if (cmbDrorCr.Text == "Dr")
                {
                    infoLedgerPosting.Debit = decOpeningBlnc;
                }
                else
                {
                    infoLedgerPosting.Credit = decOpeningBlnc;
                }
                infoLedgerPosting.LedgerPostingId = decLedgerPostingId;
                infoLedgerPosting.VoucherTypeId = 1;
                infoLedgerPosting.VoucherNo = decLedgerIdForEdit.ToString();
                infoLedgerPosting.Date = Convert.ToDateTime(strfinancialId.ToString());
                infoLedgerPosting.LedgerId = decLedgerIdForEdit;
                infoLedgerPosting.DetailsId = 0;
                infoLedgerPosting.InvoiceNo = decLedgerIdForEdit.ToString();
                infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                infoLedgerPosting.ChequeDate = DateTime.Now;
                infoLedgerPosting.ChequeNo = string.Empty;
                infoLedgerPosting.Extra1 = string.Empty;
                infoLedgerPosting.Extra2 = string.Empty;
                if (dtbl[0].Rows.Count > 0)
                {
                    if (decOpeningBlnc > 0)
                    {
                        BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting);
                    }
                    else
                    {
                        AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                        bllAccountLedger.LedgerPostingDeleteByVoucherTypeAndVoucherNo(decLedgerIdForEdit.ToString(), 1);
                    }
                }
                else
                {
                    BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cus16:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Save data to the database
        /// </summary>
        public void SaveFunction()
        {
            try
            {
                int inRowcount = dgvMultipleAccountLedger.RowCount;//edited by Runali
                int inRowcountDec = (dgvMultipleAccountLedger.RowCount) - 1;
                decimal decOpeningBalance = 0;
                decimal decLedgerId = 0;
                bool isSave = false;
                AccountLedgerInfo infoAccountledger = new AccountLedgerInfo();
                AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
                LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
                FinancialYearBll BllFinancialYear = new FinancialYearBll();
                FinancialYearInfo infoFinancialYear = new FinancialYearInfo();

                for (int i = 0; i < inRowcount - 1; i++)
                {
                    infoAccountledger.AccountGroupId = Convert.ToDecimal(cmbAccountGroup.SelectedValue.ToString());

                    infoAccountledger.LedgerName = dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtLedgerName"].Value.ToString();
                    if (dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtOpeningBalance"].Value != null)
                    {
                        infoAccountledger.OpeningBalance = Convert.ToDecimal(dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtOpeningBalance"].Value.ToString());
                    }
                    else
                    {
                        infoAccountledger.OpeningBalance = 0;
                    }
                    infoAccountledger.CrOrDr = dgvMultipleAccountLedger.Rows[i].Cells["dgvcmbDebitOrCredit"].Value.ToString();

                    if (dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtNarration"].Value != null)
                    {
                        infoAccountledger.Narration = dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtNarration"].Value.ToString();
                    }
                    else
                    {
                        infoAccountledger.Narration = string.Empty;
                    }
                    infoAccountledger.MailingName = string.Empty;
                    infoAccountledger.Address = string.Empty;
                    infoAccountledger.State = string.Empty;
                    infoAccountledger.Phone = string.Empty;
                    infoAccountledger.Mobile = string.Empty;
                    infoAccountledger.Email = string.Empty;
                    infoAccountledger.CreditPeriod = 0;
                    infoAccountledger.CreditLimit = 0;
                    infoAccountledger.PricinglevelId = 0;
                    infoAccountledger.BillByBill = false;
                    infoAccountledger.Tin = string.Empty;
                    infoAccountledger.Cst = string.Empty;
                    infoAccountledger.Pan = string.Empty;
                    infoAccountledger.RouteId = 0;
                    infoAccountledger.BankAccountNumber = string.Empty;
                    infoAccountledger.BranchName = string.Empty;
                    infoAccountledger.BranchCode = string.Empty;
                    infoAccountledger.Extra1 = string.Empty;
                    infoAccountledger.Extra2 = string.Empty;
                    infoAccountledger.AreaId = 0;
                    infoAccountledger.IsDefault = false;
                    infoAccountledger.ExtraDate = PublicVariables._dtCurrentDate;
                    decLedgerId = bllAccountLedger.AccountLedgerAddWithIdentity(infoAccountledger);

                    if (dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtOpeningBalance"].Value != null && dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtOpeningBalance"].Value.ToString() != "0")
                    {
                        if (dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtOpeningBalance"].Value.ToString() != string.Empty)
                        {
                            string strfinancialId;
                            decOpeningBalance = Convert.ToDecimal(dgvMultipleAccountLedger.Rows[i].Cells["dgvtxtOpeningBalance"].Value.ToString());
                            infoFinancialYear = BllFinancialYear.FinancialYearViewForAccountLedger(1);
                            strfinancialId = infoFinancialYear.FromDate.ToString("dd-MMM-yyyy");
                            infoLedgerPosting.VoucherTypeId = 1;
                            infoLedgerPosting.Date = Convert.ToDateTime(strfinancialId.ToString());
                            infoLedgerPosting.LedgerId = decLedgerId;
                            infoLedgerPosting.VoucherNo = decLedgerId.ToString();
                            if (dgvMultipleAccountLedger.Rows[i].Cells["dgvcmbDebitOrCredit"].Value.ToString() == "Dr")
                            {
                                infoLedgerPosting.Debit = decOpeningBalance;
                            }
                            else
                            {
                                infoLedgerPosting.Credit = decOpeningBalance;
                            }
                            infoLedgerPosting.DetailsId = 0;
                            infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
                            infoLedgerPosting.InvoiceNo = decLedgerId.ToString();

                            infoLedgerPosting.ChequeNo = string.Empty;
                            infoLedgerPosting.ChequeDate = DateTime.Now;

                            infoLedgerPosting.Extra1 = string.Empty;
                            infoLedgerPosting.Extra2 = string.Empty;
                            BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);

                        }

                    }
                    isSave = true;
                }
                if (isSave)
                {
                    Messages.SavedMessage();
                    cmbAccountGroup.Focus();
                    cmbAccountGroup.SelectedIndex = -1;
                    dgvMultipleAccountLedger.Rows.Clear();
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("MAL6:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to save values to ledgerposting table
 /// </summary>
 public void ledgerPosting()
 {
     try
     {
         string strfinancialId;
         decOpeningBlnc = Convert.ToDecimal(txtOpeningBalance.Text);
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
         FinancialYearBll BllFinancialYear = new FinancialYearBll();
         FinancialYearInfo infoFinancialYear = new FinancialYearInfo();
         infoFinancialYear = BllFinancialYear.FinancialYearViewForAccountLedger(1);
         strfinancialId = infoFinancialYear.FromDate.ToString("dd-MMM-yyyy");
         if (cmbDrorCr.Text == "Dr")
         {
             infoLedgerPosting.Debit = decOpeningBlnc;
         }
         else
         {
             infoLedgerPosting.Credit = decOpeningBlnc;
         }
         infoLedgerPosting.VoucherTypeId = 1;
         infoLedgerPosting.VoucherNo = decledgerid.ToString();
         infoLedgerPosting.Date = Convert.ToDateTime(strfinancialId.ToString());
         infoLedgerPosting.LedgerId = decledgerid;
         infoLedgerPosting.DetailsId = 0;
         infoLedgerPosting.InvoiceNo = decledgerid.ToString();
         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
         infoLedgerPosting.ChequeDate = DateTime.Now;
         infoLedgerPosting.ChequeNo = string.Empty;
         infoLedgerPosting.Extra1 = string.Empty;
         infoLedgerPosting.Extra2 = string.Empty;
        BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Cus14:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 ///Function to edit ledgerposting incase of opening balance
 /// </summary> 
 public void LedgerPostingEdit()
 {
     try
     {
         string strfinancialId;
         decOpeningBalance = Convert.ToDecimal(((txtOpeningBalance.Text == "") ? "0" : txtOpeningBalance.Text.Trim()));
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         FinancialYearBll BllFinancialYear = new FinancialYearBll();
         FinancialYearInfo infoFinancialYear = new FinancialYearInfo();
         infoFinancialYear = BllFinancialYear.FinancialYearViewForAccountLedger(1);
         strfinancialId = infoFinancialYear.FromDate.ToString("dd-MMM-yyyy");
         infoLedgerPosting.VoucherTypeId = 1;
         infoLedgerPosting.Date = Convert.ToDateTime(strfinancialId.ToString());
         if (cmbOpeningBalanceCrOrDr.Text == "Dr")
         {
             infoLedgerPosting.Debit = decOpeningBalance;
         }
         else
         {
             infoLedgerPosting.Credit = decOpeningBalance;
         }
         infoLedgerPosting.DetailsId = 0;
         infoLedgerPosting.YearId = PublicVariables._decCurrentFinancialYearId;
         infoLedgerPosting.InvoiceNo = decAccountLedgerId.ToString();
         infoLedgerPosting.Extra1 = string.Empty;
         infoLedgerPosting.Extra2 = string.Empty;
         infoLedgerPosting.LedgerId = decAccountLedgerId;
         infoLedgerPosting.VoucherNo = decAccountLedgerId.ToString();
         infoLedgerPosting.ChequeNo = string.Empty;
         infoLedgerPosting.ChequeDate = DateTime.Now;
         List<DataTable> dtbl = BllLedgerPosting.GetLedgerPostingIds(decAccountLedgerId.ToString(), 1);
         if (dtbl[0].Rows.Count > 0)
         {
             if (decOpeningBalance > 0)
             {
                 //Edit
                 infoLedgerPosting.LedgerPostingId = Convert.ToDecimal(dtbl[0].Rows[0][0].ToString());
                 BllLedgerPosting.LedgerPostingEdit(infoLedgerPosting);
             }
             else
             {
                 //Delete
                 bllAccountLedger.LedgerPostingDeleteByVoucherTypeAndVoucherNo(decAccountLedgerId.ToString(), 1);
             }
         }
         else
         {
             //Add new row
             BllLedgerPosting.LedgerPostingAdd(infoLedgerPosting);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("AL5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }