public bool Update(ProgramScheduleTime obj)
 {
     if (_programScheduleTime.UpdateEntity(obj))
     {
         return(true);
     }
     return(false);
 }
        //更新
        public static bool Update(ProgramScheduleTime obj)
        {
            string urls = url_program_schedule_time + "/update";

            var  objJson = JsonConvert.SerializeObject(obj);
            bool result  = Convert.ToBoolean(HttpHelper.HttpPut(urls, objJson));

            return(result);
        }
        //新增
        public static int Insert(ProgramScheduleTime obj)
        {
            string urls = url_program_schedule_time + "/insert";

            var objJson = JsonConvert.SerializeObject(obj);
            int result  = Convert.ToInt32(HttpHelper.HttpPost(urls, objJson));

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 开始播放任务
        /// </summary>
        public override void ProgramPlay()
        {
            DateTime            dtNow;
            ProgramScheduleTime scheduleTime = null;

            while (!StopBit)
            {
                if (schedule == null)//未有排程,持续查询
                {
                    LoadSchedule();
                    if (schedule == null)
                    {
                        Thread.Sleep(5000);
                        continue;
                    }
                }
                else if (PauseBit)
                {
                    Thread.Sleep(1000);
                    continue;
                }
                dtNow = DateTime.Now;
                foreach (var item in schedule.TimeList)
                {
                    if (!string.IsNullOrEmpty(item.schedule_date))//播放的日期设定不为空,则为优先
                    {
                        if (dtNow.ToString("yyyy-MM-dd") == item.schedule_date)
                        {
                            scheduleTime = item;
                            break;
                        }
                    }
                    else if (!string.IsNullOrEmpty(item.schedule_week))//星期设定不为空,则为优先
                    {
                        if (item.schedule_week.Contains(dtNow.DayOfWeek.ToString()))
                        {
                            scheduleTime = item;
                            break;
                        }
                    }
                }

                if (scheduleTime == null)                                                     //未有复合条件的,加载默认时刻
                {
                    scheduleTime = schedule.TimeList.FirstOrDefault(x => x.primary_bit == 1); //默认的排程
                }
                //时刻表未加载,或者时刻表变化,则加载
                if (scheduleTime != null)
                {
                    if (PresentPlayObject == null ||
                        (PresentPlayObject as ProgramScheduleTime) != scheduleTime)
                    {
                        RegionManagerDic = new Dictionary <int, ProgramRegionPlayManager>();
                        try
                        {
                            LoadScheduleDay(scheduleTime);
                            this.PresentPlayObject = scheduleTime;
                        }
                        catch (Exception ex)
                        {
                            _logWrite.WriteLog($"LoadScheduleDay出错", ex);
                        }
                    }
                }
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 加载单日时刻表
        /// </summary>
        /// <param name="programScheduleTime"></param>
        private void LoadScheduleDay(ProgramScheduleTime programScheduleTime)
        {
            DateTime           dtNow = DateTime.Now;
            DateTime           dtStart, dtEnd;
            ScheduleDayProgram dayProgram   = null;
            Canvas             canvasLayOut = null;
            ScheduleDay        scheduleDay  = programScheduleTime.scheduleDay;

            foreach (var dayProgramItem in scheduleDay.ProgramList)                       //查找具体时刻表里面符合时间范围的节目
            {
                string tmp = dtNow.ToShortDateString() + " " + dayProgramItem.start_time; //开始时间
                DateTime.TryParse(tmp, out dtStart);
                tmp = dtNow.ToShortDateString() + " " + dayProgramItem.end_time;          //结束时间
                DateTime.TryParse(tmp, out dtEnd);
                if (dtNow >= dtStart && dtNow <= dtEnd)
                {
                    dayProgram = dayProgramItem;
                    _logWrite.WriteLog($"查找到ScheduleDayProgram对象id={dayProgram.id}");
                    break;
                }
            }
            if (dayProgram != null)//查找到正确的时刻
            {
                ProgramInfo programInfo = _programInfoService.GetCompositeById(dayProgram.program_id);
                if (programInfo != null)
                {
                    _logWrite.WriteLog($"开始加载节目信息={programInfo.id} {programInfo.program_name}");

                    mainWindow.Dispatcher.Invoke(new Action(() =>
                    {
                        canvasLayOut        = new Canvas();
                        mainWindow.Width    = programInfo.w; //窗体尺寸-宽
                        mainWindow.Height   = programInfo.h; //窗体尺寸-高
                        canvasLayOut.Width  = programInfo.w;
                        canvasLayOut.Height = programInfo.h;
                    }));
                    this.PresentUIElement = canvasLayOut;

                    foreach (var region in programInfo.RegionList)//区块列表
                    {
                        if (!RegionManagerDic.ContainsKey(region.id))
                        {
                            ProgramRegionPlayManager regioManager = new ProgramRegionPlayManager(canvasLayOut, region, _mediaInfoService, _logWrite);
                            regioManager.PlayStart();
                            RegionManagerDic.Add(region.id, regioManager);
                        }
                    }

                    mainWindow.Dispatcher.Invoke(new Action(() =>
                    {
                        mainWindow.Content = canvasLayOut;//画布赋值给窗体
                    }));
                }
                else
                {
                    _logWrite.WriteLog($"未查找到ProgramInfo对象,对象id={dayProgram.program_id}");
                }
            }
            else
            {
                _logWrite.WriteLog("未查找到ScheduleDayProgram对象");
            }
        }
        public int Insert(ProgramScheduleTime scheduleDay)
        {
            int bigId = (int)_programScheduleTime.InsertBigIdentity(scheduleDay);

            return(bigId);
        }
        public IActionResult EditHandle(string schedule_name, int schedule_id, int default_program_id)
        {
            string events = HttpContext.Request.Form["myevents"].ToString();
            List <ProgramEvent> programEvents = JsonConvert.DeserializeObject <List <ProgramEvent> >(events);
            //保证对于一个排程存在ProgramScheduleTime中的schedule_day_id唯一
            List <string> eventTitle = programEvents.GroupBy(s => s.title).Select(s => s.Key).ToList();

            List <ProgramSchedule> programSchedules = ProgramScheduleCURD.Get();//判断标题名称是否重复
            List <ScheduleDay>     scheduleDays     = ScheduleDayCURD.Get();

            //新增
            if (schedule_id == 0)
            {
                int count = programSchedules.Where(s => s.schedule_name == schedule_name).ToList().Count;
                if (count > 0)
                {
                    return(Json("Repeat"));
                }
                else
                {
                    //ProgramSchedule新增
                    ProgramSchedule programSchedule = new ProgramSchedule();
                    programSchedule.schedule_name = schedule_name;
                    programSchedule.group_id      = 1;
                    programSchedule.user_id       = 1;
                    programSchedule.create_time   = DateTime.Now.ToLocalTime();
                    int program_schedule_id = ProgramScheduleCURD.Insert(programSchedule);

                    if (program_schedule_id > 0)
                    {
                        ////ProgramScheduleTime新增

                        //获取events title中对应的id

                        var scheduleDays1 = (from p in eventTitle
                                             join q in scheduleDays
                                             on p equals q.schedule_name
                                             select new {
                            q.id,
                            q.schedule_name
                        }).ToList();
                        bool flag = true;//判断默认排程是否在日历中,以避免programscheduletime中存在重复scheduleday
                        for (int i = 0; i < scheduleDays1.Count; i++)
                        {
                            ProgramScheduleTime programScheduleTime = new ProgramScheduleTime();
                            programScheduleTime.schedule_id     = program_schedule_id;
                            programScheduleTime.schedule_day_id = scheduleDays1[i].id;
                            //若默认排程在日历中则primary_bit=1
                            if (scheduleDays1[i].id == default_program_id)
                            {
                                programScheduleTime.primary_bit = 1;
                                flag = false;
                            }
                            int program_schedule_time_id = ProgramScheduleTimeCURD.Insert(programScheduleTime);
                            if (program_schedule_time_id > 0)
                            {
                                //ScheduleTimeDate新增
                                for (int j = 0; j < programEvents.Count; j++)
                                {
                                    if (programEvents[j].title == scheduleDays1[i].schedule_name)
                                    {
                                        //保证一天一笔数据
                                        if (programEvents[j].start == programEvents[j].end)
                                        {
                                            ScheduleTimeDate scheduleTimeDate = new ScheduleTimeDate();
                                            scheduleTimeDate.schedule_time_id = program_schedule_time_id;
                                            scheduleTimeDate.schedule_date    = programEvents[j].start;
                                            int schedule_time_date_id = ScheduleTimeDateCURD.Insert(scheduleTimeDate);
                                            if (schedule_time_date_id <= 0)
                                            {
                                                return(Json("Fail"));
                                            }
                                        }
                                        else
                                        {
                                            TimeSpan span    = programEvents[j].end.Subtract(programEvents[j].start);
                                            int      dayDiff = span.Days + 1;
                                            for (int day = 0; day < dayDiff; day++)
                                            {
                                                ScheduleTimeDate scheduleTimeDate1 = new ScheduleTimeDate();
                                                scheduleTimeDate1.schedule_time_id = program_schedule_time_id;
                                                scheduleTimeDate1.schedule_date    = programEvents[j].start.AddDays(day);
                                                int schedule_time_date_id = ScheduleTimeDateCURD.Insert(scheduleTimeDate1);
                                                if (schedule_time_date_id <= 0)
                                                {
                                                    return(Json("Fail"));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                return(Json("Fail"));
                            }
                        }
                        ////若默认排程不在日历中则额外添加
                        if (flag && default_program_id > 0)
                        {
                            ProgramScheduleTime programScheduleTime = new ProgramScheduleTime();
                            programScheduleTime.schedule_id     = program_schedule_id;
                            programScheduleTime.schedule_day_id = default_program_id;
                            programScheduleTime.primary_bit     = 1;
                            int id = ProgramScheduleTimeCURD.Insert(programScheduleTime);
                            if (id <= 0)
                            {
                                return(Json("Fail"));
                            }
                        }
                    }
                    else
                    {
                        return(Json("Fail"));
                    }
                }
            }
            //修改
            else
            {
                int count = programSchedules.Where(s => s.schedule_name == schedule_name && s.id != schedule_id).ToList().Count;
                if (count > 0)
                {
                    return(Json("Repeat"));
                }
                else
                {
                    List <ProgramSchedule> programs = programSchedules.Where(s => s.id == schedule_id).ToList();
                    //ProgramSchedule更新
                    ProgramSchedule programSchedule = new ProgramSchedule();
                    programSchedule.schedule_name = schedule_name;
                    programSchedule.group_id      = programs[0].group_id;
                    programSchedule.user_id       = programs[0].user_id;
                    programSchedule.create_time   = programs[0].create_time;
                    bool res = ProgramScheduleCURD.Update(programSchedule);

                    if (res)
                    {
                        //ProgramScheduleTime更新
                        List <ProgramScheduleTime> programScheduleTimes = ProgramScheduleTimeCURD.Get().Where(s => s.schedule_id == schedule_id).ToList();
                        List <ProgramScheduleTime> deleteList           = programScheduleTimes;
                        List <string> InsertList = eventTitle;
                        bool          flag       = true;
                        for (int i = 0; i < programScheduleTimes.Count; i++)
                        {
                            if (eventTitle.Contains(programScheduleTimes[i].schedule_day_name))
                            {
                                deleteList.Remove(programScheduleTimes[i]);
                                InsertList.Remove(programScheduleTimes[i].schedule_day_name);

                                //判断预设排程是否在里面,若在则更新
                                if (default_program_id == programScheduleTimes[i].schedule_day_id)
                                {
                                    flag = false;
                                    ProgramScheduleTime programScheduleTime = new ProgramScheduleTime();
                                    programScheduleTime             = programScheduleTimes[i];
                                    programScheduleTime.primary_bit = 1;
                                    bool defaultUpdate = ProgramScheduleTimeCURD.Update(programScheduleTime);
                                    if (!defaultUpdate)
                                    {
                                        return(Json("Fail"));
                                    }
                                }


                                //操作schedule_time_date(先删除再新增)
                                List <ScheduleTimeDate> scheduleTimeDates = ScheduleTimeDateCURD.Get().Where(s => s.schedule_time_id == programScheduleTimes[i].id).ToList();
                                for (int delete = 0; delete < scheduleTimeDates.Count; delete++)
                                {
                                    bool deleteRes = ScheduleTimeDateCURD.Delete(scheduleTimeDates[delete].id);
                                    if (!deleteRes)
                                    {
                                        return(Json("Fail"));
                                    }
                                }

                                //ScheduleTimeDate新增
                                for (int j = 0; j < programEvents.Count; j++)
                                {
                                    if (programEvents[j].title == programScheduleTimes[i].schedule_day_name)
                                    {
                                        //保证一天一笔数据
                                        if (programEvents[j].start == programEvents[j].end)
                                        {
                                            ScheduleTimeDate scheduleTimeDate = new ScheduleTimeDate();
                                            scheduleTimeDate.schedule_time_id = programScheduleTimes[i].id;
                                            scheduleTimeDate.schedule_date    = programEvents[j].start;
                                            int schedule_time_date_id = ScheduleTimeDateCURD.Insert(scheduleTimeDate);
                                            if (schedule_time_date_id <= 0)
                                            {
                                                return(Json("Fail"));
                                            }
                                        }
                                        else
                                        {
                                            TimeSpan span    = programEvents[j].end.Subtract(programEvents[j].start);
                                            int      dayDiff = span.Days + 1;
                                            for (int day = 0; day < dayDiff; day++)
                                            {
                                                ScheduleTimeDate scheduleTimeDate1 = new ScheduleTimeDate();
                                                scheduleTimeDate1.schedule_time_id = programScheduleTimes[i].id;
                                                scheduleTimeDate1.schedule_date    = programEvents[j].start.AddDays(day);
                                                int schedule_time_date_id = ScheduleTimeDateCURD.Insert(scheduleTimeDate1);
                                                if (schedule_time_date_id <= 0)
                                                {
                                                    return(Json("Fail"));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        ////若默认排程不在日历中则额外添加
                        if (flag && default_program_id > 0)
                        {
                            ProgramScheduleTime programScheduleTime = new ProgramScheduleTime();
                            programScheduleTime.schedule_id     = schedule_id;
                            programScheduleTime.schedule_day_id = default_program_id;
                            programScheduleTime.primary_bit     = 1;
                            int id = ProgramScheduleTimeCURD.Insert(programScheduleTime);
                            if (id <= 0)
                            {
                                return(Json("Fail"));
                            }
                        }

                        //删除数据库中不在提交的数据中的数据
                        for (int i = 0; i < deleteList.Count; i++)
                        {
                            bool deleteRes = ScheduleTimeDateCURD.Delete(deleteList[i].id);
                            if (!deleteRes)
                            {
                                return(Json("Fail"));
                            }
                        }


                        for (int j = 0; j < programEvents.Count; j++)
                        {
                            if (InsertList.Contains(programEvents[j].title))
                            {
                                List <ScheduleDay>  scheduleDays1       = scheduleDays.Where(s => s.schedule_name == programEvents[j].title).ToList();
                                ProgramScheduleTime programScheduleTime = new ProgramScheduleTime();
                                programScheduleTime.schedule_day_id = scheduleDays1[0].id;
                                int program_schedule_time_id = ProgramScheduleTimeCURD.Insert(programScheduleTime);
                                //保证一天一笔数据
                                if (programEvents[j].start == programEvents[j].end)
                                {
                                    ScheduleTimeDate scheduleTimeDate = new ScheduleTimeDate();
                                    scheduleTimeDate.schedule_time_id = program_schedule_time_id;
                                    scheduleTimeDate.schedule_date    = programEvents[j].start;
                                    int schedule_time_date_id = ScheduleTimeDateCURD.Insert(scheduleTimeDate);
                                    if (schedule_time_date_id <= 0)
                                    {
                                        return(Json("Fail"));
                                    }
                                }
                                else
                                {
                                    TimeSpan span    = programEvents[j].end.Subtract(programEvents[j].start);
                                    int      dayDiff = span.Days + 1;
                                    for (int day = 0; day < dayDiff; day++)
                                    {
                                        ScheduleTimeDate scheduleTimeDate1 = new ScheduleTimeDate();
                                        scheduleTimeDate1.schedule_time_id = program_schedule_time_id;
                                        scheduleTimeDate1.schedule_date    = programEvents[j].start.AddDays(day);
                                        int schedule_time_date_id = ScheduleTimeDateCURD.Insert(scheduleTimeDate1);
                                        if (schedule_time_date_id <= 0)
                                        {
                                            return(Json("Fail"));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        return(Json("Fail"));
                    }
                }
            }



            return(Json("Success"));
        }