using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Configuration;
using MySql.Data.MySqlClient;
using MySql.Data;
using CLS_BL;
using CLS_DL;
using CLS_PL;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing.Printing;
using System.Drawing;
using System.Drawing.Text;




namespace SUNWEB
{
    public partial class RetailPayment : System.Web.UI.Page
    {
        BL_SELECT ObjSel = new BL_SELECT();
        BLCompany ObjBL = new BLCompany();
        PLCOMMON ObjPL = new PLCOMMON();
        BL_USER ObjUserBL = new BL_USER(); //This Object for All User and Page Related fuctions included 
        PLCUSTOMER ObjCustPL = new PLCUSTOMER();
        Int32 K = 0;
        Int32 L = 0;
        Int32 S = 0;
        string ConStr = ConfigurationManager.ConnectionStrings["ConMysql"].ConnectionString;
        string ConStr_Rds = ConfigurationManager.ConnectionStrings["ConRDS"].ConnectionString;
        string Curr_Date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        string Curr_DateOnly = System.DateTime.Now.ToString("yyyy-MM-dd");
        DateTime MonthstartDt;
        DataSet ds = new DataSet();
        MYSQLDB ObjMain = new MYSQLDB();
        MYSQLCLOUD ObjCloudMain = new MYSQLCLOUD();
        DataTable DT = new DataTable();
        DataTable DtT = new DataTable();
        DataTable DtF = new DataTable();
        DataTable Dt1 = new DataTable();
        DataTable Dt2 = new DataTable();
        DataTable Dt3 = new DataTable();
        DataTable Dt4 = new DataTable();
        DataTable Dt5 = new DataTable();
        DataTable Dt6 = new DataTable();
        DataTable Dt7 = new DataTable();

        DataTable DtLicense = new DataTable();
        DataTable DtSuperAdmin = new DataTable();
        DataTable DtMultiBranch = new DataTable();
        DataTable DtNormalUser = new DataTable();
        
        MySqlCommand Cmdv = new MySqlCommand();
        // User Variables 
        string UserId = string.Empty;
        string UserName = string.Empty;
        string PortalTypeId = string.Empty;
        string cd_Id = string.Empty;
        string Datapath = string.Empty;
        string cd_BranchAlias = string.Empty;
        string IsMultiBranch = string.Empty;
        string IsSuperAdmin = string.Empty;
        string ActiveCallvalue = string.Empty;
        // License Variables ..
        string PID = string.Empty;
        string Page_Acess = string.Empty;
        string Read_Acess = string.Empty;
        string Write_Acess = string.Empty;
        string Isdowld_Acess = string.Empty;
        string Rcd_id = string.Empty;
        string RPortalid = string.Empty;
        string Useridvalue = string.Empty;
        string QueryCurr_Select = string.Empty;
        string L_MaxUserCnt = string.Empty;

        string L_RetailPayment = string.Empty;
        string Branchidval = string.Empty;
        string BranchFullName = string.Empty;
        string Curr_BranchFullName = string.Empty;
        string Cmb_BranchName = string.Empty;

        string HQ = string.Empty;
        string Cm_id = string.Empty;
        string ISHQ = string.Empty;
        DataSet DS = new DataSet();
        //ReportDocument rep = new ReportDocument();
        string Vw_Chk = string.Empty;

        string BraNam = "";
        string FDate = "";
        string TDate = "";

        string sSelQry = "";
        string sCondQry = "";
        string sCmd = "";

        protected void Page_Load(object sender, EventArgs e)
        {

            PID = "19";    // This is for Retail Payment Page 

            MySqlConnection Cn = new MySqlConnection(ConStr_Rds);
            Cn.Open();
            if (!IsPostBack)
            {
                txtFromDt.Text = Curr_DateOnly;
                txtToDt.Text = Curr_DateOnly;
            }
            if (Session["UserName"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            MonthstartDt = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, 1);

            //GridView1.Columns[10].HeaderText = "SVG";
            //GridView1.Columns[11].HeaderText = "GST";

            if (((Convert.ToBoolean(Session["IsSuperAdmin"])) == true) && (Session["PortalTypeId"].ToString() == "") && ((Convert.ToBoolean(Session["IsMultiBranch"])) == true))
            {
                if (!IsPostBack)
                {
                    LoadBranchName4SuperAdmin();

                    string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
                    ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
                    if (ActiveCallvalue != " " || ActiveCallvalue != "Select Branch")
                    {
                        ActiveCall();
                    }
                }
            }
            else if (((Convert.ToBoolean(Session["IsSuperAdmin"])) == true) && (Session["PortalTypeId"].ToString() == ""))
            {
                if (!IsPostBack)
                {
                    LoadBranchName4SuperAdmin();
                }
                cd_BranchAlias = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                BraNam = cd_BranchAlias;
                FDate = txtFromDt.Text;
                TDate = txtToDt.Text;
                LoadRetailPaymentQry(cd_BranchAlias, Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text), Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text));
            }
            else if (((Convert.ToBoolean(Session["IsMultiBranch"])) == true) && (Session["PortalTypeId"].ToString() == ""))
            {
                if (!IsPostBack)
                {
                    LoadBranchName();
                    ActiveCall();
                }
            }
            else if (((Session["PortalTypeId"].ToString() != "") || (Convert.ToBoolean(Session["IsSuperAdmin"])) == false) && ((Convert.ToBoolean(Session["IsMultiBranch"])) == false))
            {
                cmbBranches.Enabled = false;
                cmbBranches.Visible = false;

                Cm_id = ObjSel.GETcmid(Session["Cd_Id"].ToString());  // Get cm_id
                HQ = ObjSel.Get_HQ(Cm_id);     // Get the HQ Value
                Curr_BranchFullName = ObjSel.GetBranchFullName(HQ, Session["Branch_HQ"].ToString());
                lblBranchAliasName.ForeColor = System.Drawing.Color.DodgerBlue;
                lblBranchAliasName.Text = "&nbsp;" + "-" + "&nbsp;" + Curr_BranchFullName + "&nbsp; ";
                cd_BranchAlias = Session["Branch_HQ"].ToString();
                Datapath = Session["DataPath"].ToString();
                PortalTypeId = Session["PortalTypeId"].ToString();
                PID = "17"; //  This is for Journal
                DT = ObjUserBL.GetPageRightsDetailsPid(Session["UserId"].ToString(), PID);
                if (DT.Rows.Count > 0)
                {
                    Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                    Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                    Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                    Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();
                    Session["Page_Acess"] = Page_Acess;
                    Session["Read_Acess"] = Read_Acess;
                    Session["Write_Acess"] = Write_Acess;
                    Session["Isdowld_Acess"] = Isdowld_Acess;
                }
                if ((Session["L_Journal"].ToString() == "N") || (Session["Page_Acess"].ToString() == "N"))
                {
                    Response.Redirect("DeniedPage.aspx", false);
                }
                else
                {

                    // XSS Attack Prevention 
                    string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
                    string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());


                    //lblMsgTotalSelection.Text = "Search Result - Retail Payment Report  Between" + "&nbsp;&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                    lblMsgTotalSelection.Text = "Search Result - from " + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp; to &nbsp;&nbsp;" + EndDt;
                    idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White; font-size:14px;");
                    if (!IsPostBack)
                    {
                        if (Session["Isdowld_Acess"].ToString() == "N")
                        {
                            // btnExcel.Enabled = false;
                            Response.Write(@"<script language='javascript'>alert('No Access To download.')</script>");
                        }
                        else
                        {
                            btnGenerate.Visible = true;
                            //btnExcel.Enabled = true;
                            if (cmbBranches.Visible == false)
                            {

                                LoadRetailPaymentQry(Session["Branch_HQ"].ToString(), StartDT, EndDt);
                            }

                        }
                    }
                }
            }
            else
            {

            }


        }


        public void ActiveCall()
        {
            string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
            ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
            if (ActiveCallvalue == "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch7(Session["Branch_HQ"].ToString(), Session["UserId"].ToString());
            }


            ISHQ = ObjMain.ExecuteScalar("select BranchName from " + ActiveCallvalue + ".branches where Branchname='" + ActiveCallvalue + "' and branchID=1;");  //now 

            if (ISHQ != "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch7(Session["Branch_HQ"].ToString(), Session["UserId"].ToString());
                UPDATEBRANCH(ActiveCallvalue);
            }

            cd_BranchAlias = ActiveCallvalue;
            Curr_BranchFullName = ObjUserBL.GetBranchCurr_BranchVal(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), cd_BranchAlias);
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Curr_BranchFullName);  // This will Return BranchName( Actual Database Name )
            cmbBranches.Items.FindByText(Curr_BranchFullName).Selected = true;
            Branchidval = ObjUserBL.GetBranchIDbyName(ActiveCallvalue, ActiveCallvalue);
            if (Branchidval != "")
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, Branchidval);
            }
            else
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, Session["Fistbranch"].ToString());

            }
            if (DT.Rows.Count > 0)
            {
                Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();

                Session["Page_Acess"] = Page_Acess;
                Session["Read_Acess"] = Read_Acess;
                Session["Write_Acess"] = Write_Acess;
                Session["Isdowld_Acess"] = Isdowld_Acess;
            }
            Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + ActiveCallvalue + "';");
            RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
            DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);
            if (DtLicense.Rows.Count > 0)
            {


                L_RetailPayment = DtLicense.Rows[0]["RETAILPAYMENT"].ToString();
                Session["L_RetailPayment"] = L_RetailPayment;
            }
            if (Session["L_RetailPayment"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
            {
                Response.Redirect("DeniedPage.aspx");
            }
            else
            {

                //btnExcel.Enabled = true;
                //lblMsgTotalSelection.Text = "Total Sale Selection Between" + "&nbsp;&nbsp;&nbsp;" + txtStartDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtEndDt.Text;
                cd_BranchAlias = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                // BindGridview(ActiveCallvalue, txtStartDt.Text, txtEndDt.Text);
                System.Threading.Thread.Sleep(2000);

            }

        }


        public void LoadBranchName()
        {
            DtNormalUser = ObjUserBL.GetBranchOnLoginValues8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            if (DtNormalUser.Rows.Count > 0)
            {
                cmbBranches.DataSource = DtNormalUser;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");
            }
        }
        public void LoadBranchName4SuperAdmin()
        {
            DtSuperAdmin = ObjUserBL.GetBranchOnSuperAdmin8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            if (DtSuperAdmin.Rows.Count > 0)
            {
                cmbBranches.DataSource = DtSuperAdmin;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");
            }
        }

        protected void cmbBranches_SelectedIndexChanged(object sender, EventArgs e)
        {


            // XSS Attack Prevention 
            string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
            string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());

            if (cmbBranches.SelectedIndex == 0)
            {
                Response.Redirect("RetailPayment.aspx", false);
            }
            else
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, cmbBranches.SelectedItem.Value);
                if (DT.Rows.Count > 0)
                {
                    Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                    Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                    Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                    Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();

                    Session["Page_Acess"] = Page_Acess;
                    Session["Read_Acess"] = Read_Acess;
                    Session["Write_Acess"] = Write_Acess;
                    Session["Isdowld_Acess"] = Isdowld_Acess;
                }

                ISHQ = ObjMain.ExecuteScalar("select BranchName from branches where Branchname='" + ActiveCallvalue + "' and branchID=1;");  //now 

                if (ISHQ != "")
                {
                    ActiveCallvalue = ObjSel.GetFirstBranch(Session["Branch_HQ"].ToString());
                    UPDATEBRANCH(ActiveCallvalue);
                }
                else
                {
                    BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + Cmb_BranchName + "';");
                    RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
                    DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);

                }


                if (DtLicense.Rows.Count > 0)
                {
                    L_MaxUserCnt = DtLicense.Rows[0]["UserCnt"].ToString();
                    L_RetailPayment = DtLicense.Rows[0]["RetailPayment"].ToString();
                    // Create Session for License Variables 
                    Session["L_MaxUserCnt"] = L_MaxUserCnt;
                    Session["L_RetailPayment"] = L_RetailPayment;
                }
                if (Session["L_RetailPayment"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
                {
                    Response.Redirect("DeniedPage.aspx", false);
                }
                else
                {
                    //btnExcel.Enabled = true;
                    //lblMsgTotalSelection.Text = "Group Sales Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                    //lblMsgTotalSelection.Text = "Search Result - Retail Payment Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                    lblMsgTotalSelection.Text = "Search Result - from " + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp; to &nbsp;&nbsp;" + EndDt;
                    idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White; font-size:14px;");
                    cd_BranchAlias = Cmb_BranchName;
                    BraNam = cd_BranchAlias;
                    FDate = txtFromDt.Text;
                    TDate = txtToDt.Text;
                    LoadRetailPaymentQry(cd_BranchAlias, StartDT, EndDt);
                    //BindGridview(cd_BranchAlias, txtStartDt.Text, txtEndDt.Text);
                }
            }
            UPDATEBRANCH(Cmb_BranchName);

        }
        public void UPDATEBRANCH(string ActiveCallvalue)
        {
            if (!string.IsNullOrEmpty(Session["UserId"] as string))
            {
                Useridvalue = Session["UserId"].ToString();
                QueryCurr_Select = "Update portaldb.usermaster set ActiveValue='" + ActiveCallvalue + "' where Userid=" + Useridvalue + "";
                S = ObjMain.ExecuteNonQuery(QueryCurr_Select);
            }
            else
            {
                Response.Redirect("Login.aspx");

            }

        }
        protected void btnGenerate_Click(object sender, EventArgs e)
        {

            // XSS Attack Prevention 
            string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
            string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());

            GridView1.DataSource = null;
            GridView1.DataBind();

            if (cmbBranches.Visible == false)
            {
                btnGenerate.Visible = true;
                //lblMsgTotalSelection.Text = "Search Result - Retail Payment Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                lblMsgTotalSelection.Text = "Search Result - from " + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp; to &nbsp;&nbsp;" + EndDt;
                idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White; font-size:14px;");
                LoadRetailPaymentQry(Session["Branch_HQ"].ToString(), StartDT, EndDt);
                System.Threading.Thread.Sleep(2000);
            }
            else if (cmbBranches.Visible == true)
            {
                //lblMsgTotalSelection.Text = " Search Result - Retail Payment Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                lblMsgTotalSelection.Text = "Search Result - from " + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp; to &nbsp;&nbsp;" + EndDt;
                idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White; font-size:14px;");
                Curr_BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                cd_BranchAlias = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Curr_BranchFullName);  // This will Return BranchName( Actual Database Name )
                BraNam = cd_BranchAlias;
                FDate = txtFromDt.Text;
                TDate = txtToDt.Text;
                LoadRetailPaymentQry(cd_BranchAlias, StartDT, EndDt);
            }


        }

        protected void LoadRetailPaymentQry(string BranchAlias, string D1, string D2)
        {
            System.Threading.Thread.Sleep(1000);

            BraNam = BranchAlias;

            // Prevent  SQL Injections 
            // Parameterized Approach

            //for generating Date Range for the report generation (0 filling purpose)
            sCmd = "DROP TABLE IF EXISTS {0}.`olrpdates` ";
            string command = string.Format(sCmd, BraNam);
            K = ObjCloudMain.ExecuteNonQuery(command);

            string sCmd1 = "CREATE TABLE  {0}.`olrpdates` (" +
             " `BusinessDate` datetime DEFAULT NULL " +
             " ) ENGINE=InnoDB ";

            string command1 = string.Format(sCmd1, BraNam);
            K = ObjCloudMain.ExecuteNonQuery(command1);




            DateTime dateStart = Convert.ToDateTime(Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text));
            do
            {
                string sCmd3 = "INSERT INTO {0}.olrpdates (BusinessDate) VALUES ('" + dateStart.ToString("yyyy-MM-dd") + "' ) ";
                string command2 = string.Format(sCmd3, BraNam);

                K = ObjCloudMain.ExecuteNonQuery(command2);
                dateStart = dateStart.AddDays(1);
            } while (dateStart <= Convert.ToDateTime(Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text)));

            //Part 1 Total Sales,RA & PO (Datatable Dt1)
            //sCmd = "Select Mth, Date, Sum(Round(Sales,2)) as Sales, Sum(Round(PO,2)) as PO, Sum(Round(RA,2)) as RA From(" +
            sCmd = "Select Mth, Date,format(Sum(Round(Sales,2)),2)  as Sales, format(Sum(Round(PO,2)),2) as PO, format(Sum(Round(RA,2)),2) as RA From(" +
            " Select Date_Format(T.BusinessDate,'%M-%y') As Mth, " +
            " Date_Format(T.BusinessDate,'%d') as Date, 0 as Sales, 0 As PO,0 As RA" +
            " From {0}.OLRPDates T" +
            " Where T.BusinessDate Between  @D1  and  @D2  " +
            " Group by T.BusinessDate" +
            " Union" +
            " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date, Sum(T.Total) as Sales, 0 As PO,0 As RA " +
            //" From " + BraNam + ".Trans T Left Outer Join " + BraNam + ".TransPayment TP on T.TransID=TP.TransID" +
            " From {0}.Trans T " +
            " Where T.TransStatus in (2) And T.BusinessDate Between @D1  and  @D2  " +
            " Group by T.BusinessDate " +
            " Union" +
            " Select Date_Format(BusinessDate,'%M-%y') As Mth,Date_Format(BusinessDate,'%d') as Date, 0 as Sales, Amount As PO,0 As RA" +
            " From {0}.RAPO " +
            " Where BusinessDate Between @D1  and  @D2  And TransType=1 " +
            " Union" +
            " Select Date_Format(BusinessDate,'%M-%y') As Mth,Date_Format(BusinessDate,'%d') as Date, 0 as Sales, 0 As PO,Amount As RA " +
            " From {0}.RAPO " +
            " Where BusinessDate Between @D1  and  @D2  And TransType=0 " +
            " ) As K" +
            " Group by 1,2;";

            string Command4 = string.Format(sCmd, BraNam);
            MySqlParameter[] parameters =
                  {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

            Dt1 = ObjMain.NewGetData_DT(Command4, parameters);



            //Part 2 Different Types Payment Types used in the period (Datatable Dt2)
            sSelQry = "";
            sCondQry = "";
            //sCmd = "Select Distinct PaymentType" +        'nid changed this qry due to blank payment types on 04-Jan-2021
            //sCmd = "Select Distinct Replace(PaymentType,' ','') as PaymentType" +
            //    " From " + BraNam + ".Trans T Left Outer Join " + BraNam + ".TransPayment TP On T.TransID=TP.TransID " +
            //    " Where T. TransStatus in (2) And T.BusinessDate Between '" + txtFromDt.Text + "' and '" + txtToDt.Text + "' And TP.PaymentType<>'' ";
            sCmd = "Select Distinct Replace(PaymentType,' ','') as PaymentType" +
            " From {0}.TransPayment TP " +
            " Where  TP.BusinessDate Between  @D1  and  @D2  And TP.PaymentType<>'' ";
            DtT.Clear();

            string command5 = string.Format(sCmd, BraNam);

            MySqlParameter[] paramss =
                  {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

            DtT = ObjMain.NewGetData_DT(command5, paramss);


            //Sum(Round(ifnull(K.CASH,0),2)) as CASH, Sum(Round(ifnull(K.NETS,0),2)) as NETS
            //case when TP.PaymentType = 'CASH' then TP.PaymentAmount end as CASH,
            if (DtT.Rows.Count != 0)
            {
                foreach (DataRow row in DtT.Rows)
                {
                    if (sSelQry == "")
                    {
                        sSelQry = ",format(Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)),2) as " + row["PaymentType"];
                        //sCondQry = ",case when TP.PaymentType='" + row["PaymentType"] + "' then TP.PaymentAmount end As " + row["PaymentType"];
                        sCondQry = ",case when Replace(TP.PaymentType,' ','')='" + row["PaymentType"] + "' then TP.PaymentAmount end As " + row["PaymentType"];
                    }
                    else
                    {
                        sSelQry = sSelQry + ",format(Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)),2) as " + row["PaymentType"];
                        sCondQry = sCondQry + ",case when Replace(TP.PaymentType,' ','')='" + row["PaymentType"] + "' then TP.PaymentAmount end As " + row["PaymentType"];
                    }
                }
                sCmd = "Select  Mth, Date" + sSelQry + " From (" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date" + sCondQry +
                " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID " +
                " Where T. TransStatus in (2) And T.BusinessDate Between  @D1  and  @D2  " +
                ") K Group by 1,2";

                string command6 = string.Format(sCmd, BraNam);
                MySqlParameter[] paraa =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

                Dt2 = ObjMain.NewGetData_DT(command6, paraa);


            }
            //Part 3 Detailed Summary of Integrated Payment Types (Datatable Dt3)
            sCmd = "Select Distinct PaymentType" +
            " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID " +
            " Where T. TransStatus in (2) And TP.PaymentType in ('NetsCC','NetsCC4','NetsUOBCC4','U_Credit') And T.BusinessDate Between  @D1 and  @D2  ";
            DtT.Clear();

            string command7 = string.Format(sCmd, BraNam);
            MySqlParameter[] paramms =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

            DtT = ObjMain.NewGetData_DT(command7, paramms);


            if (DtT.Rows.Count != 0)
            {
                sCmd = "Select  Mth, Date,format(Sum(Round(ifnull(K.AMEX,0),2)),2) as AMEX,format(Sum(Round(ifnull(K.DINERS,0),2)),2) as DINERS,format(Sum(Round(ifnull(K.DISCOVER,0),2)),2) as DISCOVER," +
                " format(Sum(Round(ifnull(K.JCB,0),2)),2) as JCB,format(Sum(Round(ifnull(K.MASTERS,0),2)),2) as MASTERS,format(Sum(Round(ifnull(K.VISA,0),2)),2) as VISA,format(Sum(Round(ifnull(K.UNIONPAY,0),2)),2) as UNIONPAY" +
                " From (" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date," +
                " case when TP.PaymentType in ('NetsCC','NetsCC4','NetsUOBCC4','U_Credit') then TP.PaymentAmount end as 'AMEX'," +
                " 0 As DINERS,0 As DISCOVER,0 As JCB,0 as MASTERS, 0 as VISA,0 as UNIONPAY" +
                " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID" +
                " Where T. TransStatus in (2) And T.BusinessDate Between  @D1  and  @D2  " +
                " And Left(TP.CardNumber,2) in ('34','37')" +
                " Union" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date," +
                " 0 as AMEX," +
                " case when TP.PaymentType in ('NetsCC','NetsCC4','NetsUOBCC4','U_Credit') then TP.PaymentAmount end as 'DINERS'," +
                " 0 As DISCOVER,0 As JCB,0 as MASTERS,0 as VISA,0 as UNIONPAY" +
                " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID" +
                " Where T. TransStatus in (2) And T.BusinessDate Between @D1  and  @D2  " +
                " And Left(TP.CardNumber,2) in ('30','36','38','39')" +
                " Union" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date," +
                " 0 as AMEX,0 as DINERS," +
                " case when TP.PaymentType in ('NetsCC','NetsCC4','NetsUOBCC4','U_Credit') then TP.PaymentAmount end as 'DISCOVER'," +
                " 0 as JCB,0 as MASTERS,0 as VISA,0 as UNIONPAY" +
                " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID" +
                " Where T. TransStatus in (2) And T.BusinessDate Between @D1  and  @D2  " +
                " And Left(TP.CardNumber,6) Between '601100' And '601109'" +
                " And Left(TP.CardNumber,6) Between '601120' And '601149'" +
                " And Left(TP.CardNumber,6) ='601174'" +
                " And Left(TP.CardNumber,6) Between '601177' And '601179'" +
                " And Left(TP.CardNumber,6) Between '601186' And '601199'" +
                " And Left(TP.CardNumber,6) Between '644000' And '659999'" +
                " Union" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date," +
                " 0 as AMEX,0 as DINERS,0 as DISCOVER," +
                " case when TP.PaymentType in ('NetsCC','NetsCC4','NetsUOBCC4','U_Credit') then TP.PaymentAmount end as 'JCB'," +
                " 0 as MASTERS,0 as VISA,0 as UNIONPAY" +
                " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID " +
                " Where T. TransStatus in (2) And T.BusinessDate Between @D1  and  @D2  " +
                " And Left(TP.CardNumber,4) Between '3528' And '3589'" +
                " Union" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date, " +
                " 0 as AMEX,0 as DINERS,0 as DISCOVER,0 as JCB," +
                " case when TP.PaymentType in ('NetsCC','NetsCC4','NetsUOBCC4','U_Credit') then TP.PaymentAmount end as 'MASTERS'," +
                " 0 as VISA,0 as UNIONPAY" +
                " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID" +
                " Where T. TransStatus in (2) And T.BusinessDate Between @D1  and  @D2  " +
                " And (Left(TP.CardNumber,6) Between '510000' And '559999'" +
                " or Left(TP.CardNumber,6) Between '222100' And '272099')" +
                " Union" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date," +
                " 0 as AMEX,0 as DINERS,0 as DISCOVER,0 as JCB,0 as MASTERS," +
                " case when TP.PaymentType in ('NetsCC','NetsCC4','NetsUOBCC4','U_Credit') then TP.PaymentAmount end as 'VISA'," +
                " 0 as UNIONPAY" +
                " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID" +
                " Where T. TransStatus in (2) And T.BusinessDate Between  @D1  and  @D2  " +
                " And Left(TP.CardNumber,1) in ('4')" +
                " Union" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date," +
                " 0 as AMEX,0 as DINERS,0 as DISCOVER,0 as JCB,0 as MASTERS,0 as VISA," +
                " case when TP.PaymentType in ('NetsCC','NetsCC4','NetsUOBCC4','U_Credit') then TP.PaymentAmount end as 'UNIONPAY'" +
                " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID" +
                " Where T. TransStatus in (2) And T.BusinessDate Between @D1  and  @D2  " +
                " And Left(TP.CardNumber,2) in ('62','81')" +
                " ) K Group by 1,2;";

                string command8 = string.Format(sCmd, BraNam);
                MySqlParameter[] paarams =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

                Dt3 = ObjMain.NewGetData_DT(command8, paarams);
            }
            //Part 4 Extra payments added via CALLEXTRAPAYMENTCOLLECTIONS Function(Datatable Dt4)
            sSelQry = "";
            sCondQry = "";
            //sCmd = "Select Distinct PTE.PaymentType" +
            sCmd = "Select Distinct Replace(PTE.PaymentType,' ','') as PaymentType" +
                " From {0}.PaymentTypeExtra PTE Left Outer Join {0}.ExtraCollections EC On PTE.PaymentTypeID=EC.PaymentTypeID " +
                " Where EC.BusinessDate Between  @D1 and  @D2  Order by PTE.PaymentTypeID ";
            DtT.Clear();

            string command9 = string.Format(sCmd, BraNam);
            MySqlParameter[] params1 =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

            DtT = ObjMain.NewGetData_DT(command9, params1);



            //,Sum(Round(ifnull(K.GRAB,0),2)) as GRAB
            ///,case when PTE.PaymentType = 'GRAB' then EC.Amount end as GRAB
            if (DtT.Rows.Count != 0)
            {
                foreach (DataRow row in DtT.Rows)
                {
                    if (sSelQry == "")
                    {
                        sSelQry = ",format(Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)),2) as " + row["PaymentType"];
                        sCondQry = ",case when Replace(PTE.PaymentType,' ','')='" + row["PaymentType"] + "' then EC.Amount end As " + row["PaymentType"];
                    }
                    else
                    {
                        sSelQry = sSelQry + ",format(Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)),2) as " + row["PaymentType"];
                        sCondQry = sCondQry + ",case when Replace(PTE.PaymentType,' ','')='" + row["PaymentType"] + "' then EC.Amount end As " + row["PaymentType"];
                    }
                }

                sCmd = "Select  Mth, Date" + sSelQry + "  From (" +
                " Select Date_Format(EC.BusinessDate,'%M-%y') As Mth,Date_Format(EC.BusinessDate,'%d') as Date" + sCondQry +
                " From {0}.ExtraCollections EC Left Outer Join {0}.PaymentTypeExtra PTE On EC.PaymentTypeID=PTE.PaymentTypeID " +
                " Where EC.BusinessDate Between @D1 and @D2 " +
                " ) K Group by 1,2";

                string command10 = string.Format(sCmd, BraNam);
                MySqlParameter[] param2 =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };
                Dt4 = ObjMain.NewGetData_DT(command10, param2);

            }
            //Part 5 Item Disc (Datatable Dt5)
            sCmd = "Select Mth, Date, format(Sum(Round(ItemDisc,2)),2) as ItemDisc From(" +
            " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date, Sum(TD.ManualDisc) as ItemDisc" +
            " From {0}.Trans T Left Outer Join {0}.TransDetail TD on T.TransID=TD.TransID" +
            " Where T.TransStatus in (2) And T.BusinessDate Between  @D1  and  @D2  " +
            " Group by T.BusinessDate" +
            " ) As K" +
            " Group by 1,2";

            string command11 = string.Format(sCmd, BraNam);
            MySqlParameter[] param3 =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

            Dt5 = ObjMain.NewGetData_DT(command11, param3);



            //Part 6 Class 5 Voucher Types(Datatable Dt6)
            sSelQry = "";
            sCondQry = "";
            //sCmd = "Select Distinct TD.Barcode as PaymentType" +
            sCmd = "Select Distinct Replace(TD.InventoryDesc,' ','') as PaymentType" +
            " From {0}.Trans T Left Outer Join {0}.TransDetail TD On T.TransID=TD.TransID" +
            " Where T. TransStatus in (2) And Class=5 And T.BusinessDate Between  @D1 and @D2  Order by 1";

            DtT.Clear();



            string command12 = string.Format(sCmd, BraNam);

            MySqlParameter[] param4 =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

            DtT = ObjMain.NewGetData_DT(command12, param4);





            //,Sum(Round(ifnull(K.GRAB,0),2)) as GRAB
            ///,case when PTE.PaymentType = 'GRAB' then EC.Amount end as GRAB
            if (DtT.Rows.Count != 0)
            {
                foreach (DataRow row in DtT.Rows)
                {
                    if (sSelQry == "")
                    {
                        //sSelQry = ",Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)) as " + row["PaymentType"];
                        //sCondQry = ",case when TD.Barcode='" + row["PaymentType"] + "' then TD.Amount end As " + row["PaymentType"];
                        sSelQry = ",format(Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)),2) as " + row["PaymentType"];
                        sCondQry = ",case when Replace(TD.InventoryDesc,' ','')='" + row["PaymentType"] + "' then TD.Amount end As " + row["PaymentType"];
                    }
                    else
                    {
                        //sSelQry = sSelQry + ",Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)) as " + row["PaymentType"];
                        //sCondQry = sCondQry + ",case when TD.Barcode='" + row["PaymentType"] + "' then TD.Amount end As " + row["PaymentType"];
                        sSelQry = sSelQry + ",format(Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)),2) as " + row["PaymentType"];
                        sCondQry = sCondQry + ",case when Replace(TD.InventoryDesc,' ','')='" + row["PaymentType"] + "' then TD.Amount end As " + row["PaymentType"];

                    }
                }

                sCmd = "Select  Mth, Date" + sSelQry + "  From (" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date" + sCondQry +
                " From {0}.Trans T Left Outer Join {0}.TransDetail TD On T.TransID=TD.TransID " +
                " Where T. TransStatus in (2) And TD.Class=5 And TD.ItemStatus=0 And T.BusinessDate Between  @D1  and @D2  " +
                " ) K Group by 1,2";


                string command13 = string.Format(sCmd, BraNam);
                MySqlParameter[] param5 =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

                Dt6 = ObjMain.NewGetData_DT(command13, param5);





            }

            //Part 7 VIP Membership amount collection (Coffeehive only)(Datatable Dt7)
            sCmd = "Select TD.TransID" +
            " From {0}.Trans T Left Outer Join {0}.TransDetail TD on T.TransID=TD.TransID" +
            " Where T.TransStatus in (2) And TD.Barcode in ('VIP') And TD.ItemStatus=0 And T.BusinessDate Between @D1 and  @D2 ";
            DtT.Clear();

            string command14 = string.Format(sCmd, BraNam);
            MySqlParameter[] param6 =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

            DtT = ObjMain.NewGetData_DT(command14, param6);

            if (DtT.Rows.Count != 0)
            {
                sCmd = "Select Mth, Date, format(Sum(Round(Membership,2)),2) as Membership From(" +
                " Select Date_Format(T.BusinessDate,'%M-%y') As Mth,Date_Format(T.BusinessDate,'%d') as Date, " +
                " Sum(TD.Amount+TD.TaxAmount1+TD.TaxAmount2) as Membership" +
                " From {0}.Trans T Left Outer Join {0}.TransDetail TD on T.TransID=TD.TransID" +
                " Where T.TransStatus in (2) And TD.Barcode in ('VIP') And TD.ItemStatus=0 And T.BusinessDate Between  @D1 and  @D2  " +
                " Group by T.BusinessDate" +
                " ) As K" +
                " Group by 1,2";

                string command15 = string.Format(sCmd, BraNam);
                MySqlParameter[] param7 =
                    {
                     new MySqlParameter("@D1",D1),
                     new MySqlParameter("@D2",D2),
                    };

                Dt7 = ObjMain.NewGetData_DT(command15, param7);



            }
            Dt1.PrimaryKey = new DataColumn[] { Dt1.Columns["Date"], Dt1.Columns["Mth"] };
            Dt2.PrimaryKey = new DataColumn[] { Dt2.Columns["Date"], Dt2.Columns["Mth"] };
            Dt3.PrimaryKey = new DataColumn[] { Dt3.Columns["Date"], Dt3.Columns["Mth"] };
            Dt4.PrimaryKey = new DataColumn[] { Dt4.Columns["Date"], Dt4.Columns["Mth"] };
            Dt5.PrimaryKey = new DataColumn[] { Dt5.Columns["Date"], Dt5.Columns["Mth"] };
            Dt6.PrimaryKey = new DataColumn[] { Dt6.Columns["Date"], Dt6.Columns["Mth"] };
            Dt7.PrimaryKey = new DataColumn[] { Dt7.Columns["Date"], Dt7.Columns["Mth"] };
            //Dt1.Merge(Dt2);           
            Dt1.Merge(Dt2);
            Dt1.Merge(Dt3);
            Dt1.Merge(Dt4);
            Dt1.Merge(Dt5);
            Dt1.Merge(Dt6);
            Dt1.Merge(Dt7);

            //for filling 0 values
            for (int i = 0; i < Dt1.Rows.Count; i++)
            {
                for (int j = 0; j < Dt1.Columns.Count; j++)
                {
                    if (string.IsNullOrEmpty(Dt1.Rows[i][j].ToString()))
                    {

                        Dt1.Rows[i][j] = "0.00";
                    }
                }
            }

            //Part 8 For gettings Total fields
            DataRow totalsRow = Dt1.NewRow();
            DataColumn dc = new DataColumn("Sales", typeof(string));
            foreach (DataColumn col in Dt1.Columns)
            {
                Double colTotal = 0;
                foreach (DataRow row in col.Table.Rows)
                {
                    if ((col.ColumnName != "Mth") && (col.ColumnName != "Date"))
                    {
                        object value = row[col];
                        //if (row[col] != "")
                        if (value != DBNull.Value)
                        {
                            if (Double.Parse(row[col].ToString()) != 0)
                            {
                                colTotal += Double.Parse(row[col].ToString());
                            }
                        }
                    }
                }
                if (col.ColumnName == "Mth")
                {
                    totalsRow[col.ColumnName] = "Total";
                }
                else if (col.ColumnName == "Date")
                {
                    totalsRow[col.ColumnName] = "";
                }
                else
                {
                    //totalsRow[col.ColumnName] = String.Format("{0:0.00}", colTotal);

                    //totalsRow[col.ColumnName.ToString()] = string.Format("{0:n2}", colTotal);
                    totalsRow[col.ColumnName] = string.Format("{0:n2}", colTotal);

                    //totalsRow[col.ColumnName] = String.Format("{0:n2}", Convert.ToDecimal(colTotal));

                }
            }

            Dt1.Rows.Add(totalsRow);

            GridView1.DataSource = Dt1;
            //gridview totals
            GridView1.DataBind();

        }


        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            // XSS Attack Prevention 

            if (cmbBranches.Visible == false)
            {
                GridView1.PageIndex = e.NewPageIndex;
                LoadRetailPaymentQry(Session["Branch_HQ"].ToString(), Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text), Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text));
            }
            else
            {
                BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )

                GridView1.PageIndex = e.NewPageIndex;
                LoadRetailPaymentQry(Cmb_BranchName, Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text), Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text));
            }
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
             "attachment;filename=GridViewExport.xls");
            Response.Charset = "";
            
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                //Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }


            // GridView1.RenderControl(hw);

            //style to format numbers to string
            //string style = @"<style> td { mso-number-format:\@; } </style>";
            //string style = @"<style> .textmode { mso-number-format:\@; } </style>";
            //Response.Write(style);
            //Response.Output.Write(sw.ToString());
            //Response.Flush();
            //Response.End();


            GridView1.RenderControl(hw);
            //string style = @"<style> td { mso-number-format:\@; } </style>";         // Old Line :  Text   
            //string style = @"&lt;style> .text { mso-number-format:\@; } </style> ";   // Added For Number Formate Issue 
            string style = @"<style> td { mso-number-format:\@;font-size: 15px; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
               server control at run time. */
        }
    }
}