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.Entities; using EMIS.ViewModel; using EMIS.DataLogic.ExaminationApply; using EMIS.ViewModel.ExaminationApply; using Bowin.Common.Utility; using System.Text.RegularExpressions; namespace EMIS.CommonLogic.ExaminationApply { public class ExaminationSubjectServices : BaseServices, IExaminationSubjectServices { public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; } public Bowin.Common.Linq.Entity.IGridResultSet GetExaminationSubjectViewList(ViewModel.ConfiguretView examinationSubjectView, Guid? examinationTypeID, Guid? examinationSubjectID, Guid? schoolYearID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (examinationTypeID.HasValue) { exp = exp.And(x => x.ExaminationTypeID == examinationTypeID); } //要排除的科目,考试科目的要求通过科目下拉,一般排除当前科目,如英语四级选择要求通过科目时,不能选择英语四级 if (examinationSubjectID.HasValue) { exp = exp.And(x => x.ExaminationSubjectID != examinationSubjectID); } if (schoolYearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolYearID); } var q = ExaminationSubjectDAL.GetExaminationSubjectView(exp); if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute)) q = q.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue); return q.OrderBy(x => x.Name).ToGridResultSet(pageIndex, pageSize); } public IList GetExaminationSubjectViewList(ViewModel.ConfiguretView examinationSubjectView, Guid? examinationTypeID, Guid? examinationSubjectID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (examinationTypeID.HasValue) { exp = exp.And(x => x.ExaminationTypeID == examinationTypeID); } //要排除的科目,考试科目的要求通过科目下拉,一般排除当前科目,如英语四级选择要求通过科目时,不能选择英语四级 if (examinationSubjectID.HasValue) { exp = exp.And(x => x.ExaminationSubjectID != examinationSubjectID); } var q = ExaminationSubjectDAL.GetExaminationSubjectView(exp); if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute)) q = q.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue); return q.OrderBy(x => x.Name).ToList(); } public ViewModel.ExaminationApply.ExaminationSubjectView GetExaminationSubjectViewInfo(Guid? examinationSubjectID) { return ExaminationSubjectDAL.GetExaminationSubjectView(x => x.ExaminationSubjectID == examinationSubjectID).FirstOrDefault(); } public void Save(ViewModel.ExaminationApply.ExaminationSubjectView examinationSubjectView) { if (examinationSubjectView.PreposeSubjectName == examinationSubjectView.Name) throw new Exception("考试科目和要求通过科目不能相同,请核查"); if (examinationSubjectView.PreposeSubjectID!=null && examinationSubjectView.PreposeScoreLimit==null) throw new Exception("要求通过最低成绩不能为空,请核查"); var examinationSubjectEntity = ExaminationSubjectDAL.ExaminationSubjectRepository.GetSingle(x => x.ExaminationSubjectID == examinationSubjectView.ExaminationSubjectID); //考试科目名字唯一 var RepeatSubject= ExaminationSubjectDAL.ExaminationSubjectRepository.GetSingle(x => //x.ExaminationTypeID == examinationSubjectView.ExaminationTypeID && //x.ExaminationFormID == examinationSubjectView.ExaminationFormID && //x.SchoolyearID == examinationSubjectView.SchoolyearID && x.Name == examinationSubjectView.Name); if (examinationSubjectEntity != null) { if (RepeatSubject != null && examinationSubjectEntity.ExaminationSubjectID != RepeatSubject.ExaminationSubjectID) { //考试科目,判断考试类型、考试类别、学年学期、考试科目名称不能重复 throw new Exception("已存在【" + RepeatSubject.Name + "】考试科目,请核查"); } examinationSubjectEntity.ExaminationTypeID = examinationSubjectView.ExaminationTypeID; examinationSubjectEntity.SchoolyearID = examinationSubjectView.SchoolyearID; examinationSubjectEntity.ExaminationFormID = examinationSubjectView.ExaminationFormID; examinationSubjectEntity.Name = examinationSubjectView.Name; examinationSubjectEntity.PreposeSubjectID = examinationSubjectView.PreposeSubjectID; examinationSubjectEntity.PreposeScoreLimit = examinationSubjectView.PreposeScoreLimit; examinationSubjectEntity.ExaminationDate = examinationSubjectView.ExaminationDate; examinationSubjectEntity.PeopleNumLimit = examinationSubjectView.PeopleNumLimit; examinationSubjectEntity.Cost = examinationSubjectView.Cost; examinationSubjectEntity.Remark = examinationSubjectView.Remark; this.SetModifyStatus(examinationSubjectEntity); } else { if (RepeatSubject != null) { //考试科目,判断考试类型、考试类别、学年学期、名称不能重复 throw new Exception("已存在【" + RepeatSubject.Name + "】考试科目,请核查"); } examinationSubjectEntity = new EX_ExaminationSubject(); examinationSubjectEntity.ExaminationSubjectID = Guid.NewGuid(); examinationSubjectEntity.ExaminationTypeID = examinationSubjectView.ExaminationTypeID; examinationSubjectEntity.SchoolyearID = examinationSubjectView.SchoolyearID; examinationSubjectEntity.ExaminationFormID = examinationSubjectView.ExaminationFormID; examinationSubjectEntity.Name = examinationSubjectView.Name; examinationSubjectEntity.PreposeSubjectID = examinationSubjectView.PreposeSubjectID; examinationSubjectEntity.PreposeScoreLimit = examinationSubjectView.PreposeScoreLimit; examinationSubjectEntity.ExaminationDate = examinationSubjectView.ExaminationDate; examinationSubjectEntity.PeopleNumLimit = examinationSubjectView.PeopleNumLimit; examinationSubjectEntity.Cost = examinationSubjectView.Cost; examinationSubjectEntity.Remark = examinationSubjectView.Remark; this.SetNewStatus(examinationSubjectEntity); UnitOfWork.Add(examinationSubjectEntity); } UnitOfWork.Commit(); } public void Delete(IList examinationSubjectID) { if (examinationSubjectID.Count > 0) { UnitOfWork.Delete(x => examinationSubjectID.Contains(x.ExaminationSubjectID)); } } public IList GetExaminationSubjectStudentListView(ConfiguretView conditions, Guid? subjectID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, Guid? examinationTypeID, Guid? schoolYearID,bool? IsPay) { Expression> exr = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //if (schoolYearID.HasValue) //{ // exr = exr.And(x => x.SchoolyearID == schoolYearID); //} //ExaminationSchoolyearID应该才是考试学年学期 if (schoolYearID.HasValue) { exr = exr.And(x => x.ExaminationSchoolyearID == schoolYearID); } if (examinationTypeID.HasValue) { exp = exp.And(x => x.ExaminationTypeID == examinationTypeID); } if (subjectID.HasValue) { exp = exp.And(x => x.ExaminationSubjectID == subjectID.Value); } if (collegeID.HasValue) { expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (year.HasValue) { expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.GradeID == year); } if (standardID.HasValue) { expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (classmajorID.HasValue) { expStudent = expStudent.And(x => x.ClassmajorID == classmajorID); } if (IsPay.HasValue) { if (IsPay == false) { exr = exr.And(x => x.IsPay == IsPay || x.IsPay == null); } else { exr = exr.And(x => x.IsPay == IsPay); } } var q = ExaminationSubjectDAL.GetRegistedListView(exp, expStudent, exr); if (!string.IsNullOrEmpty(conditions.ConditionValue) && !string.IsNullOrEmpty(conditions.Attribute)) q = q.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.SubjectName).ThenBy(x => x.StudentNo).ToList(); } IGridResultSet IExaminationSubjectServices.GetExaminationSubjectStudentListView(ConfiguretView conditions, Guid? subjectID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, Guid? examinationTypeID, Guid? schoolYearID, bool? IsPay, int pageIndex, int pageSize) { Expression> exr = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolYearID.HasValue) { exr = exr.And(x => x.ExaminationSchoolyearID == schoolYearID); } if (examinationTypeID.HasValue) { exp = exp.And(x => x.ExaminationTypeID == examinationTypeID); } if (subjectID.HasValue) { exp = exp.And(x => x.ExaminationSubjectID == subjectID.Value); } if (collegeID.HasValue) { expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); } if (year.HasValue) { expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.GradeID == year); } if (standardID.HasValue) { expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID); } if (classmajorID.HasValue) { expStudent = expStudent.And(x => x.ClassmajorID == classmajorID); } if (IsPay.HasValue) { if(IsPay==false){ exr = exr.And(x => x.IsPay == IsPay||x.IsPay==null); } else{ exr = exr.And(x => x.IsPay == IsPay); } } var q = ExaminationSubjectDAL.GetRegistedListView(exp, expStudent,exr); if (!string.IsNullOrEmpty(conditions.ConditionValue) && !string.IsNullOrEmpty(conditions.Attribute)) q = q.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue); return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.SubjectName).ThenBy(x => x.StudentNo).ToGridResultSet(pageIndex, pageSize); } public Bowin.Common.Linq.Entity.IGridResultSet GetExaminationSubjectNameViewList(ViewModel.ConfiguretView examinationSubjectView, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var q = ExaminationSubjectDAL.GetExaminationSubjectView1(exp); if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute)) q = q.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue); return q.OrderBy(x=>x.Name).ToGridResultSet(pageIndex, pageSize); } /// /// 考试报名班级学生统计 /// /// /// /// /// /// public IGridResultSet GetExaminationSubjectClassStudentStatisticsListView(Guid? subjectID, int? schoolYear, Guid? schoolYearID, int pageIndex, int pageSize, Guid? campusID, Guid? collegeID, Guid? classmajorID, int? standardID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (campusID.HasValue) expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CampusID == campusID); if (collegeID.HasValue) expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID); if (classmajorID.HasValue) expStudent = expStudent.And(x => x.ClassmajorID == classmajorID); if (standardID.HasValue) expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID); if(schoolYear.HasValue&&schoolYear!=-1) { expStudent = expStudent.And(x => x.CF_Classmajor.CF_Grademajor.GradeID == schoolYear); } if (schoolYearID.HasValue) { exp = exp.And(x => x.ExaminationSchoolyearID == schoolYearID); } if (subjectID.HasValue) { exp = exp.And(x => x.ExaminationSubjectID == subjectID.Value); } var q = ExaminationSubjectDAL.GetRegistedClassStudentStatisticsListView(exp, expStudent); return q.OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExaminationSchoolyearCode).ThenBy(x => x.Year).ThenBy(x => x.SubjectName).ThenBy(x => x.ClassmajorName).ThenBy(x => x.Cost).ToGridResultSet(pageIndex, pageSize); } /// /// 考试报名班级学生统计 /// /// /// /// public List GetExaminationSubjectClassStudentStatisticsList(Guid? subjectID, Guid? schoolYearID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolYearID.HasValue) { exp = exp.And(x => x.SchoolyearID == schoolYearID); } if (subjectID.HasValue) { exp = exp.And(x => x.ExaminationSubjectID == subjectID.Value); } var q = ExaminationSubjectDAL.GetRegistedClassStudentStatisticsListView(exp, expStudent); return q.OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.SubjectName).ThenBy(x => x.ClassmajorName).ThenBy(x => x.Cost).ToList(); } public string[] Validation(List ExaminationTypeIDs, List SchoolyearIDs, List ExaminationFormIDs, List names) { try { for (int i = 0; i < ExaminationTypeIDs.Count; i++) { Guid? ExaminationTypeID = ExaminationTypeIDs[0]; Guid? SchoolyearID = SchoolyearIDs[0]; int? ExaminationFormID = ExaminationFormIDs[0]; string name = names[0]; //var SubjectCountLimit = SubjectCountLimitDAL.ExaminationSubjectCountLimitRepository.Entities.Where(x => // x.ExaminationTypeID == examinationType.Value && x.FacultymajorID == facultymajorIDs[0].Value && // x.Years == years[0].Value).FirstOrDefault(); var Subject = ExaminationSubjectDAL.GetExaminationSubjectView(x => x.ExaminationTypeID == ExaminationTypeID && x.SchoolyearID == SchoolyearID && x.ExaminationFormID == ExaminationFormID && x.Name == name).FirstOrDefault(); if (Subject != null) return new[] { "false", "科目【" + Subject.Name + "】" + Subject.SchoolyearCode + "学年学期的" + Subject.ExaminationTypeName + "类型、" + Subject.ExaminationFormName + "类别数据已存在。" }; } } catch (Exception ex) { return new[] { "false", ex.Message }; } return new[] { "true", "成功" }; } public void ExaminationSubjectStudentImport(Dictionary cellheader, out int OkCount, out List errdataList, out int ErrCount, string sourcePhysicalPath) { StringBuilder errorMsg = new StringBuilder(); // 错误信息 List errList = new List(); #region 1.1解析文件,存放到一个List集合里 cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要 // 1.1解析文件,存放到一个List集合里 List enlist = NpoiExcelHelper.ExcelToEntityList(cellheader, sourcePhysicalPath, out errorMsg, out errList); cellheader.Add("ErrorMessage", "错误信息");//还原字典项 if (enlist.Count() <= 0) { throw new Exception("请填写Excel模板信息数据。"); } List SchoolYear = enlist.Select(x => x.SchoolyearCode).ToList(); List StudentNoList = enlist.Select(x => x.StudentNo).ToList(); //List StudentID = enlist.Select(x => x.IDNumber).ToList(); List SubjectNameList = enlist.Select(x => x.SubjectName).ToList(); #endregion var SchoolYearList = ExaminationSubjectDAL.SchoolyearRepository.Entities.Where(x => SchoolYear.Contains(x.Code)).ToList(); List SchoolYearId = ExaminationSubjectDAL.SchoolyearRepository.Entities.Where(x => SchoolYear.Contains(x.Code)).Select(w=>w.SchoolyearID).ToList(); List exaList = new List(); Expression> exr = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE&&SchoolYearId.Contains((Guid)x.ExaminationSchoolyearID)); Expression> exp = x => SubjectNameList.Contains(x.Name); Expression> studentExp = x => StudentNoList.Contains(x.Sys_User.LoginID); List dbList = ExaminationSubjectDAL.GetRegistedStudentListView(exp, studentExp,exr).ToList(); var examiantionRegistIDList = dbList.Select(x => x.ExaminationRegistrationID).ToList(); exaList = ExaminationSubjectDAL.ExaminationRegistrationRepository.GetList(x => examiantionRegistIDList.Contains(x.ExaminationRegistrationID)).ToList(); for (int i = 0; i < enlist.Count();i++ ) { string errorMsgStr = "第" + (i + 2) + "行数据检测异常:"; StudentListView en = enlist[i]; bool isHaveNoInputValue = false; en.IsExcelVaildateOK = true; #region 检查是否有未填的值 if (string.IsNullOrEmpty(en.StudentNo)) { errorMsgStr += "学号不能为空;"; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.IsPay)) { errorMsgStr += "是否交费不能为空;"; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.SchoolyearCode)) { errorMsgStr += "考试学年学期不能为空;"; isHaveNoInputValue = true; } if (string.IsNullOrEmpty(en.SubjectName)) { errorMsgStr += "科目名称不能为空;"; isHaveNoInputValue = true; } #endregion #region 检查数据是否存在 var enSchoolYear=SchoolYearList.Where(x=>x.Code==en.SchoolyearCode).Select(w=>w.SchoolyearID).FirstOrDefault(); if (enSchoolYear != null) { var Students = dbList.Where(x => x.StudentNo == en.StudentNo && x.SubjectName == en.SubjectName&&x.ExaminationSchoolyearID==enSchoolYear).FirstOrDefault(); if (Students == null) { errorMsgStr += "无法匹配对应的数据,请检查;"; isHaveNoInputValue = true; } else { enlist[i] = Students; } } else { errorMsgStr += "考试学年学期不存在;"; isHaveNoInputValue = true; } if (en.IsPay != "是" && en.IsPay != "否") { errorMsgStr += "是否交费填写的字段不正确;"; isHaveNoInputValue = true; } else { enlist[i].IsPay = en.IsPay; } #endregion if (isHaveNoInputValue) { en.IsExcelVaildateOK = false; en.ErrorMessage = errorMsgStr; errList.Add(en); } else { enlist[i].IsExcelVaildateOK = true; } } for (int i = 0; i < enlist.Count(); i++) { StudentListView enA = enlist[i]; if (enA.IsExcelVaildateOK == false) { continue; } var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; bool ispay = enA.IsPay=="是"?true:false; EX_ExaminationRegistration examinationRegistration = exaList.FirstOrDefault(x => x.ExaminationRegistrationID == enA.ExaminationRegistrationID); examinationRegistration.ExaminationSubjectID = enA.ExaminationSubjectID; //报名学年学期 examinationRegistration.SchoolyearID = enA.SchoolyearID; examinationRegistration.UserID = enA.UserID; examinationRegistration.CertificatesType = enA.CertificatesType; examinationRegistration.IDNumber = enA.IDNumber; //考试学年学期 examinationRegistration.ExaminationSchoolyearID = enA.ExaminationSchoolyearID; examinationRegistration.IsPay = ispay; examinationRegistration.RecordStatus=(int)SYS_STATUS.USABLE; this.SetModifyStatus(examinationRegistration); //UnitOfWork.Update(examinationRegistration); } ErrCount = errList.Distinct().Count();//共条数减去失败条数 errdataList = errList.Distinct().ToList(); OkCount = enlist.Distinct().Count() - errList.Distinct().Count(); //UnitOfWork.Commit(); UnitOfWork.BatchUpdate(exaList); } } }