Changeset 1095 for Scheduling/trunk/cs/bsdx0200GUISourceCode/CGSchedLib.cs
- Timestamp:
- Feb 21, 2011, 9:21:24 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Scheduling/trunk/cs/bsdx0200GUISourceCode/CGSchedLib.cs
r1011 r1095 19 19 /// scheduling application. 20 20 /// </summary> 21 public class CGSchedLib21 public static class CGSchedLib 22 22 { 23 public CGSchedLib()24 {25 26 }27 28 23 /// <summary> 29 24 /// Gets appointments from VISTA to display in Grid … … 53 48 } 54 49 55 public static void OutputArray(DataTable dt, string sName) 56 { 57 #if (DEBUG && OUTPUTARRAY) 58 Debug.Write("\n " + sName + " OutputArray:\n"); 59 if (dt == null) 60 return; 61 62 foreach (DataColumn c in dt.Columns) 63 { 64 Debug.Write(c.ToString()); 65 } 66 Debug.Write("\n"); 67 foreach (DataRow r in dt.Rows) 68 { 69 foreach (DataColumn c in dt.Columns) 70 { 71 Debug.Write(r[c].ToString()); 72 } 73 Debug.Write("\n"); 74 } 75 Debug.Write("\n"); 76 #endif 77 } 78 50 51 /// <summary> 52 /// Gets all Availabilities and Appointments, then substracts Appointments from availabilities. 53 /// </summary> 54 /// <param name="docManager">God Class</param> 55 /// <param name="saryResourceNames">Resource Array (ArrayList)</param> 56 /// <param name="StartTime">Self-Explanatory</param> 57 /// <param name="EndTime">Self-Explanatory</param> 58 /// <param name="saryApptTypes">Array of Access Type IDs</param> 59 /// <param name="stType"></param> 60 /// <param name="sSearchInfo"></param> 61 /// <returns></returns> 79 62 public static DataTable CreateAvailabilitySchedule(CGDocumentManager docManager, 80 63 ArrayList saryResourceNames, DateTime StartTime, DateTime EndTime, … … 95 78 96 79 string sResName; 80 //TODO: Optimize: no need to keep looping through resources. 97 81 // for each resource 98 82 for (int i = 0; i < nSize; i++) 99 83 { 100 84 sResName = saryResourceNames[i].ToString(); 101 //Gets all the slots (or Availabities, if you like)85 //Gets all the slots (or Availabities, or AV Blocks if you like) 102 86 rsSlotSchedule = CGSchedLib.CreateAssignedSlotSchedule(docManager, sResName, StartTime, EndTime, saryApptTypes,/**/ stType, sSearchInfo); 103 OutputArray(rsSlotSchedule, "rsSlotSchedule");87 104 88 //if we have slots 105 89 if (rsSlotSchedule.Rows.Count > 0 ) … … 107 91 // Get appointment count to substract from the slots 108 92 rsApptSchedule = CGSchedLib.CreateAppointmentSlotSchedule(docManager, sResName, StartTime, EndTime, stType); 109 OutputArray(rsApptSchedule, "rsApptSchedule"); 93 110 94 // Perform the substraction 111 95 rsTemp1 = CGSchedLib.SubtractSlotsRS2(rsSlotSchedule, rsApptSchedule, sResName); 112 OutputArray(rsTemp1, "rsTemp1"); 113 } 96 97 } 98 //otherwise, just return the slot schedule we have. 114 99 else 115 100 { 116 101 rsTemp1 = rsSlotSchedule; 117 OutputArray(rsTemp1, "rsTemp1"); 118 } 102 103 } 104 119 105 // if only one resource was passed in, its availablility is what we want 120 106 if (i == 0) 121 107 { 122 108 rsOut = rsTemp1; 123 OutputArray(rsOut, "rsOut"); 124 } 109 110 } 111 // if more than one resource, merge them together 125 112 else 126 113 { 127 114 rsOut = CGSchedLib.UnionBlocks(rsTemp1, rsOut); 128 OutputArray(rsOut, "United rsOut");129 115 } 130 116 } … … 133 119 134 120 121 /* NOT USED ANYMORE!!! 135 122 public static DataTable CreateAssignedTypeSchedule(CGDocumentManager docManager, string sResourceName, DateTime StartTime, DateTime EndTime, ScheduleType stType) 136 123 { 137 124 138 string sStart; 139 string sEnd; 140 //sStart = StartTime.ToString("M-d-yyyy"); 141 sStart = FMDateTime.Create(StartTime).DateOnly.FMDateString; 142 //sEnd = EndTime.ToString("M-d-yyyy"); 143 sEnd = FMDateTime.Create(EndTime).DateOnly.FMDateString; 144 // string sSource = (stType == ScheduleType.Resource ? "ST_RESOURCE" : "ST_CLINIC"); 145 string sSql = "BSDX TYPE BLOCKS OVERLAP^" + sStart + "^" + sEnd + "^" + sResourceName ;//+ "^" + sSource; 125 string sStart = FMDateTime.Create(StartTime).DateOnly.FMDateString; 126 string sEnd = FMDateTime.Create(EndTime).DateOnly.FMDateString; 127 string sSql = "BSDX TYPE BLOCKS OVERLAP^" + sStart + "^" + sEnd + "^" + sResourceName; 146 128 147 129 DataTable rs = docManager.RPMSDataTable(sSql, "AssignedTypeSchedule"); … … 176 158 177 159 dCol = new DataColumn(); 178 //dCol.DataType = Type.GetType("System.Int16"); 179 dCol.DataType = Type.GetType("System.Int32"); //MJL 11/17/2006 160 dCol.DataType = Type.GetType("System.Int32"); 180 161 dCol.ColumnName = "AvailabilityID"; 181 162 dCol.ReadOnly = true; … … 196 177 DateTime dStart; 197 178 DateTime dEnd; 198 // DataRow r; 199 DataRow rNew; 200 179 DataRow rNew; //Temporary Holding place for first or last row 180 181 // Get Last Date from final row 201 182 rNew = rs.Rows[rs.Rows.Count - 1]; 202 183 dLastEnd = (DateTime) rNew["EndTime"]; 184 // Get First Date from first row 203 185 rNew = rs.Rows[0]; 204 186 dStart = (DateTime) rNew["StartTime"]; … … 210 192 // then pad with a new block 211 193 194 // if First Row time is later than the StartTime param (should always be true) 195 // then make a new row whose time starts from StartTime and ends with dStart 212 196 if (dStart > StartTime) 213 197 { … … 222 206 } 223 207 224 //if first block start time is < StartTime then trim 208 //if first block start time is < StartTime then trim (shouldn't happen) 225 209 if (dStart < StartTime) 226 210 { … … 233 217 int nAvailabilityID; 234 218 219 //dStart holds the first date for the availabilities returned from RPMS 235 220 dEnd = dStart; 236 221 foreach (DataRow rEach in rs.Rows) … … 248 233 } 249 234 235 //dEnd now EndTime for AV Block 250 236 dEnd = (DateTime) rEach["EndTime"]; 251 237 252 if (dEnd > EndTime) 253 dEnd = EndTime; 238 // if dEnd is greater than endime, set dEnd to be the same as EndTime. 239 if (dEnd > EndTime) { dEnd = EndTime; } 240 241 254 242 nAppointmentTypeID = (int) rEach["AppointmentTypeID"]; 255 243 nAvailabilityID = (int) rEach["AvailabilityID"]; … … 275 263 rsCopy.Rows.Add(rNew); 276 264 } 277 OutputArray(rsCopy, "CreateAssignedTypeSchedule");265 278 266 return rsCopy; 279 267 } 280 281 public static DataTable CreateAssignedSlotSchedule(CGDocumentManager docManager, string sResourceName, DateTime StartTime, DateTime EndTime, ArrayList rsaryApptTypeIDs, /**/ ScheduleType stType, string sSearchInfo) 282 { 283 284 //Appointment type ids is now always "" so that all appointment types are returned. 268 */ 269 270 /// <summary> 271 /// Gets the Availability Slots from the Server 272 /// </summary> 273 /// <param name="docManager">God Class</param> 274 /// <param name="sResourceName">Resource for which to get slots</param> 275 /// <param name="StartTime"></param> 276 /// <param name="EndTime"></param> 277 /// <param name="rsaryApptTypeIDs">Access Type IDs to retrieve</param> 278 /// <param name="stType">Not used</param> 279 /// <param name="sSearchInfo">If performing a slot search (i.e. for empty appointments), has search info here. Used by Find Appointments</param> 280 /// <returns>DataTable with the following Columns: 281 /// D00030START_TIME^D00030END_TIME^I00010SLOTS^T00030RESOURCE^T00010ACCESS_TYPE^T00250NOTE^I00030AVAILABILITYID 282 /// </returns> 283 public static DataTable CreateAssignedSlotSchedule(CGDocumentManager docManager, string sResourceName, DateTime StartTime, 284 DateTime EndTime, ArrayList rsaryApptTypeIDs, /**/ ScheduleType stType, string sSearchInfo) 285 { 286 //Appointment type ids is now always "" so that all appointment types are returned. 285 287 string sApptTypeIDs = ""; 286 288 287 //The following code block is not used now, but keep for possible later use: 288 //Unpack the Appointment Type IDs 289 /* 290 */ 291 int nSize = rsaryApptTypeIDs.Count; 289 //flatten types by '|' 290 int nSize = rsaryApptTypeIDs.Count; //nSize is used to decide where to put the '|' sent in the RPC as we flatten sApptTypeIDs 292 291 for (int i=0; i < nSize; i++) 293 292 { … … 297 296 } 298 297 299 string sStart; 300 string sEnd; 301 //sStart = StartTime.ToString("M-d-yyyy"); smh 302 sStart = FMDateTime.Create(StartTime).DateOnly.FMDateString; 303 //sEnd = EndTime.ToString("M-d-yyyy@H:mm"); smh 304 sEnd = FMDateTime.Create(EndTime).FMDateString; 298 string sStart = FMDateTime.Create(StartTime).DateOnly.FMDateString; 299 string sEnd = FMDateTime.Create(EndTime).FMDateString; 305 300 string sSql = "BSDX CREATE ASGND SLOT SCHED^" + sResourceName + "^" + sStart + "^" + sEnd + "^" + sApptTypeIDs + "^" + sSearchInfo; //+ "^" + sSTType ; 306 307 301 DataTable dtRet = docManager.RPMSDataTable(sSql, "AssignedSlotSchedule"); 308 302 309 if (sResourceName == "") 310 { 311 return dtRet; 312 } 313 314 return dtRet; 303 return dtRet; 315 304 } 316 305 … … 370 359 } 371 360 361 /// <summary> 362 /// This gets a datatable which shows the appointments between start and end time, one row per appointment 363 /// </summary> 364 /// <param name="docManager"></param> 365 /// <param name="sResourceName"></param> 366 /// <param name="StartTime"></param> 367 /// <param name="EndTime"></param> 368 /// <param name="stType"></param> 369 /// <returns>DataTable with 4 columns: START_TIME, END_TIME, SLOTS, RESOURCE </returns> 372 370 public static DataTable CreateAppointmentSlotSchedule(CGDocumentManager docManager, string sResourceName, DateTime StartTime, DateTime EndTime, ScheduleType stType) 373 371 { 374 375 376 string sStart; 377 string sEnd; 378 //sStart = StartTime.ToString("M-d-yyyy"); 379 sStart = FMDateTime.Create(StartTime).DateOnly.FMDateString; 380 //sEnd = EndTime.ToString("M-d-yyyy"); 381 sEnd = FMDateTime.Create(EndTime).DateOnly.FMDateString; 382 383 string sSTType = (stType == ScheduleType.Resource ? "ST_RESOURCE" : "ST_CLINIC"); 372 //Change Dates to FM Format 373 string sStart = FMDateTime.Create(StartTime).DateOnly.FMDateString; 374 string sEnd = FMDateTime.Create(EndTime).DateOnly.FMDateString; 375 376 string sSTType = (stType == ScheduleType.Resource ? "ST_RESOURCE" : "ST_CLINIC"); 384 377 string sSql = "BSDX APPT BLOCKS OVERLAP^" + sStart + "^" + sEnd + "^" + sResourceName ;//+ "^" + sSTType; 385 378 379 //This gets you a table with 2 columns containing start and end time for each appt 380 //Each appt gets its own row 386 381 DataTable dtRet = docManager.RPMSDataTable(sSql, "AppointmentSlotSchedule"); 387 382 … … 390 385 391 386 //Create CDateTimeArray & load records from rsOut 392 int nRC; 393 nRC = dtRet.Rows.Count; 387 int nRC = dtRet.Rows.Count; // nRC is row count from Appointments table just retrieved 394 388 ArrayList cdtArray = new ArrayList(); 395 cdtArray.Capacity = (nRC * 2); 389 cdtArray.Capacity = (nRC * 2); //new ArrayList has capacity double that of appointment table 396 390 DateTime v; 397 391 int i = 0; 398 392 399 foreach (DataRow r in dtRet.Rows) 393 //for each row in the Appointment Table, ArrayList cdtArray gets 2 entries: Start and End times 394 foreach (DataRow r in dtRet.Rows) 400 395 { 401 396 v = (DateTime) r[dtRet.Columns["START_TIME"]]; … … 404 399 cdtArray.Add(v); 405 400 } 401 402 //Sort start and end times (for use in ScheduleFromArray method) 406 403 cdtArray.Sort(); 407 404 408 405 //Create a CTimeBlockArray and load it from rsOut 409 406 407 //Now, create a new ArrayList with the size of the appointment table to hold availabilities 410 408 ArrayList ctbAppointments = new ArrayList(nRC); 411 409 CGAvailability cTB; 412 410 i = 0; 411 //For each appointment, create an availability 413 412 foreach (DataRow r in dtRet.Rows) 414 413 { … … 421 420 //Create a TimeBlock Array from the data in the DateTime array 422 421 ArrayList ctbApptSchedule = new ArrayList(); 422 423 //Convert Appointments to Availabilities, where all appointments become squeezed together. 423 424 ScheduleFromArray(cdtArray, StartTime, EndTime, ref ctbApptSchedule); 424 425 //Find number of TimeBlocks in ctbApptSchedule that 426 //overlap the TimeBlocks in ctbAppointments 425 426 /*So far, we have the following: 427 * dtRet -> List of Appointments Start and End times, one row per appointment 428 * cdtArray -> Linear 1 dimensional Array of dtRet Start and End times, sorted 429 * ctbAppointments -> Arraylist of dtRet as Availabilities 430 * ctbApptSchedule -> Arraylist of dtRet as Availabilities with no overlapping boundaries 431 * (overlaps in appointments get converted into availabilties themselves: so 432 * 2 appts as 10:10-10:30 and 10:20-10:40 get converted into 10:10-10:20, 433 * 10:20-10:30, 10:30-10:40). 434 */ 435 436 //Find number of TimeBlocks in ctbApptSchedule that overlap the TimeBlocks in ctbAppointments 427 437 ArrayList ctbApptSchedule2 = new ArrayList(); 428 438 CGAvailability cTB2; 429 439 int nSlots = 0; 430 for (i=0; i< ctbApptSchedule.Count; i++) 440 for (i=0; i< ctbApptSchedule.Count; i++) //for each non-overlapping appts as availabilities 431 441 { 432 442 cTB = (CGAvailability) ctbApptSchedule[i]; 433 nSlots = BlocksOverlap(cTB, ctbAppointments); 443 //How many times does the non-overlapping part show up in an appointment slot? 444 nSlots = BlocksOverlap(cTB, ctbAppointments); 434 445 cTB2 = new CGAvailability(); 435 446 cTB2.Create(cTB.StartTime, cTB.EndTime, nSlots); … … 532 543 } 533 544 534 //BOOL CResourceLink::TimesOverlap(COleDateTime dStart1, COleDateTime dEnd1, COleDateTime dStart2, COleDateTime dEnd2) 545 /// <summary> 546 /// Does an appointment overlap with another appointment in the same day? 547 /// </summary> 548 /// <param name="dStart1">Start Time of First Appt</param> 549 /// <param name="dEnd1">End Time of First Appt</param> 550 /// <param name="dStart2">Start Time of Second Appt</param> 551 /// <param name="dEnd2">End Time of Second Appt</param> 552 /// <returns>true or false</returns> 553 /// <remarks>Draws 2 rectangles and sees if they overlap using minutes from 1980 as the start point</remarks> 535 554 public static bool TimesOverlap(DateTime dStart1, DateTime dEnd1, DateTime dStart2, DateTime dEnd2) 536 555 { … … 667 686 Debug.Assert(rs1 != null); 668 687 Debug.Assert(rs2 != null); 669 CGSchedLib.OutputArray(rs1, "UnionBlocks rs1");670 CGSchedLib.OutputArray(rs2, "UnionBlocks rs2");671 688 672 689 DataTable rsCopy; … … 798 815 } 799 816 800 public static void ScheduleFromArray(ArrayList cdtArray, DateTime dStartTime, DateTime dEndTime, ref ArrayList rTBArray) 817 /// <summary> 818 /// Converts an Array of Times like this: 819 /// 10:00 10:00 10:20 10:20 10:30 10:30 10:30 10:40 820 /// To an array of availabilities like this: 821 /// 12:00-10:00 10:00-10:20 10:20-10:30 10:30-10:40 822 /// Where the 12:00 comes from the start time 823 /// </summary> 824 /// <param name="cdtArray">ArrayList containing start and end times of Appointments combmined and sorted</param> 825 /// <param name="dStartTime">Start Time for Schedule</param> 826 /// <param name="dEndTime">End Time for Schedule</param> 827 /// <param name="rTBArray">Output of Availabilities: Pass Empty</param> 828 public static void ScheduleFromArray(ArrayList cdtArray, DateTime dStartTime, DateTime dEndTime, 829 ref ArrayList rTBArray) 801 830 { 802 831 int j = 0; … … 812 841 if (dStartTime.Ticks > 0) 813 842 { 814 if ((DateTime) cdtArray[0] > dStartTime) 843 // if first Array Entry greater than start time, then create an availability 844 // with the start time as dStartTime, and end time as the first array entry, and 0 slots 845 // then add this to the output array 846 if ((DateTime) cdtArray[0] > dStartTime) 815 847 { 816 848 cTB = new CGAvailability(); … … 818 850 rTBArray.Add(cTB); 819 851 } 852 853 // if first Array Entry less than start time (shouldn't happen), 854 // convert all input array's times less than the start time to all be the start time 820 855 if ((DateTime) cdtArray[0] < dStartTime) 821 856 { … … 829 864 830 865 //Trim the end if necessary 866 //If end time is passed, set all the times in the original array greater 867 //than the end time to be the end time (Shouldn't happen). 831 868 if (dEndTime.Ticks > 0) 832 869 { … … 839 876 840 877 //build the schedule in rTBArray 841 DateTime dTemp = new DateTime(); 878 DateTime dTemp = new DateTime(); //hold previous appt time. 842 879 DateTime dStart; 843 880 DateTime dEnd; 844 881 int k = 0; 845 for (j = 0; j < (cdtArray.Count -1); j++) //TODO: why minus 1? 882 //for each time in appointment array 883 for (j = 0; j < (cdtArray.Count -1); j++) // -1 b/c k below starts with j+1. 846 884 { 847 885 if ((DateTime) cdtArray[j] != dTemp) … … 849 887 dStart =(DateTime) cdtArray[j]; 850 888 dTemp = dStart; 889 890 //for each time in appointment array, starting with the next one 851 891 for (k = j+1; k < cdtArray.Count; k++) 852 892 { 853 893 dEnd = new DateTime(); 854 if ((DateTime) cdtArray[k] != dStart) 894 if ((DateTime) cdtArray[k] != dStart) //if the next time isn't the same 855 895 { 856 dEnd = (DateTime) cdtArray[k]; 896 dEnd = (DateTime) cdtArray[k]; // set the end to be the next time 857 897 } 858 if (dEnd.Ticks > 0) 898 if (dEnd.Ticks > 0) //make a new availability and add it to the output array. 859 899 { 860 900 cTB = new CGAvailability(); … … 863 903 break; 864 904 } 905 // if the end time is still empty, loop 865 906 } 866 907 }
Note:
See TracChangeset
for help on using the changeset viewer.