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;

public partial class Admin_WLNetworkControl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["AdminEMAILID"] == null)
            {
                Response.Redirect("AdminLogin.aspx");
            }
            if (!IsPostBack)
            {
                getdetails();
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    private void getdetails()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@UserType","WL"),
                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 btn_flag_Command(object sender, CommandEventArgs e)
    {
        try
        {
            Button btn = (Button)sender;
            GridViewRow rowitem = (GridViewRow)btn.Parent.Parent;
            Label loginid = (Label)rowitem.FindControl("lbl_loginid");
            SqlParameter[] approverequest = new SqlParameter[]
        {
          new SqlParameter("@LOGINID",loginid.Text.Trim()),
        };
            DataSet objdataset = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_CHANGEUSERWORKINGSTATUS", approverequest);
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }

    protected void btnActiveWlWeb_Click(object sender, EventArgs e)
    {
        bool flag = false;
        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_CHANGE_WLNetwork_WORKINGSTATUS", paramChangeLoginStatus);
                    getdetails();
                    flag = true;
                    //Label1.Text = "Working Status Changed For Web Application";
                    //Label1.ForeColor = Color.Blue;
                }
            }
            if (flag == true)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Working Status Changed For Web Application');"), true);
            }
            else if (flag == false)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Please select Check box');"), true);
            }
        }
        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 btnDeAcWlSms_Click(object sender, EventArgs e)
    {
        bool flag = false;
        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","SMS"),
                        new SqlParameter("@loginid",lbl_loginid.Text)
                    };
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_CHANGE_WLNetwork_WORKINGSTATUS", paramChangeLoginStatus);
                    getdetails();
                    flag = true;
                    //Label1.Text = "Working Status Changed For Web Application";
                    //Label1.ForeColor = Color.Blue;
                }
            }
            if (flag == true)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Working Status Changed For SMS Application');"), true);
            }
            else if (flag == false)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Please select Check box');"), true);
            }
        }
        catch (Exception ex)
        {
            //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem. Please try again');"), true);
            throw (ex);
        }
    }
}
