private void DoSearch() { Cursor = Cursors.WaitCursor; DateTime startDate = dateSearchFrom.Value.Date.AddDays(-1); //Text on boxes is To/From. This will effecitvely make it the 'afterDate'. DateTime endDate = dateSearchTo.Value.Date.AddDays(1); _listOpenings.Clear(); #region validation if (startDate.Year < 1880 || endDate.Year < 1880) { Cursor = Cursors.Default; MsgBox.Show(this, "Invalid date selection."); return; } TimeSpan beforeTime = new TimeSpan(0); if (textBefore.Text != "") { try { beforeTime = GetBeforeAfterTime(textBefore.Text, radioBeforePM.Checked); } catch { Cursor = Cursors.Default; MsgBox.Show(this, "Invalid 'Starting before' time."); return; } } TimeSpan afterTime = new TimeSpan(0); if (textAfter.Text != "") { try { afterTime = GetBeforeAfterTime(textAfter.Text, radioAfterPM.Checked); } catch { Cursor = Cursors.Default; MsgBox.Show(this, "Invalid 'Starting after' time."); return; } } if (comboBoxMultiProv.SelectedTags <Provider>().Contains(null) && comboBlockout.GetSelectedDefNum() == 0) { Cursor = Cursors.Default; MsgBox.Show(this, "Please pick a provider or a blockout type."); return; } #endregion //get lists of info to do the search List <long> listOpNums = new List <long>(); List <long> listClinicNums = new List <long>(); List <long> listProvNums = new List <long>(); long blockoutType = 0; if (comboBlockout.GetSelectedDefNum() != 0) { blockoutType = comboBlockout.GetSelectedDefNum(); listProvNums.Add(0); //providers don't matter for blockouts } if (!comboBoxMultiProv.SelectedTags <Provider>().Contains(null)) { foreach (ODBoxItem <Provider> provBoxItem in comboBoxMultiProv.ListSelectedItems) { listProvNums.Add(provBoxItem.Tag.ProvNum); } } if (PrefC.HasClinicsEnabled) { if (comboBoxClinic.SelectedClinicNum != 0) { listClinicNums.Add(comboBoxClinic.SelectedClinicNum); listOpNums = Operatories.GetOpsForClinic(comboBoxClinic.SelectedClinicNum).Select(x => x.OperatoryNum).ToList(); } else //HQ //and unassigned (which is clinic num 0) { long apptViewNum = comboApptView.GetSelected <ApptView>().ApptViewNum; //get the disctinct clinic nums for the operatories in the current appointment view List <long> listOpsForView = ApptViewItems.GetOpsForView(apptViewNum); List <Operatory> listOperatories = Operatories.GetOperatories(listOpsForView, true); listClinicNums = listOperatories.Select(x => x.ClinicNum).Distinct().ToList(); listOpNums = listOperatories.Select(x => x.OperatoryNum).ToList(); } } else //no clinics { listOpNums = Operatories.GetDeepCopy(true).Select(x => x.OperatoryNum).ToList(); } if (blockoutType != 0 && listProvNums.Max() > 0) { _listOpenings.AddRange(ApptSearch.GetSearchResultsForBlockoutAndProvider(listProvNums, _appt.AptNum, startDate, endDate, listOpNums, listClinicNums , beforeTime, afterTime, blockoutType, 15)); } else { _listOpenings = ApptSearch.GetSearchResults(_appt.AptNum, startDate, endDate, listProvNums, listOpNums, listClinicNums , beforeTime, afterTime, blockoutType, resultCount: 15); } Cursor = Cursors.Default; FillGrid(); }