private void butOK_Click(object sender, System.EventArgs e) { #region Validation DateTime startDateT = DateTime.MinValue; DateTime stopDateT = DateTime.MinValue; if (!_isHolidayOrNote) { if (listOps.SelectedIndices.Count == 0) { MsgBox.Show(this, "Please select ops first."); return; } if (listOps.SelectedIndices.Count > 1 && listOps.SelectedIndices.Contains(0)) { MsgBox.Show(this, "Invalid selection of ops."); return; } startDateT = PIn.DateT(comboStart.Text); stopDateT = PIn.DateT(comboStop.Text); if (startDateT == DateTime.MinValue || stopDateT == DateTime.MinValue) { MsgBox.Show(this, "Incorrect time format"); return; } if (startDateT > stopDateT) { MsgBox.Show(this, "Stop time must be later than start time."); return; } List <long> listSelectedOps = new List <long>(); List <Schedule> listProvSchedsOnly = ListScheds.FindAll(x => x.SchedType == ScheduleType.Provider); if (!listOps.SelectedIndices.Contains(0)) //add selected operatories into listSelectedOps { listSelectedOps = listOps.SelectedIndices.OfType <int>().Select(x => _listOps[x - 1].OperatoryNum).ToList(); } SchedCur.Ops = listSelectedOps.ToList(); //deep copy of list. (because it is value type.) SchedCur.StartTime = startDateT.TimeOfDay; SchedCur.StopTime = stopDateT.TimeOfDay; List <long> listProvsOverlap; //====================Pre-Emptive Overlaps==================== //Because this window is explicitly designed for one start and one stop time we know that there will be overlapping if multiple providers are //selected with at least one specific operatory selected. if (ListProvNums.Count > 1 && listSelectedOps.Count > 0) { listProvsOverlap = ListProvNums.Distinct().ToList(); } else //Go see if there is going to be overlapping issues with this new schedule. { listProvsOverlap = Schedules.GetOverlappingSchedProvNums(ListProvNums, SchedCur, listProvSchedsOnly, listSelectedOps); } if (listProvsOverlap.Count > 0 && MessageBox.Show(Lan.g(this, "Overlapping provider schedules detected, would you like to continue anyway?") + "\r\n" + Lan.g(this, "Providers affected") + ":\r\n " + string.Join("\r\n ", listProvsOverlap.Select(x => Providers.GetLongDesc(x))), "", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } else if (SchedCur.Status != SchedStatus.Holiday && textNote.Text == "") //don't allow blank schedule notes { MsgBox.Show(this, "Please enter a note first."); return; } long clinicNum = 0; if (_isHolidayOrNote && SchedCur.SchedType == ScheduleType.Practice && PrefC.HasClinicsEnabled) //prov notes do not have a clinic { int indexCur = comboClinic.SelectedIndex; if (!Security.CurUser.ClinicIsRestricted) //user isn't restricted, -1 for HQ { indexCur--; } if (indexCur > -1) //will be -1 if HQ is selected, leave clinicNum=0 { clinicNum = _listClinics[indexCur].ClinicNum; } if (SchedCur.Status == SchedStatus.Holiday) //duplicate holiday check { List <Schedule> listScheds = ListScheds.FindAll(x => x.SchedType == ScheduleType.Practice && x.Status == SchedStatus.Holiday); //scheds in local list listScheds.AddRange(Schedules.GetAllForDateAndType(SchedCur.SchedDate, ScheduleType.Practice) .FindAll(x => x.ScheduleNum != SchedCur.ScheduleNum && x.Status == SchedStatus.Holiday && listScheds.All(y => y.ScheduleNum != x.ScheduleNum))); //add any in db that aren't in local list if (listScheds.Any(x => x.ClinicNum == 0 || x.ClinicNum == clinicNum) || //already a holiday for HQ in db or duplicate holiday for a clinic (clinicNum == 0 && listScheds.Count > 0)) //OR trying to create a HQ holiday when a clinic already has one for this day { MsgBox.Show(this, "There is already a Holiday for the practice or clinic on this date."); return; } } } #endregion Validation #region Set Schedule Fields SchedCur.Note = textNote.Text; SchedCur.Ops = new List <long>(); if (listOps.SelectedIndices.Count > 0 && !listOps.SelectedIndices.Contains(0)) { listOps.SelectedIndices.OfType <int>().ToList().ForEach(x => SchedCur.Ops.Add(_listOps[x - 1].OperatoryNum)); } SchedCur.ClinicNum = clinicNum; //0 if HQ selected or clinics not enabled or not a holiday or practice note #endregion Set Schedule Fields DialogResult = DialogResult.OK; }