using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class rto_IssuingofLearinglicence : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["babu1"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != string.Empty)
        {
            if (!Page.IsPostBack)
            {
                BindDropDownList3();
                BindDropDownList4();
            }
        }
            else
            {
                Response.Redirect("~/HOME/EMPLOYEES.aspx");
            }

        }
    private void BindDropDownList3()
    {
        SqlCommand cmd = new SqlCommand("select * from llrdetails ",con);
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        da.SelectCommand = cmd;
        cmd.Connection = con;
        da.Fill(ds);
        DropDownList3.DataSource = ds.Tables[0];
        DropDownList3.DataTextField = "name";
        DropDownList3.DataValueField = "llrno";
        DropDownList3.DataBind();
    }
    private void BindDropDownList4()
    {
        SqlCommand cmd = new SqlCommand("select * from result where result='Pass' ", con);
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        da.SelectCommand = cmd;
        cmd.Connection = con;
        da.Fill(ds);
        DropDownList4.DataSource = ds.Tables[0];
        DropDownList4.DataTextField = "aname";
        DropDownList4.DataValueField = "examno";
        DropDownList4.DataBind();
    }

   

    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridView3.Visible = false;
        GridView2.Visible = true ;
        if (DropDownList3.SelectedItem.Text !="--SELECT--")
        {
            try
            {
                // Create Instance of Connection and Command Object                 
                SqlCommand myCommand = new SqlCommand("select * from llrdetails where llrno='" + DropDownList3.SelectedValue + "'", con);
                SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
                DataSet myDataSet = new DataSet();
                myAdapter.SelectCommand = myCommand;
                myCommand.Connection = con;
                myAdapter.Fill(myDataSet);
                GridView2.DataSource = myDataSet;
                GridView2.DataBind();

                TextBox1.Text = myDataSet.Tables[0].Rows[0][1].ToString();
                //TextBox2.Text = myDataSet.Tables[0].Rows[0][6].ToString();
                TextBox3.Text = myDataSet.Tables[0].Rows[0][3].ToString();
                TextBox4.Text = myDataSet.Tables[0].Rows[0][4].ToString();
                TextBox5.Text = myDataSet.Tables[0].Rows[0][5].ToString();
                TextBox6.Text = myDataSet.Tables[0].Rows[0][6].ToString();
                TextBox7.Text = myDataSet.Tables[0].Rows[0][7].ToString();
                TextBox9.Text = myDataSet.Tables[0].Rows[0][9].ToString();
                TextBox11.Text = myDataSet.Tables[0].Rows[0][11].ToString();
                TextBox12.Text = myDataSet.Tables[0].Rows[0][12].ToString();
                TextBox13.Text = myDataSet.Tables[0].Rows[0][13].ToString();
                TextBox14.Text = myDataSet.Tables[0].Rows[0][14].ToString();

            }
            catch (SqlException SQLexc)
            {
                Response.Write("Data Retrival Failure. Error Details : " + SQLexc.ToString());
            }
        }
        else
        {
        }
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox15.Text != string.Empty)
        {
            SqlCommand cmd = new SqlCommand("insert into issuedllr (llr1,cha1,llr,name,validity,issu,issuby)values('" + DropDownList3.SelectedItem.Text + "','" + DropDownList4.SelectedItem.Text + "','" + TextBox1.Text + "','" + TextBox3.Text + "','" + TextBox14.Text + "','" + DropDownList2.SelectedItem.Text + "','" + TextBox15.Text + "') ", con);
            cmd.Connection = con;
            con.Open();
            int result = cmd.ExecuteNonQuery();
            if (result > 0)
            {
                Page.RegisterStartupScript("xyz", "<script>alert('Successfully Inserted')</script>");
            }
            else
            {
                Page.RegisterStartupScript("xyz", "<script>alert('Failed to Insert')</script>");
            }
        }
        else
        {
        }
    }
  
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridView2.Visible = false;
        GridView3.Visible = true;
        
            try
            {
                
                SqlCommand myCommand = new SqlCommand("select * from applyllr where name='" + DropDownList4.SelectedItem.Text+"' " , con);
                SqlDataAdapter myAdapter = new SqlDataAdapter();
                DataSet myDataSet = new DataSet();                
                myAdapter.SelectCommand = myCommand;
                myCommand.Connection = con;
                myAdapter.Fill(myDataSet);
                GridView3.DataSource = myDataSet;
                GridView3.DataBind();
                //TextBox1.Text = myDataSet.Tables[0].Rows[0][4].ToString();
                //TextBox2.Text = myDataSet.Tables[0].Rows[0][6].ToString();
                TextBox3.Text = DropDownList4.SelectedValue.ToString();                
                
                TextBox5.Text = myDataSet.Tables[0].Rows[0]["dob"].ToString();
                TextBox6.Text = myDataSet.Tables[0].Rows[0]["bloodg"].ToString();
                TextBox7.Text = myDataSet.Tables[0].Rows[0]["add1"].ToString();
                TextBox9.Text = myDataSet.Tables[0].Rows[0]["city"].ToString();
                TextBox10.Text = myDataSet.Tables[0].Rows[0]["state"].ToString();
                TextBox11.Text = myDataSet.Tables[0].Rows[0]["phno"].ToString();
                TextBox12.Text = myDataSet.Tables[0].Rows[0]["ident"].ToString();
                //TextBox13.Text = myDataSet.Tables[0].Rows[0][4].ToString();

               // TextBox16.Text = myDataSet.Tables[0].Rows[0][12].ToString();
                //TextBox11.Text = myDataSet.Tables[0].Rows[0][13].ToString();
                //TextBox12.Text = myDataSet.Tables[0].Rows[0][14].ToString();
                //TextBox13.Text = myDataSet.Tables[0].Rows[0][15].ToString();
                //TextBox14.Text = myDataSet.Tables[0].Rows[0][16].ToString();
                //TextBox16.Text = myDataSet.Tables[0].Rows[0][17].ToString();
                //TextBox16.Text = myDataSet.Tables[0].Rows[0][9].ToString();
                //TextBox9.Text = myDataSet.Tables[0].Rows[0][16].ToString();
                //TextBox10.Text = myDataSet.Tables[0].Rows[0][17].ToString();

            }

            catch (SqlException SQLexc)
            {
                Response.Write("Data Retrival Failure. Error Details : " + SQLexc.ToString());
            }        
    }
    
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox9.Text = "";
        TextBox10.Text = "";
        TextBox11.Text = "";
        TextBox12.Text = "";
        TextBox13.Text = "";
        TextBox14.Text = "";
       
        


    }

    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

