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 TSearchAll : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pnlControls.Visible = false;
            pnlControlsChannel.Visible = false;
            pnlControlsEJ.Visible = false;
        }
    }

    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 = "TRANSACTIONS_SEARCHER.Search_Master_Tran";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_re_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_card_no", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date_from", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date_to", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_time_from", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_time_to", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_source", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dest", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_acct_num", 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_re_code"].Value = OracleNumber.Null;
        oracom.Parameters["p_card_no"].Value = txtCardNumber.Text;
        oracom.Parameters["p_tran_date_from"].Value = DatePicker1.date;
        oracom.Parameters["p_tran_date_to"].Value = DatePicker2.date;
        oracom.Parameters["p_tran_time_from"].Value = "";
        oracom.Parameters["p_tran_time_to"].Value = "";

        oracom.Parameters["p_rrn"].Value = txtRefNo.Text;
        oracom.Parameters["p_atm_num"].Value = txtATM.Text;

        if (txtAccountNo.Text.Trim().Length > 0)
            oracom.Parameters["p_acct_num"].Value = txtAccountNo.Text.Trim();
        else
            oracom.Parameters["p_acct_num"].Value = OracleString.Null;

      
            oracom.Parameters["p_dest"].Value = OracleNumber.Null;
     
            oracom.Parameters["p_source"].Value = OracleNumber.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());
            }
        }
    }


    private void loadResultChannels(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 = "TRANSACTIONS_SEARCHER.Search_Channels_Tran";

        oracom.Parameters.Add("p_rc_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_re_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_card_no", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date_from", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date_to", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_source", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dest", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_page_size", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_page_num", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;


            oracom.Parameters["p_rc_code"].Value = OracleNumber.Null;
            oracom.Parameters["p_re_code"].Value = OracleNumber.Null;
            oracom.Parameters["p_card_no"].Value = txtCardNumber.Text.Trim();
            oracom.Parameters["p_tran_date_from"].Value = DatePicker1.date;
            oracom.Parameters["p_tran_date_to"].Value = DatePicker2.date; ;
            oracom.Parameters["p_rrn"].Value = txtRefNo.Text.ToString();
            oracom.Parameters["p_term_id"].Value = txtATM.Text;

            oracom.Parameters["p_dest"].Value = OracleNumber.Null;
            oracom.Parameters["p_source"].Value = OracleNumber.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();


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


    private void loadResultEJ(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 = "TRANSACTIONS_SEARCHER.search_ej_tran";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_card_no", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date_from", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date_to", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_ACCT_NO", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", 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_card_no"].Value = txtCardNumber.Text;
        oracom.Parameters["p_tran_date_from"].Value = DatePicker1.date;
        oracom.Parameters["p_tran_date_to"].Value = DatePicker2.date;
        oracom.Parameters["p_ACCT_NO"].Value = txtAccountNo.Text;
        oracom.Parameters["p_atm_num"].Value = txtATM.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());

        if (nop == -1 && ds.Tables[0].Rows.Count > 0)
            nop = int.Parse(Math.Ceiling((double.Parse(ds.Tables[0].Rows[0]["ROW_COUNT"].ToString()) / pageSize)).ToString());
        oracon.Close();

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

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DatePicker1.date.Length == 0 || DatePicker2.date.Length == 0)
            lblError.Text = "Please Enter (From) and (To) dates";
        else if (txtCardNumber.Text.Trim().Length== 0 && txtATM.Text.Trim().Length == 0 && txtRefNo.Text.Trim().Length==0)
        {
            lblError.Text = "Please Enter one of the fields i.e Card No. or Terminal No. or Reference No.";
        }
        else
        {
            lblError.Text = "";
            pnlResult.Visible = true;
            pnlResultChannel.Visible = true;
            pnlResultEJ.Visible = true;
            loadResult(Helper.gridSize(), 1);
            loadResultChannels(Helper.gridSize(), 1);
            loadResultEJ(Helper.gridSize(), 1);
            pnlControls.Visible = false;
            pnlControlsChannel.Visible = false;
            pnlControlsEJ.Visible = false;
        }
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadResult(Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
        pnlControls.Visible = false;
    }

    protected void ddlPages2_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadResultChannels(Helper.gridSize(), int.Parse(ddlPages2.SelectedValue));
        pnlControlsChannel.Visible = false;
    }

    protected void ddlPages3_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadResultEJ(Helper.gridSize(), int.Parse(ddlPages3.SelectedValue));
        pnlControlsEJ.Visible = false;
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("v"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string tID = GridView1.DataKeys[index].Value.ToString();

            loadTranDetails(tID);
        }
    }

    protected void gvChannel_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("v"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string tID = gvChannel.DataKeys[index].Value.ToString();
            loadTranDetails1(tID);
        }
    }

    protected void gvEJ_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("v"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            Label66.Text = gvEJ.Rows[index].Cells[0].Text;
            Label67.Text = gvEJ.Rows[index].Cells[9].Text;
            Label68.Text = gvEJ.Rows[index].Cells[10].Text;
            Label69.Text = gvEJ.Rows[index].Cells[1].Text;
            Label70.Text = gvEJ.Rows[index].Cells[2].Text;
            Label71.Text = gvEJ.Rows[index].Cells[3].Text;
            Label72.Text = gvEJ.Rows[index].Cells[13].Text;
            Label73.Text = gvEJ.Rows[index].Cells[4].Text;
            Label74.Text = gvEJ.Rows[index].Cells[5].Text;
            Label76.Text = gvEJ.Rows[index].Cells[6].Text;
            Label77.Text = gvEJ.Rows[index].Cells[7].Text;
            Label78.Text = gvEJ.Rows[index].Cells[8].Text;
            Label79.Text = gvEJ.Rows[index].Cells[14].Text;
            Label75.Text = gvEJ.Rows[index].Cells[11].Text;
            Label80.Text = gvEJ.Rows[index].Cells[15].Text;
            Label81.Text = gvEJ.Rows[index].Cells[16].Text;
            Label82.Text = gvEJ.Rows[index].Cells[17].Text;

            lblDenom.Text = gvEJ.Rows[index].Cells[22].Text;
            //load the message

            string termid = gvEJ.Rows[index].Cells[6].Text;
            string trace = gvEJ.Rows[index].Cells[9].Text;
            string date = gvEJ.Rows[index].Cells[18].Text;
            string status = gvEJ.Rows[index].Cells[19].Text;
            loadStatus(termid, trace, date, status);
            pnlControlsEJ.Visible = true;
        }
    }

    protected void gvEJ_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
            {
                for (int i = 10; i <= 19; i++)
                    e.Row.Cells[i].Visible = false;

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

    private void loadStatus(string termid, string trace, string date, string status)
    {
        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "ej_recon_searcher.Get_Status_Messages";

        oracom.Parameters.Add("p_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_trace", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_status_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_status_msgs", OracleType.Cursor).Direction = ParameterDirection.Output;


        oracom.Parameters["p_term_id"].Value = termid;
        oracom.Parameters["p_trace"].Value = trace;
        oracom.Parameters["p_tran_date"].Value = date;
        oracom.Parameters["p_status_code"].Value = status;

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

        oracon.Close();

        GridView3.DataSource = ds;
        GridView3.DataBind();
    }

    private void loadTranDetails(string tID)
    {
        pnlClaim.Visible = true;
        pnlControls.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 = "CLAIM_INVESTIGATOR.get_claimmaster_tran";

        oracom.Parameters.Add("p_mt_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claimb24", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_b24match_grid", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_mt_code"].Value = tID;
        txtHMTCODE.Text = tID;

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

        oracon.Close();

        //set the data in the controls
        Label1.Text = ds.Tables[0].Rows[0]["tran_date"].ToString();
        Label2.Text = ds.Tables[0].Rows[0]["tran_time"].ToString();

        Label3.Text = ds.Tables[0].Rows[0]["card_number"].ToString();
        Label4.Text = ds.Tables[0].Rows[0]["term_id"].ToString();
        Label5.Text = ds.Tables[0].Rows[0]["tran_amount"].ToString();
        Label6.Text = ds.Tables[0].Rows[0]["tran_curr"].ToString();
        Label7.Text = ds.Tables[0].Rows[0]["pcode"].ToString();
        Label8.Text = ds.Tables[0].Rows[0]["rrn"].ToString();
        Label9.Text = ds.Tables[0].Rows[0]["tran_source"].ToString();
        Label10.Text = ds.Tables[0].Rows[0]["tran_dest"].ToString();
        Label11.Text = ds.Tables[0].Rows[0]["msg_type"].ToString();
        Label12.Text = ds.Tables[0].Rows[0]["recon_status"].ToString();
        Label13.Text = ds.Tables[0].Rows[0]["merchant_paid"].ToString();
        Label14.Text = ds.Tables[0].Rows[0]["trace_id"].ToString();
        Label15.Text = ds.Tables[0].Rows[0]["b24_rsp"].ToString();
        Label16.Text = ds.Tables[0].Rows[0]["card_brand"].ToString();
        Label17.Text = ds.Tables[0].Rows[0]["card_exp_date"].ToString();
        Label18.Text = ds.Tables[0].Rows[0]["cardholder_account_number"].ToString();
        Label19.Text = ds.Tables[0].Rows[0]["auth_code"].ToString();
        Label20.Text = ds.Tables[0].Rows[0]["buss_class"].ToString();
        Label21.Text = ds.Tables[0].Rows[0]["tran_status"].ToString();
        Label22.Text = ds.Tables[0].Rows[0]["settl_curr"].ToString();
        Label23.Text = ds.Tables[0].Rows[0]["settl_amount"].ToString();
        Label24.Text = ds.Tables[0].Rows[0]["tran_chg"].ToString();
        Label25.Text = ds.Tables[0].Rows[0]["re_code"].ToString();
        Label26.Text = ds.Tables[0].Rows[0]["product"].ToString();
        Label27.Text = ds.Tables[0].Rows[0]["orig_oseq_num"].ToString();
        Label28.Text = ds.Tables[0].Rows[0]["orig_date"].ToString();
        Label29.Text = ds.Tables[0].Rows[0]["amt_2"].ToString();
        Label30.Text = ds.Tables[0].Rows[0]["amt_3"].ToString();
        Label31.Text = ds.Tables[0].Rows[0]["auth_amt"].ToString();

        txtInputTransactionDate.Text = ds.Tables[0].Rows[0]["TRAN_DATE"].ToString();
        txtInputCard.Text = ds.Tables[0].Rows[0]["CARD_NUMBER"].ToString();
        txtInputTerminalID.Text = ds.Tables[0].Rows[0]["TERM_ID"].ToString();
        txtInputAmount.Text = ds.Tables[0].Rows[0]["TRAN_AMOUNT"].ToString();
        txtInputReference.Text = ds.Tables[0].Rows[0]["RRN"].ToString();
        //dd-mm-yyyy
        string d = ds.Tables[0].Rows[0]["TRAN_DATE"].ToString();
        txtHDATE.Text = d.Substring(8) + d.Substring(3,2) + d.Substring(0,2);
        GridView2.DataSource = ds.Tables[1];
        GridView2.DataBind();

    }

    private void loadTranDetails1(string tID)
    {
        pnlControlsChannel.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 = "TRANSACTIONS_SEARCHER.Get_Channel_Tran";

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

        oracom.Parameters["p_ct_code"].Value = tID;

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

        oracon.Close();

        //set the data in the controls
        Label32.Text = ds.Tables[0].Rows[0]["RECORD_DATE"].ToString();
        Label33.Text = ds.Tables[0].Rows[0]["SETTL_DATE"].ToString();

        Label34.Text = ds.Tables[0].Rows[0]["TRAN_DATE"].ToString();
        Label35.Text = ds.Tables[0].Rows[0]["TRAN_TIME"].ToString();
        Label36.Text = ds.Tables[0].Rows[0]["CARD_NUMBER"].ToString();
        Label37.Text = ds.Tables[0].Rows[0]["ISO_RSP"].ToString();
        Label38.Text = ds.Tables[0].Rows[0]["TERM_ID"].ToString();
        Label39.Text = ds.Tables[0].Rows[0]["TRAN_AMOUNT"].ToString();
        Label40.Text = ds.Tables[0].Rows[0]["TRAN_SOURCE"].ToString();
        Label41.Text = ds.Tables[0].Rows[0]["TRAN_DEST"].ToString();
        Label42.Text = ds.Tables[0].Rows[0]["MSG_TYPE"].ToString();
        Label43.Text = ds.Tables[0].Rows[0]["TRACE_ID"].ToString();
        Label44.Text = ds.Tables[0].Rows[0]["FILE_NUMBER"].ToString();
        Label45.Text = ds.Tables[0].Rows[0]["CARD_BRAND"].ToString();
        Label46.Text = ds.Tables[0].Rows[0]["RRN"].ToString();
        Label47.Text = ds.Tables[0].Rows[0]["CARD_EXP_DATE"].ToString();
        Label48.Text = ds.Tables[0].Rows[0]["ACCT_NUMBER"].ToString();
        Label49.Text = ds.Tables[0].Rows[0]["AUTH_CODE"].ToString();
        Label50.Text = ds.Tables[0].Rows[0]["BUSS_CLS"].ToString();
        Label51.Text = ds.Tables[0].Rows[0]["RECON_STATUS"].ToString();
        Label52.Text = ds.Tables[0].Rows[0]["TRAN_CURR"].ToString();
        Label53.Text = ds.Tables[0].Rows[0]["SETTL_CURR"].ToString();
        Label54.Text = ds.Tables[0].Rows[0]["SETTL_AMOUNT"].ToString();
        Label55.Text = ds.Tables[0].Rows[0]["TRAN_CHG"].ToString();
        Label56.Text = ds.Tables[0].Rows[0]["MATCH_RESULT"].ToString();
        Label57.Text = ds.Tables[0].Rows[0]["CHIP_INDEX"].ToString();
        Label58.Text = ds.Tables[0].Rows[0]["channel_name"].ToString();
        Label59.Text = ds.Tables[0].Rows[0]["event_name"].ToString();
        Label60.Text = ds.Tables[0].Rows[0]["PCODE"].ToString();
        Label61.Text = ds.Tables[0].Rows[0]["FINANCIAL_FLAG"].ToString();
        Label62.Text = ds.Tables[0].Rows[0]["PRODUCT"].ToString();
        Label63.Text = ds.Tables[0].Rows[0]["MSG_RESAON_CODE"].ToString();
        Label64.Text = ds.Tables[0].Rows[0]["SETTL_FLAG"].ToString();
        Label65.Text = ds.Tables[0].Rows[0]["TRAN_TYPE"].ToString();

    }

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

    protected void btnCancel1_Click(object sender, EventArgs e)
    {
        pnlControlsChannel.Visible = false;
    }

    protected void btnCancel2_Click(object sender, EventArgs e)
    {
        pnlControlsEJ.Visible = false;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (pnlControls.Visible)
        {
            string ID = "", error = "";
            bool saved = addClaim(ref ID, ref error);
            if (saved)
            {
                lblError.ForeColor = System.Drawing.Color.DarkGreen;
                lblError.Text = "claim saved. (Claim ID: " + ID + " )";
                pnlControls.Visible = false;
                pnlClaim.Visible = false;
                //pnlTxn.Visible = false;

                Response.Redirect("../pos/InvestigateClaim.aspx?clID=" + ID);
            }
            else
            {
                lblError.Text = error + " " + ID;
            }
        }
        else
        {
            string ID = "", error = "";
            bool saved = addClaim(ref ID, ref error);
            if (saved)
            {
                lblError.ForeColor = System.Drawing.Color.DarkGreen;
                lblError.Text = "claim saved. (Claim ID: " + ID + " )";
            }
            else
                lblError.Text = error + " " + ID;
        }

    }

    protected void btnCancelClaim_Click(object sender, EventArgs e)
    {
        pnlControls.Visible = false;
        pnlClaim.Visible = false;
    }

    private bool addClaim(ref string ID, 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 = "CLAIM_BY_CH_PROCESS.add_claim_info";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_card_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_mt_code", OracleType.Number).Direction = ParameterDirection.Input;
        //IHJ 12-07-2012
        oracom.Parameters.Add("p_new_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;

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

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

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

        oracom.Parameters["p_card_number"].Value = txtInputCard.Text;
        oracom.Parameters["p_tran_date"].Value = txtHDATE.Text;
        oracom.Parameters["p_term_id"].Value = txtInputTerminalID.Text;
        oracom.Parameters["p_tran_amount"].Value = txtInputAmount.Text.Replace(",", "");
        oracom.Parameters["p_rrn"].Value = txtInputReference.Text;
        if (txtHMTCODE.Text.Length == 0)
            oracom.Parameters["p_mt_code"].Value = OracleNumber.Null;
        else
            oracom.Parameters["p_mt_code"].Value = txtHMTCODE.Text;

        if (txtNewRRN.Text.Length == 0)
            oracom.Parameters["p_new_rrn"].Value = OracleString.Null;
        else
            oracom.Parameters["p_new_rrn"].Value = txtNewRRN.Text;

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