Ejemplo n.º 1
0
        public static TimeSpan TGLamViecToiHienTai(int LineId)
        {
            var      timeNow    = DateTime.Now.TimeOfDay;
            var      lineShifts = BLLShift.GetShiftsOfLine(LineId);
            TimeSpan timeWork   = TimeSpan.Parse("00:00:00");

            for (int j = 0; j < lineShifts.Count; j++)
            {
                if (timeNow > lineShifts[j].Start)
                {
                    if (timeNow < lineShifts[j].End)
                    {
                        timeWork += (timeNow - lineShifts[j].Start);
                    }
                    else
                    {
                        timeWork += (lineShifts[j].End - lineShifts[j].Start);
                    }
                }
            }
            return(timeWork);
        }
Ejemplo n.º 2
0
 public static List <WorkingTimeModel> GetListWorkHoursOfLineByLineId(int lineId)
 {
     try
     {
         List <WorkingTimeModel> listWorkHours = null;
         var listShiftOfLine = BLLShift.GetShiftsOfLine(lineId);
         if (listShiftOfLine != null && listShiftOfLine.Count > 0)
         {
             listWorkHours = new List <WorkingTimeModel>();
             int      intHours         = 1;
             TimeSpan timeEnd          = new TimeSpan(0, 0, 0);
             TimeSpan timeStart        = new TimeSpan(0, 0, 0);
             bool     isWaitingTimeEnd = false;
             double   dHoursShiftOld   = 0;
             for (int i = 0; i < listShiftOfLine.Count; i++)
             {
                 var shift = listShiftOfLine[i];
                 while (true)
                 {
                     if (!isWaitingTimeEnd)
                     {
                         if (timeStart == new TimeSpan(0, 0, 0))
                         {
                             timeStart = shift.Start;
                         }
                         else
                         {
                             timeStart = timeEnd;
                         }
                     }
                     else
                     {
                         if (dHoursShiftOld == 0)
                         {
                             timeStart = shift.Start;
                         }
                     }
                     if (timeStart > shift.End)
                     {
                         break;
                     }
                     else
                     {
                         if (!isWaitingTimeEnd)
                         {
                             timeEnd = timeStart.Add(new TimeSpan(1, 0, 0));
                         }
                         else
                         {
                             if (dHoursShiftOld > 0)
                             {
                                 double hour    = 1 - dHoursShiftOld;
                                 int    minuter = (int)(hour * 60);
                                 timeEnd = shift.Start.Add(new TimeSpan(0, minuter, 0));
                             }
                             else
                             {
                                 timeEnd = timeStart.Add(new TimeSpan(1, 0, 0));
                             }
                             isWaitingTimeEnd = false;
                         }
                         if (timeEnd <= shift.End)
                         {
                             listWorkHours.Add(new WorkingTimeModel()
                             {
                                 IntHours  = intHours,
                                 TimeStart = timeStart,
                                 TimeEnd   = timeEnd,
                                 Name      = "Giờ " + intHours + " (" + timeStart.ToString(@"hh\:mm") + "-" + timeEnd.ToString(@"hh\:mm") + ")",
                                 IsShow    = (DateTime.Now.TimeOfDay > timeStart && DateTime.Now.TimeOfDay < timeEnd) ? true : false
                             });
                             intHours++;
                         }
                         else
                         {
                             isWaitingTimeEnd = true;
                             dHoursShiftOld   = shift.End.TotalHours - timeStart.TotalHours;
                             if (dHoursShiftOld != 0 && i == listShiftOfLine.Count - 1)
                             {
                                 listWorkHours.Add(new WorkingTimeModel()
                                 {
                                     IntHours  = intHours,
                                     TimeStart = timeStart,
                                     TimeEnd   = shift.End,
                                     Name      = "Giờ " + intHours + " (" + timeStart.ToString(@"hh\:mm") + "-" + shift.End.ToString(@"hh\:mm") + ")",
                                     IsShow    = (DateTime.Now.TimeOfDay > timeStart && DateTime.Now.TimeOfDay < timeEnd) ? true : false
                                 });
                                 intHours++;
                             }
                             break;
                         }
                     }
                     if (intHours > 30)
                     {
                         break;
                     }
                 }
             }
         }
         return(listWorkHours);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }