RecruitStatusServices.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.Students;
  6. using EMIS.DataLogic.SystemSetting;
  7. using EMIS.ViewModel;
  8. using EMIS.DataLogic.Common.CalendarManage;
  9. using EMIS.Entities;
  10. using System.Transactions;
  11. using EMIS.DataLogic.Common.Students.HighBaseTable;
  12. namespace EMIS.CommonLogic.Students.HighBaseTable
  13. {
  14. public class RecruitStatusServices : BaseServices, IRecruitStatusServices
  15. {
  16. public RecruitStatusDAL RecruitStatusDAL { get; set; }
  17. public DictionaryItemDAL DictionaryItemDAL { get; set; }
  18. public SchoolYearDAL SchoolYearDAL { get; set; }
  19. public void Update(int SchoolYear)
  20. {
  21. try
  22. {
  23. var schoolYear = SchoolYearDAL.GetSchoolYearQueryable(x => x.IsCurrent).FirstOrDefault().Years;
  24. var territorial = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == typeof(CF_Province).Name).Select(x => x.Value).ToList();
  25. var educationType = DictionaryItemDAL.GetDictionaryItemViewQueryable(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_EducationType).Name).Select(x => x.Value).ToList();
  26. var queryInschoolCount = RecruitStatusDAL.GetRecruitStatusInschoolCount(SchoolYear).ToList();
  27. var queryRecruitCount = RecruitStatusDAL.GetRecruitStatusRecruitCount(SchoolYear).ToList();
  28. List<HB_RecruitStatus> recruitStatusList = new List<HB_RecruitStatus>();
  29. foreach (var i in territorial)
  30. {
  31. foreach (var t in educationType)
  32. {
  33. HB_RecruitStatus recruitStatus = new HB_RecruitStatus();
  34. recruitStatus.RecruitStatusID = Guid.NewGuid();
  35. recruitStatus.Year = SchoolYear;
  36. recruitStatus.Territorial = i;
  37. recruitStatus.EducationTypeID = t;
  38. recruitStatus.RecruitCount = queryRecruitCount.Where(x => x.Territorial == i && x.EducationTypeID == t).Select(x => x.RecruitCount).FirstOrDefault();
  39. recruitStatus.InschoolCount = queryInschoolCount.Where(x => x.Territorial == i && x.EducationTypeID == t).Select(x => x.InschoolCount).FirstOrDefault();
  40. SetNewStatus(recruitStatus);
  41. recruitStatusList.Add(recruitStatus);
  42. }
  43. }
  44. using (TransactionScope ts = new TransactionScope())
  45. {
  46. UnitOfWork.Delete<HB_RecruitStatus>(x => x.Year == SchoolYear);
  47. UnitOfWork.BulkInsert(recruitStatusList);//统一写入
  48. ts.Complete();
  49. }
  50. }
  51. catch (Exception ex)
  52. {
  53. throw new Exception(ex.Message);
  54. }
  55. }
  56. public List<string> SchoolYearDropDownList()
  57. {
  58. var item = RecruitStatusDAL.RecruitStatusRepository.Entities.Select(x => x.Year.ToString()).Distinct().ToList();
  59. return item;
  60. }
  61. }
  62. }