InschoolAgeStatusServices.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.Students.HighBaseTable;
  6. using EMIS.DataLogic.SystemSetting;
  7. using EMIS.DataLogic.Common.CalendarManage;
  8. using EMIS.ViewModel;
  9. using EMIS.Entities;
  10. using System.Transactions;
  11. namespace EMIS.CommonLogic.Students.HighBaseTable
  12. {
  13. public class InschoolAgeStatusServices : BaseServices, IInschoolAgeStatusServices
  14. {
  15. public InschoolAgeStatusDAL InschoolAgeStatusDAL { get; set; }
  16. public DictionaryItemDAL DictionaryItemDAL { get; set; }
  17. public SchoolYearDAL SchoolYearDAL { get; set; }
  18. public void Update(int SchoolYear)
  19. {
  20. try
  21. {
  22. var schoolYear = SchoolYearDAL.GetSchoolYearQueryable(x => x.IsCurrent).FirstOrDefault().Years;
  23. var sex = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == typeof(CF_Sex).Name).Select(x => x.Value).ToList();
  24. var educationType = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_EducationType).Name).Select(x => x.Value).ToList();
  25. var query = InschoolAgeStatusDAL.GetInschoolAgeStatusCount(SchoolYear).ToList();
  26. var age = query.Select(x => x.Age).Distinct().ToList();
  27. query.ForEach(x =>
  28. {
  29. if (x.Age <= 17)
  30. x.Age = 17;
  31. else if (x.Age >= 31)
  32. x.Age = 31;
  33. });
  34. List<HB_InschoolAgeStatus> inschoolAgeStatusList = new List<HB_InschoolAgeStatus>();
  35. for (int i = 17; i <= 31;i++ )
  36. {
  37. foreach (var s in sex)
  38. {
  39. foreach (var t in educationType)
  40. {
  41. HB_InschoolAgeStatus inschoolAgeStatus = new HB_InschoolAgeStatus();
  42. inschoolAgeStatus.InschoolAgeStatusID = Guid.NewGuid();
  43. inschoolAgeStatus.Year = SchoolYear;
  44. inschoolAgeStatus.Age = i;
  45. inschoolAgeStatus.Sex = s;
  46. inschoolAgeStatus.EducationTypeID = t;
  47. inschoolAgeStatus.Count = query.Where(x => x.Sex == s && x.EducationTypeID == t && x.Age == i).Select(x => x.Count).Sum();
  48. SetNewStatus(inschoolAgeStatus);
  49. inschoolAgeStatusList.Add(inschoolAgeStatus);
  50. }
  51. }
  52. }
  53. using (TransactionScope ts = new TransactionScope())
  54. {
  55. UnitOfWork.Delete<HB_InschoolAgeStatus>(x => x.Year == SchoolYear);
  56. UnitOfWork.BulkInsert(inschoolAgeStatusList);//统一写入
  57. ts.Complete();
  58. }
  59. }
  60. catch (Exception ex)
  61. {
  62. throw new Exception(ex.Message);
  63. }
  64. }
  65. public List<string> SchoolYearDropDownList()
  66. {
  67. var item = InschoolAgeStatusDAL.InschoolAgeStatusRepository.Entities.Select(x => x.Year.ToString()).Distinct().ToList();
  68. return item;
  69. }
  70. }
  71. }