/// <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;
        }
コード例 #2
0
        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;
        }