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.IO;

public partial class Business_ReconResult : System.Web.UI.Page
{


    int currentPage;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadChannels();
            loadChannelEvents();
            pnlControlsChannel.Visible = false;
            pnlControlsMaster.Visible = false;
            pnlResultChannel.Visible = false;
            pnlResultMaster.Visible = false;
            btnSearch.Enabled = false;
            currentPage = 0;
            this.btn_editTran.Visible = false;
            this.pnl_editB24Tran.Visible = false;
            this.ddl_tranType.Enabled = false;
            ExceptionUtility.LogException(0, "", "21", "Page_Load", "");
        }
        lblError.Text = "";
    }

    private void loadChannels()
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.Get_Recon_Job_Channels";

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


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

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

            ddlChannels.Items.Insert(0, "------ Channels ------");
            oracon.Close();

            string dgn = ConfigurationSettings.AppSettings["DGN"];
            ddlChannels.Items.Remove(ddlChannels.Items.FindByValue(dgn));
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Recon_Job_Channels","", "loadChannels", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private void loadChannelEvents()
    {
        try
        {
            ddlEvents.Items.Clear();

            int selectedChannelId;

            if (this.ddlChannels.SelectedIndex > 0)
            {
                selectedChannelId = int.Parse(this.ddlChannels.SelectedValue.ToString());
            }
            else
            {
                selectedChannelId = 0;
            }

            if (ddlChannels.SelectedIndex > 0)
            {
                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_Recon_Job_Channel_Events";

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

                oracom.Parameters["p_rc_code"].Value = ddlChannels.SelectedValue;

                OracleDataAdapter da = new OracleDataAdapter(oracom);
                DataSet ds = new DataSet();
                da.Fill(ds);
                oracon.Close();
                ddlEvents.DataSource = ds;
                ddlEvents.DataBind();

                if (selectedChannelId == 6)
                {
                    this.ddl_eventName.DataSource = ds;
                    this.ddl_eventName.DataBind();
                }
            }
            ddlEvents.Items.Insert(0, "------ Events ------");
            string dgn = ConfigurationSettings.AppSettings["DGN"];
            if (!dgn.Equals("0"))
            {
                ddlEvents.Items.Remove(ddlEvents.Items.FindByValue("41"));
                ddlEvents.Items.Remove(ddlEvents.Items.FindByValue("42"));
                ddlEvents.Items.Remove(ddlEvents.Items.FindByValue("43"));

            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Recon_Job_Channel_Events","", "loadChannelEvents", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }

    }

    protected void ddlChannels_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadChannelEvents();
        btnSearch.Enabled = false;

        this.pnlResultMaster.Visible = false;
        this.pnlResultChannel.Visible = false;
        this.pnl_editB24Tran.Visible = false;
        this.pnlControlsChannel.Visible = false;
        this.pnlControlsMaster.Visible = false;

        int selectedChannelId = int.Parse(this.ddlChannels.SelectedValue.ToString());

        if (selectedChannelId == 6)
        {
            this.ddl_tranType.SelectedIndex = 0;
            this.ddl_tranType.Enabled = false;
        }
        else
        {
            this.ddl_tranType.Enabled = true;
        }
        ExceptionUtility.LogException(0, "", "", "ddlChannels_SelectedIndexChanged", "");
    }

    protected void ddlEvents_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.pnlResultMaster.Visible = false;
        this.pnlResultChannel.Visible = false;
        this.pnl_editB24Tran.Visible = false;
        this.pnlControlsChannel.Visible = false;
        this.pnlControlsMaster.Visible = false;
        
        if (ddlEvents.SelectedIndex > 0)
            btnSearch.Enabled = true;
        else
            btnSearch.Enabled = false;
        DatePicker1.date = "";
        ExceptionUtility.LogException(0, "", "", "ddlEvents_SelectedIndexChanged", "");
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DatePicker1.date.Length == 0)
        {
            lblError.Text = "please enter a date";
            ExceptionUtility.LogException(9, "", "", "ddlPages_SelectedIndexChanged", "");
        }
        else
        {
            pnlResultChannel.Visible = true;
            ExceptionUtility.LogException(0, "", "", "ddlPages_SelectedIndexChanged", "");
            loadResult(Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
            lblError0.Text = ddlPages.SelectedIndex.ToString();
            
            //loadResult(Helper.gridSize(), 1);
            pnlControlsChannel.Visible = false;
        }
    }

    protected void ddlPages1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DatePicker1.date.Length == 0)
        {
            lblError.Text = "please enter a date";
            ExceptionUtility.LogException(9, "", "", "ddlPages1_SelectedIndexChanged", "");
        }
        else
        {
            ExceptionUtility.LogException(0, "", "", "ddlPages1_SelectedIndexChanged", "");
            pnlResultMaster.Visible = true;
            loadResult(Helper.gridSize(), int.Parse(ddlPages1.SelectedValue));
            pnlControlsMaster.Visible = false;
        }
    }

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

            ViewState["tId"] = tID;

            int selectedEventId = int.Parse(this.ddlEvents.SelectedValue.ToString());
            ExceptionUtility.LogException(0, "", "21.348", "GridView1_RowCommand.view", "");
            if (type.Equals("C"))
            {
                loadTranDetails(tID);

                if (selectedEventId == 1)
                {
                    this.btn_editTran.Visible = true;
                }
                else
                {
                    this.btn_editTran.Visible = false;
                }
            }
            else
            {
                loadTranDetails1(tID);
            }
        }
    }

    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("v"))
        {

            int index = int.Parse(e.CommandArgument.ToString());
            string tID = GridView2.DataKeys[index].Value.ToString();
            string type = ViewState["type"].ToString();
            ExceptionUtility.LogException(0, "", "21.349", "GridView2_RowCommand.view", "");
            if (type.Equals("C"))
            {
                loadTranDetails(tID);
            }
            else
            {
                loadTranDetails1(tID);
            }
        }
    }

    private void loadTranDetails(string tID)
    {
        try
        {
            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
            Label1.Text = ds.Tables[0].Rows[0]["RECORD_DATE"].ToString();
            Label2.Text = ds.Tables[0].Rows[0]["SETTL_DATE"].ToString();

            Label3.Text = ds.Tables[0].Rows[0]["TRAN_DATE"].ToString();
            Label4.Text = ds.Tables[0].Rows[0]["TRAN_TIME"].ToString();
            Label5.Text = ds.Tables[0].Rows[0]["CARD_NUMBER"].ToString();
            Label6.Text = ds.Tables[0].Rows[0]["ISO_RSP"].ToString();
            Label7.Text = ds.Tables[0].Rows[0]["TERM_ID"].ToString();
            Label8.Text = ds.Tables[0].Rows[0]["TRAN_AMOUNT"].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]["TRACE_ID"].ToString();
            Label13.Text = ds.Tables[0].Rows[0]["FILE_NUMBER"].ToString();
            Label14.Text = ds.Tables[0].Rows[0]["CARD_BRAND"].ToString();
            Label15.Text = ds.Tables[0].Rows[0]["RRN"].ToString();
            Label16.Text = ds.Tables[0].Rows[0]["CARD_EXP_DATE"].ToString();
            Label17.Text = ds.Tables[0].Rows[0]["ACCT_NUMBER"].ToString();
            Label18.Text = ds.Tables[0].Rows[0]["AUTH_CODE"].ToString();
            Label19.Text = ds.Tables[0].Rows[0]["BUSS_CLS"].ToString();
            Label20.Text = ds.Tables[0].Rows[0]["RECON_STATUS"].ToString();
            Label21.Text = ds.Tables[0].Rows[0]["TRAN_CURR"].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]["MATCH_RESULT"].ToString();
            Label26.Text = ds.Tables[0].Rows[0]["CHIP_INDEX"].ToString();
            Label27.Text = ds.Tables[0].Rows[0]["channel_name"].ToString();
            Label28.Text = ds.Tables[0].Rows[0]["event_name"].ToString();
            Label29.Text = ds.Tables[0].Rows[0]["PCODE"].ToString();
            Label30.Text = ds.Tables[0].Rows[0]["FINANCIAL_FLAG"].ToString();
            Label31.Text = ds.Tables[0].Rows[0]["PRODUCT"].ToString();
            Label32.Text = ds.Tables[0].Rows[0]["MSG_RESAON_CODE"].ToString();
            Label33.Text = ds.Tables[0].Rows[0]["SETTL_FLAG"].ToString();
            Label82.Text = ds.Tables[0].Rows[0]["CLAIM_ID"].ToString();
            lblGLAcct.Text = ds.Tables[0].Rows[0]["GL_ACCT_NO"].ToString();

            /*06-06-2012 Add the new fields in the Channels_TRAN */
            lblFinValDate.Text = ds.Tables[0].Rows[0]["FINACLE_VALUE_DATE"].ToString();
            lblFinPostDate.Text = ds.Tables[0].Rows[0]["FINACLE_POSTING_DATE"].ToString();
            lblFinPostTime.Text = ds.Tables[0].Rows[0]["FINACLE_POSTING_TIME"].ToString();
            lblMerchantName.Text = ds.Tables[0].Rows[0]["MERCHANT_NAME"].ToString();
            ExceptionUtility.LogException(0, "TRANSACTIONS_SEARCHER.Get_Channel_Tran","348.1", "loadTranDetails", "tID: "+tID );
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "TRANSACTIONS_SEARCHER.Get_Channel_Tran","348.1", "loadTranDetails", "tID: "+tID );
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private void loadTranDetails1(string tID)
    {
        try
        {
            pnlControlsMaster.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_Master_Tran";

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

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

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

            oracon.Close();

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

            Label36.Text = ds.Tables[0].Rows[0]["TRAN_DATE"].ToString();
            Label37.Text = ds.Tables[0].Rows[0]["TRAN_TIME"].ToString();
            Label38.Text = ds.Tables[0].Rows[0]["CARD_NUMBER"].ToString();
            Label39.Text = ds.Tables[0].Rows[0]["PCODE"].ToString();
            Label40.Text = ds.Tables[0].Rows[0]["FINANCIAL_FLAG"].ToString();
            Label41.Text = ds.Tables[0].Rows[0]["B24_RSP"].ToString();
            Label42.Text = ds.Tables[0].Rows[0]["ISO_RSP"].ToString();
            Label43.Text = ds.Tables[0].Rows[0]["TERM_ID"].ToString();
            Label44.Text = ds.Tables[0].Rows[0]["TRAN_AMOUNT"].ToString();
            Label45.Text = ds.Tables[0].Rows[0]["TRAN_SOURCE"].ToString();
            Label46.Text = ds.Tables[0].Rows[0]["TRAN_DEST"].ToString();
            Label47.Text = ds.Tables[0].Rows[0]["MSG_TYPE"].ToString();
            Label48.Text = ds.Tables[0].Rows[0]["TRACE_ID"].ToString();
            Label49.Text = ds.Tables[0].Rows[0]["FILE_NUMBER"].ToString();
            Label50.Text = ds.Tables[0].Rows[0]["CARD_BRAND"].ToString();
            Label51.Text = ds.Tables[0].Rows[0]["RRN"].ToString();
            Label52.Text = ds.Tables[0].Rows[0]["CARD_EXP_DATE"].ToString();
            Label53.Text = ds.Tables[0].Rows[0]["ACCT_NUMBER"].ToString();
            Label54.Text = ds.Tables[0].Rows[0]["AUTH_CODE"].ToString();
            Label55.Text = ds.Tables[0].Rows[0]["BUSS_CLASS"].ToString();
            Label56.Text = ds.Tables[0].Rows[0]["TRAN_STATUS"].ToString();
            Label57.Text = ds.Tables[0].Rows[0]["TRAN_CURR"].ToString();
            Label58.Text = ds.Tables[0].Rows[0]["SETTL_CURR"].ToString();
            Label59.Text = ds.Tables[0].Rows[0]["SETTL_AMOUNT"].ToString();
            Label60.Text = ds.Tables[0].Rows[0]["TRAN_CHG"].ToString();
            Label61.Text = ds.Tables[0].Rows[0]["RECON_REQ_FLAG"].ToString();
            Label62.Text = ds.Tables[0].Rows[0]["RECON_PERFORMED_FLAG"].ToString();
            Label63.Text = ds.Tables[0].Rows[0]["MATCH_CRIERIA"].ToString();
            Label64.Text = ds.Tables[0].Rows[0]["MATCH_REF1"].ToString();
            Label65.Text = ds.Tables[0].Rows[0]["MATCH_REF2"].ToString();
            Label66.Text = ds.Tables[0].Rows[0]["MATCH_REF3"].ToString();
            Label67.Text = ds.Tables[0].Rows[0]["MATCH_REF4"].ToString();
            Label68.Text = ds.Tables[0].Rows[0]["MATCH_DATE1"].ToString();
            Label69.Text = ds.Tables[0].Rows[0]["MATCH_DATE2"].ToString();
            Label70.Text = ds.Tables[0].Rows[0]["MATCH_DATE3"].ToString();
            Label71.Text = ds.Tables[0].Rows[0]["MATCH_DATE4"].ToString();
            Label72.Text = ds.Tables[0].Rows[0]["CHIP_DATA"].ToString();
            Label73.Text = ds.Tables[0].Rows[0]["NEXT_MATCH"].ToString();
            Label74.Text = ds.Tables[0].Rows[0]["re_code"].ToString();
            Label75.Text = ds.Tables[0].Rows[0]["PRODUCT"].ToString();
            Label76.Text = ds.Tables[0].Rows[0]["ORIG_OSEQ_NUM"].ToString();
            Label77.Text = ds.Tables[0].Rows[0]["ORIG_DATE"].ToString();
            Label78.Text = ds.Tables[0].Rows[0]["ORIG_TIME"].ToString();
            Label79.Text = ds.Tables[0].Rows[0]["AMT_2"].ToString();
            Label80.Text = ds.Tables[0].Rows[0]["AMT_3"].ToString();
            Label81.Text = ds.Tables[0].Rows[0]["AUTH_AMT"].ToString();
            Label82.Text = ds.Tables[0].Rows[0]["CLAIM_ID"].ToString();

            GridView3.DataSource = ds.Tables[1];
            GridView3.DataBind();
            ExceptionUtility.LogException(0, "TRANSACTIONS_SEARCHER.Get_Master_Tran", "349.1", "loadTranDetails1", "tID: " + tID);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "TRANSACTIONS_SEARCHER.Get_Master_Tran","349.1", "loadTranDetails1", "tID: " + tID);
            GridView3.DataSource = null ;
            GridView3.DataBind();
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

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

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

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        pnlControlsChannel.Visible = false;
        pnlControlsMaster.Visible = false;
        pnlResultMaster.Visible = false;
        pnlResultChannel.Visible = false;
        this.pnl_editB24Tran.Visible = false;

        if (DatePicker1.date.Length == 0)
        {
            lblError.Text = "please enter a date";
            ExceptionUtility.LogException(9, "", "21.61", "btnSearch_Click", "");
        }
        else
        {
            ExceptionUtility.LogException(0, "", "21.61", "btnSearch_Click", "");
            loadResult(Helper.gridSize(), 1);

            //this.lnk_firstPage.Enabled = false;
            //this.lnk_prePage.Enabled = false;
            //this.lnk_lastPage.Enabled = true;
            //this.lnk_nextPage.Enabled = true;
        }
    }

    private void loadResult(int pageSize, int pageNumber)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            if (RadioButton1.Checked)
                oracom.CommandText = "RECON_RESULT_VIEWER.Get_Non_Match_Recon";
            else if (RadioButton2.Checked)
                oracom.CommandText = "RECON_RESULT_VIEWER.Get_Non_Match_Tran";
            else if (RadioButton3.Checked)
                oracom.CommandText = "RECON_RESULT_VIEWER.Get_Duplicate";

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

            oracom.Parameters.Add("p_rc_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_re_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_recon_date", 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_tran_type", OracleType.VarChar).Direction = ParameterDirection.Input;

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

            oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_output_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;


            oracom.Parameters["p_rc_code"].Value = ddlChannels.SelectedValue;
            oracom.Parameters["p_re_code"].Value = ddlEvents.SelectedValue;
            oracom.Parameters["p_recon_date"].Value = DatePicker1.date;

            oracom.Parameters["p_tran_type"].Value = this.ddl_tranType.SelectedValue;

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

            string type = oracom.Parameters["p_output_type"].Value.ToString();
            ViewState["type"] = type;

            if (type.Equals("C"))
            {
                GridView1.DataSource = ds;
                GridView1.DataBind();
                pnlResultChannel.Visible = true;
            }
            else
            {
                GridView2.DataSource = ds;
                GridView2.DataBind();
                pnlResultMaster.Visible = true;
            }

            //this.lbl_firstPage.Text = "Page " + pageNumber + " of " + nop;

            ViewState["currentPage"] = pageNumber;
            ViewState["totalPages"] = nop;
            if (pageNumber == 1)
            {
                ddlPages.Items.Clear();
                ddlPages1.Items.Clear();
                for (int i = 1; i <= nop; i++)
                {
                    if (type.Equals("C"))
                        ddlPages.Items.Add(i.ToString());
                    else
                        ddlPages1.Items.Add(i.ToString());
                }
            }
            ExceptionUtility.LogException(0, "RECON_RESULT_VIEWER.Get_Non_Match_Recon,RECON_RESULT_VIEWER.Get_Non_Match_Tran,RECON_RESULT_VIEWER.Get_Duplicate", "61.1", "loadResult", "pageSize: " + pageSize + ", pageNumber: " + pageNumber);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "RECON_RESULT_VIEWER.Get_Non_Match_Recon,RECON_RESULT_VIEWER.Get_Non_Match_Tran,RECON_RESULT_VIEWER.Get_Duplicate","61.1", "loadResult", "pageSize: " + pageSize +", pageNumber: "+pageNumber );
            GridView3.DataSource = null;
            GridView3.DataBind();
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }
    
    protected void ddl_tranType_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.pnlResultMaster.Visible = false;
        this.pnlResultChannel.Visible = false;

        this.pnlControlsMaster.Visible = false;
        this.pnlControlsChannel.Visible = false;
        this.pnl_editB24Tran.Visible = false;
        ExceptionUtility.LogException(0, "", "", "ddl_tranType_SelectedIndexChanged", "");//pageSize: " + pageSize + ", pageNumber: " + pageNumber);
    }
    
    protected void btn_editTran_Click(object sender, EventArgs e)
    {
        this.pnl_editB24Tran.Visible = true;
        this.pnlControlsChannel.Visible = false;

        this.lbl_recordDate.Text = this.Label1.Text;
        this.lbl_settlDate.Text = this.Label2.Text;
        this.lbl_tranDate.Text = this.Label3.Text;
        this.lbl_tranTime.Text = this.Label4.Text;
        this.lbl_cardNumber.Text = this.Label5.Text;
        this.lbl_isoRes.Text = this.Label6.Text;
        this.txt_terminalId.Text = this.Label7.Text;
        this.lbl_tranAmount.Text = this.Label8.Text;
        this.txt_tranSource.Text = this.Label9.Text;
        this.txt_tranDest.Text = this.Label10.Text;
        this.lbl_msgType.Text = this.Label11.Text;
        this.txt_traceId.Text = this.Label12.Text;
        this.lbl_fileNumber.Text = this.Label13.Text;
        this.lbl_cardBrand.Text = this.Label14.Text;
        this.lbl_refNumber.Text = this.Label15.Text;
        this.lbl_cardExpiryDate.Text = this.Label16.Text;
        this.lbl_accountNumber.Text = this.Label17.Text;
        this.txt_authCode.Text = this.Label18.Text;
        this.lbl_businessClass.Text = this.Label19.Text;
        this.lbl_reconStatus.Text = this.Label20.Text;
        this.lbl_tranCurrency.Text = this.Label21.Text;
        this.lbl_settlCurrency.Text = this.Label22.Text;
        this.lbl_settlAmount.Text = this.Label23.Text;
        this.lbl_tranChange.Text = this.Label24.Text;
        this.lbl_matchResult.Text = this.Label25.Text;
        this.lbl_chipIndex.Text = this.Label26.Text;
        this.lbl_channelName.Text = this.Label27.Text;
        this.ddl_eventName.SelectedValue = this.ddlEvents.SelectedValue;
        this.lbl_pCode.Text = this.Label29.Text;
        this.lbl_financialFlag.Text = this.Label30.Text;
        this.lbl_product.Text = this.Label31.Text;
        this.lbl_msgReasonCode.Text = this.Label32.Text;
        this.lbl_settlFlag.Text = this.Label33.Text;
        this.lbl_claimId.Text = this.Label82.Text;
        ExceptionUtility.LogException(0, "", "21.414", "btn_editTran_Click", "");
    }
    
    protected void btn_updatePnl_cancel_Click(object sender, EventArgs e)
    {
        this.pnl_editB24Tran.Visible = false;
        ExceptionUtility.LogException(0, "", "21.414", "btn_updatePnl_cancel_Click", "");
    }
    
    protected void btn_updatePnl_save_Click(object sender, EventArgs e)
    {
        int ctCode = int.Parse( ViewState["tId"].ToString() );
        string terminalID = this.txt_terminalId.Text;
        string tranSource = this.txt_tranSource.Text;
        string tranDest = this.txt_tranDest.Text;
        string traceId = this.txt_traceId.Text.Trim();
        string authCode = this.txt_authCode.Text.Trim ();
        string eventId = this.ddl_eventName.SelectedValue;

        string cardNumber = this.lbl_cardNumber.Text;
        int messageType = int.Parse( this.lbl_msgType.Text.Substring(0, 3) );
        string tranDate = Helper.formatDate_ToDBFormat( this.lbl_tranDate.Text );
        string tranTime = Helper.formatTime_toDBFormat( this.lbl_tranTime.Text );
        string tranAmount = this.lbl_tranAmount.Text.Replace(",", "") ;
        string refNumber = this.lbl_refNumber.Text;

        int resCode;
        string errorMsg = "";
        ExceptionUtility.LogException(0, "", "21.415", "btn_updatePnl_save_Click", "");
        resCode = this.updateChannelTran(ctCode, terminalID, tranSource, tranDest, traceId,
                                  authCode, eventId, cardNumber, messageType,
                                  tranDate, tranTime, tranAmount, refNumber, ref errorMsg);
        
        if (resCode == 0)
        {
            this.pnl_editB24Tran.Visible = false;
            this.loadResult(Helper.gridSize(), 1);
            this.lblError.Text = "The Transaction Updated Successfully.";
            this.loadResult(Helper.gridSize(),  int.Parse(this.lblError0.Text) + 1);
            ddlPages.SelectedIndex = int.Parse(this.lblError0.Text);
        }
        else
        {
            if (Helper.OracleError(errorMsg))
            {
                lblError.Text = "An Error Occured!";
                ExceptionUtility.LogException(9, "", "85.498", "btn_save_Click", errorMsg);
            }
            else
                lblError.Text = errorMsg;
        }
    }

    protected void img_search_Click(object sender, ImageClickEventArgs e)
    {
        Div.Visible = true;

        string cardNumber = this.lbl_cardNumber.Text;
        string refNumber = this.lbl_refNumber.Text;
        string product = this.lbl_product.Text;
        string tranTime = Helper.formatTime_toDBFormat(this.lbl_tranTime.Text);

        loadTrans(cardNumber, refNumber, product, tranTime);
    }

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

    private void loadTrans(string cardNumber, string refNumber, string product, string tranTime)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "transactions_searcher.GET_SUGGESTED_MATCHED_TRANS";

            oracom.Parameters.Add("P_CARD_NUMBER", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("P_REF_NUMBER", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("P_PRODUCT", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("P_TRAN_TIME", OracleType.VarChar).Direction = ParameterDirection.Input;

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


            oracom.Parameters["P_CARD_NUMBER"].Value = cardNumber;
            oracom.Parameters["P_REF_NUMBER"].Value = refNumber;
            oracom.Parameters["P_PRODUCT"].Value = product;
            oracom.Parameters["P_TRAN_TIME"].Value = tranTime;

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

            this.grd_trans.DataSource = ds;
            this.grd_trans.DataBind();

            oracon.Close();
            ExceptionUtility.LogException(0, "transactions_searcher.GET_SUGGESTED_MATCHED_TRANS", "", "loadTrans", "cardNumber: " + cardNumber + ", refNumber: " + refNumber + ", product: " + product + ", tranTime: " + tranTime);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "transactions_searcher.GET_SUGGESTED_MATCHED_TRANS","", "loadTrans", "cardNumber: " + cardNumber + ", refNumber: " + refNumber + ", product: " + product + ", tranTime: " + tranTime);
            grd_trans.DataSource = null;
            grd_trans.DataBind();
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    protected void grd_trans_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("s"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            //string cardNo = this.grd_trans.DataKeys[index].Value.ToString();

            this.txt_terminalId.Text = this.grd_trans.Rows[index].Cells[0].Text.ToString();
            this.txt_tranSource.Text = this.grd_trans.Rows[index].Cells[1].Text.ToString();
            this.txt_tranDest.Text = this.grd_trans.Rows[index].Cells[2].Text.ToString();
            this.txt_traceId.Text = this.grd_trans.Rows[index].Cells[3].Text.Trim()=="&nbsp;" ? "" : this.grd_trans .Rows[index].Cells[3].Text;
            this.txt_authCode.Text = this.grd_trans.Rows[index].Cells[4].Text.Trim() == "&nbsp;" ? "" : this.grd_trans.Rows[index].Cells[4].Text;
        
            this.ddl_eventName.SelectedValue = this.grd_trans.Rows[index].Cells[5].Text.ToString();

            Div.Visible = false;
        }
    }

    protected void grd_trans_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.grd_trans.PageIndex = e.NewPageIndex;


        string cardNumber = this.lbl_cardNumber.Text;
        string refNumber = this.lbl_refNumber.Text;
        string product = this.lbl_product.Text;
        string tranTime = Helper.formatTime_toDBFormat(this.lbl_tranTime.Text);

        loadTrans(cardNumber, refNumber, product, tranTime);
    }

    private int updateChannelTran(int ctCode, string terminalID, string tranSource, string tranDest, string traceId,
                                  string authCode, string eventId, string cardNumber, int messageType,
                                  string tranDate, string tranTime, string tranAmount, string refNumber, ref string errorMsg)
    {
        try
        {
            int resCode;

            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.UPDATE_BASE24_TRAN";

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

            oracom.Parameters.Add("p_channel_ct_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_terminal_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_tran_source", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_tran_dest", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_trace_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_auth_code", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_event_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_card_number", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_msg_type", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_tran_time", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_tran_amount", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_ref_number", OracleType.VarChar).Direction = ParameterDirection.Input;

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


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

            oracom.Parameters["p_channel_ct_code"].Value = ctCode;
            oracom.Parameters["p_terminal_id"].Value = terminalID;
            oracom.Parameters["p_tran_source"].Value = tranSource;//
            oracom.Parameters["p_tran_dest"].Value = tranDest;//
            if(traceId.Trim()=="" || traceId.Trim().Contains("&nbsp;"))
                oracom.Parameters["p_trace_id"].Value = OracleString .Null ;
            else 
                oracom.Parameters["p_trace_id"].Value = traceId.Trim();
            if(authCode .Trim()=="" || authCode .Trim ().Contains ("&nbsp;"))
                oracom.Parameters["p_auth_code"].Value = OracleString .Null ;
            else 
                oracom.Parameters["p_auth_code"].Value = authCode.Trim();
            oracom.Parameters["p_event_id"].Value = eventId;
            oracom.Parameters["p_card_number"].Value = cardNumber;
            oracom.Parameters["p_msg_type"].Value = messageType;
            oracom.Parameters["p_tran_date"].Value = tranDate;
            oracom.Parameters["p_tran_time"].Value = tranTime;
            oracom.Parameters["p_tran_amount"].Value = tranAmount;
            oracom.Parameters["p_ref_number"].Value = refNumber;

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

            resCode = int.Parse(oracom.Parameters["p_res_code"].Value.ToString());
            errorMsg = oracom.Parameters["p_res_msg"].Value.ToString();

            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "transactions_searcher.UPDATE_BASE24_TRAN","415.1", "updateChannelTran", "ctCode: " + ctCode  + ", terminalID: " + terminalID  + ", tranSource: " + tranSource  + ", tranDest: " + tranDest+", traceId: "+traceId +", authCode: "+authCode +", eventId: "+eventId +", cardNumber: " +cardNumber +", messageType: "+messageType+", tranDate:"+tranDate +", tranTime: "+tranTime +", tranAmount: "+tranAmount  +", refNumber: "+refNumber );
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }
    
    //protected void lnk_prePage_Click(object sender, EventArgs e)
    //{
    //    if (DatePicker1.date.Length == 0)
    //    {
    //        lblError.Text = "please enter a date";
    //    }
    //    else
    //    {
    //        pnlResultChannel.Visible = true;
    //        loadResult(Helper.gridSize(), int.Parse(ViewState["currentPage"].ToString()) - 1);
    //        pnlControlsChannel.Visible = false;

    //        this.lnk_nextPage.Enabled = true;
    //        this.lnk_lastPage.Enabled = true;

    //        if (int.Parse(ViewState["currentPage"].ToString()) == 1)
    //        {
    //            this.lnk_prePage.Enabled = false;
    //            this.lnk_firstPage.Enabled = false;
    //        }
    //    }
    //}
    //protected void lnk_nextPage_Click(object sender, EventArgs e)
    //{
    //    if (DatePicker1.date.Length == 0)
    //    {
    //        lblError.Text = "please enter a date";
    //    }
    //    else
    //    {
    //        pnlResultChannel.Visible = true;
    //        loadResult(Helper.gridSize(), int.Parse(ViewState["currentPage"].ToString()) + 1);
    //        pnlControlsChannel.Visible = false;

    //        this.lnk_prePage.Enabled = true;
    //        this.lnk_firstPage.Enabled = true;

    //        if (int.Parse(ViewState["totalPages"].ToString()) == int.Parse(ViewState["currentPage"].ToString()))
    //        {
    //            this.lnk_nextPage.Enabled = false;
    //            this.lnk_lastPage.Enabled = false;
    //        }
    //        else
    //        {
    //            this.lnk_nextPage.Enabled = true;
    //            this.lnk_lastPage.Enabled = true;
    //        }
    //    }
    //}
}
