using System;
using System.Collections;
using System.Configuration;
using System.Data;
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.Data.OracleClient;
using System.Threading;
using System.Diagnostics;

public partial class Business_ATM : System.Web.UI.Page
{
    public int page_id = 0;
    public string table_name = "";
    public string url = "";
    string accountLength = "";
    static int intCount = 0;
    //private bool btn_clicked = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        //TextBox1.Attributes.Add("onKeyPress", "return KeyPressFuncIsWholeNumber();");
        //TextBox2.Attributes.Add("onKeyPress", "return KeyPressFuncIsWholeNumber();");
       // btn_clicked = false;
        table_name = "atm_data_table";

        url = HttpContext.Current.Request.Url.AbsolutePath;
        string[] urlArr = url.Split('/');
        url = urlArr[2] + "/" + urlArr[3];
        page_id = loadPageIDs(url);
        
        if (!IsPostBack)
        {

            btnSave.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSave, null) + ";");
            
            TextBox1.Attributes.Add("onKeyPress", "return KeyPressFuncNotSpecialCharecter();");
            TextBox2.Attributes.Add("onKeyPress", "return KeyPressFuncNotSpecialCharecter();");
            TextBox3.Attributes.Add("onKeyPress", "return KeyPressFuncNotSpecialCharecter();");
            TextBox4.Attributes.Add("onKeyPress", "return KeyPressFuncNotSpecialCharecter();");
            TextBox5.Attributes.Add("onKeyPress", "return KeyPressFuncNotSpecialCharecter();");
            TextBox6.Attributes.Add("onKeyPress", "return KeyPressFuncNotSpecialCharecter();");
            //btnSave.Attributes.Add("onclick","this.disabled=true;"+ClientScript.GetPostBackEventReference (btnSave ).ToString ());
            //btnSave.Enabled = true;

            loadBranches();
            loadATMTypes();
            loadATMGroups();
            this.pnl_confirmation.Visible = false;
            ExceptionUtility.LogException(0, "", "3", "Page_Load", "");
        }
        accountLength = getParamByID("300");
        TextBox1.MaxLength = int.Parse (accountLength);
        TextBox2.MaxLength = int.Parse(accountLength);
        TextBox3.MaxLength = int.Parse(accountLength);
        TextBox4.MaxLength = int.Parse(accountLength);
        TextBox5.MaxLength = int.Parse(accountLength);
        TextBox6.MaxLength = int.Parse(accountLength);
        
        this.lblError.Text = "";
        Session["eventID"] = null;
    }

    //private string getPostBackControlName()
    //{
    //    Control control = null;
    //    string ctrlname = Page.Request.Params["_EVENTTARGET"];
    //    if (ctrlname != null && ctrlname != string.Empty)
    //    {
    //        control = Page.FindControl(ctrlname);

    //    }
    //    else
    //    {
    //        string ctrlStr = string.Empty;
    //        Control c = null;
    //        foreach (string ctl in Page.Request.Form)
    //        {
    //            c = Page.FindControl(ctrlStr);
    //            control = c;
    //        }
    //    }
    //    return control.ID;
    //}

    private string getParamByID(string ID)
    {
        try
        {
            string DBConnection = Helper.dbConnectionLive();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "SYSTEM_PARAM_EDITOR.get_parameter_by_id";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_param_id", 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;

            oracom.Parameters["p_param_id"].Value = ID;
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_current_uid"].Value = "1";

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

            string temp = ds.Tables[0].Rows[0][2].ToString();
            oracon.Close();
            //ExceptionUtility.LogException(0, "SYSTEM_PARAM_EDITOR.get_parameter_by_id", "", "getParamByID", "ID -" + ID + "");
            return temp;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "SYSTEM_PARAM_EDITOR.get_parameter_by_id","", "getParamByID", "ID -" + ID + "");
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }
    private DataSet getMakerChecker(int chgId,string changedRecId)
    {
        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.Get_Maker_Checker";

            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_changed_rec_id", 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.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

            oracom.Parameters["p_chg_id"].Value = chgId;
            //oracom.Parameters["p_changed_rec_id"].Value = changedRecId ;
            oracom.Parameters["p_page_id"].Value = OracleNumber .Null ;
            oracom.Parameters["p_chg_type"].Value = OracleNumber.Null;
            oracom.Parameters["p_lang"].Value = "EN";
            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();
            ExceptionUtility.LogException(0, "MAKER_CHECKER_EDITOR.Get_Maker_Checker", "getMakerChecker", "", "changedRecId- " + changedRecId + ": chgId- " + chgId);
            return ds;

        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "MAKER_CHECKER_EDITOR.Get_Maker_Checker", "getMakerChecker","", "changedRecId- " + changedRecId + ": chgId- " + chgId);
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }

    private void loadATMGroups()
    {
        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_atm_groups";
            oracom.Parameters.Add("p_atm_groups", OracleType.Cursor).Direction = ParameterDirection.Output;

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

            ddlATMGroup.DataSource = ds;
            ddlATMGroup.DataBind();
            ddlATMGroup.Items.Insert(0, "------ Groups ------");
            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.get_atm_groups","", "loadATMGroups", "");
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

   

    private void loadBranches()
    {
        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_Branches";

            oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_branches", OracleType.Cursor).Direction = ParameterDirection.Output;

            oracom.Parameters["p_lang"].Value = "EN";

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

            ddlChannels.DataSource = ds;
            ddlChannels.DataBind();


            DropDownList1.DataSource = ds;
            DropDownList1.DataBind();

            ddlChannels.Items.Insert(0, "------ Branches ------");
            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Branches","", "loadBranches", "p_lang-EN");
           // //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private void loadATMTypes()
    {
        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_ATM_Types";

            oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_types", OracleType.Cursor).Direction = ParameterDirection.Output;

            oracom.Parameters["p_lang"].Value = "EN";

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

            ddlType.DataSource = ds;
            ddlType.DataBind();

            DropDownList3.DataSource = ds;
            DropDownList3.DataBind();


            ddlType.Items.Insert(0, "------ Types ------");
            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_ATM_Types", "", "loadATMTypes", "p_lang-EN");
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private int loadChgID()
    {
        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.get_chg_id";


            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.ExecuteNonQuery();
            oracon.Close();

            int nop = int.Parse(oracom.Parameters["p_chg_id"].Value.ToString());
            oracon.Close();
            ExceptionUtility.LogException(0, "maker_checker_editor.get_chg_id", "391.2", "loadChgID", "");
            return nop;
            
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.get_chg_id","391.2", "loadChgID", "");
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }

    private int loadMaxChgID(string atm_number)
    {
        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.get_max_chg_id";

            oracom.Parameters.Add("p_changed_rec_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters["p_changed_rec_id"].Value = atm_number;

            oracom.ExecuteNonQuery();
            oracon.Close();
            ExceptionUtility.LogException(0, "maker_checker_editor.get_max_chg_id", "", "loadMaxChgID", "atm_number- " + atm_number);
            int nop = int.Parse(oracom.Parameters["p_chg_id"].Value.ToString());
            oracon.Close();
            return nop;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.get_max_chg_id","", "loadMaxChgID", "atm_number- " + atm_number);
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }

    private DataSet loadCurrentATMData(string terminalID)
    {
        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 = "ATM_INFO_EDITOR.Get_ATM_Info";


            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_branch_code", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_number", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_type", 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_output", OracleType.Cursor).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters["p_branch_code"].Value = OracleString.Null;
            oracom.Parameters["p_atm_number"].Value = terminalID;
            oracom.Parameters["p_atm_type"].Value = OracleString.Null;
            oracom.Parameters["p_page_size"].Value = 10;
            oracom.Parameters["p_page_num"].Value = 1;
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

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

            int nop = int.Parse(oracom.Parameters["p_total_pages"].Value.ToString());
            oracon.Close();
            ExceptionUtility.LogException(0, "ATM_INFO_EDITOR.Get_ATM_Info", "loadCurrentATMData","", "terminalID: " + terminalID+":p_lang-EN");
            return ds;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_INFO_EDITOR.Get_ATM_Info", "loadCurrentATMData", "", "terminalID- " + terminalID + ":p_lang-EN");
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }

    private void loadResultGrid(string branchID, string terminalID, string type,int pageSize, int pageNumber)
    {
        string parameters = "";
        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 = "ATM_INFO_EDITOR.Get_ATM_Info";


            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_branch_code", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_number", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_type", OracleType.VarChar).Direction = ParameterDirection.Input;
            //oracom.Parameters.Add("p_status", OracleType.Number).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_output", OracleType.Cursor).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

            if (branchID.Length != 0)
            {
                parameters = "p_branch_code-" + branchID;
                oracom.Parameters["p_branch_code"].Value = branchID;
            }
            else
                oracom.Parameters["p_branch_code"].Value = OracleString.Null;
            if (terminalID.Length != 0)
            {
                parameters = ":p_branch_code-" + terminalID;
                oracom.Parameters["p_atm_number"].Value = terminalID;
            }
            else
                oracom.Parameters["p_atm_number"].Value = OracleString.Null;
            if (type.Length != 0)
            {
                parameters = ":p_atm_type-" + type;
                oracom.Parameters["p_atm_type"].Value = type;
            }
            else
                oracom.Parameters["p_atm_type"].Value = OracleString.Null;
            //oracom.Parameters["p_status"].Value = 1;
            oracom.Parameters["p_page_size"].Value = pageSize;
            oracom.Parameters["p_page_num"].Value = pageNumber;
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

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

            int nop = int.Parse(oracom.Parameters["p_total_pages"].Value.ToString());
            oracon.Close();

            GridView1.DataSource = ds;
            GridView1.DataBind();

            if (pageNumber == 1)
            {
                ddlPages.Items.Clear();
                for (int i = 1; i <= nop; i++)
                {
                    ddlPages.Items.Add(i.ToString());
                }
            }
            ExceptionUtility.LogException(0, "ATM_INFO_EDITOR.Get_ATM_Info", "37.1.1", "loadResultGrid", parameters);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_INFO_EDITOR.Get_ATM_Info", "37.1.1", "loadResultGrid", parameters);
        }
        
    }

   

    protected void Button1_Click(object sender, EventArgs e)
    {
        ExceptionUtility.LogException(0, "", "3.37", "Button1_Click", "");
        getATMS();

    }

   

    private void getATMS()
    {
        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name;
            string channelID = "", EventID = "", type = "";

            if (ddlChannels.SelectedIndex > 0)
                channelID = ddlChannels.SelectedValue;
            EventID = txtATMnumber.Text;
            if (ddlType.SelectedIndex > 0)
                type = ddlType.SelectedValue;
            pnlResult.Visible = true;
            pnlControls.Visible = false;
            pnlResult.Enabled = true;
            if (currentMethod.Contains("Button1_Click"))
                 ExceptionUtility.LogException(0, "", "37.1", "getATMS", "");
            loadResultGrid(channelID, EventID, type, Helper.gridSize(), 1);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "", "37.1", "getATMS", "");
        }
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        string channelID = "", EventID = "", type = "";
        if (ddlChannels.SelectedIndex > 0)
            channelID = ddlChannels.SelectedValue;
        EventID = txtATMnumber.Text;
        if (ddlType.SelectedIndex > 0)
            type = ddlType.SelectedValue;
        ExceptionUtility.LogException(0, "", "", "ddlPages_SelectedIndexChanged", "");
        loadResultGrid(channelID, EventID, type, Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        intCount = 0;
        txtStatus.Visible = false;
        lblStatus.Visible = false;
        btnSave.Visible = true;
        DropDownList1.Enabled = true;
        DropDownList3.Enabled = true;
        txtTerminalID.Enabled = true;
        txtTerminalID.Text = "";
        ddlATMGroup.SelectedIndex = 0;
        pnlControls.Visible = true;
        pnlResult.Enabled = false;
        ViewState["mode"] = "a";
        DropDownList1.SelectedIndex = 0;
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        lblUser.Text = "";
        lblUserID.Text = "";
        lblDate.Text = "";
        ExceptionUtility.LogException(0, "", "3.320", "btnAdd_Click", "");
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName.Equals("vd"))
        {
            ExceptionUtility.LogException(0, "", "3.476", "GridView1_RowCommand.ViewDetails", "");
            pnlControls.Visible = false;
            //pnlGrid.Visible = true;
            txtStatus.Visible = true;
            lblStatus.Visible = true;
            btnSave.Visible = false;
           
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            //int chgId = loadMaxChgID(rowID);
           
            string terminalID = GridView1.Rows[index].Cells[2].Text.ToString();
            string branchID = GridView1.Rows[index].Cells[0].Text.ToString();
            string typeID = GridView1.Rows[index].Cells[3].Text.ToString();

            string overage = GridView1.Rows[index].Cells[5].Text.ToString();
            string shortage = GridView1.Rows[index].Cells[6].Text.ToString();
            string cash = GridView1.Rows[index].Cells[7].Text.ToString();

            string overageDep = GridView1.Rows[index].Cells[8].Text.ToString();
            string shortageDep = GridView1.Rows[index].Cells[9].Text.ToString();
            string cashDep = GridView1.Rows[index].Cells[10].Text.ToString();

            string mUser = GridView1.Rows[index].Cells[11].Text.ToString();
            string mDate = GridView1.Rows[index].Cells[12].Text.ToString();
            string status = GridView1.Rows[index].Cells[15].Text.ToString();
            //int atmStatus = int.Parse (GridView1.Rows[index].Cells[20].Text.ToString());

            DropDownList1.SelectedValue = branchID;
            txtTerminalID.Text = terminalID;
            txtTerminalID.Enabled = false;
            DropDownList3.SelectedValue = typeID;

            ddlATMGroup.SelectedValue = GridView1.Rows[index].Cells[13].Text.ToString();
            txtStatus.Text = status;
            //if (atmStatus == 1)
            //    chkStatus.Checked = true;
            //else
            //    chkStatus.Checked = false;
            if (!overage.Equals("&nbsp;"))
                TextBox1.Text = overage;
            else
                TextBox1.Text = "";
            if (!shortage.Equals("&nbsp;"))
                TextBox2.Text = shortage;
            else
                TextBox2.Text = "";
            if (!cash.Equals("&nbsp;"))
                TextBox3.Text = cash;
            else
                TextBox3.Text = "";

            if (!overageDep.Equals("&nbsp;"))
                TextBox4.Text = overageDep;
            else
                TextBox4.Text = "";
            if (!shortageDep.Equals("&nbsp;"))
                TextBox5.Text = shortageDep;
            else
                TextBox5.Text = "";
            if (!cashDep.Equals("&nbsp;"))
                TextBox6.Text = cashDep;
            else
                TextBox6.Text = "";

            if (!mUser.Equals("&nbsp;"))
                lblUser.Text = mUser;
            else
                lblUser.Text = "";
            if (!mDate.Equals("&nbsp;"))
                lblDate.Text = mDate;
            else
                lblDate.Text = "";

            pnlControls.Visible = true;
            pnlResult.Enabled = false;

        }
        if (e.CommandName.Equals("vm"))
        {
            ExceptionUtility.LogException(0, "", "3.476", "GridView1_RowCommand.ViewModification", "");
            pnlControls.Visible = false;
            //pnlGrid.Visible = true;
            txtStatus.Visible = true;
            lblStatus.Visible = true;
            btnSave.Visible = false;

            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();

            int chgId = loadMaxChgID(rowID);
            Response.Redirect("Checker.aspx?chgId=" + chgId);

            
            //pnlControls.Visible = true;
            //pnlResult.Enabled = false;

        }
        else if (e.CommandName.Equals("e"))
        {
            intCount = 0;
            btnSave.Visible = true;
            ExceptionUtility.LogException(0, "", "3.130", "GridView1_RowCommand.Edit", "");
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string terminalID = GridView1.Rows[index].Cells[2].Text.ToString();
            string branchID = GridView1.Rows[index].Cells[0].Text.ToString();
            string typeID = GridView1.Rows[index].Cells[3].Text.ToString();

            string overage = GridView1.Rows[index].Cells[5].Text.ToString();
            string shortage = GridView1.Rows[index].Cells[6].Text.ToString();
            string cash = GridView1.Rows[index].Cells[7].Text.ToString();

            string overageDep = GridView1.Rows[index].Cells[8].Text.ToString();
            string shortageDep = GridView1.Rows[index].Cells[9].Text.ToString();
            string cashDep = GridView1.Rows[index].Cells[10].Text.ToString();

            string mUser = GridView1.Rows[index].Cells[11].Text.ToString();
            string mDate = GridView1.Rows[index].Cells[12].Text.ToString();
            string status = GridView1.Rows[index].Cells[15].Text.ToString();
            //int  atmStatus = int.Parse(GridView1.Rows[index].Cells[20].Text.ToString());

            DropDownList1.SelectedValue = branchID;
            txtTerminalID.Text = terminalID;
            txtTerminalID.Enabled = false;
            DropDownList3.SelectedValue = typeID;

            ddlATMGroup.SelectedValue = GridView1.Rows[index].Cells[13].Text.ToString();
            txtStatus.Text = status;

            
            //if (atmStatus == 1)
            //    chkStatus.Checked = true;
            //else
            //    chkStatus.Checked = false;
            if (!overage.Contains("nbsp;"))
                TextBox1.Text = overage;
            else
                TextBox1.Text = "";
            if (!shortage.Contains("nbsp;"))
                TextBox2.Text = shortage;
            else
                TextBox2.Text = "";
            if (!cash.Contains("nbsp;"))
                TextBox3.Text = cash;
            else
                TextBox3.Text = "";

            if (!overageDep.Contains("nbsp;"))
                TextBox4.Text = overageDep;
            else
                TextBox4.Text = "";
            if (!shortageDep.Contains("nbsp;"))
                TextBox5.Text = shortageDep;
            else
                TextBox5.Text = "";
            if (!cashDep.Contains("nbsp;"))
                TextBox6.Text = cashDep;
            else
                TextBox6.Text = "";

            if (!mUser.Contains("nbsp;"))
                lblUser.Text = mUser;
            else
                lblUser.Text = "";
            if (!mDate.Contains("nbsp;"))
                lblDate.Text = mDate;
            else
                lblDate.Text = "";

            pnlControls.Visible = true;
            pnlResult.Enabled = false;

            ViewState["mode"] = "u";
            ViewState["rowid"] = rowID;
        }
        
        else if (e.CommandName.Equals("d"))
        {
            ExceptionUtility.LogException(0, "", "3.32", "GridView1_RowCommand.Delete", "");
            this.pnl_confirmation.Visible = true;
            this.pnlControls.Visible = false;
            this.pnlResult.Visible = false;
            this.pnl_filters.Visible = false;
            
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();

            ViewState["selectedAtmID"] = rowID;

        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        pnlControls.Visible = false;
        pnlResult.Enabled = true;
        //ddlChannels.SelectedIndex = -1;
        //txtATMnumber.Text = "";
        //ddlType.SelectedIndex = -1;
        ExceptionUtility.LogException(0, "", "3.130", "btnCancel_Click", "");
        getATMS();
    }

    public static string DataRowToString(DataRow dr)
    {
        return dr["column_name"].ToString();
    }
    private bool Can_Insert()
    {
        string parameters = "";
        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.can_insert_ATM";

            oracom.Parameters.Add("P_ATM_NUMBER", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;


            oracom.Parameters["P_ATM_NUMBER"].Value = this.txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4);
            if (txtTerminalID.Text.Length > 0)
                parameters = "P_ATM_NUMBER-" + this.txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4);
            oracom.ExecuteNonQuery();
            oracon.Close();
            string a = oracom.Parameters["p_res_code"].Value.ToString();
            if (a == "0")
            {
                ExceptionUtility.LogException(0, "maker_checker_editor.can_insert_ATM", "391.1", "Can_Insert", parameters );
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "maker_checker_editor.can_insert_ATM", "391.1", "Can_Insert", parameters );
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.can_insert_ATM","391.1", "Can_Insert", parameters);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false;
        }
    }
    //private void OnMouseDownClickCount(object sender, MouseEventArgs e)
    protected void btnSave_Click(object sender, EventArgs e)
    {



        if (intCount < 1)
            intCount++;
        else
        {   
            pnlControls.Visible = false;
            lblError.Text = "Your request has been sent to Checker user for Approval";
            return;
        }

        ExceptionUtility.LogException(0, "", "3.391", "btnSave_Click", "");
        #region "Save"
        try
        {
            //lblCount.Text = intCount.ToString();

            //if (int.Parse(lblCount.Text) < 2)
            //{
                string mode = ViewState["mode"].ToString();
                string error = "";
                //string atm_number="";
                if (mode.Equals("a"))
                {
                    if (Can_Insert())
                    {
                        int chgId = loadChgID();

                        string BRANCH_CODE_NEW = DropDownList1.SelectedValue;
                        string TERM_ID_NEW = txtTerminalID.Text.Trim();
                        string ATM_TYPE_NEW = DropDownList3.SelectedValue;
                        string atm_type_desc_new = DropDownList3.SelectedItem.Text;
                        string ATM_GROUP_NEW = ddlATMGroup.SelectedValue;
                        string atm_group_desc_new = ddlATMGroup.SelectedItem.Text;
                        //string status_new= chkStatus.Checked ? "1" : "0";

                        string OVERAGE_ACCT_NUMBER_NEW = TextBox1.Text.Trim();
                        string SHORTAGE_ACCT_NUMBER_NEW = TextBox2.Text.Trim();
                        string CASH_ACCT_NUMBER_NEW = TextBox3.Text.Trim();
                        string OVERAGE_DEP_ACCT_NUMBER_NEW = TextBox4.Text.Trim();
                        string SHORTAGE_DEP_ACCT_NUMBER_NEW = TextBox5.Text.Trim();
                        string CASH_DEP_ACCT_NUMBER_NEW = TextBox6.Text.Trim();

                        if (ddlATMGroup.SelectedIndex > 0)
                        {
                            //bool saved = addATM(ref error);
                            //if (saved)
                            //{

                            bool saved = false;
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "ATM_NUMBER", "", txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "TERM_ID", "", TERM_ID_NEW, "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "BRANCH_CODE", "", BRANCH_CODE_NEW, "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "ATM_TYPE", "", atm_type_desc_new, "", ATM_TYPE_NEW, 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "ATM_GROUP", "", atm_group_desc_new, "", ATM_GROUP_NEW, 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "OVERAGE_ACCT_NUMBER", "", OVERAGE_ACCT_NUMBER_NEW, "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "SHORTAGE_ACCT_NUMBER", "", SHORTAGE_ACCT_NUMBER_NEW, "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "CASH_ACCT_NUMBER", "", CASH_ACCT_NUMBER_NEW, "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "OVERAGE_DEP_ACCT_NUMBER", "", OVERAGE_DEP_ACCT_NUMBER_NEW, "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "SHORTAGE_DEP_ACCT_NUMBER", "", SHORTAGE_DEP_ACCT_NUMBER_NEW, "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "CASH_DEP_ACCT_NUMBER", "", CASH_DEP_ACCT_NUMBER_NEW, "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                            //saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "STATUS", "", status_new, "", "", 0, ref error);
                            //if (saved == false)
                            //{
                            //    lblError.Text = error;
                            //    return;
                            //}
                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "CREATE_DATE", lblDate.Text, System.DateTime.Now.ToString(), "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }


                            saved = UpdateMakerChecker(chgId, txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4), "CREATED_BY", lblUserID.Text, Session["uid"].ToString(), "", "", 0, ref error);
                            if (saved == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An error occured!";
                                    ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }

                            lblError.Text = "Your request has been sent to Checker user for Approval";

                        }
                        else
                        {
                            lblError.Text = "Please Select the Group";
                            pnlControls.Visible = true;
                            ddlATMGroup.Focus();
                            return;
                        }
                    }
                    else
                    {
                        lblError.Text = "ATM Number is existing";
                    }
                }
                else if (mode.Equals("u"))
                {
                    int count = 0;
                    string Uid = ViewState["rowid"].ToString();
                    int chgId = loadChgID();
                    bool compare = false;
                    //string status =chkStatus.Checked ? "1" : "0";
                    DataSet ds = loadCurrentATMData(Uid);
                    if (DropDownList1.SelectedValue == ds.Tables[0].Rows[0]["branch_code"].ToString() && txtTerminalID.Text == ds.Tables[0].Rows[0]["term_id"].ToString() &&
                        DropDownList3.SelectedValue == ds.Tables[0].Rows[0]["type_code"].ToString() && ddlATMGroup.SelectedValue == ds.Tables[0].Rows[0]["atm_group"].ToString() &&
                        TextBox1.Text.Trim() == ds.Tables[0].Rows[0]["overage_acct_number"].ToString().Trim() && TextBox2.Text.Trim() == ds.Tables[0].Rows[0]["shortage_acct_number"].ToString().Trim() &&
                         TextBox3.Text.Trim() == ds.Tables[0].Rows[0]["cash_acct_number"].ToString().Trim() && TextBox4.Text.Trim() == ds.Tables[0].Rows[0]["overage_dep_acct_number"].ToString().Trim() &&
                          TextBox5.Text.Trim() == ds.Tables[0].Rows[0]["shortage_dep_acct_number"].ToString().Trim() && TextBox6.Text.Trim() == ds.Tables[0].Rows[0]["cash_dep_acct_number"].ToString().Trim())
                    {
                        compare = true;
                    }
                    if (compare == false)
                    {
                        if (ddlATMGroup.SelectedIndex > 0)
                        {

                            bool update = false;
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                string ATM_NUMBER_OLD = Uid;
                                string ATM_NUMBER_NEW = Uid;

                                string BRANCH_CODE_OLD = ds.Tables[0].Rows[0]["branch_code"].ToString();
                                string BRANCH_CODE_NEW = DropDownList1.SelectedValue;
                                //string branch_code_desc_new = DropDownList1.SelectedItem.Text;

                                string TERM_ID_OLD = ds.Tables[0].Rows[0]["term_id"].ToString();
                                string TERM_ID_NEW = txtTerminalID.Text;

                                string ATM_TYPE_OLD = ds.Tables[0].Rows[0]["type_code"].ToString();
                                string ATM_TYPE_NEW = DropDownList3.SelectedValue;
                                string atm_type_desc_new = DropDownList3.SelectedItem.Text;
                                string atm_type_desc_old = ds.Tables[0].Rows[0]["atm_type"].ToString();

                                string ATM_GROUP_OLD = ds.Tables[0].Rows[0]["atm_group"].ToString();
                                string ATM_GROUP_NEW = ddlATMGroup.SelectedValue;
                                string atm_group_desc_new = ddlATMGroup.SelectedItem.Text;
                                string atm_gropu_desc_old = ds.Tables[0].Rows[0]["group_name"].ToString();

                                string OVERAGE_ACCT_NUMBER_OLD = ds.Tables[0].Rows[0]["overage_acct_number"].ToString();
                                string OVERAGE_ACCT_NUMBER_NEW = TextBox1.Text;


                                string SHORTAGE_ACCT_NUMBER_OLD = ds.Tables[0].Rows[0]["shortage_acct_number"].ToString();
                                string SHORTAGE_ACCT_NUMBER_NEW = TextBox2.Text;

                                string CASH_ACCT_NUMBER_OLD = ds.Tables[0].Rows[0]["cash_acct_number"].ToString();
                                string CASH_ACCT_NUMBER_NEW = TextBox3.Text;

                                string OVERAGE_DEP_ACCT_NUMBER_OLD = ds.Tables[0].Rows[0]["overage_dep_acct_number"].ToString();
                                string OVERAGE_DEP_ACCT_NUMBER_NEW = TextBox4.Text;

                                string SHORTAGE_DEP_ACCT_NUMBER_OLD = ds.Tables[0].Rows[0]["shortage_dep_acct_number"].ToString();
                                string SHORTAGE_DEP_ACCT_NUMBER_NEW = TextBox5.Text;

                                string CASH_DEP_ACCT_NUMBER_OLD = ds.Tables[0].Rows[0]["cash_dep_acct_number"].ToString();
                                string CASH_DEP_ACCT_NUMBER_NEW = TextBox6.Text;

                                //string STATUS_OLD = ds.Tables[0].Rows[0]["atm_status"].ToString();
                                //string STATUS_NEW = chkStatus.Checked ? "1" : "0";

                                if (BRANCH_CODE_OLD != BRANCH_CODE_NEW)
                                    update = UpdateMakerChecker(chgId, Uid, "BRANCH_CODE", BRANCH_CODE_OLD, BRANCH_CODE_NEW, "", "", 1, ref error);


                                if (TERM_ID_OLD != TERM_ID_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "TERM_ID", TERM_ID_OLD, TERM_ID_NEW, "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                if (ATM_TYPE_OLD != ATM_TYPE_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "ATM_TYPE", atm_type_desc_old, atm_type_desc_new, ATM_TYPE_OLD, ATM_TYPE_NEW, 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                if (ATM_GROUP_OLD != ATM_GROUP_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "ATM_GROUP", atm_gropu_desc_old, atm_group_desc_new, ATM_GROUP_OLD, ATM_GROUP_NEW, 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                if (OVERAGE_ACCT_NUMBER_OLD != OVERAGE_ACCT_NUMBER_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "OVERAGE_ACCT_NUMBER", OVERAGE_ACCT_NUMBER_OLD, OVERAGE_ACCT_NUMBER_NEW, "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                if (SHORTAGE_ACCT_NUMBER_OLD != SHORTAGE_ACCT_NUMBER_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "SHORTAGE_ACCT_NUMBER", SHORTAGE_ACCT_NUMBER_OLD, SHORTAGE_ACCT_NUMBER_NEW, "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                if (CASH_ACCT_NUMBER_OLD != CASH_ACCT_NUMBER_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "CASH_ACCT_NUMBER", CASH_ACCT_NUMBER_OLD, CASH_ACCT_NUMBER_NEW, "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                if (OVERAGE_DEP_ACCT_NUMBER_OLD != OVERAGE_DEP_ACCT_NUMBER_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "OVERAGE_DEP_ACCT_NUMBER", OVERAGE_DEP_ACCT_NUMBER_OLD, OVERAGE_DEP_ACCT_NUMBER_NEW, "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                if (SHORTAGE_DEP_ACCT_NUMBER_OLD != SHORTAGE_DEP_ACCT_NUMBER_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "SHORTAGE_DEP_ACCT_NUMBER", SHORTAGE_DEP_ACCT_NUMBER_OLD, SHORTAGE_DEP_ACCT_NUMBER_NEW, "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                if (CASH_DEP_ACCT_NUMBER_OLD != CASH_DEP_ACCT_NUMBER_NEW)
                                {
                                    update = UpdateMakerChecker(chgId, Uid, "CASH_DEP_ACCT_NUMBER", CASH_DEP_ACCT_NUMBER_OLD, CASH_DEP_ACCT_NUMBER_NEW, "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }
                                }
                                //if (STATUS_NEW != STATUS_OLD)
                                //{
                                //    update = UpdateMakerChecker(chgId, Uid, "STATUS", STATUS_OLD, STATUS_NEW, "", "", 1, ref error);
                                //    if (update == false)
                                //    {
                                //        lblError.Text = error;
                                //        return;
                                //    }
                                //}
                                update = UpdateMakerChecker(chgId, Uid, "MODIFY_DATE", lblDate.Text, System.DateTime.Now.ToString(), "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }


                                    update = UpdateMakerChecker(chgId, Uid, "MODIFIED_BY", lblUserID.Text, Session["uid"].ToString(), "", "", 1, ref error);
                                    if (update == false)
                                    {
                                        if (Helper.OracleError(error))
                                        {
                                            lblError.Text = "An error occured!";
                                            ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
                                        }
                                        else
                                            lblError.Text = error;
                                        return;
                                    }

                                  
                               
                                //string mUserOld = ds.Tables[0].Rows[0]["created_by"].ToString();
                                //string mDateOld = ds.Tables[0].Rows[0]["create_date"].ToString();

                            }
                            lblError.Text = "Your request has been sent to Checker user for Approval";

                        }

                        else
                        {
                            lblError.Text = "Please Select the Group";
                            pnlControls.Visible = true;
                            ddlATMGroup.Focus();
                            return;
                        }
                    }
                    //else
                    //    lblError.Text = "No Modification";

                }
                getATMS();
                ViewState["mode"] = null;
                ViewState["rowid"] = null;
                pnlControls.Visible = false;
                pnlResult.Enabled = true;
                pnlControls.Visible = false;
                
                   // btn_clicked = false;
                
            //}
            //else
            //{
            //    lblError.Text = "Your request has been sent to Checker user for Approval";
            //    pnlControls.Visible = false;
                
            //    return;
            //}
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "", "3.391", "btnSave_Click", "");
        }
        #endregion 
    }

    private bool UpdateMakerChecker(int chgId,string atm_number,string columnName,string oldValue,string newValue,string oldValueNo,string NewValueNo,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.Add_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_chg_type", OracleType.Number).Direction = ParameterDirection.Input;            
            oracom.Parameters.Add("p_page_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_old_value", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_new_value", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_maker_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_made_on_date", OracleType.DateTime).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checker_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checked_on_date", OracleType.DateTime).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_changed_rec_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_status", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checker_notes", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_old_number", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_new_number", 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["p_current_uid"].Value = Session["uid"].ToString();          
            oracom.Parameters["p_page_id"].Value = page_id;
            oracom.Parameters["p_table_name"].Value = table_name;
            oracom.Parameters["p_chg_id"].Value = chgId;
            oracom.Parameters["p_chg_type"].Value = chgType;
            oracom.Parameters["p_column_name"].Value = columnName;
            oracom.Parameters["p_new_value"].Value = newValue ;
            oracom.Parameters["p_old_value"].Value = oldValue;                    
            oracom.Parameters["p_maker_id"].Value = Session["uid"].ToString();
            oracom.Parameters["p_made_on_date"].Value = OracleDateTime.Null;
            oracom.Parameters["p_checker_id"].Value = OracleNumber.Null;
            oracom.Parameters["p_checked_on_date"].Value = OracleDateTime.Null;
            oracom.Parameters["p_changed_rec_id"].Value = atm_number;
            oracom.Parameters["p_chg_status"].Value = 0;
            oracom.Parameters["p_checker_notes"].Value = OracleString.Null;

            if(oldValueNo.Trim ()=="")
                oracom.Parameters["p_old_number"].Value = OracleNumber.Null;
            else
                oracom.Parameters["p_old_number"].Value = oldValueNo;
            if(NewValueNo.Trim ()=="")
                oracom.Parameters["p_new_number"].Value = OracleNumber.Null;
            else
                oracom.Parameters["p_new_number"].Value = NewValueNo;
            
            oracom.Parameters["p_lang"].Value = "EN";

            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.Add_Maker_Checker", "UpdateMakerChecker", "391.3", "chgId: " + chgId + ", columnName: " + columnName + ": oldValue: " + oldValue + " : newValue- " + newValue + " : oldValueNo- " + oldValueNo + ": NewValueNo- " + NewValueNo + " :chgType- " + chgType);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "UpdateMakerChecker", "391.3", "chgId- " + chgId + ", columnName-" + columnName + ": oldValue- " + oldValue + " : newValue- " + newValue + " : oldValueNo- " + oldValueNo + ": NewValueNo- " + NewValueNo + " :chgType- " + chgType);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "UpdateMakerChecker","391.3", "chgId: " + chgId + ": columnName- " + columnName + ": oldValue- " + oldValue + " : newValue- " + newValue + " : oldValueNo- " + oldValueNo + ": NewValueNo- " + NewValueNo + " :chgType- " + chgType);
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false;
        }
    }
    private int loadPageIDs(string URL)
    {
        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_pages";

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


            oracom.Parameters["p_url"].Value = URL;

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

            oracon.Close();
            //ExceptionUtility.LogException(0, "lookup_getter.get_pages", "", "loadPageIDs", "URL- " + URL);
            return int.Parse(ds.Tables[0].Rows[0]["pid"].ToString());
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "lookup_getter.get_pages","", "loadPageIDs", "URL- " + URL);
            ////Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }
    
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
           
           
            e.Row.Cells[3].Visible = false;
            e.Row.Cells[5].Visible = false;
            e.Row.Cells[6].Visible = false;
            e.Row.Cells[7].Visible = false;
            e.Row.Cells[8].Visible = false;
            e.Row.Cells[9].Visible = false;
            e.Row.Cells[10].Visible = false;
            e.Row.Cells[11].Visible = false;
            e.Row.Cells[12].Visible = false;
            e.Row.Cells[14].Visible = false;
            //e.Row.Cells[20].Visible = false;
        }
       
    }

    protected void btn_conf_ok_Click(object sender, EventArgs e)
    {
        string rowID = ViewState["selectedAtmID"].ToString();
        ViewState["mode"] = "d";
        string error = "";
        ExceptionUtility.LogException(0, "", "", "btn_conf_ok_Click", "");
        int chgId = loadChgID();       
        bool saved = UpdateMakerChecker(chgId, rowID, "atm_number", "", rowID, "", "", 2, ref error);
        if (saved)
        {
            lblError.Text = "Your request has been sent to Checker user for Approval";
        }
        else
        {
            if (Helper.OracleError(error))
            {
                lblError.Text = "An error occured!";
                ExceptionUtility.LogException(9, "", "3.391", "btnSave_Click", error);
            }
            else
                lblError.Text = error;
            
            ExceptionUtility.LogException(9, "", "", "btn_conf_ok_Click", "");
            return;
        }

        this.pnl_confirmation.Visible = false;
        this.pnl_filters.Visible = true;
        this.pnlResult.Visible = true;        
        getATMS();
        ViewState["mode"] = null;
    }
    protected void btn_conf_cancel_Click(object sender, EventArgs e)
    {
        this.pnl_confirmation.Visible = false;
        this.pnl_filters.Visible = true;
        this.pnlResult.Visible = true;
        ExceptionUtility.LogException(0, "", "", "btn_conf_cancel_Click", "");
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            
            int app_status = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "app_status"));
          
            if (app_status == 0)
            {
                //e.Row.Cells[17].Enabled = true;
                e.Row.Cells[16].Visible = true;
                e.Row.Cells[18].Visible = false ;
                e.Row.Cells[19].Visible = false ;

            }
            else
            {
                //e.Row.Cells[17].Visible = false;
                e.Row.Cells[16].Visible = false ;
                e.Row.Cells[18].Visible = true;
                e.Row.Cells[19].Visible = true;
            }
        }
    }
}
