private void Button2_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-AQUQBDR\SQLEXPRESS;Initial Catalog=AttendanceProtDb;Integrated Security=True"); SqlDataAdapter sda = new SqlDataAdapter("Sp_Login", conn); sda.SelectCommand.Parameters.AddWithValue("@username", txt_username.Text); sda.SelectCommand.Parameters.AddWithValue("@userpass", txt_password.Text); sda.SelectCommand.CommandType = CommandType.StoredProcedure; DataTable dt = new System.Data.DataTable(); gettersetter set_ID = new gettersetter(); sda.Fill(dt); if (dt.Rows.Count == 1) { set_ID.setEmp_ID(Convert.ToInt32(dt.Rows[0][1].ToString())); switch (dt.Rows[0][0].ToString()) { case "1": { this.Hide(); Form4 f4 = new Form4(); f4.Show(); break; } case "2": { conn.Open(); SqlCommand Comm2 = new SqlCommand("sp_timecon", conn); Comm2.Parameters.AddWithValue("@username", txt_username.Text); Comm2.CommandType = CommandType.StoredProcedure; SqlDataReader DR1 = Comm2.ExecuteReader(); if (DR1.Read()) { EmpID = Convert.ToInt32(DR1[0]); Emprate = Convert.ToInt32(DR1[1]); } this.Hide(); Form3 f3 = new Form3(); f3.Show(); conn.Close(); break; } default: { // ... handle unexpected roles here... break; } } } else { MessageBox.Show("Wrong Username or Password"); } }
private void Profile_Load(object sender, EventArgs e) { gettersetter setter_profile = new gettersetter(); Conn.Open(); SqlCommand Comm1 = new SqlCommand("Sp_Select_EmpInfo", Conn); Comm1.Parameters.AddWithValue("@p_EmpID", setter_profile.getEmp_ID()); Comm1.CommandType = CommandType.StoredProcedure; SqlDataReader DR1 = Comm1.ExecuteReader(); while (DR1.Read()) { text_ID.Text = DR1["Emp_ID"].ToString(); text_Fname.Text = DR1["FirstName"].ToString(); text_Lname.Text = DR1["LastName"].ToString(); text_Age.Text = DR1["Age"].ToString(); text_Bdate.Text = DR1["Birthdate"].ToString(); text_Address.Text = DR1["Emp_Address"].ToString(); sampleAge.Text = DR1["Age"].ToString(); } }
public void EmpRefresh() { gettersetter setter_profile = new gettersetter(); Conn.Open(); SqlDataAdapter Comm1 = new SqlDataAdapter("sp_Emp_Read", Conn); Comm1.SelectCommand.Parameters.AddWithValue("@Emp_ID", setter_profile.getEmp_ID()); Comm1.SelectCommand.CommandType = CommandType.StoredProcedure; DataTable dt = new DataTable(); Comm1.Fill(dt); label1ID.DataBindings.Clear(); labelFname.DataBindings.Clear(); labelLName.DataBindings.Clear(); label1Age.DataBindings.Clear(); label1Bdate.DataBindings.Clear(); label1Address.DataBindings.Clear(); label1username.DataBindings.Clear(); label1userpass.DataBindings.Clear(); label_ERate.DataBindings.Clear(); label1ID.DataBindings.Add("Text", dt, "Emp_ID"); labelFname.DataBindings.Add("Text", dt, "FirstName"); labelLName.DataBindings.Add("Text", dt, "LastName"); label1Age.DataBindings.Add("Text", dt, "Age"); label1Bdate.DataBindings.Add("Text", dt, "Birthdate"); label1Address.DataBindings.Add("Text", dt, "Emp_Address"); label1username.DataBindings.Add("Text", dt, "username"); label1userpass.DataBindings.Add("Text", dt, "userpass"); label_ERate.DataBindings.Add("Text", dt, "Emp_Rate"); dataRepeater1.DataSource = dt; Conn.Close(); }