/// <summary> /// Delete the TimeSlots based in [slotLevel] that applies for the [fsTimeSlotRow]. /// </summary> public virtual void DeleteTimeSlotsByLevel(FSTimeSlot fsTimeSlotRow, int slotLevel) { using (var ts = new PXTransactionScope()) { List <object> cmdArg = new List <object>(); TimeSlotMaint timeSlotMaintGraph = PXGraph.CreateInstance <TimeSlotMaint>(); DateHandler dateHandler = new DateHandler(Convert.ToDateTime(fsTimeSlotRow.TimeStart)); PXSelectBase <FSTimeSlot> fsTimeSlotsBaseToDelete = new PXSelect <FSTimeSlot, Where < FSTimeSlot.branchID, Equal <Required <FSTimeSlot.branchID> >, And <FSTimeSlot.employeeID, Equal <Required <FSTimeSlot.employeeID> >, And <FSTimeSlot.slotLevel, Equal <Required <FSTimeSlot.slotLevel> >, And <FSTimeSlot.timeStart, GreaterEqual <Required <FSTimeSlot.timeStart> >, And <FSTimeSlot.timeStart, LessEqual <Required <FSTimeSlot.timeStart> > > > > > > > (timeSlotMaintGraph); cmdArg.Add(fsTimeSlotRow.BranchID); cmdArg.Add(fsTimeSlotRow.EmployeeID); cmdArg.Add(slotLevel); cmdArg.Add(dateHandler.StartOfDay()); cmdArg.Add(dateHandler.BeginOfNextDay()); if (fsTimeSlotRow.BranchLocationID != null) { fsTimeSlotsBaseToDelete.WhereAnd <Where <FSTimeSlot.branchLocationID, Equal <Required <FSTimeSlot.branchLocationID> > > >(); cmdArg.Add(fsTimeSlotRow.BranchLocationID); } var fsTimeSlotSet = fsTimeSlotsBaseToDelete.Select(cmdArg.ToArray()); foreach (FSTimeSlot fsTimeSlotRow_ToDelete in fsTimeSlotSet) { timeSlotMaintGraph.TimeSlotRecords.Delete(fsTimeSlotRow_ToDelete); } timeSlotMaintGraph.Save.Press(); ts.Complete(); } }
/// <summary> /// Creates the compressed Time Slots that applies for the [fsTimeSlotRow]. /// </summary> public virtual void CreateAndCompressedTimeSlots(FSTimeSlot fsTimeSlotRow, TimeSlotMaint timeSlotMaintGraph) { List <object> cmdArg = new List <object>(); List <FSTimeSlot> fsTimeSlotListToCompress = new List <FSTimeSlot>(); List <Scheduler.Slot> slotListToCompress = new List <Scheduler.Slot>(); var fsBranchLocationSet = PXSelect <FSBranchLocation, Where < FSBranchLocation.branchID, Equal <Required <FSBranchLocation.branchID> > >, OrderBy < Asc <FSBranchLocation.branchLocationID> > > .Select(timeSlotMaintGraph, fsTimeSlotRow.BranchID); DateHandler dateHandler = new DateHandler(SharedFunctions.TryParseHandlingDateTime(timeSlotMaintGraph.TimeSlotRecords.Cache, fsTimeSlotRow.TimeStart)); PXSelectBase <FSTimeSlot> fsTimeSlotsBaseToCompress = new PXSelect <FSTimeSlot, Where < FSTimeSlot.branchID, Equal <Required <FSTimeSlot.branchID> >, And <FSTimeSlot.employeeID, Equal <Required <FSTimeSlot.employeeID> >, And <FSTimeSlot.slotLevel, Equal <Required <FSTimeSlot.slotLevel> >, And <FSTimeSlot.timeStart, GreaterEqual <Required <FSTimeSlot.timeStart> >, And <FSTimeSlot.timeStart, LessEqual <Required <FSTimeSlot.timeStart> > > > > > > > (timeSlotMaintGraph); cmdArg.Add(fsTimeSlotRow.BranchID); cmdArg.Add(fsTimeSlotRow.EmployeeID); cmdArg.Add(ID.EmployeeTimeSlotLevel.BASE); cmdArg.Add(dateHandler.StartOfDay()); cmdArg.Add(dateHandler.BeginOfNextDay()); if (fsTimeSlotRow.BranchLocationID != null) { fsTimeSlotsBaseToCompress.WhereAnd <Where <FSTimeSlot.branchLocationID, Equal <Required <FSTimeSlot.branchLocationID> > > >(); cmdArg.Add(fsTimeSlotRow.BranchLocationID); } var fsTimeSlotSet = fsTimeSlotsBaseToCompress.Select(cmdArg.ToArray()); foreach (FSTimeSlot fsTimeSlotRow_ToCompress in fsTimeSlotSet) { fsTimeSlotListToCompress.Add(fsTimeSlotRow_ToCompress); } var groupedSlotList = fsTimeSlotListToCompress .GroupBy(u => u.BranchLocationID == null ? -1 : u.BranchLocationID) .Select(group => new { BranchLocationID = group.Key, FSTimeSlots = group.ToList() }) .OrderBy(group => group.BranchLocationID) .ToList(); List <Scheduler.Slot> compressedSlots = new List <Scheduler.Slot>(); foreach (FSBranchLocation fsBranchLocationRow in fsBranchLocationSet) { var existingBranchLocationList = groupedSlotList .Select(bl => new { BranchLocationID = bl.BranchLocationID, FSTimeSlot = bl.FSTimeSlots.ToList() }) .Where(S => S.BranchLocationID == fsBranchLocationRow.BranchLocationID).ToList(); fsTimeSlotListToCompress.Clear(); slotListToCompress.Clear(); if (existingBranchLocationList.Count > 0) { fsTimeSlotListToCompress = existingBranchLocationList[0].FSTimeSlot; } if (groupedSlotList.Count > 0 && groupedSlotList[0].BranchLocationID == -1) { fsTimeSlotListToCompress = fsTimeSlotListToCompress.Concat(groupedSlotList[0].FSTimeSlots).ToList(); } foreach (FSTimeSlot fsTimeSlotRow_ToCompress in fsTimeSlotListToCompress) { slotListToCompress.Add(ConvertFSTimeSlotToSlot(fsTimeSlotRow_ToCompress)); } if (slotListToCompress.Count > 0) { fsTimeSlotRow.BranchLocationID = fsBranchLocationRow.BranchLocationID; CreateCompressedSlots(CompressAndIntersectSlots(slotListToCompress).ToList(), fsTimeSlotRow); } } }