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 EjadaMQProcessor;
using System.Web.Services;
//using Ejada.SharpSsh.jsch;

public partial class POS_InvestigateClaim : System.Web.UI.Page
{
    // static string prevPage = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //if(Request.UrlReferrer !=null )
            //    prevPage = Request.UrlReferrer.ToString();
            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;
            loadCPSTypes(Request.QueryString["clID"]);
            loadPrepaidAccountTypes();

            //if (lbl_Re_Code.Text == "5" || lbl_Re_Code.Text == "17")
            //    btnsenttoCPS.Enabled = false;

        }

        //if ( (lbl_Re_Code.Text == "5" || lbl_Re_Code.Text == "17") && (lblFromAcctDesc.Text.Length < 5 || lblToAcctDesc.Text.Length <5) )
        if (lblFromAcctDesc.Text.Length < 5 || lblToAcctDesc.Text.Length < 5)
            btnsenttoCPS.Enabled = false;
        else
            btnsenttoCPS.Enabled = true;

        btnPaySlip.OnClientClick = "javascript:return popUp('" + Request.QueryString["clID"] + "')";
    }



    [WebMethod(enableSession: true)]
    public static string Update_Ext_Ref_No(string claim_id, string Ext_Ref_No)
    {

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

        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_ext_RRN", 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 = claim_id;
        oracom.Parameters["p_ext_RRN"].Value = Ext_Ref_No;
        oracom.Parameters["p_current_uid"].Value = HttpContext.Current.Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();

        if (a == "0")
            return "Sucessfully Updated";
        else
            return oracom.Parameters["p_res_msg"].Value.ToString();
    }


    //ddlPrepaidAcctType

    private void loadPrepaidAccountTypes()
    {

        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_EXT_ACCT_TYPE";

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



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

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

        oracon.Close();

        ddlPrepaidAcctType.Items.Insert(0, "------ Account Type ------");



    }
    private void loadCPSTypes(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 = "poslookup_getter.Get_CPS_Claim_Type";

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

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

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

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

        oracon.Close();

        ddlCPSType.Items.Insert(0, "------ Claim Type ------");


        //if (lblClaimType.Text != "100")
        //    ddlCPSType.SelectedValue = lblClaimType.Text;
    }

    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;
        lblClaimID.NavigateUrl = "ClaimHistory.aspx?clID=" + 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();

        lblSettlementAmt.Text = ds.Tables[0].Rows[0]["settl_amount"].ToString(); // IRFAN_MOD 190908

        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();
        lblCPSType.Text = ds.Tables[0].Rows[0]["claim_type"].ToString();
        lblSugAmt.Text = ds.Tables[0].Rows[0]["claim_amount"].ToString();
        lblClMessage.Text = ds.Tables[0].Rows[0]["message_text"].ToString();
        lblCPSFile.Text = ds.Tables[0].Rows[0]["sama_file_name"].ToString();
        lblModifiedBy.Text = ds.Tables[0].Rows[0]["last_Modified_by"].ToString();
        string claimStatusCD = ds.Tables[0].Rows[0]["claim_status_cd"].ToString();
        string samaStatusCD = ds.Tables[0].Rows[0]["sama_status_cd"].ToString();
        string transSrc = ds.Tables[0].Rows[0]["tran_src"].ToString();
        string samaClaim = ds.Tables[0].Rows[0]["sama_claim"].ToString();
        lbl_sama_claim_id.Text = ds.Tables[0].Rows[0]["ORG_CLAIM_ID"].ToString();

        lblfromAccount.Text = ds.Tables[0].Rows[0]["FROM_ACCT"].ToString();
        lbltoAccount.Text = ds.Tables[0].Rows[0]["TO_ACCT"].ToString();
        lblClaimType.Text = ds.Tables[0].Rows[0]["CLAIM_TYPE_VAL"].ToString();

        LblOriginator.Text = ds.Tables[0].Rows[0]["Originator_Id"].ToString(); //irfan_mod 170216

        string err = "";
        string cpsID = Request.QueryString["clID"];
        //samaActions.Visible = cansenttoCPS(Request.QueryString["clID"], ref err);
        cpsInfo.Visible = samaActions.Visible;
        //txtSugAmt.Text = lblAmount.Text;
        txtSugAmt.Text = lblSugAmt.Text;

        this.lbl_acquirerBank.Text = ds.Tables[0].Rows[0]["ACQUIRER_BANK_CODE"].ToString();
        this.lbl_issuerBank.Text = ds.Tables[0].Rows[0]["ISSUER_BANK_CODE"].ToString();

        //irfan_mod
        txtExtRefNo.Text = ds.Tables[0].Rows[0]["ext_ref_no"].ToString();
        lblExtOutwardFileID.Text = ds.Tables[0].Rows[0]["ext_outward_file_id"].ToString();
        if (lblExtOutwardFileID.Text.Trim().Length > 1)
        {
            txtExtRefNo.Enabled = false;
            btnSavePPPMS.Visible = false;
        }
        //


        this.lblNEW_RRN.Text = ds.Tables[0].Rows[0]["NEW_RRN"].ToString();
        this.lblDEBIT_ISSUER.Text = ds.Tables[0].Rows[0]["DEBIT_ISSUER"].ToString();
        this.lblDEBIT_ACQUIRER.Text = ds.Tables[0].Rows[0]["DEBIT_ACQUIRER"].ToString();
        this.lblCREDIT_ACQUIRER.Text = ds.Tables[0].Rows[0]["CREDIT_ACQUIRER"].ToString();
        this.lblCREDIT_ISSUER.Text = ds.Tables[0].Rows[0]["CREDIT_ISSUER"].ToString();
        this.lblFromAcctDesc.Text = ds.Tables[0].Rows[0]["FROM_ACCT_DESC"].ToString();
        this.lblToAcctDesc.Text = ds.Tables[0].Rows[0]["TO_ACCT_DESC"].ToString();
        // IRFAN_MOD 170322 SAIB CR
        this.lblValFromAcct_2.Text = ds.Tables[0].Rows[0]["FROM_ACCT_2"].ToString();
        this.lblValToAcct_2.Text = ds.Tables[0].Rows[0]["To_Acct_2"].ToString();

        this.lblValFromAcct_3.Text = ds.Tables[0].Rows[0]["From_Acct_3"].ToString();
        this.lblValToAcct_3.Text = ds.Tables[0].Rows[0]["To_Acct_3"].ToString();
        //IRFAN_MOD 170322 SAIB CR


        hideButtons();


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

        lbl_Re_Code.Text = Re_Code;

        //if (ViewState["product"]=="2")
        //{
        lblNarrrFromAcct.Text = lblFrom.Text = "From Account";
        lblNarrrToAcct.Text = lblTo.Text = "To Account";
        lblNarrrFromAcct_2.Text = lblFrom_2.Text = "From Account 2nd GL";
        lblNarrrToAcct_2.Text = lblTo_2.Text = "To Account 2nd GL";
        lblNarrrFromAcct_3.Text = lblFrom_3.Text = "From Account 3rd Gl";
        lblNarrrToAcct_3.Text = lblTo_3.Text = "To Account 3rd GL";
        //    //this.Pos_Claim.Visible = true;
        //}
        //else
        //{
        //    lblNarrrFromAcct.Text = lblFrom.Text = "From Account";
        //    lblNarrrToAcct.Text = lblTo.Text = "To Account";
        //   // this.Pos_Claim.Visible = false;
        //  //  lblCommissionFee.Visible = false;
        //   // txtCommissionFee.Visible = false;
        //}
        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;

            // not for saib  lblAtmOvShort.Visible = false;
            //not for saib TxtRefNo.Visible = false;

        }

    }

    public void SetAccountsFor2nd3rdGl()
    {
        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.CLAIMS_CONTRA_GL";

        oracom.Parameters.Add("P_RE_CODE", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_FROM_ACCT_1", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_TO_ACCT_1", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_FROM_ACCT_2", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_TO_ACCT_2", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_FROM_ACCT_2DESC", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_TO_ACCT_2DESC", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_FROM_ACCT_3", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_TO_ACCT_3", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_Res", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_FROM_ACCT_3DESC", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_TO_ACCT_3DESC", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("P_FLAG_C_M", OracleType.VarChar).Direction = ParameterDirection.Input;
       
        if ((lbl_Re_Code.Text == "8" || lbl_Re_Code.Text == "33") && rdCard.Checked==true)
            oracom.Parameters["P_FLAG_C_M"].Value = "C";
        else if ((lbl_Re_Code.Text == "8" || lbl_Re_Code.Text == "33") && reMer.Checked == true)
            oracom.Parameters["P_FLAG_C_M"].Value = "M";
        else
            oracom.Parameters["P_FLAG_C_M"].Value = OracleString.Null;


      

        oracom.Parameters["P_RE_CODE"].Value = lbl_Re_Code.Text;

        oracom.Parameters["P_FROM_ACCT_1"].Value = ddlFromAcct.SelectedValue;
        oracom.Parameters["P_TO_ACCT_1"].Value = ddlToAcct.SelectedValue;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        string resp = oracom.Parameters["P_Res"].Value.ToString();



        lblFrom_2.Text = oracom.Parameters["P_FROM_ACCT_2DESC"].Value.ToString();
        lblTo_2.Text = oracom.Parameters["P_TO_ACCT_2DESC"].Value.ToString();

        if (lblFrom_2.Text.ToUpper().Contains("MERCH") || lblFrom_2.Text.ToUpper().Contains("CARD"))
            lbl_FromAcct2.Enabled = true;
        else
            lbl_FromAcct2.Enabled = false;

        if (lblTo_2.Text.ToUpper().Contains("MERCH")   || lblTo_2.Text.ToUpper().Contains("CARD"))
            txtToManualMerAccount.Enabled = true;
        else
            txtToManualMerAccount.Enabled = false;

        lbl_FromAcct2.Text = oracom.Parameters["P_FROM_ACCT_2"].Value.ToString();
        txtToManualMerAccount.Text = oracom.Parameters["P_TO_ACCT_2"].Value.ToString();



        lblFrom_3.Text = oracom.Parameters["P_FROM_ACCT_3DESC"].Value.ToString();
        lblTo_3.Text = oracom.Parameters["P_TO_ACCT_3DESC"].Value.ToString();

        lbl_FromAcct3.Text = oracom.Parameters["P_FROM_ACCT_3"].Value.ToString();
        lbl_ToAcct3.Text = oracom.Parameters["P_TO_ACCT_3"].Value.ToString();

        //VAT

        lblVatRate.Text = Convert.ToString( Helper.Get_VAT_Rate()* 100 );
        //
        oracon.Close();

    }



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

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

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

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

        oracon.Close();
    }
    //public string PopulateAcct()
    //{
    //    string result="";
    //    try
    //    {
    //        string sQMgrName = "", sSendQName = "", sRecQName = "",sTimeout="";
    //        sQMgrName = ConfigurationManager.AppSettings["QMgrName"];
    //        sSendQName = ConfigurationManager.AppSettings["CardInqReq"];
    //        sRecQName = ConfigurationManager.AppSettings["CardInqResp"];
    //        sTimeout = ConfigurationManager.AppSettings["TimeOut"];
    //        CardDtlsInqGenerator.CardDtlsInqGen CardDtlsGenObj = new CardDtlsInqGenerator.CardDtlsInqGen();
    //        //string strReqMsg = CardDtlsGenObj.GenReqMsg(Label36 .Text.Trim ());
    //        //string strReqMsg = CardDtlsGenObj.GenReqMsg("4323282970109050");this.lblCardNo.Text

    //        string strReqMsg = CardDtlsGenObj.GenReqMsg(this.lblCardNo.Text);

    //        Helper.writeMWLog("Message Request : " + strReqMsg);

    //        //call mq processor


    //        //EjadaMQProcessorCls EjadaMQProcessorObj = new EjadaMQProcessorCls(sQMgrName, sSendQName, sRecQName, Label36 .Text);
    //        EjadaMQProcessorCls EjadaMQProcessorObj = new EjadaMQProcessorCls(sQMgrName , sSendQName , sRecQName , this.lblCardNo.Text);
    //        string[] resultantAccounts;

    //        //string result = CardDtlsGenObj.ParseResMsgXMLBased(EjadaMQProcessorObj.ProcessMessage(strReqMsg, "90000"), out resultantAccounts);
    //        string RecvMsg = EjadaMQProcessorObj.ProcessMessage(strReqMsg, sTimeout);
    //        Helper.writeMWLog("RecvMsg : " + RecvMsg);
    //        result = CardDtlsGenObj.ParseResMsgXMLBased(RecvMsg, out resultantAccounts);

    //        for (int i = 0; i < resultantAccounts.Length; i++)
    //        {
    //            ddlFromAcct.Items.Add(resultantAccounts[i]);
    //            ddlToAcct.Items.Add(resultantAccounts[i]);

    //        }
    //        return result;

    //    }
    //    catch (Exception ex)
    //    {
    //        Helper.writeMWLog(ex.Message);

    //        return  ex.Message;

    //    }

    //    //}
    //}


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

        if (gvNotes.Rows.Count > 0)
        {
            lblClaimNote.Text = "Claim Notes (*)";
            lblClaimNote.ForeColor = System.Drawing.Color.Red;
        }
        else
        {
            lblClaimNote.Text = "Claim Notes";
            lblClaimNote.ForeColor = System.Drawing.Color.Empty;
        }
    }

    protected void btnApprove_Click(object sender, EventArgs e)
    {
        lbl_FromAcct2.Text = "";
        txtToManualMerAccount.Text = "";
        lbl_FromAcct3.Text = "";
        lbl_ToAcct3.Text = "";


        OtherFromMerAccountNo.Text = "";
        OtherToMerAccount.Text = "";

        string product = ViewState["product"].ToString();

        this.pnlApprove.Visible = true;
        //this.OtherFromMerAccountNo.Visible = true;
        //this.OtherToMerAccount.Visible = true;
        if (product.Equals("1"))
        {

            loadFromAcct(Request.QueryString["clID"]);
            loadToAcct(Request.QueryString["clID"]);
            //if (!GetCustomerAccountNo())
            //{

            //    string res = PopulateAcct();
            //    if (!res.Equals("I000000"))
            //        lblError.Text = "Error Occured while populating Account Numbers";
            //}
        }
        //else if (product.Equals("2")) // ECOM CR Code merging 
        else{

            this.loadClaimAcct(Request.QueryString["clID"]);
        }

        this.lblGlAmt1.Text = this.txt_approve_suggestedAmount.Text = this.getSuggestedAmount();

        try
        {
            if (lblfromAccount.Text != "")
            {
                ddlFromAcct.SelectedValue = lblfromAccount.Text.Trim();
            }

            if (lbltoAccount.Text != "")
            {
                ddlToAcct.SelectedValue = lbltoAccount.Text.Trim();
            }
        }
        catch (Exception ex)
        {
            lbltoAccount.Text = "";
            lblfromAccount.Text = "";
        }
    }

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

        // string OVER_SHORT_REF_NO = ;

        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_sugg_amt", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_to_account", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_to_account_desc", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_from_account", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_from_account_desc", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_CARD_NUMBER", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_TRAN_DATE", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_RRN", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_OVER_SHORT_REF_NO", 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_sugg_amt"].Value = this.txt_approve_suggestedAmount.Text;
        oracom.Parameters["p_to_account"].Value = ddlToAcct.SelectedValue;
        oracom.Parameters["p_from_account"].Value = ddlFromAcct.SelectedValue;

        oracom.Parameters["P_CARD_NUMBER"].Value = this.lblCardNo.Text;
        oracom.Parameters["P_TRAN_DATE"].Value = Helper.formatDate_ToDBFormat(lblTxnDate.Text);
        oracom.Parameters["P_RRN"].Value = lblReference.Text;


        // IRFAN_MOD 170322 SAIB_CR Starts
        oracom.Parameters.Add("P_TXN_CHG", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("P_FROM_ACCT_2", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_TO_ACCT_2", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_FROM_ACCT_3", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_TO_ACCT_3", OracleType.VarChar).Direction = ParameterDirection.Input;

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

       
            if (ddlPrepaidAcctType.SelectedIndex > 0)
            {
                oracom.Parameters["P_Ext_Acct_Type"].Value = ddlPrepaidAcctType.SelectedValue;
            }
            else
                oracom.Parameters["P_Ext_Acct_Type"].Value = OracleString.Null;


        if (OtherToMerAccount.Text.Trim().Length == 0)
        {
            oracom.Parameters["p_to_account_desc"].Value = ddlToAcct.SelectedItem.Text;
            oracom.Parameters["p_to_account"].Value = ddlToAcct.SelectedValue;
        }
        else
        {
            oracom.Parameters["p_to_account_desc"].Value = OtherToMerAccount.Text;
            oracom.Parameters["p_to_account"].Value = OtherToMerAccount.Text;
        }

        if (OtherFromMerAccountNo.Text.Trim().Length == 0)
        {
            oracom.Parameters["p_from_account_desc"].Value = ddlFromAcct.SelectedItem.Text;
            oracom.Parameters["p_from_account"].Value = ddlFromAcct.SelectedValue;
        }
        else
        {
            oracom.Parameters["p_from_account_desc"].Value = OtherFromMerAccountNo.Text;
            oracom.Parameters["p_from_account"].Value = OtherFromMerAccountNo.Text;
        }



        //if (ViewState["product"].ToString().Equals("1"))
        //    oracom.Parameters["P_OVER_SHORT_REF_NO"].Value = this.TxtRefNo.Text;
        //else // IRFAN_MOD not used for saib
        oracom.Parameters["P_OVER_SHORT_REF_NO"].Value = OracleString.Null;

        if (this.txtCommissionFee.Text.Trim().Length >= 1)
            oracom.Parameters["P_TXN_CHG"].Value = Convert.ToDecimal(this.txtCommissionFee.Text.Trim());
        else
            oracom.Parameters["P_TXN_CHG"].Value = OracleNumber.Null;


        if (lbl_FromAcct2.Text.Length > 1)
        {


            oracom.Parameters["P_FROM_ACCT_2"].Value = lbl_FromAcct2.Text;
            oracom.Parameters["P_TO_ACCT_2"].Value = txtToManualMerAccount.Text;

        }
        else
        {

            oracom.Parameters["P_FROM_ACCT_2"].Value = OracleString.Null;
            oracom.Parameters["P_TO_ACCT_2"].Value = OracleString.Null;

        }

        if (lbl_FromAcct3.Text.Length > 1 && lbl_ToAcct3.Text.Length > 1)
        {
            oracom.Parameters["P_FROM_ACCT_3"].Value = lbl_FromAcct3.Text;
            oracom.Parameters["P_TO_ACCT_3"].Value = lbl_ToAcct3.Text;
        }
        else
        {
            oracom.Parameters["P_FROM_ACCT_3"].Value = OracleString.Null;
            oracom.Parameters["P_TO_ACCT_3"].Value = OracleString.Null;



        }//
        // IRFAN_MOD 170322 SAIB_CR Ends

        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;

            lblDenom.Text = gvEJ.Rows[index].Cells[22].Text;

            //load the message

            string termid = gvEJ.Rows[index].Cells[6].Text;
            string trace = gvEJ.Rows[index].Cells[9].Text;
            string date = gvEJ.Rows[index].Cells[18].Text;
            string status = gvEJ.Rows[index].Cells[19].Text;
            loadStatus(termid, trace, date, status);
            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();
        /*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();
    }

    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);
        // Response.Redirect("Slip.aspx");
        //ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        // "window.open('slip.aspx?clID=" + lblClaimID.Text .Trim() + "','Redirect')", true);


    }

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

    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)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        if (ddlCPSType.SelectedIndex == 0)
        {
            lblError.Text = "Please select Claim Type";
        }
        else
        {
            bool saved = SamasenttoCPS(clID, ref error);
            if (saved)
            {
                lblError.Text = "Sent To CPS succesfully";
                loadClaimByID(Request.QueryString["clID"]);
            }
            else
            {
                lblError.Text = error;
            }
        }
    }

    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)
    {
        double sugAmt;
        try
        {
            sugAmt = Double.Parse(txtSugAmt.Text);

            if (sugAmt > Double.Parse(lblAmount.Text) && sugAmt > Double.Parse(lblSettlementAmt.Text)) // IRFAN_MOD 190908
            {
                error = "Suggested Amount cannot be larger than Claim Amount";
                return false;
            }

        }
        catch (Exception)
        {
            error = "Wrong Amount Entered";
            return false;
        }

        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_claim_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_sug_amt", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_notes", 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_claim_type"].Value = ddlCPSType.SelectedValue;
        oracom.Parameters["p_sug_amt"].Value = Double.Parse(txtSugAmt.Text);
        oracom.Parameters["p_notes"].Value = txtNote.Text;

        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 = 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 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;
    //        loadCPSTypes(Request.QueryString["clID"]);
    //        txtSugAmt.Text = lblSugAmt.Text;

    //        return true;
    //    }

    //    else if (p == "999")
    //        //samaActions.Visible = false;
    //        return false;

    //    return false;
    //}

    //protected void btnBack_Click(object sender, EventArgs e)
    //{
    //    //Response.Redirect("POSClaimsATM.aspx");
    //    //Response.Redirect(prevPage);
    //    Response.Redirect(Request.QueryString["URL"].ToString());
    //}

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

    private void hideButtons()
    {
        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.View_screen_buttons";

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

        oracom.Parameters.Add("p_Req_Pay_Slip", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_Sub_Approv", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_Reject", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_Send_CPS", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_Sama_accept", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_Sama_reject", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_Req_info", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_Info_resp", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_claim_id"].Value = Request.QueryString["clID"];

        oracom.ExecuteNonQuery();

        string paySlip = oracom.Parameters["p_Req_Pay_Slip"].Value.ToString();
        string approve = oracom.Parameters["p_Sub_Approv"].Value.ToString();
        string reject = oracom.Parameters["p_Reject"].Value.ToString();
        string CPS = oracom.Parameters["p_Send_CPS"].Value.ToString();
        string samaAccept = oracom.Parameters["p_Sama_accept"].Value.ToString();
        string samReject = oracom.Parameters["p_Sama_reject"].Value.ToString();
        string reqInfo = oracom.Parameters["p_Req_info"].Value.ToString();
        string infoResp = oracom.Parameters["p_Info_resp"].Value.ToString();

        if (paySlip.Equals("N"))
            btnPaySlip.Visible = false;

        if (approve.Equals("N"))
        {
            btnApprove.Visible = false;
        }

        if (reject.Equals("N"))
            btnDecline.Visible = false;

        if (CPS.Equals("N"))
        {

            btnsenttoCPS.Visible = false;
            cpsInfo.Visible = false;
        }

        if (CPS.Equals("N") && approve.Equals("N"))
            rowSugAmt.Visible = false;

        if (samaAccept.Equals("N"))
            btnSamaAccept.Visible = false;

        if (samReject.Equals("N"))
            btnSamaReject.Visible = false;

        if (reqInfo.Equals("N"))
            btnRequest.Visible = false;

        if (infoResp.Equals("N"))
        {
            btnResponse.Visible = false;
            Panel2.Visible = false;
        }

        oracon.Close();

    }

    private bool GetCustomerAccountNo()
    {
        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_APPROVER.Get_CT_Acct";


        oracom.Parameters.Add("p_Card_Number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_Tran_Date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_RRN", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_Acc_Number", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_Card_Number"].Value = this.lblCardNo.Text;
        oracom.Parameters["p_Tran_Date"].Value = Helper.formatDate_ToDBFormat(lblTxnDate.Text);
        oracom.Parameters["P_RRN"].Value = this.lblReference.Text;

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

        string Account = oracom.Parameters["p_Acc_Number"].Value.ToString();

        if (String.IsNullOrWhiteSpace(Account))
            return false;

        ddlToAcct.Items.Add(Account);
        ddlFromAcct.Items.Add(Account);

        return true;


    }


    private void loadFromAcct(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_APPROVER.Get_ATM_frm_Acct";

        oracom.Parameters.Add("p_claim_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_output", 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();

        ddlFromAcct.DataSource = ds;
        ddlFromAcct.DataBind();
        this.ddlFromAcct.Items.Insert(0, "Other");
        if (ds.Tables[0].Rows.Count > 1)
        {
            ddlFromAcct.SelectedIndex = 1;

        }
        else
            OtherFromMerAccountNo.Visible = true;


        if (lblfromAccount.Text != "")
        {
            ddlFromAcct.SelectedValue = lblfromAccount.Text.Trim();
        }

    }

    private void loadToAcct(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_APPROVER.Get_ATM_to_Acct";

        oracom.Parameters.Add("p_claim_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_output", 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();

        ddlToAcct.DataSource = ds;
        ddlToAcct.DataBind();
        this.ddlToAcct.Items.Insert(0, "Other");
        if (ds.Tables[0].Rows.Count > 1)
        {
            ddlToAcct.SelectedIndex = 1;

        }
        else
            OtherToMerAccount.Visible = true;


        if (lbltoAccount.Text != "")
        {
            ddlToAcct.SelectedValue = lbltoAccount.Text.Trim();
        }

    }

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

    protected void btnSavePost_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        decimal amount, sugAmount;



        amount = decimal.Parse(lblAmount.Text);
        sugAmount = decimal.Parse(txt_approve_suggestedAmount.Text);

        if ((lbl_FromAcct2.Text.Trim().Length > 1 && txtToManualMerAccount.Text.Trim().Length == 0)
            || (lbl_FromAcct2.Text.Trim().Length == 0 && txtToManualMerAccount.Text.Trim().Length > 1))
        {
            lblError.Text = "Account should not be blank";

        }
        else if (lblCardNo.Text.Trim().Substring(0, 6) == Helper.getParamByID("302") && ddlPrepaidAcctType.SelectedIndex == 0)
            lblError.Text = "Select Prepaid Account Type";

        else if (OtherFromMerAccountNo.Text.Trim().Length == 0 || OtherToMerAccount.Text.Trim().Length == 0)
        {
            if (ddlToAcct.SelectedValue.Equals(ddlFromAcct.SelectedValue))
            {
                lblError.Text = "From Account must be different than To Account";
            }
            else
            {
                bool saved = Approve(clID, ref error);
                if (saved)
                {
                    lblError.Text = "Claim Submitted for approval";
                    loadClaimByID(Request.QueryString["clID"]);
                    btnsenttoCPS.Enabled = true; // Enable after accounts r saved
                }
                else
                {
                    lblError.Text = error;
                }

                this.pnlApprove.Visible = false;
            }
        }
        else
        {
            bool saved = Approve(clID, ref error);
            if (saved)
            {
                lblError.Text = "Claim Submitted for approval";
                loadClaimByID(Request.QueryString["clID"]);
            }
            else
            {
                lblError.Text = error;
            }

            this.pnlApprove.Visible = false;
        }

    }

    private void loadClaimAcct(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 = "POSLOOKUP_GETTER.Get_Claim_Accounts_List";

        oracom.Parameters.Add("p_claim_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_output", 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();

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


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



        this.ddlFromAcct.Items.Insert(0, "Other");
        this.ddlToAcct.Items.Insert(0, "Other");


    }

    private string getSuggestedAmount()
    {
        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_APPROVER.GET_SUGGESTED_AMOUNT";

        oracom.Parameters.Add("P_CLAIM_ID", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_CARD_NUMBER", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_TRAN_DATE", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("P_RRN", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("P_SUGGESTED_AMOUNT", OracleType.Number).Direction = ParameterDirection.Output;

        oracom.Parameters["P_CLAIM_ID"].Value = this.lblClaimID.Text;
        oracom.Parameters["P_CARD_NUMBER"].Value = this.lblCardNo.Text;
        oracom.Parameters["P_TRAN_DATE"].Value = Helper.formatDate_ToDBFormat(this.lblTxnDate.Text);
        oracom.Parameters["P_RRN"].Value = this.lblReference.Text;

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

        return oracom.Parameters["P_SUGGESTED_AMOUNT"].Value.ToString();
    }
    protected void ddlFromAcct_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlFromAcct.SelectedIndex == 0)
            OtherFromMerAccountNo.Visible = true;
        else
        {
            OtherFromMerAccountNo.Visible = false;


        }
        if (ViewState["product"].ToString().Equals("2")||ViewState["product"].ToString().Equals("3"))
        {

            SetAccountsFor2nd3rdGl();

        }


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

        if (ddlToAcct.SelectedIndex == 0)
            OtherToMerAccount.Visible = true;
        else
        {
            OtherToMerAccount.Visible = false;


        }
        if (ViewState["product"].ToString().Equals("2")||ViewState["product"].ToString().Equals("3"))
        {
            SetAccountsFor2nd3rdGl();
        }

    }

    // Only POS Aread Starts//
    protected void ddlFromAcct2_SelectedIndexChanged(object sender, EventArgs e) { }

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


    protected void ddlToAcct2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlToAcct.SelectedIndex == 0)
            txtToManualMerAccount.Visible = true;
        else
            txtToManualMerAccount.Visible = false;

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

    }
    // Only POS Aread Ends//
    protected void reMer_CheckedChanged(object sender, EventArgs e)
    {
        if (lbl_Re_Code.Text == "8" || lbl_Re_Code.Text=="33")
            SetAccountsFor2nd3rdGl();

   
    }
    protected void rdCard_CheckedChanged(object sender, EventArgs e)
    {
        if (lbl_Re_Code.Text == "8" || lbl_Re_Code.Text == "33")
            SetAccountsFor2nd3rdGl();

   
    }
}