private void GetResultsData()
    {
        try
        {
            LeadsDownloadBL objLeadDownload = new LeadsDownloadBL();

            DataSet dsLeadsStats = objLeadDownload.GetAllcotedLeadsConsolidated(ddlVehicleType.SelectedValue, ddlCenter.SelectedValue, txtStartDate.Text, txtEndDate.Text);
            if (dsLeadsStats.Tables[0].Rows.Count > 0)
            {
                dvLeads.Style["display"] = "block";
                rptrDownload.DataSource = dsLeadsStats.Tables[0];
                rptrDownload.DataBind();
                dvLeads.Visible = true;
                lblResHead.Visible = false;
            }
            else
            {
                dvLeads.Style["display"] = "none";
                dvLeads.Visible = false;
                lblResHead.Visible = true;
                lblResHead.Text = "No Leads found to Download";
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void AllDownloaded_Click(object sender, EventArgs e)
    {
        LeadsDownloadBL objLeadDownload = new LeadsDownloadBL();
        DataSet dsTotal = new DataSet();
        string strStateID = string.Empty;

        int i = 0;

        for (int index = 0; index < rptrDownload.Items.Count; index++)
        {
            HiddenField lblStateID = (HiddenField)rptrDownload.Items[index].FindControl("lblStateID");

            Label lblStateCode = (Label)rptrDownload.Items[index].FindControl("lblStateCode");

            CheckBox chk = (CheckBox)rptrDownload.Items[index].FindControl("chk");

            if (i == 0)
            {
                strStateID = lblStateID.Value;
                i = +1;
            }
            else
            {
                strStateID = strStateID + "," + lblStateID.Value;
            }

        }

        DataSet dsLeadsDownload = objLeadDownload.GetAllcotedLeadsDownload(ddlVehicleType.SelectedItem.Value, ddlCenter.SelectedItem.Value, txtStartDate.Text, txtEndDate.Text, strStateID, Session[Constants.USER_ID].ToString());

        if (dsLeadsDownload != null)
        {
            if (dsLeadsDownload.Tables.Count > 0)
            {
                if (dsLeadsDownload.Tables[0].Rows.Count > 0)
                {

                    objLeadDownload.UpdateLeadsAllcotedLeadsStatus(ddlVehicleType.SelectedItem.Value, ddlCenter.SelectedItem.Value, txtStartDate.Text, txtEndDate.Text, strStateID, Session[Constants.USER_ID].ToString(), dsLeadsDownload.Tables[0].Rows.Count.ToString());
                    //GetResultsData();
                    //DataSetToExcel.Convert(dsLeadsDownload, "UCE-CarLeads-" + ddlCenter.SelectedItem.Text + "-" + String.Format("{0:yyyy-MM-dd}", System.DateTime.Now.ToString()) + ".xls");
                    GetResultsData();
                    Session["PageDown"] = "LeadsDownload";
                    Session["LeadsDownDataset"] = dsLeadsDownload;
                    Session["LeadsdownloadName"] = "UCE-CarLeads-" + ddlCenter.SelectedItem.Text + "-" + String.Format("{0:yyyy-MM-dd}", System.DateTime.Now.ToString()) + ".xls";
                    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "javascript:poptasticTest('GetExcelDownload.aspx');", true);

                }
                else
                {
                    lblErrorExists.Visible = true;
                    lblErrorExists.Text = "No leads are available for view/download";
                    mdepAlertExists.Show();
                }
            }
            else
            {
                lblErrorExists.Visible = true;
                lblErrorExists.Text = "No leads are available for view/download";
                mdepAlertExists.Show();
            }
        }
        else
        {
            lblErrorExists.Visible = true;
            lblErrorExists.Text = "No leads are available for view/download";
            mdepAlertExists.Show();
        }
    }
    protected void btnView_Click(object sender, EventArgs e)
    {
        LeadsDownloadBL objLeadDownload = new LeadsDownloadBL();
        DataSet dsTotal = new DataSet();
        string strStateID = string.Empty;
        int i = 0;
        for (int index = 0; index < rptrDownload.Items.Count; index++)
        {
            HiddenField lblStateID = (HiddenField)rptrDownload.Items[index].FindControl("lblStateID");

            Label lblStateCode = (Label)rptrDownload.Items[index].FindControl("lblStateCode");

            CheckBox chk = (CheckBox)rptrDownload.Items[index].FindControl("chk");
            Label lblTobeDownload = (Label)rptrDownload.Items[index].FindControl("lblTobeDownload");

            if (chk.Checked == true)
            {
                if (lblTobeDownload.Text != "0")
                {
                    if (i == 0)
                    {
                        strStateID = "'" + lblStateID.Value + "'";
                        i = +1;
                    }
                    else
                    {
                        strStateID = strStateID + ",'" + lblStateID.Value + "'";
                    }
                }
            }
        }
        if (strStateID != "")
        {
            DataSet dsLeadsDownload = objLeadDownload.GetAllcotedLeadsDownload(ddlVehicleType.SelectedItem.Value, ddlCenter.SelectedItem.Value, txtStartDate.Text, txtEndDate.Text, strStateID, Session[Constants.USER_ID].ToString());

            if (dsLeadsDownload != null)
            {
                if (dsLeadsDownload.Tables.Count > 0)
                {
                    if (dsLeadsDownload.Tables[0].Rows.Count > 0)
                    {
                        lblLeadCnt.Text = dsLeadsDownload.Tables.Count.ToString();
                        DataView dv = GetTopDataViewRows(dsLeadsDownload.Tables[0].DefaultView, 25);

                        rptrLeads.DataSource = dv.ToTable();
                        rptrLeads.DataBind();

                        lblLeadCnt.Text = dv.ToTable().Rows.Count.ToString();
                        MpeShowLeads.Show();
                    }
                    else
                    {
                        lblErrorExists.Visible = true;
                        lblErrorExists.Text = "No leads are available for view/download";
                        mdepAlertExists.Show();
                    }
                }
                else
                {
                    lblErrorExists.Visible = true;
                    lblErrorExists.Text = "No leads are available for view/download";
                    mdepAlertExists.Show();
                }
            }
            else
            {
                lblErrorExists.Visible = true;
                lblErrorExists.Text = "No leads are available for view/download";
                mdepAlertExists.Show();
            }
        }
        else
        {
            lblErrorExists.Visible = true;
            lblErrorExists.Text = "No leads are available for view/download";
            mdepAlertExists.Show();
        }
    }
    protected void rptrDownload_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        LeadsDownloadBL objLeadDownload = new LeadsDownloadBL();

        HiddenField lblStateID = (HiddenField)e.Item.FindControl("lblStateID");

        Label lblStateCode = (Label)e.Item.FindControl("lblStateCode");

        DataSet dsLeadsDownload = objLeadDownload.GetAllcotedLeadsDownload(ddlVehicleType.SelectedItem.Value, ddlCenter.SelectedItem.Value, txtStartDate.Text, txtEndDate.Text, lblStateID.Value, Session[Constants.USER_ID].ToString());

        //DataSetToExcel.Convert(dsLeadsDownload, Response, ddlVehicleType.SelectedItem.Value + lblStateCode.Text);

        DataSetToExcel.Convert(dsLeadsDownload, Response, "UCE-CarLeads-" + ddlCenter.SelectedItem.Text + "-" + String.Format("{0:yyyy-MM-dd}", System.DateTime.Now.ToString()) + ".xls");
    }
    private void GetLeadsDownloadHistory()
    {
        try
        {
            LeadsDownloadBL objLeadsDownloadBL = new LeadsDownloadBL();

            DataSet dsStateAllocation = objLeadsDownloadBL.GetLeadsDownloadUploadHistory(ddlVehicleType.SelectedItem.Value);
            if (dsStateAllocation.Tables[0].Rows.Count > 0)
            {
                rptrDownload.Visible = true;
                ldsHeading.Visible = true;
                ldsHeading.Text = "Center wise leads";
                rptrDownload.DataSource = dsStateAllocation.Tables[0];
                rptrDownload.DataBind();
            }
            else
            {
                ldsHeading.Visible = true;
                ldsHeading.Text = "Leads not uploaded";
                rptrDownload.Visible = false;
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void rptrDownload_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            LinkButton lblIssuanceBatchID = (LinkButton)e.Item.FindControl("lblIssuanceBatchID");
            LeadsDownloadBL obj = new LeadsDownloadBL();

            DataSet ds = obj.LeadsUploadDetailsByBatchID(lblIssuanceBatchID.Text);

            DataSetToExcel.Convert(ds, Response, "LeadsUploadHistory" + lblIssuanceBatchID.Text);
            //DataSetToExcel.Convert(ds, Response, "LeadsHistory" + lblIssuanceBatchID.Text + ".xls");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void GetLeadsDownloadHistory()
    {
        LeadsDownloadBL objLeadsDownloadBL = new LeadsDownloadBL();

        DataSet dsStateAllocation = objLeadsDownloadBL.GetLeadsDownloadHistory(ddlVehicleType.SelectedItem.Value, ddlCenter.SelectedItem.Value);
        h3hed.Style["display"] = "block";
        rptrDownload.DataSource = dsStateAllocation.Tables[0];
        rptrDownload.DataBind();
    }
 protected void rptrDownload_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     LinkButton lblIssuanceBatchID = (LinkButton)e.Item.FindControl("lblIssuanceBatchID");
     LeadsDownloadBL obj = new LeadsDownloadBL();
     clsMailFormats format = new clsMailFormats();
     DataSet ds = obj.GetLeadsIssuedDetails(lblIssuanceBatchID.Text);
     //string text = string.Empty;
     //text = format.DownloadLeadInfoDetails(ref text, ds.Tables[0]);
     //lblMultiListMail.Visible = true;
     //lblMultiListMail.Text = text;
     //MpeListMail.Show();
     DataSetToExcel.Convert(ds, Response, "LeadsHistory" + lblIssuanceBatchID.Text);
 }
    private void GetLeadsDownloadHistory()
    {
        LeadsDownloadBL objLeadsDownloadBL = new LeadsDownloadBL();

        DataSet dsStateAllocation = objLeadsDownloadBL.GetLeadsDownloadUploadHistory(ddlVehicleType.SelectedItem.Value);

        rptrDownload.DataSource = dsStateAllocation.Tables[0];
        rptrDownload.DataBind();
    }