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

public partial class UserControls_LOV : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Div.Visible = true;
        ViewState["cn"] = txtCardNo.Text;

        loadCards(ViewState["cn"].ToString());
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        Div.Visible = false;
    }

    private void loadCards(string cardNo)
    {
        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_card_numbers";

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


        oracom.Parameters["p_card_no"].Value = cardNo;

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

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

        oracon.Close();
    }

    protected void gvCards_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("s"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string cardNo = gvCards.DataKeys[index].Value.ToString();

            txtCardNo.Text = cardNo;
            Div.Visible = false;
        }
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvCards.PageIndex = e.NewPageIndex;
        loadCards(ViewState["cn"].ToString());
    }

    public string getSelectedCardNumber()
    {
        return this.txtCardNo.Text;
    }
}