using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.CommonLogic.SystemServices; using EMIS.Entities; using EMIS.DataLogic.ScoreManage; using EMIS.ViewModel; using EMIS.CommonLogic.CalendarManage; using EMIS.Utility.FormValidate; namespace EMIS.CommonLogic.ScoreManage { public class ExaminationExemptionServices : BaseWorkflowServices, IExaminationExemptionServices { public ExaminationExemptionDAL ExaminationExemptionDAL { get; set; } public FinalExaminationDAL FinalExaminationDAL { get; set; } public Lazy ScoreServices { get; set; } public Bowin.Common.Linq.Entity.IGridResultSet GetExaminationExemptionGridView( ViewModel.ConfiguretView conditions, Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, int? examsCatagoryID, int? recordStatus,int? learningformID, int? education,string LearnSystem, int? pageIndex = null, int? pageSize = null) { var statusList = this.GetStatusViewList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var startStatus = this.GetStartStatus(); var userID = CustomPrincipal.Current.UserID; exp = exp.And(x => x.RecordStatus != startStatus || (x.RecordStatus == startStatus && x.CreateUserID == userID)); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (year.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year); } if (standardID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (classmajorID.HasValue) { exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID); } if (examsCatagoryID.HasValue) { exp = exp.And(x => x.ExamsCategoryID == examsCatagoryID); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } if (learningformID.HasValue) exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID); if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } query = this.GetQueryByDataRangeByCollege(query); var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => { var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus); if (currentStatus != null) { x.RecordStatusName = currentStatus.Name; } else { x.RecordStatusName = ""; } }); return result; } public Bowin.Common.Linq.Entity.IGridResultSet GetExaminationExemptionStudentGridView( ViewModel.ConfiguretView conditions, Guid? userID = null, int? pageIndex = null, int? pageSize = null) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var statusList = this.GetStatusViewList(); if (userID.HasValue) { exp = exp.And(x => x.UserID == userID); } var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => { var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus); if (currentStatus != null) { x.RecordStatusName = currentStatus.Name; } else { x.RecordStatusName = ""; } }); return result; } public List GetExaminationExemptionViewList(ViewModel.ConfiguretView conditions, Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, int? examsCatagoryID, int? recordStatus,int? learningformID, int? education,string LearnSystem) { var statusList = this.GetStatusViewList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var startStatus = this.GetStartStatus(); exp = exp.And(x => x.RecordStatus != startStatus); if (schoolyearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolyearID); } if (collegeID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (year.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year); } if (standardID.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (classmajorID.HasValue) { exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID); } if (examsCatagoryID.HasValue) { exp = exp.And(x => x.ExamsCategoryID == examsCatagoryID); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } if (learningformID.HasValue) exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID); if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1") { var LearnSystems = Convert.ToDecimal(LearnSystem); exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems); } if (education.HasValue) { exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value); } var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } query = this.GetQueryByDataRangeByCollege(query); var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList(); result.ForEach(x => { var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus); if (currentStatus != null) { x.RecordStatusName = currentStatus.Name; } else { x.RecordStatusName = ""; } }); return result; } public List GetExaminationExemptionViewStudentList(ViewModel.ConfiguretView conditions, Guid? userID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var statusList = this.GetStatusViewList(); if (userID.HasValue) { exp = exp.And(x => x.UserID == userID); } var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList(); result.ForEach(x => { var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus); if (currentStatus != null) { x.RecordStatusName = currentStatus.Name; } else { x.RecordStatusName = ""; } }); return result; } public EMIS.ViewModel.ScoreManage.ExaminationExemptionView GetExaminationExemptionView(Guid examinationExemptionID) { var statusList = this.GetStatusViewList(); var examinationExemptionView = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(x => x.ExaminationExemptionID == examinationExemptionID) .FirstOrDefault(); if (examinationExemptionView != null) { var recordStatus = statusList.FirstOrDefault(x => x.ID == examinationExemptionView.RecordStatus); if (recordStatus != null) { examinationExemptionView.RecordStatusName = recordStatus.Name; } } return examinationExemptionView; } public void Save(ViewModel.ScoreManage.ExaminationExemptionView examinationExemptionView) { var dupExemption = this.ExaminationExemptionDAL.ExaminationExemptionRepository .GetSingle(x => x.UserID == examinationExemptionView.UserID && x.SchoolyearID == examinationExemptionView.SchoolyearID && x.CoursematerialID == examinationExemptionView.CoursematerialID && x.ExamsCategoryID == examinationExemptionView.ExamsCategoryID); ER_ExaminationExemption examinationExemption = this.ExaminationExemptionDAL.ExaminationExemptionRepository .GetSingle(x => x.ExaminationExemptionID == examinationExemptionView.ExaminationExemptionID); if (examinationExemption == null) { if (dupExemption != null) { throw new Exception("该科目在这个学期已经申请过免考,请勿重复申请。"); } examinationExemption = new ER_ExaminationExemption(); examinationExemption.ExaminationExemptionID = Guid.NewGuid(); this.SetNewStatus(examinationExemption); examinationExemption.RecordStatus = this.GetStartStatus(); this.UnitOfWork.Add(examinationExemption); } else { if (dupExemption != null && dupExemption.ExaminationExemptionID != examinationExemption.ExaminationExemptionID) { throw new Exception("该科目在这个学期已经申请过免考,请勿重复申请。"); } this.SetModifyStatus(examinationExemption); } examinationExemption.UserID = examinationExemptionView.UserID; examinationExemption.SchoolyearID = examinationExemptionView.SchoolyearID; examinationExemption.CoursematerialID = examinationExemptionView.CoursematerialID; examinationExemption.ExamsCategoryID = examinationExemptionView.ExamsCategoryID; examinationExemption.Reason = examinationExemptionView.Reason; this.UnitOfWork.Commit(); } public void Delete(IList examinationExemptionIDList) { this.UnitOfWork.Remove(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID)); this.UnitOfWork.Commit(); } public IGridResultSet GetExaminationExemptionCoursematerialGridView( ConfiguretView conditions, int? pageIndex = null, int? pageSize = null) { var userID = CustomPrincipal.Current.UserID; Expression> schoolyearExp = (x => x.IsCurrent == true); Expression> studentExp = (x => x.UserID == userID); var query = this.ExaminationExemptionDAL.GetExaminationExemptionCoursematerialViewQueryable(schoolyearExp, studentExp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } var result = query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseName).ToGridResultSet(pageIndex, pageSize); return result; } public IGridResultSet GetExaminationExemptionCoursematerialGridViewForTeacher( ConfiguretView conditions,Guid? UserID, int? pageIndex = null, int? pageSize = null) { Expression> schoolyearExp = (x => x.IsCurrent == true); Expression> studentExp = (x => true); if (UserID.HasValue) { studentExp = (x => x.UserID == UserID); } var query = this.ExaminationExemptionDAL.GetExaminationExemptionCoursematerialViewQueryable(schoolyearExp, studentExp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } var result = query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseName).ToGridResultSet(pageIndex, pageSize); return result; } public void OnApproveEnd(List examinationExemptionIDList, Guid? userID) { ScoreServices.Value.RefreshExaminationExemptionState(examinationExemptionIDList); } public void OnRollback(List examinationExemptionIDList, Guid? userID) { ScoreServices.Value.RefreshCancelExaminationExemptionState(examinationExemptionIDList); } public List GetExaminationExemptionViewListByFinalExamination(Guid? finalExaminationID) { var endStatus = this.GetCorrectEndStatus(); var finalExaminationView = FinalExaminationDAL.GetFinalExaminationViewQueryable(x => x.FinalExaminationID == finalExaminationID).FirstOrDefault(); if (finalExaminationView == null) { return new List(); } Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.SchoolyearID == finalExaminationView.SchoolyearID && x.CoursematerialID == finalExaminationView.CoursematerialID && x.ExamsCategoryID == finalExaminationView.ExamsCategoryID && x.RecordStatus == 3); var statusList = this.GetStatusViewList(); var query = this.ExaminationExemptionDAL.GetExaminationExemptionViewQueryable(exp); var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList(); result.ForEach(x => { var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus); if (currentStatus != null) { x.RecordStatusName = currentStatus.Name; } else { x.RecordStatusName = ""; } }); return result; } public void Cancel(List examinationExemptionIDList, Guid userID, string comment) { var endStatusID = GetEndStatusID(); var examinationExemptionList = ExaminationExemptionDAL.ExaminationExemptionRepository .GetList(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID)).ToList(); if (examinationExemptionList.Any(x => x.RecordStatus != endStatusID)) { throw new Exception("只能撤回已通过状态的记录。"); } var actionViewList = this.GetActionView(examinationExemptionIDList[0], userID); var actionView = actionViewList.FirstOrDefault(); this.Approve(examinationExemptionIDList, userID, actionView.ActionID, comment); } public int? GetEndStatusID() { var endStatus = this.GetStatusViewList().FirstOrDefault(x => x.Description.Contains("[End]")); if (endStatus != null) { return endStatus.ID; } else { return null; } } } }