Пример #1
0
 public ActionResult Detail(Models.StudyReport.Detail vm)
 {
     return(Code.MvcHelper.Post(null, Url.Action("Detail", new
     {
         searchText = vm.SearchText,
         studyId = vm.StudyId,
         dateSearchFrom = vm.DateSearchFrom,
         dateSearchTo = vm.DateSearchTo
     })));
 }
Пример #2
0
        public ActionResult DetailExport()
        {
            var vm = new Models.StudyReport.Detail();

            using (var db = new XkSystem.Models.DbContext())
            {
                var file = System.IO.Path.GetTempFileName();

                var fromDate = Convert.ToDateTime(vm.DateSearchFrom);
                var toDate   = Convert.ToDateTime(vm.DateSearchTo).AddDays(1);

                var tbStudyDataList = (from p in db.Table <Study.Entity.tbStudyData>()
                                       .Include(d => d.tbStudy)
                                       .Include(d => d.tbStudent)
                                       .Include(d => d.tbStudyOption)
                                       where p.InputDate >= fromDate && p.InputDate < toDate &&
                                       p.tbStudent.IsDeleted == false &&
                                       p.tbStudyOption.IsDeleted == false &&
                                       p.tbSysUser.IsDeleted == false
                                       select new Dto.StudyData.List
                {
                    StudyId = p.tbStudy.Id,
                    StudyName = p.tbStudy.StudyName,
                    StudentId = p.tbStudent.Id,
                    StudentCode = p.tbStudent.StudentCode,
                    StudentName = p.tbStudent.StudentName,
                    StudyOptionName = p.tbStudyOption.StudyOptionName,
                    Remark = p.Remark,
                    SexName = p.tbStudent.tbSysUser.tbSex.SexName,
                    InputDate = p.InputDate,
                    ClassId = 0,
                    ClassName = "",
                    SysUserName = p.tbSysUser.UserName
                }).ToList();

                var studyIds = (from p in tbStudyDataList
                                select p.StudyId).Distinct().ToList();

                var tbStudyList = (from p in db.Table <Study.Entity.tbStudy>()
                                   where studyIds.Contains(p.Id) &&
                                   p.tbYear.IsDeleted == false
                                   select p).ToList();

                var classList = new List <Dto.StudyClassStudent.List>();
                foreach (var tbStudy in tbStudyList)
                {
                    if (tbStudy.IsRoom)//教室模式
                    {
                        var tbClassList = (from p in db.Table <Study.Entity.tbStudyRoomStudent>()
                                           where p.tbStudy.Id == tbStudy.Id &&
                                           p.tbStudy.IsDeleted == false &&
                                           p.tbRoom.IsDeleted == false &&
                                           p.tbStudent.IsDeleted == false
                                           select new Dto.StudyClassStudent.List
                        {
                            ClassId = p.tbRoom.Id,
                            ClassName = p.tbRoom.RoomName,
                            StudentId = p.tbStudent.Id,
                            StudentCode = p.tbStudent.StudentCode,
                            StudentName = p.tbStudent.StudentName,
                            StudyId = p.tbStudy.Id,
                            StudyName = p.tbStudy.StudyName
                        }).ToList();
                        classList.AddRange(tbClassList);
                    }
                    else//班级模式
                    {
                        var tbClassList = (from p in db.Table <Study.Entity.tbStudyClassStudent>()
                                           where p.tbStudy.Id == tbStudy.Id &&
                                           p.tbStudy.IsDeleted == false &&
                                           p.tbClass.IsDeleted == false &&
                                           p.tbStudent.IsDeleted == false
                                           select new Dto.StudyClassStudent.List
                        {
                            ClassId = p.tbClass.Id,
                            ClassName = p.tbClass.ClassName,
                            StudentId = p.tbStudent.Id,
                            StudentCode = p.tbStudent.StudentCode,
                            StudentName = p.tbStudent.StudentName,
                            StudyId = p.tbStudy.Id,
                            StudyName = p.tbStudy.StudyName
                        }).ToList();

                        classList.AddRange(tbClassList);
                    }
                }
                foreach (var item in tbStudyDataList)
                {
                    var data = classList.Where(d => d.StudyId == item.StudyId && d.StudentId == item.StudentId).FirstOrDefault();
                    if (data != null)
                    {
                        item.ClassId   = data.ClassId;
                        item.ClassName = data.ClassName;
                    }
                }
                vm.StudyReportDetailList = (from p in tbStudyDataList
                                            where p.ClassId != 0
                                            select new Dto.StudyReport.Detail
                {
                    StudyName = p.StudyName,
                    ClassName = p.ClassName,
                    InputDate = p.InputDate,
                    Remark = p.Remark,
                    SysUserName = p.SysUserName,
                    SexName = p.SexName,
                    StudentCode = p.StudentCode,
                    StudentName = p.StudentName,
                    StudyOptionName = p.StudyOptionName
                }).ToList();

                var dt = new System.Data.DataTable();
                dt.Columns.AddRange(new System.Data.DataColumn[]
                {
                    new System.Data.DataColumn("序号"),
                    new System.Data.DataColumn("晚自习"),
                    new System.Data.DataColumn("行政班"),
                    new System.Data.DataColumn("自习日期"),
                    new System.Data.DataColumn("学号"),
                    new System.Data.DataColumn("姓名"),
                    new System.Data.DataColumn("性别"),
                    new System.Data.DataColumn("表现名称"),
                    new System.Data.DataColumn("备注"),
                    new System.Data.DataColumn("录入人员")
                });

                var index = 0;
                foreach (var a in vm.StudyReportDetailList)
                {
                    index++;
                    var dr = dt.NewRow();
                    dr["序号"]   = index.ToString();
                    dr["晚自习"]  = a.StudyName;
                    dr["行政班"]  = a.ClassName;
                    dr["自习日期"] = a.InputDate.ToString(Code.Common.StringToDate);
                    dr["学号"]   = a.StudentCode;
                    dr["姓名"]   = a.StudentName;
                    dr["性别"]   = a.SexName;
                    dr["表现名称"] = a.StudyOptionName;
                    dr["备注"]   = a.Remark;
                    dr["录入人员"] = a.SysUserName;
                    dt.Rows.Add(dr);
                }

                Code.NpoiHelper.DataTableToExcel(file, dt);

                if (string.IsNullOrEmpty(file) == false)
                {
                    return(File(file, Code.Common.DownloadType, Code.Common.ExportByExcel));
                }
                else
                {
                    return(View());
                }
            }
        }
Пример #3
0
        public ActionResult Detail()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.StudyReport.Detail();

                var dateTimeNow = DateTime.Now;

                if (string.IsNullOrEmpty(vm.DateSearchFrom))
                {
                    vm.DateSearchFrom = new DateTime(dateTimeNow.Year, dateTimeNow.Month, 1).ToString(Code.Common.StringToDate);
                }

                if (string.IsNullOrEmpty(vm.DateSearchTo))
                {
                    vm.DateSearchTo = new DateTime(dateTimeNow.Year, dateTimeNow.Month, 1).AddMonths(1).AddDays(-1).ToString(Code.Common.StringToDate);
                }

                var fromDate = Convert.ToDateTime(vm.DateSearchFrom);

                var toDate = Convert.ToDateTime(vm.DateSearchTo).AddDays(1);

                var tbStudyDataList = (from p in db.Table <Study.Entity.tbStudyData>()
                                       .Include(d => d.tbStudy)
                                       .Include(d => d.tbStudent)
                                       .Include(d => d.tbStudyOption)
                                       where p.InputDate >= fromDate && p.InputDate < toDate &&
                                       p.tbStudent.IsDeleted == false &&
                                       p.tbStudyOption.IsDeleted == false &&
                                       p.tbSysUser.IsDeleted == false
                                       select new Dto.StudyData.List
                {
                    StudyId = p.tbStudy.Id,
                    StudyName = p.tbStudy.StudyName,
                    StudentId = p.tbStudent.Id,
                    StudentCode = p.tbStudent.StudentCode,
                    StudentName = p.tbStudent.StudentName,
                    StudyOptionName = p.tbStudyOption.StudyOptionName,
                    Remark = p.Remark,
                    SexName = p.tbStudent.tbSysUser.tbSex.SexName,
                    InputDate = p.InputDate,
                    ClassId = 0,
                    ClassName = "",
                    SysUserName = p.tbSysUser.UserName
                }).ToList();

                var studyIds = (from p in tbStudyDataList
                                select p.StudyId).Distinct().ToList();

                var tbStudyList = (from p in db.Table <Study.Entity.tbStudy>()
                                   where studyIds.Contains(p.Id) &&
                                   p.tbYear.IsDeleted == false
                                   select p).ToList();

                var classList = new List <Dto.StudyClassStudent.List>();
                foreach (var tbStudy in tbStudyList)
                {
                    if (tbStudy.IsRoom)//教室模式
                    {
                        var tbClassList = (from p in db.Table <Study.Entity.tbStudyRoomStudent>()
                                           where p.tbStudy.Id == tbStudy.Id &&
                                           p.tbStudy.IsDeleted == false &&
                                           p.tbRoom.IsDeleted == false &&
                                           p.tbStudent.IsDeleted == false
                                           select new Dto.StudyClassStudent.List
                        {
                            ClassId = p.tbRoom.Id,
                            ClassName = p.tbRoom.RoomName,
                            StudentId = p.tbStudent.Id,
                            StudentCode = p.tbStudent.StudentCode,
                            StudentName = p.tbStudent.StudentName,
                            StudyId = p.tbStudy.Id,
                            StudyName = p.tbStudy.StudyName
                        }).ToList();
                        classList.AddRange(tbClassList);
                    }
                    else//班级模式
                    {
                        var tbClassList = (from p in db.Table <Study.Entity.tbStudyClassStudent>()
                                           where p.tbStudy.Id == tbStudy.Id &&
                                           p.tbStudy.IsDeleted == false &&
                                           p.tbClass.IsDeleted == false &&
                                           p.tbStudent.IsDeleted == false
                                           select new Dto.StudyClassStudent.List
                        {
                            ClassId = p.tbClass.Id,
                            ClassName = p.tbClass.ClassName,
                            StudentId = p.tbStudent.Id,
                            StudentCode = p.tbStudent.StudentCode,
                            StudentName = p.tbStudent.StudentName,
                            StudyId = p.tbStudy.Id,
                            StudyName = p.tbStudy.StudyName
                        }).ToList();

                        classList.AddRange(tbClassList);
                    }
                }
                foreach (var item in tbStudyDataList)
                {
                    var data = classList.Where(d => d.StudyId == item.StudyId && d.StudentId == item.StudentId).FirstOrDefault();
                    if (data != null)
                    {
                        item.ClassId   = data.ClassId;
                        item.ClassName = data.ClassName;
                    }
                }
                vm.StudyReportDetailList = (from p in tbStudyDataList
                                            where p.ClassId != 0
                                            select new Dto.StudyReport.Detail
                {
                    StudyName = p.StudyName,
                    ClassName = p.ClassName,
                    InputDate = p.InputDate,
                    Remark = p.Remark,
                    SysUserName = p.SysUserName,
                    SexName = p.SexName,
                    StudentCode = p.StudentCode,
                    StudentName = p.StudentName,
                    StudyOptionName = p.StudyOptionName
                }).ToList();

                return(View(vm));
            }
        }