private void butOK_Click(object sender, System.EventArgs e) { if(listOp.SelectedIndices.Count==0){ MsgBox.Show(this,"Please select at least one operatory first."); return; } try{ SchedCur.StartTime=DateTime.Parse(comboStart.Text).TimeOfDay; SchedCur.StopTime=DateTime.Parse(comboStop.Text).TimeOfDay; } catch{ MsgBox.Show(this,"Incorrect time format"); return; } SchedCur.Note=textNote.Text; SchedCur.BlockoutType=DefC.Short[(int)DefCat.BlockoutTypes][listType.SelectedIndex].DefNum; SchedCur.Ops=new List<long>(); for(int i=0;i<listOp.SelectedIndices.Count;i++){ SchedCur.Ops.Add(OperatoryC.ListShort[listOp.SelectedIndices[i]].OperatoryNum); } try{ if(IsNew) { Schedules.Insert(SchedCur,true); } else { Schedules.Update(SchedCur); } } catch(Exception ex){ MessageBox.Show(ex.Message); return; } DialogResult=DialogResult.OK; }
private void butOK_Click(object sender, System.EventArgs e) { if (listOp.SelectedIndices.Count == 0) { MsgBox.Show(this, "Please select at least one operatory first."); return; } try{ _schedCur.StartTime = DateTime.Parse(comboStart.Text).TimeOfDay; _schedCur.StopTime = DateTime.Parse(comboStop.Text).TimeOfDay; } catch { MsgBox.Show(this, "Incorrect time format"); return; } _schedCur.Note = textNote.Text; _schedCur.BlockoutType = _listBlockoutCatDefs[listType.SelectedIndex].DefNum; _schedCur.Ops = new List <long>(); for (int i = 0; i < listOp.SelectedIndices.Count; i++) { _schedCur.Ops.Add(_listOps[listOp.SelectedIndices[i]].OperatoryNum); } List <Schedule> listOverlapSchedules; if (Schedules.Overlaps(_schedCur, out listOverlapSchedules)) { if (!PrefC.GetBool(PrefName.ReplaceExistingBlockout) || !Schedules.IsAppointmentBlocking(_schedCur.BlockoutType)) { MsgBox.Show(this, "Blockouts not allowed to overlap."); return; } if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "Creating this blockout will cause blockouts to overlap. Continuing will delete the existing " + "blockout(s). Continue?")) { return; } Schedules.DeleteMany(listOverlapSchedules.Select(x => x.ScheduleNum).ToList()); } try{ if (IsNew) { Schedules.Insert(_schedCur, true); Schedules.BlockoutLogHelper(BlockoutAction.Create, _schedCur); } else { Schedules.Update(_schedCur); Schedules.BlockoutLogHelper(BlockoutAction.Edit, _schedCur); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } DialogResult = DialogResult.OK; }
private void butOK_Click(object sender, System.EventArgs e) { if (listOp.SelectedIndices.Count == 0) { MsgBox.Show(this, "Please select at least one operatory first."); return; } try{ _schedCur.StartTime = DateTime.Parse(comboStart.Text).TimeOfDay; _schedCur.StopTime = DateTime.Parse(comboStop.Text).TimeOfDay; } catch { MsgBox.Show(this, "Incorrect time format"); return; } _schedCur.Note = textNote.Text; _schedCur.BlockoutType = _listBlockoutCatDefs[listType.SelectedIndex].DefNum; _schedCur.Ops = new List <long>(); for (int i = 0; i < listOp.SelectedIndices.Count; i++) { _schedCur.Ops.Add(_listOps[listOp.SelectedIndices[i]].OperatoryNum); } if (Schedules.Overlaps(_schedCur)) { MsgBox.Show(this, "Blockouts not allowed to overlap."); return; } try{ if (IsNew) { Schedules.Insert(_schedCur, true); SecurityLogs.MakeLogEntry(Permissions.Blockouts, 0, "Blockout add."); } else { Schedules.Update(_schedCur); SecurityLogs.MakeLogEntry(Permissions.Blockouts, 0, "Blockout edit."); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } DialogResult = DialogResult.OK; }
private void butRepeat_Click(object sender, EventArgs e) { if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" || textDateTo.errorProvider1.GetError(textDateTo) != "") { MsgBox.Show(this, "Please fix errors first."); return; } try{ int.Parse(textRepeat.Text); } catch { MsgBox.Show(this, "Please fix number box first."); return; } if (gridMain.SelectedCell.X == -1) { MsgBox.Show(this, "Please select a date first."); return; } if (DateCopyStart.Year < 1880) { MsgBox.Show(this, "Please copy a selection to the clipboard first."); return; } if (ProvsChanged) { MsgBox.Show(this, "Provider or Employee selection has been changed. Please refresh first."); return; } //calculate which day or week is currently selected. DateTime dateSelectedStart; DateTime dateSelectedEnd; bool isWeek = DateCopyStart != DateCopyEnd; if (isWeek) { int startI = 1; if (checkWeekend.Checked) { startI = 0; } dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, startI); if (checkWeekend.Checked) { dateSelectedEnd = dateSelectedStart.AddDays(6); } else { dateSelectedEnd = dateSelectedStart.AddDays(4); } } else { int selectedCol = gridMain.SelectedCell.X; if (!checkWeekend.Checked) { selectedCol++; } dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, selectedCol); dateSelectedEnd = dateSelectedStart; } //it is allowed to paste back over the same day or week. //if(dateSelectedStart==DateCopyStart) { // MsgBox.Show(this,"Not allowed to paste back onto the same date as is on the clipboard."); // return; //} List <int> provNums = new List <int>(); for (int i = 0; i < listProv.SelectedIndices.Count; i++) { provNums.Add(Providers.List[listProv.SelectedIndices[i]].ProvNum); } List <int> empNums = new List <int>(); for (int i = 0; i < listEmp.SelectedIndices.Count; i++) { empNums.Add(Employees.ListShort[listEmp.SelectedIndices[i]].EmployeeNum); } List <Schedule> SchedList = Schedules.RefreshPeriod(DateCopyStart, DateCopyEnd, provNums.ToArray(), empNums.ToArray(), checkPractice.Checked); Schedule sched; int weekDelta = 0; TimeSpan span; if (isWeek) { span = dateSelectedStart - DateCopyStart; weekDelta = span.Days / 7; //usually a positive # representing a future paste, but can be negative } int dayDelta = 0; //this is needed when repeat pasting days in order to calculate skipping weekends. //dayDelta will start out zero and increment separately from r. for (int r = 0; r < PIn.PInt(textRepeat.Text); r++) { if (checkReplace.Checked) { if (isWeek) { Schedules.Clear(dateSelectedStart.AddDays(r * 7), dateSelectedEnd.AddDays(r * 7), provNums.ToArray(), empNums.ToArray(), checkPractice.Checked); } else { Schedules.Clear(dateSelectedStart.AddDays(dayDelta), dateSelectedEnd.AddDays(dayDelta), provNums.ToArray(), empNums.ToArray(), checkPractice.Checked); } } for (int i = 0; i < SchedList.Count; i++) { sched = SchedList[i].Copy(); if (isWeek) { sched.SchedDate = sched.SchedDate.AddDays((weekDelta + r) * 7); } else { sched.SchedDate = dateSelectedStart.AddDays(dayDelta); } Schedules.Insert(sched); } if (!checkWeekend.Checked && dateSelectedStart.AddDays(dayDelta).DayOfWeek == DayOfWeek.Friday) { dayDelta += 3; } else { dayDelta++; } } DateTime rememberDateStart = DateCopyStart; DateTime rememberDateEnd = DateCopyEnd; FillGrid(); DateCopyStart = rememberDateStart; DateCopyEnd = rememberDateEnd; if (isWeek) { textClipboard.Text = DateCopyStart.ToShortDateString() + "-" + DateCopyEnd.ToShortDateString(); } else { textClipboard.Text = DateCopyStart.ToShortDateString(); } changed = true; }
private void butPaste_Click(object sender, EventArgs e) { if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" || textDateTo.errorProvider1.GetError(textDateTo) != "") { MsgBox.Show(this, "Please fix errors first."); return; } if (gridMain.SelectedCell.X == -1) { MsgBox.Show(this, "Please select a date first."); return; } if (DateCopyStart.Year < 1880) { MsgBox.Show(this, "Please copy a selection to the clipboard first."); return; } if (ProvsChanged) { MsgBox.Show(this, "Provider or Employee selection has been changed. Please refresh first."); return; } //calculate which day or week is currently selected. DateTime dateSelectedStart; DateTime dateSelectedEnd; bool isWeek = DateCopyStart != DateCopyEnd; if (isWeek) { int startI = 1; if (checkWeekend.Checked) { startI = 0; } dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, startI); if (checkWeekend.Checked) { dateSelectedEnd = dateSelectedStart.AddDays(6); } else { dateSelectedEnd = dateSelectedStart.AddDays(4); } } else { int selectedCol = gridMain.SelectedCell.X; if (!checkWeekend.Checked) { selectedCol++; } dateSelectedStart = Schedules.GetDateCal(PIn.PDate(textDateFrom.Text), gridMain.SelectedCell.Y, selectedCol); dateSelectedEnd = dateSelectedStart; } //it's not allowed to paste back over the same day or week. if (dateSelectedStart == DateCopyStart) { MsgBox.Show(this, "Not allowed to paste back onto the same date as is on the clipboard."); return; } List <int> provNums = new List <int>(); for (int i = 0; i < listProv.SelectedIndices.Count; i++) { provNums.Add(Providers.List[listProv.SelectedIndices[i]].ProvNum); } List <int> empNums = new List <int>(); for (int i = 0; i < listEmp.SelectedIndices.Count; i++) { empNums.Add(Employees.ListShort[listEmp.SelectedIndices[i]].EmployeeNum); } if (checkReplace.Checked) { Schedules.Clear(dateSelectedStart, dateSelectedEnd, provNums.ToArray(), empNums.ToArray(), checkPractice.Checked); } List <Schedule> SchedList = Schedules.RefreshPeriod(DateCopyStart, DateCopyEnd, provNums.ToArray(), empNums.ToArray(), checkPractice.Checked); Schedule sched; int weekDelta = 0; if (isWeek) { TimeSpan span = dateSelectedStart - DateCopyStart; weekDelta = span.Days / 7; //usually a positive # representing a future paste, but can be negative } for (int i = 0; i < SchedList.Count; i++) { sched = SchedList[i]; if (isWeek) { sched.SchedDate = sched.SchedDate.AddDays(weekDelta * 7); } else { sched.SchedDate = dateSelectedStart; } Schedules.Insert(sched); } DateTime rememberDateStart = DateCopyStart; DateTime rememberDateEnd = DateCopyEnd; FillGrid(); DateCopyStart = rememberDateStart; DateCopyEnd = rememberDateEnd; if (isWeek) { textClipboard.Text = DateCopyStart.ToShortDateString() + "-" + DateCopyEnd.ToShortDateString(); } else { textClipboard.Text = DateCopyStart.ToShortDateString(); } changed = true; }
private void CopyOverBlockouts(long numRepeat, string type) { if (DateCopyStart.Year < 1880) { MsgBox.Show(this, "Please copy a selection to the clipboard first."); return; } //calculate which day or week is currently selected. DateTime dateSelectedStart; DateTime dateSelectedEnd; bool isWeek = DateCopyStart != DateCopyEnd; if (isWeek) { //Always start week on Monday if (DateSelected.DayOfWeek == DayOfWeek.Sunday) //if selecting Sunday, go back to the previous Monday. { dateSelectedStart = DateSelected.AddDays(-6); } else //Any other day. eg Wed.AddDays(1-3)=Wed.AddDays(-2)=Monday { dateSelectedStart = DateSelected.AddDays(1 - (int)DateSelected.DayOfWeek); //eg Wed.AddDays(1-3)=Wed.AddDays(-2)=Monday } //DateCopyEnd is greater than DateCopyStart and is either 4 days greater or 6 days greater, so clear/paste the same number of days dateSelectedEnd = dateSelectedStart.AddDays((DateCopyEnd - DateCopyStart).Days); } else { dateSelectedStart = DateSelected; dateSelectedEnd = DateSelected; } //When pasting, it's not allowed to paste back over the same day or week. if (dateSelectedStart == DateCopyStart && type == "Paste") { MsgBox.Show(this, "Not allowed to paste back onto the same date as is on the clipboard."); return; } Cursor = Cursors.WaitCursor; //it is allowed to paste back over the same day or week. List <long> opNums = ApptViewItems.GetOpsForView(ApptViewNumCur); List <Schedule> SchedList = Schedules.RefreshPeriodBlockouts(DateCopyStart, DateCopyEnd, opNums); //Build a list of blockouts that can't be Cut/Copy/Pasted List <Def> listUserBlockoutDefs = Defs.GetDefsForCategory(DefCat.BlockoutTypes, true) .FindAll(x => x.ItemValue.Contains(BlockoutType.DontCopy.GetDescription())); //No SchedList only contains blockouts that are NOT marked "Do not Cut/Copy/Paste" SchedList.RemoveAll(x => listUserBlockoutDefs.Any(y => y.DefNum == x.BlockoutType)); Schedule sched; int weekDelta = 0; TimeSpan span; if (isWeek) { span = dateSelectedStart - DateCopyStart; weekDelta = span.Days / 7; //usually a positive # representing a future paste, but can be negative } int dayDelta = 0; //this is needed when repeat pasting days in order to calculate skipping weekends. //dayDelta will start out zero and increment separately from r. for (int r = 0; r < numRepeat; r++) { if (checkReplace.Checked) { if (type == "Repeat") { if (isWeek) { Schedules.ClearBlockouts(dateSelectedStart.AddDays(r * 7), dateSelectedEnd.AddDays(r * 7), opNums); } else { //dateSelectedStart will equal dateSelectedEnd if repeating a single day Schedules.ClearBlockouts(dateSelectedStart.AddDays(dayDelta), dateSelectedEnd.AddDays(dayDelta), opNums); } } else { Schedules.ClearBlockouts(dateSelectedStart, dateSelectedEnd, opNums); } } List <Schedule> listNewScheds = new List <Schedule>(); for (int i = 0; i < SchedList.Count; i++) { sched = SchedList[i].Copy(); sched.ScheduleNum = 0; //So that overlap logic works. if (isWeek) { sched.SchedDate = sched.SchedDate.AddDays((weekDelta + r) * 7); } else { sched.SchedDate = dateSelectedStart.AddDays(dayDelta); } if (!checkReplace.Checked && Schedules.Overlaps(sched)) { MessageBox.Show(Lans.g("Schedule", "A blockout overlaps with an existing blockout. Could not paste the blockout on") + " " + sched.SchedDate.ToShortDateString() + " " + sched.StartTime.ToShortTimeString()); Cursor = Cursors.Default; return; } listNewScheds.Add(sched); } //dayDelta is only used for repeating single days, not for repeating weeks, so we don't need to determine whether or not they copied weekends, we can rely on checkWeekend.Checked if (!checkWeekend.Checked && dateSelectedStart.AddDays(dayDelta).DayOfWeek == DayOfWeek.Friday) { dayDelta += 3; } else { dayDelta++; } //This is located outside of the previous for loop because we do not want to insert any blockouts unless there were no overlaps. foreach (Schedule schedule in listNewScheds) { Schedules.Insert(schedule, true); //Doing it this way makes use of validation to prevent overlaps } } Cursor = Cursors.Default; Close(); }
private void butRepeat_Click(object sender, EventArgs e) { try { int.Parse(textRepeat.Text); } catch { MsgBox.Show(this, "Please fix number box first."); return; } if (DateCopyStart.Year < 1880) { MsgBox.Show(this, "Please copy a selection to the clipboard first."); return; } //calculate which day or week is currently selected. DateTime dateSelectedStart; DateTime dateSelectedEnd; bool isWeek = DateCopyStart != DateCopyEnd; if (isWeek) { if (checkWeekend.Checked) { dateSelectedStart = DateSelected.AddDays(-(int)DateSelected.DayOfWeek); dateSelectedEnd = dateSelectedStart.AddDays(6); } else { dateSelectedStart = DateSelected.AddDays(-(int)DateSelected.DayOfWeek + 1); dateSelectedEnd = dateSelectedStart.AddDays(4); } } else { dateSelectedStart = DateSelected; dateSelectedEnd = DateSelected; } //it is allowed to paste back over the same day or week. int[] opNums = ApptViewItems.GetOpsForView(ApptViewNumCur); List <Schedule> SchedList = Schedules.RefreshPeriodBlockouts(DateCopyStart, DateCopyEnd, opNums); Schedule sched; int weekDelta = 0; TimeSpan span; if (isWeek) { span = dateSelectedStart - DateCopyStart; weekDelta = span.Days / 7; //usually a positive # representing a future paste, but can be negative } int dayDelta = 0; //this is needed when repeat pasting days in order to calculate skipping weekends. //dayDelta will start out zero and increment separately from r. for (int r = 0; r < PIn.PInt(textRepeat.Text); r++) { if (checkReplace.Checked) { if (isWeek) { Schedules.ClearBlockouts(dateSelectedStart.AddDays(r * 7), dateSelectedEnd.AddDays(r * 7), opNums); } else { Schedules.ClearBlockouts(dateSelectedStart.AddDays(dayDelta), dateSelectedEnd.AddDays(dayDelta), opNums); } } for (int i = 0; i < SchedList.Count; i++) { sched = SchedList[i].Copy(); if (isWeek) { sched.SchedDate = sched.SchedDate.AddDays((weekDelta + r) * 7); } else { sched.SchedDate = dateSelectedStart.AddDays(dayDelta); } Schedules.Insert(sched); } if (!checkWeekend.Checked && dateSelectedStart.AddDays(dayDelta).DayOfWeek == DayOfWeek.Friday) { dayDelta += 3; } else { dayDelta++; } } Close(); }
private void butPaste_Click(object sender, EventArgs e) { if (DateCopyStart.Year < 1880) { MsgBox.Show(this, "Please copy a selection to the clipboard first."); return; } //calculate which day or week is currently selected. DateTime dateSelectedStart; DateTime dateSelectedEnd; bool isWeek = DateCopyStart != DateCopyEnd; if (isWeek) { if (checkWeekend.Checked) { dateSelectedStart = DateSelected.AddDays(-(int)DateSelected.DayOfWeek); dateSelectedEnd = dateSelectedStart.AddDays(6); } else { dateSelectedStart = DateSelected.AddDays(-(int)DateSelected.DayOfWeek + 1); dateSelectedEnd = dateSelectedStart.AddDays(4); } } else { dateSelectedStart = DateSelected; dateSelectedEnd = DateSelected; } //it's not allowed to paste back over the same day or week. if (dateSelectedStart == DateCopyStart) { MsgBox.Show(this, "Not allowed to paste back onto the same date as is on the clipboard."); return; } int[] opNums = ApptViewItems.GetOpsForView(ApptViewNumCur); List <Schedule> SchedList = Schedules.RefreshPeriodBlockouts(DateCopyStart, DateCopyEnd, opNums); if (checkReplace.Checked) { Schedules.ClearBlockouts(dateSelectedStart, dateSelectedEnd, opNums); } Schedule sched; int weekDelta = 0; if (isWeek) { TimeSpan span = dateSelectedStart - DateCopyStart; weekDelta = span.Days / 7; //usually a positive # representing a future paste, but can be negative } for (int i = 0; i < SchedList.Count; i++) { sched = SchedList[i]; if (isWeek) { sched.SchedDate = sched.SchedDate.AddDays(weekDelta * 7); } else { sched.SchedDate = dateSelectedStart; } Schedules.Insert(sched); } Close(); }