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_AddMClaim1 : System.Web.UI.Page
{

    string ID_ReOpenClaim;
    string error_ReOpenClaim;
    string claim_id_CheckTranasctions;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pnlClaim.Visible = false;
            pnlTxn.Visible = false;
            pnlControls.Visible = false;
            pnlControls2.Visible = false;
            pnl_Add_Claim_confirmation.Visible = false;
        }
        lblError.Text = "";
    }

    private bool checkClaimStatus()
    {
        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "CLAIM_BY_CH_PROCESS.CHECK_CLAIM_STATUS";
        oracom.Parameters.Add("p_claim_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_result", OracleType.Number).Direction = ParameterDirection.Output;


        oracom.Parameters["p_claim_id"].Value = lblClaimId.Text;
        oracom.ExecuteNonQuery();
        oracon.Close();

        if (int.Parse(oracom.Parameters["p_result"].Value.ToString()) == 1)
            return true; // Can be re-opened
        else
            return false;

    }

    protected void btnSave_Click(object sender, EventArgs e)
    {

        lblError.Text = "";
        if (lblClaimId.Text.Length > 0)
        {
            checkTransactionClaims();
            if (claim_id_CheckTranasctions != "0")
            {
                lblError.Text = "Claim " + claim_id_CheckTranasctions + " Is Already opened for this transaction "
                    + Environment.NewLine + "Please close the claim before open a new one";
            }
            else
            {

                if (checkClaimStatus())
                {
                    pnl_Add_Claim_confirmation.Visible = true;
                    pnl_Add_Claim_confirmation.Focus();
                }
                else
                {
                    lblError.Text = "This claim is still opened in SAMA" + Environment.NewLine + "Please make sure to close this claim before re-open it";
                }
            }
        }
        else
        {
            if (pnlControls.Visible)
            {
                string ID = "", error = "";
                bool saved = addClaim(ref ID, ref error);
                if (saved)
                {
                    lblError.Text = "claim saved. (Claim ID: " + ID + " )";
                    pnlControls.Visible = false;
                    pnlControls2.Visible = false;
                    pnlTxn.Visible = false;
                }
                else
                    lblError.Text = error + " " + ID;
            }
            else
            {
                string ID = "", error = "";
                bool saved = addClaim(ref ID, ref error);
                if (saved)
                {
                    lblError.Text = "claim saved. (Claim ID: " + ID + " )";
                }
                else
                    lblError.Text = error + " " + ID;
            }
        }
            
    }

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

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        txtCardNo.Text = txtCardNo.Text.Trim();
        txtAmount.Text = txtAmount.Text.Trim();
        txtReference.Text = txtReference.Text.Trim();
        txtAuthenticateCode.Text = txtAuthenticateCode.Text.Trim();

        if (txtCardNo.Text.Length == 0)
            lblError.Text = "you must enter the card number";
        else if (dtTxnDate.date.Length == 0)
            lblError.Text = "you must enter the transaction date";
        else
        {
            loadB24(Helper.gridSize(), 1);
            pnlTxn.Visible = true;
            pnlControls.Visible = false;
            pnlControls2.Visible = false;
        }
    }

    protected void btnSearchMer_Click(object sender, EventArgs e)
    {
        txtClientNo.Text = txtClientNo.Text.Trim();
        txtRetailerID.Text = txtRetailerID.Text.Trim();

        if (txtClientNo.Text.Length == 0 && txtRetailerID.Text.Length == 0)
        {
            lblError.Text = "you must enter the client number or the retailer id";
            pnlClaim.Visible = false;
        }
        else
        {
            loadTerminals(Helper.gridSize(), 1);
            pnlClaim.Visible = true;
            pnlTxn.Visible = false;
            pnlControls.Visible = false;
            pnlControls2.Visible = 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);
            txtInputAmount.ReadOnly = true;
            txtInputReference.ReadOnly = true;
            txtInputTerminalID.ReadOnly = true;
        }
    }

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

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        pnlControls2.Visible = true;
        txtInputCard.Text = txtCardNo.Text;
        txtInputTransactionDate.Text = dtTxnDate.FormatedDate;
        txtHDATE.Text = dtTxnDate.date;

        txtInputAmount.ReadOnly = false;
        txtInputReference.ReadOnly = false;
        txtInputTerminalID.ReadOnly = false;
    }


    //************************************** transactions **************************************\\

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "claim_by_merchant_ch_process.search_mer_ch_info";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_retailer_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_client_no", 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_out_mer_chinfo", OracleType.Cursor).Direction = ParameterDirection.Output;


        oracom.Parameters["p_retailer_id"].Value    = txtRetailerID.Text;
        if (txtClientNo.Text.Length == 0)
            oracom.Parameters["p_client_no"].Value = OracleNumber.Null;
        else
            oracom.Parameters["p_client_no"].Value      = txtClientNo.Text;

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

        oracon.Close();

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

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "claim_by_merchant_ch_process.search_mer_ch_b24txns";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_card_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_auth_code", 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_out_mer_ch_b24", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;


        oracom.Parameters["p_card_number"].Value = txtCardNo.Text;
        oracom.Parameters["p_tran_date"].Value = dtTxnDate.date;
        oracom.Parameters["p_term_id"].Value = ddlTerminals.SelectedValue;
        oracom.Parameters["p_tran_amount"].Value = txtAmount.Text;
        oracom.Parameters["p_rrn"].Value = txtReference.Text;
        oracom.Parameters["p_auth_code"].Value = txtAuthenticateCode.Text;

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

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

        int nop = int.Parse(oracom.Parameters["p_total_pages"].Value.ToString());
        oracon.Close();

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

    private void loadTranDetails(string tID)
    {
        pnlControls.Visible = true;
        pnlControls2.Visible = true;
        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "TRANSACTIONS_SEARCHER.Get_Master_Tran";

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

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

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

        oracon.Close();

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

        Label3.Text = ds.Tables[0].Rows[0]["TRAN_DATE"].ToString();
        txtInputTransactionDate.Text = ds.Tables[0].Rows[0]["TRAN_DATE"].ToString();
        Label4.Text = ds.Tables[0].Rows[0]["TRAN_TIME"].ToString();
        Label5.Text = ds.Tables[0].Rows[0]["CARD_NUMBER"].ToString();
        txtInputCard.Text = ds.Tables[0].Rows[0]["CARD_NUMBER"].ToString();
        Label6.Text = ds.Tables[0].Rows[0]["PCODE"].ToString();
        Label7.Text = ds.Tables[0].Rows[0]["FINANCIAL_FLAG"].ToString();
        Label8.Text = ds.Tables[0].Rows[0]["B24_RSP"].ToString();
        Label9.Text = ds.Tables[0].Rows[0]["ISO_RSP"].ToString();
        Label10.Text = ds.Tables[0].Rows[0]["TERM_ID"].ToString();
        txtInputTerminalID.Text = ds.Tables[0].Rows[0]["TERM_ID"].ToString();
        Label11.Text = ds.Tables[0].Rows[0]["TRAN_AMOUNT"].ToString();
        txtInputAmount.Text = ds.Tables[0].Rows[0]["TRAN_AMOUNT"].ToString();
        Label12.Text = ds.Tables[0].Rows[0]["TRAN_SOURCE"].ToString();
        Label13.Text = ds.Tables[0].Rows[0]["TRAN_DEST"].ToString();
        Label14.Text = ds.Tables[0].Rows[0]["MSG_TYPE"].ToString();
        Label15.Text = ds.Tables[0].Rows[0]["TRACE_ID"].ToString();
        Label16.Text = ds.Tables[0].Rows[0]["FILE_NUMBER"].ToString();
        Label17.Text = ds.Tables[0].Rows[0]["CARD_BRAND"].ToString();
        lblRRN.Text = ds.Tables[0].Rows[0]["RRN"].ToString();
        txtInputReference.Text = ds.Tables[0].Rows[0]["RRN"].ToString();
        Label19.Text = ds.Tables[0].Rows[0]["CARD_EXP_DATE"].ToString();
        Label20.Text = ds.Tables[0].Rows[0]["ACCT_NUMBER"].ToString();
        Label21.Text = ds.Tables[0].Rows[0]["AUTH_CODE"].ToString();
        txtInputAuthenticationCode.Text = ds.Tables[0].Rows[0]["AUTH_CODE"].ToString();
        Label22.Text = ds.Tables[0].Rows[0]["BUSS_CLASS"].ToString();
        Label23.Text = ds.Tables[0].Rows[0]["TRAN_STATUS"].ToString();
        Label24.Text = ds.Tables[0].Rows[0]["TRAN_CURR"].ToString();
        Label25.Text = ds.Tables[0].Rows[0]["SETTL_CURR"].ToString();
        Label26.Text = ds.Tables[0].Rows[0]["SETTL_AMOUNT"].ToString();
        Label27.Text = ds.Tables[0].Rows[0]["TRAN_CHG"].ToString();
        Label28.Text = ds.Tables[0].Rows[0]["RECON_REQ_FLAG"].ToString();
        Label29.Text = ds.Tables[0].Rows[0]["RECON_PERFORMED_FLAG"].ToString();
        Label30.Text = ds.Tables[0].Rows[0]["MATCH_CRIERIA"].ToString();
        Label31.Text = ds.Tables[0].Rows[0]["MATCH_REF1"].ToString();
        Label32.Text = ds.Tables[0].Rows[0]["MATCH_REF2"].ToString();
        Label33.Text = ds.Tables[0].Rows[0]["MATCH_REF3"].ToString();
        Label34.Text = ds.Tables[0].Rows[0]["MATCH_REF4"].ToString();
        Label35.Text = ds.Tables[0].Rows[0]["MATCH_DATE1"].ToString();
        Label36.Text = ds.Tables[0].Rows[0]["MATCH_DATE2"].ToString();
        Label37.Text = ds.Tables[0].Rows[0]["MATCH_DATE3"].ToString();
        Label38.Text = ds.Tables[0].Rows[0]["MATCH_DATE4"].ToString();
        Label39.Text = ds.Tables[0].Rows[0]["CHIP_DATA"].ToString();
        Label40.Text = ds.Tables[0].Rows[0]["NEXT_MATCH"].ToString();
        Label41.Text = ds.Tables[0].Rows[0]["re_code"].ToString();
        Label42.Text = ds.Tables[0].Rows[0]["PRODUCT"].ToString();
        Label43.Text = ds.Tables[0].Rows[0]["ORIG_OSEQ_NUM"].ToString();
        Label44.Text = ds.Tables[0].Rows[0]["ORIG_DATE"].ToString();
        Label45.Text = ds.Tables[0].Rows[0]["ORIG_TIME"].ToString();
        Label46.Text = ds.Tables[0].Rows[0]["AMT_2"].ToString();
        Label47.Text = ds.Tables[0].Rows[0]["AMT_3"].ToString();
        Label48.Text = ds.Tables[0].Rows[0]["AUTH_AMT"].ToString();
        txtHDATE.Text = ds.Tables[0].Rows[0]["TRAN_DATE_ORG"].ToString();

        lblClaimId.Text = ds.Tables[0].Rows[0]["claim_id"].ToString();

    }

    private bool addClaim(ref string ID, ref string error)
    {
        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "claim_by_merchant_ch_process.merch_add_claim_info";

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

        oracom.Parameters.Add("p_retailer_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_client_no", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_card_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_mt_code", OracleType.Number).Direction = ParameterDirection.Input;

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

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

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

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

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

    private bool matchClaim(string clID, string mtCode, 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_process.match_claimtxn";

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

        oracom.Parameters.Add("p_mt_code", OracleType.VarChar).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_lang"].Value = "EN";
        oracom.Parameters["c_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_mt_code"].Value = mtCode;
        oracom.Parameters["p_claim_id"].Value = clID;

        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 CheckDigit(string new_RRN)
    {
        bool status = true;
        for (int i = 0; i < new_RRN.Length; i++)
        {
            if (!Char.IsDigit(new_RRN[i]))
                status = false;
        }
        return status;
    }


    private bool ReOpenClaim(ref string claim, ref string error)
    {
        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "CLAIM_BY_CH_PROCESS.ADD_CLAIM_NEW_RRN";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claimid", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_new_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_mt_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_channel", 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_new_claimId", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_claim_channel"].Value = "001";
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();
        oracom.Parameters["p_new_rrn"].Value = txtNewRRN.Text.Trim();
        oracom.Parameters["p_claimid"].Value = lblClaimId.Text.Trim();
        if (txtHMTCODE.Text.Length == 0)
            oracom.Parameters["p_mt_code"].Value = OracleNumber.Null;
        else
            oracom.Parameters["p_mt_code"].Value = txtHMTCODE.Text;

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        ID_ReOpenClaim = oracom.Parameters["p_new_claimId"].Value.ToString();
        error_ReOpenClaim = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }
    protected void btn_Add_Claim_cancel_Click(object sender, EventArgs e)
    {
        pnl_Add_Claim_confirmation.Visible = false;
    }

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "CLAIM_BY_CH_PROCESS.GET_TRANSACTION_CLAIMS";

        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_claim_out", OracleType.VarChar, 250).Direction = ParameterDirection.Output;


        oracom.Parameters["p_card_number"].Value = txtCardNo.Text;
        string date = txtInputTransactionDate.Text.Replace("-", "");
        oracom.Parameters["p_tran_date"].Value = date.Substring(6, 2) + date.Substring(2, 2) + date.Substring(0, 2);
        oracom.Parameters["p_rrn"].Value = txtInputReference.Text;

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

        if (oracom.Parameters["p_claim_out"].Value.ToString() != "0")
            claim_id_CheckTranasctions = oracom.Parameters["p_claim_out"].Value.ToString();
        else
            claim_id_CheckTranasctions = "0";
    }

    protected void btn_Add_Claim_confirmation_Click(object sender, EventArgs e)
    {
        string ID = "", error = "";
        if (txtNewRRN.Text.Length <= 0)
        {
            lblError.Text = "Please enter the new RRN , and it shouldn't be same as the original RRN";
            pnl_Add_Claim_confirmation.Visible = false;
            txtNewRRN.Focus();
        }
        else
        {
            if (txtNewRRN.Text != lblRRN.Text)
            {
                if (CheckDigit(txtNewRRN.Text.Trim()))
                {

                    bool saved = ReOpenClaim(ref ID, ref error);
                    if (saved)
                    {
                        lblError.Text = "claim saved. --> Claim ID: " + ID_ReOpenClaim;
                        pnl_Add_Claim_confirmation.Visible = false;
                        ID_ReOpenClaim = "";
                        error_ReOpenClaim = "";
                    }
                    else
                    {
                        lblError.Text = error_ReOpenClaim + " " + ID;
                        pnl_Add_Claim_confirmation.Visible = false;
                        ID_ReOpenClaim = "";
                        error_ReOpenClaim = "";
                    }
                }
                else
                {
                    lblError.Text = "The RRN That you Enterd is Invalid, Please re-Check";
                    pnl_Add_Claim_confirmation.Visible = false;
                    txtNewRRN.Focus();
                }
            }
            else
            {
                lblError.Text = "Please enter the new RRN , and it shouldn't be same as the original RRN";
                pnl_Add_Claim_confirmation.Visible = false;
            }
        }
    }
}
