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 Distributor_ActiveAgent : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                getmy_network_details();
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    private void getmy_network_details()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@loginid",Session["LOGINID"].ToString()),
                new SqlParameter("@ActiveINactive","Active"),
                new SqlParameter ("@checked", "0"),
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_setActiveInactiveAgent", param);
            if (ds.Tables[0].Rows.Count != 0)
            {
                gvActiveAgent.DataSource = ds;
                gvActiveAgent.DataBind();
            }
            else
            {
                //Label1.Text = "No Data Available";
                //Label1.ForeColor = Color.Red;
            }
        }
        catch (Exception ex)
        {
            //Server.Transfer("Error.aspx?id=" + ex + "");
            throw (ex);
        }
    }

    protected void btnActive_Click(object sender, EventArgs e)
    {
        try
        {
            bool flag = true;
            foreach (GridViewRow gvdr in this.gvActiveAgent.Rows)
            {
                if (((CheckBox)gvdr.FindControl("chkbox")).Checked)
                {
                    flag = false;
                    string LoginID = Convert.ToString(gvActiveAgent.DataKeys[gvdr.RowIndex][0]);

                    //int fundtransfer_id;
                    //= (Label)gvdr.FindControl("lblOperator");
                    //TextBox txt_commission = (TextBox)gvdr.FindControl("txtCommission");
                    //lbl_Operator.Text= gvdr.
                    //CustomersGridView.DataKeys[index].Value.ToString()

                    SqlParameter[] param_setActiveInactive = new SqlParameter[]
                    {   
                        //new SqlParameter("@loginid",Session["LOGINID"].ToString()),
                        new SqlParameter("@ActiveINactive","Active"),
                        new SqlParameter("@loginid",LoginID),
                        new SqlParameter ("@checked", "1"),
                        //new SqlParameter("@userType",ddlUserType.SelectedItem.Text.Trim()),
                        //new SqlParameter("@comissionCategory",ddlCategory.SelectedValue),
                        //new SqlParameter("@comission",txt_commission.Text.Trim()),
                    };
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_setActiveInactiveAgent", param_setActiveInactive);
                }
            }
            if (flag)
            {
                lblerror.Text = "Please select any one checkbox";
                lblerror.ForeColor = Color.Red;
            }
            else
            {
                lblerror.Text = "Agent Activate Successfully";
                lblerror.ForeColor = Color.Blue;
                getmy_network_details();
               // BindGrid();
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }
        getmy_network_details();
    }

    protected void btnnew_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddAgent.aspx");
    }
    protected void gvActiveAgent_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            gvActiveAgent.PageIndex = e.NewPageIndex;
            getmy_network_details();
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
}
