private void BtnSetShift_Click(object sender, EventArgs e)
        {
            Shift    shift;
            DateTime date          = dateTimePicker.Value;
            decimal  wage          = Convert.ToDecimal(tbWage.Text);
            int      workersNeeded = Convert.ToInt32(tbWorkersNeeded.Text);

            if (rbMorning.Checked)
            {
                shift = Shift.Morning;
            }
            else if (rbAfternoon.Checked)
            {
                shift = Shift.Afternoon;
            }
            else
            {
                shift = Shift.Evening;
            }

            WorkShift addedShift = new WorkShift(shift, date, wage, workersNeeded);

            if (!CheckIfExists(addedShift))
            {
                this.shifts.Add(addedShift);
                this.UpdateListBox();
            }
            else
            {
                MessageBox.Show("This shift is already in the list");
            }
        }
Example #2
0
        private void AuthButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (UserComboBox.SelectedItem is User currentUser)
                {
                    if (PasswordBox.Password == currentUser.Password)
                    {
                        WorkShift workShift = new WorkShift {
                            UserID = currentUser.ID, Datetime = DateTime.Now
                        };

                        DbHelper.GetContext().WorkShift.Add(workShift);
                        DbHelper.GetContext().SaveChanges();
                        OperatorForm operatorForm = new OperatorForm(currentUser);
                        operatorForm.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Неправильные логин или пароль!");
                    }
                }
                else
                {
                    MessageBox.Show("Выберите оператора!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch
            {
            }
        }
Example #3
0
 public Tuple <int, string> StopShift(WorkShift shift)
 {
     using (HuboDbContext ctx = new HuboDbContext())
     {
         try
         {
             WorkShift currentShift = ctx.WorkShiftSet.Single <WorkShift>(s => s.Id == shift.Id);
             if (currentShift.isActive == false)
             {
                 return(Tuple.Create(-1, "Shift has already ended"));
             }
             currentShift.EndDate          = shift.EndDate;
             currentShift.EndLocationLat   = shift.EndLocationLat;
             currentShift.EndLocationLong  = shift.EndLocationLong;
             currentShift.EndLocation      = shift.EndLocation;
             currentShift.EndNote          = shift.EndNote;
             currentShift.isActive         = false;
             ctx.Entry(currentShift).State = EntityState.Modified;
             ctx.SaveChanges();
             return(Tuple.Create(1, "Success"));
         }
         catch (ArgumentNullException ex)
         {
             return(Tuple.Create(-1, ex.Message));
         }
         catch (Exception ex)
         {
             return(Tuple.Create(-1, ex.Message));
         }
     }
 }
Example #4
0
 /// <summary>Updates the work shift data for this citizen's schedule.</summary>
 /// <param name="workShift">The citizen's work shift.</param>
 /// <param name="startHour">The work shift start hour.</param>
 /// <param name="endHour">The work shift end hour.</param>
 /// <param name="worksOnWeekends">if <c>true</c>, the citizen works on weekends.</param>
 public void UpdateWorkShift(WorkShift workShift, float startHour, float endHour, bool worksOnWeekends)
 {
     WorkShift          = workShift;
     WorkShiftStartHour = startHour;
     WorkShiftEndHour   = endHour;
     WorksOnWeekends    = worksOnWeekends;
 }
Example #5
0
        public Tuple <int, string> StartShift(WorkShift shift)
        {
            using (HuboDbContext ctx = new HuboDbContext())
            {
                try
                {
                    //if (!ctx.DriverSet.Any(d => d.Id == shift.DriverId))
                    //{
                    //    //Driver ID does not exist
                    //    return Tuple.Create(-1, "No Driver exists with the ID = " + shift.DriverId);
                    //}

                    //if (!ctx.CompanySet.Any(c => c.Id == shift.CompanyId))
                    //{
                    //    return Tuple.Create(-1, "No Company exists with the ID = " + shift.CompanyId);
                    //}

                    //if (ctx.WorkShiftSet.Any(c => c.isActive == true && shift.DriverId == c.DriverId))
                    //{
                    //    return Tuple.Create(-1, "An active shift already exists");
                    //}

                    shift.isActive = true;
                    ctx.WorkShiftSet.Add(shift);
                    ctx.SaveChanges();
                    return(Tuple.Create(shift.Id, "Success"));
                }
                catch (Exception ex)
                {
                    return(Tuple.Create(-1, ex.Message));
                }
            }
        }
Example #6
0
        public ActionResult Edit(int id, Lookout lookout, int s, List <PreferredCompany> pc)
        {
            Lookout look = db.Lookouts.Find(id);

            lookout.LastActive = System.DateTime.Now;
            db.Entry(look).CurrentValues.SetValues(lookout);
            db.SaveChanges();
            //    WorkShift ws = new WorkShift();
            //      Shift sf = new Shift();
            //        sf = db.Shifts.Find(s);
            //          ws.Lookout_Id = look.Id;
            //            ws.Shift_Id = sf.id;
            WorkShift ws  = db.WorkShifts.FirstOrDefault(a => a.Lookout_Id == id);
            WorkShift wst = new WorkShift();
            Shift     sf  = new Shift();

            sf                 = db.Shifts.Find(s);
            ws.Shift_Id        = sf.id;
            db.Entry(ws).State = EntityState.Modified;
            db.SaveChanges();



            return(Json("", JsonRequestBehavior.AllowGet));
        }
Example #7
0
        private void AddOrRemoveShift(ShiftType shiftType, bool isToggled)
        {
            var workShift = _workShiftsRepository.Get(SelectedDate, shiftType);

            if (isToggled)
            {
                if (workShift == null)
                {
                    var newWorkShift = new WorkShift {
                        Date = SelectedDate, ShiftType = shiftType
                    };
                    var inlineCalendarEvent = WorkShiftConverter.ToCalendarInlineEvent(newWorkShift);
                    _workShiftsRepository.Insert(newWorkShift);
                    WorkShifts.Add(inlineCalendarEvent);
                    _workshiftCalendar.Add(newWorkShift, inlineCalendarEvent);
                }
            }
            else
            {
                if (workShift != null)
                {
                    var foundCalendarItem = _workshiftCalendar[workShift];
                    _workShiftsRepository.Delete(workShift);
                    WorkShifts.Remove(foundCalendarItem);
                    _workshiftCalendar.Remove(workShift);
                }
            }
        }
        public async Task <IActionResult> PutWorkShift(Guid id, WorkShift workShift)
        {
            if (id != workShift.ShiftId)
            {
                return(BadRequest());
            }

            _repoWrapper.WorkShift.Update(workShift);

            try
            {
                await _repoWrapper.save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkShiftExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public IHttpActionResult PutWorkShift(string id, WorkShift workShift)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != workShift.Shift)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #10
0
 public void SaveWorkShift()
 {
     try
     {
         using (ProxyBE p = new ProxyBE())
         {
             if (parm.WorkShiftID == Guid.Empty)
             {
                 throw new Exception("请选择对应工序。");
             }
             SaveWorkShiftArgs args      = new SaveWorkShiftArgs();
             WorkShift         workshift = p.Client.GetWorkShift(SenderUser, parm.WorkShiftID);
             if (workshift == null)
             {
                 workshift             = new WorkShift();
                 workshift.WorkShiftID = parm.WorkShiftID;
             }
             workshift.WorkShiftCode = parm.WorkShiftCode;
             workshift.WorkShiftName = parm.WorkShiftName;
             workshift.WorkShiftID   = parm.WorkShiftID;
             workshift.Started       = parm.Started;
             workshift.Ended         = parm.Ended;
             args.WorkShift          = workshift;
             p.Client.SaveWorkShift(SenderUser, args);
         }
         WriteSuccess();
     }
     catch (Exception ex)
     {
         WriteError(ex.Message, ex);
     }
 }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            WorkShift workShift = new WorkShift();

            workShift.ID        = Convert.ToInt32(Request.QueryString["id"].ToString());
            workShift.ShiftName = txtShiftName.Text;
            workShift.From      = ddlFrom.SelectedValue.ToString();
            workShift.To        = ddlTo.SelectedValue.ToString();
            HttpCookie myCookie = Request.Cookies["user"];

            workShift.OperatorID = Convert.ToInt32(myCookie.Values["userid"].ToString());
            string[] from = ddlFrom.SelectedValue.ToString().Split(':', '\t');
            string[] to   = ddlTo.SelectedValue.ToString().ToString().Split(':', '\t');


            string diffhoure  = (Convert.ToInt32(to[0]) - Convert.ToInt32(from[0])).ToString();
            string diffminute = (Convert.ToInt32(to[1]) - Convert.ToInt32(from[1])).ToString();

            workShift.Duration = diffhoure + ":" + diffminute;
            for (int i = 0; i < box2View.Items.Count; i++)
            {
                workShift.Emps[i] = Convert.ToInt32(box2View.Items[i].Value.ToString());
            }
            int id = workShift.update();

            if (id > 0)
            {
                Response.Redirect("~/HR/WorkShifts.aspx?alert=success");
            }
            else
            {
                Response.Redirect("~/HR/CreateWorkShifts.aspx?id=0&&alret=notpass");
            }
        }
Example #12
0
        /// <summary>
        /// Gets the probability whether a citizen with specified age would go out on current time.
        /// </summary>
        ///
        /// <param name="citizenAge">The age of the citizen to check.</param>
        /// <param name="workShift">The citizen's assigned work shift (or <see cref="WorkShift.Unemployed"/>).</param>
        /// <param name="needsShopping"><c>true</c> when the citizen needs to buy something; otherwise, <c>false</c>.</param>
        ///
        /// <returns>A percentage value in range of 0..100 that describes the probability whether
        /// a citizen with specified age would go out on current time.</returns>
        public uint GetGoOutChance(Citizen.AgeGroup citizenAge, WorkShift workShift, bool needsShopping)
        {
            if (needsShopping)
            {
                return(shoppingChances[(int)citizenAge]);
            }

            int age = (int)citizenAge;

            switch (citizenAge)
            {
            case Citizen.AgeGroup.Young:
            case Citizen.AgeGroup.Adult:
                switch (workShift)
                {
                case WorkShift.Second:
                    return(secondShiftChances[age]);

                case WorkShift.Night:
                    return(nightShiftChances[age]);

                default:
                    return(defaultChances[age]);
                }

            default:
                return(defaultChances[age]);
            }
        }
        public async Task <ActionResult <int> > Put(WorkShift ws)
        {
            context.Update(ws);
            await context.SaveChangesAsync();

            return(ws.Id);
        }
Example #14
0
 public void SaveWorkShift(Sender sender, SaveWorkShiftArgs args)
 {
     try
     {
         using (ObjectProxy op = new ObjectProxy(true))
         {
             WorkShift obj = new WorkShift();
             obj.WorkShiftID = args.WorkShift.WorkShiftID;
             if (op.LoadWorkShiftByWorkShiftID(obj) == 0)
             {
                 args.WorkShift.Created    = DateTime.Now;
                 args.WorkShift.CreatedBy  = string.Format("{0}.{1}", sender.UserCode, sender.UserName);
                 args.WorkShift.Modified   = DateTime.Now;
                 args.WorkShift.ModifiedBy = string.Format("{0}.{1}", sender.UserCode, sender.UserName);
                 op.InsertWorkShift(args.WorkShift);
             }
             else
             {
                 args.WorkShift.Modified   = DateTime.Now;
                 args.WorkShift.ModifiedBy = string.Format("{0}.{1}", sender.UserCode, sender.UserName);
                 op.UpdateWorkShiftByWorkShiftID(args.WorkShift);
             }
             op.CommitTransaction();
         }
     }
     catch (Exception ex)
     {
         PLogger.LogError(ex);
         throw ex;
     }
 }
Example #15
0
        public async Task SeedAsync(DataSeedContext context)
        {
            var curCompanies = await _CompaniesRepo.GetListAsync();

            var curDepartments = await _DepartmentsRepo.GetListAsync();

            var curEmployees = await _EmployeesRepo.GetListAsync();

            try
            {
                if (curCompanies.Any(x => x.CompanyName == "TestCorp"))
                {
                    if (curDepartments.Any(x => x.Name == "Admin"))
                    {
                        WorkShift workShift = new WorkShift()
                        {
                            Title     = "Morning",
                            StartHour = 0900,
                            EndHour   = 1700,
                            //Department = curDepartments.First(x => x.Name == "Admin"),
                            //DepartmentId = curDepartments.First(x => x.Name == "Admin").Id,
                            TenantId = context.TenantId
                        };

                        await _WorkShiftsRepo.InsertAsync(workShift);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public IHttpActionResult PostWorkShift(WorkShift workShift)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.WorkShifts.Add(workShift);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (WorkShiftExists(workShift.Shift))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = workShift.Shift }, workShift));
        }
Example #17
0
        /// <summary>
        /// Gets the probability whether a citizen with specified age would go relaxing on current time.
        /// </summary>
        ///
        /// <param name="citizenAge">The age of the citizen to check.</param>
        /// <param name="workShift">The citizen's assigned work shift (default is <see cref="WorkShift.Unemployed"/>).</param>
        /// <param name="isOnVacation"><c>true</c> if the citizen is on vacation.</param>
        ///
        /// <returns>A percentage value in range of 0..100 that describes the probability whether
        /// a citizen with specified age would go relaxing on current time.</returns>
        public uint GetRelaxingChance(Citizen.AgeGroup citizenAge, WorkShift workShift = WorkShift.Unemployed, bool isOnVacation = false)
        {
            if (isOnVacation)
            {
                return(defaultChances[(int)citizenAge] * 2u);
            }

            int age = (int)citizenAge;

            switch (citizenAge)
            {
            case Citizen.AgeGroup.Young:
            case Citizen.AgeGroup.Adult:
                switch (workShift)
                {
                case WorkShift.Second:
                    return(secondShiftChances[age]);

                case WorkShift.Night:
                    return(nightShiftChances[age]);

                default:
                    return(defaultChances[age]);
                }

            default:
                return(defaultChances[age]);
            }
        }
Example #18
0
        public static List <uint> GetWorkersForShift(this Building building, WorkShift shift)
        {
            var allWorkers             = building.GetAllWorkers();
            var totalWorkers           = allWorkers.Count;
            var weekdaySplitPercentage = 60;
            var weekdayCount           = (int)Math.Ceiling((weekdaySplitPercentage / 100f) * totalWorkers);
            var weekendCount           = totalWorkers - weekdayCount;

            if (totalWorkers > 0)
            {
                switch (shift)
                {
                case WorkShift.WeekdayDay:
                    return(allWorkers.GetRange(0, weekdayCount));

                case WorkShift.WeekendDay:
                    if (weekendCount > 0)
                    {
                        return(allWorkers.GetRange(weekdayCount - 1, weekendCount));
                    }
                    break;
                }
            }

            return(allWorkers);
        }
        public WorkShiftView(WorkShift model)
        {
            Mapper.CreateMap <WorkShift, WorkShiftView>();
            Mapper.Map <WorkShift, WorkShiftView>(model, this);

            this.created = model.created.ToString().Replace('T', ' ');
            this.updated = model.updated.ToString().Replace('T', ' ');
        }
Example #20
0
        public void WorkShiftsWithOnlyLockedAsDifferenceAreNotEqual()
        {
            var shift1 = new WorkShift(1, false);
            var shift2 = new WorkShift(1, true);
            var actual = shift1.Equals(shift2);

            Assert.AreEqual(false, actual);
        }
Example #21
0
        public ActionResult DeleteConfirmed(int id)
        {
            WorkShift workShift = db.WorkShifts.Find(id);

            db.WorkShifts.Remove(workShift);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public WorkShiftView(WorkShift model)
        {
            Mapper.CreateMap<WorkShift, WorkShiftView>();
            Mapper.Map<WorkShift, WorkShiftView>(model, this);

            this.created = model.created.ToString().Replace('T', ' ');
            this.updated = model.updated.ToString().Replace('T', ' ');
        }
Example #23
0
        /// <summary>Updates the citizen's work shift parameters in the specified citizen's <paramref name="schedule"/>.</summary>
        /// <param name="schedule">The citizen's schedule to update the work shift in.</param>
        /// <param name="citizenAge">The age of the citizen.</param>
        public void UpdateWorkShift(ref CitizenSchedule schedule, Citizen.AgeGroup citizenAge)
        {
            if (schedule.WorkBuilding == 0 || citizenAge == Citizen.AgeGroup.Senior)
            {
                schedule.UpdateWorkShift(WorkShift.Unemployed, 0, 0, false);
                return;
            }

            ItemClass.Service    buildingSevice     = buildingManager.GetBuildingService(schedule.WorkBuilding);
            ItemClass.SubService buildingSubService = buildingManager.GetBuildingSubService(schedule.WorkBuilding);

            float     workBegin, workEnd;
            WorkShift workShift = schedule.WorkShift;

            switch (citizenAge)
            {
            case Citizen.AgeGroup.Child:
            case Citizen.AgeGroup.Teen:
                workShift = WorkShift.First;
                workBegin = config.SchoolBegin;
                workEnd   = config.SchoolEnd;
                break;

            case Citizen.AgeGroup.Young:
            case Citizen.AgeGroup.Adult:
                if (workShift == WorkShift.Unemployed)
                {
                    workShift = GetWorkShift(GetBuildingWorkShiftCount(buildingSevice, buildingSubService));
                }

                workBegin = config.WorkBegin;
                workEnd   = config.WorkEnd;
                break;

            default:
                return;
            }

            switch (workShift)
            {
            case WorkShift.First when HasExtendedFirstWorkShift(buildingSevice, buildingSubService):
                workBegin = Math.Min(config.WakeupHour, EarliestWakeUp);

                break;

            case WorkShift.Second:
                workBegin = workEnd;
                workEnd   = 0;
                break;

            case WorkShift.Night:
                workEnd   = workBegin;
                workBegin = 0;
                break;
            }

            schedule.UpdateWorkShift(workShift, workBegin, workEnd, IsBuildingActiveOnWeekend(buildingSevice, buildingSubService));
        }
        public WorkShift getModel()
        {
            var model = new WorkShift();

            Mapper.CreateMap<WorkShiftView, WorkShift>();
            Mapper.Map<WorkShiftView, WorkShift>(this, model);

            return model;
        }
        public WorkShift getModel()
        {
            var model = new WorkShift();

            Mapper.CreateMap <WorkShiftView, WorkShift>();
            Mapper.Map <WorkShiftView, WorkShift>(this, model);

            return(model);
        }
Example #26
0
        public ActionResult DeleteConfirmed(int id)
        {
            WorkShift workShift = db.WorkShifts.Find(id);

            db.WorkShifts.Remove(workShift);
            db.SaveChanges();
            // Redirects to ShowShift with the specified ID. That way you only see the shift you are creating.
            return(RedirectToAction("ShowShift", "WorkShift", new { id = workShift.ShiftID }));
        }
Example #27
0
        // --- WorkShift Functions ---
        #region WorkShift Functions
        public async Task CreateWorkShift(WorkShift ws)
        {
            var response = await httpService.Post(ControllerURL.urlWorkShift, ws);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
        }
Example #28
0
 public WorkShift GetWorkShift(int workShiftId)
 {
     using (HuboDbContext ctx = new HuboDbContext())
     {
         WorkShift currentShift = (from workShift in ctx.WorkShiftSet
                                   where workShift.Id == workShiftId
                                   select workShift).FirstOrDefault <WorkShift>();
         return(currentShift);
     }
 }
Example #29
0
        public ActionResult WorkShiftDetailView(string title)
        {
            var objs = new WorkShift().GetObjectsValueFromExpression(x => x.WorkShiftTitle.Equals(title));

            if (objs != null && objs.Count > 0)
            {
                return(PartialView(objs));
            }
            return(PartialView(new List <WorkShift>()));
        }
Example #30
0
 public ActionResult Edit([Bind(Include = "Description,Date,StartTime,EndTime,TotalTime,OB1,OB2,FirstSickDay,SickDayTime,VAB")] WorkShift workShift)
 {
     if (ModelState.IsValid)
     {
         db.Entry(workShift).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(workShift));
 }
        public IHttpActionResult GetWorkShift(string id)
        {
            WorkShift workShift = db.WorkShifts.Find(id);

            if (workShift == null)
            {
                return(NotFound());
            }

            return(Ok(workShift));
        }
Example #32
0
        public ActionResult Create([Bind(Include = "Description,Date,StartTime,EndTime,TotalTime,OB1,OB2,FirstSickDay,SickDayTime,VAB")] WorkShift workShift)
        {
            if (ModelState.IsValid)
            {
                db.WorkShifts.Add(workShift);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(workShift));
        }
 public WorkShift createWorkShift(WorkShift model)
 {
     db.workShifts.Add(model);
     db.SaveChanges();
     return model;
 }