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_ClaimHistory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadStatus();
            rdATM_CheckedChanged(sender, e);
            //loadClaims(Helper.gridSize(), 1);
        }
    }

    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 btnSearch_Click(object sender, EventArgs e)
    {
        txtClaimID.Text = txtClaimID.Text.Trim();
        txtReference.Text = txtReference.Text.Trim();
        txtCardNumber.Text = txtCardNumber.Text.Trim();

        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_history.get_claim_history";

        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_claim_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("c_claim_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_out_claim_hist", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;


        oracom.Parameters["c_claim_id"].Value    = txtClaimID.Text;
        oracom.Parameters["c_card_number"].Value = txtCardNumber.Text;
        oracom.Parameters["c_claim_date"].Value = dtTranDate.date;

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




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

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