public ClockInOutWindow(int id) { InitializeComponent(); lblDepartment.Visible = false; cmbxDepartment.Visible = false; dtpClockIn.Value = DateTime.Now; dtpClockOut.Value = DateTime.Now; this.userid = id; employeeStorage = new EmployeeMySQL(); shiftStorage = new ShiftMySQL(); departmentStorage = new DepartmentMySQL(); ComboboxItem ci = null; foreach (Employee e in employeeStorage.GetAll(true)) { ci = new ComboboxItem(); ci.Text = e.Id.ToString() + " - " + e.FirstName + " " + e.SurName; ci.Value = e.Id; cmbxEmployee.Items.Add(ci); if (e.Id == id) { cmbxEmployee.SelectedItem = ci; } } }
// Loads all of the department from the departmentStorage and sets them into the combobox private void LoadDepartments() { departmentStorage = new DepartmentMySQL(); shiftStorage = new ShiftMySQL(); allDepartments = departmentStorage.GetAll(); if (isEditing) { this.departmentCapacity = shiftStorage.GetCapacityPerDepartment(oldId); } foreach (Department d in allDepartments) { if (isEditing) { d.Employees = shiftStorage.GetDepartmentEmployees(oldId, d.Id); if (departmentCapacity.ContainsKey(d.Id)) { d.Capacity = departmentCapacity[d.Id]; } else { d.Capacity = 0; } } comboBoxSelectDepartments.DisplayMember = "Text"; comboBoxSelectDepartments.ValueMember = "Department"; comboBoxSelectDepartments.Items.Add(new { Text = d.Name, Department = d }); } if (previousSelectedDepartment != null) { foreach (dynamic depDynamic in comboBoxSelectDepartments.Items) { Department d = (depDynamic).Department; if (d.Name == previousSelectedDepartment.Name) { comboBoxSelectDepartments.SelectedItem = depDynamic; numericUpDownCapacity.Value = d.Capacity; break; } } } }
/// <summary> /// Loads all of the departments from the database. /// </summary> /// <param name="departmentId">ID of the currently selected department</param> private void LoadAllDepartments(int departmentId) { departmentStorage = new DepartmentMySQL(); allDepartments = departmentStorage.GetAll(); foreach (Department d in allDepartments) { comboBoxSelectDepartment.DisplayMember = "Text"; comboBoxSelectDepartment.ValueMember = "Department"; comboBoxSelectDepartment.Items.Add(new { Text = d.Name, Department = d }); } foreach (dynamic dynamicDep in comboBoxSelectDepartment.Items) { Department dep = dynamicDep.Department; if (dep.Id == departmentId) { comboBoxSelectDepartment.SelectedItem = dynamicDep; } } }
public DepartmentService(IDepartmentStorage departmentStorage) { this.departmentStorage = departmentStorage; }
/// <summary> /// Returns all of the departments from the database /// </summary> private List <Department> GetAllDepartments() { departmentStorage = new DepartmentMySQL(); return(departmentStorage.GetAll()); }