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.IO;
using System.Text;


public partial class Admin_airtoegen : System.Web.UI.Page
{
    string id_statusparam;
    string transactionid;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["AdminEMAILID"] == null)
            {
                Response.Redirect("AdminLogin.aspx");
            }
            if (!IsPostBack)
            {
                BindCategory();
                BindGrid();
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }    
    }
    protected void btnSetCommission_Click(object sender, EventArgs e)
    {
        try
        {
            bool flag = true;
            foreach (GridViewRow gvdr in this.gvCommissionsheet.Rows)
            {
                if (((CheckBox)gvdr.FindControl("chkbox")).Checked)
                {
                    flag = false;
                    string operatorID = Convert.ToString(gvCommissionsheet.DataKeys[gvdr.RowIndex][0]);                    
                    TextBox txt_commission = (TextBox)gvdr.FindControl("txtCommission");
                    SqlParameter[] param_setcommission = new SqlParameter[]
                    {
                        new SqlParameter("@serviceType","Online"),
                        new SqlParameter("@userType",ddlUserType.SelectedItem.Text.Trim()),
                        new SqlParameter("@comissionCategory",ddlCategory.SelectedValue),
                        new SqlParameter("@operator",operatorID),
                        new SqlParameter("@comission",txt_commission.Text.Trim()),
                    };
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_setComissionCategory", param_setcommission);
                }
            }
            if (flag)
            {
                Label3.Text = "Please select any checkbox";
                Label3.ForeColor = Color.Red;
            }
            else
            {
                Label3.Text = "Record Approved Successfully";
                Label3.ForeColor = Color.Blue;
                BindGrid();
            }
        }
        catch (Exception ex)
        {
            throw(ex);
        }
    }

    private void BindCategory()
    {
        try
        {
            SqlParameter[] BindCategory = new SqlParameter[]
            {             
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_BindCategory", BindCategory);
            if (ds.Tables[0].Rows.Count != 0)
            {
                ddlCategory.DataSource = ds;
                ddlCategory.DataTextField = "Category";
                ddlCategory.DataValueField = "Category_id";
                ddlCategory.Items.Clear();
                ddlCategory.DataBind();
            }
        }
        catch (Exception ex)
        {

        }
    }

    private void BindGrid()
    {
        SqlParameter[] param = new SqlParameter[]
        {
           new SqlParameter("@serviceType","Online"),
           new SqlParameter("@userType",ddlUserType.SelectedItem.Text),
           new SqlParameter("@comissionCategory",ddlCategory.SelectedValue)
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_GetCommissionDetails", param);
        if (ds.Tables[0].Rows.Count != 0)
        {
            gvCommissionsheet.DataSource = ds;
            gvCommissionsheet.DataBind();
        }
        else
        {
            Label3.Text = "No Data Available with " + ddlCategory.SelectedItem.Text.Trim() + " Category";
            Label3.ForeColor = Color.Red;
            gvCommissionsheet.Visible = false;
        }
    }
    protected void btnShow_Click(object sender, EventArgs e)
    {
        try
        {
            BindGrid();
        }
        catch (Exception ex)
        {
            throw (ex);
        }    
    }
    
}
        

        
    

