Esempio n. 1
0
        public Dictionary <DateCycleTypeEnum, Sum_StudyFactDateCycle> FetchOrCreateCycleData(int studentId, int classId, DateTime asOfDate)
        {
            Dictionary <DateCycleTypeEnum, Sum_StudyFactDateCycle> dic = new Dictionary <DateCycleTypeEnum, Sum_StudyFactDateCycle>();

            SumStudentBll bll = new SumStudentBll();
            List <Sum_StudyFactDateCycle> cycles = bll.GetCycleDatasByStudent(studentId, classId);

            Sum_StudyFactDateCycle totalCycle = cycles.FirstOrDefault(x => x.Sdc_CycleType == (int)DateCycleTypeEnum.Total);

            if (totalCycle == null)
            {
                totalCycle = new Sum_StudyFactDateCycle();
                totalCycle.ForceAudit();
                totalCycle.Sdc_CycleType = (int)DateCycleTypeEnum.Total;
                totalCycle.Sdc_Date      = new DateTime(1900, 1, 1);
            }
            dic[DateCycleTypeEnum.Total] = totalCycle;

            Sum_StudyFactDateCycle yearCycle = cycles.FirstOrDefault(x => x.Sdc_CycleType == (int)DateCycleTypeEnum.Year);

            if (yearCycle == null || yearCycle.Sdc_Date != DateTool.FirstDayOfYear(asOfDate))
            {
                int id = yearCycle == null ? 0 : yearCycle.Sdc_Id;
                yearCycle = new Sum_StudyFactDateCycle();
                yearCycle.ForceAudit();
                yearCycle.Sdc_Id        = id;
                yearCycle.Sdc_CycleType = (int)DateCycleTypeEnum.Year;
                yearCycle.Sdc_Date      = DateTool.FirstDayOfYear(asOfDate);
            }
            dic[DateCycleTypeEnum.Year] = yearCycle;

            Sum_StudyFactDateCycle monthCycle = cycles.FirstOrDefault(x => x.Sdc_CycleType == (int)DateCycleTypeEnum.Month);

            if (monthCycle == null || monthCycle.Sdc_Date != DateTool.FirstDayOfMonth(asOfDate))
            {
                int id = monthCycle == null ? 0 : monthCycle.Sdc_Id;
                monthCycle = new Sum_StudyFactDateCycle();
                monthCycle.ForceAudit();
                monthCycle.Sdc_Id        = id;
                monthCycle.Sdc_CycleType = (int)DateCycleTypeEnum.Month;
                monthCycle.Sdc_Date      = DateTool.FirstDayOfMonth(asOfDate);
            }
            dic[DateCycleTypeEnum.Month] = monthCycle;

            Sum_StudyFactDateCycle weekCycle = cycles.FirstOrDefault(x => x.Sdc_CycleType == (int)DateCycleTypeEnum.Week);

            if (weekCycle == null || weekCycle.Sdc_Date != DateTool.FirstDayOfWeek(asOfDate))
            {
                int id = weekCycle == null ? 0 : weekCycle.Sdc_Id;
                weekCycle = new Sum_StudyFactDateCycle();
                weekCycle.ForceAudit();
                weekCycle.Sdc_Id        = id;
                weekCycle.Sdc_CycleType = (int)DateCycleTypeEnum.Week;
                weekCycle.Sdc_Date      = DateTool.FirstDayOfWeek(asOfDate);
            }
            dic[DateCycleTypeEnum.Week] = weekCycle;

            return(dic);
        }
Esempio n. 2
0
        public void TestDate()
        {
            DateTime x = DateTool.FirstDayOfWeek(DateTime.Now);
            DateTime y = DateTool.FirstDayOfMonth(DateTime.Now);
            DateTime z = DateTool.FirstDayOfYear(DateTime.Now);

            x = DateTool.FirstDayOfWeek(new DateTime(2019, 10, 28));
            x = DateTool.FirstDayOfWeek(new DateTime(2019, 11, 3));
            y = DateTool.FirstDayOfMonth(new DateTime(2019, 10, 1));
            y = DateTool.FirstDayOfMonth(new DateTime(2019, 10, 31));
            //z = DateTool.FirstDayOfMonth(new DateTime(2019, 11, 3));
        }