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

public partial class PreAuthTranSearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadChannels();
            loadServices();

            pnlControlsChannel.Visible = false;
            pnlControlsMaster.Visible = false;
            pnlResultChannel.Visible = false;
            pnlResultMaster.Visible = false;
            dtFrom.date = DateTime.Today.AddDays(-7).ToString("dd-MM-yyyy");
            dtTo.date   = DateTime.Today.AddDays(0).ToString("dd-MM-yyyy");
            txtFromTime.Text = "000000";
            txtToTime.Text = "235959";
            txtORRN.Enabled = false;
            ExceptionUtility.LogException(0, "", "99", "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 = "poslookup_getter.get_posPreAuth_channels";

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


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

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

            oracon.Close();
            //ExceptionUtility.LogException("Success", "poslookup_getter.get_pos_channels", "loadChannels", "");
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "poslookup_getter.get_posPreAuth_channels", "", "loadChannels", "");

        }
    }

    private void loadServices()
    {
        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 = "poslookup_getter.get_preauth_merservices";

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


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

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

            oracon.Close();
           // ExceptionUtility.LogException("Success", "poslookup_getter.get_pos_channels", "loadChannels", "");
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "poslookup_getter.get_preauth_merservices", "", "loadChannels", "");

        }
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (dtFrom.date.Length == 0 || dtTo.date.Length == 0 || txtFromTime.Text.Length == 0
                                   || txtToTime.Text.Length == 0 || txtTerminalID.Text.Length == 0)
        {
            //if (ddlServices.SelectedValue == "001")
            //{
            //    lblError.Text = "please complete all data";
            //    ExceptionUtility.LogException(9, "", "", "ddlPages_SelectedIndexChanged", "");
            //}
            //else
            //{
                ExceptionUtility.LogException(0, "", "", "ddlPages_SelectedIndexChanged", "");
                pnlResultChannel.Visible = true;
                loadResult(Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
                pnlControlsChannel.Visible = false;
            //}
        }
        else
        {
            lblError.Text = "please complete all data";
            ExceptionUtility.LogException(9, "", "", "ddlPages_SelectedIndexChanged", "");
          
        }
    }

    protected void ddlPages1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (dtFrom.date.Length == 0 || dtTo.date.Length == 0 || txtFromTime.Text.Length == 0
                                   || txtToTime.Text.Length == 0 || txtTerminalID.Text.Length == 0)
        {
            //if (ddlServices.SelectedValue == "001")
            //{
            //    lblError.Text = "please complete all data";
            //    ExceptionUtility.LogException(9, "", "", "ddlPages1_SelectedIndexChanged", "");
            //}
            //else
            //{
                ExceptionUtility.LogException(0, "", "", "ddlPages1_SelectedIndexChanged", "");
                pnlResultMaster.Visible = true;
                loadResult(Helper.gridSize(), int.Parse(ddlPages1.SelectedValue));
                pnlControlsMaster.Visible = false;
            //}
        }
        else
        {
            lblError.Text = "please complete all data";
            ExceptionUtility.LogException(9, "", "", "ddlPages1_SelectedIndexChanged", "");
       
        }
    }

    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();
            string type = ViewState["type"].ToString();
            if (type.Equals("CH"))
            {
                ExceptionUtility.LogException(0, "", "99.571", "GridView1_RowCommand.view", "");
                loadTranDetails(tID);
                
            }
            else
            {
                ExceptionUtility.LogException(0, "", "99.572", "GridView1_RowCommand.view", "");
                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();
            if (type.Equals("CH"))
            {
                ExceptionUtility.LogException(0, "", "99.571", "GridView2_RowCommand.view", "");
                loadTranDetails(tID);
                
            }
            else
            {
                ExceptionUtility.LogException(0, "", "99.572", "GridView2_RowCommand.view", "");
                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 = "PreAuth_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]["TRAN_TYPE"].ToString();
            lblFnCode.Text = ds.Tables[0].Rows[0]["Fnct_Code"].ToString();
            lblMsgRsnCode.Text = ds.Tables[0].Rows[0]["Msg_Resaon_Code"].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, "PreAuth_Transactions_Searcher.Get_Channel_Tran", "571.1", "loadTranDetails", "tID: " + tID);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "PreAuth_Transactions_Searcher.Get_Channel_Tran", "571.1", "loadTranDetails", "tID: " + tID);

        }
    }

    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 = "PreAuth_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();
            Label83.Text = ds.Tables[0].Rows[0]["merch_settle_desc"].ToString();
            Label84.Text = ds.Tables[0].Rows[0]["SAMA_FEE"].ToString();
            Label85.Text = ds.Tables[0].Rows[0]["GCC_FEE"].ToString();
            txtFncde.Text = ds.Tables[0].Rows[0]["Fnct_Code"].ToString();
            txtMsgRsnCd.Text = ds.Tables[0].Rows[0]["Msg_Rsn_Code"].ToString();
            txtClaimId.Text = ds.Tables[0].Rows[0]["Claim_Id"].ToString();
            txtPreAuthExpry.Text = ds.Tables[0].Rows[0]["Preauth_Expirydate"].ToString();
            txtMerchRefNum.Text = ds.Tables[0].Rows[0]["Merchant_Refnum"].ToString();


            GridView3.DataSource = ds.Tables[1];
            GridView3.DataBind();
            ExceptionUtility.LogException(0, "PreAuth_Transactions_Searcher.Get_Master_Tran", "572.1", "loadTranDetails1", "tID: " + tID);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "PreAuth_Transactions_Searcher.Get_Master_Tran", "572.1", "loadTranDetails1", "tID: " + tID);
            GridView3.DataSource =null ;
            GridView3.DataBind();
        }
    }

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

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

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        txtTerminalID.Text = txtTerminalID.Text.Trim();
        txtCardNo.Text = txtCardNo.Text.Trim();
        txtRRN.Text  = txtRRN.Text.Trim();
        txtORRN.Text = txtORRN.Text.Trim();

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

            if (dtFrom.date.Length == 0 || dtTo.date.Length == 0 || txtFromTime.Text.Length == 0
                                        || txtToTime.Text.Length == 0)
            {
                ExceptionUtility.LogException(9, "", "99.570", "btnSearch_Click", "");
                lblError.Text = "please complete all date and time fields";
            }
            else
            {
                if (txtTerminalID.Text.Length == 0 && txtCardNo.Text.Length == 0 && ddlServices.SelectedValue == "001")
                {
                    ExceptionUtility.LogException(9, "", "99.570", "btnSearch_Click", "");
                    lblError.Text = "please Enter Card Number or Terminal ID";
               }
                else if (txtRRN.Text.Length > 0 && txtORRN.Text.Length >0 && txtRRN.Text.Equals(txtORRN.Text))
               {
                lblError.Text = "Note RRN and ORG RRN cannot not be Same!";
                ExceptionUtility.LogException(9, "", "99.570", "btnSearch_Click", "");
               }
                else
                {
                    ExceptionUtility.LogException(0, "", "99.570", "btnSearch_Click", "");
                    loadResult(Helper.gridSize(), 1);
                }
            }
    }

    private void loadResult(int pageSize, int pageNumber)
    {
        string parameters = "";
        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name;
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "PreAuth_Transactions_Searcher.Search_POS_Tran";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_card_no", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_Orrn", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_rc_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_srv_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_fin_flg", OracleType.Number).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_ch_b24", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_page_size", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_page_num", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

            if (txtTerminalID.Text.Length != 0)
            {
                oracom.Parameters["p_term_id"].Value = txtTerminalID.Text;
                parameters = "p_term_id-" + txtTerminalID.Text + ":";
            }
            else
                oracom.Parameters["p_term_id"].Value = OracleString.Null;

            if (txtCardNo.Text.Length != 0)
            {
                parameters = parameters + "p_card_no-" + Helper.Mask_CardNumber(txtCardNo.Text) + ":";
                oracom.Parameters["p_card_no"].Value = txtCardNo.Text;
            }
            else
                oracom.Parameters["p_card_no"].Value = OracleString.Null;


            if (txtRRN.Text.Length != 0)
            {
                parameters = parameters + "p_rrn-" + txtRRN.Text + ":";
                oracom.Parameters["p_rrn"].Value = txtRRN.Text;
            }
            else
                oracom.Parameters["p_rrn"].Value = OracleString.Null;
               
            if (txtORRN.Text.Length != 0)
            {
                parameters = parameters + "p_Orrn-" + txtORRN.Text + ":";
                oracom.Parameters["p_Orrn"].Value = txtORRN.Text;
            }
            else
                oracom.Parameters["p_Orrn"].Value = OracleString.Null; 

            oracom.Parameters["p_rc_code"].Value = ddlChannels.SelectedValue;
            if (ddlChannels.SelectedIndex > 0)
                parameters = parameters + "p_rc_code-" + ddlChannels.SelectedItem .Text  + ":";
            oracom.Parameters["p_srv_code"].Value = ddlServices.SelectedValue;
            if (ddlServices.SelectedIndex > 0)
                parameters = parameters + "p_srv_code-" + ddlServices.SelectedItem.Text + ":";
            oracom.Parameters["p_fin_flg"].Value = ddlFinancial.SelectedValue;
            parameters = parameters +"p_fin_flg-"+ ddlFinancial.SelectedItem.Text + ":";
            oracom.Parameters["p_tran_date_from"].Value = dtFrom.date;            
            oracom.Parameters["p_tran_date_to"].Value = dtTo.date;
            oracom.Parameters["p_tran_time_from"].Value = txtFromTime.Text;
            oracom.Parameters["p_tran_time_to"].Value = txtToTime.Text;
            parameters = parameters + "p_tran_date_from-" + dtFrom.date + ":p_tran_date_to-" + dtTo.date + ":p_tran_time_from-" + txtFromTime.Text + ":p_tran_time_to-" + txtToTime.Text + ":";
            if (rdB24.Checked)
            {
                oracom.Parameters["p_ch_b24"].Value = "B24";
                parameters = parameters + "p_ch_b24-B24:";
            }
            else
            {
                oracom.Parameters["p_ch_b24"].Value = "CH";
                parameters = parameters + "p_ch_b24-CH:";
            }
            ViewState["type"] = oracom.Parameters["p_ch_b24"].Value;

            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 = ViewState["type"].ToString();
            if (type.Equals("CH"))
            {
                GridView1.DataSource = ds;
                GridView1.DataBind();
                pnlResultChannel.Visible = true;
            }
            else
            {
                GridView2.DataSource = ds;
                GridView2.DataBind();
                pnlResultMaster.Visible = true;
            }

            if (pageNumber == 1)
            {
                ddlPages.Items.Clear();
                ddlPages1.Items.Clear();
                for (int i = 1; i <= nop; i++)
                {
                    if (type.Equals("CH"))
                        ddlPages.Items.Add(i.ToString());
                    else
                        ddlPages1.Items.Add(i.ToString());
                }
            }
            if (currentMethod.Contains("btnSearch_Click"))
                ExceptionUtility.LogException(0, "PreAuth_Transactions_Searcher.Search_POS_Tran", "571.1", "loadResult", parameters);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "PreAuth_Transactions_Searcher.Search_POS_Tran", "loadResult", "571.1", parameters);
            GridView1.DataSource = null;
            GridView1.DataBind();
            GridView2.DataSource = null;
            GridView2.DataBind();
        }
    }
    protected void rdB24_CheckedChanged(object sender, EventArgs e)
    {
        if(rdB24.Checked)
            ddlChannels.Enabled = false;
            txtORRN.Enabled = true;
            pnlControlsChannel.Visible = false;
            pnlControlsMaster.Visible = false;
            pnlResultMaster.Visible = false;
            pnlResultChannel.Visible = false;
            dtFrom.date = DateTime.Today.AddDays(-7).ToString("dd-MM-yyyy");
            dtTo.date = DateTime.Today.AddDays(0).ToString("dd-MM-yyyy");
            txtFromTime.Text = "000000";
            txtToTime.Text = "235959";
            txtTerminalID.Text = "";
            txtCardNo.Text = "";
            txtRRN.Text = "";
            txtORRN.Text = "";
            txtCardNo.Focus();
    }
    protected void rdCH_CheckedChanged(object sender, EventArgs e)
    {
        if (rdCH.Checked)
            ddlChannels.Enabled = true;
            txtORRN.Enabled = false;
            pnlControlsChannel.Visible = false;
            pnlControlsMaster.Visible = false;
            pnlResultMaster.Visible = false;
            pnlResultChannel.Visible = false;
            dtFrom.date = DateTime.Today.AddDays(-7).ToString("dd-MM-yyyy");
            dtTo.date = DateTime.Today.AddDays(0).ToString("dd-MM-yyyy");
            txtFromTime.Text = "000000";
            txtToTime.Text = "235959";
            txtTerminalID.Text = "";
            txtCardNo.Text   = "";
            txtRRN.Text = "";
            txtORRN.Text = "";
            txtCardNo.Focus();
    }
    protected void btnRep_Click(object sender, EventArgs e)
    {

        txtTerminalID.Text = txtTerminalID.Text.Trim();
        txtCardNo.Text = txtCardNo.Text.Trim();
        txtRRN.Text = txtRRN.Text.Trim();
        txtORRN.Text = txtORRN.Text.Trim(); 

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

        if (txtRRN.Text.Equals(txtORRN.Text))
        {
            lblError.Text = "Note RRN and ORG RRN Must not be Same!";
            ExceptionUtility.LogException(9, "99.573", "", "btnRep_Click", "");
        }
        if (dtFrom.date.Length == 0 || dtTo.date.Length == 0 || txtFromTime.Text.Length == 0
                                    || txtToTime.Text.Length == 0)
        {
            lblError.Text = "please complete all date and time fields";
            ExceptionUtility.LogException(9, "99.573", "", "btnRep_Click", "");
        }
         
        else
        {
            if (txtTerminalID.Text.Length == 0 && txtCardNo.Text.Length == 0 && ddlServices.SelectedValue == "001")
            {
                lblError.Text = "please Enter Card Number or Terminal ID";
                ExceptionUtility.LogException(9, "99.573", "", "btnRep_Click", "");
            }
            else if (txtRRN.Text.Length > 0 && txtORRN.Text.Length > 0 && txtRRN.Text.Equals(txtORRN.Text))
            {
                lblError.Text = "Note RRN and ORG RRN cannot not be Same!";
                ExceptionUtility.LogException(9, "", "99.573", "btnRep_Click", "");
            }
            else
            {
                string terminal = txtTerminalID.Text;
                string card = txtCardNo.Text;
                string rrn = txtRRN.Text;
                string Orrn = txtORRN.Text;
                string chan = ddlChannels.SelectedValue;
                string serv = ddlServices.SelectedValue;
                string finflag = ddlFinancial.SelectedValue;
                string dateF = dtFrom.date;
                string dateT = dtTo.date;
                string timeF = txtFromTime.Text;
                string timeT = txtToTime.Text;
                string chb24 = "";
                string typename = "";
                if (rdB24.Checked)
                {
                    chb24 = "B24";
                    typename = "Base 24";
                }
                else
                {
                    chb24 = "CH";
                    typename = "Channel";
                }
                string uid = Session["uid"].ToString();
                string perFdate = dtFrom.FormatedDate;
                string perTdate = dtTo.FormatedDate;
                string perFtime = txtFromTime.Text.Substring(0, 2) + ":"
                                 + txtFromTime.Text.Substring(2, 2) + ":" + txtFromTime.Text.Substring(4, 2);
                string perTtime = txtToTime.Text.Substring(0, 2) + ":"
                                 + txtToTime.Text.Substring(2, 2) + ":" + txtToTime.Text.Substring(4, 2);
                string servname = ddlServices.SelectedItem.Text;

                string UrlString = "rpt=500&terminal=" +
                     terminal + "&card=" + card + "&rrn=" + rrn + "&chan=" + chan + "&serv=" + serv + "&finflag=" +
                     finflag + "&dateF=" + dateF + "&dateT=" + dateT + "&timeF=" + timeF +
                     "&timeT=" + timeT + "&chb24=" + chb24 + "&perFdate=" + perFdate +
                     "&perTdate=" + perTdate + "&servname=" + servname + "&typename=" + typename +
                     "&perFtime=" + perFtime + "&perTtime=" + perTtime + "&uid=" + uid;
                ExceptionUtility.LogException(0, "99.573", "", "btnRep_Click", "");
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?" + UrlString + "','Report')", true);
            }
        }
    }
}
