/// <summary>
        /// Function to fill Datagridview
        /// </summary>
        public void FillGrid()
        {
            try
            {
                if (!isFormLoad)
                {
                    DateValidation objValidation = new DateValidation();
                    objValidation.DateValidationFunction(txtToDate);
                    if (txtToDate.Text == string.Empty)
                        txtToDate.Text = PublicVariables._dtToDate.ToString("dd-MMM-yyyy");
                    Font newFont = new Font(dgvReport.Font, FontStyle.Bold);
                    CurrencyInfo InfoCurrency = new CurrencyInfo();
                    CurrencyBll BllCurrency = new CurrencyBll();
                    InfoCurrency = BllCurrency.CurrencyView(1);
                    int inDecimalPlaces = InfoCurrency.NoOfDecimalPlaces;
                    dgvReport.Rows.Clear();
                    FinancialStatementBll bllFinancialStatement = new FinancialStatementBll();

                   // FinancialStatementSP SpFinance = new FinancialStatementSP();
                    DataSet DsetBalanceSheet = new DataSet();
                    DataTable dtbl = new DataTable();
                    SettingsInfo InfoSettings = new SettingsInfo();
                    SettingsBll BllSettings = new SettingsBll();
                    //--------------- Selection Of Calculation Method According To Settings ------------------//
                    if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "FIFO")
                    {
                        calculationMethod = "FIFO";
                    }
                    else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Average Cost")
                    {
                        calculationMethod = "Average Cost";
                    }
                    else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "High Cost")
                    {
                        calculationMethod = "High Cost";
                    }
                    else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Low Cost")
                    {
                        calculationMethod = "Low Cost";
                    }
                    else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Last Purchase Rate")
                    {
                        calculationMethod = "Last Purchase Rate";
                    }
                    DsetBalanceSheet = bllFinancialStatement.BalanceSheet(PublicVariables._dtFromDate, DateTime.Parse(txtToDate.Text));
                    //------------------- Asset -------------------------------//
                    dtbl = DsetBalanceSheet.Tables[0];
                    foreach (DataRow rw in dtbl.Rows)
                    {
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = rw["Name"].ToString();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Value = rw["Balance"].ToString();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["GroupId1"].Value = rw["ID"].ToString();
                    }
                    decimal dcTotalAsset = 0;
                    if (dtbl.Rows.Count > 0)
                    {
                        dcTotalAsset = decimal.Parse(dtbl.Compute("Sum(Balance)", string.Empty).ToString());
                    }
                    //------------------------ Liability ---------------------//
                    dtbl = new DataTable();
                    dtbl = DsetBalanceSheet.Tables[1];
                    int index = 0;
                    foreach (DataRow rw in dtbl.Rows)
                    {
                        if (index < dgvReport.Rows.Count)
                        {
                            dgvReport.Rows[index].Cells["dgvtxtLiability"].Value = rw["Name"].ToString();
                            dgvReport.Rows[index].Cells["Amount2"].Value = rw["Balance"].ToString();
                            dgvReport.Rows[index].Cells["GroupId2"].Value = rw["ID"].ToString();
                        }
                        else
                        {
                            dgvReport.Rows.Add();
                            dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = rw["Name"].ToString();
                            dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Value = rw["Balance"].ToString();
                            dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["GroupId2"].Value = rw["ID"].ToString();
                        }
                        index++;
                    }
                    decimal dcTotalLiability = 0;
                    if (dtbl.Rows.Count > 0)
                    {
                        dcTotalLiability = decimal.Parse(dtbl.Compute("Sum(Balance)", string.Empty).ToString());
                    }
                    decimal dcClosingStock = bllFinancialStatement.StockValueGetOnDate(Convert.ToDateTime(txtToDate.Text), calculationMethod, false, false);
                    dcClosingStock = Math.Round(dcClosingStock, inDecimalPlaces);
                    //---------------------Opening Stock---------------------------------------------------------------------------------------------------------------
                    decimal dcOpeninggStock = bllFinancialStatement.StockValueGetOnDate(PublicVariables._dtFromDate, calculationMethod, true, true);
                    decimal dcProfit = 0;
                    DataSet dsetProfitAndLoss = new DataSet();
                    dsetProfitAndLoss = bllFinancialStatement.ProfitAndLossAnalysisUpToaDateForBalansheet(PublicVariables._dtFromDate, DateTime.Parse(txtToDate.Text));
                    DataTable dtblProfit = new DataTable();
                    dtblProfit = dsetProfitAndLoss.Tables[0];
                    for (int i = 0; i < dsetProfitAndLoss.Tables.Count; ++i)
                    {
                        dtbl = dsetProfitAndLoss.Tables[i];
                        decimal dcSum = 0;
                        if (i == 0 || (i % 2) == 0)
                        {
                            if (dtbl.Rows.Count > 0)
                            {
                                dcSum = decimal.Parse(dtbl.Compute("Sum(Debit)", string.Empty).ToString());
                                dcProfit = dcProfit - dcSum;
                            }
                        }
                        else
                        {
                            if (dtbl.Rows.Count > 0)
                            {
                                dcSum = decimal.Parse(dtbl.Compute("Sum(Credit)", string.Empty).ToString());
                                dcProfit = dcProfit + dcSum;
                            }
                        }
                    }
                    decimal decCurrentProfitLoss = 0;
                    decCurrentProfitLoss = dcProfit + (dcClosingStock - dcOpeninggStock);
                    decimal dcProfitOpening = 0;
                    DataSet dsetProfitAndLossOpening = new DataSet();
                    dsetProfitAndLossOpening = bllFinancialStatement.ProfitAndLossAnalysisUpToaDateForPreviousYears(PublicVariables._dtFromDate);
                    DataTable dtblProfitOpening = new DataTable();
                    dtblProfitOpening = dsetProfitAndLossOpening.Tables[0];
                    for (int i = 0; i < dsetProfitAndLossOpening.Tables.Count; ++i)
                    {
                        dtbl = dsetProfitAndLossOpening.Tables[i];
                        decimal dcSum = 0;
                        if (i == 0 || (i % 2) == 0)
                        {
                            if (dtbl.Rows.Count > 0)
                            {
                                dcSum = decimal.Parse(dtbl.Compute("Sum(Debit)", string.Empty).ToString());
                                dcProfitOpening = dcProfitOpening - dcSum;
                            }
                        }
                        else
                        {
                            if (dtbl.Rows.Count > 0)
                            {
                                dcSum = decimal.Parse(dtbl.Compute("Sum(Credit)", string.Empty).ToString());
                                dcProfitOpening = dcProfitOpening + dcSum;
                            }
                        }
                    }
                    DataTable dtblProfitLedgerOpening = new DataTable();
                    dtblProfitLedgerOpening = DsetBalanceSheet.Tables[3];
                    decimal decProfitLedgerOpening = 0;
                    foreach (DataRow dRow in dtblProfitLedgerOpening.Rows)
                    {
                        decProfitLedgerOpening += decimal.Parse(dRow["Balance"].ToString());
                    }
                    DataTable dtblProf = new DataTable();
                    dtblProf = DsetBalanceSheet.Tables[2];
                    decimal decProfitLedger = 0;
                    if (dtblProf.Rows.Count > 0)
                    {
                        decProfitLedger = decimal.Parse(dtblProf.Compute("Sum(Balance)", string.Empty).ToString());
                    }
                    decimal decTotalProfitAndLoss = 0;
                    if (dcProfitOpening >= 0)
                    {
                        decTotalProfitAndLoss = decProfitLedger;
                    }
                    else if (dcProfitOpening < 0)
                    {
                        decTotalProfitAndLoss = decProfitLedger;
                    }
                    index = 0;
                    if (dcClosingStock >= 0)
                    {
                        //---------- Asset ----------//
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = "Closing Stock";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Value = Math.Round(dcClosingStock, inDecimalPlaces);
                        dcTotalAsset += dcClosingStock;
                    }
                    else
                    {
                        //--------- Liability ---------//
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = "Closing Stock";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Value = -(Math.Round(dcClosingStock, inDecimalPlaces));
                        dcTotalLiability += -dcClosingStock;
                    }
                    dgvReport.Rows.Add();
                    decimal decOpeningOfProfitAndLoss = decProfitLedgerOpening + dcProfitOpening;
                    decimal decTotalProfitAndLossOverAll = decTotalProfitAndLoss + decOpeningOfProfitAndLoss + decCurrentProfitLoss;
                    if (decTotalProfitAndLossOverAll <= 0)
                    {
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = "----------------------------------------";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                        foreach (DataRow dRow in dtblProf.Rows)
                        {
                            if (dRow["Name"].ToString() == "Profit And Loss Account")
                            {
                                dgvReport.Rows.Add();
                                dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                                dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.DarkSlateGray;
                                dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = dRow["Name"].ToString();
                                if (decCurrentProfitLoss < 0)
                                {
                                    decCurrentProfitLoss = decCurrentProfitLoss * -1;
                                }
                                dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Value =Math.Round(decTotalProfitAndLoss + decCurrentProfitLoss,PublicVariables._inNoOfDecimalPlaces);
                                dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["GroupId1"].Value = dRow["ID"].ToString();
                            }
                        }
                        //-------------- Asset ---------------//
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = "Profit And Loss (Opening)";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Value = Math.Round(decTotalProfitAndLoss, PublicVariables._inNoOfDecimalPlaces);
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Style.ForeColor = Color.DarkSlateGray;
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Style.ForeColor = Color.DarkSlateGray;
                        //-------------- Asset ---------------//
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = "Current Period";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Value = Math.Round(decCurrentProfitLoss, PublicVariables._inNoOfDecimalPlaces);
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Style.ForeColor = Color.DarkSlateGray;
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Style.ForeColor = Color.DarkSlateGray;
                        dcTotalAsset = dcTotalAsset + (decCurrentProfitLoss + decTotalProfitAndLoss);
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = "----------------------------------------";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                    }
                    else if (decTotalProfitAndLossOverAll > 0)
                    {
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = "----------------------------------------";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                        foreach (DataRow dRow in dtblProf.Rows)
                        {
                            if (dRow["Name"].ToString() == "Profit And Loss Account")
                            {
                                dgvReport.Rows.Add();
                                dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                                dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.DarkSlateGray;
                                dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = dRow[1].ToString();
                                dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Value =Math.Round(decTotalProfitAndLoss + decCurrentProfitLoss,PublicVariables._inNoOfDecimalPlaces);
                                dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["GroupId2"].Value = dRow[0].ToString();
                            }
                        }
                        //------------ Liability ------------//
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = "Profit And Loss (Opening)";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Value = Math.Round(decTotalProfitAndLoss, inDecimalPlaces);
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Style.ForeColor = Color.DarkSlateGray;
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Style.ForeColor = Color.DarkSlateGray;
                        dcTotalLiability += decOpeningOfProfitAndLoss;
                        //------------ Liability ------------//
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = "Current Period";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Value = Math.Round(decCurrentProfitLoss, inDecimalPlaces);
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Style.ForeColor = Color.DarkSlateGray;
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Style.ForeColor = Color.DarkSlateGray;
                        dcTotalLiability = dcTotalLiability + (decCurrentProfitLoss + decTotalProfitAndLoss); //dcProfit;
                        dgvReport.Rows.Add();
                        dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = "----------------------------------------";
                        dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                    }
                    dgvReport.Rows.Add();
                    decimal dcDiffAsset = 0;
                    decimal dcDiffLiability = 0;
                    decimal dcTotalValue = dcTotalAsset;
                    if (dcTotalAsset != dcTotalLiability)
                    {
                        if (dcTotalAsset > dcTotalLiability)
                        {
                            //--------------- Liability exceeds so in asset side ----------------//
                            dgvReport.Rows.Add();
                            dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = "Difference";
                            dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Value = Math.Round((dcTotalAsset - dcTotalLiability), inDecimalPlaces);
                            dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                            dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.DarkRed;
                            dcDiffLiability = dcTotalAsset - dcTotalLiability;
                        }
                        else
                        {
                            //--------------- Asset exceeds so in liability side ----------------//
                            dgvReport.Rows.Add();
                            dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = "Difference";
                            dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Value = Math.Round((dcTotalLiability - dcTotalAsset), inDecimalPlaces); ;
                            dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                            dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.DarkRed;
                            dcDiffAsset = dcTotalLiability - dcTotalAsset;
                        }
                    }
                    dgvReport.Rows.Add();
                    dgvReport.Rows.Add();
                    dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Value = "__________________________";
                    dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Value = "__________________________";
                    dgvReport.Rows.Add();
                    dgvReport.Rows[dgvReport.Rows.Count - 1].DefaultCellStyle.Font = newFont;
                    dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtLiability"].Value = "Total";
                    dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["dgvtxtAsset"].Value = "Total";
                    dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount1"].Value = Math.Round((dcTotalAsset + dcDiffAsset), inDecimalPlaces);
                    dgvReport.Rows[dgvReport.Rows.Count - 1].Cells["Amount2"].Value = Math.Round((dcTotalLiability + dcDiffLiability), inDecimalPlaces);
                    if (dgvReport.Columns.Count > 0)
                    {
                        dgvReport.Columns["Amount1"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dgvReport.Columns["Amount2"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    }
                    decPrintOrNot = dcTotalAsset + dcDiffAsset;
                    decPrintOrNot1 = dcTotalLiability + dcDiffLiability;
                    if (inCurrenRowIndex >= 0 && dgvReport.Rows.Count > 0 && inCurrenRowIndex < dgvReport.Rows.Count)
                    {
                        if (dgvReport.Rows[inCurrenRowIndex].Cells[inCurentcolIndex].Visible)
                        {
                            dgvReport.CurrentCell = dgvReport.Rows[inCurrenRowIndex].Cells[inCurentcolIndex];
                        }
                        if (dgvReport.CurrentCell != null && dgvReport.CurrentCell.Visible)
                            dgvReport.CurrentCell.Selected = true;
                    }
                    inCurrenRowIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("BS :1" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Function to fill Datagridview after calculation
        /// </summary>
        public void GridFill()
        {
            try
            {
                if (!isFormLoad)
                {
                    string calculationMethod = string.Empty;
                    SettingsInfo InfoSettings = new SettingsInfo();
                    SettingsBll BllSettings = new SettingsBll();
                    //--------------- Selection Of Calculation Method According To Settings ------------------//
                    if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "FIFO")
                    {
                        calculationMethod = "FIFO";
                    }
                    else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Average Cost")
                    {
                        calculationMethod = "Average Cost";
                    }
                    else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "High Cost")
                    {
                        calculationMethod = "High Cost";
                    }
                    else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Low Cost")
                    {
                        calculationMethod = "Low Cost";
                    }
                    else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Last Purchase Rate")
                    {
                        calculationMethod = "Last Purchase Rate";
                    }
                    FinancialStatementBll bllFinancialStatement = new FinancialStatementBll();

                    DataTable dtbl1 = new DataTable();
                    CurrencyInfo InfoCurrency = new CurrencyInfo();
                    CurrencyBll BllCurrency = new CurrencyBll();
                    int inDecimalPlaces = InfoCurrency.NoOfDecimalPlaces;
                    decimal dcClosingStock = bllFinancialStatement.StockValueGetOnDate(Convert.ToDateTime(txtTodate.Text), calculationMethod, false, false);
                    dcClosingStock = Math.Round(dcClosingStock, inDecimalPlaces);
                    //---------------------Opening Stock-----------------------
                    decimal dcOpeninggStock = bllFinancialStatement.StockValueGetOnDate(PublicVariables._dtFromDate, calculationMethod, true, true);
                    decimal dcProfit = 0;
                    DataSet dsetProfitAndLoss = new DataSet();
                    dsetProfitAndLoss = bllFinancialStatement.ProfitAndLossAnalysisUpToaDateForBalansheet(PublicVariables._dtFromDate, DateTime.Parse(txtTodate.Text));
                    DataTable dtblProfit = new DataTable();
                    dtblProfit = dsetProfitAndLoss.Tables[0];
                    for (int i = 0; i < dsetProfitAndLoss.Tables.Count; ++i)
                    {
                        dtbl1 = dsetProfitAndLoss.Tables[i];
                        decimal dcSum = 0;
                        if (i == 0 || (i % 2) == 0)
                        {
                            if (dtbl1.Rows.Count > 0)
                            {
                                dcSum = decimal.Parse(dtbl1.Compute("Sum(Debit)", string.Empty).ToString());
                            }
                        }
                        else
                        {
                            if (dtbl1.Rows.Count > 0)
                            {
                                dcSum = decimal.Parse(dtbl1.Compute("Sum(Credit)", string.Empty).ToString());
                            }
                        }
                    }
                    DateValidation objValidation = new DateValidation();
                    objValidation.DateValidationFunction(txtTodate);
                    if (txtTodate.Text == string.Empty)
                        txtTodate.Text = PublicVariables._dtToDate.ToString("dd-MMM-yyyy");
                    Font newFont = new Font(dgvTrailBalance.Font, FontStyle.Bold);

                    DataSet DsetTrailbalance = new DataSet();
                    DataTable dtbl = new DataTable();
                    decimal dcTotalCredit = 0;
                    decimal dcTotalDebit = 0;
                    DateValidation objvalidation = new DateValidation();
                    objvalidation.DateValidationFunction(txtFromDate);
                    if (txtFromDate.Text == string.Empty)
                    {
                        txtFromDate.Text = PublicVariables._dtFromDate.ToString("dd-MMM-yyyy");
                    }
                    objvalidation.DateValidationFunction(txtTodate);
                    if (txtTodate.Text == string.Empty)
                    {
                        txtTodate.Text = PublicVariables._dtToDate.ToString("dd-MMM-yyyy");
                    }
                    DataTable dtblTrail = new DataTable();
                    DataTable dtblTrail1 = new DataTable();
                    DataTable dtblProfitAndLossAcc = new DataTable();
                    DataTable dtblProfitAndLossAcc1 = new DataTable();
                    DataSet dsTrial = new DataSet();
                    Font newfont = new Font(dgvTrailBalance.Font, FontStyle.Bold);

                    dgvTrailBalance.Rows.Clear();
                    dsTrial = bllFinancialStatement.TrialBalance(DateTime.Parse(txtFromDate.Text), DateTime.Parse(txtTodate.Text), 0);
                    dtblTrail = dsTrial.Tables[0];
                    dtblProfitAndLossAcc = dsTrial.Tables[1];
                    if (dgvTrailBalance.RowCount > 0)
                    {
                        dcTotalCredit = decimal.Parse(dtblTrail.Compute("Sum(credit)", string.Empty).ToString());
                        dcTotalDebit = decimal.Parse(dtblTrail.Compute("Sum(debit)", string.Empty).ToString());
                    }
                    for (int i = 0; i < dtblTrail.Rows.Count; ++i)
                    {
                        dgvTrailBalance.Rows.Add();
                        if (Convert.ToDecimal(dtblTrail.Rows[i]["accountGroupId"].ToString()) != 6)
                        {
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtAccountGroupId"].Value = dtblTrail.Rows[i]["accountGroupId"];
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["accountGroupName"].Value = dtblTrail.Rows[i]["name"];
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["openingBalance"].Value = dtblTrail.Rows[i]["OpeningBalance"];
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtBalance"].Value = dtblTrail.Rows[i]["Balance"];
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["credit"].Value = dtblTrail.Rows[i]["credit"];
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["debit"].Value = dtblTrail.Rows[i]["debit"];
                            dcTotalCredit += decimal.Parse(dtblTrail.Rows[i]["credit"].ToString());
                            dcTotalDebit += decimal.Parse(dtblTrail.Rows[i]["debit"].ToString());
                        }
                        else
                        {
                            decimal decOpBalance = dcOpeninggStock + Convert.ToDecimal(dtblTrail.Rows[i]["OpBalance"].ToString());
                            decimal decBalance = dcOpeninggStock + Convert.ToDecimal(dtblTrail.Rows[i]["Balance1"].ToString());
                            string strOpBalance = string.Empty;
                            string strBalance = string.Empty;
                            if (decOpBalance < 0)
                            {
                                strOpBalance = Math.Round(decOpBalance, PublicVariables._inNoOfDecimalPlaces).ToString() + "Cr";
                            }
                            else
                            {
                                strOpBalance = Math.Round(decOpBalance, PublicVariables._inNoOfDecimalPlaces).ToString() + "Dr";
                            }
                            if (decBalance < 0)
                            {
                                strBalance = Math.Round(decBalance, PublicVariables._inNoOfDecimalPlaces).ToString() + "Cr";
                            }
                            else
                            {
                                strBalance = Math.Round(decBalance, PublicVariables._inNoOfDecimalPlaces).ToString() + "Dr";
                            }
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtAccountGroupId"].Value = dtblTrail.Rows[i]["accountGroupId"];
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["accountGroupName"].Value = dtblTrail.Rows[i]["name"];
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["openingBalance"].Value = strOpBalance;
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtBalance"].Value = strBalance;
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["credit"].Value = dtblTrail.Rows[i]["credit"];
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["debit"].Value = dtblTrail.Rows[i]["debit"];
                            dcTotalCredit += decimal.Parse(dtblTrail.Rows[i]["credit"].ToString());
                            dcTotalDebit += decimal.Parse(dtblTrail.Rows[i]["debit"].ToString());
                        }
                    }
                    decimal OpeningProfit;
                    dtblProfitAndLossAcc1 = dsTrial.Tables[2];
                    if (dgvTrailBalance.RowCount > 0)
                    {
                        decimal dcTotalCredit1 = decimal.Parse(dtblTrail.Compute("Sum(credit)", string.Empty).ToString());
                        decimal dcTotalDebit1 = decimal.Parse(dtblTrail.Compute("Sum(debit)", string.Empty).ToString());
                        OpeningProfit = dcTotalCredit1 + dcTotalDebit1;
                    }
                    DataSet DsetBalanceSheet = new DataSet();
                    DsetBalanceSheet = bllFinancialStatement.BalanceSheet(PublicVariables._dtFromDate, DateTime.Parse(txtTodate.Text));
                    DataTable dtblProf = new DataTable();
                    decimal dcProfitOpening = 0;
                    dtblProf = DsetBalanceSheet.Tables[2];
                    decimal decProfitLedger = 0;
                    if (dtblProf.Rows.Count > 0)
                    {
                        decProfitLedger = decimal.Parse(dtblProf.Compute("Sum(Balance)", string.Empty).ToString());
                    }
                    DataTable dtblProfitLedgerOpening = new DataTable();
                    dtblProfitLedgerOpening = DsetBalanceSheet.Tables[3];
                    decimal decProfitLedgerOpening = 0;
                    foreach (DataRow dRow in dtblProfitLedgerOpening.Rows)
                    {
                        decProfitLedgerOpening += decimal.Parse(dRow["Balance"].ToString());
                    }
                    decimal decTotalProfitAndLoss = decProfitLedger;
                    decimal OpeningProfit1;
                    decimal openingBalance;
                    dgvTrailBalance.Rows.Add();
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtSlNo"].Value = "  ";
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["accountGroupName"].Value = "Profit and Loss";
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtAccountGroupId"].Value = "0";
                    openingBalance = Convert.ToDecimal(dtblProfitAndLossAcc.Rows[0]["OpeningBalance"].ToString());
                    {
                        if (openingBalance > 0)
                        {
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["openingBalance"].Value = openingBalance + "Dr";
                        }
                        else
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["openingBalance"].Value = (-1) * openingBalance + "Cr";
                    }
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtSlNo"].Value = dgvTrailBalance.Rows.Count.ToString();
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.Blue;
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].DefaultCellStyle.Font = new Font(dgvTrailBalance.Font, FontStyle.Regular);
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["credit"].Value = dtblProfitAndLossAcc.Rows[0]["credit"].ToString();
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["debit"].Value = dtblProfitAndLossAcc.Rows[0]["debit"].ToString();
                    OpeningProfit1 = (Convert.ToDecimal(dtblProfitAndLossAcc.Rows[0]["OpeningBalance"].ToString())) + Convert.ToDecimal(dtblProfitAndLossAcc.Rows[0]["debit"].ToString()) - Convert.ToDecimal(dtblProfitAndLossAcc.Rows[0]["credit"].ToString());
                    {
                        if (OpeningProfit1 > 0)
                        {
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtBalance"].Value = decTotalProfitAndLoss + dcProfit + "Dr";
                        }
                        else
                            dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtBalance"].Value = (-1) * decTotalProfitAndLoss - dcProfit + "Cr";
                    };
                    dcTotalCredit = dcTotalCredit + Convert.ToDecimal(dtblProfitAndLossAcc.Rows[0]["credit"].ToString());
                    dcTotalDebit = dcTotalDebit + Convert.ToDecimal(dtblProfitAndLossAcc.Rows[0]["debit"].ToString());
                    //=================================Net profit and NetLoss transation for previousyear==============
                    decimal decprofitLossbal = 0;
                    decimal decbalance = 0;
                    decimal decProfitAndLossOfPrevious = decProfitLedgerOpening;
                    dgvTrailBalance.Rows.Add();
                    if (dcProfitOpening > 0)
                    {
                        dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["openingBalance"].Value = dcProfitOpening + "Dr";
                        decprofitLossbal = dcProfitOpening;
                    }
                    if (dcProfitOpening <= 0)
                    {
                        dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["openingBalance"].Value = (-1) * dcProfitOpening + "Cr";
                        decprofitLossbal = dcProfitOpening;
                    }
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtSlNo"].Value = "  ";
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["accountGroupName"].Value = "Profit and Loss Opening";
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["openingBalance"].Value = "0.00Dr";
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.Brown;
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].DefaultCellStyle.Font = new Font(dgvTrailBalance.Font, FontStyle.Regular);
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtAccountGroupId"].Value = "0";
                    if (decProfitAndLossOfPrevious > 0)
                    {
                        dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["debit"].Value = decProfitAndLossOfPrevious;
                        dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["credit"].Value = "0.00";
                        decbalance = (decProfitAndLossOfPrevious);
                    }
                    if (decProfitAndLossOfPrevious <= 0)
                    {
                        dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["credit"].Value = (-1) * (decProfitAndLossOfPrevious);
                        dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["debit"].Value = "0.00";
                        decbalance = ((decProfitAndLossOfPrevious));
                    }
                    if (decbalance >= 0)
                    {
                        dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtBalance"].Value = decbalance + decprofitLossbal + "Dr";
                    }
                    if (decbalance < 0)
                    {
                        decbalance = -(decbalance);
                        dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtBalance"].Value = decbalance + decprofitLossbal + "Cr";
                    }
                    dgvTrailBalance.Rows.Add();
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtSlNo"].Value = "  ";
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["accountGroupName"].Value = "Total:";
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["dgvtxtSlNo"].Value = string.Empty;
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.Red;
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].DefaultCellStyle.Font = new Font(dgvTrailBalance.Font, FontStyle.Bold);
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["credit"].Value = dcTotalCredit;
                    dgvTrailBalance.Rows[dgvTrailBalance.Rows.Count - 1].Cells["debit"].Value = dcTotalDebit;
                    if (dgvTrailBalance.Columns.Count > 0)
                    {
                        dgvTrailBalance.Columns["credit"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dgvTrailBalance.Columns["debit"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dgvTrailBalance.Columns["openingBalance"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dgvTrailBalance.Columns["dgvtxtBalance"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    }
                    dgvTrailBalance.ScrollBars = ScrollBars.Both;
                    dgvTrailBalance.ClearSelection();
                    if (inCurrenRowIndex > 0 && dgvTrailBalance.Rows.Count > 0 && inCurrenRowIndex < dgvTrailBalance.Rows.Count)
                    {
                        if (dgvTrailBalance.Rows[inCurrenRowIndex].Cells[inCurrentColIndex].Visible)
                        {
                            dgvTrailBalance.CurrentCell = dgvTrailBalance.Rows[inCurrenRowIndex].Cells[inCurrentColIndex];
                        }
                        else
                        {
                            dgvTrailBalance.CurrentCell = dgvTrailBalance.Rows[inCurrenRowIndex].Cells["debit"];
                        }
                        dgvTrailBalance.CurrentCell.Selected = true;
                    }
                    inCurrenRowIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Tb:2" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to fill Datagridview after calculation
 /// </summary>
 public void GridFill()
 {
     try
     {
         if (!isFormLoad)
         {
             DateValidation objValidation = new DateValidation();
             objValidation.DateValidationFunction(txtFundFlowFromDate);
             if (txtFundFlowFromDate.Text == string.Empty)
                 txtFundFlowFromDate.Text = PublicVariables._dtFromDate.ToString("dd-MMM-yyyy");
             objValidation.DateValidationFunction(txtFundflowToDate);
             if (txtFundflowToDate.Text == string.Empty)
                 txtFundflowToDate.Text = PublicVariables._dtToDate.ToString("dd-MMM-yyyy");
             //-------------------------------------First gridfill-------------------------------------//
             DateTime strFromDate = Convert.ToDateTime(txtFundFlowFromDate.Text.ToString());
             DateTime strTodate = Convert.ToDateTime(txtFundflowToDate.Text.ToString());
             FinancialStatementBll bllFinancialStatement = new FinancialStatementBll();
             DataSet dsetFinancial = new DataSet();
             SettingsInfo InfoSettings = new SettingsInfo();
             SettingsBll BllSettings = new SettingsBll();
             //--------------- Selection Of Calculation Method According To Settings ------------------//
             if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "FIFO")
             {
                 strCalculationMethod = "FIFO";
             }
             else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Average Cost")
             {
                 strCalculationMethod = "Average Cost";
             }
             else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "High Cost")
             {
                 strCalculationMethod = "High Cost";
             }
             else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Low Cost")
             {
                 strCalculationMethod = "Low Cost";
             }
             else if (BllSettings.SettingsStatusCheck("StockValueCalculationMethod") == "Last Purchase Rate")
             {
                 strCalculationMethod = "Last Purchase Rate";
             }
             dsetFinancial = bllFinancialStatement.FundFlow(strFromDate, strTodate);
             DataTable dtbl = new DataTable();
             Font newFont = new Font(dgvFundFlow.Font, FontStyle.Bold);
             CurrencyInfo InfoCurrency = new CurrencyInfo();
             CurrencyBll BllCurrency = new CurrencyBll();
             InfoCurrency = BllCurrency.CurrencyView(1);
             int inDecimalPlaces = InfoCurrency.NoOfDecimalPlaces;
             dgvFundFlow.Rows.Clear();
             ////-------------------Source--------------------------------------------------------------
             dtbl = dsetFinancial.Tables[0];
             foreach (DataRow rw in dtbl.Rows)
             {
                 dgvFundFlow.Rows.Add();
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtSource"].Value = rw["Name"].ToString();
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = rw["Balance"].ToString();
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtgroupId1"].Value = rw["ID"].ToString();
             }
             decimal dcTotalAsset = 0;
             if (dtbl.Rows.Count > 0)
             {
                 dcTotalAsset = decimal.Parse(dtbl.Compute("Sum(Balance)", string.Empty).ToString());
             }
             ////-----------------Application------------------------------------------------------------
             dtbl = new DataTable();
             dtbl = dsetFinancial.Tables[1];
             int index = 0;
             foreach (DataRow rw in dtbl.Rows)
             {
                 if (index < dgvFundFlow.Rows.Count)
                 {
                     dgvFundFlow.Rows[index].Cells["dgvtxtApplication"].Value = rw["Name"].ToString();
                     dgvFundFlow.Rows[index].Cells["dgvtxtAmount2"].Value = rw["Balance"].ToString();
                     dgvFundFlow.Rows[index].Cells["dgvtxtgroupId2"].Value = rw["ID"].ToString();
                 }
                 else
                 {
                     dgvFundFlow.Rows.Add();
                     dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtApplication"].Value = rw["Name"].ToString();
                     dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = rw["Balance"].ToString();
                     dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtgroupId2"].Value = rw["ID"].ToString();
                 }
                 index++;
             }
             decimal dcTotalLiability = 0;
             if (dtbl.Rows.Count > 0)
             {
                 dcTotalLiability = Convert.ToDecimal(dtbl.Compute("Sum(Balance)", string.Empty).ToString());
             }
             //-------------------- Closing Stock -----------------------//  With Calculation
             dcClosingStock = bllFinancialStatement.StockValueGetOnDate(Convert.ToDateTime(txtFundflowToDate.Text), strCalculationMethod, false, false);
             dcClosingStock = Math.Round(dcClosingStock, inDecimalPlaces);
             //---------------------Opening Stock-----------------------
             decimal dcOpeninggStock = bllFinancialStatement.StockValueGetOnDate(Convert.ToDateTime(txtFundFlowFromDate.Text), strCalculationMethod, true, false);
             //------------- Profit Or Loss -----------// With Calculation
             decimal dcProfit = 0;
             DataSet dsetProfitAndLoss = new DataSet();
             dsetProfitAndLoss = bllFinancialStatement.ProfitAndLossAnalysisUpToaDateForBalansheet(Convert.ToDateTime(txtFundFlowFromDate.Text), Convert.ToDateTime(txtFundflowToDate.Text));
             DataTable dtblProfit = new DataTable();
             dtblProfit = dsetProfitAndLoss.Tables[0];
             for (int i = 0; i < dsetProfitAndLoss.Tables.Count; ++i)
             {
                 dtbl = dsetProfitAndLoss.Tables[i];
                 decimal dcSum = 0;
                 if (i == 0 || (i % 2) == 0)
                 {
                     if (dtbl.Rows.Count > 0)
                     {
                         dcSum = Convert.ToDecimal(dtbl.Compute("Sum(Debit)", string.Empty).ToString());
                         dcProfit = dcProfit - dcSum;
                     }
                 }
                 else
                 {
                     if (dtbl.Rows.Count > 0)
                     {
                         dcSum = Convert.ToDecimal(dtbl.Compute("Sum(Credit)", string.Empty).ToString());
                         dcProfit = dcProfit + dcSum;
                     }
                 }
             }
             //---------------------NetProfit/NetLoss Calculation--------------------------
             dcProfit = dcProfit + dcClosingStock - dcOpeninggStock;
             if (dcProfit > 0)
             {
                 //------------ Liability ------------//
                 dgvFundFlow.Rows.Add();
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtSource"].Value = "Net Profit";
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = Math.Round(dcProfit, inDecimalPlaces);
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount1"].Style.ForeColor = Color.Green;
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtSource"].Style.ForeColor = Color.Green;
                 //dcTotalLiability += dcProfit;
             }
             else
             {
                 //-------------- Asset ---------------//
                 dgvFundFlow.Rows.Add();
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtApplication"].Value = "Net Loss";
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = -Math.Round(dcProfit, inDecimalPlaces);
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount2"].Style.ForeColor = Color.Red;
                 dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtApplication"].Style.ForeColor = Color.Red;
             }
             if (dcProfit > 0)
             {
                 dcTotalAsset += (dcProfit);
             }
             else
             {
                 dcTotalLiability += (-dcProfit);
             }
             decimal dcTotalValue = dcTotalAsset;
             dgvFundFlow.Rows.Add();
             dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = "_______________________";
             dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = "_______________________";
             dgvFundFlow.Rows.Add();
             dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].DefaultCellStyle.Font = newFont;
             dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtApplication"].Value = "Total";
             dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtSource"].Value = "Total";
             dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount1"].Value = Math.Round((dcTotalAsset), inDecimalPlaces);
             dgvFundFlow.Rows[dgvFundFlow.Rows.Count - 1].Cells["dgvtxtAmount2"].Value = Math.Round((dcTotalLiability), inDecimalPlaces);
             //----------------------------------------Second gridfill----------------------------------------------
             //--------------------------------------Current Assets-------------------------------------------
             Font newFont2 = new Font(dgvFundFlow2.Font, FontStyle.Bold);
             dgvFundFlow2.Rows.Clear();
             dtbl = dsetFinancial.Tables[3];
             decimal decWC = 0;
             foreach (DataRow rw in dtbl.Rows)
             {
                 dgvFundFlow2.Rows.Add();
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtgroupId"].Value = rw["ID"].ToString();
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtParticulars"].Value = rw["Name"].ToString();
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtOpeningBalance"].Value = rw["OpeningBalance"].ToString() + "Dr";
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtop"].Value = rw["OpeningBalance"].ToString();
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtcb"].Value = rw["ClosingBalance"].ToString();
                 decimal decOB = Convert.ToDecimal(rw["OpeningBalance"].ToString());
                 decimal decCB = Convert.ToDecimal(rw["ClosingBalance"].ToString());
                 decCB = decCB + dcClosingStock;
                 if (decCB > 0)
                 {
                     dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtClosingBalance"].Value = Math.Round(decCB, inDecimalPlaces).ToString() + "Dr";
                     dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtcb"].Value = Math.Round(decCB, inDecimalPlaces).ToString();
                 }
                 else
                 {
                     decCB = -1 * decCB;
                     dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtClosingBalance"].Value = Math.Round(decCB, inDecimalPlaces).ToString() + "Dr";
                     dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtcb"].Value = Math.Round(decCB, inDecimalPlaces).ToString();
                 }
                 decWC = decOB - decCB;
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtWorkingCapitalIncrease"].Value = Math.Round(decWC, inDecimalPlaces).ToString();
             }
             //--------------------------------------Current Liability-------------------------------------------
             dtbl = dsetFinancial.Tables[5];
             decimal decWCCL = 0;
             foreach (DataRow rw in dtbl.Rows)
             {
                 dgvFundFlow2.Rows.Add();
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtgroupId"].Value = rw["ID"].ToString();
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtParticulars"].Value = rw["Name"].ToString();
                 decimal decOp = Convert.ToDecimal(rw["OpeningBalance"].ToString());
                 decimal decCb = Convert.ToDecimal(rw["ClosingBalance"].ToString());
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtOpeningBalance"].Value = decOp.ToString() + "Cr";
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtop"].Value = rw["OpeningBalance"].ToString();
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtcb"].Value = rw["ClosingBalance"].ToString();
                 if (decCb > 0)
                 {
                     dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtClosingBalance"].Value = decCb.ToString() + "Cr";
                     dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtcb"].Value = decCb.ToString();
                 }
                 else
                 {
                     decCb = -1 * decCb;
                     dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtClosingBalance"].Value = decCb.ToString() + "Cr";
                     dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtcb"].Value = decCb.ToString();
                 }
                 decimal decOB = Convert.ToDecimal(rw["OpeningBalance"].ToString());
                 decimal decCB = Convert.ToDecimal(rw["ClosingBalance"].ToString());
                 decWCCL = decOp - decCb;
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtWorkingCapitalIncrease"].Value = decWCCL.ToString();
             }
             //-----------------Calculating Working capital---------------
             decimal decOpen = 0;
             decimal decClose = 0;
             decimal decWork = 0;
             decOpen = Convert.ToDecimal(dgvFundFlow2.Rows[0].Cells[3].Value.ToString()) - Convert.ToDecimal(dgvFundFlow2.Rows[1].Cells[3].Value.ToString());
             decClose = Convert.ToDecimal(dgvFundFlow2.Rows[0].Cells[5].Value.ToString()) - Convert.ToDecimal(dgvFundFlow2.Rows[1].Cells[5].Value.ToString());
             decWork = Convert.ToDecimal(dgvFundFlow2.Rows[0].Cells[6].Value.ToString()) - Convert.ToDecimal(dgvFundFlow2.Rows[1].Cells[6].Value.ToString());
             decimal decW1 = Convert.ToDecimal(dgvFundFlow2.Rows[0].Cells[6].Value.ToString());
             decimal decW2 = Convert.ToDecimal(dgvFundFlow2.Rows[1].Cells[6].Value.ToString());
             dgvFundFlow2.Rows.Add();
             dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtParticulars"].Value = "Working Capital";
             if (decOpen > 0)
             {
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtOpeningBalance"].Value = decOpen.ToString() + "Dr";
             }
             else
             {
                 decOpen *= -1;
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtOpeningBalance"].Value = decOpen.ToString() + "Cr";
             }
             if (decClose > 0)
             {
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtClosingBalance"].Value = decClose.ToString() + "Dr";
             }
             else
             {
                 decClose *= -1;
                 dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtClosingBalance"].Value = decClose.ToString() + "Cr";
             }
             dgvFundFlow2.Rows[dgvFundFlow2.Rows.Count - 1].Cells["dgvtxtWorkingCapitalIncrease"].Value = decWork.ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("FF:06" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }