public ChapeauModel.Employee LoginCheck(string username, string password) { ChapeauDAL dal = new ChapeauDAL(); ChapeauModel.Employee employee = dal.LoginDAO(username, password); return(employee); }
public ChapeauModel.Employee loginUI(string username, string password) { LoginLogic logic = new LoginLogic(); ChapeauModel.Employee employee = logic.LoginCheck(username, password); return(employee); }
public ChapeauModel.Employee LoginDAO(string username, string password) { ChapeauModel.Employee loginTry = null; SqlConnection conn = OpenConnDB(); string query = $"SELECT EmployeeId, Username, Password, JobRole, Firstname, Lastname " + $"FROM Employee " + $"WHERE Username = @username AND Password = @password"; SqlCommand command = new SqlCommand(query, conn); command.Parameters.AddWithValue("@username", username); //this is to prevent sql injection!! command.Parameters.AddWithValue("@password", password); SqlDataReader reader = command.ExecuteReader(); ChapeauModel.Employee LoginEmployee = null; if (reader.Read()) { // dit zou je in een methode kunnen stoppen om weer opnieuw te gebruiken (geef reader mee als parameter), voor bijvoorbeeld het ophalen van een lijst. int employeeId = reader.GetInt32(0); string loginUsername = reader.GetString(1); string loginPassword = reader.GetString(2); JobRole role = (JobRole)reader.GetInt32(3); string firstname = reader.GetString(4); string lastname = reader.GetString(5); LoginEmployee = new ChapeauModel.Employee(employeeId, firstname, lastname, loginPassword, role, loginUsername); } conn.Close(); return(LoginEmployee); }
private void btn_login_Click(object sender, EventArgs e) { string username = txtbox_username.Text; string password = txtbox_password.Text; LoginLogic logic = new LoginLogic(); ChapeauModel.Employee employee = logic.LoginCheck(username, password); if (employee == null) { MessageBox.Show("Please enter a valid username and/or password"); txtbox_password.Text = string.Empty; } else { switch (employee.Role) { case JobRole.Bar: MessageBox.Show("Bar login successfull"); //employee en login form meepassen of een showDialog gebruiken! break; case JobRole.Kitchen: MessageBox.Show("Kitchen login successfull"); break; case JobRole.Manager: MessageBox.Show("Manager login successfull"); break; case JobRole.Wait: MessageBox.Show("Waiter login successfull"); // LoginForm.Hide(); break; } } }
public List <ChapeauModel.Employee> EmployeeDAO() //Made by Machelle { SqlConnection conn = OpenConnDB(); List <ChapeauModel.Employee> employee_list = new List <ChapeauModel.Employee>(); StringBuilder sb = new StringBuilder(); sb.Append("SELECT EmployeeId, Firstname, Lastname, Password, JobRole, Username FROM Employee"); String sql = sb.ToString(); SqlCommand command = new SqlCommand(sql, conn); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ChapeauModel.Employee employee = new ChapeauModel.Employee(Int32.Parse(reader["EmployeeId"].ToString()), reader["Firstname"].ToString(), reader["Lastname"].ToString(), reader["Password"].ToString(), (JobRole)reader["JobRole"], reader["Username"].ToString()); employee_list.Add(employee); } CloseConnDB(conn); return(employee_list); }