using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Data;

public partial class ClaimsPOS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadStatus();
            loadEvents();
            loadSamaStatuses();
            loadSamaClaimTypes();
            //rdATM_CheckedChanged(sender, e);
            //loadClaims(Helper.gridSize(), 1);
            rdCH.Checked = true;
        }
        lblError.Text = "";
    }

    /// <summary>
    /// IJR 
    /// 28-Jan-2012
    /// Add The load events functions to get the events related to ATM (1)
    /// </summary>
    private void loadEvents()
    {
        ddlEvents.Items.Clear();
        string DBConnection = Helper.dbConnection();

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

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

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

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

        oracom.Parameters["p_product"].Value = 2;

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

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

        oracon.Close();
        ddlEvents.Items.Insert(0, "------ Events ------");
    }

    /// <summary>
    /// IJR
    /// 30-Jan-2012
    /// Load Sama Statuses
    /// </summary>
    private void loadSamaStatuses()
    {
        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_samastatus";

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

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

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


        ddlSamaStatuses.Items.Insert(0, "------ All ------");
        oracon.Close();
    }

    /// <summary>
    /// IJR
    /// 18-Feb-2012
    /// Load Sama claim types
    /// </summary>
    private void loadSamaClaimTypes()
    {
        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "lookup_getter.GET_SAMA_CLAIM_TYPES";

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

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

        ddlClaimType2.DataSource = ds;
        ddlClaimType2.DataBind();
        ddlClaimType2.Items.Insert(0, "------ All ------");
        oracon.Close();
    }

    private void loadStatus()
    {
        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_status";

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

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

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

        ddlClaimType.Items.Insert(0, "------ All ------");
        oracon.Close();
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddClaim.aspx?p=1");
    }

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

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        txtClaimID.Text = txtClaimID.Text.Trim();
        txtReference.Text = txtReference.Text.Trim();
        txtCardNumber.Text = txtCardNumber.Text.Trim();
        txtATMNo.Text = txtATMNo.Text.Trim();
        //IJR - 28-1-2012 , Add the original claim ID to search Criteria
        txtOrgClaimID.Text = txtOrgClaimID.Text.Trim();

        if (("".Equals(txtscfdate.Text.Trim()) && txtsctdate.Text.Trim().Length > 3) || ("".Equals(txtsctdate.Text.Trim()) && txtscfdate.Text.Trim().Length > 3))
        {
            //lblError.Text = "Please Enter both (From and To) Date";
            Notifications.showMessage("Please Enter both (From and To) Date", this, Notifications.errorMessage, false);
            return;
        }

        if (ddlClaimType.SelectedValue.ToString() == "301" && ddlSamaStatuses.SelectedValue.ToString() == "1")
        {
            loadClaims(Helper.gridSize(), 1);
        }
        else if (txtTermID.Text.Length == 0 && txtCardPOS.Text.Length == 0 && txtClaimID.Text.Length == 0 && txtOrgClaimID.Text.Length == 0 && (txtscfdate.Text.Length != 6 && txtsctdate.Text.Length != 6))
        {
            //lblError.Text = "Please enter at least one of the marked(*) fields";
            Notifications.showMessage("please enter at least one of the marked fields", this, Notifications.errorMessage, false);
            return;
        }  
        else loadClaims(Helper.gridSize(), 1);
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadClaims(Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
    }

    private void loadClaims(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_process.get_atmposclaim_info";

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

        //IRFAN_MOD SAIB_CR 170202 starts
        // oracom.Parameters.Add("c_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_date_from", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_date_To", OracleType.VarChar).Direction = ParameterDirection.Input;
        //   oracom.Parameters.Add("p_claim_Date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_on_off_Us_Flag", OracleType.VarChar).Direction = ParameterDirection.Input;
        // Ends

        //
        oracom.Parameters.Add("c_product", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_client_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_retailer_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_claim_status", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_onus", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_onus", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_mer_ch", OracleType.Number).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_getclaim_atmpos", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

        //IJR - 28-1-2012 , Add the original claim ID to search Criteria
        oracom.Parameters.Add("p_org_claim_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        //IJR - 28-1-2012 , Add the Event ID to search Criteria
        oracom.Parameters.Add("p_EventId", OracleType.VarChar).Direction = ParameterDirection.Input;
        //IJR - 30-1-2012 , edd claim action status to search Criteria
        oracom.Parameters.Add("p_claim_action_status", OracleType.VarChar).Direction = ParameterDirection.Input;

        //if (rdATM.Checked)
        //    oracom.Parameters["c_card_number"].Value = txtCardNumber.Text;
        //else
        //    oracom.Parameters["c_card_number"].Value = txtCardPOS.Text;




        oracom.Parameters["c_claim_id"].Value = txtClaimID.Text;
        oracom.Parameters["c_rrn"].Value = txtReference.Text;

        //IRFAN_MOD SAIB_CR 170202 starts
        //  oracom.Parameters["p_claim_date"].Value = dtClaimDate.date;
        oracom.Parameters["p_claim_date_from"].Value = Helper.getDate(txtscfdate.Text);
        oracom.Parameters["p_claim_date_To"].Value = Helper.getDate(txtsctdate.Text);

        if (rdClaimOnUS.Checked == true)
            oracom.Parameters["p_on_off_Us_Flag"].Value = "on-us";
        else if (rdClaimOffUs.Checked == true)
            oracom.Parameters["p_on_off_Us_Flag"].Value = "off-us";
        else
            oracom.Parameters["p_on_off_Us_Flag"].Value = "";
        // ENDS
        oracom.Parameters["c_client_number"].Value = txtClientNo.Text;
        oracom.Parameters["c_retailer_id"].Value = txtRetailerID.Text;
        oracom.Parameters["c_term_id"].Value = txtTermID.Text;
        oracom.Parameters["p_atm_num"].Value = txtATMNo.Text;


        if (txtCardPOS.Text.Length > 0)
            oracom.Parameters["c_card_number"].Value = txtCardPOS.Text;
        else
            oracom.Parameters["c_card_number"].Value = OracleString.Null;


        //if (rdATM.Checked)
        //{
        //    oracom.Parameters["c_product"].Value = "1";

        //    oracom.Parameters["p_mer_ch"].Value = OracleNumber.Null;

        //    if (rdOnUs.Checked)
        //        oracom.Parameters["p_onus"].Value = "1";
        //    else
        //        oracom.Parameters["p_onus"].Value = "0";
        //}
        //else
        //{
        oracom.Parameters["c_product"].Value = "2";
        //oracom.Parameters["p_onus"].Value = OracleNumber.Null;

        if (rdCH.Checked)
            oracom.Parameters["p_mer_ch"].Value = "0";
        else
            oracom.Parameters["p_mer_ch"].Value = "1";

        //}

        if (ddlClaimType.SelectedIndex > 0)
            oracom.Parameters["c_claim_status"].Value = ddlClaimType.SelectedValue;
        else
            oracom.Parameters["c_claim_status"].Value = OracleString.Null;

        if (txtOrgClaimID.Text.Length > 0)
            oracom.Parameters["p_org_claim_id"].Value = txtOrgClaimID.Text;
        else
            oracom.Parameters["p_org_claim_id"].Value = OracleString.Null;
        // oracom.Parameters["p_org_claim_id"].Value = txtOrgClaimID.Text;
        //IJR - 28-1-2012 , Add the Event ID to search Criteria
        if (ddlEvents.SelectedIndex > 0)
            oracom.Parameters["p_EventId"].Value = ddlEvents.SelectedValue;
        else
            oracom.Parameters["p_EventId"].Value = OracleString.Null;

        ////IJR - 30-1-2012 , edd claim action status to search Criteria
        if (ddlSamaStatuses.Enabled == false)
            oracom.Parameters["p_claim_action_status"].Value = OracleString.Null;
        else
            if (ddlSamaStatuses.SelectedIndex > 0)
                oracom.Parameters["p_claim_action_status"].Value = ddlSamaStatuses.SelectedValue;
            else
                oracom.Parameters["p_claim_action_status"].Value = OracleString.Null;

        if (rdOnUs.Enabled)
            if (rdOnUs.Checked)
                oracom.Parameters["p_onus"].Value = "C";
            else
                oracom.Parameters["p_onus"].Value = "S";
        else
            oracom.Parameters["p_onus"].Value = "C";

        //Start --> 18-2-2012 IJR: Add new parameter to define the ATM Type (CW or DEP)
        // and add the sama from/to date and the sma claim type
        oracom.Parameters.Add("p_atmType", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters["p_atmType"].Value = OracleString.Null;

        oracom.Parameters.Add("p_sama_from_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_sama_to_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_sama_claim_type", OracleType.VarChar).Direction = ParameterDirection.Input;

        if (txtssfdate.Text.Length > 0)
            oracom.Parameters["p_sama_from_date"].Value = Helper.getDate(txtssfdate.Text);
        else
            oracom.Parameters["p_sama_from_date"].Value = OracleString.Null;

        if (txtsstdate.Text.Length > 0)
            oracom.Parameters["p_sama_to_date"].Value = Helper.getDate(txtsstdate.Text);
        else
            oracom.Parameters["p_sama_to_date"].Value = OracleString.Null;


        if (ddlClaimType2.SelectedIndex > 0)
            oracom.Parameters["p_sama_claim_type"].Value = ddlClaimType2.SelectedValue;
        else
            oracom.Parameters["p_sama_claim_type"].Value = OracleString.Null;

        //END --> 18-2-2012 IJR: Add new parameter to define the ATM Type (CW or DEP)
        // and add the sama from/to date and the sma claim type

        oracom.Parameters["p_page_size"].Value = pageSize;
        oracom.Parameters["p_page_num"].Value = pageNumber;
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["c_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();

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

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

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

    private void loadClaims111(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_process.get_atmposclaim_info";

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

        //IRFAN_MOD SAIB_CR 170202 starts
        // oracom.Parameters.Add("c_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_date_from", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_claim_date_To", OracleType.VarChar).Direction = ParameterDirection.Input;
        // oracom.Parameters.Add("p_claim_Date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_on_off_Us_Flag", OracleType.VarChar).Direction = ParameterDirection.Input;
        // Ends

        oracom.Parameters.Add("c_product", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_client_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_retailer_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_claim_status", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_num", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_onus", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_onus", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_mer_ch", OracleType.Number).Direction = ParameterDirection.Input;

        //IJR - 28-1-2012 , Add the original claim ID to search Criteria
        oracom.Parameters.Add("p_org_claim_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        //IJR - 28-1-2012 , Add the Event ID to search Criteria
        oracom.Parameters.Add("p_EventId", OracleType.VarChar).Direction = ParameterDirection.Input;
        //IJR - 30-1-2012 , edd claim action status to search Criteria
        oracom.Parameters.Add("p_claim_action_status", 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_getclaim_atmpos", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

        if (txtClaimID.Text.Length > 0)
            oracom.Parameters["c_claim_id"].Value = txtClaimID.Text;
        else
            oracom.Parameters["c_claim_id"].Value = OracleString.Null;
        // oracom.Parameters["c_claim_id"].Value = txtClaimID.Text;


        if (txtReference.Text.Length > 0)
            oracom.Parameters["c_rrn"].Value = txtReference.Text;
        else
            oracom.Parameters["c_rrn"].Value = OracleString.Null;
        //oracom.Parameters["c_rrn"].Value = OracleString.Null;

        //IRFAN_MOD SAIB_CR 170202 starts
        // oracom.Parameters["p_claim_date"].Value =     dtClaimDate.date;
        oracom.Parameters["p_claim_date_from"].Value = Helper.getDate( txtscfdate.Text );
        oracom.Parameters["p_claim_date_To"].Value = Helper.getDate(txtsctdate.Text);

        if (rdClaimOnUS.Checked == true)
            oracom.Parameters["p_on_off_Us_Flag"].Value = "on-us";
        else if (rdClaimOffUs.Checked == true)
            oracom.Parameters["p_on_off_Us_Flag"].Value = "off-us";
        else
            oracom.Parameters["p_on_off_Us_Flag"].Value = "";

        // ENDS
        if (txtClientNo.Text.Length > 0)
            oracom.Parameters["c_client_number"].Value = txtClientNo.Text;
        else
            oracom.Parameters["c_client_number"].Value = OracleString.Null;
        //oracom.Parameters["c_client_number"].Value = txtClientNo.Text;

        if (txtRetailerID.Text.Length > 0)
            oracom.Parameters["c_retailer_id"].Value = txtRetailerID.Text;
        else
            oracom.Parameters["c_retailer_id"].Value = OracleString.Null;
        //oracom.Parameters["c_retailer_id"].Value = txtRetailerID.Text;


        if (txtTermID.Text.Length > 0)
            oracom.Parameters["c_term_id"].Value = txtTermID.Text;
        else
            oracom.Parameters["c_term_id"].Value = OracleString.Null;
        //oracom.Parameters["c_term_id"].Value = txtTermID.Text;


        if (txtATMNo.Text.Length > 0)
            oracom.Parameters["p_atm_num"].Value = txtATMNo.Text;
        else
            oracom.Parameters["p_atm_num"].Value = OracleString.Null;
        //oracom.Parameters["p_atm_num"].Value = txtATMNo.Text;

        //IJR - 31-1-2012 , On US OF Us Handling

        oracom.Parameters["c_product"].Value = "2";
        //oracom.Parameters["p_mer_ch"].Value = OracleNumber.Null;




        //if (ddlOnOf.Enabled == false)
        //{
        //    oracom.Parameters["p_onus"].Value = "0";
        //}
        //else
        //{
        //    if(ddlOnOf.SelectedIndex > 0)
        //        oracom.Parameters["p_onus"].Value = ddlOnOf.SelectedValue;
        //    else
        //        oracom.Parameters["p_onus"].Value = "0";//??
        //}

        if (txtCardNumber.Text.Length > 0)
            oracom.Parameters["c_card_number"].Value = txtCardNumber.Text;
        else
            oracom.Parameters["c_card_number"].Value = OracleString.Null;


        ////oracom.Parameters["c_card_number"].Value = txtCardPOS.Text;
        //if (rdATM.Checked)
        //    oracom.Parameters["c_card_number"].Value = txtCardNumber.Text;
        //else
        //    oracom.Parameters["c_card_number"].Value = txtCardPOS.Text;
        //if (rdATM.Checked)
        //{
        //    oracom.Parameters["c_product"].Value = "1";
        //    oracom.Parameters["p_mer_ch"].Value = OracleNumber.Null;

        //    if (rdOnUs.Checked)
        //        oracom.Parameters["p_onus"].Value = "1";
        //    else
        //        oracom.Parameters["p_onus"].Value = "0";
        //}
        //else
        //{
        //    oracom.Parameters["c_product"].Value = "2";
        //    oracom.Parameters["p_onus"].Value = OracleNumber.Null;

        if (rdCH.Checked)
            oracom.Parameters["p_mer_ch"].Value = "0";
        else
            oracom.Parameters["p_mer_ch"].Value = "1";
        //}

        if (ddlClaimType.SelectedIndex > 0)
            oracom.Parameters["c_claim_status"].Value = ddlClaimType.SelectedValue;
        else
            oracom.Parameters["c_claim_status"].Value = OracleString.Null;

        //IJR - 28-1-2012 , Add the original claim ID to search Criteria
        if (txtOrgClaimID.Text.Length > 0)
            oracom.Parameters["p_org_claim_id"].Value = txtOrgClaimID.Text;
        else
            oracom.Parameters["p_org_claim_id"].Value = OracleString.Null;
        // oracom.Parameters["p_org_claim_id"].Value = txtOrgClaimID.Text;
        //IJR - 28-1-2012 , Add the Event ID to search Criteria
        if (ddlEvents.SelectedIndex > 0)
            oracom.Parameters["p_EventId"].Value = ddlEvents.SelectedValue;
        else
            oracom.Parameters["p_EventId"].Value = OracleString.Null;

        ////IJR - 30-1-2012 , edd claim action status to search Criteria
        if (ddlSamaStatuses.Enabled == false)
            oracom.Parameters["p_claim_action_status"].Value = OracleString.Null;
        else
            if (ddlSamaStatuses.SelectedIndex > 0)
                oracom.Parameters["p_claim_action_status"].Value = ddlSamaStatuses.SelectedValue;
            else
                oracom.Parameters["p_claim_action_status"].Value = OracleString.Null;


        if (rdOnUs.Enabled)
            if (rdOnUs.Checked)
                oracom.Parameters["p_onus"].Value = "C";
            else
                oracom.Parameters["p_onus"].Value = "S";
        else
            oracom.Parameters["p_onus"].Value = "C";



        //Start --> 18-2-2012 IJR: Add new parameter to define the ATM Type (CW or DEP)
        // and add the sama from/to date and the sma claim type
        oracom.Parameters.Add("p_atmType", OracleType.VarChar).Direction = ParameterDirection.Input;
        if (ddlATM_Type.SelectedIndex > 0)
        {
            oracom.Parameters["p_atmType"].Value = ddlATM_Type.SelectedValue;
        }
        else
        {
            oracom.Parameters["p_atmType"].Value = OracleString.Null;
        }

        oracom.Parameters.Add("p_sama_from_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_sama_to_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_sama_claim_type", OracleType.VarChar).Direction = ParameterDirection.Input;

        if (txtssfdate.Text.Length > 0)
            oracom.Parameters["p_sama_from_date"].Value = Helper.getDate(txtssfdate.Text);
        else
            oracom.Parameters["p_sama_from_date"].Value = OracleString.Null;

        if (txtsstdate.Text.Length > 0)
            oracom.Parameters["p_sama_to_date"].Value = Helper.getDate(txtsstdate.Text);
        else
            oracom.Parameters["p_sama_to_date"].Value = OracleString.Null;


        if (ddlClaimType2.SelectedIndex > 0)
            oracom.Parameters["p_sama_claim_type"].Value = ddlClaimType2.SelectedValue;
        else
            oracom.Parameters["p_sama_claim_type"].Value = OracleString.Null;

        //END --> 18-2-2012 IJR: Add new parameter to define the ATM Type (CW or DEP)
        // and add the sama from/to date and the sma claim type

        oracom.Parameters["p_page_size"].Value = pageSize;
        oracom.Parameters["p_page_num"].Value = pageNumber;
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["c_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();

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

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("i"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();

            //By Ibrahim Al-Ashqar
            //For ANB Bank, because in it we are not using the departments concept
            //if (authenticateUser(rowID))


            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                            "window.open('InvestigateClaim.aspx?clID=" + rowID + "','Redirect')", true);


            //            Response.Redirect("InvestigateClaim.aspx?clID=" + rowID);

            //else
            //  lblError.Text = "You are not authorized to investigate this claim";
        }
        else if (e.CommandName.Equals("a"))
        {
            Lbl_CommandName.Text = "a";
            Lbl_CommandArgument.Text = e.CommandArgument.ToString();
            Lbl_URC_Message.Text = "Are you sure you want to Approve ?";

            Notifications.showModal("UR-confirmation-modal-xl", this);
        }
        else if (e.CommandName.Equals("d"))
        {
            Lbl_CommandName.Text = "d";
            Lbl_CommandArgument.Text = e.CommandArgument.ToString();
            Lbl_URC_Message.Text = "Are you sure you want to Delete ?";

            Notifications.showModal("UR-confirmation-modal-xl", this);
        }
        else if (e.CommandName.Equals("r"))
        {
            Lbl_CommandName.Text = "r";
            Lbl_CommandArgument.Text = e.CommandArgument.ToString();
            Lbl_URC_Message.Text = "Are you sure you want to Reset ?";

            Notifications.showModal("UR-confirmation-modal-xl", this);
        }
        else if (e.CommandName.Equals("decline"))
        {
            Lbl_CommandName.Text = "decline";
            Lbl_CommandArgument.Text = e.CommandArgument.ToString();
            Lbl_URC_Message.Text = "Are you sure you want to Decline ?";

            Notifications.showModal("UR-confirmation-modal-xl", this);
        }
        loadClaims(Helper.gridSize(), 1);
    }

    protected void btn_URConfirm_OK_Click(object sender, EventArgs e)
    {
        if (Lbl_CommandName.Text == "a")
        {
            //int index = int.Parse(e.CommandArgument.ToString());
            int index = int.Parse(Lbl_CommandArgument.Text);
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string product = GridView1.Rows[index].Cells[16].Text;
            string amount = GridView1.Rows[index].Cells[17].Text;
            string approved = GridView1.Rows[index].Cells[7].Text;
            if (!approved.ToLower().Equals("approved claim"))
            {
                if (product == "2")
                {
                    //POS
                    //pnlApprove.Visible = true;
                    Notifications.showModal("pnlApprove-modal-xl", this);

                    ddlATMAcc.Visible = false;
                    //ddlFromAcct.Visible = true;
                    // ddlToAcct.Visible = true;
                    ddlGLtype.Visible = true;

                    //loadClaimAcct(rowID);
                    //txtSugAmt.Visible = true;
                    ViewState["clid"] = rowID;
                    txtSugAmt.Text = amount;
                    this.loadPOSSelectedAcct(rowID);

                    btnSavePost.Focus();
                    //txtSugAmt.ReadOnly = true;
                    //string error = "";
                    //bool saved = Approve(rowID,"2","", ref error);
                    //if (saved)
                    //{
                    //    lblError.Text = "Claim Approved Successful";
                    //}
                    //else
                    //{
                    //    lblError.Text = error;
                    //}

                    lblNarrrFromAcct.Text = "From Account";
                    lblNarrrToAcct.Text = "To Account";
                    lblNarrrFromAcct.Text = "From Account";
                    lblNarrrToAcct.Text = "To Account"; ;
                    lblNarrrFromAcct_2.Text = "2nd Gl From Account";
                    lblNarrrToAcct_2.Text = "2nd Gl To Account";
                    lblNarrrFromAcct_3.Text = "3rd Gl From Account";
                    lblNarrrToAcct_3.Text = "3rd Gl To Account";
                }
                else
                {
                    //pnlApprove.Visible = true;
                    Notifications.showModal("pnlApprove-modal-xl", this);

                    //lblApprove.Text = "ATM cash Account";
                    // ddlFromAcct.Visible = false;
                    //  ddlToAcct.Visible = false;
                    ddlGLtype.Visible = false;
                    ddlATMAcc.Visible = true;
                    //txtSugAmt.Visible = true;
                    loadATMAcc(rowID);
                    ViewState["clid"] = rowID;
                    txtSugAmt.Text = amount;

                    btnSavePost.Focus();
                    //txtSugAmt.ReadOnly = false;
                }
            }
            else
            {
                //lblError.Text = "Claim already approved";
                Notifications.showMessage("Claim already approved", this, Notifications.errorMessage, false);
                return;

                //pnlApprove.Visible = false;
                // btnSavePost.Enabled = false;
            }
        }
        else if (Lbl_CommandName.Text == "d")
        {
            //int index = int.Parse(e.CommandArgument.ToString());
            int index = int.Parse(Lbl_CommandArgument.Text);
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string error = "";
            bool saved = Delete(rowID, ref error);
            if (saved)
            {
                //lblError.Text = "Claim Inactivated Successful";
                Notifications.showMessage("Claim Inactivated Successful", this, Notifications.successMessage, false);
                return;
            }
            else
            {
                //lblError.Text = error;
                Notifications.showMessage(error, this, Notifications.errorMessage, false);
                return;
            }
        }
        else if (Lbl_CommandName.Text == "r")
        {
            //int index = int.Parse(e.CommandArgument.ToString());
            int index = int.Parse(Lbl_CommandArgument.Text);
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string error = "";
            bool saved = Reset(rowID, ref error);
            if (saved)
            {
                //lblError.Text = "Claim Reset Successful";
                Notifications.showMessage("Claim Reset Successful", this, Notifications.successMessage, false);
                return;
            }
            else
            {
                //lblError.Text = error;
                Notifications.showMessage(error, this, Notifications.errorMessage, false);
                return;
            }
        }
        else if (Lbl_CommandName.Text == "decline")
        {
            //int index = int.Parse(e.CommandArgument.ToString());
            int index = int.Parse(Lbl_CommandArgument.Text);
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string approved = GridView1.Rows[index].Cells[7].Text;
            if (!approved.ToLower().Equals("declined claim"))
            {
                string error = "";
                bool saved = Decline(rowID, ref error);
                if (saved)
                {
                    //lblError.Text = "Claim Declined Successful";
                    Notifications.showMessage("Claim Declined Successful", this, Notifications.successMessage, false);
                    return;
                }
                else
                {
                    //lblError.Text = error;
                    Notifications.showMessage(error, this, Notifications.errorMessage, false);
                    return;
                }
            }
            else
            {
                //lblError.Text = "claim already declined";
                Notifications.showMessage("claim already declined", this, Notifications.errorMessage, false);
                return;
            }
        }

    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[16].Visible = false;
            e.Row.Cells[17].Visible = false;
            e.Row.Cells[18].Visible = false;
            //e.Row.Cells[14].Visible = false;
        }
    }
    private void loadATMAcc(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_glaccts";

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

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

    private bool Approve(string index, string isATM, 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_APPROVER.apprv_claim_gl";

        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_amount", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_atm_acct", 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;
        if (txtSugAmt.Text.Length == 0)
            txtSugAmt.Text = "0";
        if (isATM == "2")
            oracom.Parameters["p_atm_acct"].Value = OracleString.Null;
        else
            oracom.Parameters["p_atm_acct"].Value = ddlATMAcc.SelectedValue;

        oracom.Parameters["p_sugg_amount"].Value = txtSugAmt.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 ApprovePOSCalim(string index, string isATM, 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_APPROVER.approve_POS_claim_gl";

        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_frm_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_to_acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_gl_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_sugg_amount", 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["p_claim_id"].Value = index;

        if (txtSugAmt.Text.Length == 0)
            txtSugAmt.Text = "0";
        //if (isATM == "2")
        //    oracom.Parameters["p_atm_acct"].Value = OracleString.Null;
        //else
        //    oracom.Parameters["p_atm_acct"].Value = ddlATMAcc.SelectedValue;

        oracom.Parameters["p_frm_acct"].Value = lblValFromAcct.Text;
        oracom.Parameters["p_to_acct"].Value = lblValToAcct.Text;
        oracom.Parameters["p_gl_type"].Value = ddlGLtype.SelectedValue;

        oracom.Parameters["p_sugg_amount"].Value = txtSugAmt.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 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_APPROVER.decline_claim_info";

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

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

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

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }
    private bool Delete(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_process.inactive_claim_info";

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

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

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

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }
    private bool Reset(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_process.resetclm_to_orgclmstatus";

        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 rdATM_CheckedChanged(object sender, EventArgs e)
    //{
    //    rowATM.Visible = true;
    //    rowATM2.Visible = true;
    //    rowPOS.Visible = false;
    //    rowPOS2.Visible = false;
    //    rowPOS3.Visible = false;
    //    btnAdd1.Visible = false;

    //}

    //protected void rdPOS_CheckedChanged(object sender, EventArgs e)
    //{
    //    rowATM.Visible = false;
    //    rowATM2.Visible = false;
    //    rowPOS.Visible = true;
    //    rowPOS2.Visible = true;
    //    rowPOS3.Visible = true;
    //    btnAdd1.Visible = true;
    //}

    private bool authenticateUser(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_SECURITY.get_auth_user_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_user_id", 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_auth_user", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_claim_id"].Value = claimID;
        oracom.Parameters["p_user_id"].Value = Session["uid"].ToString();

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

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_out_auth_user"].Value.ToString();
        if (a == "1")
            return true;
        else
            return false;
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void ddlClaimType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlClaimType.SelectedValue == "301")
        {
            ddlSamaStatuses.Enabled = true;
            rdOnUs.Enabled = true;
            rdOther.Enabled = true;
        }
        else
        {
            ddlSamaStatuses.Enabled = false;
            rdOnUs.Enabled = false;
            rdOther.Enabled = false;
        }
    }
    protected void ddlEvents_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlEvents.SelectedValue == "4"
            || ddlEvents.SelectedValue == "10"
            || ddlEvents.SelectedValue == "12"
            || ddlEvents.SelectedValue == "13"
            || ddlEvents.SelectedValue == "111"
            || ddlEvents.SelectedValue == "112"
            || ddlEvents.SelectedValue == "113"
            || ddlEvents.SelectedValue == "114"
            || ddlEvents.SelectedValue == "115")
            ddlATM_Type.Enabled = true;
        else
            ddlATM_Type.Enabled = false;
    }
    protected void ddlATM_Type_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void btnGenReport_Click(object sender, EventArgs e)
    {
        txtClaimID.Text = txtClaimID.Text.Trim();
        txtReference.Text = txtReference.Text.Trim();
        txtCardNumber.Text = txtCardNumber.Text.Trim();
        txtATMNo.Text = txtATMNo.Text.Trim();
        //IJR - 28-1-2012 , Add the original claim ID to search Criteria
        txtOrgClaimID.Text = txtOrgClaimID.Text.Trim();

        if (ddlClaimType.SelectedValue.ToString() == "301" && ddlSamaStatuses.SelectedValue.ToString() == "1")
        {
            loadClaimsReport();
        }
        else if (txtATMNo.Text.Length == 0 && txtCardNumber.Text.Length == 0 && txtClaimID.Text.Length == 0 && txtOrgClaimID.Text.Length == 0)
        {
            //lblError.Text = "please enter at least one of the marked fields";
            Notifications.showMessage("Please enter at least one of the marked fields", this, Notifications.errorMessage, false);
            return;
        }
        else loadClaimsReport();
    }

    private void loadPOSSelectedAcct(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_selected_POS_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();

        lblValFromAcct.Text = ds.Tables[0].Rows[0]["FROM_ACCT"] as string;
        lblValFromAcct_2.Text = ds.Tables[0].Rows[0]["FROM_ACCT_2"] as string;
        lblValFromAcct_3.Text = ds.Tables[0].Rows[0]["FROM_ACCT_3"] as string;
        lblValToAcct.Text = ds.Tables[0].Rows[0]["TO_ACCT"] as string;
        lblValToAcct_2.Text = ds.Tables[0].Rows[0]["TO_ACCT_2"] as string;
        lblValToAcct_3.Text = ds.Tables[0].Rows[0]["TO_ACCT_3"] as string;

        lbl3rdGlAmt.Text = ds.Tables[0].Rows[0]["tran_chg"].ToString();
        decimal Commission = Convert.ToDecimal(lbl3rdGlAmt.Text);
        decimal VAT = Commission * Helper.Get_VAT_Rate();

        if (lbl3rdGlAmt.Text.Trim().Length > 0)
        {
            lbl2ndGlAmt.Text = (Convert.ToDecimal(txtSugAmt.Text) - Commission - VAT).ToString("0.##");
        }
    }

    private void loadClaimsReport()
    {
        string c_current_uid = "";
        string c_claim_id = "";
        string c_card_number = "";
        string c_rrn = "";
        string p_claim_date = "";
        string c_product = "";
        string c_client_number = "";
        string c_retailer_id = "";
        string c_term_id = "";
        string c_claim_status = "";
        string p_atm_num = "";
        string p_onus = "";
        int p_mer_ch = -1;
        string p_org_claim_id = "";
        string p_EventId = "";
        string p_claim_action_status = "";
        string p_atmType = "";
        string p_sama_from_date = "";
        string p_sama_to_date = "";
        string p_sama_claim_type = "";

        int p_page_size = 0;
        int p_page_num = 0;
        string p_lang = "EN";

        if (txtClaimID.Text.Length > 0)
            c_claim_id = txtClaimID.Text;
        else
            c_claim_id = null;

        if (txtReference.Text.Length > 0)
            c_rrn = txtReference.Text;
        else
            c_rrn = null;

        //    p_claim_date = dtClaimDate.date;

        if (txtClientNo.Text.Length > 0)
            c_client_number = txtClientNo.Text;
        else
            c_client_number = null;

        if (txtRetailerID.Text.Length > 0)
            c_retailer_id = txtRetailerID.Text;
        else
            c_retailer_id = null;

        if (txtTermID.Text.Length > 0)
            c_term_id = txtTermID.Text;
        else
            c_term_id = null;


        if (txtATMNo.Text.Length > 0)
            p_atm_num = txtATMNo.Text;
        else
            p_atm_num = null;

        c_product = "2";
        //p_mer_ch = null;

        if (txtCardNumber.Text.Length > 0)
            c_card_number = txtCardNumber.Text;
        else
            c_card_number = null;

        if (ddlClaimType.SelectedIndex > 0)
            c_claim_status = ddlClaimType.SelectedValue;
        else
            c_claim_status = null;

        if (txtOrgClaimID.Text.Length > 0)
            p_org_claim_id = txtOrgClaimID.Text;
        else
            p_org_claim_id = null;


        if (ddlEvents.SelectedIndex > 0)
            p_EventId = ddlEvents.SelectedValue;
        else
            p_EventId = null;

        if (ddlSamaStatuses.Enabled == false)
            p_claim_action_status = null;
        else
            if (ddlSamaStatuses.SelectedIndex > 0)
                p_claim_action_status = ddlSamaStatuses.SelectedValue;
            else
                p_claim_action_status = null;


        if (rdOnUs.Enabled)
            if (rdOnUs.Checked)
                p_onus = "C";
            else
                p_onus = "S";
        else
            p_onus = "C";


        if (ddlATM_Type.SelectedIndex > 0)
        {
            p_atmType = ddlATM_Type.SelectedValue;
        }
        else
        {
            p_atmType = null;
        }

        if (txtssfdate.Text.Length > 0)
            p_sama_from_date = Helper.getDate(txtssfdate.Text);
        else
            p_sama_from_date = null;

        if (txtsstdate.Text.Length > 0)
            p_sama_to_date = Helper.getDate(txtsstdate.Text);
        else
            p_sama_to_date = null;


        if (ddlClaimType2.SelectedIndex > 0)
            p_sama_claim_type = ddlClaimType2.SelectedValue;
        else
            p_sama_claim_type = null;

        c_current_uid = Session["uid"].ToString();

        string UrlString = "rpt=506&c_current_uid=" + c_current_uid
                            + "&c_claim_id=" + c_claim_id
                            + "&c_card_number=" + c_card_number
                            + "&c_rrn=" + c_rrn
                            + "&p_claim_date=" + p_claim_date
                            + "&c_product=" + c_product
                            + "&c_client_number=" + c_client_number
                            + "&c_retailer_id=" + c_retailer_id
                            + "&c_term_id=" + c_term_id
                            + "&c_claim_status=" + c_claim_status
                            + "&p_atm_num=" + p_atm_num
                            + "&p_onus=" + p_onus
                            + "&p_mer_ch=" + p_mer_ch
                            + "&p_org_claim_id=" + p_org_claim_id
                            + "&p_EventId=" + p_EventId
                            + "&p_claim_action_status=" + p_claim_action_status
                            + "&p_atmType=" + p_atmType
                            + "&p_sama_from_date=" + p_sama_from_date
                            + "&p_sama_to_date=" + p_sama_to_date
                            + "&p_sama_claim_type=" + p_sama_claim_type
                            + "&p_page_size=" + p_page_size
                            + "&p_page_num=" + p_page_num
                            + "&p_lang=" + p_lang;

        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
            "window.open('../Reports/Default.aspx?" + UrlString + "','Report')", true);
    }

    protected void GridView1_PreRender(object sender, EventArgs e)
    {
        if (GridView1.Rows.Count > 0)
        {
            GridView1.UseAccessibleHeader = true;
            GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
    }

    protected void btnSavePost_Click(object sender, EventArgs e)
    {
        string error = "";
        bool saved = false;
        if (ddlATMAcc.Visible)
            saved = Approve(ViewState["clid"].ToString(), "1", ref error);
        else
            saved = ApprovePOSCalim(ViewState["clid"].ToString(), "2", ref error);
        if (saved)
        {
            //lblError.Text = "Claim Approved Successful";
            Notifications.showMessage("Claim Approved Successful", this, Notifications.successMessage, false);
            return;
        }
        else
        {
            //lblError.Text = error;
            Notifications.showMessage(error, this, Notifications.errorMessage, false);
            return;
        }
        //pnlApprove.Visible = false;
        loadClaims(Helper.gridSize(), 1);
    }

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