using System;
using System.Collections;
using System.Collections.Specialized;
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.IO;
using RKLib.ExportData;

public partial class RegisteredMDS : System.Web.UI.Page
{
    string id_statusparam;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["AdminEMAILID"] == null)
            {
                Response.Redirect("AdminLogin.aspx");
            }
            if (!IsPostBack)
            {
                getdetails();

                if (Request.QueryString.AllKeys.Contains("var"))
                {
                    // The query string parameter "parameterName" exists.
                    string value = Request.QueryString["var"];
                    // Further processing with 'value'
                    if (value.ToLower() == "master distributor")
                    {
                        ddlUserInfo.SelectedIndex = 2;
                    }
                }
                //NameValueCollection queryString = stringhelpers.DecryptQueryString(Request.QueryString.ToString());
                //if (queryString != null)
                //{
                //    if (queryString["var"].Equals("Master Distributor"))
                //    {
                //        ddlUserInfo.SelectedIndex = 2;
                //    }
                //}
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    private void getdetails()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@UserType","MDS"),
                new SqlParameter("@Date","")
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_getregisteredMDSdetailsNew", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('No Data Available');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem. Please try again');"), true);
        }
    }  
    
    protected void btnWLChangeStatus_Click(object sender, EventArgs e)
    {
        try
        {
            foreach (GridViewRow gvdr in this.GridView1.Rows)
            {
                if (((CheckBox)gvdr.FindControl("chk1")).Checked == true)
                {
                    Label lbl_loginid = (Label)gvdr.FindControl("lbl_loginid");

                    SqlParameter[] paramChangeLoginStatus = new SqlParameter[]
                    {
                        new SqlParameter("@Portal","Web"),
                        new SqlParameter("@loginid",lbl_loginid.Text)
                    };
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_CHANGEUSERWORKINGSTATUS", paramChangeLoginStatus);
                    getdetails();
                    Label1.Text = "Working Status Changed For Web Application";
                    Label1.ForeColor = Color.Blue;
                }
            }
        }
        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 ddlUserInfo_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (ddlUserInfo.SelectedItem.Text.Equals("White Label"))
            {
                Response.Redirect("RegisteredWL.aspx?var=White Label") ;
            }
            else if (ddlUserInfo.SelectedItem.Text.Equals("Master Distributor"))
            {
                Response.Redirect("RegisteredMDS.aspx?var=Master Distributor");
            }
            else if (ddlUserInfo.SelectedItem.Text.Equals("Distributor"))
            {
                Response.Redirect("registereddistributor.aspx?var=Distributor") ;
            }
            else if (ddlUserInfo.SelectedItem.Text.Equals("Agent"))
            {
                Response.Redirect("ViewAgents.aspx?var=Agent");
            }
            else if (ddlUserInfo.SelectedItem.Text.Equals("Advance Search"))
            {
                Response.Redirect("AdvanceSearch.aspx?var=Advance Search");
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
}
