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;

public partial class Business_ATM : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadBranches();
            loadATMTypes();
            loadATMGroups();
            this.pnl_confirmation.Visible = false;
        }

        this.lblError.Text = "";
    }


    private void loadATMGroups()
    {
        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();
    }



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

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

    private void loadResult(string branchID, string terminalID, string type, int pageSize, int pageNumber)
    {
        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;

        if (branchID.Length != 0)
            oracom.Parameters["p_branch_code"].Value = branchID;
        else
            oracom.Parameters["p_branch_code"].Value = OracleString.Null;
        if (terminalID.Length != 0)
            oracom.Parameters["p_atm_number"].Value = terminalID;
        else
            oracom.Parameters["p_atm_number"].Value = OracleString.Null;
        if (type.Length != 0)
            oracom.Parameters["p_atm_type"].Value = type;
        else
            oracom.Parameters["p_atm_type"].Value = OracleString.Null;
        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());
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        getATMS();
    }

    private void getATMS()
    {
        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;
        loadResult(channelID, EventID, type, Helper.gridSize(), 1);
    }

    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;
        loadResult(channelID, EventID, type, Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        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 = "";
        txtSuspense.Text = "";
        txtDepSuspense.Text = "";
        txtUSDCashAccount.Text = "";
        txtUSDShortageAccount.Text = "";
        txtUSDSurplusAccount.Text = "";
        txtUSDSuspenseAccount.Text = "";
        txtCoinAcct.Text = "";
        txtCoinShortAcct.Text = "";
        txtCoinSurpAccc.Text = "";
        txtCoinSusAcc.Text = "";
    
    
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("e"))
        {
            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 suspense = GridView1.Rows[index].Cells[16].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 suspenseDep = GridView1.Rows[index].Cells[17].Text.ToString();

            string overageUSD = GridView1.Rows[index].Cells[18].Text.ToString();
            string shortageUSD = GridView1.Rows[index].Cells[19].Text.ToString();
            string cashUSD = GridView1.Rows[index].Cells[20].Text.ToString();
            string suspenseUSD = GridView1.Rows[index].Cells[21].Text.ToString();

            string mUser = GridView1.Rows[index].Cells[11].Text.ToString();
            string mDate = GridView1.Rows[index].Cells[12].Text.ToString();



            txtCoinSurpAccc.Text = GridView1.Rows[index].Cells[22].Text.ToString().Equals("&nbsp;") ? "" : GridView1.Rows[index].Cells[22].Text.ToString();
            txtCoinShortAcct.Text = GridView1.Rows[index].Cells[23].Text.ToString().Equals("&nbsp;") ? "" :GridView1.Rows[index].Cells[23].Text.ToString() ;
            txtCoinAcct.Text = GridView1.Rows[index].Cells[24].Text.ToString().Equals("&nbsp;") ? "" : GridView1.Rows[index].Cells[24].Text.ToString();
            txtCoinSusAcc.Text = GridView1.Rows[index].Cells[25].Text.ToString().Equals("&nbsp;") ? "" :GridView1.Rows[index].Cells[25].Text.ToString();
    

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

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

            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 (!suspense.Equals("&nbsp;"))
                txtSuspense.Text = suspense ;
            else
                txtSuspense.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 (!suspenseDep .Equals("&nbsp;"))
                txtDepSuspense .Text = suspenseDep;
            else
                txtDepSuspense.Text = "";

            if (!overageUSD.Equals("&nbsp;"))
                txtUSDSurplusAccount.Text = overageUSD;
            else
                txtUSDSurplusAccount.Text = "";
            if (!shortageUSD.Equals("&nbsp;"))
                txtUSDShortageAccount.Text = shortageUSD;
            else
                txtUSDShortageAccount.Text = "";
            if (!cashUSD.Equals("&nbsp;"))
                txtUSDCashAccount.Text = cashUSD;
            else
                txtUSDCashAccount.Text = "";
            if (!suspenseUSD.Equals("&nbsp;"))
                txtUSDSuspenseAccount .Text = suspenseUSD;
            else
                txtUSDSuspenseAccount.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;

            ViewState["mode"] = "u";
            ViewState["rowid"] = rowID;
        }
        
        else if (e.CommandName.Equals("d"))
        {
            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;

            //string error = "";
            //bool saved = deleteATM(rowID, ref error);
            //if (saved)
            //{
            //    lblError.Text = "ATM deleted";
            //}
            //else
            //{
            //    lblError.Text = error;
            //}
            //getATMS();
        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        pnlControls.Visible = false;
        pnlResult.Enabled = true;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        //if (Page.IsValid)
        //{
            try
            {
                string mode = ViewState["mode"].ToString();
                string error = "";
                if (mode.Equals("a"))
                {
                    if (ddlATMGroup.SelectedIndex > 0)
                    {
                        bool saved = addATM(ref error);
                        if (saved)
                        {
                            lblError.ForeColor = System.Drawing.Color.DarkGreen;
                            lblError.Text = "ATM data Saved";
                        }
                        else
                        {
                            lblError.Text = error;
                        }
                    }
                    else
                        lblError.Text = "Please Select the Group";
                }
                else if (mode.Equals("u"))
                {
                    string Uid = ViewState["rowid"].ToString();
                    if (ddlATMGroup.SelectedIndex > 0)
                    {
                        bool saved = updateATM(Uid, ref error);
                        if (saved)
                        {
                            lblError.ForeColor = System.Drawing.Color.DarkGreen;
                            lblError.Text = "ATM data Saved";
                        }
                        else
                        {
                            lblError.Text = error;
                        }
                    }
                    else
                        lblError.Text = "Please Select the Group";
                }
                getATMS();
                ViewState["mode"] = null;
                ViewState["rowid"] = null;
                pnlControls.Visible = false;
                pnlResult.Enabled = true;
            }
            catch (Exception ex)
            {
            }
        //}
    }
    private bool addATM(ref string error)
    {
        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.Add_ATM";

        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_terminal_id", 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_overage_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_shortage_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cash_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_suspense_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_overage_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_shortage_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cash_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_suspense_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_overage_usd_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_shortage_usd_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cash_usd_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_suspense_usd_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_group", 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_branch_code"].Value = DropDownList1.SelectedValue;
        oracom.Parameters["p_terminal_id"].Value = txtTerminalID.Text;
        oracom.Parameters["p_atm_number"].Value = txtTerminalID.Text.Substring(txtTerminalID.Text.Length-4);
        oracom.Parameters["p_atm_type"].Value = DropDownList3.SelectedValue;

        oracom.Parameters["p_overage_acct"].Value = TextBox1.Text;
        oracom.Parameters["p_shortage_acct"].Value = TextBox2.Text;
        oracom.Parameters["p_cash_acct"].Value = TextBox3.Text;
        oracom.Parameters["p_suspense_acct"].Value = txtSuspense .Text;

        oracom.Parameters["p_overage_dep_acct"].Value = TextBox4.Text;
        oracom.Parameters["p_shortage_dep_acct"].Value = TextBox5.Text;
        oracom.Parameters["p_cash_dep_acct"].Value = TextBox6.Text;
        oracom.Parameters["p_suspense_dep_acct"].Value = txtDepSuspense .Text;

        oracom.Parameters["p_overage_usd_acct"].Value = txtUSDSurplusAccount .Text;
        oracom.Parameters["p_shortage_usd_acct"].Value = txtUSDShortageAccount .Text ;
        oracom.Parameters["p_cash_usd_acct"].Value = txtUSDCashAccount .Text ;
        oracom.Parameters["p_suspense_usd_acct"].Value = txtUSDSuspenseAccount .Text ;


        //Coin Starts IRFAN_MOD
        oracom.Parameters.Add("p_coin_overage_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_coin_shortage_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_coin_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_coin_suspense_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters["p_coin_overage_dep_acct"].Value = txtCoinSurpAccc.Text;
        oracom.Parameters["p_coin_shortage_dep_acct"].Value = txtCoinShortAcct.Text;
        oracom.Parameters["p_coin_dep_acct"].Value = txtCoinAcct.Text;
        oracom.Parameters["p_coin_suspense_dep_acct"].Value = txtCoinSusAcc.Text;
        //Coin Ends IRFAN_MOD


        oracom.Parameters["p_group"].Value = ddlATMGroup.SelectedValue;

        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")
            return true;
        else
            return false;
    }

    private bool updateATM(string rowID, ref string error)
    {
        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.update_atm_info";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_branch_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_overage_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_shortage_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cash_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_suspense_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_overage_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_shortage_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cash_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_suspense_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_overage_usd_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_shortage_usd_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cash_usd_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_suspense_usd_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_group", 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_atm_number"].Value = rowID;
        oracom.Parameters["p_branch_code"].Value = DropDownList1.SelectedValue;
        oracom.Parameters["p_atm_type"].Value = DropDownList3.SelectedValue;

        oracom.Parameters["p_overage_acct"].Value = TextBox1.Text;
        oracom.Parameters["p_shortage_acct"].Value = TextBox2.Text;
        oracom.Parameters["p_cash_acct"].Value = TextBox3.Text;
        oracom.Parameters["p_suspense_acct"].Value = txtSuspense .Text;

        oracom.Parameters["p_overage_dep_acct"].Value = TextBox4.Text;
        oracom.Parameters["p_shortage_dep_acct"].Value = TextBox5.Text;
        oracom.Parameters["p_cash_dep_acct"].Value = TextBox6.Text;
        oracom.Parameters["p_suspense_dep_acct"].Value = txtSuspense.Text;

        oracom.Parameters["p_overage_usd_acct"].Value = txtUSDSurplusAccount.Text;
        oracom.Parameters["p_shortage_usd_acct"].Value = txtUSDShortageAccount.Text;
        oracom.Parameters["p_cash_usd_acct"].Value = txtUSDCashAccount.Text;
        oracom.Parameters["p_suspense_usd_acct"].Value = txtUSDSuspenseAccount.Text;

        //Coin Starts IRFAN_MOD
        oracom.Parameters.Add("p_coin_overage_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_coin_shortage_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_coin_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_coin_suspense_dep_acct", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters["p_coin_overage_dep_acct"].Value = txtCoinSurpAccc.Text;
        oracom.Parameters["p_coin_shortage_dep_acct"].Value = txtCoinShortAcct.Text;
        oracom.Parameters["p_coin_dep_acct"].Value = txtCoinAcct.Text;
        oracom.Parameters["p_coin_suspense_dep_acct"].Value = txtCoinSusAcc.Text;
        //Coin Ends IRFAN_MOD

        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_group"].Value = ddlATMGroup.SelectedValue;


        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }

    private bool deleteATM(string atmID, ref string error)
    {
        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.Delete_ATM";

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

        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")
            return true;
        else
            return false;
    }

    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[16].Visible = false;
            e.Row.Cells[17].Visible = false;
            e.Row.Cells[18].Visible = false;
            e.Row.Cells[19].Visible = false;
            e.Row.Cells[20].Visible = false;
            e.Row.Cells[21].Visible = false;

            e.Row.Cells[22].Visible = false;
            e.Row.Cells[23].Visible = false;
            e.Row.Cells[24].Visible = false;
            e.Row.Cells[25].Visible = false;
            
            
        }
    }

    protected void btn_conf_ok_Click(object sender, EventArgs e)
    {
        string rowID = ViewState["selectedAtmID"].ToString();
        
        string error = "";
        bool saved = deleteATM(rowID, ref error);
        if (saved)
        {
            lblError.ForeColor = System.Drawing.Color.DarkGreen;
            lblError.Text = "ATM deleted";
        }
        else
        {
            lblError.Text = error;
        }

        this.pnl_confirmation.Visible = false;
        this.pnl_filters.Visible = true;
        this.pnlResult.Visible = true;

        getATMS();
    }
    protected void btn_conf_cancel_Click(object sender, EventArgs e)
    {
        this.pnl_confirmation.Visible = false;
        this.pnl_filters.Visible = true;
        this.pnlResult.Visible = true;
    }
    protected void ddlChannels_SelectedIndexChanged(object sender, EventArgs e)
    {
        pnlResult.Visible = false;
        pnlControls.Visible = false;
    }
    //protected void TextBox1_TextChanged(object sender, EventArgs e)
    //{
    //    //TextBox1.Text = TextBox1.Text.Replace(",", "");
    //}
}
