InschoolAgeStatusDAL.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.DataLogic.Common.CalendarManage;
  7. using EMIS.ViewModel.Students.HighBaseTable;
  8. namespace EMIS.DataLogic.Common.Students.HighBaseTable
  9. {
  10. public class InschoolAgeStatusDAL
  11. {
  12. public InschoolAgeStatusRepository InschoolAgeStatusRepository { get; set; }
  13. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  14. public StudentRepository StudentRepository { get; set; }
  15. public StudentProfileRepository StudentProfileRepository { get; set; }
  16. public ClassmajorRepository ClassmajorRepository { get; set; }
  17. public GrademajorRepository GrademajorRepository { get; set; }
  18. public FacultymajorRepository FacultymajorRepository { get; set; }
  19. public SchoolyearRepository SchoolyearRepository { get; set; }
  20. public RecruitstudentsRepository RecruitstudentsRepository { get; set; }
  21. public InSchoolSettingRepository InSchoolSettingRepository { get; set; }
  22. public EducationTypeSettingRepository EducationTypeSettingRepository { get; set; }
  23. public SchoolYearDAL SchoolYearDAL { get; set; }
  24. public StudentReportRepository StudentReportRepository { get; set; }
  25. //public IQueryable<InschoolAgeStatusView> GetStudentBirthDay(int? schoolYear)
  26. //{
  27. // var query = from student in StudentRepository.GetList(x => x.StudentStatus == (int)EMIS.ViewModel.CF_StudentStatus.registration)
  28. // join profile in StudentProfileRepository.Entities on student.UserID equals profile.UserID
  29. // join clmajor in ClassmajorRepository.Entities on student.ClassmajorID equals clmajor.ClassmajorID
  30. // join grmajor in GrademajorRepository.Entities on clmajor.GrademajorID equals grmajor.GrademajorID
  31. // join famajor in FacultymajorRepository.Entities on grmajor.FacultymajorID equals famajor.FacultymajorID
  32. // join edutype in EducationTypeSettingRepository.Entities on famajor.EducationID equals edutype.EducationID
  33. // select new InschoolAgeStatusView
  34. // {
  35. // UserID=student.UserID,
  36. // BirthDate =profile.BirthDate
  37. // };
  38. // return query;
  39. //}
  40. public IQueryable<InschoolAgeStatusView> GetInschoolAgeStatusCount(int? schoolYear)
  41. {
  42. //var year = DateTime.Now.Year;
  43. //var schYear = SchoolYearDAL.GetSchoolYearQueryable(x => x.IsCurrent).FirstOrDefault().Years;
  44. var query = from student in StudentRepository.Entities
  45. join inschool in InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true)
  46. on student.InSchoolStatusID equals inschool.InSchoolStatusID
  47. join profile in StudentProfileRepository.Entities on student.UserID equals profile.UserID
  48. join clmajor in ClassmajorRepository.Entities on student.ClassmajorID equals clmajor.ClassmajorID
  49. join grmajor in GrademajorRepository.Entities on clmajor.GrademajorID equals grmajor.GrademajorID
  50. join famajor in FacultymajorRepository.Entities on grmajor.FacultymajorID equals famajor.FacultymajorID
  51. join edutype in EducationTypeSettingRepository.Entities on famajor.EducationID equals edutype.EducationID
  52. //join report in
  53. // (
  54. // from report in StudentReportRepository.GetList(x => x.RecordStatus > (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE
  55. // && x.ReportStatusID == (int)EMIS.ViewModel.CF_ReportStatus.Havetoreportforduty)
  56. // join schoolyear in SchoolyearRepository.Entities on report.SchoolyearID equals schoolyear.SchoolyearID
  57. // where schoolyear.Years == schoolYear
  58. // select report.UserID
  59. // ).Distinct() on student.UserID equals report
  60. group student by new
  61. {
  62. student.SexID,
  63. edutype.EducationTypeID,
  64. age = (schoolYear - student.BirthDate.Value.Year)
  65. + ((student.BirthDate.Value.Month >= 9 && student.BirthDate.Value.Day >= 1) ? 0 : 1)
  66. } into g
  67. select new InschoolAgeStatusView
  68. {
  69. Age = g.Key.age,
  70. //StudentType = g.Key.StudentType,
  71. Sex = g.Key.SexID,
  72. EducationTypeID = g.Key.EducationTypeID,
  73. Count = g.Count()
  74. };
  75. return query;
  76. }
  77. }
  78. }