123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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 InschoolAgeStatusServices : BaseServices, IInschoolAgeStatusServices
- {
- public InschoolAgeStatusDAL InschoolAgeStatusDAL { get; set; }
- public DictionaryItemDAL DictionaryItemDAL { get; set; }
- public SchoolYearDAL SchoolYearDAL { get; set; }
- public void Update(int SchoolYear)
- {
- try
- {
- var schoolYear = SchoolYearDAL.GetSchoolYearQueryable(x => x.IsCurrent).FirstOrDefault().Years;
- var sex = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == typeof(CF_Sex).Name).Select(x => x.Value).ToList();
- var educationType = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_EducationType).Name).Select(x => x.Value).ToList();
- var query = InschoolAgeStatusDAL.GetInschoolAgeStatusCount(SchoolYear).ToList();
- var age = query.Select(x => x.Age).Distinct().ToList();
- query.ForEach(x =>
- {
- if (x.Age <= 17)
- x.Age = 17;
- else if (x.Age >= 31)
- x.Age = 31;
- });
- List<HB_InschoolAgeStatus> inschoolAgeStatusList = new List<HB_InschoolAgeStatus>();
- for (int i = 17; i <= 31;i++ )
- {
- foreach (var s in sex)
- {
- foreach (var t in educationType)
- {
- HB_InschoolAgeStatus inschoolAgeStatus = new HB_InschoolAgeStatus();
- inschoolAgeStatus.InschoolAgeStatusID = Guid.NewGuid();
- inschoolAgeStatus.Year = SchoolYear;
- inschoolAgeStatus.Age = i;
- inschoolAgeStatus.Sex = s;
- inschoolAgeStatus.EducationTypeID = t;
- inschoolAgeStatus.Count = query.Where(x => x.Sex == s && x.EducationTypeID == t && x.Age == i).Select(x => x.Count).Sum();
- SetNewStatus(inschoolAgeStatus);
- inschoolAgeStatusList.Add(inschoolAgeStatus);
- }
- }
- }
- using (TransactionScope ts = new TransactionScope())
- {
- UnitOfWork.Delete<HB_InschoolAgeStatus>(x => x.Year == SchoolYear);
- UnitOfWork.BulkInsert(inschoolAgeStatusList);//统一写入
- ts.Complete();
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- public List<string> SchoolYearDropDownList()
- {
- var item = InschoolAgeStatusDAL.InschoolAgeStatusRepository.Entities.Select(x => x.Year.ToString()).Distinct().ToList();
- return item;
- }
- }
- }
|