/** * Method to get staff */ public List <Staff> getStaffFromDB(Department dep) { MySqlConnection conn = new MySqlConnection(connString); conn.Open(); String sql = "SELECT * FROM person JOIN role ON person.RoleID = role.Id WHERE DepartmentID = @DepartmentID"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@DepartmentID", dep.DepartmentID); MySqlDataReader reader = cmd.ExecuteReader(); //List<Staff> result = new List<Staff>(); while (reader.Read()) { int ID = (int)reader.GetValue(0); String firstName = reader.GetString(1); String lastName = reader.GetString(2); DateTime birthDate = (DateTime)reader.GetValue(3); String address = reader.GetString(4); String email = reader.GetString(5); double salary = reader.GetDouble(7); int hoursavailable = (int)reader.GetValue(9); int dbContract = (int)reader.GetValue(14); //13 String role = reader.GetString(16); //16 Contract contract; if (dbContract == 1) { contract = Contract.FullTime; } else { contract = Contract.PartTime; } if (role == "Manager" || role == "Stock Manager") { Manager man = new Manager(ID, firstName, lastName, birthDate, address, salary, hoursavailable, email, contract); if (dep.GetStaffMember(man.FirstName, man.LastName) == null) { dep.AddStaffMember(man); } } else if (role == "Employee") { Employee emp = new Employee(ID, firstName, lastName, birthDate, address, salary, hoursavailable, email, contract); if (dep.GetStaffMember(emp.FirstName, emp.LastName) == null) { dep.AddStaffMember(emp); } } } reader.Close(); conn.Close(); return(dep.GetStaff()); }
private void getDepInfo() { lBoxDepartmentStats.Items.Clear(); int length = department.GetStaff().Count; lBoxDepartmentStats.Items.Add("# of employees and managers that are employed: " + length + " "); int empfullTime = 0; int empPartTime = 0; int manfullTime = 0; int manPartTime = 0; int managers = 0; foreach (Staff staff in department.GetStaff()) { if (staff is Employee) { if (staff.Contract == Contract.FullTime) { empfullTime++; } else if (staff.Contract == Contract.PartTime) { empPartTime++; } } else if (staff is Manager) { managers++; if (staff.Contract == Contract.FullTime) { manfullTime++; } else if (staff.Contract == Contract.PartTime) { manPartTime++; } } } lBoxDepartmentStats.Items.Add(manfullTime + empfullTime + " Fulltime workers."); lBoxDepartmentStats.Items.Add(manPartTime + empPartTime + " Parttime workers."); int dep = 0; for (int i = 0; i < department.GetSchedules().Count; i++) { if (department.GetSchedules()[i].DepartmentName == department.Name) { dep++; } } lBoxDepartmentStats.Items.Add("# of schedules related to this department: " + dep); lBoxDepartmentStats.Items.Add("# of managers: " + managers); }