/// <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(); } }
private void btnClockIn_Click(object sender, EventArgs e) { if (cmbShift.SelectedIndex == -1) { return; } if (chbxForceShift.Checked) { DateTime date = dtpDate.Value.Date; int shifttype = (cmbShift.SelectedItem as ComboboxItem).Value; ShiftTime shifttime = new ShiftTime(); switch (shifttype) { case 0: shifttime = ShiftTime.Morning; break; case 1: shifttime = ShiftTime.Afternoon; break; case 2: shifttime = ShiftTime.Evening; break; } Shift shift = shiftStorage.Get(date, shifttime); if (shift == null) { // shift does not exist shift = new Shift(0, date, shifttime, 1); shiftStorage.Create(shift); shift = shiftStorage.Get(date, shifttime); } // check if a department is selected if (cmbxDepartment.SelectedIndex == -1) { MessageBox.Show("Please select a department!"); return; } int depid = (cmbxDepartment.SelectedItem as ComboboxItem).Value; shiftStorage.Assign(shift.Id, this.userid, depid); string dateclockin = dtpClockIn.Value.ToString("yyyy-MM-dd hh:mm:ss"); shiftStorage.CreateAttendance(this.userid, shift.Id, dateclockin); MessageBox.Show("Succesfully clocked in! Tip: in order to have minutes worked you have to clock out"); } else { // modify an existing shift int shiftid = (cmbShift.SelectedItem as ComboboxItem).Value; string dateclockin = dtpClockIn.Value.ToString("yyyy-MM-dd hh:mm:ss"); int attendenceid = shiftStorage.CheckAttendance(this.userid, shiftid); if (attendenceid != 0) { shiftStorage.ModifyClockInAttendance(attendenceid, dateclockin); } else { shiftStorage.CreateAttendance(this.userid, shiftid, dateclockin); } MessageBox.Show("Succesfully clocked in! Tip: in order to have minutes worked you have to clock out"); } cmbxDepartment.Items.Clear(); lblDepartment.Visible = false; cmbxDepartment.Visible = false; chbxForceShift.Checked = false; }