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

public partial class Business_ViewConfiguration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            btnClose.Attributes.Add("onclick", "closeWindow();");
            int pageID = int.Parse (Request.QueryString["PageID"]);
            string eventID = Request.QueryString["id"];
            int status = int.Parse(Request.QueryString["Status"]);
            switch (pageID)
            {
                case 3:
                    pnlATM .Visible =true ;
                    loadBranches();
                    loadATMTypes();
                    loadATMGroups();
                    getATMS(eventID);
                    break;
            }
        }
    }
    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);

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

        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);

       

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

        oracon.Close();
    }
    private void getATMS(string EventID)
    {
        
        //EventID = txtATMnumber.Text;       
        loadResult(EventID,Helper.gridSize(), 1);
    }
    private void loadResult(string terminalID, int pageSize, int pageNumber)
    {
        string overage,shortage,cash;
        string overageDep, shortageDep, cashDep;
        string mUser, mDate;
        
        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.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.Trim ();
        //if (status == 1)
        //{
        //    oracom.Parameters["p_status"].Value = 2;
        //}
        //else
        //{
        //    oracom.Parameters["p_status"].Value = 1;
        //}
        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());
        //    }
        //}

        if (ds.Tables[0].Rows.Count == 1)
        {
            DropDownList1.SelectedValue = ds.Tables[0].Rows[0]["branch_code"].ToString();
            txtTerminalID.Text = ds.Tables[0].Rows[0]["term_id"].ToString();
            txtTerminalID.Enabled = false;
            DropDownList3.SelectedValue = ds.Tables[0].Rows[0]["type_code"].ToString();

            ddlATMGroup.SelectedValue = ds.Tables[0].Rows[0]["atm_group"].ToString();

            overage = ds.Tables[0].Rows[0]["overage_acct_number"].ToString();
            shortage = ds.Tables[0].Rows[0]["shortage_acct_number"].ToString();
            cash = ds.Tables[0].Rows[0]["cash_acct_number"].ToString();

            overageDep = ds.Tables[0].Rows[0]["overage_dep_acct_number"].ToString();
            shortageDep = ds.Tables[0].Rows[0]["shortage_dep_acct_number"].ToString();
            cashDep = ds.Tables[0].Rows[0]["cash_dep_acct_number"].ToString();

            mUser = ds.Tables[0].Rows[0]["modified_by"].ToString();
            mDate = ds.Tables[0].Rows[0]["modify_date"].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 (!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 = "";
        }

    }
}