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 POS_InvestigateClaim : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadClaimByID(Request.QueryString["clID"]);
            loadB24(Request.QueryString["clID"]);
            loadChannel(Request.QueryString["clID"]);
            loadEJ(Request.QueryString["clID"]);
            loadNotes(Request.QueryString["clID"]);
            pnlControls.Visible = false;
            pnlControls1.Visible = false;
            pnlControls2.Visible = false;
        }
    }

    private void loadClaimByID(string claimID)
    {
        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_claim_data_by_id";

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

        oracom.Parameters["p_claim_id"].Value = claimID;

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

        oracon.Close();

        //set the data in the controls
        lblClaimID.Text = claimID;
        lblCardNo.Text = ds.Tables[0].Rows[0]["card_number"].ToString();
        lblTxnDate.Text = ds.Tables[0].Rows[0]["tran_date"].ToString();
        lblTermID.Text = ds.Tables[0].Rows[0]["term_id"].ToString();
        lblAmount.Text = ds.Tables[0].Rows[0]["tran_amount"].ToString();
        lblReference.Text = ds.Tables[0].Rows[0]["rrn"].ToString();
        lblStatus.Text = ds.Tables[0].Rows[0]["claim_status"].ToString();
        lblProduct.Text = ds.Tables[0].Rows[0]["product_desc"].ToString();
        lblDuration.Text = ds.Tables[0].Rows[0]["duration_days"].ToString();
        txtNote.Text = ds.Tables[0].Rows[0]["note_text"].ToString();
        lblSamaStatus.Text = ds.Tables[0].Rows[0]["SAMA_status"].ToString();
        lblModifiedBy.Text = ds.Tables[0].Rows[0]["last_Modified_by"].ToString();
        string claimStatusCD = ds.Tables[0].Rows[0]["claim_status_cd"].ToString();
        string err="";
        string cpsID = Request.QueryString["clID"];
        //samaActions.Visible = cansenttoCPS(Request.QueryString["clID"], ref err);

        string product = ds.Tables[0].Rows[0]["product"].ToString();

        ViewState["product"] = product;
        if (product.Equals("1"))
        {
            //atm
            pnlEJ.Visible = true;
            pnlPOS.Visible = false;
            pnlAcc.Visible = false;
            pnlAccATM.Visible = true;
            btnPaySlip.Visible = false;
        }
        else
        {
            //pos
            loadRelatedClaims(claimID);
            pnlEJ.Visible = false;
            pnlPOS.Visible = true;
            pnlAcc.Visible = true;
            pnlAccATM.Visible = false;
            btnPaySlip.Visible = true;
        }
    }

    private void loadRelatedClaims(string claimID)
    {
        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_merchant_recon_proces.get_merch_groupclaim";

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

        oracom.Parameters["c_claim_id"].Value = claimID;

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

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

        oracon.Close();
    }
    
    private void loadB24(string claimID)
    {
        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.search_invstb24_claim";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_id", 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_outputclaimdet", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_gl_info", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_atm_gl_info", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

        oracom.Parameters["p_claim_id"].Value = claimID;

        oracom.Parameters["p_page_size"].Value = 100;
        oracom.Parameters["p_page_num"].Value = 1;
        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);

        gvB24.DataSource = ds.Tables[0];
        gvB24.DataBind();

        gvAcc.DataSource = ds.Tables[1];
        gvAcc.DataBind();

        gvAccATM.DataSource = ds.Tables[2];
        gvAccATM.DataBind();

        oracon.Close();
    }

    private void loadChannel(string claimID)
    {
        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.search_invstchl_claim";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_id", 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_outputchlinvst", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

        oracom.Parameters["p_claim_id"].Value = claimID;

        oracom.Parameters["p_page_size"].Value = 100;
        oracom.Parameters["p_page_num"].Value = 1;
        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);

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

        oracon.Close();
    }

    private void loadEJ(string claimID)
    {
        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.search_invstej_claim";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_id", 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_outputejlinvst", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

        oracom.Parameters["p_claim_id"].Value = claimID;

        oracom.Parameters["p_page_size"].Value = 100;
        oracom.Parameters["p_page_num"].Value = 1;
        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);

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

        oracon.Close();
    }

    private void loadNotes(string claimID)
    {
        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_COMMENTATOR.Get_Claim_Comments";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_id", 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["p_claim_id"].Value = claimID;

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

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

        oracon.Close();
    }

    protected void btnApprove_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        bool saved = Approve(clID, ref error);
        if (saved)
        {
            lblError.Text = "Claim Submitted for approval";
            loadClaimByID(Request.QueryString["clID"]);
        }
        else
        {
            lblError.Text = error;
        }
    }

    protected void btnDecline_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        bool saved = Decline(clID, ref error);
        if (saved)
        {
            lblError.Text = "Claim Rejected";
            loadClaimByID(Request.QueryString["clID"]);
        }
        else
        {
            lblError.Text = error;
        }
    }

    private bool Approve(string index, 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_INVESTIGATOR.submit_claim_info";

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

        oracom.Parameters["p_claim_id"].Value = index;

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

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

    private bool Decline(string index, 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_INVESTIGATOR.reject_claim_info";

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

        oracom.Parameters["p_claim_id"].Value = index;

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

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

    protected void gvB24_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("v"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string tID = gvB24.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;

            //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);
            pnlControls2.Visible = true;
        }
    }

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

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

    private void loadTranDetails(string tID)
    {
        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;

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

        GridView2.DataSource = ds.Tables[1];
        GridView2.DataBind();

    }

    private void loadTranDetails1(string tID)
    {
        pnlControls1.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)
    {
        pnlControls1.Visible = false;
    }

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

    protected void gvClaims_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("i"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvClaims.DataKeys[index].Value.ToString();
            Response.Redirect("InvestigateClaim.aspx?clID=" + rowID);
        }
    }

    protected void gvB24_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            if(ViewState["product"].ToString().Equals("1"))
                e.Row.Cells[9].Visible = false;
        }
    }
            
    protected void btnPaySlip_Click(object sender, EventArgs e)
    {
        string p1 = Session["uid"].ToString();
        string p2 = Request.QueryString["clID"];
        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        "window.open('../Reports/Default.aspx?rpt=102&p1=" + p1 + "&p2=" + p2 + "','Report')", 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;
        }
    }
    protected void ddlRespons_SelectedIndexChanged(object sender, EventArgs e)
    {
       
    }


    protected void btnCancelResponse_Click(object sender, EventArgs e)
    {

        Panel2.Visible = false;


    }
    protected void btnSaveResponse_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        bool saved = SamaResponse(clID, ref error);
        if (saved)
        {
            lblError.Text = "Informatino Response Saved";
            loadClaimByID(Request.QueryString["clID"]);
        }
        else
        {
            lblError.Text = error;
        }
    }

    //**************************************** Sama Operations ******************************************\\
    protected void btnsenttoCPS_Click(object sender, EventArgs e)
    {
        if (!lblStatus.Text.Equals("Pending"))
        {
            string error = "";
            string clID = Request.QueryString["clID"];
            bool saved = SamasenttoCPS(clID, ref error);
            if (saved)
            {
                lblError.Text = "Sent To CPS succesfully";
                loadClaimByID(Request.QueryString["clID"]);
            }
            else
            {
                lblError.Text = error;
            }
        }
        else
        {
            lblError.Text = "Claim is already sent to CPS file";
        }
        
    }

    protected void btnSamaAccept_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        bool saved = SamaApprove(clID, ref error);
        if (saved)
        {
            lblError.Text = "Claim is Approved";
            loadClaimByID(Request.QueryString["clID"]);
        }
        else
        {
            lblError.Text = error;
        }
    }

    protected void btnSamaReject_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        bool saved = SamaReject(clID, ref error);
        if (saved)
        {
            lblError.Text = "Claims is Rejected";
            loadClaimByID(Request.QueryString["clID"]);
        }
        else
        {
            lblError.Text = error;
        }
    }

    protected void btnRequest_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        bool saved = SamaRequest(clID, ref error);
        if (saved)
        {
            lblError.Text = "Information Request saved";
            loadClaimByID(Request.QueryString["clID"]);
        }
        else
        {
            lblError.Text = error;
        }
    }

    protected void btnResponse_Click(object sender, EventArgs e)
    {
        Panel2.Visible = true;
    }

    private bool SamasenttoCPS(string index, 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_INVESTIGATOR.send_to_CPS";

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

        oracom.Parameters["p_claim_id"].Value = index;

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

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

    private bool SamaApprove(string index, 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_INVESTIGATOR.samaclaim_closedaccpt";

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

        oracom.Parameters["p_claim_id"].Value = index;
        oracom.Parameters["p_note_text"].Value = txtNote.Text;

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

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

    private bool SamaReject(string index, 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_INVESTIGATOR.samaclaim_closedreject";

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

        oracom.Parameters["p_claim_id"].Value = index;
        oracom.Parameters["p_note_text"].Value = txtNote.Text;

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

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

    private bool SamaRequest(string index, 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_INVESTIGATOR.samaclaim_acqinfo_request";

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

        oracom.Parameters["p_claim_id"].Value = index;
        oracom.Parameters["p_note_text"].Value = txtNote.Text;

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

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

    private bool SamaResponse(string index, 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_INVESTIGATOR.samaclaim_inforesp";

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

        oracom.Parameters["p_claim_id"].Value = index;
        oracom.Parameters["p_note_text"].Value = ddlRespons.SelectedValue;

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

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

    //private bool cansenttoCPS(string index, 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_INVESTIGATOR.Can_Send_To_CPS";

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

    //    oracom.Parameters["p_claim_id"].Value = index;

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

    //    oracom.ExecuteNonQuery();
    //    oracon.Close();
    //    string p = oracom.Parameters["p_res_code"].Value.ToString();
    //    error = oracom.Parameters["p_res_msg"].Value.ToString();
    //    if (p == "0")
    //        //samaActions.Visible = true;
    //       return true;
        
    
    //     else if (p == "999")
    //        //samaActions.Visible = false;
    //        return false;

    //    return false;
    //}

    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("POSClaimsPOS.aspx");
    }

    protected void gvClaims_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void btnAddNote_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        bool saved = addNote(clID, ref error);
        if (saved)
        {
            lblError.Text = "Note Saved";
            loadNotes(Request.QueryString["clID"]);
        }
        else
        {
            lblError.Text = error;
        }
    }

    private bool addNote(string index, 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_COMMENTATOR.Add_Claim_Comment";

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

        oracom.Parameters["p_claim_id"].Value = index;
        oracom.Parameters["p_note"].Value = txtAddNote.Text;

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

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