public JsonResult GetWorkingCalendar(string calendarID)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = null;

                WorkingCalendar calendar = this.Engine.WorkingCalendarManager.GetCalendar(calendarID);
                if (calendar == null)
                {
                    result = new ActionResult(false, "WorkingCalendar.CalendarNotExists");
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                WorkingCalendarViewModel workingCalendar = new WorkingCalendarViewModel()
                {
                    DisplayName = calendar.DisplayName,
                    IsDefault = calendar.IsDefault,
                    IsMondayWork = calendar.IsMondayWork,
                    IsTuesdayWork = calendar.IsTuesdayWork,
                    IsThursdayWork = calendar.IsThursdayWork,
                    IsWednesdayWork = calendar.IsWednesdayWork,
                    IsFridayWork = calendar.IsFridayWork,
                    MinDate = calendar.MinDate.ToString("yyyy-MM-dd"),
                    MaxDate = calendar.MaxDate.ToString("yyyy-MM-dd"),
                    IsSaturdayWork = calendar.IsSaturdayWork,
                    IsSundayWork = calendar.IsSundayWork,
                    Description = calendar.Description,
                    ObjectID = calendar.ObjectID
                };
                if (calendar.WorkingTimeSpans != null && calendar.WorkingTimeSpans.Length > 0)
                {
                    workingCalendar.AMStartHour = calendar.WorkingTimeSpans[0].StartTimeHour;
                    workingCalendar.AMStartMinute = calendar.WorkingTimeSpans[0].StartTimeMinute;
                    workingCalendar.AMEndHour = calendar.WorkingTimeSpans[0].EndTimeHour;
                    workingCalendar.AMEndMinute = calendar.WorkingTimeSpans[0].EndTimeMinute;
                }
                if (calendar.WorkingTimeSpans != null && calendar.WorkingTimeSpans.Length > 1)
                {
                    workingCalendar.PMStartHour = calendar.WorkingTimeSpans[1].StartTimeHour;
                    workingCalendar.PMStartMinute = calendar.WorkingTimeSpans[1].StartTimeMinute;
                    workingCalendar.PMEndHour = calendar.WorkingTimeSpans[1].EndTimeHour;
                    workingCalendar.PMEndMinute = calendar.WorkingTimeSpans[1].EndTimeMinute;
                }
                result = new ActionResult(true, string.Empty, workingCalendar);
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
        public JsonResult SaveWorkingCalendar(WorkingCalendarViewModel workingCalendar)
        {
            ActionResult    result   = null;
            WorkingCalendar calendar = null;

            if (!string.IsNullOrEmpty(workingCalendar.ObjectID))
            {
                calendar = this.Engine.WorkingCalendarManager.GetCalendar(workingCalendar.ObjectID);
                if (calendar == null)
                {
                    result = new ActionResult(false, "WorkingCalendar.CalendarNotExists");
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                calendar = new WorkingCalendar();
            }

            calendar.DisplayName     = workingCalendar.DisplayName;
            calendar.IsDefault       = workingCalendar.IsDefault;
            calendar.IsMondayWork    = workingCalendar.IsMondayWork;
            calendar.IsTuesdayWork   = workingCalendar.IsTuesdayWork;
            calendar.IsThursdayWork  = workingCalendar.IsThursdayWork;
            calendar.IsWednesdayWork = workingCalendar.IsWednesdayWork;
            calendar.IsFridayWork    = workingCalendar.IsFridayWork;
            calendar.MinDate         = Convert.ToDateTime(workingCalendar.MinDate);
            calendar.MaxDate         = Convert.ToDateTime(workingCalendar.MaxDate);
            calendar.IsSaturdayWork  = workingCalendar.IsSaturdayWork;
            calendar.IsSundayWork    = workingCalendar.IsSundayWork;
            calendar.Description     = workingCalendar.Description;

            List <WorkingTimeSpan> times = new List <WorkingTimeSpan>();

            times.Add(new WorkingTimeSpan()
            {
                StartTimeHour   = workingCalendar.AMStartHour,
                StartTimeMinute = workingCalendar.AMStartMinute,
                EndTimeHour     = workingCalendar.AMEndHour,
                EndTimeMinute   = workingCalendar.AMEndMinute
            });
            times.Add(new WorkingTimeSpan()
            {
                StartTimeHour   = workingCalendar.PMStartHour,
                StartTimeMinute = workingCalendar.PMStartMinute,
                EndTimeHour     = workingCalendar.PMEndHour,
                EndTimeMinute   = workingCalendar.PMEndMinute
            });
            calendar.WorkingTimeSpans = times.ToArray();

            //if (workingCalendar.WorkingTimeSpans == null || workingCalendar.WorkingTimeSpans.Length == 0)
            //{// 没有设置工作时间
            //    result = new ActionResult(false, "WorkingCalendar.NoWorkingTimeSpans");
            //    return Json(result, JsonRequestBehavior.AllowGet);
            //}
            //else
            if (!workingCalendar.IsMondayWork &&
                !workingCalendar.IsTuesdayWork &&
                !workingCalendar.IsWednesdayWork &&
                !workingCalendar.IsThursdayWork &&
                !workingCalendar.IsFridayWork &&
                !workingCalendar.IsSaturdayWork &&
                !workingCalendar.IsSundayWork)
            {// 没有设置工作时间
                result = new ActionResult(false, "WorkingCalendar.NoWorkingDays");
                return(Json(result, JsonRequestBehavior.DenyGet));
            }

            if (calendar.MaxDate.Subtract(calendar.MinDate).TotalDays > 366 * 10)
            {
                result = new ActionResult(false, "WorkingCalendar.DaysToLong");
                return(Json(result, JsonRequestBehavior.DenyGet));
            }

            return(ExecuteFunctionRun(() =>
            {
                if (calendar.Serialized)
                {
                    this.Engine.WorkingCalendarManager.UpdateCalendar(calendar);
                }
                else
                {
                    this.Engine.WorkingCalendarManager.AddCalendar(calendar);
                }
                result = new ActionResult(true, "msgGlobalString.SaveSucced");

                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }