Пример #1
0
        private void listViewDay_MouseDown(object sender, MouseEventArgs e)
        {
            var info = listViewDay.HitTest(e.X, e.Y);

            if (info.Item != null)
            {
                var row = info.Item.Index;
                var col = info.Item.SubItems.IndexOf(info.SubItem);
                if (info.SubItem != null)
                {
                    var value = info.Item.SubItems[col].Text;
                    if (col > 0 && col < instructorsUserNames.Count + 1 && row < timesOfDate.Count)
                    {
                        if (value == "0")
                        {
                            if (DBData.checkExistingsStlots(DateTime.Parse(labelDate.Text), listViewDay.Items[row].Text))
                            {
                                int weekHours    = DBData.getHoursAssignedPerWeek(firstDayOfWeek, lastDayOfWeek, listViewDay.Columns[col].Text);
                                int DayHours     = DBData.getHoursAssignedPerDay(DateTime.Parse(labelDate.Text), listViewDay.Columns[col].Text);
                                int newDayHours  = int.Parse(listViewDay.Items[listViewDay.Items.Count - 1].SubItems[col].Text) + 1;
                                int newWeekHours = weekHours - DayHours + newDayHours;
                                if (int.Parse(listViewDay.Items[listViewDay.Items.Count - 1].SubItems[col].Text) < 8 && newWeekHours <= 40)
                                {
                                    ControlFunctions.changeListViewSubItemValue(listViewDay, row, col, "1");
                                    ControlFunctions.recalculateTotal(listViewDay, row, col, 1);
                                }
                                else
                                {
                                    MessageBox.Show("You cannot assign more than 8hours/day and 40hours/week.");
                                }
                            }
                            else
                            {
                                MessageBox.Show("There are no slots available for that Date and Time. Please select another one.");
                            }
                        }
                        else
                        {
                            if (DBData.checkAppointmentOccupiedByClient(labelDate.Text, listViewDay.Items[row].Text, instructorsUserNames[col - 1]))
                            {
                                ControlFunctions.changeListViewSubItemValue(listViewDay, row, col, "0");
                                ControlFunctions.recalculateTotal(listViewDay, row, col, 0);
                            }
                            else
                            {
                                MessageBox.Show("That Slot cannot be changed because there is already an Appointment with a Client.");
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        //It obtains the slot clicked and activates or desactivates it
        private void listViewWeek_MouseDown(object sender, MouseEventArgs e)
        {
            var info = listViewWeek.HitTest(e.X, e.Y);

            if (info.Item != null)
            {
                var row = info.Item.Index;
                var col = info.Item.SubItems.IndexOf(info.SubItem);
                if (info.SubItem != null)
                {
                    var value = info.Item.SubItems[col].Text;
                    if (col > 0 && col < daysOfWeek + 1 && row < timesOfDate.Count - 1)
                    {
                        if (value == "0")
                        {
                            //It checks that there are Slots available for the Instructor to assign his availability
                            if (DBData.checkExistingsStlots(DateTime.Parse(listViewWeek.Columns[col].Text), listViewWeek.Items[row].Text))
                            {
                                //It checks that the Instructor has not selected more than 8 hours per Day and 40 per Week
                                if (int.Parse(listViewWeek.Items[listViewWeek.Items.Count - 1].SubItems[col].Text) < 8 && int.Parse(listViewWeek.Items[listViewWeek.Items.Count - 1].SubItems[listViewWeek.Columns.Count - 1].Text) < 40)
                                {
                                    ControlFunctions.changeListViewSubItemValue(listViewWeek, row, col, "1");
                                    ControlFunctions.recalculateTotal(listViewWeek, row, col, 1);
                                }
                                else
                                {
                                    MessageBox.Show("You cannot assign more than 8hours/day and 40hours/week.");
                                }
                            }
                            else
                            {
                                MessageBox.Show("There are no slots available for that Date and Time. Please select another one.");
                            }
                        }
                        else
                        {
                            //It checks if the Appointment is already booked by a Client
                            if (DBData.checkAppointmentConfirmedByAdmin(listViewWeek.Columns[col].Text, listViewWeek.Items[row].Text, instructorUserName))
                            {
                                ControlFunctions.changeListViewSubItemValue(listViewWeek, row, col, "0");
                                ControlFunctions.recalculateTotal(listViewWeek, row, col, 0);
                            }
                            else
                            {
                                MessageBox.Show("That Slot cannot be changed because it was confirmed by the Administrator.");
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        //It obtains the desired Appointment from the ListView
        private void listViewAppointmentSelection_MouseDown(object sender, MouseEventArgs e)
        {
            var info = listViewAppointmentSelection.HitTest(e.X, e.Y);

            if (info.Item != null)
            {
                var row = info.Item.Index;
                var col = info.Item.SubItems.IndexOf(info.SubItem);
                if (info.SubItem != null)
                {
                    var value = info.Item.SubItems[col].Text;
                    if (col > 0)
                    {
                        switch (value)
                        {
                        case slotAvailable:
                            appointmentTime = listViewAppointmentSelection.Items[row].Text;
                            instructor      = listViewAppointmentSelection.Columns[col].Text;
                            if (checkAppointmentDuplicity())
                            {
                                MessageBox.Show("There is already an Appointment that day at that time with another Instructor. Please delete the Appointment first.");
                            }
                            else
                            {
                                if (checkReservationDuplicity())
                                {
                                    MessageBox.Show("You cannot book two Appointments at once. Click in other reserved Appointment to free it first.");
                                }
                                else
                                {
                                    ControlFunctions.changeListViewSubItemValue(listViewAppointmentSelection, row, col, slotReserved);
                                    labelAppointmentSelected.Text = $"{selectedDate.ToString("d")} at {appointmentTime} with {instructor}";
                                }
                            }
                            break;

                        case slotReserved:
                            appointmentTime = "";
                            instructor      = "";
                            ControlFunctions.changeListViewSubItemValue(listViewAppointmentSelection, row, col, slotAvailable);
                            labelAppointmentSelected.Text = "No appointment selected";
                            break;
                        }
                    }
                }
            }
        }