コード例 #1
0
        public ActionResult Edit(int id = 0)
        {
            var vm = new Models.Calendar.Edit();

            if (id > 0)
            {
                using (var db = new XkSystem.Models.DbContext())
                {
                    var tb = (from p in db.Table <Basis.Entity.tbCalendar>()
                              where p.tbYear.Id == vm.YearId && p.CalendarDate == vm.CalendarDate
                              select new Dto.Calendar.Edit()
                    {
                        Id = p.Id,
                        tbWeekId = p.tbWeek.Id,
                        tbYearId = p.tbYear.Id,
                        CalendarDate = p.CalendarDate,
                        Remark = p.Remark
                    }).FirstOrDefault();
                    if (tb != null)
                    {
                        vm.CalendarEdit = tb;
                    }
                }
            }
            else
            {
                vm.CalendarEdit.tbYearId = vm.YearId;
                vm.CalendarDate          = vm.CalendarDate;
            }
            vm.WeekList = WeekController.SelectList();
            return(View(vm));
        }
コード例 #2
0
        public ActionResult List()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.Calendar.List();
                vm.WeekList = WeekController.SelectList();

                vm.YearList = YearController.SelectList(Code.EnumHelper.YearType.Section);
                if (vm.YearId > 0 && vm.YearList.Exists(p => int.Parse(p.Value) == vm.YearId.Value))
                {
                    vm.YearList.ForEach(p => {
                        p.Selected = int.Parse(p.Value) == vm.YearId;
                    });
                }
                //获取当前激活学段的起始日期
                if (vm.FromDate == Code.DateHelper.MinDate || vm.ToDate.Value == Code.DateHelper.MinDate || vm.ToDate.Value < vm.FromDate.Value)
                {
                    var yearId = vm.YearId.HasValue ? vm.YearId.Value : 0;
                    if (yearId == 0)
                    {
                        yearId = vm.YearList.Where(p => p.Selected).Select(p => p.Value).FirstOrDefault().ConvertToInt();
                    }

                    var tbYear = YearController.SelectInfo(yearId);
                    if (tbYear != null)
                    {
                        vm.FromDate = tbYear.FromDate.HasValue ? tbYear.FromDate.Value : Code.DateHelper.MonthFirstDay;
                        vm.ToDate   = tbYear.ToDate.HasValue ? tbYear.ToDate.Value : DateTime.Now;
                    }
                    else
                    {
                        vm.FromDate = Code.DateHelper.MonthFirstDay;
                        vm.ToDate   = DateTime.Now;
                    }
                }
                vm.ToDate = vm.ToDate.Value.AddDays(1).AddSeconds(-1);

                if (vm.YearId == 0 && vm.YearList.Count > 0)
                {
                    vm.YearId = vm.YearList.OrderByDescending(d => d.Selected).FirstOrDefault().Value.ConvertToInt();
                }


                vm.DataList = (from p in db.Table <Entity.tbCalendar>()
                               where p.tbYear.Id == vm.YearId && p.CalendarDate >= vm.FromDate && p.CalendarDate <= vm.ToDate
                               select new Dto.Calendar.List()
                {
                    Id = p.Id,
                    tbWeekId = p.tbWeek.Id,
                    tbWeekName = p.tbWeek.WeekName,
                    tbYear = p.tbYear.YearName,
                    CalendarDate = p.CalendarDate,
                    Remark = p.Remark
                }).ToList();
                vm.DataList.ForEach(p =>
                {
                    p.tbWeekName = TbWeek[p.tbWeekId - 1];
                });
                return(View(vm));
            }
        }