///<summary>If a particular day already has some non-default schedule items, then this does nothing and returns false. But if the day is all default, then it converts each default entry into an actual schedule entry and returns true. The user would not notice this change, but now they can edit or add.</summary> public static bool ConvertFromDefault(DateTime forDate, ScheduleType schedType, int provNum) { Schedule[] List = RefreshDay(forDate); Schedule[] ListForType = GetForType(List, schedType, provNum); if (ListForType.Length > 0) { return(false); //do nothing, since it has already been converted from default. //it is also possible there will be no default entries to convert, but that's ok. } SchedDefault[] ListDefaults = SchedDefaults.GetForType(schedType, provNum); for (int i = 0; i < ListDefaults.Length; i++) { if (ListDefaults[i].DayOfWeek != (int)forDate.DayOfWeek) { continue; //if day of week doesn't match, then skip } Schedule SchedCur = new Schedule(); SchedCur.Status = SchedStatus.Open; SchedCur.SchedDate = forDate; SchedCur.StartTime = ListDefaults[i].StartTime; SchedCur.StopTime = ListDefaults[i].StopTime; SchedCur.SchedType = schedType; SchedCur.ProvNum = provNum; SchedCur.Op = ListDefaults[i].Op; SchedCur.BlockoutType = ListDefaults[i].BlockoutType; InsertOrUpdate(SchedCur, true); } return(true); }
///<summary>The background provider schedule for the timebar on the left</summary> private void DrawProvSchedInTimebar(Graphics g) { Provider provCur; SchedDefault[] schedDefs; //for one type at a time Schedule[] schedForType; for (int j = 0; j < ApptViewItems.VisProvs.Length; j++) { provCur = Providers.List[ApptViewItems.VisProvs[j]]; schedForType = Schedules.GetForType(SchedListDay, ScheduleType.Provider, provCur.ProvNum); if (schedForType.Length == 0) //use default sched { schedDefs = SchedDefaults.GetForType(ScheduleType.Provider, provCur.ProvNum); for (int i = 0; i < schedDefs.Length; i++) { if (schedDefs[i].DayOfWeek == (int)Appointments.DateSelected.DayOfWeek) { g.FillRectangle(openBrush , TimeWidth + ProvWidth * j , schedDefs[i].StartTime.Hour * Lh * RowsPerHr + schedDefs[i].StartTime.Minute * Lh / MinPerRow , ProvWidth , (schedDefs[i].StopTime - schedDefs[i].StartTime).Hours * Lh * RowsPerHr + (schedDefs[i].StopTime - schedDefs[i].StartTime).Minutes * Lh / MinPerRow); } } } else //use schedForType { for (int i = 0; i < schedForType.Length; i++) { if (schedForType[i].Status == SchedStatus.Holiday) { g.FillRectangle(holidayBrush, TimeWidth + ProvWidth * j, 0 , ProvWidth, Height); } else { g.FillRectangle(openBrush , TimeWidth + ProvWidth * j , schedForType[i].StartTime.Hour * Lh * RowsPerHr //6 + (int)schedForType[i].StartTime.Minute * Lh / MinPerRow //10 , ProvWidth , (schedForType[i].StopTime - schedForType[i].StartTime).Hours * Lh * RowsPerHr //6 + (schedForType[i].StopTime - schedForType[i].StartTime).Minutes * Lh / MinPerRow); //10 } } } } }
///<summary></summary> private static bool Overlaps(SchedDefault sd) { SchedDefaults.Refresh(); SchedDefault[] ListForType = SchedDefaults.GetForType(sd.SchedType, sd.ProvNum); for (int i = 0; i < ListForType.Length; i++) { //if(SchedDefaults.List[i].SchedType!=SchedType){ // continue;//skip if different sched type //} //if(SchedDefaults.List[i].SchedType==ScheduleType.Provider // && SchedDefaults.List[i].ProvNum!=ProvNum) //{ // continue;//skip if provider type and this is different provider //} if (ListForType[i].SchedType == ScheduleType.Blockout) { //skip if blockout, and ops don't interfere if (sd.Op != 0 && ListForType[i].Op != 0) //neither op can be zero, or they will interfere { if (sd.Op != ListForType[i].Op) { continue; } } } if (sd.SchedDefaultNum != ListForType[i].SchedDefaultNum && sd.DayOfWeek == ListForType[i].DayOfWeek && sd.StartTime.TimeOfDay >= ListForType[i].StartTime.TimeOfDay && sd.StartTime.TimeOfDay < ListForType[i].StopTime.TimeOfDay) { return(true); } if (sd.SchedDefaultNum != ListForType[i].SchedDefaultNum && sd.DayOfWeek == ListForType[i].DayOfWeek && sd.StopTime.TimeOfDay > ListForType[i].StartTime.TimeOfDay && sd.StopTime.TimeOfDay <= ListForType[i].StopTime.TimeOfDay) { return(true); } if (sd.SchedDefaultNum != ListForType[i].SchedDefaultNum && sd.DayOfWeek == ListForType[i].DayOfWeek && sd.StartTime.TimeOfDay <= ListForType[i].StartTime.TimeOfDay && sd.StopTime.TimeOfDay >= ListForType[i].StopTime.TimeOfDay) { return(true); } } return(false); }
private void FillList() { Schedule[] SchedListAll = Schedules.RefreshDay(SchedCurDate); SchedListDay = Schedules.GetForType(SchedListAll, SchedType, ProvNum); SchedDefaults.Refresh(); SchedDefault[] schedDefForType = SchedDefaults.GetForType(SchedType, ProvNum); listTimeBlocks.Items.Clear(); ALdefaults = new ArrayList(); labelDefault.Visible = false; if (SchedListDay.Length == 0) { //show defaults instead of user-entered list for (int i = 0; i < schedDefForType.Length; i++) { if ((int)SchedCurDate.DayOfWeek == schedDefForType[i].DayOfWeek) { ALdefaults.Add(schedDefForType[i]); listTimeBlocks.Items.Add(schedDefForType[i].StartTime.ToShortTimeString() + " - " + schedDefForType[i].StopTime.ToShortTimeString()); } } labelDefault.Visible = true; } else//show the list of user-entered schedule items { if (SchedListDay.Length == 1 && SchedListDay[0].Status == SchedStatus.Closed) { listTimeBlocks.Items.Add("Office Closed " + SchedListDay[0].Note); } else if (SchedListDay.Length == 1 && SchedListDay[0].Status == SchedStatus.Holiday) { listTimeBlocks.Items.Add("Holiday: " + SchedListDay[0].Note); } else { for (int i = 0; i < SchedListDay.Length; i++) { listTimeBlocks.Items.Add(SchedListDay[i].StartTime.ToShortTimeString() + " - " + SchedListDay[i].StopTime.ToShortTimeString()); } } } }
///<summary>Draws all the blockouts for the entire day.</summary> private void DrawBlockouts(Graphics g) { SchedDefault[] schedDefs; //for one type at a time Schedule[] schedForType; schedForType = Schedules.GetForType(SchedListDay, ScheduleType.Blockout, 0); SolidBrush blockBrush; Pen blockOutlinePen = new Pen(Color.Black, 1); Font blockFont = new Font("Arial", 8); string blockText; RectangleF rect; g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; //to make printing clearer if (schedForType.Length == 0) //use default sched { schedDefs = SchedDefaults.GetForType(ScheduleType.Blockout, 0); for (int i = 0; i < schedDefs.Length; i++) { if (schedDefs[i].DayOfWeek == (int)Appointments.DateSelected.DayOfWeek) { blockBrush = new SolidBrush(DefB.GetColor(DefCat.BlockoutTypes, schedDefs[i].BlockoutType)); blockText = DefB.GetName(DefCat.BlockoutTypes, schedDefs[i].BlockoutType); if (schedDefs[i].Op == 0) //all ops { rect = new RectangleF( TimeWidth + ProvWidth * ProvCount + 1 , schedDefs[i].StartTime.Hour * Lh * RowsPerHr + schedDefs[i].StartTime.Minute * Lh / MinPerRow , ColWidth * ColCount - 1 , (schedDefs[i].StopTime - schedDefs[i].StartTime).Hours * Lh * RowsPerHr + (schedDefs[i].StopTime - schedDefs[i].StartTime).Minutes * Lh / MinPerRow); } else //just one op { if (ApptViewItems.GetIndexOp(schedDefs[i].Op) == -1) { continue; //don't display if op not visible } rect = new RectangleF( TimeWidth + ProvWidth * ProvCount + ColWidth * ApptViewItems.GetIndexOp(schedDefs[i].Op) + 1 , schedDefs[i].StartTime.Hour * Lh * RowsPerHr + schedDefs[i].StartTime.Minute * Lh / MinPerRow , ColWidth - 1 , (schedDefs[i].StopTime - schedDefs[i].StartTime).Hours * Lh * RowsPerHr + (schedDefs[i].StopTime - schedDefs[i].StartTime).Minutes * Lh / MinPerRow); } g.FillRectangle(blockBrush, rect); g.DrawRectangle(blockOutlinePen, rect.X + 1, rect.Y + 2, rect.Width - 2, rect.Height - 4); g.DrawString(blockText, blockFont , new SolidBrush(DefB.Short[(int)DefCat.AppointmentColors][5].ItemColor), rect); } } } else //use schedForType { for (int i = 0; i < schedForType.Length; i++) { blockBrush = new SolidBrush(DefB.GetColor(DefCat.BlockoutTypes, schedForType[i].BlockoutType)); blockText = DefB.GetName(DefCat.BlockoutTypes, schedForType[i].BlockoutType) + "\r\n" + schedForType[i].Note; if (schedForType[i].Op == 0) //all ops { rect = new RectangleF( TimeWidth + ProvWidth * ProvCount + 1 , schedForType[i].StartTime.Hour * Lh * RowsPerHr //6 + schedForType[i].StartTime.Minute * Lh / MinPerRow //10 , ColWidth * ColCount - 1 , (schedForType[i].StopTime - schedForType[i].StartTime).Hours * Lh * RowsPerHr + (schedForType[i].StopTime - schedForType[i].StartTime).Minutes * Lh / MinPerRow); } else //just one op { if (ApptViewItems.GetIndexOp(schedForType[i].Op) == -1) { continue; //don't display if op not visible } rect = new RectangleF( TimeWidth + ProvWidth * ProvCount + ColWidth * ApptViewItems.GetIndexOp(schedForType[i].Op) + 1 , schedForType[i].StartTime.Hour * Lh * RowsPerHr + schedForType[i].StartTime.Minute * Lh / MinPerRow , ColWidth - 1 , (schedForType[i].StopTime - schedForType[i].StartTime).Hours * Lh * RowsPerHr + (schedForType[i].StopTime - schedForType[i].StartTime).Minutes * Lh / MinPerRow); } g.FillRectangle(blockBrush, rect); //g.DrawRectangle(blockOutlinePen,rect.X,rect.Y+1,rect.Width-1,rect.Height-3); g.DrawLine(blockOutlinePen, rect.X, rect.Y + 1, rect.Right - 1, rect.Y + 1); g.DrawString(blockText, blockFont , new SolidBrush(DefB.Short[(int)DefCat.AppointmentColors][5].ItemColor), rect); } } }
///<summary>Including the practice schedule</summary> private void DrawMainBackground(Graphics g) { SchedDefault[] schedDefs; //for one type at a time Schedule[] schedForType; //one giant rectangle for everything closed g.FillRectangle(closedBrush, TimeWidth, 0, ColWidth * ColCount + ProvWidth * ProvCount, Height); //then, loop through each operatory Operatory curOp; for (int j = 0; j < ColCount; j++) { curOp = Operatories.ListShort[ApptViewItems.VisOps[j]]; if (curOp.ProvDentist != 0 && !curOp.IsHygiene) //dentist { schedForType = Schedules.GetForType(SchedListDay, ScheduleType.Provider, curOp.ProvDentist); } else if (curOp.ProvHygienist != 0 && curOp.IsHygiene) //hygienist { schedForType = Schedules.GetForType(SchedListDay, ScheduleType.Provider, curOp.ProvHygienist); } else //practice { schedForType = Schedules.GetForType(SchedListDay, ScheduleType.Practice, 0); } if (schedForType.Length == 0) //use default sched { if (curOp.ProvDentist != 0 && !curOp.IsHygiene) //dentist { schedDefs = SchedDefaults.GetForType(ScheduleType.Provider, curOp.ProvDentist); } else if (curOp.ProvHygienist != 0 && curOp.IsHygiene) //hygienist { schedDefs = SchedDefaults.GetForType(ScheduleType.Provider, curOp.ProvHygienist); } else //practice { schedDefs = SchedDefaults.GetForType(ScheduleType.Practice, 0); } for (int i = 0; i < schedDefs.Length; i++) { if (schedDefs[i].DayOfWeek == (int)Appointments.DateSelected.DayOfWeek) { g.FillRectangle(openBrush , TimeWidth + ProvWidth * ProvCount + j * ColWidth , schedDefs[i].StartTime.Hour * Lh * RowsPerHr + schedDefs[i].StartTime.Minute * Lh / MinPerRow , ColWidth , (schedDefs[i].StopTime - schedDefs[i].StartTime).Hours * Lh * RowsPerHr + (schedDefs[i].StopTime - schedDefs[i].StartTime).Minutes * Lh / MinPerRow); } } } else //use schedForType { for (int i = 0; i < schedForType.Length; i++) { if (schedForType[i].Status == SchedStatus.Holiday) { //g.FillRectangle(holidayBrush,TimeWidth+ProvWidth*ProvCount,0,ColWidth*ColCount,Height); g.FillRectangle(holidayBrush, TimeWidth + ProvWidth * ProvCount + j * ColWidth, 0, ColWidth, Height); } else { g.FillRectangle(openBrush , TimeWidth + ProvWidth * ProvCount + j * ColWidth , schedForType[i].StartTime.Hour * Lh * RowsPerHr + (int)schedForType[i].StartTime.Minute * Lh / MinPerRow //6RowsPerHr 10MinPerRow , ColWidth , (schedForType[i].StopTime - schedForType[i].StartTime).Hours * Lh * RowsPerHr //6 + (schedForType[i].StopTime - schedForType[i].StartTime).Minutes * Lh / MinPerRow); //10 } } } //else use schedForType } //for colCount }
private void GetScheduleData() { ProvNum = 0; if (SchedType == ScheduleType.Provider) { ProvNum = Providers.List[listProv.SelectedIndex].ProvNum; } SchedListMonth = Schedules.RefreshMonth(cal.SelectedDate , SchedType, ProvNum); //Schedules.RefreshDay(cal.SelectedDate);//? SchedDefault[] schedDefForType = SchedDefaults.GetForType(SchedType, ProvNum); //if(SchedType==SchedType. cal.ResetList(); bool HasSchedDefault; bool HasScheduleData; for (int i = 1; i < cal.List.Length; i++)//loop through each day { HasSchedDefault = false; HasScheduleData = false; for (int j = 0; j < SchedListMonth.Length; j++) { if (cal.List[i].Date == SchedListMonth[j].SchedDate) { if (SchedListMonth[j].Status == SchedStatus.Open) { cal.AddText(i, SchedListMonth[j].StartTime.ToShortTimeString() + " - " + SchedListMonth[j].StopTime.ToShortTimeString()); cal.List[i].color = OpenColor; if (SchedListMonth[j].Note == "") { } else { cal.AddText(i, SchedListMonth[j].Note); } } else if (SchedListMonth[j].Status == SchedStatus.Holiday) { if (SchedListMonth[j].Note == "") { } else { cal.AddText(i, SchedListMonth[j].Note); } cal.ChangeColor(i, HolidayColor); } else { if (SchedListMonth[j].Note == "") { } else { cal.AddText(i, SchedListMonth[j].Note); } cal.ChangeColor(i, ClosedColor); } HasScheduleData = true; } } //Debug.WriteLine(HasScheduleData); if (!HasScheduleData)//use defaults instead { for (int j = 0; j < schedDefForType.Length; j++) { if ((int)cal.List[i].Date.DayOfWeek == schedDefForType[j].DayOfWeek) { cal.AddText(i, schedDefForType[j].StartTime.ToShortTimeString() + " - " + schedDefForType[j].StopTime.ToShortTimeString()); HasSchedDefault = true; cal.ChangeColor(i, OpenColor); } } if (!HasSchedDefault) { cal.List[i].color = ClosedColor; } } }//day loop }