using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.Students.HighBaseTable; using EMIS.DataLogic.SystemSetting; using EMIS.DataLogic.Common.CalendarManage; using EMIS.ViewModel; using EMIS.Entities; using System.Transactions; namespace EMIS.CommonLogic.Students.HighBaseTable { public class BachelorSpecialtyStudentCountServices : BaseServices, IBachelorSpecialtyStudentCountServices { public DictionaryItemDAL DictionaryItemDAL { get; set; } public SchoolYearDAL SchoolYearDAL { get; set; } public BachelorSpecialtyStudentCountDAL BachelorSpecialtyStudentCountDAL { get; set; } public void Update() { try { var query = BachelorSpecialtyStudentCountDAL.GetStudent().ToList(); //var specialty = query.Select(x => x.SpecialtyID).Distinct().ToList(); //var learningform = query.Select(x => x.LearningformID).Distinct().ToList(); var sex = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == typeof(CF_Sex).Name).Select(x => x.Value).ToList(); var schoolYear = SchoolYearDAL.GetSchoolYearQueryable(x => x.IsCurrent).FirstOrDefault().Years; //在校生数 var queryInschool = BachelorSpecialtyStudentCountDAL.GetInschoolCount(schoolYear).ToList(); //招生数 var queryRecruit = BachelorSpecialtyStudentCountDAL.GetRecruitCount(schoolYear).ToList(); //春季招生数,普教需要 var querySpringRecruit = BachelorSpecialtyStudentCountDAL.SpringRecruitCount(schoolYear).ToList(); //预计毕业生数 var queryPlanGraduation = BachelorSpecialtyStudentCountDAL.PlanGraduationCount(schoolYear).ToList(); //毕业生数 var queryGraduated = BachelorSpecialtyStudentCountDAL.GetGraduationCount(schoolYear).ToList(); //应届毕业生数 var queryGraduating = BachelorSpecialtyStudentCountDAL.GetGraduatingCount(schoolYear).ToList(); //授予学位数 var queryDegreed = BachelorSpecialtyStudentCountDAL.GetDegreedCount(schoolYear).ToList(); List SpecialtyStudentCountList = new List(); List SpecialtyStudentCountDetailList = new List(); foreach (var i in query) { foreach (var j in sex) { HB_BachelorSpecialtyStudentCount SpecialtyStudentCount = new HB_BachelorSpecialtyStudentCount(); SpecialtyStudentCount.BachelorSpecialtyStudentCountID = Guid.NewGuid(); SpecialtyStudentCount.Year = schoolYear; SpecialtyStudentCount.Sex = j; SpecialtyStudentCount.EducationTypeID = (int)EMIS.ViewModel.CF_EducationType.Special; SpecialtyStudentCount.LearningformID = i.LearningformID; SpecialtyStudentCount.StandardID = i.StandardID; SpecialtyStudentCount.LearnSystem = i.LearnSystem; SpecialtyStudentCount.IsTeacherIdentification = string.IsNullOrEmpty(i.IsTeacherIdentification) ? false : true; //毕业生数 SpecialtyStudentCount.GraduationCount = queryGraduated.Where(x => x.LearningformID == i.LearningformID && x.Sex == j && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.GraduationCount).FirstOrDefault(); //授予学位数 SpecialtyStudentCount.DegreeCount = queryDegreed.Where(x => x.LearningformID == i.LearningformID && x.Sex == j && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.DegreeCount).FirstOrDefault(); //招生数 SpecialtyStudentCount.RecruitCount = queryRecruit.Where(x => x.LearningformID == i.LearningformID && x.Sex == j && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.RecruitCount).FirstOrDefault(); //预计毕业生数 SpecialtyStudentCount.PlanGraduationCount = queryPlanGraduation.Where(x => x.LearningformID == i.LearningformID && x.Sex == j && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.SpringRecruitCount).FirstOrDefault(); //春季招生数 SpecialtyStudentCount.SpringRecruitCount = querySpringRecruit.Where(x => x.LearningformID == i.LearningformID && x.Sex == j && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.SpringRecruitCount).FirstOrDefault(); //应届毕业生数 SpecialtyStudentCount.GraduatingCount = queryGraduating.Where(x => x.LearningformID == i.LearningformID && x.Sex == j && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).Select(x => x.GraduatingCount).FirstOrDefault(); SetNewStatus(SpecialtyStudentCount); SpecialtyStudentCountList.Add(SpecialtyStudentCount); var list = queryInschool.Where(x => x.LearningformID == i.LearningformID && x.Sex == j && x.StandardID == i.StandardID && x.LearnSystem == i.LearnSystem).ToList(); foreach (var k in list) { HB_BachelorSpecialtyStudentCountDetail SpecialtyStudentCountDetail = new HB_BachelorSpecialtyStudentCountDetail(); SpecialtyStudentCountDetail.BachelorSpecialtyStudentCountDetailID = Guid.NewGuid(); SpecialtyStudentCountDetail.BachelorSpecialtyStudentCountID = SpecialtyStudentCount.BachelorSpecialtyStudentCountID; SpecialtyStudentCountDetail.SchoolyearNumID = k.SchoolyearNumID; SpecialtyStudentCountDetail.InschoolCount = k.InschoolCount; SetNewStatus(SpecialtyStudentCountDetail); SpecialtyStudentCountDetailList.Add(SpecialtyStudentCountDetail); } } } using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => x.HB_BachelorSpecialtyStudentCount.Year == schoolYear); UnitOfWork.Delete(x => x.Year == schoolYear); UnitOfWork.BulkInsert(SpecialtyStudentCountList);//统一写入 UnitOfWork.BulkInsert(SpecialtyStudentCountDetailList);//统一写入 ts.Complete(); } } catch (Exception ex) { throw new Exception(ex.Message); } } //public List SchoolYearDropDownList() //{ // var item = RecruitStatusDAL.RecruitStatusRepository.Entities.Select(x => x.Year.ToString()).Distinct().ToList(); // return item; //} } }