Пример #1
0
            public static int GetStandardWorkingTimeByProductId_SpecificationId(string ProductId, string SpecificationId)
            {
                MOProductSpecification ps = SchedulePlan.GetEntity().MOProductSpecification.Where(p => p.ProductId == ProductId && p.SpecificationId == SpecificationId).FirstOrDefault();

                if (ps != null && ps.StandardWorkingTime != null)
                {
                    return((int)ps.StandardWorkingTime);
                }
                else
                {
                    return(0);
                }
            }
Пример #2
0
            public static DateTime GetWorkTime(DateTime startTime, string ventureId)
            {
                WorkCenterCalendar noWorkCalender = SchedulePlan.GetEntity().WorkCenterCalendar.Where(p => DbFunctions.TruncateTime(p.NoWorkBeginDate) <= startTime && DbFunctions.TruncateTime(p.NoWorkEndDate) >= startTime).FirstOrDefault();

                DateTime workTime;

                if (noWorkCalender != null)
                {
                    workTime = (DateTime)noWorkCalender.NoWorkEndDate;
                }
                else
                {
                    workTime = startTime;
                }

                List <Venture_Shift> vfList = SchedulePlan.GetEntity().Venture_Shift.Where(p => p.VentureId == ventureId).ToList();



                if (!vfList.Any())
                {
                    Venture v = SchedulePlan.GetEntity().Venture.Where(p => p.VentureId == ventureId).FirstOrDefault();
                    throw new Exception(v.VentureName + "(" + v.VentureId + ")" + "经营体与工厂日历关系未维护!");
                }

                var shiftIdList = vfList.Select(p => p.ShiftId).ToList();


                var shiftList = SchedulePlan.GetEntity().Shift.Where(p => shiftIdList.Contains(p.ShiftId)).ToList();

                var minTimeFrom = shiftList.Max(p => p.TimeFrom);

                Shift shift = shiftList.Where(p => p.TimeFrom == minTimeFrom).FirstOrDefault();

                if (shift == null)
                {
                    throw new Exception("工厂日历未维护!");
                }

                string[] minsecond = shift.TimeFrom.Split(new char[] { ':' });

                DateTime workStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, int.Parse(minsecond[0]), int.Parse(minsecond[1]), 0);
                DateTime workEndTime   = workStartTime.AddMinutes(Convert.ToDouble(shift.TimeRange));

                if (workTime < workStartTime || workTime > workEndTime)
                {
                    workTime = workStartTime.AddDays(1);

                    noWorkCalender = SchedulePlan.GetEntity().WorkCenterCalendar.Where(p => DbFunctions.TruncateTime(p.NoWorkBeginDate) >= workTime || DbFunctions.TruncateTime(p.NoWorkEndDate) <= workTime).FirstOrDefault();

                    if (noWorkCalender != null)
                    {
                        TimeSpan?ts  = noWorkCalender.NoWorkEndDate - noWorkCalender.NoWorkBeginDate;
                        int      day = ((TimeSpan)ts).Days;

                        workTime = workStartTime.AddDays(day + 1);
                    }
                }

                //return
                return(workTime);
            }