private void btn_SelectInstructor_Click(object sender, EventArgs e) { int id = Convert.ToInt32(cmb_SearchInstructor.Text); // MessageBox.Show(id.ToString()); ViewInstructorInfo vIIForm = new ViewInstructorInfo(id); vIIForm.ShowDialog(); }
private void btn_login_Click(object sender, EventArgs e) { con = new SqlConnection(ConfigurationManager.ConnectionStrings["SIMS2.Properties.Settings.Database1_ConnectionString"].ConnectionString); adp = new SqlDataAdapter(); ds = new DataSet(); if (cmb_loginType.SelectedIndex == 1) { //student adp.SelectCommand = new SqlCommand("select studentId, password from Student", con); adp.Fill(ds, "myData"); dt = ds.Tables["myData"]; // dr = dt.Rows[0]; dg.DataSource = ds.Tables["mydata"]; int auth_flag = 0; foreach (DataRow dr in dt.Rows) { string password = dr["password"].ToString(); string Id = dr["studentId"].ToString(); //removing spaces so the if condition works password = password.Replace(" ", String.Empty); Id = Id.Replace(" ", String.Empty); if (Id == tb_username.Text && tb_password.Text == password) { this.Hide(); int id = Convert.ToInt32(Id); ViewStudentInfo vsfForm = new ViewStudentInfo(id, "student"); vsfForm.ShowDialog(); auth_flag = 1; break; } } if (auth_flag == 0) { MessageBox.Show("please try again", "login failed", MessageBoxButtons.OK); } } else if (cmb_loginType.SelectedIndex == 0) { //Instructor adp.SelectCommand = new SqlCommand("select instId,password from inst", con); adp.Fill(ds, "myData"); dt = ds.Tables["myData"]; // dr = dt.Rows[0]; dg.DataSource = ds.Tables["mydata"]; int auth_flag = 0; foreach (DataRow dr in dt.Rows) { string password = dr["password"].ToString(); string Id = dr["instId"].ToString(); //removing spaces so the if condition works password = password.Replace(" ", String.Empty); Id = Id.Replace(" ", String.Empty); if (Id == tb_username.Text && tb_password.Text == password) { this.Hide(); int id = Convert.ToInt32(Id); id = Convert.ToInt32(Id); ViewInstructorInfo vIIForm = new ViewInstructorInfo(id); vIIForm.ShowDialog(); auth_flag = 1; break; } } if (auth_flag == 0) { MessageBox.Show("please try again", "login failed", MessageBoxButtons.OK); } } else if (cmb_loginType.SelectedIndex == 2) { //Staff adp.SelectCommand = new SqlCommand("select id, password from staff", con); adp.Fill(ds, "myData"); dt = ds.Tables["myData"]; // dr = dt.Rows[0]; dg.DataSource = ds.Tables["mydata"]; int auth_flag = 0; foreach (DataRow dr in dt.Rows) { string password = dr["password"].ToString(); string Id = dr["Id"].ToString(); //removing spaces so the if conditin works password = password.Replace(" ", String.Empty); Id = Id.Replace(" ", String.Empty); if (Id == tb_username.Text && tb_password.Text == password) { this.Hide(); new Staff_Form().Show(); auth_flag = 1; break; } } if (auth_flag == 0) { MessageBox.Show("please try again", "login failed", MessageBoxButtons.OK); } } con.Close(); }