123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using Bowin.Common.Linq;
- using EMIS.DataLogic.Repositories;
- using EMIS.ViewModel.UniversityManage.ClassroomManage;
- using EMIS.Entities;
- using EMIS.ViewModel.ExaminationManage;
- using EMIS.ViewModel.ExaminationApply;
- using EMIS.ViewModel;
- using EMIS.DataLogic.UniversityManage.ClassroomManage;
- namespace EMIS.DataLogic.ExaminationManage
- {
- public class RoomSettingDAL
- {
- public ExaminationRoomSettingRepository ExaminationRoomSettingRepository { get; set; }
- public ExaminationRoomLayoutRepository ExaminationRoomLayoutRepository { get; set; }
- public ExaminationPlanRepository ExaminationPlanRepository { get; set; }
- public ClassroomRepository ClassroomRepository { get; set; }
- public DictionaryItemRepository DictionaryItemRepository { get; set; }
- public Lazy<ClassroomDAL> ClassroomDAL { get; set; }
- public virtual IQueryable<ExaminationClassroomView> GetAvailableClassroomView(Expression<Func<EX_ExaminationPlan, bool>> examinationPlanExp,
- Expression<Func<EX_ExaminationRoomLayout, bool>> examinationRoomLayoutExp,
- Expression<Func<CF_Classroom, bool>> classroomExp)
- {
- var q = (from c in ClassroomRepository.GetList(classroomExp)
- join b in DictionaryItemRepository.Entities on new { c.RoomUseID, DictionaryCode = typeof(CF_RoomUse).Name }
- equals new { RoomUseID = b.Value, b.DictionaryCode } into gru
- from giru in gru.DefaultIfEmpty()
- join cid in
- (
- (from ers in ExaminationRoomSettingRepository.Entities
- join erl in ExaminationRoomLayoutRepository.GetList(examinationRoomLayoutExp) on ers.ClassroomID equals erl.ClassroomID into derl
- from eerl in derl.DefaultIfEmpty()
- join nas in
- (
- from ep in ExaminationPlanRepository.GetList(examinationPlanExp)
- join erl in ExaminationRoomLayoutRepository.Entities on true equals true
- where erl.EX_ExaminationPlan.ExaminationDate == ep.ExaminationDate
- && erl.EX_ExaminationPlan.EndTime >= ep.StartTime && erl.EX_ExaminationPlan.StartTime <= ep.EndTime
- group erl by erl.ClassroomID into g
- select new { ClassroomID = g.Key, StudentCount = (int?)g.Sum(x => x.EX_ExaminationRoomStudent.Count()) }
- ) on ers.ClassroomID equals nas.ClassroomID into dnas
- from enas in dnas.DefaultIfEmpty()
- where (enas.ClassroomID == null || ers.CF_Classroom.Examinationseating > (enas.StudentCount ?? 0)) && eerl.ExaminationRoomLayoutID == null
- select new { ers.ClassroomID, RemainSeatCount = ers.CF_Classroom.Examinationseating - (enas.StudentCount ?? 0) }
- ).Concat(
- from erl in ExaminationRoomLayoutRepository.GetList(examinationRoomLayoutExp)
- from oerl in ExaminationRoomLayoutRepository.Entities.Where(x => x.ExaminationRoomLayoutID != erl.ExaminationRoomLayoutID
- && x.ClassroomID == erl.ClassroomID && erl.EX_ExaminationPlan.ExaminationDate == x.EX_ExaminationPlan.ExaminationDate
- && x.EX_ExaminationPlan.EndTime >= erl.EX_ExaminationPlan.StartTime
- && x.EX_ExaminationPlan.StartTime <= erl.EX_ExaminationPlan.EndTime).DefaultIfEmpty()
- group oerl by new { erl.ClassroomID, erl.CF_Classroom.Examinationseating } into g
- select new { g.Key.ClassroomID, RemainSeatCount = g.Key.Examinationseating - g.Sum(x => (x.ExaminationRoomLayoutID == null) ? 0 : x.EX_ExaminationRoomStudent.Count()) }
- )
- ) on c.ClassroomID equals cid.ClassroomID
- select new ExaminationClassroomView
- {
- ClassroomID = c.ClassroomID,
- CampusID = c.CF_BuildingsInfo.CampusID,
- CollegeID = c.CollegeID,
- CollegeCode = c.CF_College.No,
- CollegeName = c.CF_College.Name,
- Code = c.Code,
- Name = c.Name,
- BuildingsInfoID = c.BuildingsInfoID,
- BuildingsInfoCode = c.CF_BuildingsInfo.Code,
- BuildingsInfoName = c.CF_BuildingsInfo.Name,
- RoomUseID = c.RoomUseID,
- FloorLevel = c.FloorLevel,
- IsAvailable = c.IsAvailable ?? false,
- IsConcurrentUse = c.IsConcurrentUse ?? false,
- Acreage = c.Acreage,
- RowCout = c.RowCout,
- ColumnCount = c.ColumnCount,
- Totalseating = c.Totalseating,
- Effectiveseating = c.Effectiveseating,
- Examinationseating = c.Examinationseating,
- RemainSeatCount = cid.RemainSeatCount,
- LayoutTypeID = c.LayoutTypeID,
- IsWrittenExam = c.IsWrittenExam ?? false,
- IsMachinetest = c.IsMachinetest ?? false,
- CreateUserID = c.CreateUserID,
- CreateTime = c.CreateTime,
- Remark = c.Remark,
- CF_ClassroomType = c.CF_ClassroomType
- });
- return q;
- }
- public IQueryable<ExaminationClassroomView> GetAvailableClassroomViewGdss(Expression<Func<EX_ExaminationPlan, bool>> otherExaminationPlanExp,
- Expression<Func<CF_Classroom, bool>> classroomExp, int? studentCount)
- {
- var q = (from c in ClassroomRepository.GetList(classroomExp)
- join b in DictionaryItemRepository.Entities on new { c.RoomUseID, DictionaryCode = typeof(CF_RoomUse).Name }
- equals new { RoomUseID = b.Value, b.DictionaryCode } into gru
- from giru in gru.DefaultIfEmpty()
- join cid in
- (from ers in ExaminationRoomSettingRepository.Entities
- join nas in
- (
- from otherPlan in ExaminationPlanRepository.Entities.Where(otherExaminationPlanExp)
- from otherLayout in otherPlan.EX_ExaminationRoomLayout
- group otherLayout by otherLayout.ClassroomID into g
- select new { ClassroomID = g.Key, StudentCount = (int?)g.Sum(x => x.EX_ExaminationRoomStudent.Count()) }
- ) on ers.ClassroomID equals nas.ClassroomID into dnas
- from enas in dnas.DefaultIfEmpty()
- where (enas.ClassroomID == null || ers.CF_Classroom.Examinationseating > (enas.StudentCount ?? 0))
- select new { ers.ClassroomID, RemainSeatCount = ers.CF_Classroom.Examinationseating - (enas.StudentCount ?? 0) }
- ) on c.ClassroomID equals cid.ClassroomID
- where (studentCount == null || cid.RemainSeatCount >= studentCount)
- select new ExaminationClassroomView
- {
- ClassroomID = c.ClassroomID,
- CampusID = c.CF_BuildingsInfo.CampusID,
- CollegeID = c.CollegeID,
- CollegeCode = c.CF_College.No,
- CollegeName = c.CF_College.Name,
- Code = c.Code,
- Name = c.Name,
- BuildingsInfoID = c.BuildingsInfoID,
- BuildingsInfoCode = c.CF_BuildingsInfo.Code,
- BuildingsInfoName = c.CF_BuildingsInfo.Name,
- RoomUseID = c.RoomUseID,
- FloorLevel = c.FloorLevel,
- IsAvailable = c.IsAvailable ?? false,
- IsConcurrentUse = c.IsConcurrentUse ?? false,
- Acreage = c.Acreage,
- RowCout = c.RowCout,
- ColumnCount = c.ColumnCount,
- Totalseating = c.Totalseating,
- Effectiveseating = c.Effectiveseating,
- Examinationseating = c.Examinationseating,
- RemainSeatCount = cid.RemainSeatCount,
- LayoutTypeID = c.LayoutTypeID,
- IsWrittenExam = c.IsWrittenExam ?? false,
- IsMachinetest = c.IsMachinetest ?? false,
- CreateUserID = c.CreateUserID,
- CreateTime = c.CreateTime,
- Remark = c.Remark,
- CF_ClassroomType = c.CF_ClassroomType
- });
- return q;
- }
- public IQueryable<ClassroomConflictView> GetConflictClassroomView(Expression<Func<EX_ExaminationPlan, bool>> examinationPlanExp,
- DateTime? date, TimeSpan? startTime, TimeSpan? endTime)
- {
- var q = (
- from ep in ExaminationPlanRepository.GetList(examinationPlanExp)
- from erl in ep.EX_ExaminationRoomLayout
- join erlt in
- (
- from erlt1 in ExaminationRoomLayoutRepository.Entities
- select new
- {
- ClassroomID = erlt1.ClassroomID,
- ExaminationPlanID = erlt1.EX_ExaminationPlan.ExaminationPlanID,
- ExaminationPlanName = erlt1.EX_ExaminationPlan.ClassName,
- erlt1.EX_ExaminationPlan.ExaminationDate,
- erlt1.EX_ExaminationPlan.StartTime,
- erlt1.EX_ExaminationPlan.EndTime
- }
- ) on erl.ClassroomID equals erlt.ClassroomID
- where ep.ExaminationPlanID != erlt.ExaminationPlanID && erlt.ExaminationDate == date
- && erlt.EndTime >= startTime && erlt.StartTime <= endTime
- select new ClassroomConflictView
- {
- ClassroomID = erl.CF_Classroom.ClassroomID,
- Name = erl.CF_Classroom.Name,
- ExaminationPlanID = erlt.ExaminationPlanID,
- ExaminationPlanName = erlt.ExaminationPlanName,
- StartTime = erlt.StartTime,
- EndTime = erlt.EndTime
- }
- );
- return q;
- }
- }
- }
|