/// <summary> /// Shows the correct shift upon execution. /// </summary> /// <param name="time"></param> private void ShowShift(ShiftTime time) { // Refreshes the shift data from the shiftStorage shiftEmployees.Clear(); shiftStorage = new ShiftMySQL(); newShift = shiftStorage.Get(date, time); //Department currentSelectedDepartment = currentSelectedDepartment(); // If a shift exists, show it. Else create a new one if (newShift != null) { shiftEmployees = shiftStorage.GetEmployees(newShift.Id); schedule = new SchedulingWindow(labelCalendarDate.Text, labelCalendarDay.Text, time, date, shiftEmployees, true, newShift.Id, newShift.Capacity, allEmployees, currentSelectedDepartment, loggedInUser); } else { schedule = new SchedulingWindow(labelCalendarDate.Text, labelCalendarDay.Text, time, date, shiftEmployees, false, 0, 0, allEmployees, currentSelectedDepartment, loggedInUser); } // Show a dialog for the shift if (schedule.ShowDialog() == DialogResult.OK) { ReloadCalendarDayEvent?.Invoke(); ReloadEmployeeHoursEvent?.Invoke(); } }
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; } } }
/// <summary> /// Logic for the confirm button. Adds each employee in the scheduled listbox to the shift in the shiftStorage. /// </summary> private void Confirm() { // Makes sure everything is set up correctly. shiftStorage = new ShiftMySQL(); workingEmployeeIds = new List <int>(); int capacityNew = Convert.ToInt32(numericUpDownCapacity.Value); int shiftId = 0; // Checks if the shift is in editing mode and chooses whether to edit or create a shift in the shiftStorage if (isEditing) { // Creates a new shift object and sets the list of employeeIds to the one we just created. currentShift = new Shift(oldId, date, shiftTime, capacityNew); // Removes all information about the shift in the shiftStorage to prevent duplication of entries shiftStorage.Clear(oldId); shiftId = oldId; foreach (dynamic depDynamic in comboBoxSelectDepartments.Items) { Department dep = (depDynamic).Department; if (departmentCapacity.ContainsKey(dep.Id)) { shiftStorage.UpdateCapacityPerDepartment(shiftId, dep.Id, dep.Capacity); } else { shiftStorage.AddCapacityForDepartment(shiftId, dep.Id, dep.Capacity); } } } else { // Creates a new shift object and sets the list of employeeIds to the one we just created. currentShift = new Shift(0, date, shiftTime, capacityNew); shiftId = shiftStorage.Create(currentShift); foreach (dynamic depDynamic in comboBoxSelectDepartments.Items) { Department dep = (depDynamic).Department; shiftStorage.AddCapacityForDepartment(shiftId, dep.Id, dep.Capacity); } } foreach (dynamic depDynamic in comboBoxSelectDepartments.Items) { Department dep = (depDynamic).Department; // Makes a list of all ids of the employees scheduled for that shift foreach (Employee emp in dep.Employees) { //workingEmployeeIds.Add(emp.Id); shiftStorage.Assign(shiftId, emp.Id, dep.Id); } } this.DialogResult = DialogResult.OK; }
/// <summary> /// Loads all of the capacities per department from the database. /// </summary> /// <param name="weekShifts">A list of all of the shifts in this week</param> private void LoadAllCapacities(List <Shift> weekShifts) { shiftStorage = new ShiftMySQL(); Dictionary <int, Dictionary <int, int> > weekDepartments = new Dictionary <int, Dictionary <int, int> >(); foreach (Shift s in weekShifts) { Dictionary <int, int> temp = shiftStorage.GetCapacityPerDepartment(s.Id); if (temp.Count() > 0) { weekDepartments.Add(s.Id, temp); this.initialShiftIds.Add(s.Id); } } this.allDepartmentCapacityInWeek = weekDepartments; }
// 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; } } } }