/// <summary>
 /// function to find the total balance while from balancesheet and trial balance
 /// </summary>
 public void AccountGroupWiseReportForProfitAndLossLedgerGridfill()
 {
     decimal decBalanceTotal = 0;
     try
     {
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllAccountGroup.AccountGroupWiseReportForProfitAndLossLedger(decAccountGroupId, Convert.ToDateTime(txtFromDate.Text), Convert.ToDateTime(txtToDate.Text));
         dgvAccountGroupWiseReport.DataSource = ListObj;
         if (ListObj[0].Rows.Count > 0)
         {
             for (int i = 0; i < dgvAccountGroupWiseReport.RowCount; i++)
             {
                 decBalanceTotal += Convert.ToDecimal(dgvAccountGroupWiseReport.Rows[i].Cells["balance1"].Value.ToString());
             }
         }
         if (decBalanceTotal < 0)
         {
             decBalanceTotal = -1 * decBalanceTotal;
             lblBalanceTotal.Text = decBalanceTotal.ToString() + "Cr";
         }
         else
         {
             lblBalanceTotal.Text = decBalanceTotal.ToString() + "Dr";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("AGWREP07:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill accountgroup combobox
 /// </summary>
 /// <param name="cmbAccountGroup"></param>
 public void AccountGroupComboFill(ComboBox cmbAccountGroup)
 {
     try
     {
         cmbAccountGroup.Enabled = true;
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         bllAccountGroup.BillAllocationAccountGroupFill(cmbAccountGroup, true);
     }
     catch (Exception ex)
     {
         MessageBox.Show("BA:02" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill ledgers as TreeMode
 /// </summary>
 /// <param name="tn"></param>
 public void FillTree(TreeNode tn)
 {
     try
     {
         List<DataTable> ListObj = new List<DataTable>();
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         ListObj = bllAccountGroup.AccountGroupViewAllByGroupUnder(Convert.ToDecimal(tn.Name));
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         if (ListObj[0].Rows.Count > 0)
         {
             foreach (DataRow dr in ListObj[0].Rows)
             {
                 tn.Nodes.Add(dr["accountGroupId"].ToString(), dr["accountGroupName"].ToString());
                 tn.ExpandAll();
                 if (tn.LastNode != null)
                 {
                     tn.LastNode.ForeColor = Color.Red;
                 }
                 else
                 {
                     tn.LastNode.ForeColor = Color.Blue;
                 }
             }
             foreach (TreeNode tn1 in tn.Nodes)
             {
                 FillTree(tn1);
                 List<DataTable> ListObjLedger= bllAccountLedger.AccountLedgerViewAllByLedgerName(Convert.ToDecimal(tn1.Name));
                 foreach (DataRow dr in ListObjLedger[0].Rows)
                 {
                     tn1.Nodes.Add(dr["ledgerId"].ToString(), dr["ledgerName"].ToString());
                     tn1.ExpandAll();
                     if (tn1.LastNode != null)
                     {
                         tn1.LastNode.ForeColor = Color.Blue;
                     }
                     else
                     {
                         tn.LastNode.ForeColor = Color.Red;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("COA:1" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the accountgroup combo box
 /// </summary>
 public void AccountGroupComboFill()
 {
     try
     {
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllAccountGroup.AccountGroupViewAllComboFillForAccountLedger();
         DataRow dr = ListObj[0].NewRow();
         dr["accountGroupName"] = "All";
         dr["accountGroupId"] = -1;
         ListObj[0].Rows.InsertAt(dr, 0);
         cmbAccountGroup.DataSource = ListObj[0];
         cmbAccountGroup.ValueMember = "accountGroupId";
         cmbAccountGroup.DisplayMember = "accountGroupName";
     }
     catch (Exception ex)
     {
         MessageBox.Show("ALREP2:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// on combobox account group text changing
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmbAccountGroup_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (isLoad)
         {
             int index = cmbAccountGroup.SelectedIndex;
             string strinr = cmbAccountGroup.Text.ToString();
             int dec = cmbAccountGroup.SelectedIndex;
             int inRowcount = dgvMultipleAccountLedger.RowCount;
             AccountGroupBll bllAccountGroup = new AccountGroupBll();
             string strNature;
             strNature = bllAccountGroup.MultipleAccountLedgerCrOrDr(cmbAccountGroup.Text);
             for (int i = 0; i < inRowcount; i++)
             {
                 if (strNature == "Assets" || strNature == "Income")
                 {
                     dgvMultipleAccountLedger.Rows[i].Cells["dgvcmbDebitOrCredit"].Value = "Cr";
                 }
                 else if (strNature == "Expenses" || strNature == "Liabilities")
                 {
                     dgvMultipleAccountLedger.Rows[i].Cells["dgvcmbDebitOrCredit"].Value = "Dr";
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("MAL12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// on grid opening balance textbox keypress
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvtxtOpeningBalance_KeyPress(object sender, KeyPressEventArgs e)
        {
            AccountGroupBll bllAccountGroup = new AccountGroupBll();
            try
            {
                if (dgvMultipleAccountLedger.CurrentCell != null)
                {
                    if (dgvMultipleAccountLedger.Columns[dgvMultipleAccountLedger.CurrentCell.ColumnIndex].Name == "dgvtxtOpeningBalance")
                    {
                        Common.DecimalValidation(sender, e, false);
                    }

                    if (dgvMultipleAccountLedger.Columns[dgvMultipleAccountLedger.CurrentCell.ColumnIndex].Name == "dgvtxtLedgerName")
                    {
                        if (dgvMultipleAccountLedger.Columns["dgvtxtLedgerName"].Index == 1)
                        {
                            string strNature;
                            strNature = bllAccountGroup.MultipleAccountLedgerCrOrDr(cmbAccountGroup.Text);
                            if (strNature == "Assets" || strNature == "Income")
                            {
                                dgvMultipleAccountLedger.Rows[dgvMultipleAccountLedger.CurrentRow.Index].Cells["dgvcmbDebitOrCredit"].Value = "Cr";
                            }
                            else if (strNature == "Expenses" || strNature == "Liabilities")
                            {
                                dgvMultipleAccountLedger.Rows[dgvMultipleAccountLedger.CurrentRow.Index].Cells["dgvcmbDebitOrCredit"].Value = "Dr";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("MAL17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// datagridview cell beginend edit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvBudget_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            try
            {
                inUpdatingRowIndexForPartyRemove = -1;
                decUpdatingLedgerForPartyremove = 0;
                List<DataTable> ListObj = new List<DataTable>();
                AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                if (cmbType.SelectedIndex == 0)
                {
                    if (dgvBudget.CurrentCell.ColumnIndex == dgvBudget.Columns["dgvcmbParticular"].Index)
                    {

                        ListObj = bllAccountLedger.AccountLedgerViewAll();
                        DataRow dr = ListObj[0].NewRow();
                        dr[0] = 0;
                        dr[2] = string.Empty;
                        ListObj[0].Rows.InsertAt(dr, 0);
                        if (ListObj[0].Rows.Count > 0)
                        {

                            if (dgvBudget.RowCount > 1)
                            {
                                int inGridRowCount = dgvBudget.RowCount;
                                for (int inI = 0; inI < inGridRowCount - 1; inI++)
                                {
                                    if (inI != e.RowIndex)
                                    {
                                        int inTableRowcount = ListObj[0].Rows.Count;
                                        for (int inJ = 0; inJ < inTableRowcount; inJ++)
                                        {
                                            if (dgvBudget.Rows[inI].Cells["dgvcmbParticular"].Value != null && dgvBudget.Rows[inI].Cells["dgvcmbParticular"].Value.ToString() != string.Empty)
                                            {
                                                if (ListObj[0].Rows[inJ]["ledgerId"].ToString() == dgvBudget.Rows[inI].Cells["dgvcmbParticular"].Value.ToString())
                                                {
                                                    ListObj[0].Rows.RemoveAt(inJ);
                                                    break;
                                                }
                                            }
                                        }

                                    }
                                }
                            }
                            DataGridViewComboBoxCell dgvccVoucherType = (DataGridViewComboBoxCell)dgvBudget[dgvBudget.Columns["dgvcmbParticular"].Index, e.RowIndex];
                            dgvccVoucherType.DataSource = ListObj[0];
                            dgvccVoucherType.ValueMember = "ledgerId";
                            dgvccVoucherType.DisplayMember = "ledgerName";
                        }
                    }

                    if (dgvBudget.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvcmbParticular")
                    {
                        if (dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value != null && dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value.ToString() != string.Empty)
                        {
                            if (bllAccountLedger.AccountGroupIdCheck(dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].FormattedValue.ToString()))
                            {
                                inUpdatingRowIndexForPartyRemove = e.RowIndex;
                                decUpdatingLedgerForPartyremove = Convert.ToDecimal(dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value.ToString());
                            }
                        }
                    }
                    if (dgvBudget.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvcmbDrOrCr")
                    {
                        if (dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value != null && dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value.ToString() != string.Empty)
                        {
                            if (bllAccountLedger.AccountGroupIdCheck(dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].FormattedValue.ToString()))
                            {
                                inUpdatingRowIndexForPartyRemove = e.RowIndex;
                                decUpdatingLedgerForPartyremove = Convert.ToDecimal(dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value.ToString());
                            }
                        }
                    }
                }
                else
                {
                    if (dgvBudget.CurrentCell.ColumnIndex == dgvBudget.Columns["dgvcmbParticular"].Index)
                    {
                        AccountGroupBll bllAccountGroup = new AccountGroupBll();
                        ListObj = bllAccountGroup.GroupNameViewForComboFill();
                        DataRow dr = ListObj[0].NewRow();
                        dr[0] = 0;

                        ListObj[0].Rows.InsertAt(dr, 0);
                        if (ListObj[0].Rows.Count > 0)
                        {

                            if (dgvBudget.RowCount > 1)
                            {
                                int inGridRowCount = dgvBudget.RowCount;
                                for (int inI = 0; inI < inGridRowCount - 1; inI++)
                                {
                                    if (inI != e.RowIndex)
                                    {
                                        int inTableRowcount = ListObj[0].Rows.Count;
                                        for (int inJ = 0; inJ < inTableRowcount; inJ++)
                                        {
                                            if (dgvBudget.Rows[inI].Cells["dgvcmbParticular"].Value != null && dgvBudget.Rows[inI].Cells["dgvcmbParticular"].Value.ToString() != string.Empty)
                                            {
                                                if (ListObj[0].Rows[inJ]["accountGroupName"].ToString() == dgvBudget.Rows[inI].Cells["dgvcmbParticular"].Value.ToString())
                                                {
                                                    ListObj[0].Rows.RemoveAt(inJ);
                                                    break;
                                                }
                                            }
                                        }

                                    }
                                }
                            }
                            DataGridViewComboBoxCell dgvccVoucherType = (DataGridViewComboBoxCell)dgvBudget[dgvBudget.Columns["dgvcmbParticular"].Index, e.RowIndex];
                            dgvccVoucherType.DataSource = ListObj[0];
                            dgvccVoucherType.ValueMember = "accountGroupId";
                            dgvccVoucherType.DisplayMember = "accountGroupName";
                        }
                    }

                    if (dgvBudget.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvcmbParticular")
                    {
                        if (dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value != null && dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value.ToString() != string.Empty)
                        {
                            if (bllAccountLedger.AccountGroupIdCheck(dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].FormattedValue.ToString()))
                            {
                                inUpdatingRowIndexForPartyRemove = e.RowIndex;
                                decUpdatingLedgerForPartyremove = Convert.ToDecimal(dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value.ToString());
                            }
                        }
                    }
                    if (dgvBudget.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "dgvcmbDrOrCr")
                    {
                        if (dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value != null && dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value.ToString() != string.Empty)
                        {
                            if (bllAccountLedger.AccountGroupIdCheck(dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].FormattedValue.ToString()))
                            {
                                inUpdatingRowIndexForPartyRemove = e.RowIndex;
                                decUpdatingLedgerForPartyremove = Convert.ToDecimal(dgvBudget.Rows[e.RowIndex].Cells["dgvcmbParticular"].Value.ToString());
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("BU37:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// function to fill particulars combo
        /// </summary>
        public void GroupNameViewForComboFill()
        {
            try
            {

                List<DataTable> ListObj = new List<DataTable>();
                AccountGroupBll bllAccountGroup = new AccountGroupBll();
                ListObj = bllAccountGroup.GroupNameViewForComboFill();
                dgvcmbParticular.DataSource = ListObj[0];
                dgvcmbParticular.ValueMember = "accountGroupId";
                dgvcmbParticular.DisplayMember = "accountGroupName";

            }
            catch (Exception ex)
            {
                MessageBox.Show("BU3:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to save and edit account group
 /// </summary>
 public void SaveOrEdit()
 {
     try
     {
         strAccountGroupName = btnSave.Text == "Save" ? string.Empty : strAccountGroupName;
         if (CheckExistanceOfGroupName() == false)
         {
             if (txtAccountGroupName.Text.Trim() == string.Empty)
             {
                 Messages.InformationMessage("Enter account group name");
                 txtAccountGroupName.Focus();
             }
             else if (cmbGroupUnder.SelectedIndex == -1)
             {
                 Messages.InformationMessage("Select under");
                 cmbGroupUnder.Focus();
             }
             else if (cmbNature.SelectedIndex == -1)
             {
                 Messages.InformationMessage("Select nature");
                 cmbNature.Focus();
             }
             else
             {
                 AccountGroupInfo infoAccountGroup = new AccountGroupInfo();
                 AccountGroupBll bllAccountGroup = new AccountGroupBll();
                 infoAccountGroup.AccountGroupName = txtAccountGroupName.Text.Trim();
                 infoAccountGroup.GroupUnder = Convert.ToDecimal(cmbGroupUnder.SelectedValue.ToString());
                 infoAccountGroup.Nature = cmbNature.SelectedItem.ToString();
                 if (cmbAffectGrossProfit.SelectedIndex == -1)
                 {
                     infoAccountGroup.AffectGrossProfit = "No";
                 }
                 else
                 {
                     infoAccountGroup.AffectGrossProfit = cmbAffectGrossProfit.SelectedItem.ToString();
                 }
                 infoAccountGroup.IsDefault = false;
                 infoAccountGroup.Narration = txtNarration.Text.Trim();
                 infoAccountGroup.Extra1 = string.Empty;
                 infoAccountGroup.Extra2 = string.Empty;
                 if (btnSave.Text == "Save")
                 {
                     if (Messages.SaveConfirmation())
                     {
                         decAccountGroupId = bllAccountGroup.AccountGroupAddWithIdentity(infoAccountGroup);
                         Messages.SavedMessage();
                         decIdForOtherForms = decAccountGroupId;
                         if (frmAccountLedgerobj != null)
                         {
                             this.Close();
                         }
                         GridFill();
                         Clear();
                     }
                 }
                 else
                 {
                     if (isDefault == true)
                     {
                         Messages.InformationMessage("Can't update build in account group");
                     }
                     else if (txtAccountGroupName.Text.Trim().ToLower() != cmbGroupUnder.Text.ToLower())
                     {
                         if (Messages.UpdateConfirmation())
                         {
                             infoAccountGroup.AccountGroupId = decAccountGroupIdForEdit;
                             if (bllAccountGroup.AccountGroupUpdate(infoAccountGroup))
                             {
                                 Messages.UpdatedMessage();
                             }
                             GridFill();
                             Clear();
                         }
                     }
                     else
                     {
                         Messages.InformationMessage(" Can't save under same group");
                     }
                 }
             }
         }
         else
         {
             Messages.InformationMessage(" Account group already exist");
             txtAccountGroupName.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("AG8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill acoountgroup combobox
 /// </summary>
 public void AccountGroupComboFillSearch()
 {
     try
     {
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         List<DataTable> ListObj = new List<DataTable>();
         DataTable dtblAcccountGroup = new DataTable();
         ListObj = bllAccountGroup.AccountGroupViewAllComboFill();
         DataRow dr = ListObj[0].NewRow();
         dr[1] = "All";
         ListObj[0].Rows.InsertAt(dr, 0);
         cmbGroupSearch.DataSource = ListObj[0];
         ListObj.Add(dtblAcccountGroup);
         cmbGroupSearch.ValueMember = "accountGroupId";
         cmbGroupSearch.DisplayMember = "accountGroupName";
         cmbGroupSearch.SelectedIndex = 0;
     }
     catch (Exception ex)
     {
         MessageBox.Show("AL9:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Form Load
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void frmChartOfAccount_Load(object sender, EventArgs e)
 {
     try
     {
         dtblItems.Columns.Add("name");
         dtblItems.Columns.Add("type");
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllAccountGroup.AccountGroupViewAllByGroupUnder(-1);
         foreach (DataRow dr in ListObj[0].Rows)
         {
             tvChartOfAccount.Nodes.Add(dr["accountGroupId"].ToString(), dr["accountGroupName"].ToString());
         }
         foreach (TreeNode tn1 in tvChartOfAccount.Nodes)
         {
             FillTree(tn1);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("COA:3" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Grid Fill function while coming from other form to update or delete
 /// </summary>
 public void FillFunction()
 {
     try
     {
         //PaymentMasterSP SpPaymentMaster = new PaymentMasterSP();
         PaymentMasterInfo InfoPaymentMaster = new PaymentMasterInfo();
         //PaymentDetailsSP SpPaymentDetails = new PaymentDetailsSP();
         PaymentVoucherBll BllPaymentVoucher = new PaymentVoucherBll();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         VoucherTypeBll BllVoucherType = new VoucherTypeBll();
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
         InfoPaymentMaster = BllPaymentVoucher.PaymentMasterViewByMasterId(decPaymentmasterId);//view master details
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(InfoPaymentMaster.VoucherTypeId);
         if (isAutomatic)
         {
             txtVoucherNo.ReadOnly = true;
             txtVoucherNo.Text = InfoPaymentMaster.InvoiceNo;
             txtDate.Focus();
         }
         else
         {
             txtVoucherNo.ReadOnly = false;
             txtVoucherNo.Text = InfoPaymentMaster.InvoiceNo;
             txtVoucherNo.Focus();
         }
         dtpDate.Text = InfoPaymentMaster.Date.ToString();
         cmbBankorCash.SelectedValue = InfoPaymentMaster.LedgerId;
         txtNarration.Text = InfoPaymentMaster.Narration;
         txtTotal.Text = InfoPaymentMaster.TotalAmount.ToString();
         decDailySuffixPrefixId = InfoPaymentMaster.SuffixPrefixId;
         decPaymentVoucherTypeId = InfoPaymentMaster.VoucherTypeId;
         strVoucherNo = InfoPaymentMaster.VoucherNo;
         strInvoiceNo = InfoPaymentMaster.InvoiceNo;
         //DataTable dtbl = new DataTable();
         List<DataTable> listObj1 = new List<DataTable>();
         listObj1 = BllPaymentVoucher.PaymentDetailsViewByMasterId(decPaymentmasterId);//view details details
         for (int inI = 0; inI < listObj1[0].Rows.Count; inI++)
         {
             dgvPaymentVoucher.Rows.Add();
             dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].Value = Convert.ToDecimal(listObj1[0].Rows[inI]["ledgerId"].ToString());
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentMasterId"].Value = listObj1[0].Rows[inI]["paymentMasterId"].ToString();
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtpaymentDetailsId"].Value = listObj1[0].Rows[inI]["paymentDetailsId"].ToString();
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].Value = listObj1[0].Rows[inI]["amount"].ToString();
             dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(listObj1[0].Rows[inI]["exchangeRateId"].ToString());
             decimal decDetailsId1 = Convert.ToDecimal(listObj1[0].Rows[inI]["paymentDetailsId"].ToString());
             decimal decLedgerPostingId = BllLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, decPaymentVoucherTypeId);
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString();
             decimal decLedgerId = Convert.ToDecimal(listObj1[0].Rows[inI]["ledgerId"].ToString());
             bool IsBankAccount = bllAccountGroup.AccountGroupwithLedgerId(decLedgerId);
             decimal decI = Convert.ToDecimal(bllAccountLedger.AccountGroupIdCheck(dgvPaymentVoucher.Rows[inI].Cells["dgvcmbAccountLedger"].FormattedValue.ToString()));
             if (decI > 0)//to make amount and currency read only when party is choosen as ledger
             {
                 dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = true;
                 dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = true;
             }
             else
             {
                 dgvPaymentVoucher.Rows[inI].Cells["dgvtxtAmount"].ReadOnly = false;
                 dgvPaymentVoucher.Rows[inI].Cells["dgvcmbCurrency"].ReadOnly = false;
             }
             dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value = listObj1[0].Rows[inI]["ChequeNo"].ToString();
             if (dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value != null && dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeNo"].Value.ToString() != string.Empty)
             {
                 dgvPaymentVoucher.Rows[inI].Cells["dgvtxtChequeDate"].Value = Convert.ToDateTime(listObj1[0].Rows[inI]["ChequeDate"].ToString()).ToString("dd-MMM-yyyy");
             }
             dgvPaymentVoucher.Rows[inI].HeaderCell.Value = string.Empty;
         }
         List<DataTable> listObj = new List<DataTable>();
         listObj = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherType(decPaymentVoucherTypeId, strVoucherNo, InfoPaymentMaster.Date);
         dtblPartyBalance = listObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("PV36:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// On print button click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnPrint_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvCashOrBank.Rows.Count > 0)
         {
             AccountGroupBll bllAccountGroup = new AccountGroupBll();
             DataSet dsCashBankBook = bllAccountGroup.CashBankBookPrinting(1, this.dtpFromDate.Value, this.dtpToDate.Value, true);
             frmReport frmReport = new frmReport();
             frmReport.MdiParent = formMDI.MDIObj;
             frmReport.CashBankBookPrinting(dsCashBankBook);
         }
         else
         {
             Messages.InformationMessage("No data found");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("CBBOOK09 :" + 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 check existance of account group in DataBase
 /// </summary>
 /// <returns></returns>
 public bool CheckExistanceOfGroupName()
 {
     bool isExist = false;
     try
     {
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         isExist = bllAccountGroup.AccountGroupCheckExistence(txtAccountGroupName.Text.Trim(), 0);
         if (isExist)
         {
             if (txtAccountGroupName.Text.ToLower() == strAccountGroupName.ToLower())
             {
                 isExist = false;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("AG5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     return isExist;
 }
        /// <summary>
        /// Fills to control on cell double click in Datagridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvAccountGroup_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1)
                {
                    AccountGroupInfo InfoAccountGroup = new AccountGroupInfo();
                    AccountGroupBll bllAccountGroup = new AccountGroupBll();
                    InfoAccountGroup = bllAccountGroup.AccountGroupViewForUpdate(Convert.ToDecimal(dgvAccountGroup.CurrentRow.Cells["dgvtxtAccountGroupId"].Value.ToString()));
                    bool Isdefault=InfoAccountGroup.IsDefault;
                    txtAccountGroupName.Text = InfoAccountGroup.AccountGroupName;
                    cmbGroupUnder.SelectedValue = InfoAccountGroup.GroupUnder.ToString();
                    decimal decAccountGroupId =Convert.ToDecimal(cmbGroupUnder.SelectedValue.ToString());
                    string strNature = bllAccountGroup.AccountGroupNatureUnderGroup(decAccountGroupId);
                    if (strNature != "NA")
                    {
                        cmbNature.Text = InfoAccountGroup.Nature;
                        cmbNature.Enabled = false;
                    }
                    else
                    {
                        cmbNature.Text = InfoAccountGroup.Nature;
                        cmbNature.Enabled = true;
                    }
                    if (Isdefault)
                    {
                        decimal decAffectGrossProfit = Convert.ToDecimal(InfoAccountGroup.AffectGrossProfit);
                        if (decAffectGrossProfit == 0)
                        {
                            cmbAffectGrossProfit.Text = "No";

                        }
                        else
                        {
                            cmbAffectGrossProfit.Text = "Yes";
                        }
                    }
                    else
                    {
                        cmbAffectGrossProfit.Text = InfoAccountGroup.AffectGrossProfit;
                    }
                    txtNarration.Text = InfoAccountGroup.Narration;
                    btnSave.Text = "Update";
                    txtAccountGroupName.Focus();
                    btnDelete.Enabled = true;
                    strAccountGroupName = InfoAccountGroup.AccountGroupName;
                    decAccountGroupIdForEdit = Convert.ToDecimal(dgvAccountGroup.CurrentRow.Cells["dgvtxtAccountGroupId"].Value.ToString());
                    inId = Convert.ToInt32(InfoAccountGroup.AccountGroupId.ToString());
                    isDefault = Convert.ToBoolean(InfoAccountGroup.IsDefault);

                    if (isDefault == true  && strNature!="NA")
                    {
                        txtAccountGroupName.Enabled = false;
                        cmbAffectGrossProfit.Enabled = false;
                        cmbGroupUnder.Enabled = false;
                        cmbNature.Enabled = false;
                    }
                    else
                    {
                        if (strNature == "NA")
                        {
                            txtAccountGroupName.Enabled = true;
                            cmbAffectGrossProfit.Enabled = true;
                            cmbGroupUnder.Enabled = true;
                            cmbNature.Enabled = true;
                        }

                     }
                    if (isDefault == false)
                    {
                        if (bllAccountGroup.AccountGroupCheckExistenceOfUnderGroup(Convert.ToDecimal(inId.ToString())) == false)
                        {
                            cmbAffectGrossProfit.Enabled = false;
                            cmbGroupUnder.Enabled = false;
                            cmbNature.Enabled = false;
                        }
                        else
                        {
                            if (strNature == "NA")
                            {
                                cmbAffectGrossProfit.Enabled = true;
                                cmbGroupUnder.Enabled = true;
                                cmbNature.Enabled = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("AG18:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void cmbGroupUnder_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (cmbGroupUnder.SelectedValue != null && cmbGroupUnder.SelectedValue.ToString() != "System.Data.DataRowView")
                {
                    decimal decAccountGroupId = Convert.ToDecimal(cmbGroupUnder.SelectedValue.ToString());
                    AccountGroupBll bllAccountGroup = new AccountGroupBll();
                    AccountGroupInfo infoAccountGroup = new AccountGroupInfo();
                    infoAccountGroup = bllAccountGroup.AccountGroupView(decAccountGroupId);
                    string strNature = infoAccountGroup.Nature;
                    string strIsAffectGrossProfit = infoAccountGroup.AffectGrossProfit;
                    if (strNature != "NA")
                    {
                        cmbNature.Text = strNature;
                        if (infoAccountGroup.AffectGrossProfit == "1")
                        {
                            cmbAffectGrossProfit.SelectedIndex = 0;
                        }
                        else
                        {
                            cmbAffectGrossProfit.SelectedIndex = 1;
                        }
                        cmbNature.Enabled = false;
                        cmbAffectGrossProfit.Enabled = false;

                    }
                    else
                    {
                        cmbNature.Enabled = true;
                        cmbAffectGrossProfit.Enabled = true;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// Function to print report
        /// </summary>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        public void Print(DateTime fromDate, DateTime toDate)
        {
            try
            {
                FinancialStatementBll bllFinancialStatement = new FinancialStatementBll();
                AccountGroupBll bllAccountGroup = new AccountGroupBll();
                DataSet dsAccountGroup = new DataSet();
                List<DataTable> ListObj = bllAccountGroup.AccountGroupReportFill(fromDate, toDate);
                string strSum = lblBalanceTotal.Text;
                DataTable dtblSum = new DataTable();
                dtblSum.Columns.Add("Sum", typeof(string));
                DataRow dr = dtblSum.NewRow();
                dr[0] = strSum;
                dtblSum.Rows.InsertAt(dr, 0);

                List<DataTable> listCompany = bllFinancialStatement.FundFlowReportPrintCompany(1);
                dsAccountGroup.Tables.Add(ListObj[0]);
                dsAccountGroup.Tables.Add(listCompany[0]);
                dsAccountGroup.Tables.Add(dtblSum);
                frmReport frmReport = new frmReport();
                frmReport.MdiParent = formMDI.MDIObj;
                frmReport.AccountGroup(dsAccountGroup);
            }
            catch (Exception ex)
            {
                MessageBox.Show("AGR:1" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to delete account group
 /// </summary>
 public void Delete()
 {
     try
     {
         if (isDefault == true)
         {
             Messages.InformationMessage("Can't delete build in account group");
         }
         //else if (PublicVariables.isMessageDelete)
         //{
         else if (Messages.DeleteConfirmation())
         {
             AccountGroupInfo InfoAccountGroup = new AccountGroupInfo();
             AccountGroupBll bllAccountGroup = new AccountGroupBll();
             if ((bllAccountGroup.AccountGroupReferenceDelete(decAccountGroupIdForEdit) == -1))
             {
                 Messages.ReferenceExistsMessage();
             }
             else
             {
                 Messages.DeletedMessage();
                 btnSave.Text = "Save";
                 btnDelete.Enabled = false;
                 Clear();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("AG10:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the report in grid
 /// </summary>
 public void AccountGroupGridFill()
 {
     decimal decBalanceTotal = 0;
     DateTime dtmFromDate = DateTime.Now;
     DateTime dtmToDate = DateTime.Now;
     AccountGroupBll bllAccountGroup = new AccountGroupBll();
     List<DataTable> ListObj = new List<DataTable>();
     try
     {
         if (txtFromDate.Text != string.Empty)
         {
             dtmFromDate = Convert.ToDateTime(txtFromDate.Text);
         }
         if (txtToDate.Text != string.Empty)
         {
             dtmToDate = Convert.ToDateTime(txtToDate.Text);
         }
         ListObj = bllAccountGroup.AccountGroupReportFill(dtmFromDate, dtmToDate);
         for (int i = 0; i < ListObj[0].Rows.Count; i++)
         {
             if (Convert.ToDecimal(ListObj[0].Rows[i]["accountGroupId"].ToString()) == 6)
             {
                 FinancialStatementBll bllFinancialStatement = new FinancialStatementBll();
                 CalculationMethod();
                 decimal dcOpeninggStock = bllFinancialStatement.StockValueGetOnDate(PublicVariables._dtFromDate, calculationMethod, true, true);
                 dcOpeninggStock = Math.Round(dcOpeninggStock, PublicVariables._inNoOfDecimalPlaces);
                 decimal decOpBalance = Convert.ToDecimal(ListObj[0].Rows[i]["OpBalance"].ToString()) + dcOpeninggStock;
                 decimal decClosing = Convert.ToDecimal(ListObj[0].Rows[i]["balance1"].ToString()) + dcOpeninggStock;
                 if (decOpBalance >= 0)
                 {
                     ListObj[0].Rows[i]["OpeningBalance"] = decOpBalance.ToString() + "Dr";
                 }
                 else
                 {
                     ListObj[0].Rows[i]["OpeningBalance"] = decOpBalance.ToString() + "Cr";
                 }
                 if (decClosing >= 0)
                 {
                     ListObj[0].Rows[i]["balance"] = decClosing.ToString() + "Dr";
                 }
                 else
                 {
                     ListObj[0].Rows[i]["balance"] = decClosing.ToString() + "Cr";
                 }
                 ListObj[0].Rows[i]["balance1"] = decClosing.ToString();
             }
         }
         dgvAccountGroupReport.DataSource = ListObj[0];
         if (dgvAccountGroupReport.RowCount > 0)
         {
             for (int i = 0; i < dgvAccountGroupReport.RowCount; i++)
             {
                 decBalanceTotal = decBalanceTotal + Convert.ToDecimal(dgvAccountGroupReport.Rows[i].Cells["dgvtxtBalance1"].Value.ToString());
             }
         }
         if (decBalanceTotal < 0)
         {
             decBalanceTotal = -1 * decBalanceTotal;
             lblBalanceTotal.Text = decBalanceTotal.ToString() + "Cr";
         }
         else
         {
             lblBalanceTotal.Text = decBalanceTotal.ToString() + "Dr"; ;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("AGR:4" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the report in grid for fundflow
 /// </summary>
 /// <param name="decCS"></param>
 public void GridFillForFundFlow(decimal decCS)
 {
     decimal decBalanceTotal = 0;
     try
     {
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllAccountGroup.AccountGroupWiseReportViewAll(decAccountGroupId, Convert.ToDateTime(txtFromDate.Text), Convert.ToDateTime(txtToDate.Text));
         DataRow drow = ListObj[0].NewRow();
         decimal decCsop = 0;
         drow[1] = -2;
         drow[2] = 0;
         drow[3] = "Closing Stock";
         drow[4] = decCsop .ToString ()+ ".00Dr";
         drow[5] = decCS;
         drow[6] = "0.00";
         drow[7] = decCS.ToString ()+"Dr";
         drow[8] = decCS.ToString();
         ListObj[0].Rows.InsertAt(drow, ListObj[0].Rows.Count);
         dgvAccountGroupWiseReport.DataSource = ListObj[0];
         if (ListObj[0].Rows.Count > 0)
         {
             for (int i = 0; i < dgvAccountGroupWiseReport.RowCount; i++)
             {
                 decBalanceTotal += Convert.ToDecimal(dgvAccountGroupWiseReport.Rows[i].Cells["balance1"].Value.ToString());
             }
         }
         if (decBalanceTotal < 0)
         {
             decBalanceTotal = -1 * decBalanceTotal;
             lblBalanceTotal.Text = decBalanceTotal.ToString() + "Cr";
         }
         else
         {
             lblBalanceTotal.Text = decBalanceTotal.ToString() + "Dr";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("AGWREP03:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Gridview cell value changed , doing basic calculations and checking invalid entries
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvPaymentVoucher_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1 && e.ColumnIndex != -1)
                {
                    TotalAmount();

                    if (dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value.ToString() != string.Empty)
                    {

                        if (dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value == null || dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value.ToString() == string.Empty)
                        {
                            dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(1);
                        }

                    }
                    AccountGroupBll bllAccountGroup = new AccountGroupBll();
                    AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
                    if (dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value != null && dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value.ToString().Trim() != string.Empty)
                    {
                        if (dgvPaymentVoucher.CurrentCell.ColumnIndex == dgvPaymentVoucher.CurrentRow.Cells["dgvcmbAccountLedger"].ColumnIndex)
                        {

                            /*************Remove partybalance while changing the ledger ************/
                            if (inUpdatingRowIndexForPartyRemove != -1)
                            {
                                int inTableRowCount = dtblPartyBalance.Rows.Count;
                                for (int inJ = 0; inJ < inTableRowCount; inJ++)
                                {
                                    if (dtblPartyBalance.Rows.Count == inJ)
                                    {
                                        break;
                                    }
                                    if (Convert.ToDecimal(dtblPartyBalance.Rows[inJ]["ledgerId"].ToString()) == decUpdatingLedgerForPartyremove)
                                    {
                                        if (dtblPartyBalance.Rows[inJ]["PartyBalanceId"].ToString() != "0")
                                        {
                                            arrlstOfDeletedPartyBalanceRow.Add(dtblPartyBalance.Rows[inJ]["PartyBalanceId"]);
                                        }
                                        dtblPartyBalance.Rows.RemoveAt(inJ);
                                        inJ--;
                                    }
                                }
                                dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = string.Empty;
                                decUpdatingLedgerForPartyremove = 0;
                                inUpdatingRowIndexForPartyRemove = -1;
                            }
                            /*************************************************************************/
                            decimal decLedgerId = Convert.ToDecimal(dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbAccountLedger"].Value.ToString());
                            bool IsBankAccount = bllAccountGroup.AccountGroupwithLedgerId(decLedgerId);
                            decimal decI = Convert.ToDecimal(bllAccountLedger.AccountGroupIdCheck(dgvPaymentVoucher.CurrentRow.Cells["dgvcmbAccountLedger"].FormattedValue.ToString()));
                            if (decI > 0)//to make amount and currency read only when party is choosen as ledger
                            {
                                dgvPaymentVoucher.CurrentRow.Cells["dgvtxtAmount"].ReadOnly = true;
                                dgvPaymentVoucher.CurrentRow.Cells["dgvtxtAmount"].Value = string.Empty;
                                dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(1);
                                dgvPaymentVoucher.CurrentRow.Cells["dgvcmbCurrency"].ReadOnly = true;
                            }
                            else
                            {
                                dgvPaymentVoucher.CurrentRow.Cells["dgvtxtAmount"].ReadOnly = false;
                                SettingsBll BllSettings = new SettingsBll();
                                if (BllSettings.SettingsStatusCheck("MultiCurrency") == "Yes")
                                {
                                    dgvcmbCurrency.ReadOnly = false;
                                }
                                else
                                {
                                    dgvcmbCurrency.ReadOnly = true;

                                }
                            }
                        }
                    }
                    CheckColumnMissing();
                    DateValidation objVal = new DateValidation();
                    TextBox txtDate1 = new TextBox();
                    if (dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value != null)
                    {

                        txtDate1.Text = dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value.ToString();
                        bool isDate = objVal.DateValidationFunction(txtDate1);
                        if (isDate)
                        {
                            dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = txtDate1.Text;
                        }
                        else
                        {
                            dgvPaymentVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = PublicVariables._dtCurrentDate.ToString("dd-MMM-yyyy");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PV48:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to fill master grid
 /// </summary>
 public void GridFill()
 {
     try
     {
         List<DataTable> ListObj = new List<DataTable>();
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         if (cmbGroupUnderSearch.Text.Trim() == string.Empty)
         {
             cmbGroupUnderSearch.Text = "All";
         }
         ListObj = bllAccountGroup.AccountGroupSearch(txtAccountGroupNameSearch.Text.Trim(), cmbGroupUnderSearch.Text);
         dgvAccountGroup.DataSource = ListObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("AG1:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to check wheteher cash or bank is selected
 /// </summary>
 public void CheckWhetherBankOrCash()
 {
     try
     {
         //----- To make readonly txtChequeNo and txtChequeDate if selected ledger group is cash-----//
         if (cmbCashOrBank.SelectedValue != null && cmbCashOrBank.SelectedValue.ToString() != string.Empty)
         {
             decimal decLedger = Convert.ToDecimal(cmbCashOrBank.SelectedValue.ToString());
             bool isBankAcocunt = false;
             AccountGroupBll bllAccountGroup = new AccountGroupBll();
             List<DataTable> ListObj = new List<DataTable>();
             ListObj = bllAccountGroup.CheckWheatherLedgerUnderCash();
             //-------- Checking whether the selected legder is under bank----------//
             foreach (DataRow dr in ListObj[0].Rows)
             {
                 string str = dr.ItemArray[0].ToString();
                 if (decLedger == Convert.ToDecimal(dr.ItemArray[0].ToString()))
                 {
                     isBankAcocunt = true;
                 }
             }
             if (isBankAcocunt)
             {
                 txtCheckNo.Enabled = false;
                 txtChequeDate.Enabled = false;
                 dtpCheckDate.Enabled = false;
                 txtCheckNo.Clear();
             }
             else
             {
                 txtCheckNo.Enabled = true;
                 txtChequeDate.Enabled = true;
                 dtpCheckDate.Enabled = true;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("AP17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 ///Function to fill acoountgroup combobox
 /// </summary>  
 public void AccountGroupComboFill()
 {
     try
     {
         AccountGroupBll bllAccountGroup = new AccountGroupBll();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllAccountGroup.AccountGroupViewAllComboFillForAccountLedger();
         cmbGroup.DataSource = ListObj[0];
         cmbGroup.ValueMember = "accountGroupId";
         cmbGroup.DisplayMember = "accountGroupName";
     }
     catch (Exception ex)
     {
         MessageBox.Show("AL8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Call the totalamount,SlNo,InvalidEntry functions to do the all are the process even if change one value of the grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvContraVoucher_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                AccountGroupBll bllAccountGroup = new AccountGroupBll();
                if (e.RowIndex != -1 && e.ColumnIndex != -1)
                {
                    if (dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbBankorCashAccount"].Value != null && dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbBankorCashAccount"].Value.ToString() != "")
                    {
                        if (dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value == null || dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value.ToString() == "")
                        {
                            dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbCurrency"].Value = Convert.ToDecimal(1);//PublicVariables._decCurrencyId;
                        }
                    }
                    TotalAmount();
                    SlNo();

                    if (dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbBankorCashAccount"].Value != null)
                    {

                        decimal decLedger = Convert.ToDecimal(dgvContraVoucher.Rows[e.RowIndex].Cells["dgvcmbBankorCashAccount"].Value.ToString());
                        isBankAcocunt = bllAccountGroup.AccountGroupwithLedgerId(decLedger);
                        if (isBankAcocunt)
                        {
                            dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].ReadOnly = false;
                            dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeNo"].ReadOnly = false;
                        }
                        else
                        {
                            dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].ReadOnly = true;
                            dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeNo"].ReadOnly = true;
                            dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = string.Empty;
                            dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeNo"].Value = string.Empty;

                        }
                    }
                    CheckColumnMissing(e);
                    if (!dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].ReadOnly)
                    {
                        DateValidation objVal = new DateValidation();
                        TextBox txtDate = new TextBox();
                        if (dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value != null)
                        {

                            txtDate.Text = dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value.ToString();
                            bool isDate = objVal.DateValidationFunction(txtDate);
                            if (isDate)
                            {
                                dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = txtDate.Text;
                            }
                            else
                            {
                                dgvContraVoucher.Rows[e.RowIndex].Cells["dgvtxtChequeDate"].Value = PublicVariables._dtCurrentDate.ToString("dd-MMM-yyyy");
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CV:42" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to fill the report in grid
        /// </summary>
        public void GridFill()
        {
            decimal decBalanceTotal = 0;
            try
            {
                AccountGroupBll bllAccountGroup = new AccountGroupBll();
                List<DataTable> ListObj = new List<DataTable>();
                ListObj = bllAccountGroup.AccountGroupWiseReportViewAll(decAccountGroupId, Convert.ToDateTime(txtFromDate.Text), Convert.ToDateTime(txtToDate.Text));
                if (decAccountGroupId == 6)
                {
                    FinancialStatementBll bllFinancialStatement = new FinancialStatementBll();
                    CalculationMethod();
                    decimal dcOpeninggStock = bllFinancialStatement.StockValueGetOnDate(PublicVariables._dtFromDate, calculationMethod, true, true);
                    dcOpeninggStock = Math.Round(dcOpeninggStock, PublicVariables._inNoOfDecimalPlaces);
                    int inRowCount = ListObj[0].Rows.Count;
                    DataRow dr = ListObj[0].NewRow();
                    dr["SlNo"] = inRowCount+1;
                    dr["accountGroupId"] = -2;
                    dr["ledgerId"] = 0;
                    dr["name"] = "Opening Stock";
                    if (dcOpeninggStock >= 0)
                    {
                        dr["OpeningBalance"] = dcOpeninggStock + "Dr";
                        dr["Balance"] = dcOpeninggStock + "Dr";
                    }
                    else
                    {
                        dr["OpeningBalance"] = dcOpeninggStock + "Cr";
                        dr["Balance"] = dcOpeninggStock + "Cr";
                    }
                    dr["debit"] = Math.Round(Convert.ToDecimal(0.00000), PublicVariables._inNoOfDecimalPlaces).ToString()+".00" ;
                    dr["credit"] = Math.Round(Convert.ToDecimal(0.00000), PublicVariables._inNoOfDecimalPlaces).ToString()+".00";
                    dr["balance1"] = dcOpeninggStock;
                    ListObj[0].Rows.InsertAt(dr, inRowCount);
                }
                dgvAccountGroupWiseReport.DataSource = ListObj[0];
                if (ListObj[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dgvAccountGroupWiseReport.RowCount; i++)
                    {
                        decBalanceTotal += Convert.ToDecimal(dgvAccountGroupWiseReport.Rows[i].Cells["balance1"].Value.ToString());

                    }
                }
                if (decBalanceTotal < 0)
                {
                    decBalanceTotal = -1 * decBalanceTotal;
                    lblBalanceTotal.Text = decBalanceTotal.ToString() + "Cr";
                }
                else
                {
                    lblBalanceTotal.Text = decBalanceTotal.ToString()+"Dr";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("AGWREP02:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }