Exemplo n.º 1
0
        /// <summary>
        /// 快速创建天模板的工厂方法
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="beginTime"></param>
        /// <param name="blockCount"></param>
        /// <param name="spanMinutes"></param>
        /// <param name="restMinutes"></param>
        /// <returns></returns>
        public static SectionTemplate FastCreateSectionTemplateOfDay(string templateName, DateTime beginTime, int blockCount, int spanMinutes, int restMinutes)
        {
            NbGuard.MakeSureIsNotDefault(templateName);
            NbGuard.MakeSureIsNotDefault(beginTime);
            NbGuard.MakeSureIsNotDefault(blockCount);
            NbGuard.MakeSureIsNotDefault(spanMinutes);

            var sectionTemplate = new SectionTemplate();

            sectionTemplate.Id   = GuidHelper.GenerateComb();
            sectionTemplate.Name = templateName;

            var currentBeginTime = beginTime;
            var blockSpan        = spanMinutes + restMinutes;

            for (int i = 0; i < blockCount; i++)
            {
                var currentRange = DateTimeRange.CreateMinuteRange(currentBeginTime, blockSpan);
                var section      = new Section()
                {
                    DateTimeRange = currentRange,
                    Title         = string.Format("第{0}节", i + 1)
                };

                sectionTemplate.AddSection(section);
                currentBeginTime = currentBeginTime.AddMinutes(blockSpan);
            }

            return(sectionTemplate);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 默认模板的工厂方法
        /// </summary>
        /// <returns></returns>
        public static SectionTemplate FastCreateSectionTemplateOfDay()
        {
            var sectionTemplate = new SectionTemplate();

            sectionTemplate.Name = "默认模板";

            var currentBeginTime = new DateTime(2000, 1, 1, 8, 0, 0);
            int spanMinutes      = 45;
            int restMinutes      = 10;
            var blockSpan        = spanMinutes + restMinutes;

            //第1节 08:00 ~ 08:45
            //第2节 09:00 ~ 09:45
            //第3节 10:00 ~ 10:45
            //第4节 11:00 ~ 11:45
            //午休  12:00 ~ 13:00
            //第5节 13:00 ~ 13:45
            //第6节 14:00 ~ 14:45
            //第7节 15:00 ~ 15:45
            //第8节 16:00 ~ 16:45

            for (int i = 0; i < 4; i++)
            {
                var currentRange = DateTimeRange.CreateMinuteRange(currentBeginTime, spanMinutes);
                var section      = new Section()
                {
                    DateTimeRange = currentRange,
                    Title         = string.Format("第{0}节", i + 1)
                };
                sectionTemplate.AddSection(section);

                currentBeginTime = currentBeginTime.AddMinutes(blockSpan);
            }

            currentBeginTime = new DateTime(2000, 1, 1, 14, 0, 0);

            for (int i = 5; i < 9; i++)
            {
                var currentRange = DateTimeRange.CreateMinuteRange(currentBeginTime, spanMinutes);
                var section      = new Section()
                {
                    DateTimeRange = currentRange,
                    Title         = string.Format("第{0}节", i)
                };
                sectionTemplate.AddSection(section);

                currentBeginTime = currentBeginTime.AddMinutes(blockSpan);
            }


            return(sectionTemplate);
        }