public async Task <IActionResult> Edit(int id, [Bind("ShiftName,StartTime,EndTime,WorkingHr,WorkingMin,Id")] WorkingShift workingShift)
        {
            if (id != workingShift.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(workingShift);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WorkingShiftExists(workingShift.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(workingShift));
        }
        public async Task <IActionResult> Create([Bind("ShiftName,StartTime,EndTime,WorkingHr,WorkingMin,Id")] WorkingShift workingShift)
        {
            //if (ModelState.IsValid)
            //{
            _context.Add(workingShift);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
            //}
            //return View(workingShift);
        }
Example #3
0
        public DailySchedule GetSchedule(DateTime date)
        {
            DailySchedule                       schedule              = new DailySchedule(date);
            Table <DAL.Schedule>                scheduleTable         = GetScheduleTable();
            Table <DAL.WorkingCashier>          cashierTable          = GetWorkingCashierTable();
            Table <DAL.WorkingManager>          managerTable          = GetWorkingManagerTable();
            Table <DAL.WorkingRegularStaff>     staffTable            = GetWorkingRegularStaffTable();
            Table <DAL.WorkingWarehouseManager> warehouseManagerTable = GetWorkingWarehouseManagerTable();

            var matchedScheduleInDate = (from sch in scheduleTable
                                         where date.Date.CompareTo(sch.date) == 0
                                         select sch).ToList();

            foreach (DAL.Schedule matchedData in matchedScheduleInDate)
            {
                WorkingShift newShift       = new WorkingShift(matchedData.workingShiftID);
                var          matchedCashier = (from cashier in cashierTable
                                               where matchedData.scheduleID == cashier.scheduleID
                                               select cashier.staffID).ToList();
                foreach (string cashierID in matchedCashier)
                {
                    newShift.AddWorkingStaff(staffManager.GetStaff(cashierID));
                }

                var matchedManager = (from manager in managerTable
                                      where matchedData.scheduleID == manager.scheduleID
                                      select manager.staffID).ToList();
                foreach (string managerID in matchedManager)
                {
                    newShift.AddWorkingStaff(staffManager.GetStaff(managerID));
                }

                var matchedStaff = (from staff in staffTable
                                    where matchedData.scheduleID == staff.scheduleID
                                    select staff.staffID).ToList();
                foreach (string staffID in matchedStaff)
                {
                    newShift.AddWorkingStaff(staffManager.GetStaff(staffID));
                }

                var matchedKeeper = (from keeper in warehouseManagerTable
                                     where matchedData.scheduleID == keeper.scheduleID
                                     select keeper.staffID).ToList();
                foreach (string keeperID in matchedKeeper)
                {
                    newShift.AddWorkingStaff(staffManager.GetStaff(keeperID));
                }

                schedule.AddWorkingShift(newShift);
            }

            return(schedule);
        }
Example #4
0
        public string GetProgressionAsync(string startDate, string endDate, string machineNo, string machineGroup, string machineModel, string pdLine)
        {
            ProductionProgressModel progression = new ProductionProgressModel();

            progression.StartTime = string.IsNullOrEmpty(startDate) ? DateTime.Now.Date : Convert.ToDateTime(startDate).Date;
            progression.EndTime   = string.IsNullOrEmpty(endDate) ? DateTime.Now.Date : Convert.ToDateTime(endDate).Date;

            Machine machine = new Machine();

            //Get Machine Master and Working Shifts
            machine = _context.MachinesMaster.Include(c => c.WorkingTime)
                      .Where(x => x.MachineCode.Equals(machineNo))
                      .FirstOrDefault();
            //Machine is available
            if (machine != null)
            {
                progression.MachineCode = machine.MachineCode;
                int days = Convert.ToInt32((progression.EndTime - progression.StartTime).TotalDays);

                for (int i = 0; i <= days; i++)
                {
                    WorkingDay wkDay = new WorkingDay();
                    wkDay.WorkDate = progression.StartTime.AddDays(i);
                    foreach (var item in machine.WorkingTime.OrderBy(o => o.ShiftId))
                    {
                        WorkingShift shift    = _context.WorkingShifts.Where(x => x.Id == item.ShiftId).FirstOrDefault();
                        ShiftsDay    wkShift  = new ShiftsDay();
                        int          dayTotal = Convert.ToInt32((wkDay.WorkDate.Date - shift.StartTime.Date).TotalDays);

                        wkShift.ShiftId    = shift.Id;
                        wkShift.StartTime  = shift.StartTime.AddDays(dayTotal);
                        wkShift.EndTime    = shift.EndTime.AddDays(dayTotal);
                        wkShift.TasksCount = _context.JobTasks
                                             .Where(x => x.MachineNo.Equals(machineNo) &&
                                                    x.StartDate >= progression.StartTime && x.StartDate <= progression.EndTime).Count();
                        wkDay.ShiftTasks.Add(wkShift);
                    }

                    wkDay.StartDate = wkDay.ShiftTasks.OrderBy(o => o.StartTime).FirstOrDefault().StartTime;
                    wkDay.EndDate   = wkDay.ShiftTasks.OrderByDescending(o => o.EndTime).FirstOrDefault().EndTime;
                    progression.WorkingDays.Add(wkDay);
                }
            }

            return(JsonConvert.SerializeObject(progression, new JsonSerializerSettings()
            {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                Formatting = Formatting.Indented
            }));
        }
Example #5
0
        private void FormatDataInLabel(WorkingShift workingShift, BunifuCustomLabel target)
        {
            string printData = "";

            if (workingShift == null)
            {
                target.Text = "(No data)";
                return;
            }
            foreach (Staff staff in workingShift.WorkingStaff.Values)
            {
                printData += staff.FullName + " (" + staff.CurrentPosition + ")" + Environment.NewLine;
            }

            target.Text = printData;
        }
Example #6
0
        private bool updateWorkShiftAttendance(CheckFace checkFace)
        {
            int workShiftId = checkTimeAttendace(checkFace);

            if (workShiftId != -1)
            {
                // *** LINQ *** get row data workshift update
                WorkingShift working = _unitOfWork.Repository <WorkingShift>().Find(x => x.Active == true && x.Id == workShiftId);
                //update status -  checkTime - modeAttendance
                working.Status            = true;
                working.CheckInExpandTime = checkFace.CreateTime.TimeOfDay;
                working.ModeAttendance    = checkFace.Mode;
                // *** LINQ *** save change data
                return(_unitOfWork.Commit() > 0);
            }
            return(false);
        }
Example #7
0
        private string AddOrUpdateScheduleShift(WorkingShift schedule)
        {
            Table <DAL.Schedule> scheduleTable = GetScheduleTable();
            int matchedScheduleID = (from sch in scheduleTable
                                     where schedule.StartTime.Date.CompareTo(sch.date) == 0 && sch.workingShiftID == schedule.ShiftID
                                     select sch.scheduleID).FirstOrDefault();

            if (matchedScheduleID == default(int))
            {
                // Create new schedule
                DAL.Schedule newData = new DAL.Schedule();
                try
                {
                    newData.date           = schedule.StartTime.Date;
                    newData.workingShiftID = schedule.ShiftID;

                    scheduleTable.InsertOnSubmit(newData);
                    scheduleTable.Context.SubmitChanges();
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }

                matchedScheduleID = newData.scheduleID;
            }

            string err = DeleteCurrentWorkingStaffInfo(matchedScheduleID);

            if (err != "")
            {
                return(err);
            }

            foreach (Staff staff in schedule.WorkingStaff.Values)
            {
                err = "No data updated";
                if (staffManager.GetPositionCode(staff.CurrentPosition) == 1)
                {
                    err = AddOrNewWorkingCashier(staff, matchedScheduleID);
                }
                else if (staffManager.GetPositionCode(staff.CurrentPosition) == 2)
                {
                    err = AddOrUpdateNewWorkingManager(staff, matchedScheduleID);
                }
                else if (staffManager.GetPositionCode(staff.CurrentPosition) == 3)
                {
                    err = AddOrUpdateNewWorkingKeeper(staff, matchedScheduleID);
                }
                else if (staffManager.GetPositionCode(staff.CurrentPosition) == 4)
                {
                    err = AddOrUpdateNewWorkingStaff(staff, matchedScheduleID);
                }
                if (err != "")
                {
                    return(err);
                }
                staffManager.AddWorkingHours(staff.StaffID, ParameterManager.GetShiftHour());
            }

            return("");
        }
Example #8
0
        private void CallCollector(BunifuCustomLabel targetLabel)
        {
            if (UserRequest == "Edit schedule")
            {
                Select_Staff_Form CallForm = new Select_Staff_Form();
                CallForm.ShowDialog();
                string[] field = targetLabel.Name.Split('_');

                if (field.Count <string>() < 3)
                {
                    ErrorManager.MessageDisplay("Can't extract lablel name. Make sure the label name is in correct format", "", "Get information failed");
                }
                DateTime GetDay   = currentViewDate;
                int      shiftNum = 0;
                switch (field[1])
                {
                case "Mon":
                    GetDay = currentViewDate;
                    break;

                case "Tue":
                    GetDay = currentViewDate.AddDays(1);
                    break;

                case "Wed":
                    GetDay = currentViewDate.AddDays(2);
                    break;

                case "Thu":
                    GetDay = currentViewDate.AddDays(3);
                    break;

                case "Fri":
                    GetDay = currentViewDate.AddDays(4);
                    break;

                case "Sat":
                    GetDay = currentViewDate.AddDays(5);
                    break;

                case "Sun":
                    GetDay = currentViewDate.AddDays(6);
                    break;
                }
                switch (field[2])
                {
                case "S1":
                    shiftNum = 1;
                    break;

                case "S2":
                    shiftNum = 2;
                    break;
                }

                WorkingShift data = new WorkingShift(GetDay, GetDay, shiftNum);
                foreach (Staff staff in CallForm.selectedStaff)
                {
                    data.AddWorkingStaff(staff);
                }

                newSchedule.Add(data);

                FormatDataInLabel(data, targetLabel);
            }
        }
Example #9
0
        /// <summary>
        /// Generating of the workingshifts from the calculated flows
        /// </summary>
        /// <returns>List of coherents shifts given the constructed graph</returns>
        public List <WorkingShift> GetShifts()
        {
            List <WorkingShift> shifts = new List <WorkingShift>();

            CalculateMaximumFlow();

            // init quotas dict
            Dictionary <ScheduleSlot, List <Tuple <Person, double> > > quotas = new Dictionary <ScheduleSlot, List <Tuple <Person, double> > >();

            foreach (FlowNode node in this.Nodes)
            {
                if (node.Type == FlowNodeType.Slot)
                {
                    quotas.Add(((SlotFlowNode)node).Slot, new List <Tuple <Person, double> >());
                }
            }

            // recup quotas
            foreach (KeyValuePair <FlowArc, double> flowDict in this.Flows)
            {
                FlowArc arc = flowDict.Key; double flow = flowDict.Value;
                switch (arc.Start.Type)
                {
                case FlowNodeType.Virtual:
                    // si flow < capacité alors personne pas complètement occupée => trop de RH
                    break;

                case FlowNodeType.Person:
                    if (flow > 0)
                    {
                        quotas[((SlotFlowNode)arc.End).Slot].Add(new Tuple <Person, double>(((PersonFlowNode)arc.Start).Person, flow));
                    }
                    break;

                case FlowNodeType.Slot:
                    // si flow < capacité alors plage pas complètement couverte => pas assez de RH
                    break;

                default:
                    break;
                }
            }

            // create shifts
            foreach (KeyValuePair <ScheduleSlot, List <Tuple <Person, double> > > quotaDict in quotas)
            {
                ScheduleSlot slot = quotaDict.Key; List <Tuple <Person, double> > liste = quotaDict.Value;
                TimeSpan     start     = slot.startHour;
                TimeSpan     end       = slot.endHour;
                TimeSpan     fromThere = start;
                foreach (Tuple <Person, double> quotaTuple in liste)
                {
                    Person person = quotaTuple.Item1;; double hours = quotaTuple.Item2;
                    while (hours > 0)
                    {
                        TimeSpan     toThere = TimeSpan.FromTicks(Math.Min(end.Ticks, fromThere.Add(TimeSpan.FromHours(hours)).Ticks));
                        WorkingShift shift   = new WorkingShift();
                        DateTime     theDay  = WeekStart.AddDays(((int)slot.dayOfWeek - (int)WeekStart.DayOfWeek) % 7);
                        shift.start  = theDay.Add(fromThere);
                        shift.end    = theDay.Add(toThere);
                        shift.Person = person;
                        shifts.Add(shift);
                        hours -= toThere.Subtract(fromThere).TotalHours;
                        if (toThere == end)
                        {
                            fromThere = start;
                        }
                        else
                        {
                            fromThere = toThere;
                        }
                    }
                }
            }

            // merging contiguous shifts
            int i = 0;

            while (i < shifts.Count)
            {
                WorkingShift shiftI = shifts[i];
                int          j      = i + 1;
                while (j < shifts.Count)
                {
                    WorkingShift shiftJ = shifts[j];
                    if (shiftJ.Person == shiftI.Person &&
                        shiftJ.start == shiftI.end)
                    {
                        shiftI.end = shiftJ.end;
                        shifts.Remove(shiftJ);
                    }
                    else
                    {
                        j++;
                    }
                }
                i++;
            }

            return(shifts);
        }