private void btnLogin_Click(object sender, EventArgs e) { if (Login_ID.Text == "") { MessageBox.Show("Please Enter the User ID"); return; } if (Password.Text == "") { MessageBox.Show("The Password is Not Valid"); return; } try { con = new SqlConnection(GlobalClass.conn); con.Open(); SqlDataAdapter adp = new SqlDataAdapter("Select * from EmployeeDetails", con); DataSet ds = new DataSet(); adp.Fill(ds, "EmployeeDetails"); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if ((dr["EmpID"].ToString() == Login_ID.Text) && (dr["Password"].ToString() == Password.Text) && (dr["Department"].ToString() == "HR")) { i = 1; break; } else { continue; } } } if (i == 1) { if (Login_ID.Text == "HR001") { GlobalClass.EmpID = "admin"; } HRDepartment hrd = new HRDepartment(); GlobalClass.hrd = hrd; GlobalClass.hrd.Show(); this.Hide(); } else { MessageBox.Show("Provided information do not match with database.\nPlease check your data"); } } catch (Exception ex) { MessageBox.Show("Provided information do not match with database.\nPlease check your data"); } }
private void btnLogin_Click(object sender, EventArgs e) { if (Login_ID.Text == "") { MessageBox.Show("Please Enter the User ID"); return; } if (Password.Text == "") { MessageBox.Show("The Password is Not Valid"); return; } try { con = new SqlConnection(GlobalClass.conn); con.Open(); SqlDataAdapter adp = new SqlDataAdapter("Select * from EmployeeDetails", con); DataSet ds = new DataSet(); adp.Fill(ds, "EmployeeDetails"); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if ((dr["EmpID"].ToString() == Login_ID.Text) && (dr["Password"].ToString() == Password.Text) && (dr["Department"].ToString() == "HR")) { i = 1; break; } else { continue; } } } if (i == 1) { if (Login_ID.Text == "HR001") { GlobalClass.EmpID = "admin"; } HRDepartment hrd = new HRDepartment(); GlobalClass.hrd = hrd; GlobalClass.hrd.Show(); this.Hide(); } else { MessageBox.Show("Provided information do not match with database.\nPlease check your data"); } } catch (Exception ex) { MessageBox.Show("Provided information do not match with database.\nPlease check your data"); } }