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 ExaminationSuspensionServices : BaseWorkflowServices, IExaminationSuspensionServices { public ExaminationSuspensionDAL ExaminationSuspensionDAL { get; set; } public FinalExaminationDAL FinalExaminationDAL { get; set; } public Lazy ScoreServices { get; set; } public Bowin.Common.Linq.Entity.IGridResultSet GetExaminationSuspensionGridView( 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.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(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 GetExaminationSuspensionStudentGridView( 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.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(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 GetExaminationSuspensionViewList(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.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(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 GetExaminationSuspensionViewStudentList(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.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(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.ExaminationSuspensionView GetExaminationSuspensionView(Guid examinationSuspensionID) { var statusList = this.GetStatusViewList(); var examinationSuspensionView = this.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(x => x.ExaminationSuspensionID == examinationSuspensionID) .FirstOrDefault(); if (examinationSuspensionView != null) { var recordStatus = statusList.FirstOrDefault(x => x.ID == examinationSuspensionView.RecordStatus); if (recordStatus != null) { examinationSuspensionView.RecordStatusName = recordStatus.Name; } } return examinationSuspensionView; } public void Save(ViewModel.ScoreManage.ExaminationSuspensionView examinationSuspensionView) { int? endStatus = this.GetCorrectEndStatus(); var dupSuspension = this.ExaminationSuspensionDAL.ExaminationSuspensionRepository .GetSingle(x => x.UserID == examinationSuspensionView.UserID && x.SchoolyearID == examinationSuspensionView.SchoolyearID && x.CoursematerialID == examinationSuspensionView.CoursematerialID && x.ExamsCategoryID == examinationSuspensionView.ExamsCategoryID && x.RecordStatus != endStatus); ER_ExaminationSuspension examinationSuspension = this.ExaminationSuspensionDAL.ExaminationSuspensionRepository .GetSingle(x => x.ExaminationSuspensionID == examinationSuspensionView.ExaminationSuspensionID); if (examinationSuspension == null) { if (dupSuspension != null) { throw new Exception("该科目在这个学期已经申请过缓考,请勿重复申请。"); } examinationSuspension = new ER_ExaminationSuspension(); examinationSuspension.ExaminationSuspensionID = Guid.NewGuid(); this.SetNewStatus(examinationSuspension); examinationSuspension.RecordStatus = this.GetStartStatus(); this.UnitOfWork.Add(examinationSuspension); } else { if (dupSuspension != null && dupSuspension.ExaminationSuspensionID != examinationSuspension.ExaminationSuspensionID && dupSuspension.RecordStatus != endStatus) { throw new Exception("该科目在这个学期已经申请过缓考,请勿重复申请。"); } this.SetModifyStatus(examinationSuspension); } examinationSuspension.UserID = examinationSuspensionView.UserID; examinationSuspension.SchoolyearID = examinationSuspensionView.SchoolyearID; examinationSuspension.CoursematerialID = examinationSuspensionView.CoursematerialID; examinationSuspension.ExamsCategoryID = examinationSuspensionView.ExamsCategoryID; examinationSuspension.Reason = examinationSuspensionView.Reason; this.UnitOfWork.Commit(); } public void Delete(IList examinationSuspensionIDList) { this.UnitOfWork.Remove(x => examinationSuspensionIDList.Contains(x.ExaminationSuspensionID)); this.UnitOfWork.Commit(); } public IGridResultSet GetExaminationSuspensionCoursematerialGridView( 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.ExaminationSuspensionDAL.GetExaminationSuspensionCoursematerialViewQueryable(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 GetExaminationSuspensionCoursematerialGridViewForTeacher( 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.ExaminationSuspensionDAL.GetExaminationSuspensionCoursematerialViewQueryable(schoolyearExp, studentExp); if (!string.IsNullOrEmpty(conditions.ConditionValue)) { query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); } query = query.Distinct(); 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 examinationSuspensionIDList, Guid? userID) { ScoreServices.Value.RefreshExaminationSuspensionState(examinationSuspensionIDList); } public void OnApproveEnds(List examinationSuspensionIDList, Guid? userID) { ScoreServices.Value.RefreshCancelExaminationSuspensionState(examinationSuspensionIDList); } public List GetExaminationSuspensionViewListByFinalExamination(Guid? finalExaminationID) { var endStatus = this.GetStatusViewList().FirstOrDefault(x => x.Description == "[End]"); int? endStatusID = null; if (endStatus != null) { endStatusID = endStatus.ID; } 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 == endStatusID); var statusList = this.GetStatusViewList(); var query = this.ExaminationSuspensionDAL.GetExaminationSuspensionViewQueryable(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 examinationSuspensionIDList, Guid userID, string comment) { var endStatusID = GetEndStatusID(); var examinationSuspensionList = ExaminationSuspensionDAL.ExaminationSuspensionRepository .GetList(x => examinationSuspensionIDList.Contains(x.ExaminationSuspensionID)).ToList(); if (examinationSuspensionList.Any(x => x.RecordStatus != endStatusID)) { throw new Exception("只能撤回已通过状态的记录。"); } var actionViewList = this.GetActionView(examinationSuspensionIDList[0], userID); var actionView = actionViewList.FirstOrDefault(); this.Approve(examinationSuspensionIDList, 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; } } } }