using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.DataLogic.Repositories;
using EMIS.ViewModel.RetakeManage;
using System.Linq.Expressions;
using EMIS.Entities;
using EMIS.ViewModel;
namespace EMIS.DataLogic.RetakeManage
{
public class RetakeConditionDAL
{
public RetakeConditionRepository RetakConditionRepository { get; set; }
public RetakeConditionParameterRepository RetakeConditionParameterRepository { get; set; }
public StudentRepository StudentRepository { get; set; }
public InSchoolSettingRepository InSchoolSettingRepository { get; set; }
public ParameterRepository ParameterRepository { get; set; }
public RetakePlanStudentRepository RetakePlanStudentRepository { get; set; }
public RetakeExamsCatagoryRepository RetakeExamsCatagoryRepository { get; set; }
public CoursematerialRepository CoursematerialRepository { get; set; }
public FinallyScoreRepository FinallyScoreRepository { get; set; }
///
/// 查询重修条件限定信息View
///
///
///
public IQueryable GetRetakeConditionView(Expression> exp)
{
var q = (from condition in RetakConditionRepository.GetList(exp)
select new RetakeConditionView
{
RetakeConditionID = condition.RetakeConditionID,
RetakeConditionTypeID = condition.RetakeConditionTypeID,
Title = condition.Title,
MethodFullName = condition.MethodFullName,
RecordStatus = condition.RecordStatus
});
return q;
}
///
/// 查询对应的重修条件参数
///
///
///
private string GetParameterValue(ER_RetakeParameterType parameterType)
{
return RetakeConditionParameterRepository.GetList(x => x.RetakeParameterTypeID == (int)parameterType
&& x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
.Select(x => x.Value).FirstOrDefault();
}
///
/// 重修条件限定查询(大于等于最小不及格门数且小于等于最大不及格门数)
///
///
///
public IQueryable NoPassCondition(IQueryable sourceView)
{
var minNoPassCount = Convert.ToInt32(GetParameterValue(ER_RetakeParameterType.MinNoPassCount) ?? "1");
var maxNoPassCount = Convert.ToInt32(GetParameterValue(ER_RetakeParameterType.MaxNoPassCount) ?? "100");
var query = (from retake in sourceView
group retake by retake.UserID
into g
where g.Count() >= minNoPassCount && g.Count() <= maxNoPassCount
select g).SelectMany(x => x.Select(w => w));
return query;
}
public IQueryable GetRetakeStudentView()
{
var schoolyearIDStr = ParameterRepository.GetList(x => x.ParameterTypeID == (int)CF_ParameterType.RetakeSchoolyearID)
.Select(x => x.Value).FirstOrDefault();
Guid? schoolyearID = null;
if (schoolyearIDStr != null)
{
schoolyearID = new Guid(schoolyearIDStr);
}
else
{
throw new Exception("未设置重修学年学期,请设置。");
}
var query = (from score in FinallyScoreRepository.GetList(x => x.TotalScore < 60 && x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
join type in RetakeExamsCatagoryRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
on score.ExamsCategoryID equals type.ExamsCategoryID
join student in StudentRepository.Entities
on score.UserID equals student.UserID
join inschool in InSchoolSettingRepository.GetList(x => x.IsSelected == true)
on student.InSchoolStatusID equals inschool.InSchoolStatusID
join course in CoursematerialRepository.Entities
on score.CoursematerialID equals course.CoursematerialID
join retake in RetakePlanStudentRepository.GetList(x => x.ER_RetakePlan.SchoolyearID == schoolyearID)
on
new { score.CoursematerialID, score.CourseTypeID, score.Credit, score.UserID }
equals
new { retake.ER_RetakePlan.CoursematerialID, retake.ER_RetakePlan.CourseTypeID, retake.ER_RetakePlan.Credit, UserID = (Guid?)retake.UserID }
into dretake
from eretake in dretake.DefaultIfEmpty()
where eretake.RetakePlanStudentID == null
select new RetakeStudentView
{
CoursematerialID = score.CoursematerialID,
Abbreviation = course.Abbreviation,
CourseCode = course.CourseCode,
CourseName = course.CourseName,
CourseTypeID = score.CourseTypeID,
UserID = score.UserID,
Credit = score.Credit,
SchoolyearNumID = score.SchoolyearNumID,
StarttermID = score.StarttermID
});
return query;
}
}
}