protected void OpenRecord()
    {
        string strGenFor = "";

        if (ddlGroup.SelectedValue.Trim() == "A")
        {
            if (ddlLocation.SelectedValue.Trim() != "-1")
            {
                strGenFor = "O";
            }
            else
            {
                //lblMsg.Text = "No value is selected. Please select either DOS or Office to generate the report.";
                //return;
                strGenFor = "A";
            }
        }
        else
        {
            strGenFor = "D";
        }


        DataTable dtEmp     = new DataTable();
        DataTable dtDate    = new DataTable();
        DataTable dtRecords = new DataTable();

        if (strGenFor != "A")
        {
            dtEmp     = objITMgr.GetDistinctEmpoyeeData("-1", ddlLocation.SelectedValue.Trim(), ddlFinYear.SelectedValue.Trim(), strGenFor);
            dtDate    = objITMgr.GetDistinctDate("-1", ddlLocation.SelectedValue.Trim(), ddlFinYear.SelectedValue.Trim(), strGenFor);
            dtRecords = objITMgr.GetDetailsData("-1", ddlLocation.SelectedValue.Trim(), ddlFinYear.SelectedValue.Trim(), strGenFor);
        }
        else
        {
            dtEmp     = objITMgr.GetDistinctEmpoyeeDataAll(ddlFinYear.SelectedValue.Trim());
            dtDate    = objITMgr.GetDistinctDateAll(ddlFinYear.SelectedValue.Trim());
            dtRecords = objITMgr.GetDetailsDataAll(ddlFinYear.SelectedValue.Trim());
        }

        // Payroll data
        DataTable dtPayrollDet   = objPayRptMgr.GetPayrollDataForITStatement(ddlFinYear.SelectedValue.Trim());
        DataTable dtBenefitsHead = objPayrollMgr.GetSalaryBenefitsHead();

        DataRow[] fPayrollDet;

        lblFiscalYear.Text = ddlFinYear.SelectedItem.Text.Trim();
        // Data Filling for Report
        if (dtDate.Rows.Count == 0)
        {
            lblMsg.Text           = "No deposited reocrds found. Please use IT deposit Records screen to input the data.";
            grEmployee.DataSource = null;
            grEmployee.DataBind();
            return;
        }
        this.IniReportDataTable(dtDate.Rows.Count + 3 + dtBenefitsHead.Rows.Count + 3 + 4);
        int     inSL       = 1;
        int     i          = 2;
        decimal decTotal   = 0;
        decimal decBfTotal = 0;

        foreach (DataRow dEmpRow in dtEmp.Rows)
        {
            DataRow nRow = dtReport.NewRow();
            nRow[0]    = inSL.ToString();
            nRow[1]    = dEmpRow["EMPID"].ToString().Trim();
            nRow[2]    = dEmpRow["FULLNAME"].ToString().Trim();
            nRow[3]    = dEmpRow["JobTitleName"].ToString().Trim();
            nRow[4]    = dEmpRow["PostingDivName"].ToString().Trim();
            nRow[5]    = Common.SetDate(dEmpRow["JOININGDATE"].ToString().Trim());
            i          = 6;
            decBfTotal = 0;
            foreach (DataRow dBfRows in dtBenefitsHead.Rows)
            {
                fPayrollDet = dtPayrollDet.Select("EMPID='" + dEmpRow["EMPID"].ToString().Trim() + "' AND SHEADID=" + dBfRows["SHEADID"].ToString().Trim());
                if (fPayrollDet.Length > 0)
                {
                    nRow[i]    = Common.RoundDecimal(fPayrollDet[0]["PAYAMT"].ToString().Trim(), 0).ToString();
                    decBfTotal = decBfTotal + Common.RoundDecimal(fPayrollDet[0]["PAYAMT"].ToString().Trim(), 0);
                }
                else
                {
                    nRow[i] = "0";
                }

                i++;

                fPayrollDet = null;
            }
            nRow[i] = decBfTotal.ToString();
            i++;
            nRow[i] = objCashWord.getCashWord(decBfTotal.ToString() + ".00");
            i++;

            decTotal = 0;
            foreach (DataRow dDateRow in dtDate.Rows)
            {
                DataRow[] foundRows = dtRecords.Select("EMPID='" + dEmpRow["EMPID"].ToString().Trim() + "' AND CHALLANDATE='" + dDateRow["CHALLANDATE"].ToString().Trim() + "'");
                if (foundRows.Length > 0)
                {
                    nRow[i]  = foundRows[0]["PAYAMT"].ToString().Trim();
                    decTotal = decTotal + Convert.ToDecimal(foundRows[0]["PAYAMT"].ToString().Trim());
                }
                else
                {
                    nRow[i] = "0";
                }
                i++;
            }
            inSL++;
            nRow[i] = decTotal.ToString();
            i++;
            nRow[i] = objCashWord.getCashWord(decTotal.ToString() + ".00");

            dtReport.Rows.Add(nRow);
            dtReport.AcceptChanges();
        }

        grEmployee.DataSource = dtReport;
        grEmployee.DataBind();

        if (grEmployee.Rows.Count > 0)
        {
            grEmployee.HeaderRow.Cells[0].Text            = "SL#";
            grEmployee.HeaderRow.Cells[0].HorizontalAlign = HorizontalAlign.Left;
            grEmployee.HeaderRow.Cells[0].VerticalAlign   = VerticalAlign.Top;
            grEmployee.HeaderRow.Cells[1].Text            = "Employee ID";
            grEmployee.HeaderRow.Cells[1].HorizontalAlign = HorizontalAlign.Left;
            grEmployee.HeaderRow.Cells[2].Text            = "Employee Name";
            grEmployee.HeaderRow.Cells[2].HorizontalAlign = HorizontalAlign.Left;
            grEmployee.HeaderRow.Cells[3].Text            = "Designation";
            grEmployee.HeaderRow.Cells[3].HorizontalAlign = HorizontalAlign.Left;
            grEmployee.HeaderRow.Cells[4].Text            = "Office";
            grEmployee.HeaderRow.Cells[4].HorizontalAlign = HorizontalAlign.Left;
            grEmployee.HeaderRow.Cells[5].Text            = "Joining Date";
            grEmployee.HeaderRow.Cells[5].HorizontalAlign = HorizontalAlign.Left;

            int j = 6;
            foreach (DataRow dBfRows in dtBenefitsHead.Rows)
            {
                grEmployee.HeaderRow.Cells[j].Text            = dBfRows["HeadName"].ToString();
                grEmployee.HeaderRow.Cells[j].HorizontalAlign = HorizontalAlign.Right;
                j++;
            }

            grEmployee.HeaderRow.Cells[j].Text            = "Total Remuneration ";
            grEmployee.HeaderRow.Cells[j].HorizontalAlign = HorizontalAlign.Right;
            j++;
            grEmployee.HeaderRow.Cells[j].Text            = "In Word";
            grEmployee.HeaderRow.Cells[j].HorizontalAlign = HorizontalAlign.Left;
            j++;

            for (i = j; i < dtReport.Columns.Count - 2; i++)
            {
                grEmployee.HeaderRow.Cells[i].Text            = Common.DisplayDate(dtDate.Rows[i - j]["CHALLANDATE"].ToString().Trim()) + "<br><br>" + dtDate.Rows[i - j]["CHALLANNO"].ToString().Trim();
                grEmployee.HeaderRow.Cells[i].HorizontalAlign = HorizontalAlign.Right;
            }
            grEmployee.HeaderRow.Cells[dtReport.Columns.Count - 2].Text            = "Total Tax";
            grEmployee.HeaderRow.Cells[dtReport.Columns.Count - 2].HorizontalAlign = HorizontalAlign.Right;
            grEmployee.HeaderRow.Cells[dtReport.Columns.Count - 2].VerticalAlign   = VerticalAlign.Top;
            grEmployee.HeaderRow.Cells[dtReport.Columns.Count - 1].Text            = "In Word";
            grEmployee.HeaderRow.Cells[dtReport.Columns.Count - 1].HorizontalAlign = HorizontalAlign.Left;
            grEmployee.HeaderRow.Cells[dtReport.Columns.Count - 1].VerticalAlign   = VerticalAlign.Top;
        }

        //// Summary Total
        //decimal dclFooterTotal = 0;
        //int j = 0;
        //grEmployee.FooterRow.Cells[1].Text = "Total :";
        //grEmployee.FooterRow.Cells[1].HorizontalAlign = HorizontalAlign.Left;
        //for (i = 2; i < dtReport.Columns.Count; i++)
        //{
        //    dclFooterTotal = 0;
        //    for (j = 0; j < grEmployee.Rows.Count;j++ )
        //    {
        //        dclFooterTotal = dclFooterTotal + Convert.ToDecimal(grEmployee.Rows[j].Cells[i].Text.Trim());
        //        grEmployee.Rows[j].Cells[i].HorizontalAlign = HorizontalAlign.Right;
        //        if (Convert.ToDecimal(grEmployee.Rows[j].Cells[i].Text.Trim()) == 0)
        //            grEmployee.Rows[j].Cells[i].Text = "-";
        //    }
        //    grEmployee.FooterRow.Cells[i].Text = dclFooterTotal.ToString();
        //    grEmployee.FooterRow.Cells[i].HorizontalAlign = HorizontalAlign.Right;
        //}
    }