using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;

public partial class Admin_PendingAccountRequest : System.Web.UI.Page
{
    string transactionid;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["AdminEMAILID"] == null)
            {
                Response.Redirect("AdminLogin.aspx");
            }
            if (!IsPostBack)
            {
                PanCard.Visible = false;
                //DigitalSignature.Visible = false;
                //LIC.Visible = false;
                BindDdlForDistributorFrmTo();
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }

    private void BindDdlForDistributorFrmTo()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[] { };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "uspGetDistributor", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlDSId.DataSource = ds;
                ddlDSId.DataTextField = "username";

                ddlDSId.DataValueField = "loginid";
                ddlDSId.DataBind();
                ddlDSId.Items.Insert(0,new ListItem("Select", "0"));

                
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem. Please try again');"), true);
            throw (ex);
        }
    }
    protected void ddl_ServiceType_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (ddl_ServiceType.SelectedItem.ToString().Equals("Agent"))
            {
                PanCard.Visible = true;
                //DigitalSignature.Visible = false;
                //LIC.Visible = false;
                BindGrid();
            }
            
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    private void BindGrid()
    {
        SqlParameter[] BindGridPanCard = new SqlParameter[]
        {
            new SqlParameter("@Flag",1)
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_ProcessForAgentCreation", BindGridPanCard);
        if (ds.Tables[0].Rows.Count > 0)
        {
            gvPancardReport.DataSource = ds;
            gvPancardReport.DataBind();
            lblerror.Visible = false;
        }
        else
        {
            lblerror.Visible = true;
            lblerror.Text = "No Data Available";
            lblerror.ForeColor = Color.Red;
            gvPancardReport.Visible = false;
        }
    }
    protected void btn_PancardRequestAccept_Click(object sender, EventArgs e)
    {
        try
        {
            bool flag = true;
            foreach (GridViewRow gvreport in this.gvPancardReport.Rows)
            {
                if (((CheckBox)gvreport.FindControl("chkbox")).Checked)
                {
                    flag = false;
                    string referenceno = Convert.ToString(gvPancardReport.DataKeys[gvreport.RowIndex][0]);
                    SqlParameter[] AcceptRequestPanCard = new SqlParameter[]
                    {
                        new SqlParameter("@Flag",2),
                        new SqlParameter("@RequestId",referenceno),
                        new SqlParameter("@Remark",""),
                        new SqlParameter("@dsId",ddlDSId.SelectedValue)
                    };
                    DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_ProcessForAgentCreation", AcceptRequestPanCard);
                    if (ds.Tables[0].Rows.Count>0)
                    {
                        //CommonFunction objcommonfun = new CommonFunction();
                        //string sms = "Your ID is created MPIN is " + ds.Tables[0].Rows[0]["username"].ToString() + "- Pass: "+ ds.Tables[0].Rows[0]["password"].ToString() + " Use Format as VUS<space>(M for Mobile D for DTH)M<space>OP Code<space>Mob No<space>Amount<space>MPIN send to 8082556631";
                        //objcommonfun.SendSMSByAdmin(ds.Tables[0].Rows[0]["MobileNo"].ToString(), sms, ds.Tables[0].Rows[0]["username"].ToString(), ds.Tables[0].Rows[0]["password"].ToString());
                    }
                } 
                
            }
            if (flag)
            {
                lblerror.Text = "Please Select Any One CheckBox";
                lblerror.ForeColor = Color.Red;
                lblerror.Visible = true;
            }
            else
            {
                BindGrid();
                lblerror.Text = "Request Approved Successfully";
                lblerror.ForeColor = Color.Blue;
                lblerror.Visible = true;
            }
        }
        catch (Exception ev)
        {
            throw (ev);
        }
    }
    protected void btn_PancardRequestDecline_Click(object sender, EventArgs e)
    {
        //    try
        //    {
        //        bool flag = true;
        //        bool textboxDecPanCard = false;
        //        foreach (GridViewRow gdrvw in this.gvPancardReport.Rows)
        //        {
        //            if (((CheckBox)gdrvw.FindControl("chkbox")).Checked)
        //            {
        //                flag = false;
        //                TextBox txt_Decline = (TextBox)gdrvw.FindControl("txt_DeclineReasion");
        //                if (txt_Decline.Text == "")
        //                {
        //                    textboxDecPanCard = true;                      
        //                }
        //                else
        //                {
        //                    string referenceno = Convert.ToString(gvPancardReport.DataKeys[gdrvw.RowIndex][0]);
        //                    SqlParameter[] AcceptRequestPanCard = new SqlParameter[]
        //                    {
        //                        new SqlParameter("@ServiceType","Pan Card"),
        //                        new SqlParameter("@Status","Refunded"),
        //                        new SqlParameter("@RefrenceNo",referenceno),
        //                        new SqlParameter("@Decline",txt_Decline),
        //                    };
        //                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_GetPancardReport", AcceptRequestPanCard);                       

        //                }
        //            } BindGrid();
        //        }
        //        if (flag)
        //        {
        //            lblerror.Text = "Please Select Any One Checkbox";
        //            lblerror.ForeColor = Color.Red;
        //            lblerror.Visible = true;
        //        }
        //        else if (textboxDecPanCard)
        //        {
        //            lblerror.Text = "Please Enter The Reasion";
        //            lblerror.ForeColor = Color.Red;
        //            lblerror.Visible = true;
        //        }
        //        else
        //        {
        //            lblerror.Text = "Request Decline Successfully";
        //            lblerror.ForeColor = Color.Blue;
        //            lblerror.Visible = true;
        //        }
        //    }
        //    catch (Exception ev)
        //    {
        //        throw (ev);
        //    }
        }
        private void getdetails_digitalsignature()
    {
        SqlParameter[] param = new SqlParameter[]
        {
            
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_DigitalSignaturePendingRequests", param);
        if (ds.Tables[0].Rows.Count != 0)
        {
            //gvDigitalsignature.DataSource = ds;
            //gvDigitalsignature.DataBind();
            lblerror.Visible = false;
        }
        else
        {
            lblerror.Visible = true;
            lblerror.Text = "No Data Available";
            lblerror.ForeColor = Color.Red;
           // gvDigitalsignature.Visible = false;
        }
    }
    protected void btn_DSCRequest_Accept_Click(object sender, EventArgs e)
    {
        //try
        //{
        //    bool flag = true;
        //    foreach (GridViewRow gvreportDSC in this.gvDigitalsignature.Rows)
        //    {
        //        if (((CheckBox)gvreportDSC.FindControl("chkboxDSC")).Checked)
        //        {
        //            flag = false;
        //            string refnum = Convert.ToString(gvDigitalsignature.DataKeys[gvreportDSC.RowIndex][0]);
        //            string CurrentLevel = Convert.ToString(gvDigitalsignature.DataKeys[gvreportDSC.RowIndex][1]);
        //            SqlParameter[] approverequest = new SqlParameter[]
        //            {
        //              new SqlParameter("@currentlevel",CurrentLevel),
        //              new SqlParameter("@ReferenceNo",refnum),
        //              //new SqlParameter ("@Status","Success")
        //            };
        //            DataSet objdataset = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udpApproveRequestDigitalSignature", approverequest);
        //            getdetails_digitalsignature();
        //            lblerror.Text = "Approved Sucessfully";
        //            lblerror.ForeColor = Color.Blue;
        //        }                
        //    }
        //    if (flag)
        //    {
        //        lblerror.Text = "Please Select Any One Checkbox";
        //        lblerror.ForeColor = Color.Red;
        //        lblerror.Visible = true;
        //    }
        //    else
        //    {
        //        lblerror.Text = "Request Approved Successfully";
        //        lblerror.ForeColor = Color.Blue;
        //        getdetails_digitalsignature();
        //        lblerror.Visible = true;
        //    }
            
        //}
        //catch(Exception ex)
        //{
        //    lblerror.Text = "There is some Technical Problem.Please try Again";
        //    lblerror.ForeColor = Color.Red;
        //    lblerror.Visible = true;
        //    throw (ex);
        //}
    }
    protected void btn_DSCRequest_Decline_Click(object sender, EventArgs e)
    {
        //try
        //{
        //    bool flag = true;
        //    bool textboxDecPanCard = false;
        //    foreach (GridViewRow gvreportDSC in this.gvDigitalsignature.Rows)
        //    {
        //        if (((CheckBox)gvreportDSC.FindControl("chkboxDSC")).Checked)
        //        {
        //            flag = false;
        //            TextBox txt_Decline = (TextBox)gvreportDSC.FindControl("txt_DeclineReasionDSC");
        //            if (txt_Decline.Text == "")
        //            {
        //                textboxDecPanCard = true;
        //            }
        //            else
        //            {
        //                string lblReferenceNo = Convert.ToString(gvDigitalsignature.DataKeys[gvreportDSC.RowIndex][0]);
        //                string CurrentLevel = Convert.ToString(gvDigitalsignature.DataKeys[gvreportDSC.RowIndex][1]);
        //                string AmountRequest = Convert.ToString(gvDigitalsignature.DataKeys[gvreportDSC.RowIndex][2]);
        //                SqlParameter[] param_del = new SqlParameter[]
        //                {
        //                    new SqlParameter("@refrenceno",lblReferenceNo),
        //                    new SqlParameter("@Service","Digital Signature"),
        //                    new SqlParameter("@REQUEST_AMOUNT",AmountRequest),
        //                    new SqlParameter("@AgentID",CurrentLevel),
        //                    new SqlParameter("@Operator",""),
        //                };
        //                SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_Refund_Insurance_DigitalSignature", param_del);
        //            }
        //        } getdetails_digitalsignature();
        //    }
        //    if (flag)
        //    {
        //        lblerror.Text = "Please Select Any One Checkbox";
        //        lblerror.ForeColor = Color.Red;
        //        lblerror.Visible = true;
        //    }
        //    else if (textboxDecPanCard)
        //    {
        //        lblerror.Text = "Please Enter The Reasion";
        //        lblerror.ForeColor = Color.Red;
        //        lblerror.Visible = true;
        //    }
        //    else
        //    {
        //        lblerror.Text = "Request Decline Successfully";
        //        lblerror.ForeColor = Color.Blue;
        //        lblerror.Visible = true;
        //    }
        //}
        //catch (Exception ev)
        //{
        //    lblerror.Text = "There is some Technical Problem.Please try Again";
        //    lblerror.ForeColor = Color.Red;
        //    lblerror.Visible = true;
        //    throw (ev);
        //}
    }
    private void getdetails_Insurance()
    {
        SqlParameter[] param = new SqlParameter[]
        {
            
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_Insurance_Pending_Requests", param);
        if (ds.Tables[0].Rows.Count != 0)
        {
            //gvInsurance.DataSource = ds;
            //gvInsurance.DataBind();
            //gvInsurance.Visible = true;
            lblerror.Visible = false;
        }
        else
        {
            lblerror.Visible = true;
            lblerror.Text = "No Data Available";
            lblerror.ForeColor = Color.Red;
        }
    }
    protected void btn_Request_Accept_Click(object sender, EventArgs e)
    {
        //try
        //{
        //    bool flag = true;
        //    foreach (GridViewRow gvreport in this.gvInsurance.Rows)
        //    {
        //        if (((CheckBox)gvreport.FindControl("chkboxLic")).Checked)
        //        {
        //            flag = false;
        //            string referenceno = Convert.ToString(gvInsurance.DataKeys[gvreport.RowIndex][0]);
        //            string lblCurrentlevel = Convert.ToString(gvInsurance.DataKeys[gvreport.RowIndex][1]);
        //            SqlParameter[] approverequest = new SqlParameter[]
        //            {
        //              new SqlParameter("@currentlevel",lblCurrentlevel),
        //              new SqlParameter("@ReferenceNo",referenceno)
        //            };
        //            DataSet objdataset = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udpApproveRequestInsurance", approverequest);
        //        }
                
        //    }
        //    if (flag)
        //    {
        //        lblerror.Text = "Please Select Any One CheckBox";
        //        lblerror.ForeColor = Color.Red;
        //        lblerror.Visible = true;
        //    }
        //    else
        //    {
        //        getdetails_Insurance();
        //        lblerror.Text = "Request Approved Successfully";
        //        lblerror.ForeColor = Color.Blue;
        //        lblerror.Visible = true;
        //    }
        //}
        //catch (Exception ev)
        //{
        //    lblerror.Text = "There is some Technical Problem.Please try Again";
        //    lblerror.ForeColor = Color.Red;
        //    lblerror.Visible = true;
        //    throw (ev);
        //}
    }
    protected void btn_RequestLic_Decline_Click(object sender, EventArgs e)
    {
        //try
        //{
        //    bool flag = true;
        //    bool textboxLic = false;
        //    foreach (GridViewRow gvreportLic in this.gvInsurance.Rows)
        //    {
        //        if (((CheckBox)gvreportLic.FindControl("chkboxLic")).Checked)
        //        {
        //            flag = false;
        //            TextBox txt_Decline = (TextBox)gvreportLic.FindControl("txt_DeclineReasionLIC");
        //            if (txt_Decline.Text == "")
        //            {
        //                textboxLic = true;
        //            }
        //            else
        //            {
        //                string lblReferenceNo = Convert.ToString(gvInsurance.DataKeys[gvreportLic.RowIndex][0]);
        //                string CurrentLevel = Convert.ToString(gvInsurance.DataKeys[gvreportLic.RowIndex][1]);
        //                string AmountRequest = Convert.ToString(gvInsurance.DataKeys[gvreportLic.RowIndex][2]);
        //                string CompanyName = Convert.ToString(gvInsurance.DataKeys[gvreportLic.RowIndex][3]);
        //                SqlParameter[] param_del = new SqlParameter[]
        //                {
        //                    new SqlParameter("@refrenceno",lblReferenceNo),
        //                     new SqlParameter("@Service","Premium Payment"),
        //                    new SqlParameter("@REQUEST_AMOUNT",AmountRequest),
        //                    new SqlParameter("@AgentID",CurrentLevel),
        //                    new SqlParameter("@Operator",CompanyName),
        //                };
        //                SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_Refund_Insurance_DigitalSignature", param_del);
        //            }
        //            getdetails_Insurance();
        //        } 
        //    }
        //    if (flag)
        //    {
        //        lblerror.Text = "Please Select Any One Checkbox";
        //        lblerror.ForeColor = Color.Red;
        //        lblerror.Visible = true;
        //    }
        //    else if (textboxLic)
        //    {
        //        lblerror.Text = "Please Enter The Reasion";
        //        lblerror.ForeColor = Color.Red;
        //        lblerror.Visible = true;
        //    }
        //    else
        //    {
        //        lblerror.Text = "Request Decline Successfully";
        //        lblerror.ForeColor = Color.Blue;
        //        lblerror.Visible = true;
        //    }
        //}
        //catch (Exception ev)
        //{
        //    lblerror.Text = "There is some Technical Problem.Please try Again";
        //    lblerror.ForeColor = Color.Red;
        //    lblerror.Visible = true;
        //    throw (ev);
        //}
    }
}
