using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Data;
using System.Diagnostics;

public partial class Business_Checker : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        ViewState["flg"] = 0;
        if (!IsPostBack)
        {
            //pnlControls.Visible = false;
            
            
            if (Request .QueryString ["chgId"]!=null )
            {
               
                pnl_filters.Visible = false;
                getMakerChecker();
                btnClose.Visible = true;
            }
            else
            {
                btnClose.Visible = false;
            }
            
            loadPages();
            loadRequestTypes();
            loadStatus();
            ExceptionUtility.LogException(0, "", "82", "Page_Load", "");
        }
        lblError.Text = "";
    }

    private void loadPages()
    {
        try
        {
            string DBConnection = Helper.dbConnection();

            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

            OracleCommand oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.get_configuration_pages";

            oracom.Parameters.Add("p_pages", OracleType.Cursor).Direction = ParameterDirection.Output;



            OracleDataAdapter da = new OracleDataAdapter(oracom);
            DataSet ds = new DataSet();
            da.Fill(ds);

            ddlPages.DataSource = ds;
            ddlPages.DataBind();
            ddlPages.Items.Insert(0, "------ Pages ------");
            oracon.Close();
            //ExceptionUtility.LogException(ex, "LOOKUP_GETTER.get_configuration_pages", "loadPages", "");
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.get_configuration_pages","", "loadPages", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private bool CheckVarchar(string tableName,string columnName)
    {
        try
        {
            string dataType = "";
            bool isVarchar = false;
            string DBConnection = Helper.dbConnection();

            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

            OracleCommand oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.get_column_names";
            oracom.Parameters.Add("p_table_name", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_columns", OracleType.Cursor).Direction = ParameterDirection.Output;

            oracom.Parameters["p_table_name"].Value = tableName;
            OracleDataAdapter da = new OracleDataAdapter(oracom);
            DataSet ds = new DataSet();
            da.Fill(ds);
            oracon.Close();
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["column_name"].ToString().Trim() == columnName.ToUpper())
                    {
                        dataType = ds.Tables[0].Rows[i]["data_type"].ToString();
                        if (dataType.Contains("VARCHAR2"))
                            isVarchar = true;
                    }
                }
            }
            ExceptionUtility.LogException(0, "LOOKUP_GETTER.get_column_names", "", "CheckVarchar", "tableName: " + tableName + ", columnName: " + columnName);
            return isVarchar;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.get_column_names","", "CheckVarchar", "tableName: " + tableName + ", columnName: " + columnName);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false;
        }
    }

    private void loadRequestTypes()
    {
        try
        {
            string DBConnection = Helper.dbConnection();

            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

            OracleCommand oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.get_change_type";
            oracom.Parameters.Add("p_chg_types", OracleType.Cursor).Direction = ParameterDirection.Output;

            OracleDataAdapter da = new OracleDataAdapter(oracom);
            DataSet ds = new DataSet();
            da.Fill(ds);

            ddlRequestType.DataSource = ds;
            ddlRequestType.DataBind();
            //ddlRequestType.Items.Insert(3, "------ Request Types ------");
            //ddlRequestType.SelectedIndex = 3;
            ddlRequestType.Items.Insert(0, new ListItem("------ Request Types ------", "ct_code"));

            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.get_change_type","", "loadRequestTypes", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private void loadStatus()
    {
        try
        {
            string DBConnection = Helper.dbConnection();

            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

            OracleCommand oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.get_change_status";
            oracom.Parameters.Add("p_chg_status", OracleType.Cursor).Direction = ParameterDirection.Output;

            OracleDataAdapter da = new OracleDataAdapter(oracom);
            DataSet ds = new DataSet();
            da.Fill(ds);

            ddlStatus.DataSource = ds;
            ddlStatus.DataBind();
            //ddlRequestType.Items.Insert(3, "------ Request Types ------");
            //ddlRequestType.SelectedIndex = 3;
            ddlStatus.Items.Insert(0, new ListItem("------ Status ------", "sc_code"));

            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.get_change_status","", "loadStatus", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }
    private void getMakerChecker()
    {
        string parameters = "";
        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name; 
            string DBConnection = Helper.dbConnection();

            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

            OracleCommand oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "MAKER_CHECKER_EDITOR.Get_Maker_Checker_Master";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            //oracom.Parameters.Add("p_mkt_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Input;            
            oracom.Parameters.Add("p_page_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_type", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_status", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

            if (Request.QueryString["chgId"] == null)
                oracom.Parameters["p_chg_id"].Value = OracleNumber.Null;
            else
            {
                oracom.Parameters["p_chg_id"].Value = int.Parse(Request.QueryString["chgId"]);
                parameters = "p_chg_id-" + int.Parse(Request.QueryString["chgId"]);
            }

            if (ddlPages.SelectedIndex == 0 || ddlPages.SelectedIndex == -1)
                oracom.Parameters["p_page_id"].Value = OracleNumber.Null;
            else
            {
                parameters = parameters + ":p_page_id-" + ddlPages.SelectedItem .Text ;
                oracom.Parameters["p_page_id"].Value = ddlPages.SelectedValue;
            }

            if (ddlRequestType.SelectedIndex == 0 || ddlRequestType.SelectedIndex == -1)
                oracom.Parameters["p_chg_type"].Value = OracleNumber.Null;
            else
            {
                parameters = parameters + ":p_chg_type-" + ddlRequestType.SelectedItem .Text ;
                oracom.Parameters["p_chg_type"].Value = ddlRequestType.SelectedValue;
            }

            if (ddlStatus.SelectedIndex == 0 || ddlStatus.SelectedIndex == -1)
                oracom.Parameters["p_chg_status"].Value = OracleNumber.Null;
            else
            {
                parameters = parameters + ":p_chg_status-" + ddlStatus.SelectedItem.Text;
                oracom.Parameters["p_chg_status"].Value = ddlStatus.SelectedValue;
            }
            //oracom.Parameters["p_changed_rec_id"].Value = OracleString .Null;
            oracom.Parameters["p_lang"].Value = "EN";
            parameters = parameters + ":p_lang-EN";// +ddlStatus.SelectedItem.Text;
            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();
            //oracom.Parameters["p_mkt_code"].Value = OracleNumber.Null;

            OracleDataAdapter da = new OracleDataAdapter(oracom);
            DataSet ds = new DataSet();
            da.Fill(ds);

            oracon.Close();

            GridView1.DataSource = ds;
            GridView1.DataBind();
            if(currentMethod .Contains ("Button1_Click"))
                ExceptionUtility.LogException(0, "MAKER_CHECKER_EDITOR.Get_Maker_Checker_Master", "480.1", "getMakerChecker", parameters);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "MAKER_CHECKER_EDITOR.Get_Maker_Checker_Master","480.1", "getMakerChecker", parameters );
            GridView1.DataSource = null;
            GridView1.DataBind();
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private void getMakerCheckerDetails(int chgId)
    {
        try
        {
            ViewState["count"] = null;
            string DBConnection = Helper.dbConnection();

            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

            OracleCommand oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "MAKER_CHECKER_EDITOR.Get_Maker_Checker_Detail";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            //oracom.Parameters.Add("p_mkt_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Input;
            //oracom.Parameters.Add("p_changed_rec_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            //oracom.Parameters.Add("p_page_size", OracleType.Number).Direction = ParameterDirection.Input;
            //oracom.Parameters.Add("p_page_num", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            //oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

            oracom.Parameters["p_chg_id"].Value = chgId;
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();
            //oracom.Parameters["p_page_size"].Value = pageSize;
            //oracom.Parameters["p_page_num"].Value = pageNumber;
            //oracom.Parameters["p_mkt_code"].Value = OracleNumber.Null;

            OracleDataAdapter da = new OracleDataAdapter(oracom);
            DataSet ds = new DataSet();
            da.Fill(ds);
            //ViewState["count"] = ds.Tables[0].Rows.Count;
            oracon.Close();
            
            GridView2.DataSource = ds;            
            GridView2.DataBind();
           
            if(ds.Tables[0].Rows[0]["checker_notes"].ToString().Trim().Length !=0)
            txtCheckerNotes.Text = ds.Tables[0].Rows[0]["checker_notes"].ToString();
            ExceptionUtility.LogException(0, "MAKER_CHECKER_EDITOR.Get_Maker_Checker_Detail", "481.1", "getMakerCheckerDetails", "chgId- " + chgId+":p_lang-EN"); 
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "MAKER_CHECKER_EDITOR.Get_Maker_Checker_Detail", "481.1", "getMakerCheckerDetails", "chgId- " + chgId + ":p_lang-EN"); 
            GridView2.DataSource = null;
            GridView2.DataBind();
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

   

    private bool decline(int chgId, string tableName, string columnName, string changedRecId, int chgType, ref string error)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

            OracleCommand oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "MAKER_CHECKER_EDITOR.decline_maker_checker";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;            
            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_table_name", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_column_name", OracleType.VarChar).Direction = ParameterDirection.Input;            
            oracom.Parameters.Add("p_changed_rec_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_type", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checker_notes", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

            
            oracom.Parameters["p_chg_id"].Value = chgId;
            oracom.Parameters["p_table_name"].Value = tableName;
            oracom.Parameters["p_column_name"].Value = columnName;            
            oracom.Parameters["p_changed_rec_id"].Value = changedRecId;
            oracom.Parameters["p_chg_type"].Value = chgType;
            oracom.Parameters["p_checker_notes"].Value = txtCheckerNotes.Text;
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

            oracom.ExecuteNonQuery();
            oracon.Close();
            string a = oracom.Parameters["p_res_code"].Value.ToString();
            error = oracom.Parameters["p_res_msg"].Value.ToString();
            if (a == "0")
            {
                ExceptionUtility.LogException(0, "MAKER_CHECKER_EDITOR.decline_maker_checker", "472.1", "decline", "chgId: " + chgId + ", tableName: " + tableName + ", columnName: " + columnName + ", changedRecId: " + changedRecId + ", chgType: " + chgType);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(0, "MAKER_CHECKER_EDITOR.decline_maker_checker", "472.1", "decline", "chgId: " + chgId + ", tableName: " + tableName + ", columnName: " + columnName + ", changedRecId: " + changedRecId + ", chgType: " + chgType);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "MAKER_CHECKER_EDITOR.decline_maker_checker","472.1", "decline", "chgId: " + chgId + ", tableName: " + tableName + ", columnName: " + columnName + ", changedRecId: " + changedRecId + ", chgType: " + chgType);
            return false;
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private bool approve(int chgId, string tableName, string changedRecId,ref string error)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

            OracleCommand oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "MAKER_CHECKER_EDITOR.approve_maker_checker";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_table_name", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_changed_rec_id", OracleType.VarChar).Direction = ParameterDirection.Input;         
            oracom.Parameters.Add("p_checker_notes", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        
            oracom.Parameters["p_chg_id"].Value = chgId;
            oracom.Parameters["p_table_name"].Value = tableName;
            oracom.Parameters["p_changed_rec_id"].Value = changedRecId;                   
            oracom.Parameters["p_checker_notes"].Value = ViewState["checkerNotes"];
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

            oracom.ExecuteNonQuery();
            oracon.Close();
            string a = oracom.Parameters["p_res_code"].Value.ToString();
            error = oracom.Parameters["p_res_msg"].Value.ToString();
            if (a == "0")
            {
                ExceptionUtility.LogException(0, "", "471.2", "approve", "chgId: " + chgId + ", tableName: " + tableName + ",  changedRecId: " + changedRecId);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "", "471.2", "approve", "chgId: " + chgId + ", tableName: " + tableName + ",  changedRecId: " + changedRecId);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "","471.2", "approve", "chgId: " + chgId + ", tableName: " + tableName + ",  changedRecId: " + changedRecId);
            return false;
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

       
        if (e.CommandName.Equals("vd"))
        {
            ExceptionUtility.LogException(0, "", "82.481", "GridView1_RowCommand.ViewDetails", "");//chgId: " + chgId + ", tableName: " + tableName + ",  changedRecId: " + changedRecId);
            txtCheckerNotes.Text = "";
            pnlControls.Visible = true;
            pnlDetails.Visible = true;
            //pnlGrid.Enabled = false;
            int index = int.Parse(e.CommandArgument.ToString());
            int chgId = int.Parse(GridView1.DataKeys[index].Value.ToString());
            ViewState["chgID"] = chgId;
            getMakerCheckerDetails(chgId);
           

            if (Request.QueryString["chgID"] != null )
                pnlControls.Visible = false;
            if (int.Parse(GridView1.Rows[index].Cells[10].Text) == 1 || int.Parse(GridView1.Rows[index].Cells[10].Text) == 2)
            {
                btnApprove.Visible = false;
                btnCancel.Visible = false;
                btnCancel1.Visible = false;
            }
            else
            {
                btnApprove.Visible = true ;
                btnCancel.Visible = true ;
                btnCancel1.Visible = true ;
            }
            
           
        }

    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Visible = false;
            e.Row.Cells[3].Visible = false;
            e.Row.Cells[8].Visible = false;
            e.Row.Cells[10].Visible = false;
        }
    }


    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        ExceptionUtility.LogException(0, "", "", "GridView1_PageIndexChanging", "");
        getMakerChecker();
        
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
           // chgType = DataBinder.Eval(e.Row.DataItem, "chg_type").ToString ();
           
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ExceptionUtility.LogException(0, "", "82.480", "Button1_Click", "");
        getMakerChecker();
    }
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        string error = "";
        bool temp = false;
        int chgID = 0, chgType = 0;
        string pageName = "", tableName = "", changedRecId = "";

        ViewState["checkerNotes"] = txtCheckerNotes.Text;
        getMakerCheckerDetails(int.Parse (ViewState["chgID"].ToString ()));
       
        foreach(GridViewRow row in GridView2.Rows )
        {
             chgID = int.Parse(row.Cells[1].Text);                    
             pageName = row.Cells[3].Text;                   
             changedRecId = row.Cells[10].Text;
             chgType = int.Parse(row.Cells[11].Text);
             tableName = row.Cells[4].Text.Trim();
             if (chgType != 0)
             {
                 ExceptionUtility.LogException(0, "", "82.471", "btnApprove_Click", "");
                 temp = approve(chgID, tableName, changedRecId, ref error);
                 if (temp)
                     lblError.Text = "Your request has been processed successfully";
                 else
                 {
                     lblError.Text = error;
                     if (error.Contains("Exception - ORA-00001: unique constraint"))
                     {
                         lblError.Text = "Please note this record already exists";
                         pnlDetails.Visible = false;
                         pnlControls.Visible = false;
                         //getMakerCheckerDetails(chgID, true);
                         return;
                     }
                 }
             }
        }
        if (chgType == 0)
        {
            temp = approve(chgID, tableName, changedRecId, ref error);
            if (temp)
                lblError.Text = "Your request has been processed successfully";
            else
            {
                lblError.Text = error;
                if (error.Contains("Exception - ORA-00001: unique constraint"))
                {
                    lblError.Text = "Please note this record already exists";
                    pnlDetails.Visible = false;
                    pnlControls.Visible = false;
                    //getMakerCheckerDetails(chgID, true);
                    return;
                }
            }
        }           
                   
        getMakerCheckerDetails(chgID);
        
        txtCheckerNotes.Text = "";
        pnlControls.Visible = false;
        pnlDetails.Visible = false;
        //getMakerChecker(int.Parse(ddlPages .SelectedValue), ddlRequestType .SelectedValue ,ddlStatus .SelectedValue);
        getMakerChecker();
       
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        string error = "";
        int chgID = 0, chgType = 0;
        string tableName = "", columnName = "", changedRecId = "";
        bool temp=false ;
        foreach (GridViewRow gvr in GridView2.Rows)
        {
            chgID = int.Parse(gvr.Cells[1].Text.Trim ());
            tableName = gvr.Cells[4].Text.Trim();
            columnName = gvr.Cells[5].Text.Trim();            
            changedRecId = gvr.Cells[10].Text;
            chgType = int.Parse(gvr.Cells[11].Text);
            //if (chgType != 1 && !tableName.Contains("atm_data_table") && !columnName.Contains("modify_date"))
            ExceptionUtility.LogException(0, "", "82.472", "btnCancel_Click", "");
                temp = decline(chgID, tableName, columnName, changedRecId, chgType, ref error);
            if (temp)
            {
                lblError.Text = "Request rejected";
               
            }
            else
            {
                lblError.Text = error;
                break;
            }
            getMakerCheckerDetails(chgID);
        }
        txtCheckerNotes.Text = "";
        pnlControls.Visible = false;
        pnlDetails.Visible = false;
        getMakerChecker();
       // getMakerChecker(int.Parse(ddlPages .SelectedValue), ddlRequestType .SelectedValue , ddlStatus .SelectedValue);
    }

   
    protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Visible = false;
            e.Row.Cells[2].Visible = false;
            e.Row.Cells[3].Visible = false;
            e.Row.Cells[8].Visible = false;
            e.Row.Cells[9].Visible = false;
            e.Row.Cells[11].Visible = false;
            e.Row.Cells[13].Visible = false;
            e.Row.Cells[16].Visible = false;
        }
    }
    protected void btnCancel1_Click(object sender, EventArgs e)
    {
        pnlControls.Visible = false;
        pnlDetails.Visible = false;
        ExceptionUtility.LogException(0, "", "", "btnCancel1_Click", "");
    }
    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        
        if (e.CommandName.Contains ("vd"))
        {
            ExceptionUtility.LogException(0, "", "", "GridView2_RowCommand.ViewDetails", "");
            Session["eventID"] = null;
            int index = int.Parse(e.CommandArgument.ToString());
            string URL = GridView2.Rows[index].Cells[3].Text;
            string[] newURL = URL.Split('/');
            URL = newURL[1];
            Session["eventID"] = GridView2.Rows[index].Cells[10].Text;

            string popup = "<script language='javascript'>" +
                            "window.open('"+URL+"');" +
                            "</script>";           
            ClientScript.RegisterStartupScript(this.GetType(), "", popup, false);

        }
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                if (e.Row.Cells[i].Text.Length == 0 || e.Row.Cells[i].Text.Equals("&nbsp;") || e.Row.Cells[i].Text.Equals("") || e.Row.Cells[i].Text.Equals(string.Empty))
                {
                    e.Row.Cells[i].Text = string.Empty;
                }
            }
            int type = int.Parse(e.Row.Cells[11].Text);
            int status = int.Parse(e.Row.Cells[13].Text);
            if (type == 0 || type ==1)
            {
                e.Row.Cells[15].Enabled = false;
            }
            else
            {
                e.Row.Cells[15].Enabled = true;
            }
            if (status == 0)
            {
                e.Row.Cells[15].Enabled = true;
            }
            else
            {
                e.Row.Cells[15].Enabled = false;
            }
        }
    }
    protected void btnClose_Click(object sender, EventArgs e)
    {

    }
    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView2.PageIndex = e.NewPageIndex;
        ExceptionUtility.LogException(0, "", "", "GridView2_PageIndexChanging", "");
        getMakerCheckerDetails(int.Parse(ViewState["chgID"].ToString()));
    }
}