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."); } } } } } }
//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."); } } } } } }