using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using EMIS.Entities;
using Bowin.Common.Linq;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel;
using EMIS.DataLogic.EducationManage;
using EMIS.DataLogic.EducationSchedule;
using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
using EMIS.ViewModel.EducationManagement;
using Bowin.Common.Utility;
using EMIS.Utility;
using Bowin.Common.DataTime;
using EMIS.DataLogic.Repositories;
using EMIS.ViewModel.CacheManage;
using EMIS.ViewModel.SchedulingManage.SchedulingSettings;
using EMIS.DataLogic;
using EMIS.ViewModel.EducationManage;
using System.Data.Entity;
namespace EMIS.CommonLogic.EducationSchedule
{
public class RealtimeServices : BaseServices, IRealtimeServices
{
public RealtimeDAL RealtimeDAL { get; set; }
public EducationMissionClassDAL educationMissionClassDAL { get; set; }
///
/// 列表信息查询
///
///
///
///
///
///
///
///
///
///
///
public IGridResultSet GetEducationMissionClassScheduleViewGrid(ConfiguretView configuretView,
Guid? collegeID, Guid? openCollegeID, Guid? schoolyearID, int? WeekNum, int? WeekDay, Guid? Times, Guid? ClassroomID, int pageIndex, int pageSize)
{
Expression> exp = (x => true);
Expression> exeducationScheduling = (x => true);
Expression> exducationSchedulingWeekNum = (x => true);
Expression> exexcessiveUse = (x => true);
Expression> exexcessiveUseScheduling = (x => true);
Expression> exexcessiveUseSchedulingWeekNum = (x => true);
Expression> exeClassroom = (x => true);
Expression> exeCoursesTime = (x => true);
if (openCollegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CF_Department.CollegeID == openCollegeID);
exexcessiveUse = exexcessiveUse.And(x => x.CollegeID == openCollegeID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
}
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
exexcessiveUse = exexcessiveUse.And(x => x.SchoolyearID == schoolyearID);
}
if (WeekNum.HasValue)
{
exducationSchedulingWeekNum = exducationSchedulingWeekNum.And(x => x.WeekNum == WeekNum);
exexcessiveUseSchedulingWeekNum = exexcessiveUseSchedulingWeekNum.And(x => x.WeekNum == WeekNum);
}
if (WeekDay.HasValue)
{
exeducationScheduling = exeducationScheduling.And(x => x.Weekday == WeekDay);
exexcessiveUseScheduling = exexcessiveUseScheduling.And(x => x.Weekday == WeekDay);
}
if (Times.HasValue)
{
exeducationScheduling = exeducationScheduling.And(x => x.CoursesTimeID == Times);
exexcessiveUseScheduling = exexcessiveUseScheduling.And(x => x.CoursesTimeID == Times);
}
if (ClassroomID.HasValue)
{
exeducationScheduling = exeducationScheduling.And(x => x.ClassroomID == ClassroomID);
exexcessiveUse = exexcessiveUse.And(x => x.ClassroomID == ClassroomID);
}
var query = RealtimeDAL.GetEducationMissionClassViewQueryble(exp, exeducationScheduling, exducationSchedulingWeekNum,
exexcessiveUse, exexcessiveUseScheduling, exexcessiveUseSchedulingWeekNum);
//if (openCollegeID.HasValue)
//{
// query = query.Where(x => x.OpenCollegeID == openCollegeID || x.OpenCollegeID == null);
//}
//if (collegeID.HasValue)
//{
// query = query.Where(x => x.CollegeID == collegeID || x.CollegeID == null);
//}
//if (schoolyearID.HasValue)
//{
// query = query.Where(x => x.SchoolyearID == schoolyearID || x.SchoolyearID == null);
//}
//if (WeekNum.HasValue)
//{
// query = query.Where(x => x.WeekNum == WeekNum);
//}
//if (WeekDay.HasValue)
//{
// query = query.Where(x => x.Weekday == WeekDay);
//}
//if (Times.HasValue)
//{
// query = query.Where(x => x.newCoursesTimeID == Times);
//}
//if (ClassroomID.HasValue)
//{
// query = query.Where(x => x.ClassroomID == ClassroomID);
//}
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
var resultQuery = query.OrderBy(x => x.ClassroomName)
.ThenBy(x => x.WeekNum).ThenBy(x => x.Weekday).ThenBy(x => x.StarTimes);
var result = resultQuery.ToGridResultSet(pageIndex, pageSize);
var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList();
var missionClassTeacherList = educationMissionClassDAL.GetEducationSchedulingTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID && y.WeekNum == x.WeekNum && y.Weekday == x.Weekday && y.StarTimes == x.StarTimes)));
return result;
}
public IGridResultSet GetEducationMissionClassScheduleViewGridGT(ConfiguretView configuretView,
Guid? collegeID, Guid? openCollegeID, Guid? schoolyearID, int? WeekNum, int? WeekDay, Guid? Times, Guid? ClassroomID, int pageIndex, int pageSize)
{
Expression> exp = (x => true);
Expression> exeducationScheduling = (x => true);
Expression> exducationSchedulingWeekNum = (x => true);
Expression> exexcessiveUse = (x => true);
Expression> exexcessiveUseScheduling = (x => true);
Expression> exexcessiveUseSchedulingWeekNum = (x => true);
Expression> exeClassroom = (x => true);
Expression> exeCoursesTime = (x => true);
if (openCollegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CF_Department.CollegeID == openCollegeID);
exexcessiveUse = exexcessiveUse.And(x => x.CollegeID == openCollegeID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
}
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
exexcessiveUse = exexcessiveUse.And(x => x.SchoolyearID == schoolyearID);
}
//if (WeekNum.HasValue)
//{
// exducationSchedulingWeekNum = exducationSchedulingWeekNum.And(x => x.WeekNum == WeekNum);
// exexcessiveUseSchedulingWeekNum = exexcessiveUseSchedulingWeekNum.And(x => x.WeekNum == WeekNum);
//}
//if(WeekDay.HasValue)
//{
// exeducationScheduling = exeducationScheduling.And(x => x.Weekday == WeekDay);
// exexcessiveUseScheduling = exexcessiveUseScheduling.And(x => x.Weekday == WeekDay);
//}
//if(Times.HasValue)
//{
// exeducationScheduling = exeducationScheduling.And(x => x.CoursesTimeID == Times);
// exexcessiveUseScheduling = exexcessiveUseScheduling.And(x => x.CoursesTimeID == Times);
//}
//if (ClassroomID.HasValue)
//{
// exeducationScheduling = exeducationScheduling.And(x => x.ClassroomID == ClassroomID);
// exexcessiveUse = exexcessiveUse.And(x => x.ClassroomID == ClassroomID);
//}
var query = RealtimeDAL.GetNewEducationMissionClassViewQueryble(exp, exeducationScheduling, exducationSchedulingWeekNum,
exexcessiveUse, exexcessiveUseScheduling, exexcessiveUseSchedulingWeekNum, exeClassroom, exeCoursesTime);
//if (openCollegeID.HasValue)
//{
// query = query.Where(x => x.OpenCollegeID == openCollegeID || x.OpenCollegeID == null);
//}
//if (collegeID.HasValue)
//{
// query = query.Where(x => x.CollegeID == collegeID || x.CollegeID == null);
//}
//if (schoolyearID.HasValue)
//{
// query = query.Where(x => x.SchoolyearID == schoolyearID || x.SchoolyearID == null);
//}
if (WeekNum.HasValue)
{
query = query.Where(x => x.WeekNum == WeekNum);
}
if (WeekDay.HasValue)
{
query = query.Where(x => x.Weekday == WeekDay);
}
if (Times.HasValue)
{
query = query.Where(x => x.newCoursesTimeID == Times);
}
if (ClassroomID.HasValue)
{
query = query.Where(x => x.ClassroomID == ClassroomID);
}
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
var resultQuery = query.OrderBy(x => x.ClassroomName)
.ThenBy(x => x.WeekNum).ThenBy(x => x.Weekday).ThenBy(x => x.StarTimes);
var result = resultQuery.ToGridResultSet(pageIndex, pageSize);
var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList();
var missionClassTeacherList = educationMissionClassDAL.GetEducationSchedulingTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID && y.WeekNum == x.WeekNum && y.Weekday == x.Weekday && y.StarTimes == x.StarTimes)));
return result;
}
///
/// 查询对应的实时课表信息List
///
///
///
///
///
///
///
///
///
public List GetEducationMissionClassScheduleViewGridForExcel(ConfiguretView configuretView,
Guid? collegeID, Guid? openCollegeID, Guid? schoolyearID, int? WeekNum, int? WeekDay, Guid? Times, Guid? ClassroomID)
{
Expression> exp = (x => true);
Expression> exeducationScheduling = (x => true);
Expression> exducationSchedulingWeekNum = (x => true);
Expression> exexcessiveUse = (x => true);
Expression> exexcessiveUseScheduling = (x => true);
Expression> exexcessiveUseSchedulingWeekNum = (x => true);
Expression> exeClassroom = (x => true);
Expression> exeCoursesTime = (x => true);
if (openCollegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CF_Department.CollegeID == openCollegeID);
exexcessiveUse = exexcessiveUse.And(x => x.CollegeID == openCollegeID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
}
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
exexcessiveUse = exexcessiveUse.And(x => x.SchoolyearID == schoolyearID);
}
if (WeekNum.HasValue)
{
exducationSchedulingWeekNum = exducationSchedulingWeekNum.And(x => x.WeekNum == WeekNum);
exexcessiveUseSchedulingWeekNum = exexcessiveUseSchedulingWeekNum.And(x => x.WeekNum == WeekNum);
}
if (WeekDay.HasValue)
{
exeducationScheduling = exeducationScheduling.And(x => x.Weekday == WeekDay);
exexcessiveUseScheduling = exexcessiveUseScheduling.And(x => x.Weekday == WeekDay);
}
if (Times.HasValue)
{
exeducationScheduling = exeducationScheduling.And(x => x.CoursesTimeID == Times);
exexcessiveUseScheduling = exexcessiveUseScheduling.And(x => x.CoursesTimeID == Times);
exeCoursesTime = exeCoursesTime.And(x => x.CoursesTimeID == Times);
}
if (ClassroomID.HasValue)
{
exeducationScheduling = exeducationScheduling.And(x => x.ClassroomID == ClassroomID);
exexcessiveUse = exexcessiveUse.And(x => x.ClassroomID == ClassroomID);
exeClassroom = exeClassroom.And(x => x.ClassroomID == ClassroomID);
}
var query =
//RealtimeDAL.GetNewEducationMissionClassViewQueryble(exp, exeducationScheduling, exducationSchedulingWeekNum,
//exexcessiveUse, exexcessiveUseScheduling, exexcessiveUseSchedulingWeekNum, exeClassroom, exeCoursesTime);
RealtimeDAL.GetEducationMissionClassViewQueryble(exp, exeducationScheduling, exducationSchedulingWeekNum,
exexcessiveUse, exexcessiveUseScheduling, exexcessiveUseSchedulingWeekNum);
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
var resultQuery = query.OrderBy(x => x.ClassroomName)
.ThenBy(x => x.WeekNum).ThenBy(x => x.Weekday).ThenBy(x => x.Times).ThenBy(x => x.TimesHoure);
var result = resultQuery.ToList();
var educationMissionClassID = result.Select(x => x.EducationMissionClassID).ToList();
var missionClassTeacherList = educationMissionClassDAL.GetEducationSchedulingTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
result.ForEach(x => x.MissionClassTeacherView = new HashSet(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID && y.WeekNum == x.WeekNum && y.Weekday == x.Weekday && y.StarTimes == x.StarTimes)));
return result.ToList();
}
}
}