Esempio n. 1
0
        public NightSchedule Update(NightSchedule nightSchedule, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                NightSchedule exists = ubc.Group_NightSchedules
                                       .Where(x => x.GroupId == nightSchedule.GroupId)
                                       .FirstOrDefault();
                if (exists == null)
                {
                    return(null);
                }

                try
                {
                    exists.State        = nightSchedule.State;
                    exists.UtcStartDate = nightSchedule.UtcStartDate;
                    exists.UtcEndDate   = nightSchedule.UtcEndDate;

                    ubc.SaveChanges();
                    return(nightSchedule);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.NightScheduleService.Update",
                        Level      = SystemLog.Levels.Warn,
                        Message    = ex.Message,
                        UserId     = callerId
                    });
                    if (ex.InnerException != null)
                    {
                        Utils.Logging.AddLog(new SystemLog()
                        {
                            LoggerName = "Unifiedban.Data",
                            Date       = DateTime.Now,
                            Function   = "Unifiedban.Data.NightScheduleService.Update",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(null);
            }
        }
Esempio n. 2
0
        public SystemLog.ErrorCodes Remove(NightSchedule nightSchedule, int callerId)
        {
            using (UBContext ubc = new UBContext())
            {
                NightSchedule exists = ubc.Group_NightSchedules
                                       .Where(x => x.NightScheduleId == nightSchedule.NightScheduleId)
                                       .FirstOrDefault();
                if (exists == null)
                {
                    return(SystemLog.ErrorCodes.Error);
                }

                try
                {
                    ubc.Remove(exists);
                    ubc.SaveChanges();
                    return(SystemLog.ErrorCodes.OK);
                }
                catch (Exception ex)
                {
                    Utils.Logging.AddLog(new SystemLog()
                    {
                        LoggerName = "Unifiedban",
                        Date       = DateTime.Now,
                        Function   = "Unifiedban.Data.NightScheduleService.Remove",
                        Level      = SystemLog.Levels.Warn,
                        Message    = ex.Message,
                        UserId     = callerId
                    });
                    if (ex.InnerException != null)
                    {
                        Utils.Logging.AddLog(new SystemLog()
                        {
                            LoggerName = "Unifiedban.Data",
                            Date       = DateTime.Now,
                            Function   = "Unifiedban.Data.NightScheduleService.Remove",
                            Level      = SystemLog.Levels.Warn,
                            Message    = ex.InnerException.Message,
                            UserId     = callerId
                        });
                    }
                }
                return(SystemLog.ErrorCodes.Error);
            }
        }
Esempio n. 3
0
 public NightSchedule Add(NightSchedule nightSchedule, int callerId)
 {
     using (UBContext ubc = new UBContext())
     {
         try
         {
             ubc.Add(nightSchedule);
             ubc.SaveChanges();
             return(nightSchedule);
         }
         catch (Exception ex)
         {
             Utils.Logging.AddLog(new SystemLog()
             {
                 LoggerName = "Unifiedban",
                 Date       = DateTime.Now,
                 Function   = "Unifiedban.Data.NightScheduleService.Add",
                 Level      = SystemLog.Levels.Warn,
                 Message    = ex.Message,
                 UserId     = callerId
             });
             if (ex.InnerException != null)
             {
                 Utils.Logging.AddLog(new SystemLog()
                 {
                     LoggerName = "Unifiedban.Data",
                     Date       = DateTime.Now,
                     Function   = "Unifiedban.Data.NightScheduleService.Add",
                     Level      = SystemLog.Levels.Warn,
                     Message    = ex.InnerException.Message,
                     UserId     = callerId
                 });
             }
         }
         return(null);
     }
 }
Esempio n. 4
0
        public ActionResult GetShcedule()
        {
            List <DateScheduleViewModel> result = new List <DateScheduleViewModel>();

            using (ANDONEntities entities = new ANDONEntities())
            {
                List <ShiftSet> list = entities.Database.SqlQuery <ShiftSet>(@"SELECT [1] _1,[2] _2,[3] _3,[4] _4,[5] _5,[6] _6,[7] _7,[8] _8,[9] _9,[10] _10,[11] _11,[12] _12,[13] _13,[14] _14,[15] _15,[16] _16,[17] _17,[18] _18,[19] _19,[20] _20,shift FROM shift_set").ToList();

                ShiftSet dayS   = list.Where(t => t.shift.Trim() == "1").FirstOrDefault();
                ShiftSet nightS = list.Where(t => t.shift.Trim() == "2").FirstOrDefault();


                //1
                DaySchedule day = new DaySchedule {
                    StartTime = dayS._1.Trim() + ":" + dayS._2.Trim(), EndTime = dayS._3.Trim() + ":" + dayS._4.Trim()
                };
                NightSchedule night = new NightSchedule {
                    StartTime = nightS._1.Trim() + ":" + nightS._2.Trim(), EndTime = nightS._3.Trim() + ":" + nightS._4.Trim()
                };
                DateScheduleViewModel model = new DateScheduleViewModel {
                    Day = day, Night = night, Name = "开停线"
                };
                result.Add(model);
                //2
                day = new DaySchedule {
                    StartTime = dayS._5.Trim() + ":" + dayS._6.Trim(), EndTime = dayS._7.Trim() + ":" + dayS._8.Trim()
                };
                night = new NightSchedule {
                    StartTime = nightS._5.Trim() + ":" + nightS._6.Trim(), EndTime = nightS._7.Trim() + ":" + nightS._8.Trim()
                };
                model = new DateScheduleViewModel {
                    Day = day, Night = night, Name = "休息一"
                };
                result.Add(model);
                //3
                day = new DaySchedule {
                    StartTime = dayS._9.Trim() + ":" + dayS._10.Trim(), EndTime = dayS._11.Trim() + ":" + dayS._12.Trim()
                };
                night = new NightSchedule {
                    StartTime = nightS._9.Trim() + ":" + nightS._10.Trim(), EndTime = nightS._11.Trim() + ":" + nightS._12.Trim()
                };
                model = new DateScheduleViewModel {
                    Day = day, Night = night, Name = "休息二"
                };
                result.Add(model);
                //4
                day = new DaySchedule {
                    StartTime = dayS._13.Trim() + ":" + dayS._14.Trim(), EndTime = dayS._15.Trim() + ":" + dayS._16.Trim()
                };
                night = new NightSchedule {
                    StartTime = nightS._13.Trim() + ":" + nightS._14.Trim(), EndTime = nightS._15.Trim() + ":" + nightS._16.Trim()
                };
                model = new DateScheduleViewModel {
                    Day = day, Night = night, Name = "休息三"
                };
                result.Add(model);
                //5
                day = new DaySchedule {
                    StartTime = dayS._17.Trim() + ":" + dayS._18.Trim(), EndTime = dayS._19.Trim() + ":" + dayS._20.Trim()
                };
                night = new NightSchedule {
                    StartTime = nightS._17.Trim() + ":" + nightS._18.Trim(), EndTime = nightS._19.Trim() + ":" + nightS._20.Trim()
                };
                model = new DateScheduleViewModel {
                    Day = day, Night = night, Name = "休息四"
                };
                result.Add(model);
                //entities
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }