using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.ViewModel.DQPSystem; using System.Linq.Expressions; using EMIS.Entities; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.Students; namespace EMIS.DataLogic.DQPSystem { public class SOCDetailGroupDAL { public SOCRepository SOCRepository { get; set; } public SOCDetailRepository SOCDetailRepository { get; set; } public SOCDetailAttachmentRepository SOCDetailAttachmentRepository { get; set; } public SOCDetailGroupRepository SOCDetailGroupRepository { get; set; } public StudentRepository studentRepository { get; set; } public EducationMissionRepository educationMissionRepository { get; set; } public IQueryable GetSOCDetailGroupViewQueryable(Expression> exp) { var query = from fgro in SOCDetailGroupRepository.GetList(exp) join edu in educationMissionRepository.Entities on fgro.DQP_SOCDetail.DQP_SOC.EducationMissionID equals edu.EducationMissionID into gedu from edu in gedu.DefaultIfEmpty() //join att in SOCDetailAttachmentRepository.Entities //on detail.SOCDetailID equals att.SOCDetailID //into gatt //from fatt in gatt.DefaultIfEmpty() select new SOCDetailGroupView { SOCDetailGroupID = fgro.SOCDetailGroupID, EducationMissionID = fgro.DQP_SOCDetail.DQP_SOC.EducationMissionID, EducationMissionName = edu.ClassName, SOCDetailID = fgro.DQP_SOCDetail.SOCDetailID, Name = fgro.DQP_SOCDetail.Name, CoursematerialID = fgro.DQP_SOCDetail.DQP_SOC.CoursematerialID, CourseCode = fgro.DQP_SOCDetail.DQP_SOC.EM_Coursematerial.CourseCode, CourseName = fgro.DQP_SOCDetail.DQP_SOC.EM_Coursematerial.CourseName, No = fgro.No, Score = fgro.Score, StudentCount = fgro.CF_Student.Select(x => x.Sys_User).Distinct().Count(), StudentList = fgro.CF_Student.Select(x => x.Sys_User).Distinct() }; return query; } /// /// 获取学生信息 /// /// /// public IQueryable GetStudentListForGroup(Guid? SOCDetailID) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var query = from a in SOCRepository.GetList(x => x.DQP_SOCDetail.Any(y => y.SOCDetailID == SOCDetailID)) from c in a.DQP_SOCStaff.FirstOrDefault(x => x.UserID == curUser.UserID).CF_Student select new BaseStudentView { UserID = c.UserID, LoginID = c.Sys_User.LoginID, UserName = c.Sys_User.Name, SexID = c.SexID, IDNumber = c.IDNumber, InSchoolStatusID = c.InSchoolStatusID, StudentStatus = c.StudentStatus, ClassmajorCode = c.CF_Classmajor.No, ClassmajorName = c.CF_Classmajor.Name, }; return query; } public IQueryable GetGroupSOCDetailViewQueryable(Expression> exp) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var query = from detail in SOCDetailRepository.GetList(exp) select new GroupSOCDetailView { SOCDetailID = detail.SOCDetailID, StudentTotalNum = detail.DQP_SOC.DQP_SOCStaff.FirstOrDefault(x => x.UserID == curUser.UserID).CF_Student.Distinct().Count(), }; return query; } //public List GetStudentsForGroup(Expression> exp) //{ // var query = SOCRepository.GetList(exp, x => x.CF_Student).ToList(); // return query; //} /// /// 获取学生信息 /// /// /// public IQueryable GetSOCDetailGroupViewStudentList(Guid? SOCDetailGroupID) { var query = from a in SOCDetailGroupRepository.GetList(x => x.SOCDetailGroupID == SOCDetailGroupID) from c in a.CF_Student select new BaseStudentView { UserID = c.UserID, LoginID = c.Sys_User.LoginID, UserName = c.Sys_User.Name, SexID = c.SexID, IDNumber = c.IDNumber, InSchoolStatusID = c.InSchoolStatusID, StudentStatus = c.StudentStatus, ClassmajorCode = c.CF_Classmajor.No, ClassmajorName = c.CF_Classmajor.Name, }; return query; } /// /// 获取学生信息(未分组) /// /// /// public IQueryable GetNotGroupStudentList(Guid? SOCDetailGroupID) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var groupStu = from a in SOCDetailRepository.GetList(x => x.DQP_SOCDetailGroup.Any(y => y.SOCDetailGroupID == SOCDetailGroupID)) from gro in a.DQP_SOCDetailGroup from stu in gro.CF_Student select new { UserID = stu.UserID, }; var gStuID = groupStu.Select(x => x.UserID).Distinct().ToList(); var query = from a in SOCDetailGroupRepository.GetList(x => x.SOCDetailGroupID == SOCDetailGroupID) from stu in a.DQP_SOCDetail.DQP_SOC.DQP_SOCStaff.FirstOrDefault(y => y.UserID == curUser.UserID).CF_Student join gstu in studentRepository.Entities on stu.UserID equals gstu.UserID where !gStuID.Contains(stu.UserID) select new BaseStudentView { UserID = stu.UserID, LoginID = gstu.Sys_User.LoginID, UserName = gstu.Sys_User.Name, SexID = stu.SexID, IDNumber = stu.IDNumber, InSchoolStatusID = stu.InSchoolStatusID, StudentStatus = stu.StudentStatus, ClassmajorCode = gstu.CF_Classmajor.No, ClassmajorName = gstu.CF_Classmajor.Name, }; return query; } } }