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

public partial class Business_Repl_2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadBranches();
            loadStatus();
            loadModifyReasons();
            loadValues(sender, e);
            loadCurrency();
          
        }
        this.pnl_confirmation_recon.Visible = false;
        this.pnl_confirmation_glentry.Visible = false;
        lblError.Text = "";
       

    }

    private void loadValues(object sender, EventArgs e)
    {
        if (Request.QueryString["atmno"] != null)
        {
            if (Request.QueryString["status"] == null)
            {
                txtTerminal.Text = Request.QueryString["atmno"];

                if (Request.QueryString["pReplDate"] != null)
                    DatePicker1.date = Request.QueryString["pReplDate"];

                if (Request.QueryString["pReplTime"] != null)
                    txtPrevTime.Text = Request.QueryString["pReplTime"];

                if (Request.QueryString["ReplDate"] != null)
                    DatePicker2.date = Request.QueryString["ReplDate"];

                if (Request.QueryString["ReplTime"] != null)
                    txtTime.Text = Request.QueryString["ReplTime"];

                Button1_Click(sender, e);
                row1.Visible = true;
                lblTime.Visible = true;
                txtTime.Visible = true;
            }

            else
            {
                if ( Request.QueryString["status"] == "4")
                {
                    if (Request.QueryString["ReplDate"] != null)
                        DatePicker1.date = Request.QueryString["ReplDate"];

                    pnlSearch.Visible = false;
                    pnlResult.Visible = false;
                    pnlControls.Visible = true;
                    getEJMissingReplenishmentData();
                }

            }
        }
        else
        {
            row1.Visible = false;
            lblTime.Visible = false;
            txtTime.Visible = false;
        }
    }
    private void getEJMissingReplenishmentData()
    {
        
        pnlReadOnly.Visible = true;

        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_dep_replenishment_editor.get_replinfo_ejmissing";


        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_cur", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_openBal", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_closeBal", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;


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


        oracom.Parameters["p_atm_num"].Value = Request.QueryString["atmno"];
        oracom.Parameters["p_repl_date"].Value = DatePicker1.date;
        oracom.Parameters["p_repl_time"].Value = Request.QueryString["ReplTime"].Replace(":", "");
        oracom.Parameters["p_repl_cur"].Value = Request.QueryString["replCurrency"];
        oracom.Parameters["p_atm_type"].Value = Request.QueryString["type"];
        oracom.Parameters["p_openBal"].Value = getNumber(Request.QueryString["openingBalance"]);
        oracom.Parameters["p_closeBal"].Value = getNumber(Request.QueryString["closingBalance"]);

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

        ViewState["rowid"] = ds.Tables[0].Rows[0]["rid"].ToString();
        ViewState["acctNo"] = ds.Tables[0].Rows[0]["acct_number"].ToString();
        string terminalID = ds.Tables[0].Rows[0]["terminal_id"].ToString();
        string branchID = ds.Tables[0].Rows[0]["branch_code"].ToString();

        DropDownList1.SelectedValue = branchID;
        txtATMNumberAdd.Text = terminalID;
        DropDownList1.Enabled = false;
        txtATMNumberAdd.Enabled = false;

        TextBox5.Enabled = true;
        //TextBox7.Enabled = true;
        TextBox8.Enabled = true;

        datePrev.date = ds.Tables[0].Rows[0]["prev_replenishment_date"].ToString();
        lblPrevReplDate.Text = ds.Tables[0].Rows[0]["prev_replenishment_date"].ToString();

        txtPreTime.Text = ds.Tables[0].Rows[0]["prev_replenishment_time"].ToString();

        dateCurrent.date = ds.Tables[0].Rows[0]["replenishment_date"].ToString();
        lblReplDate.Text = ds.Tables[0].Rows[0]["replenishment_date"].ToString();//

        txtRepTime.Text = ds.Tables[0].Rows[0]["replenishment_time"].ToString();//GridView1.Rows[index].Cells[4].Text.ToString();
        TextBox5.Text = ds.Tables[0].Rows[0]["replenishment_currency"].ToString();//GridView1.Rows[index].Cells[2].Text.ToString();
        TextBox6.Text = ds.Tables[0].Rows[0]["amount_dispensed"].ToString();//GridView1.Rows[index].Cells[11].Text.ToString();
       // TextBox7.Text = ds.Tables[0].Rows[0]["amount_frm_vault"].ToString();//GridView1.Rows[index].Cells[12].Text.ToString();
        TextBox8.Text = ds.Tables[0].Rows[0]["amount_to_vault"].ToString();//GridView1.Rows[index].Cells[13].Text.ToString();
        ddlStatus.SelectedValue = ds.Tables[0].Rows[0]["status_code"].ToString();//GridView1.Rows[index].Cells[24].Text.ToString();
        TextBox10.Text = ds.Tables[0].Rows[0]["record_date"].ToString();//GridView1.Rows[index].Cells[14].Text.ToString();
        TextBox11.Text = ds.Tables[0].Rows[0]["opening_balance"].ToString();//GridView1.Rows[index].Cells[16].Text.ToString();
        TextBox12.Text = ds.Tables[0].Rows[0]["closing_balance"].ToString();//GridView1.Rows[index].Cells[17].Text.ToString();
        TextBox13.Text = ds.Tables[0].Rows[0]["gl_atm_difference"].ToString();//GridView1.Rows[index].Cells[18].Text.ToString();
        TextBox14.Text = ds.Tables[0].Rows[0]["ej_atm_difference"].ToString();//GridView1.Rows[index].Cells[19].Text.ToString();
        TextBox15.Text = ds.Tables[0].Rows[0]["overall_atm_diff"].ToString();//GridView1.Rows[index].Cells[20].Text.ToString();
        TextBox16.Text = ds.Tables[0].Rows[0]["rec_type_code"].ToString();//GridView1.Rows[index].Cells[21].Text.ToString();
        TextBox17.Text = ds.Tables[0].Rows[0]["verified_date"].ToString();//GridView1.Rows[index].Cells[22].Text.ToString();
        TextBox18.Text = ds.Tables[0].Rows[0]["verified_time"].ToString();//GridView1.Rows[index].Cells[23].Text.ToString();
        TextBox19.Text = ds.Tables[0].Rows[0]["sw_amount_dispensed"].ToString();//GridView1.Rows[index].Cells[15].Text.ToString();
        TextBox1.Text = ds.Tables[0].Rows[0]["error_description"].ToString();//GridView1.Rows[index].Cells[25].Text.ToString();
        TextBox3.Text = ds.Tables[0].Rows[0]["GL_amount_dispensed"].ToString();//GridView1.Rows[index].Cells[26].Text.ToString();
        if (ds.Tables[0].Rows[0]["Modify_Reason"].ToString().Length > 0)
            ddlModifyReason.SelectedValue = ds.Tables[0].Rows[0]["Modify_Reason"].ToString();//GridView1.Rows[index].Cells[27].Text.ToString();
        if (ds.Tables[0].Rows[0]["from_b24"].ToString() == "Y")
            chkFromBase24.Checked = true;
        lblClAdd.Text = ds.Tables[0].Rows[0]["ej_print_flag"].ToString();//GridView1.Rows[index].Cells[29].Text.ToString();
        lblBANCS.Text = ds.Tables[0].Rows[0]["bancs_recon_result"].ToString();//GridView1.Rows[index].Cells[30].Text.ToString();

        TextBox20.Text = ds.Tables[0].Rows[0]["b24_amount_dispensed"].ToString();//GridView1.Rows[index].Cells[31].Text.ToString();
        TextBox21.Text = ds.Tables[0].Rows[0]["b24_amount_frm_vault"].ToString();//GridView1.Rows[index].Cells[32].Text.ToString();
        TextBox22.Text = ds.Tables[0].Rows[0]["b24_amount_to_vault"].ToString();//GridView1.Rows[index].Cells[33].Text.ToString();

        txtB24Time.Text = ds.Tables[0].Rows[0]["b24_rpl_time"].ToString();//GridView1.Rows[index].Cells[34].Text.ToString();
        txtPrevB24Time.Text = ds.Tables[0].Rows[0]["b24_p_rpl_time"].ToString();//GridView1.Rows[index].Cells[35].Text.ToString();

        lblUser.Text = ds.Tables[0].Rows[0]["created_by"].ToString();//GridView1.Rows[index].Cells[36].Text.ToString();
        lblUserDate.Text = ds.Tables[0].Rows[0]["create_date"].ToString();//GridView1.Rows[index].Cells[37].Text.ToString();

        dateB24Date.date = ds.Tables[0].Rows[0]["b24_rpl_date"].ToString();//GridView1.Rows[index].Cells[38].Text.ToString();
        dateB24PrevDate.date = ds.Tables[0].Rows[0]["b24_p_rpl_date"].ToString();//GridView1.Rows[index].Cells[39].Text.ToString();

        TextBox11.Enabled = false;
        TextBox12.Enabled = false;

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

        ViewState["mode"] = "u";
        //ViewState["rowid"] = rowID;
        //ViewState["index"] = index;
        Session["fromdate"] = ds.Tables[0].Rows[0]["prev_repl_date"].ToString();
        Session["todate"] = ds.Tables[0].Rows[0]["repl_date"].ToString();
        Session["fromtime"] = ds.Tables[0].Rows[0]["prev_repl_time"].ToString();
        Session["totime"] = ds.Tables[0].Rows[0]["repl_time"].ToString();
        //viewClaims(Session["fromdate"].ToString(), Session["todate"].ToString(), Session["fromtime"].ToString(), Session["totime"].ToString(), index, Helper.gridSize(), 1);



        if (chkFromBase24.Checked)
        {
            txtRejected.Text = "NA";
            txtRetracted.Text = "NA";
        }
        else
        {
            oracom = new OracleCommand();
            oracom.Connection = oracon;

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "atm_replenishment_editor.get_atm_ret_rej";

            oracom.Parameters.Clear();
            oracom.Parameters.Add("p_atm_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pre_clear_date", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pre_clear_time", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_msg_date", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_msg_time", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_amount_rej", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_amount_ret", OracleType.Number).Direction = ParameterDirection.Output;


            oracom.Parameters["p_atm_id"].Value = txtATMNumberAdd.Text;
            oracom.Parameters["p_pre_clear_date"].Value = datePrev.date;
            if (txtPreTime.Text.Length > 0)
                oracom.Parameters["p_pre_clear_time"].Value = txtPreTime.Text.Substring(0, 5);
            else
                oracom.Parameters["p_pre_clear_time"].Value = OracleString.Null;
            oracom.Parameters["p_msg_date"].Value = dateCurrent.date;
            oracom.Parameters["p_msg_time"].Value = txtRepTime.Text.Substring(0, 5);

            da = new OracleDataAdapter(oracom);
            ds = new DataSet();
            da.Fill(ds);
            txtRetracted.Text = oracom.Parameters["p_amount_ret"].Value.ToString();
            txtRejected.Text = oracom.Parameters["p_amount_rej"].Value.ToString();
        }

    }
    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 loadStatus()
    {
        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_repl_status";

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


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

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

        oracon.Close();
    }

    private void loadCurrency()
    {
        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_repl_curr";

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

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

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

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

        oracon.Close();
    }

    private void loadModifyReasons()
    {
        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_Repl_Mod_Reasons";

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


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

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

        ddlModifyReason.Items.Insert(0, "------ Reasons ------");

        oracon.Close();
    }

    private void loadResult(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_DEP_REPLENISHMENT_EDITOR.get_atm_replenishments";

        
        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_prev_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_prev_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_time", 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_atm_num"].Value = txtTerminal.Text;
        oracom.Parameters["p_prev_repl_date"].Value = DatePicker1.date;
        oracom.Parameters["p_prev_repl_time"].Value = txtPrevTime.Text;
        oracom.Parameters["p_repl_date"].Value = DatePicker2.date;
        oracom.Parameters["p_repl_time"].Value = txtTime.Text;

        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)
    {
        pnlResult.Visible = true;
        pnlControls.Visible = false;
        pnlResult.Enabled = true;
        loadResult(Helper.gridSize(), 1);
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadResult(Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
    }
    
    protected void btnAdd_Click(object sender, EventArgs e) 
    {
        DropDownList1.Enabled = true;
        txtATMNumberAdd.Enabled = true;
        clear();
        lblReplDate.Visible = false;
        lblPrevReplDate.Visible = false;
        datePrev.Visible = true;
        dateCurrent.Visible = true;
        TextBox5.Enabled = true;
        TextBox6.Enabled = true;
        //TextBox7.Enabled = true;
        TextBox8.Enabled = true;

        pnlControls.Visible = true;
        pnlResult.Enabled = false;
        ViewState["mode"] = "a";

        DropDownList1.SelectedIndex = 0;
        pnlReadOnly.Visible = false;

        ddlCurrency.Visible = true;
        TextBox5.Visible = false;
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("e"))
        {
            pnlReadOnly.Visible = true;
            ddlCurrency.Visible = false;
            TextBox5.Visible = true;
            clear();
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string acctNo = GridView1.Rows[index].Cells[6].Text.Trim();
            ViewState["acctNo"] = acctNo;

            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_dep_replenishment_editor.get_repl_by_id";


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

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

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

            DropDownList2.SelectedValue = ds.Tables[0].Rows[0]["repl_curr"].ToString();
            string terminalID = ds.Tables[0].Rows[0]["terminal_id"].ToString();
            string branchID = ds.Tables[0].Rows[0]["branch_code"].ToString();

            DropDownList1.SelectedValue = branchID;
            txtATMNumberAdd.Text = terminalID;
            DropDownList1.Enabled = false;
            txtATMNumberAdd.Enabled = false;

            TextBox5.Enabled = false;
           // TextBox7.Enabled = false;
            TextBox8.Enabled = false;

            datePrev.date = ds.Tables[0].Rows[0]["prev_replenishment_date"].ToString();
            lblPrevReplDate.Text = ds.Tables[0].Rows[0]["prev_replenishment_date"].ToString();

            txtPreTime.Text = ds.Tables[0].Rows[0]["prev_replenishment_time"].ToString();

            dateCurrent.date = ds.Tables[0].Rows[0]["replenishment_date"].ToString();
            lblReplDate.Text = ds.Tables[0].Rows[0]["replenishment_date"].ToString();//

            txtRepTime.Text = ds.Tables[0].Rows[0]["replenishment_time"].ToString();//GridView1.Rows[index].Cells[4].Text.ToString();
            TextBox5.Text = ds.Tables[0].Rows[0]["replenishment_currency"].ToString();//GridView1.Rows[index].Cells[2].Text.ToString();
            TextBox6.Text = ds.Tables[0].Rows[0]["amount_dispensed"].ToString();//GridView1.Rows[index].Cells[11].Text.ToString();
            txtRetracted.Text = ds.Tables[0].Rows[0]["b24_ret_amount"].ToString();
            //TextBox7.Text = ds.Tables[0].Rows[0]["amount_frm_vault"].ToString();//GridView1.Rows[index].Cells[12].Text.ToString();
            TextBox8.Text = ds.Tables[0].Rows[0]["amount_to_vault"].ToString();//GridView1.Rows[index].Cells[13].Text.ToString();
            ddlStatus.SelectedValue = ds.Tables[0].Rows[0]["status_code"].ToString();//GridView1.Rows[index].Cells[24].Text.ToString();
            TextBox10.Text = ds.Tables[0].Rows[0]["record_date"].ToString();//GridView1.Rows[index].Cells[14].Text.ToString();
            TextBox11.Text = ds.Tables[0].Rows[0]["opening_balance"].ToString();//GridView1.Rows[index].Cells[16].Text.ToString();
            TextBox12.Text = ds.Tables[0].Rows[0]["closing_balance"].ToString();//GridView1.Rows[index].Cells[17].Text.ToString();
            TextBox13.Text = ds.Tables[0].Rows[0]["gl_atm_difference"].ToString();//GridView1.Rows[index].Cells[18].Text.ToString();
            TextBox14.Text = ds.Tables[0].Rows[0]["ej_atm_difference"].ToString();//GridView1.Rows[index].Cells[19].Text.ToString();
            TextBox15.Text = ds.Tables[0].Rows[0]["overall_atm_diff"].ToString();//GridView1.Rows[index].Cells[20].Text.ToString();
            TextBox16.Text = ds.Tables[0].Rows[0]["rec_type_code"].ToString();//GridView1.Rows[index].Cells[21].Text.ToString();
            TextBox17.Text = ds.Tables[0].Rows[0]["verified_date"].ToString();//GridView1.Rows[index].Cells[22].Text.ToString();
            TextBox18.Text = ds.Tables[0].Rows[0]["verified_time"].ToString();//GridView1.Rows[index].Cells[23].Text.ToString();
            TextBox19.Text = ds.Tables[0].Rows[0]["sw_amount_dispensed"].ToString();//GridView1.Rows[index].Cells[15].Text.ToString();
            TextBox1.Text = ds.Tables[0].Rows[0]["error_description"].ToString();//GridView1.Rows[index].Cells[25].Text.ToString();
            TextBox3.Text = ds.Tables[0].Rows[0]["GL_amount_dispensed"].ToString();//GridView1.Rows[index].Cells[26].Text.ToString();
            if (ds.Tables[0].Rows[0]["Modify_Reason"].ToString().Length > 0)
            {
                if (ds.Tables[0].Rows[0]["Modify_Reason"].ToString() == "0")
                    ddlModifyReason.SelectedIndex = -1;
                else
                    ddlModifyReason.SelectedValue = ds.Tables[0].Rows[0]["Modify_Reason"].ToString();//GridView1.Rows[index].Cells[27].Text.ToString();
            }
            if (ds.Tables[0].Rows[0]["from_b24"].ToString() == "Y")
                chkFromBase24.Checked = true;
            lblClAdd.Text = ds.Tables[0].Rows[0]["ej_print_flag"].ToString();//GridView1.Rows[index].Cells[29].Text.ToString();
            lblBANCS.Text = ds.Tables[0].Rows[0]["bancs_recon_result"].ToString();//GridView1.Rows[index].Cells[30].Text.ToString();

            TextBox20.Text = ds.Tables[0].Rows[0]["b24_amount_dispensed"].ToString();//GridView1.Rows[index].Cells[31].Text.ToString();
            TextBox21.Text = ds.Tables[0].Rows[0]["b24_amount_frm_vault"].ToString();//GridView1.Rows[index].Cells[32].Text.ToString();
            TextBox22.Text = ds.Tables[0].Rows[0]["b24_amount_to_vault"].ToString();//GridView1.Rows[index].Cells[33].Text.ToString();

            txtB24Time.Text = ds.Tables[0].Rows[0]["b24_rpl_time"].ToString();//GridView1.Rows[index].Cells[34].Text.ToString();
            txtPrevB24Time.Text = ds.Tables[0].Rows[0]["b24_p_rpl_time"].ToString();//GridView1.Rows[index].Cells[35].Text.ToString();

            lblUser.Text = ds.Tables[0].Rows[0]["created_by"].ToString();//GridView1.Rows[index].Cells[36].Text.ToString();
            lblUserDate.Text = ds.Tables[0].Rows[0]["create_date"].ToString();//GridView1.Rows[index].Cells[37].Text.ToString();

            dateB24Date.date = ds.Tables[0].Rows[0]["b24_rpl_date"].ToString();//GridView1.Rows[index].Cells[38].Text.ToString();
            dateB24PrevDate.date = ds.Tables[0].Rows[0]["b24_p_rpl_date"].ToString();//GridView1.Rows[index].Cells[39].Text.ToString();

            TextBox11.Enabled = false;
            TextBox12.Enabled = false;

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

            ViewState["mode"] = "u";
            ViewState["rowid"] = rowID;
            ViewState["index"] = index;
            Session["fromdate"] = ds.Tables[0].Rows[0]["prev_repl_date"].ToString();
            Session["todate"] = ds.Tables[0].Rows[0]["repl_date"].ToString();
            Session["fromtime"] = ds.Tables[0].Rows[0]["prev_repl_time"].ToString();
            Session["totime"] = ds.Tables[0].Rows[0]["repl_time"].ToString();
            viewClaims(Session["fromdate"].ToString(), Session["todate"].ToString(), Session["fromtime"].ToString(), Session["totime"].ToString(), index, Helper.gridSize(), 1);



            if (chkFromBase24.Checked)
            {
                txtRejected.Text = "NA";
                txtRetracted.Text = "NA";
            }
            else
            {
                oracom = new OracleCommand();
                oracom.Connection = oracon;

                oracom.CommandType = CommandType.StoredProcedure;
                oracom.CommandText = "atm_replenishment_editor.get_atm_ret_rej";

                oracom.Parameters.Clear();
                oracom.Parameters.Add("p_atm_id", OracleType.VarChar).Direction = ParameterDirection.Input;
                oracom.Parameters.Add("p_pre_clear_date", OracleType.VarChar).Direction = ParameterDirection.Input;
                oracom.Parameters.Add("p_pre_clear_time", OracleType.VarChar).Direction = ParameterDirection.Input;
                oracom.Parameters.Add("p_msg_date", OracleType.VarChar).Direction = ParameterDirection.Input;
                oracom.Parameters.Add("p_msg_time", OracleType.VarChar).Direction = ParameterDirection.Input;
                oracom.Parameters.Add("p_amount_rej", OracleType.Number).Direction = ParameterDirection.Output;
                oracom.Parameters.Add("p_amount_ret", OracleType.Number).Direction = ParameterDirection.Output;


                oracom.Parameters["p_atm_id"].Value = txtATMNumberAdd.Text;
                oracom.Parameters["p_pre_clear_date"].Value = datePrev.date;
                if (txtPreTime.Text.Length > 0)
                    oracom.Parameters["p_pre_clear_time"].Value = txtPreTime.Text.Substring(0, 5);
                else
                    oracom.Parameters["p_pre_clear_time"].Value = OracleString.Null;
                oracom.Parameters["p_msg_date"].Value = dateCurrent.date;
                if (txtReplTime.Text.Length > 0)
                    oracom.Parameters["p_msg_time"].Value = txtRepTime.Text.Substring(0, 5);
                else
                    oracom.Parameters["p_msg_time"].Value = OracleString.Null;
                              
                da = new OracleDataAdapter(oracom);
                ds = new DataSet();
                da.Fill(ds);
                //txtRetracted.Text = oracom.Parameters["p_amount_ret"].Value.ToString();
                txtRejected.Text = oracom.Parameters["p_amount_rej"].Value.ToString();
            }

        }
    }

    private void viewClaims(string fromdate, string todate, string fromtime, string totime, int index, 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 = "claim_process.get_atm_claims_for_period";


        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rec_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_from_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_to_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_from_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_to_time", 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_atm_num"].Value = txtTerminal.Text;
        oracom.Parameters["p_rec_type"].Value = "030";
        oracom.Parameters["p_from_date"].Value = fromdate;
        oracom.Parameters["p_to_date"].Value = todate;
        oracom.Parameters["p_from_time"].Value = fromtime;
        oracom.Parameters["p_to_time"].Value = totime;

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

        GridView2.DataSource = ds;
        GridView2.DataBind();
        if (pageNumber == 1)
        {
            DropDownList3.Items.Clear();
            for (int i = 1; i <= nop; i++)
            {
                DropDownList3.Items.Add(i.ToString());
            }
        }
    }

    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        int index = int.Parse(ViewState["index"].ToString());
        viewClaims(Session["fromdate"].ToString(), Session["todate"].ToString(), Session["fromtime"].ToString(), Session["totime"].ToString(), index, Helper.gridSize(), int.Parse(DropDownList3.SelectedValue));
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["status"] == null)
        {
            pnlControls.Visible = false;
            pnlResult.Enabled = true;
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "ATM Deposit Replenishment", "window.close()", true);
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        pnl_confirmation_recon.Visible = true;
        pnlResult.Enabled = false;
        pnlControls.Visible = false;
        //try
        //{
        //    if (txtPrevB24Time.Text.Length != 0 && txtPrevB24Time.Text.Length != 8)
        //        lblError.Text = "time fields must be entered correctly";
        //    else if (txtB24Time.Text.Length != 0 && txtB24Time.Text.Length != 8)
        //        lblError.Text = "time fields must be entered correctly";
        //    else if (txtPreTime.Text.Length != 0 && txtPreTime.Text.Length != 8)
        //        lblError.Text = "time fields must be entered correctly";
        //    else if (txtRepTime.Text.Length != 0 && txtRepTime.Text.Length != 8)
        //        lblError.Text = "time fields must be entered correctly";
        //    else
        //    {
        //        string mode = ViewState["mode"].ToString();
        //        string error = "";

        //        if (mode.Equals("a"))
        //        {
        //            bool saved = addRepl(ref error);
        //            if (saved)
        //            {
        //                lblError.Text = "Replenishment data Saved";
        //            }
        //            else
        //            {
        //                lblError.Text = error;
        //            }
        //        }
        //        else if (mode.Equals("u"))
        //        {
        //            string Uid = ViewState["rowid"].ToString();
        //            if (TextBox11.Text.Length > 0)
        //            {
        //                bool saved = updateRepl(Uid, ref error);
        //                if (saved)
        //                {
        //                    lblError.Text = "Replenishment data Saved";
        //                }
        //                else
        //                {
        //                    lblError.Text = error;
        //                }
        //            }
        //            else
        //            {
        //                lblError.Text = "Please enter opening balance";
        //            }
        //        }
        //        //getrepS();
        //        ViewState["mode"] = null;
        //        ViewState["rowid"] = null;
        //        pnlControls.Visible = false;
        //        pnlResult.Enabled = true;
        //        lblError.Visible = true;
        //    }
        //}
        //catch (Exception ex)
        //{
        //}
    }

    private bool addRepl(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_DEP_REPLENISHMENT_EDITOR.add_atm_replenishment";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rid", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_branch_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_prev_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_prev_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_b24_prepl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_b24_prepl_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_b24_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_b24_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_repl_cur", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_amt_disp", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_amt_frm_vault", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_amt_to_vault", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_record_status", 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;


        if (ViewState["rowid"] != null)
            oracom.Parameters["p_rid"].Value = ViewState["rowid"];
        else
            oracom.Parameters["p_rid"].Value = "0";
        oracom.Parameters["p_branch_code"].Value = DropDownList1.SelectedValue;
        oracom.Parameters["p_atm_num"].Value = txtATMNumberAdd.Text;

        oracom.Parameters["p_prev_repl_date"].Value = datePrev.date;
        oracom.Parameters["p_prev_repl_time"].Value = txtPreTime.Text.Replace(":", "");
        oracom.Parameters["p_repl_date"].Value = dateCurrent.date;
        oracom.Parameters["p_repl_time"].Value = txtRepTime.Text.Replace(":", "");

        if (dateB24PrevDate.date.Length > 0)
            oracom.Parameters["p_b24_prepl_date"].Value = dateB24PrevDate.date;
        else
            oracom.Parameters["p_b24_prepl_date"].Value = OracleString.Null;
        oracom.Parameters["p_b24_prepl_time"].Value = txtPrevB24Time.Text.Replace(":", "");
        if (dateB24Date.date.Length > 0)
            oracom.Parameters["p_b24_repl_date"].Value = dateB24Date.date;
        else
            oracom.Parameters["p_b24_repl_date"].Value = OracleString.Null;
        oracom.Parameters["p_b24_repl_time"].Value = txtB24Time.Text.Replace(":", "");


        oracom.Parameters["p_repl_cur"].Value = ddlCurrency.SelectedValue; //TextBox5.Text;

        if (getNumber(TextBox6.Text).Length > 0)
            oracom.Parameters["p_amt_disp"].Value = getNumber(TextBox6.Text);
        else
            oracom.Parameters["p_amt_disp"].Value = OracleNumber.Null;

        if (getNumber(TextBox7.Text).Length > 0)
            oracom.Parameters["p_amt_frm_vault"].Value = getNumber(TextBox7.Text);
        else
            oracom.Parameters["p_amt_frm_vault"].Value = OracleNumber.Null;

        if (getNumber(TextBox8.Text).Length > 0)
            oracom.Parameters["p_amt_to_vault"].Value = getNumber(TextBox8.Text);
        else
            oracom.Parameters["p_amt_to_vault"].Value = OracleNumber.Null;

        oracom.Parameters["p_record_status"].Value = ddlStatus.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 updateRepl(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_DEP_REPLENISHMENT_EDITOR.update_atm_replenishment";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rid", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_prev_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_prev_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_b24_prepl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_b24_prepl_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_b24_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_b24_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_amt_disp", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_record_status", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_open_bal", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_close_bal", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_error_desc", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_reason", 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_rid"].Value = rowID;

        if (dateB24PrevDate.date.Length > 0)
            oracom.Parameters["p_b24_prepl_date"].Value = dateB24PrevDate.date;
        else
            oracom.Parameters["p_b24_prepl_date"].Value = OracleString.Null;

        oracom.Parameters["p_b24_prepl_time"].Value = txtPrevB24Time.Text.Replace(":", "");
        if (dateB24Date.date.Length > 0)
            oracom.Parameters["p_b24_repl_date"].Value = dateB24Date.date;
        else
            oracom.Parameters["p_b24_repl_date"].Value = OracleString.Null;
        oracom.Parameters["p_b24_repl_time"].Value = txtB24Time.Text.Replace(":", "");

        oracom.Parameters["p_prev_repl_date"].Value = datePrev.date;
        oracom.Parameters["p_repl_date"].Value = dateCurrent.date;
        oracom.Parameters["p_prev_repl_time"].Value = txtPreTime.Text.Replace(":", "");
        oracom.Parameters["p_repl_time"].Value = txtRepTime.Text.Replace(":", "");

        if (getNumber(TextBox6.Text).Length > 0)
            oracom.Parameters["p_amt_disp"].Value = getNumber(TextBox6.Text);
        else
            oracom.Parameters["p_amt_disp"].Value = OracleNumber.Null;

        oracom.Parameters["p_record_status"].Value = ddlStatus.SelectedValue;
        oracom.Parameters["p_open_bal"].Value = getNumber(TextBox11.Text);
        oracom.Parameters["p_close_bal"].Value = getNumber(TextBox12.Text);
        oracom.Parameters["p_error_desc"].Value = TextBox1.Text;
        if (ddlModifyReason.SelectedIndex > 0)
            oracom.Parameters["p_reason"].Value = ddlModifyReason.SelectedValue;
        else
            oracom.Parameters["p_reason"].Value = OracleString.Null;

        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)
        //{
        //    for (int i = 7; i <= 39;i++ )
        //        e.Row.Cells[i].Visible = false;
        //}
    }

    private string getNumber(string amount)
    {
        
            return amount.Replace(",", "");
       
    }

    private void clear()
    {
        datePrev.date = "";
        lblPrevReplDate.Text = "";
        txtPreTime.Text = "";
        dateCurrent.date = "";
        lblReplDate.Text = "";
        txtRepTime.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox8.Text = "";
        ddlStatus.SelectedIndex = 0;
        TextBox10.Text = "";
        TextBox11.Text = "";
        TextBox12.Text = "";
        TextBox13.Text = "";
        TextBox14.Text = "";
        TextBox15.Text = "";
        TextBox16.Text = "";
        TextBox17.Text = "";
        TextBox18.Text = "";
        TextBox19.Text = "";
        TextBox1.Text = "";
        TextBox3.Text = "";
        ddlModifyReason.SelectedIndex = 0;
        chkFromBase24.Checked = false;
        lblClAdd.Text = "";
        lblBANCS.Text = "";
        TextBox20.Text = "";
        TextBox21.Text = "";
        TextBox22.Text = "";
        txtATMNumberAdd.Text = "";
        lblUser.Text = "";
        lblUserDate.Text = "";
        dateB24PrevDate.date = "";
        dateB24Date.date = "";
        txtB24Time.Text = "";
        txtPrevB24Time.Text = "";

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

       // StringBuilder sb = new StringBuilder();
       // string atmNo = txtATMNumberAdd.Text.Trim();
       // string branchNo = DropDownList1.SelectedValue;
       // string replDate = dateCurrent.date;
       // string replTime = txtRepTime.Text.Trim();
       // string atmType = "Deposit";
       // string replCurrency = ddlCurrency.SelectedItem.Text;
       // string glAcctNo = ViewState["acctNo"].ToString();
       // string openingBalance = TextBox11.Text.Trim();
       // string closingBalance = TextBox12.Text.Trim();

       // if (!atmNo.Equals("&nbsp;"))
       //     sb.Append("atmno=" + atmNo + "&");

       // if (!replDate.Equals("&nbsp;"))
       //     sb.Append("replDate=" + replDate + "&");

       // if (!replTime.Equals("&nbsp;"))
       //     sb.Append("replTime=" + replTime + "&");

       // if (!atmType.Equals("&nbsp;"))
       //     sb.Append("atmType=" + atmType + "&");

       // if (!replCurrency.Equals("&nbsp;"))
       //     sb.Append("replCurrency=" + replCurrency + "&");

       // if (!glAcctNo.Equals("&nbsp;"))
       //     sb.Append("glAcctNo=" + glAcctNo + "&");

       // if (!openingBalance.Equals("&nbsp;"))
       //     sb.Append("openingBalance=" + openingBalance + "&");

       // if (!closingBalance.Equals("&nbsp;"))
       //     sb.Append("closingBalance=" + closingBalance + "&");

       // string queryString = sb.ToString();
       // queryString = queryString.TrimEnd('&');

       //// ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
       //                    // "window.open('ManualGLEntry.aspx?" + queryString + "','ManualGLEntry')", true);

       // ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
       //                          "window.open('ManualGLEntry.aspx?" + queryString + "','popWindow','toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=350,left=300,top=50')", true);
    }
    protected void btn_confirm_ok_glentry_Click(object sender, EventArgs e)
    {

        pnlManualGlEntry.Visible = true;
        pnl_confirmation_glentry.Visible = false;
        pnlResult.Visible = true;
        pnlControls.Visible = false;

        //StringBuilder sb = new StringBuilder();
        txtTerminalID.Text = "";
        dtReplDate.date = "";
        txtReplTime.Text = "";
        
        txtGLAccountNo.Text = "";
        txtOpeningBalance.Text = "";
        txtClosingBalance.Text = "";

        string glAcctNo = "";
        string atmNo = txtATMNumberAdd.Text.Trim();
        string branchNo = DropDownList1.SelectedValue;
        string replDate = dateCurrent.date;
        string replTime = txtRepTime.Text.Trim();
        
        string replCurrency = ddlCurrency.SelectedItem.Text;
        if (ViewState["acctNo"] != null)
            glAcctNo = ViewState["acctNo"].ToString();
        string openingBalance = TextBox11.Text.Trim();
        string closingBalance = TextBox12.Text.Trim();

        txtTerminalID.Enabled = false;

        if (!atmNo.Equals("&nbsp;"))
            txtTerminalID.Text = atmNo;
            //sb.Append("atmno=" + atmNo + "&");

        if (!replDate.Equals("&nbsp;"))
        {
            if (replDate.Length > 0)
            {
                txtReplDate.Visible = false;
                dtReplDate.Visible = true;
                //txtReplDate.Text = Request.QueryString["replDate"];

                string d, m, y;
                d = replDate.Substring(4, 2);
                m = replDate.Substring(2, 2);
                y = replDate.Substring(0, 2);
                dtReplDate.date = d + "-" + m + "-" + "20" + y;
            }
        }
            //sb.Append("replDate=" + replDate + "&");

        if (!replTime.Equals("&nbsp;"))
            txtReplTime.Text = replTime;
            //sb.Append("replTime=" + replTime + "&");

        ddlReplType.SelectedValue = "030";

        

        if (!glAcctNo.Equals("&nbsp;"))
            txtGLAccountNo.Text = glAcctNo;
            //sb.Append("glAcctNo=" + glAcctNo + "&");

        if (!openingBalance.Equals("&nbsp;"))
            txtOpeningBalance.Text = openingBalance;
            //sb.Append("openingBalance=" + openingBalance + "&");

        if (!closingBalance.Equals("&nbsp;"))
            txtClosingBalance.Text = closingBalance;
            //sb.Append("closingBalance=" + closingBalance + "&");

        //string queryString = sb.ToString();
        //queryString = queryString.TrimEnd('&');

        // ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        // "window.open('ManualGLEntry.aspx?" + queryString + "','ManualGLEntry')", true);

        //ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        //                         "window.open('ManualGLEntry.aspx?" + queryString + "','popWindow','toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=350,left=300,top=50')", true);
    }
    protected void btn_confirm_cancel_glentry_Click(object sender, EventArgs e)
    {
        pnl_confirmation_glentry.Visible = false;
        pnl_confirmation_recon.Visible = false;
        pnlControls.Visible = true;
        pnlResult.Visible = true;
        pnlSearch.Enabled = true;
    }
    protected void btn_conf_ok_Click(object sender, EventArgs e)
    {
        pnl_confirmation_recon.Visible = false;
        pnlControls.Visible = false;
        pnlSearch.Enabled = true;
        try
        {
            if (txtPrevB24Time.Text.Length != 0 && txtPrevB24Time.Text.Length != 8)
            {                
                lblError.Text = "time fields must be entered correctly";
                pnlControls.Visible = true;
                return;
            }
            else if (txtB24Time.Text.Length != 0 && txtB24Time.Text.Length != 8)
            {
                lblError.Text = "time fields must be entered correctly";
                pnlControls.Visible = true;
                return;
            }
            else if (txtPreTime.Text.Length != 0 && txtPreTime.Text.Length != 8)
            {
                lblError.Text = "time fields must be entered correctly";
                pnlControls.Visible = true;
                return;
            }
            else if (txtRepTime.Text.Length != 0 && txtRepTime.Text.Length != 8)
            {
                lblError.Text = "time fields must be entered correctly";
                pnlControls.Visible = true;
                return;
            }
            else if (datePrev.date.Length > 0 && dateCurrent.date.Length > 0)
            {
                if (int.Parse(datePrev.date) > int.Parse(dateCurrent.date))
                {
                    lblError.Text = "Previos Replenishment Date should be less than Replenishment Date";
                    pnlControls.Visible = true;
                    return;
                }
                else
                {
                    string mode = ViewState["mode"].ToString();
                    string error = "";

                    if (mode.Equals("a"))
                    {
                        bool saved = addRepl(ref error);
                        if (saved)
                        {
                            lblError.ForeColor = System.Drawing.Color.DarkGreen;
                            lblError.Text = "Replenishment data Saved";
                            pnlControls.Visible = true;
                            btnSave.Visible = false;
                        }
                        else
                        {
                            lblError.Text = error;
                            pnlControls.Visible = true;
                            
                        }
                    }
                    else if (mode.Equals("u"))
                    {
                        string Uid = ViewState["rowid"].ToString();
                        if (Uid.Length > 0)
                        {
                            if (TextBox11.Text.Length > 0)
                            {
                                bool saved = updateRepl(Uid, ref error);
                                if (saved)
                                {
                                    lblError.ForeColor = System.Drawing.Color.DarkGreen;
                                    lblError.Text = "Replenishment data Saved";
                                    pnlControls.Visible = true;
                                    btnSave.Visible = false;
                                    
                                }
                                else
                                {
                                    lblError.Text = error;
                                    pnlControls.Visible = true;
                                    
                                }
                            }
                            else
                            {
                                lblError.Text = "Please enter opening balance";
                                pnlControls.Visible = true;
                                return;
                            }
                        }
                        else
                        {
                            bool saved = addRepl(ref error);
                            if (saved)
                            {
                                lblError.ForeColor = System.Drawing.Color.DarkGreen;
                                lblError.Text = "Replenishment data Saved";
                                pnlControls.Visible = true;
                                btnSave.Visible = false;
                            }
                            else
                            {
                                lblError.Text = error;
                                pnlControls.Visible = true;
                                return;
                            }
                        }
                    }
                }
            }
            else
            {
                string mode = ViewState["mode"].ToString();
                string error = "";

                if (mode.Equals("a"))
                {
                    bool saved = addRepl(ref error);
                    if (saved)
                    {
                        lblError.ForeColor = System.Drawing.Color.DarkGreen;
                        lblError.Text = "Replenishment data Saved";
                        pnlControls.Visible = true;
                        btnSave.Visible = false;
                    }
                    else
                    {
                        lblError.Text = error;
                    }
                }
                else if (mode.Equals("u"))
                {
                    string Uid = ViewState["rowid"].ToString();
                    if (Uid.Length > 0)
                    {
                        if (TextBox11.Text.Length > 0)
                        {
                            bool saved = updateRepl(Uid, ref error);
                            if (saved)
                            {
                                lblError.ForeColor = System.Drawing.Color.DarkGreen;
                                lblError.Text = "Replenishment data Saved";
                                pnlControls.Visible = true;
                                btnSave.Visible = false;
                            }
                            else
                            {
                                lblError.Text = error;
                                pnlControls.Visible = true;
                                
                            }
                        }
                        else
                        {
                            lblError.Text = "Please enter opening balance";
                            pnlControls.Visible = true;
                            btnSave.Visible = false;
                        }
                    }
                    else
                    {
                        bool saved = addRepl(ref error);
                        if (saved)
                        {
                            lblError.ForeColor = System.Drawing.Color.DarkGreen;
                            lblError.Text = "Replenishment data Saved";
                            pnlControls.Visible = true;
                            btnSave.Visible = false;
                        }
                        else
                        {
                            lblError.Text = error;
                            pnlControls.Visible = true;
                            
                        }
                    }
                }
                //getrepS();
                ViewState["mode"] = null;
                ViewState["rowid"] = null;
                if (Request.QueryString["status"] == null)
                {
                    pnlControls.Visible = false;
                    pnlResult.Enabled = true;
                }
                else
                {
                    pnlControls.Visible = true;
                    btnSave.Enabled = false;
                }

                lblError.Visible = true;
                loadResult(Helper.gridSize(), 1);
            }
        }
        catch (Exception ex)
        {
        }
    }
    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static List<string> GetCompletionList(string prefixText, int count)
    {
        return AutoFillAtmNo(prefixText);

    }
    private static List<string> AutoFillAtmNo(string prefixText)
    {
        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.Text;
        oracom.CommandText = "select distinct substr(terminal_id,-4) as atm_number from atm_repl_details where record_type='030' and substr(terminal_id,-4) like '" + prefixText + "%' ";

        //oracom.Parameters.Add("p_value",OracleType.VarChar).Direction=ParameterDirection.Input;


        //oracom.Parameters["p_value"].Value = prefixText;

        List<string> atmList = new List<string>();
        OracleDataReader odr = oracom.ExecuteReader();

        while (odr.Read())
        {
            atmList.Add(odr["atm_number"].ToString());
        }

        oracon.Close();
        return atmList;

    }
    protected void btn_conf_cancel_Click(object sender, EventArgs e)
    {
        pnl_confirmation_recon.Visible = false;
        pnlControls.Visible = false;
        pnlResult.Enabled = true;
    }
    private bool addBancsRepl(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_summary_viewer.add_manual_gl_entry";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rid", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_repl_cur", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_gl_account", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_opening_balance", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_closing_balance", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_retractAmt", OracleType.Number).Direction = ParameterDirection.Input; // irfan_mod
      
        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_rid"].Value = ViewState["rowid"];
        oracom.Parameters["p_atm_num"].Value = txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4);
        oracom.Parameters["p_repl_date"].Value = dtReplDate.date;
        // oracom.Parameters["p_repl_date"].Value = txtReplDate.Text;
        oracom.Parameters["p_repl_time"].Value = txtReplTime.Text.Replace(":", "");
        oracom.Parameters["p_atm_type"].Value = "030";
        oracom.Parameters["p_repl_cur"].Value = DropDownList2.SelectedValue;
        oracom.Parameters["p_gl_account"].Value = txtGLAccountNo.Text;

        if (getNumber(txtOpeningBalance.Text).Length > 0)
            oracom.Parameters["p_opening_balance"].Value = getNumber(txtOpeningBalance.Text);
        else
            oracom.Parameters["p_opening_balance"].Value = OracleNumber.Null;

        if (getNumber(txtClosingBalance.Text).Length > 0)
            oracom.Parameters["p_closing_balance"].Value = getNumber(txtClosingBalance.Text);
        else
            oracom.Parameters["p_closing_balance"].Value = OracleNumber.Null;

        oracom.Parameters["p_retractAmt"].Value = OracleNumber.Null; // // irfan_mod

        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 btnSaveManualGlEntry_Click(object sender, EventArgs e)
    {
        string error = "";
        string openingBalance;
        string closingBalance;
        if (txtOpeningBalance.Text.Length == 0)
            openingBalance = "0";
        else
            openingBalance = txtOpeningBalance.Text;

        if (txtClosingBalance.Text.Length == 0)
            closingBalance = "0";
        else
            closingBalance = txtClosingBalance.Text;

        if (double.Parse(getNumber(openingBalance)) > 0 || double.Parse(getNumber(closingBalance)) > 0)
        {
            if (dtReplDate.date.Length > 0)
            {
                if (txtReplTime.Text.Length > 0)
                {
                    if (txtGLAccountNo.Text.Length > 0)
                    {
                        //btnSave.Enabled = false;
                        bool saved = addBancsRepl(ref error);
                        if (saved)
                        {
                            //lblError1.Visible = true;
                            lblError1.ForeColor = System.Drawing.Color.DarkGreen;
                            lblError1.Text = "Manual GL Entry Saved!!";
                            btnEdit.Visible = false;
                            btnSave.Visible = false;
                            btnManualGLEntry.Visible = false;
                            //Session["Msg"] = lblError1.Text;
                            //Label lbl = ((Label)PreviousPage.FindControl("lblError1"));
                            //lbl.Text = lblError1.Text;
                            //ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.close();", true);

                        }
                        else
                        {
                            lblError1.Visible = true;
                            lblError1.Text = error;
                            pnlManualGlEntry.Visible = true;
                            pnlControls.Visible = false;
                            return;
                        }
                    }
                    else
                    {
                        lblError1.Visible = true;
                        lblError1.Text = "Please enter Account No.";
                        pnlManualGlEntry.Visible = true;
                        pnlControls.Visible = false;
                        return;
                    }
                }
                else
                {
                    lblError1.Visible = true;
                    lblError1.Text = "Please enter Replenishment Time";
                    pnlManualGlEntry.Visible = true;
                    pnlControls.Visible = false;
                    return;
                }
            }
            else
            {
                lblError1.Visible = true;
                lblError1.Text = "Please enter Replenishment Date";
                pnlManualGlEntry.Visible = true;
                pnlControls.Visible = false;
                return;
            }
        }
        else
        {
            lblError1.Visible = true;
            lblError1.Text = "Either Opening Balance or Closing Balance greater than zero";
            pnlManualGlEntry.Visible = true;
            pnlControls.Visible = false;
            return;
        }
        pnlManualGlEntry.Visible = false;
        pnlControls.Visible = true;
    }
    protected void btnCancelManualGlEntry_Click(object sender, EventArgs e)
    {
        pnlManualGlEntry.Visible = false;
        pnlSearch.Enabled = true;
        pnlResult.Enabled = true;
    }

    
    protected void btnEdit_Click1(object sender, EventArgs e)
    {
        ddlModifyReason.SelectedValue = "4";
        ddlStatus.SelectedValue = "020";
        ViewState["mode"] = "a";
        ddlModifyReason.Enabled = false;
        ddlStatus.Enabled = false;
        TextBox6.Enabled = true;
        btnEdit.Visible = false;
    }

    protected void btn_DifferenceGlEntry_Click(object sender, EventArgs e)
    {
        PanelGlEntrySave.Visible = true;
        //pnl_confirmation_glentry.Visible = false;
        //pnlSearch.Enabled = false;
        //pnl_confirmation_recon.Visible = false;
        pnlControls.Enabled = false;
        //pnlResult.Enabled = false;
        lblError_PanelGlEntrySave.Text = "";

        GetGlEntry();


    }
    protected void btn_GlEntrySave_Click(object sender, EventArgs e)
    {

        SaveGlEntry();
        btn_GlEntrySave.Enabled = false;
    }
    protected void btn_GlEntryCancel_Click(object sender, EventArgs e)
    {
        PanelGlEntrySave.Visible = false;
        pnlControls.Enabled = true;
        lblError_PanelGlEntrySave.Text = "";
        btn_GlEntryDelete.Enabled = true;
        btn_GlEntrySave.Enabled = true;

    }
    protected void ddlShortageType_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblError_PanelGlEntrySave.Text = "";

        GetGlEntry();


    }
    private void SaveGlEntry()
    {


        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_summary_viewer.GenerateGL_ReplEntry";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_RID", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("Posting_for_ReplDate", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("Acct_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("settle_account", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("gl_tran_amt", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("GL_Desc", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_Res", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();
        oracom.Parameters["p_RID"].Value = ViewState["rowid"];
        oracom.Parameters["Posting_for_ReplDate"].Value = lbl_Posting_for_ReplDate.Text.Substring(8, 2) + lbl_Posting_for_ReplDate.Text.Substring(3, 2) + lbl_Posting_for_ReplDate.Text.Substring(0, 2);
        oracom.Parameters["p_atm_number"].Value = lbl_ATM_NO.Text;
        oracom.Parameters["Acct_number"].Value = lbl_Acct_number.Text;
        oracom.Parameters["settle_account"].Value = lbl_settle_account.Text;

        oracom.Parameters["gl_tran_amt"].Value = Convert.ToDecimal(lbl_gl_tran_amt.Text);
        oracom.Parameters["GL_Desc"].Value = txt_GL_Desc.Text;

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

        string error = oracom.Parameters["p_Res"].Value.ToString();
        if (error == "Sucessful")
        {
            lblError_PanelGlEntrySave.ForeColor = System.Drawing.Color.DarkGreen;
            lblError_PanelGlEntrySave.Text = "Successfully Created Entry";
        }
        else
        {
            lblError_PanelGlEntrySave.Text = error;
        }
    }

    private void GetGlEntry()
    {
        if (lblBANCS.Text == "Shortage" && ddlShortageType.SelectedIndex < 1)
        {
            lblError_PanelGlEntrySave.Text = "Please Select Shortage Type";
            return;
        }

        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_summary_viewer.GetATMRepl_GL";

        oracom.Parameters.Add("p_RID", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_AcctType", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_SubAcctTYpe", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_Res", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_RID"].Value = ViewState["rowid"];

        if (lblBANCS.Text == "Overage")
        {
            oracom.Parameters["p_AcctType"].Value = 1;
            oracom.Parameters["p_SubAcctTYpe"].Value = 0;
        }
        else if (lblBANCS.Text == "Shortage")
        {
            oracom.Parameters["p_AcctType"].Value = 2;
            oracom.Parameters["p_SubAcctTYpe"].Value = Convert.ToInt32(ddlShortageType.SelectedValue);
        }
        // oracom.Parameters["p_atm_num"].Value = txtTerminalID.Text.Substring(txtTerminalID.Text.Length - 4);
        // oracom.Parameters["p_repl_date"].Value = dtReplDate.date;
        // oracom.Parameters["p_repl_date"].Value = txtReplDate.Text;


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

        string error = oracom.Parameters["p_Res"].Value.ToString();
        if (error != "Successful")
        {
            lblError_PanelGlEntrySave.Text = error;
            btn_GlEntrySave.Enabled = false;
            ddlShortageType.Enabled = false;
            txt_GL_Desc.Enabled = false;
        }
        else // Enable Save
        {
            btn_GlEntrySave.Enabled = true;
            ddlShortageType.Enabled = true;
            txt_GL_Desc.Enabled = true;
        }
        lbl_CreatedDate.Text = ds.Tables[0].Rows[0]["GL_Created_Date"].ToString();
        lbl_Posting_for_ReplDate.Text = ds.Tables[0].Rows[0]["Posting_for_ReplDate"].ToString();
        lbl_Acct_number.Text = ds.Tables[0].Rows[0]["Acct_number"].ToString();
        lbl_settle_account.Text = ds.Tables[0].Rows[0]["settle_account"].ToString();
        lbl_txn_type.Text = ds.Tables[0].Rows[0]["txn_type"].ToString();
        lbl_approved_by.Text = ds.Tables[0].Rows[0]["approved"].ToString();
        lbl_approve_date.Text = ds.Tables[0].Rows[0]["approve_date"].ToString();
        lbl_gl_tran_amt.Text = ds.Tables[0].Rows[0]["gl_tran_amt"].ToString();
        txt_GL_Desc.Text = ds.Tables[0].Rows[0]["GL_Desc"].ToString();

        lbl_POSTED.Text = ds.Tables[0].Rows[0]["POSTED"].ToString();
        lbl_GPE_CODE.Text = ds.Tables[0].Rows[0]["GPE_CODE"].ToString();
        lbl_ATM_NO.Text = ds.Tables[0].Rows[0]["atm_no"].ToString();


    }

    private void DeleteGlEntry()
    {


        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_summary_viewer.DEL_ATMREPLGL";

        oracom.Parameters.Add("p_gpe_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_Res", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gpe_code"].Value = Convert.ToInt32(lbl_GPE_CODE.Text);
        oracom.ExecuteNonQuery();
        oracon.Close();

        string error = oracom.Parameters["p_Res"].Value.ToString();
        if (error == "Successful")
        {
            lblError_PanelGlEntrySave.ForeColor = System.Drawing.Color.DarkGreen;
            lblError_PanelGlEntrySave.Text = "Successfully Deleted Entry";
            btn_GlEntryDelete.Enabled = false;
            PanelGlEntrySave.Visible = true;
        }
        else
        {
            lblError_PanelGlEntrySave.Text = error;
        }
    }

    protected void btn_GlEntryDelete_Click(object sender, EventArgs e)
    {
        DeleteGlEntry();
    }
}

