Example #1
0
        public void TestPostalServiceShifts()
        {
            // United States Postal Service
            schedule = new WorkSchedule("USPS", "Six 9 hr shifts, rotating every 42 days");

            // shift, start at 08:00 for 9 hours
            Shift day = schedule.CreateShift("Day", "day shift", new LocalTime(8, 0, 0), Duration.FromHours(9));

            Rotation rotation = new Rotation("Day", "Day");

            rotation.AddSegment(day, 3, 7);
            rotation.AddSegment(day, 1, 7);
            rotation.AddSegment(day, 1, 7);
            rotation.AddSegment(day, 1, 7);
            rotation.AddSegment(day, 1, 7);

            LocalDate rotationStart = new LocalDate(2017, 1, 27);

            // day teams
            schedule.CreateTeam("Team A", "A team", rotation, rotationStart);
            schedule.CreateTeam("Team B", "B team", rotation, rotationStart.Minus(Period.FromDays(7)));
            schedule.CreateTeam("Team C", "C team", rotation, rotationStart.Minus(Period.FromDays(14)));
            schedule.CreateTeam("Team D", "D team", rotation, rotationStart.Minus(Period.FromDays(21)));
            schedule.CreateTeam("Team E", "E team", rotation, rotationStart.Minus(Period.FromDays(28)));
            schedule.CreateTeam("Team F", "F team", rotation, rotationStart.Minus(Period.FromDays(35)));

            runBaseTest(schedule, Duration.FromHours(63), Duration.FromDays(42), rotationStart);
        }
Example #2
0
        public void UpdateWorkSchedule(WorkSchedule workSchedule)
        {
            String error = "";

            if (DateTime.Compare(workSchedule.workSchedule_date, DateTime.Today) > 0)
            {
                error += "התאריך שהזנת שגוי, תאריך עתידי טרם נקבע סידור עבודה";
            }
            if (selectDistributors(d => d.distributors_id == workSchedule.distributor_id).Count == 0)
            {
                error += "תעודת זהות של מחלק לא קיימת במערכת";
            }
            if (error == "")
            {
                try
                {
                    dalImp.UpdateWorkSchedule(workSchedule);
                }
                catch (Exception exp)
                {
                    throw exp;
                }
            }

            else
            {
                throw new Exception(error);
            }
        }
Example #3
0
        protected void runBaseTest(WorkSchedule ws, Duration hoursPerRotation, Duration rotationDays,
                                   LocalDate instanceReference)
        {
            // toString
            if (testToString)
            {
                Console.WriteLine(ws.ToString());
                ws.PrintShiftInstances(instanceReference, instanceReference.PlusDays(rotationDays.Days));
            }

            Assert.IsTrue(ws.Name.Length > 0);
            Assert.IsTrue(ws.Description.Length > 0);
            Assert.IsTrue(ws.NonWorkingPeriods != null);

            // shifts
            TestShifts(ws);

            // teams
            TestTeams(ws, hoursPerRotation, rotationDays);

            // shift instances
            TestShiftInstances(ws, instanceReference);

            if (testDeletions)
            {
                TestDeletions();
            }
        }
Example #4
0
 public void Send(WorkSchedule model)
 {
     try
     {
         _log.Info("班次{0},开始同步", model.Code);
         string url = string.Format("{0}/PosSync/WorkScheduleSync", _serverUrl);
         var    dateTimeConverter = new IsoDateTimeConverter {
             DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
         };
         string body = JsonConvert.SerializeObject(model, dateTimeConverter);
         body = HttpHelper.UrlEncode(body); //Url编码
         string param  = string.Format("{0}&body={1}", BuildAccessToken(), body);
         string result = HttpHelper.HttpPost(url, param);
         if (result == "1")
         {
             if (model.EndBy > 0 && model.CashAmount > 0)
             {
                 string sql = @"Update WorkSchedule set IsSync=1 where @Id=@Id";
                 _db.ExecuteSql(sql, new { Id = model.Id });
                 _log.Info("班次{0}设置金额已同步", model.Code);
             }
             _log.Info("班次{0}数据已上传", model.Code);
         }
         else
         {
             _log.Info("班次{0},同步失败:{1}", model.Code, result);
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex);
     }
 }
Example #5
0
        public static WorkSchedule GetWeeklySchedule(int wsid)
        {
            List <Tuple <string, object> > args = new List <Tuple <string, object> >();

            args.Add(new Tuple <string, object>("WSID", wsid));
            var ds = GetDataSet("sp_GetWeeklySchedule", args);

            WorkSchedule ws       = new WorkSchedule(wsid, GetWeekStartDate());
            var          workers  = GetWorkers();
            var          stations = GetStations();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                var    row       = ds.Tables[0].Rows[i];
                int    shift     = (int)row["ShiftTime"];
                int    day       = (int)row["Day"];
                int    stationId = (int)row["StationId"];
                string workerId  = row["WorkerId"].ToString();
                var    worker    = workers.Find(x => x.IdNumber.TrimStart('0') == workerId);
                var    station   = stations.Find(x => x.Id == stationId);

                int shiftIndex = Shift.GetShiftIndex((DayOfWeek)day, (PartOfDay)shift);

                var currentStation = ws.Schedule.Shifts[shiftIndex].Stations.Find(x => x.Id == station.Id);
                if (currentStation == null)
                {
                    currentStation = new Station(station);
                    ws.Schedule.Shifts[shiftIndex].Stations.Add(currentStation);
                }

                currentStation.Workers.Add(worker);
            }

            return(ws);
        }
        public void Equals_BIsNull_ReturnsFalse()
        {
            WorkSchedule A = WorkSchedule.MaxValue;
            WorkSchedule B = null;

            Expect(() => A.Equals(B), Is.False);
        }
Example #7
0
        public void TestICUInterns()
        {
            string description = "This plan supports a combination of 14-hr day shift , 15.5-hr cross-cover shift , and a 14-hr night shift for medical interns. "
                                 + "The day shift and the cross-cover shift have the same start time (7:00AM). "
                                 + "The night shift starts at around 10:00PM and ends at 12:00PM on the next day.";

            schedule = new WorkSchedule("ICU Interns Plan", description);

            // Day shift #1, starts at 07:00 for 15.5 hours
            Shift crossover = schedule.CreateShift("Crossover", "Day shift #1 cross-over", new LocalTime(7, 0, 0),
                                                   Duration.FromHours(15).Plus(Duration.FromMinutes(30)));

            // Day shift #2, starts at 07:00 for 14 hours
            Shift day = schedule.CreateShift("Day", "Day shift #2", new LocalTime(7, 0, 0), Duration.FromHours(14));

            // Night shift, starts at 22:00 for 14 hours
            Shift night = schedule.CreateShift("Night", "Night shift", new LocalTime(22, 0, 0), Duration.FromHours(14));

            // Team1 rotation
            Rotation rotation = schedule.CreateRotation("ICU", "ICU");

            rotation.AddSegment(day, 1, 0);
            rotation.AddSegment(crossover, 1, 0);
            rotation.AddSegment(night, 1, 1);

            schedule.CreateTeam("Team 1", "First team", rotation, referenceDate);
            schedule.CreateTeam("Team 2", "Second team", rotation, referenceDate.PlusDays(-3));
            schedule.CreateTeam("Team 3", "Third team", rotation, referenceDate.PlusDays(-2));
            schedule.CreateTeam("Team 4", "Forth team", rotation, referenceDate.PlusDays(-1));

            RunBaseTest(schedule, Duration.FromMinutes(2610), Duration.FromDays(4), referenceDate);
        }
Example #8
0
 public WorkScheduleDetailUI()
 {
     InitializeComponent();
     lId            = "";
     lOperation     = GlobalVariables.Operation.Add;
     loWorkSchedule = new WorkSchedule();
 }
        private void tsmWorkSchedule_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (TabPage _tab in this.tbcNSites_V.TabPages)
                {
                    if (_tab.Text == "WorkSchedule List")
                    {
                        tbcNSites_V.SelectedTab = _tab;
                        return;
                    }
                }

                WorkSchedule   _WorkSchedule = new WorkSchedule();
                Type           _Type         = typeof(WorkSchedule);
                ListFormHRISUI _ListForm     = new ListFormHRISUI((object)_WorkSchedule, _Type);
                TabPage        _ListFormTab  = new TabPage();
                _ListFormTab.ImageIndex = 24;
                _ListForm.ParentList    = this;
                displayControlOnTab(_ListForm, _ListFormTab);
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "tsmWorkSchedule_Click");
                em.ShowDialog();
                return;
            }
        }
        public void Equals_AIsEqualToB_ReturnsTrue()
        {
            WorkSchedule A = WorkSchedule.MaxValue;
            WorkSchedule B = WorkSchedule.MaxValue;

            Expect(() => A.Equals(B), Is.True);
        }
        public IHttpActionResult PutWorkSchedule(int id, WorkSchedule workSchedule)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != workSchedule.WorkScheduleID)
            {
                return(BadRequest());
            }

            db.Entry(workSchedule).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkScheduleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void Deliver(WorkSchedule workSchedule, byte[] exportedWorkSchedule, WorkScheduleDeliveryOptions options)
        {
            var bodyBuilder = new BodyBuilder();

            bodyBuilder.TextBody = $"Här kommer ditt exporterade arbetsschema.";
            bodyBuilder.Attachments.Add("Arbetsschema.ics", new MemoryStream(exportedWorkSchedule));

            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(configuration.From));
            message.To.Add(new MailboxAddress(options.Target));
            message.Subject = $"Ditt exporterade arbetsschema";
            message.Body    = bodyBuilder.ToMessageBody();

            using (SmtpClient client = new SmtpClient())
            {
                client.Connect(configuration.Host, configuration.Port, configuration.UseSsl);

                if (configuration.ContainCredentials)
                {
                    client.Authenticate(configuration.Username, configuration.Password);
                }

                client.Send(message);
                client.Disconnect(true);
            }
        }
        public byte[] Export(WorkSchedule workSchedule)
        {
            var iCal = new Calendar
            {
                Method  = "PUBLISH",
                Version = "2.0",
            };

            foreach (WorkShift workShift in workSchedule.WorkShifts)
            {
                if (workShift.WorkCode.Contains("*"))
                {
                    continue;
                }

                var calendarEvent = iCal.Create <CalendarEvent>();
                calendarEvent.Class       = "PUBLIC";
                calendarEvent.Summary     = workShift.WorkCode;
                calendarEvent.Start       = new CalDateTime(workShift.Start);
                calendarEvent.End         = new CalDateTime(workShift.End);
                calendarEvent.Duration    = workShift.Duration;
                calendarEvent.Description = workShift.Notes;
                calendarEvent.IsAllDay    = false;
            }

            string calendarContent = new CalendarSerializer().SerializeToString(iCal);

            return(Encoding.UTF8.GetBytes(calendarContent));
        }
Example #14
0
        public void TestDupont()
        {
            string description = "The DuPont 12-hour rotating shift schedule uses 4 teams (crews) and 2 twelve-hour shifts to provide 24/7 coverage. "
                                 + "It consists of a 4-week cycle where each team works 4 consecutive night shifts, "
                                 + "followed by 3 days off duty, works 3 consecutive day shifts, followed by 1 day off duty, works 3 consecutive night shifts, "
                                 + "followed by 3 days off duty, work 4 consecutive day shift, then have 7 consecutive days off duty. "
                                 + "Personnel works an average 42 hours per week.";

            schedule = new WorkSchedule("DuPont Shift Schedule", description);

            // Day shift, starts at 07:00 for 12 hours
            Shift day = schedule.CreateShift("Day", "Day shift", new LocalTime(7, 0, 0), Duration.FromHours(12));

            // Night shift, starts at 19:00 for 12 hours
            Shift night = schedule.CreateShift("Night", "Night shift", new LocalTime(19, 0, 0), Duration.FromHours(12));

            // Team1 rotation
            Rotation rotation = schedule.CreateRotation("DuPont", "DuPont");

            rotation.AddSegment(night, 4, 3);
            rotation.AddSegment(day, 3, 1);
            rotation.AddSegment(night, 3, 3);
            rotation.AddSegment(day, 4, 7);

            schedule.CreateTeam("Team 1", "First team", rotation, referenceDate);
            schedule.CreateTeam("Team 2", "Second team", rotation, referenceDate.PlusDays(-7));
            schedule.CreateTeam("Team 3", "Third team", rotation, referenceDate.PlusDays(-14));
            schedule.CreateTeam("Team 4", "Forth team", rotation, referenceDate.PlusDays(-21));

            RunBaseTest(schedule, Duration.FromHours(168), Duration.FromDays(28), referenceDate);
        }
        public async Task <IdResponse> HandleAsync(AssignUserToShiftCommand cmd, CancellationToken ct)
        {
            // if guid is empty delete employee from shift
            if (cmd.Id.Equals(Guid.Empty))
            {
                var assignedUser = new WorkSchedule
                {
                    Id      = cmd.Id,
                    ShiftId = cmd.ShiftId
                };

                var result = await _workScheduleRepository.DeleteByTAsync(assignedUser);

                return(new IdResponse(assignedUser.Id));
            }

            var shift = await _workScheduleRepository.GetByIdAsync(cmd.ShiftId);

            await _workScheduleRepository.DeleteByTAsync(shift);

            await _workScheduleRepository.InsertAsync(new WorkSchedule
            {
                Id      = cmd.Id,
                ShiftId = cmd.ShiftId
            });

            return(new IdResponse(cmd.Id));
        }
Example #16
0
        public IActionResult Index(WorkScheduleExportViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            IWorkScheduleReader workScheduleReader = workScheduleReaderFactory.Create(model.SchemaFile.OpenReadStream());
            WorkSchedule        workSchedule       = workScheduleReader.Read();

            byte[] exportedSchema = workScheduleExporter.Export(workSchedule);

            if (model.ContainsEmail)
            {
                deliveryService.Deliver(workSchedule, exportedSchema, new WorkScheduleDeliveryOptions {
                    Target = model.Email
                });

                ViewBag.SuccessMessage = "Ditt schema har nu skickats till din e-post";

                return(View());
            }

            return(new FileContentResult(exportedSchema, "text/calendar")
            {
                FileDownloadName = "Arbetsschema.ics"
            });
        }
Example #17
0
        public void TestTwoTeam()
        {
            string description = "This is a fixed (no rotation) plan that uses 2 teams and two 12-hr shifts to provide 24/7 coverage. "
                                 + "One team will be permanently on the day shift and the other will be on the night shift.";

            schedule = new WorkSchedule("2 Team Fixed 12 Plan", description);

            // Day shift, starts at 07:00 for 12 hours
            Shift day = schedule.CreateShift("Day", "Day shift", new LocalTime(7, 0, 0), Duration.FromHours(12));

            // Night shift, starts at 19:00 for 12 hours
            Shift night = schedule.CreateShift("Night", "Night shift", new LocalTime(19, 0, 0), Duration.FromHours(12));

            // Team1 rotation
            Rotation team1Rotation = schedule.CreateRotation("Team1", "Team1");

            team1Rotation.AddSegment(day, 1, 0);

            // Team1 rotation
            Rotation team2Rotation = schedule.CreateRotation("Team2", "Team2");

            team2Rotation.AddSegment(night, 1, 0);

            schedule.CreateTeam("Team 1", "First team", team1Rotation, referenceDate);
            schedule.CreateTeam("Team 2", "Second team", team2Rotation, referenceDate);

            RunBaseTest(schedule, Duration.FromHours(12), Duration.FromDays(1), referenceDate);
        }
Example #18
0
        public void Test549()
        {
            string description = "Compressed work schedule.";

            schedule = new WorkSchedule("5/4/9 Plan", description);

            // Shift 1 starts at 07:00 for 9 hours
            Shift day1 = schedule.CreateShift("Day1", "Day shift #1", new LocalTime(7, 0, 0), Duration.FromHours(9));

            // Shift 2 starts at 07:00 for 8 hours
            Shift day2 = schedule.CreateShift("Day2", "Day shift #2", new LocalTime(7, 0, 0), Duration.FromHours(8));

            // Team rotation (28 days)
            Rotation rotation = schedule.CreateRotation("5/4/9 ", "5/4/9 ");

            rotation.AddSegment(day1, 4, 0);
            rotation.AddSegment(day2, 1, 3);
            rotation.AddSegment(day1, 4, 3);
            rotation.AddSegment(day1, 4, 2);
            rotation.AddSegment(day1, 4, 0);
            rotation.AddSegment(day2, 1, 2);

            // 2 teams
            schedule.CreateTeam("Team1", "First team", rotation, referenceDate);
            schedule.CreateTeam("Team2", "Second team", rotation, referenceDate.PlusDays(-14));

            RunBaseTest(schedule, Duration.FromHours(160), Duration.FromDays(28), referenceDate);
        }
Example #19
0
        public void TestDNO()
        {
            string description = "This is a fast rotation plan that uses 3 teams and two 12-hr shifts to provide 24/7 coverage. "
                                 + "Each team rotates through the following sequence every three days: 1 day shift, 1 night shift, and 1 day off.";

            schedule = new WorkSchedule("DNO Plan", description);

            // Day shift, starts at 07:00 for 12 hours
            Shift day = schedule.CreateShift("Day", "Day shift", new LocalTime(7, 0, 0), Duration.FromHours(12));

            // Night shift, starts at 19:00 for 12 hours
            Shift night = schedule.CreateShift("Night", "Night shift", new LocalTime(19, 0, 0), Duration.FromHours(12));

            // rotation
            Rotation rotation = schedule.CreateRotation("DNO", "DNO");

            rotation.AddSegment(day, 1, 0);
            rotation.AddSegment(night, 1, 1);

            schedule.CreateTeam("Team 1", "First team", rotation, referenceDate);
            schedule.CreateTeam("Team 2", "Second team", rotation, referenceDate.PlusDays(-1));
            schedule.CreateTeam("Team 3", "Third team", rotation, referenceDate.PlusDays(-2));

            // rotation working time
            LocalDateTime from     = referenceDate.PlusDays(rotation.GetDayCount()).At(new LocalTime(7, 0, 0));
            Duration      duration = schedule.CalculateWorkingTime(from, from.PlusDays(3));

            Assert.IsTrue(duration.Equals(Duration.FromHours(72)));

            RunBaseTest(schedule, Duration.FromHours(24), Duration.FromDays(3), referenceDate);
        }
Example #20
0
        public void TestLowNight()
        {
            string description = "Low night demand";

            schedule = new WorkSchedule("Low Night Demand Plan", description);

            // 3 shifts
            Shift day   = schedule.CreateShift("Day", "Day shift", new LocalTime(7, 0, 0), Duration.FromHours(8));
            Shift swing = schedule.CreateShift("Swing", "Swing shift", new LocalTime(15, 0, 0), Duration.FromHours(8));
            Shift night = schedule.CreateShift("Night", "Night shift", new LocalTime(23, 0, 0), Duration.FromHours(8));

            // Team rotation
            Rotation rotation = schedule.CreateRotation("Low night demand", "Low night demand");

            rotation.AddSegment(day, 3, 0);
            rotation.AddSegment(swing, 4, 3);
            rotation.AddSegment(day, 4, 0);
            rotation.AddSegment(swing, 3, 4);
            rotation.AddSegment(day, 3, 0);
            rotation.AddSegment(night, 4, 3);
            rotation.AddSegment(day, 4, 0);
            rotation.AddSegment(night, 3, 4);

            // 6 teams
            schedule.CreateTeam("Team1", "First team", rotation, referenceDate);
            schedule.CreateTeam("Team2", "Second team", rotation, referenceDate.PlusDays(-21));
            schedule.CreateTeam("Team3", "Third team", rotation, referenceDate.PlusDays(-7));
            schedule.CreateTeam("Team4", "Fourth team", rotation, referenceDate.PlusDays(-28));
            schedule.CreateTeam("Team5", "Fifth team", rotation, referenceDate.PlusDays(-14));
            schedule.CreateTeam("Team6", "Sixth team", rotation, referenceDate.PlusDays(-35));

            RunBaseTest(schedule, Duration.FromHours(224), Duration.FromDays(42), referenceDate);
        }
        public void Equals_AIsNotEqualToB_ReturnsFalse()
        {
            WorkSchedule A = WorkSchedule.MaxValue;
            WorkSchedule B = WorkSchedule.MinValue;

            Expect(() => A.Equals(B), Is.False);
        }
Example #22
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 19, Configuration.FieldSeparator),
                       Id,
                       SetId.HasValue ? SetId.Value.ToString(culture) : null,
                       ActionCode,
                       EnteredDate.HasValue ? EnteredDate.Value.ToString(Consts.DateFormatPrecisionDay, culture) : null,
                       Occupation?.ToDelimitedString(),
                       Industry?.ToDelimitedString(),
                       WorkClassification?.ToDelimitedString(),
                       JobStartDate.HasValue ? JobStartDate.Value.ToString(Consts.DateFormatPrecisionDay, culture) : null,
                       JobEndDate.HasValue ? JobEndDate.Value.ToString(Consts.DateFormatPrecisionDay, culture) : null,
                       WorkSchedule?.ToDelimitedString(),
                       AverageHoursWorkedPerDay.HasValue ? AverageHoursWorkedPerDay.Value.ToString(Consts.NumericFormat, culture) : null,
                       AverageDaysWorkedPerWeek.HasValue ? AverageDaysWorkedPerWeek.Value.ToString(Consts.NumericFormat, culture) : null,
                       EmployerOrganization?.ToDelimitedString(),
                       EmployerAddress != null ? string.Join(Configuration.FieldRepeatSeparator, EmployerAddress.Select(x => x.ToDelimitedString())) : null,
                       SupervisoryLevel?.ToDelimitedString(),
                       JobDuties != null ? string.Join(Configuration.FieldRepeatSeparator, JobDuties) : null,
                       OccupationalHazards != null ? string.Join(Configuration.FieldRepeatSeparator, OccupationalHazards) : null,
                       JobUniqueIdentifier?.ToDelimitedString(),
                       CurrentJobIndicator?.ToDelimitedString()
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
Example #23
0
        public async Task <ActionResult <Candidate> > PostCandidate(Candidate candidate)
        {
            WorkLoad     workLoad     = candidate.WorkLoad;
            WorkSchedule workSchedule = candidate.WorkSchedule;
            List <CandidateKnowledge> candidateKnowledges        = candidate.CandidateKnowledges;
            List <CandidateKnowledge> candidateKnowledgesForSave = new List <CandidateKnowledge>();

            candidate.WorkSchedule = null;
            candidate.WorkLoad     = null;
            _context.Candidates.Add(candidate);
            await _context.SaveChangesAsync();

            workLoad.CandidateId = candidate.Id;
            _context.WorkLoads.Add(workLoad);
            workSchedule.CandidateId = candidate.Id;
            _context.WorkSchedules.Add(workSchedule);
            await _context.SaveChangesAsync();

            foreach (CandidateKnowledge item in candidateKnowledges)
            {
                CandidateKnowledge candidateKnowledge = new CandidateKnowledge();
                candidateKnowledge.CandidateId = candidate.Id;
                candidateKnowledge.KnowledgeId = item.KnowledgeId;
                candidateKnowledge.Rate        = item.Rate;
                candidateKnowledgesForSave.Add(candidateKnowledge);
                //_context.CandidateKnowledges.Add(candidateKnowledge);
                //await _context.SaveChangesAsync();
            }
            _context.CandidateKnowledges.AddRange(candidateKnowledgesForSave);
            await _context.SaveChangesAsync();

            candidate.WorkSchedule = null;
            candidate.WorkLoad     = null;
            return(candidate);
        }
Example #24
0
        public void TestManufacturingShifts()
        {
            // manufacturing company
            schedule = new WorkSchedule("Manufacturing Company - four twelves",
                                        "Four 12 hour alternating day/night shifts");

            // day shift, start at 07:00 for 12 hours
            Shift day = schedule.CreateShift("Day", "Day shift", new LocalTime(7, 0, 0), Duration.FromHours(12));

            // night shift, start at 19:00 for 12 hours
            Shift night = schedule.CreateShift("Night", "Night shift", new LocalTime(19, 0, 0), Duration.FromHours(12));

            // 7 days ON, 7 OFF
            Rotation dayRotation = new Rotation("Day", "Day");

            dayRotation.AddSegment(day, 7, 7);

            // 7 nights ON, 7 OFF
            Rotation nightRotation = new Rotation("Night", "Night");

            nightRotation.AddSegment(night, 7, 7);

            schedule.CreateTeam("A", "A day shift", dayRotation, new LocalDate(2014, 1, 2));
            schedule.CreateTeam("B", "B night shift", nightRotation, new LocalDate(2014, 1, 2));
            schedule.CreateTeam("C", "C day shift", dayRotation, new LocalDate(2014, 1, 9));
            schedule.CreateTeam("D", "D night shift", nightRotation, new LocalDate(2014, 1, 9));

            runBaseTest(schedule, Duration.FromHours(84), Duration.FromDays(14), new LocalDate(2014, 1, 9));
        }
Example #25
0
        public void TestFirefighterShifts1()
        {
            // Kern Co, CA
            schedule = new WorkSchedule("Kern Co.", "Three 24 hour alternating shifts");

            // shift, start 07:00 for 24 hours
            Shift shift = schedule.CreateShift("24 Hour", "24 hour shift", new LocalTime(7, 0, 0), Duration.FromHours(24));

            // 2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF
            Rotation rotation = new Rotation("24 Hour", "2 days ON, 2 OFF, 2 ON, 2 OFF, 2 ON, 8 OFF");

            rotation.AddSegment(shift, 2, 2);
            rotation.AddSegment(shift, 2, 2);
            rotation.AddSegment(shift, 2, 8);

            Team platoon1 = schedule.CreateTeam("Red", "A Shift", rotation, new LocalDate(2017, 1, 8));
            Team platoon2 = schedule.CreateTeam("Black", "B Shift", rotation, new LocalDate(2017, 2, 1));
            Team platoon3 = schedule.CreateTeam("Green", "C Shift", rotation, new LocalDate(2017, 1, 2));

            List <ShiftInstance> instances = schedule.GetShiftInstancesForDay(new LocalDate(2017, 3, 1));

            Assert.IsTrue(instances.Count == 1);
            Assert.IsTrue(instances[0].Team.Equals(platoon3));

            instances = schedule.GetShiftInstancesForDay(new LocalDate(2017, 3, 3));
            Assert.IsTrue(instances.Count == 1);
            Assert.IsTrue(instances[0].Team.Equals(platoon1));

            instances = schedule.GetShiftInstancesForDay(new LocalDate(2017, 3, 9));
            Assert.IsTrue(instances.Count == 1);
            Assert.IsTrue(instances[0].Team.Equals(platoon2));

            runBaseTest(schedule, Duration.FromHours(144), Duration.FromDays(18), new LocalDate(2017, 2, 1));
        }
        // GET: WorkSchedules1/Details/5
        public ActionResult Details(int?id)
        {
            ViewBag.idError = id == null;
            WorkSchedule workSchedule = db.WorkScheudules.Find(id);

            ViewBag.schedule = workSchedule == null;
            return(View(workSchedule));
        }
Example #27
0
        public ActionResult DeleteConfirmed(int id)
        {
            WorkSchedule workSchedule = db.WorkSchedules.Find(id);

            db.WorkSchedules.Remove(workSchedule);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void Location_Update(Location item)
 {
     using (WorkSchedule context = new WorkSchedule())
     {
         context.Entry <Location>(context.Locations.Attach(item)).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
        public ActionResult Delete(int?id)
        {
            WorkSchedule workSchedule = db.WorkScheudules.Find(id);

            ViewBag.error         = id == null;
            ViewBag.scheduleError = workSchedule == null;
            return(View(workSchedule));
        }
Example #30
0
 public WorkScheduleDetailUI(string[] pRecords)
 {
     InitializeComponent();
     lId            = "";
     lOperation     = GlobalVariables.Operation.Edit;
     loWorkSchedule = new WorkSchedule();
     lRecords       = pRecords;
 }
Example #31
0
        private static decimal Calc(WorkSchedule obj, DateTime from, DateTime until, CalcModes what)
        {
            decimal result = 0;
            var rules = obj.RulesAndParents();

            while (from <= until)
            {
                WorkScheduleRule foundRule = null;
                // Find YearlyRule
                foundRule = rules.OfType<YearlyWorkScheduleRule>().FirstOrDefault(r => r.AppliesTo(from));
                // Find DayOfWeekRule
                if (foundRule == null)
                {
                    foundRule = rules.OfType<DayOfWeekWorkScheduleRule>().FirstOrDefault(r => r.AppliesTo(from));
                }
                // Find CommonRule
                if (foundRule == null)
                {
                    foundRule = rules.OfType<CommonWorkScheduleRule>().FirstOrDefault(r => r.AppliesTo(from));
                }

                if (foundRule != null)
                {
                    switch (what)
                    {
                        case CalcModes.WorkingHours:
                            result += foundRule.WorkingHours;
                            break;
                        case CalcModes.WorkingDays:
                            if (foundRule.IsWorkingDay)
                                result++;
                            break;
                        case CalcModes.OffDays:
                            if (!foundRule.IsWorkingDay)
                                result++;
                            break;
                    }
                }
                else
                {
                    Logging.Log.WarnFormat("No Calendar rule found in {0} for {1}", obj.Name, from);
                }

                from = from.AddDays(1);
            }

            return result;
        }
Example #32
0
 public static void GetWorkingHours(WorkSchedule obj, MethodReturnEventArgs<System.Decimal> e, System.DateTime from, System.DateTime until)
 {
     e.Result = Calc(obj, from, until, CalcModes.WorkingHours);
 }
Example #33
0
 public static void GetWorkingDays(WorkSchedule obj, MethodReturnEventArgs<System.Int32> e, System.DateTime from, System.DateTime until)
 {
     e.Result = (int)Calc(obj, from, until, CalcModes.WorkingDays);
 }
Example #34
0
 public static void ToString(WorkSchedule obj, MethodReturnEventArgs<System.String> e)
 {
     e.Result = obj.Name;
 }