public ActionResult List(Models.StudyRoomStudent.List vm) { return(Code.MvcHelper.Post(null, Url.Action("List", new { studyId = vm.StudyId, roomId = vm.RoomId, searchText = vm.SearchText }))); }
public ActionResult List() { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.StudyRoomStudent.List(); vm.RoomName = db.Set <Basis.Entity.tbRoom>().Find(vm.RoomId).RoomName; var tb = from p in db.Table <Study.Entity.tbStudyRoomStudent>() where p.tbStudy.Id == vm.StudyId && p.tbRoom.Id == vm.RoomId && p.tbStudy.IsDeleted == false && p.tbRoom.IsDeleted == false && p.tbStudent.IsDeleted == false select p; if (string.IsNullOrEmpty(vm.SearchText) == false) { tb = tb.Where(d => d.tbStudent.StudentCode.Contains(vm.SearchText) || d.tbStudent.StudentName.Contains(vm.SearchText)); } vm.StudyRoomStudentList = (from p in tb orderby p.tbStudent.StudentCode select new Dto.StudyRoomStudent.List { Id = p.Id, StudentId = p.tbStudent.Id, StudyId = p.tbStudy.Id, RoomId = p.tbRoom.Id, RoomName = p.tbRoom.RoomName, StudentCode = p.tbStudent.StudentCode, SexName = p.tbStudent.tbSysUser.tbSex.SexName, StudentName = p.tbStudent.StudentName }).ToList(); return(View(vm)); } }
public ActionResult Export() { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.StudyRoomStudent.List(); var file = System.IO.Path.GetTempFileName(); var tb = from p in db.Table <Study.Entity.tbStudyRoomStudent>() where p.tbStudy.Id == vm.StudyId && p.tbRoom.Id == vm.RoomId && p.tbStudy.IsDeleted == false && p.tbRoom.IsDeleted == false && p.tbStudent.IsDeleted == false select p; if (string.IsNullOrEmpty(vm.SearchText) == false) { tb = tb.Where(d => d.tbStudent.StudentCode.Contains(vm.SearchText) || d.tbStudent.StudentName.Contains(vm.SearchText)); } vm.StudyRoomStudentList = (from p in tb orderby p.tbStudent.StudentCode select new Dto.StudyRoomStudent.List { Id = p.Id, StudentId = p.tbStudent.Id, StudyId = p.tbStudy.Id, RoomId = p.tbRoom.Id, RoomName = p.tbRoom.RoomName, StudentCode = p.tbStudent.StudentCode, SexName = p.tbStudent.tbSysUser.tbSex.SexName, StudentName = p.tbStudent.StudentName }).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("性别"), }); var index = 0; foreach (var a in vm.StudyRoomStudentList) { index++; var dr = dt.NewRow(); dr["序号"] = index.ToString(); dr["教室"] = a.RoomName; dr["学号"] = a.StudentCode; dr["姓名"] = a.StudentName; dr["性别"] = a.SexName; 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()); } } }