123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Transactions;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using Bowin.Common.Utility;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.ScoreManage.LevelScoreManage;
- using EMIS.DataLogic.ScoreManage.LevelScoreManage;
- using EMIS.CommonLogic.StudentManage.StudentStatistics;
- using EMIS.CommonLogic.SystemServices;
- namespace EMIS.CommonLogic.ScoreManage.LevelScoreManage
- {
- public class LevelScoreServices : BaseWorkflowServices<ER_LevelScore>, ILevelScoreServices
- {
- public Lazy<LevelScoreDAL> LevelScoreDAL { get; set; }
- public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
- /// <summary>
- /// 数据范围
- /// </summary>
- public LevelScoreServices()
- {
- DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege<ER_LevelScore>(x, y, (w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID)));
- }
- /// <summary>
- /// 查询对应的等级成绩信息LevelScoreView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="gradeID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="classmajorID"></param>
- /// <param name="examinationSubjectID"></param>
- /// <param name="inSchoolStatus"></param>
- /// <param name="approvalStatus"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<LevelScoreView> GetLevelScoreViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
- int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? examinationSubjectID, int? inSchoolStatus, int? approvalStatus, int pageIndex, int pageSize)
- {
- var approveStatusList = this.GetStatusViewList();
- Expression<Func<ER_LevelScore, bool>> expLevelScore = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- expLevelScore = expLevelScore.And(x => x.SchoolyearID == schoolyearID);
- }
- if (examinationSubjectID.HasValue)
- {
- expLevelScore = expLevelScore.And(x => x.ExaminationSubjectID == examinationSubjectID);
- }
- if (approvalStatus.HasValue)
- {
- expLevelScore = expLevelScore.And(x => x.ApprovalStatus == approvalStatus);
- }
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (classmajorID.HasValue)
- {
- expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
- }
- if (inSchoolStatus != null && inSchoolStatus > -1)
- {
- var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
- if (inSchoolStatus == 1)
- {
- expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
- }
- if (inSchoolStatus == 0)
- {
- expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
- }
- }
- var query = LevelScoreDAL.Value.GetLevelScoreViewQueryable(expLevelScore, expStudent);
- if (campusID.HasValue)
- {
- query = query.Where(x => x.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- query = query.Where(x => x.CollegeID == collegeID);
- }
- if (gradeID.HasValue)
- {
- query = query.Where(x => x.GradeID == gradeID);
- }
- if (standardID.HasValue)
- {
- query = query.Where(x => x.StandardID == standardID);
- }
- if (educationID.HasValue)
- {
- query = query.Where(x => x.EducationID == educationID);
- }
- if (learningformID.HasValue)
- {
- query = query.Where(x => x.LearningformID == learningformID);
- }
- if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
- {
- var LearnSystems = Convert.ToDecimal(learnSystem);
- query = query.Where(x => x.LearnSystem == LearnSystems);
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.ClassmajorNo.Length)
- .ThenBy(x => x.ClassmajorNo).ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToGridResultSet<LevelScoreView>(pageIndex, pageSize);
- result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
- return result;
- }
- /// <summary>
- /// 查询对应的等级成绩信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="gradeID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="classmajorID"></param>
- /// <param name="examinationSubjectID"></param>
- /// <param name="inSchoolStatus"></param>
- /// <param name="approvalStatus"></param>
- /// <returns></returns>
- public IList<LevelScoreView> GetLevelScoreViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
- int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? examinationSubjectID, int? inSchoolStatus, int? approvalStatus)
- {
- var approveStatusList = this.GetStatusViewList();
- Expression<Func<ER_LevelScore, bool>> expLevelScore = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- expLevelScore = expLevelScore.And(x => x.SchoolyearID == schoolyearID);
- }
- if (examinationSubjectID.HasValue)
- {
- expLevelScore = expLevelScore.And(x => x.ExaminationSubjectID == examinationSubjectID);
- }
- if (approvalStatus.HasValue)
- {
- expLevelScore = expLevelScore.And(x => x.ApprovalStatus == approvalStatus);
- }
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (classmajorID.HasValue)
- {
- expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
- }
- if (inSchoolStatus != null && inSchoolStatus > -1)
- {
- var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
- if (inSchoolStatus == 1)
- {
- expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
- }
- if (inSchoolStatus == 0)
- {
- expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
- }
- }
- var query = LevelScoreDAL.Value.GetLevelScoreViewQueryable(expLevelScore, expStudent);
- if (campusID.HasValue)
- {
- query = query.Where(x => x.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- query = query.Where(x => x.CollegeID == collegeID);
- }
- if (gradeID.HasValue)
- {
- query = query.Where(x => x.GradeID == gradeID);
- }
- if (standardID.HasValue)
- {
- query = query.Where(x => x.StandardID == standardID);
- }
- if (educationID.HasValue)
- {
- query = query.Where(x => x.EducationID == educationID);
- }
- if (learningformID.HasValue)
- {
- query = query.Where(x => x.LearningformID == learningformID);
- }
- if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
- {
- var LearnSystems = Convert.ToDecimal(learnSystem);
- query = query.Where(x => x.LearnSystem == LearnSystems);
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.ClassmajorNo.Length)
- .ThenBy(x => x.ClassmajorNo).ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToList();
- result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
- return result;
- }
- /// <summary>
- /// 查询对应的等级成绩信息View
- /// </summary>
- /// <param name="levelScoreID"></param>
- /// <returns></returns>
- public LevelScoreView GetLevelScoreView(Guid? levelScoreID)
- {
- try
- {
- var query = LevelScoreDAL.Value.GetLevelScoreViewQueryable(x => x.LevelScoreID == levelScoreID).SingleOrDefault();
- return query;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="levelScoreView"></param>
- public virtual void LevelScoreEdit(LevelScoreView levelScoreView)
- {
- try
- {
- var approveStatusList = this.GetStatusViewList();
- if (approveStatusList == null || approveStatusList.Count() <= 0)
- {
- throw new Exception("工作流平台中,科目成绩录入流程未配置,请核查。");
- }
- var startStatusID = this.GetStartStatus();
- if (startStatusID == null)
- {
- throw new Exception("工作流平台中,科目成绩录入流程开始环节未配置,请核查。");
- }
- var correctEndStatusID = this.GetCorrectEndStatus();
- if (correctEndStatusID == null)
- {
- throw new Exception("工作流平台中,科目成绩录入流程结束环节未配置,请核查。");
- }
- ER_LevelScore levelScoreVerify = null;
- var levelScoreList = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => x.LevelScoreID != levelScoreView.LevelScoreID && x.UserID == levelScoreView.UserID && x.ExaminationSubjectID == levelScoreView.ExaminationSubjectID).ToList();
- if (levelScoreList != null && levelScoreList.Count() > 0)
- {
- levelScoreVerify = levelScoreList.Where(x => x.ExaminationDate.ToStringEx("yyyyMM") == levelScoreView.ExaminationDate.ToStringEx("yyyyMM")).SingleOrDefault();
- }
- if (levelScoreVerify == null)
- {
- if (levelScoreView.LevelScoreID != Guid.Empty)
- {
- var levelScore = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => x.LevelScoreID == levelScoreView.LevelScoreID).SingleOrDefault();
- if (levelScore == null)
- {
- throw new Exception("数据有误,请核查。");
- }
- else
- {
- //表示修改
- levelScore.UserID = levelScoreView.UserID;
- levelScore.ExaminationSubjectID = levelScoreView.ExaminationSubjectID;
- levelScore.SchoolyearID = levelScoreView.SchoolyearID;
- levelScore.ExaminationDate = levelScoreView.ExaminationDate;
- levelScore.ScoreNo = levelScoreView.ScoreNo;
- levelScore.TotalScore = levelScoreView.TotalScore;
- levelScore.Remark = levelScoreView.Remark;
- SetModifyStatus(levelScore);
- }
- }
- else
- {
- //表示新增
- var newLevelScore = new ER_LevelScore();
- newLevelScore.LevelScoreID = Guid.NewGuid();
- newLevelScore.UserID = levelScoreView.UserID;
- newLevelScore.ExaminationSubjectID = levelScoreView.ExaminationSubjectID;
- newLevelScore.SchoolyearID = levelScoreView.SchoolyearID;
- newLevelScore.ExaminationDate = levelScoreView.ExaminationDate;
- newLevelScore.ScoreNo = levelScoreView.ScoreNo.Trim();
- newLevelScore.TotalScore = levelScoreView.TotalScore;
- newLevelScore.Remark = levelScoreView.Remark;
- newLevelScore.ApprovalStatus = correctEndStatusID;
- SetNewStatus(newLevelScore);
- UnitOfWork.Add(newLevelScore);
- }
- }
- else
- {
- throw new Exception("已存在相同的科目成绩信息(学生信息、考试科目、考试日期唯一),请核查。");
- }
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="levelScoreIDs"></param>
- /// <returns></returns>
- public bool LevelScoreDelete(List<Guid?> levelScoreIDs)
- {
- try
- {
- UnitOfWork.Delete<ER_LevelScore>(x => levelScoreIDs.Contains(x.LevelScoreID));
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 提交
- /// </summary>
- /// <param name="levelScoreIDs"></param>
- /// <param name="userID"></param>
- /// <param name="comment"></param>
- /// <returns></returns>
- public string LevelScoreSubmit(List<Guid> levelScoreIDs, Guid userID, string comment = "")
- {
- try
- {
- var startStatusID = this.GetStartStatus();
- if (startStatusID == null)
- {
- throw new Exception("工作流平台中,科目成绩录入流程开始环节流程未配置,请核查。");
- }
- var levelScoreList = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => levelScoreIDs.Contains(x.LevelScoreID)).ToList();
- int success = 0;
- string tipMessage = null;
- var submitIDList = new List<Guid>();
- var approveIDList = new List<Guid>();
- foreach (var levelScore in levelScoreList)
- {
- if (levelScore.ExaminationDate == null || levelScore.TotalScore == null)
- {
- throw new Exception("提交失败,原因:选择提交的数据有误,考试日期或总成绩不能为空,请核查。");
- }
- if (levelScore.ApprovalStatus == startStatusID)
- {
- submitIDList.Add(levelScore.LevelScoreID);
- }
- else
- {
- approveIDList.Add(levelScore.LevelScoreID);
- }
- success++;
- }
- if (submitIDList.Count > 0)
- {
- this.StartUp(submitIDList, userID, comment);
- }
- if (approveIDList.Count > 0)
- {
- this.Approve(approveIDList, userID, Guid.Empty, comment);
- }
- tipMessage = success + "条";
- return tipMessage;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 审核确定(批量)
- /// </summary>
- /// <param name="levelScoreIDs"></param>
- /// <param name="userID"></param>
- /// <param name="actionID"></param>
- /// <param name="comment"></param>
- public void LevelScoreApproveConfirm(List<Guid?> levelScoreIDs, Guid userID, Guid actionID, string comment)
- {
- try
- {
- var levelScoreList = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => levelScoreIDs.Contains(x.LevelScoreID)).ToList();
- foreach (var levelScoreID in levelScoreIDs)
- {
- var levelScore = levelScoreList.Where(x => x.LevelScoreID == levelScoreID).SingleOrDefault();
- if (levelScore == null)
- {
- throw new Exception("数据有误,请核查。");
- }
- if (levelScore.ExaminationDate == null || levelScore.TotalScore == null)
- {
- throw new Exception("审核失败,原因:提交审核的数据有误,考试日期或总成绩不能为空,请核查。");
- }
- }
- this.Approve(levelScoreIDs.Select(x => x.Value).ToList(), userID, actionID, comment);
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 等级成绩Excel导入
- /// </summary>
- /// <param name="cellheader"></param>
- /// <param name="inCount"></param>
- /// <param name="upCount"></param>
- /// <param name="errdataList"></param>
- /// <param name="errCount"></param>
- /// <param name="sourcePhysicalPath"></param>
- public virtual void LevelScoreImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<LevelScoreView> errdataList, out int? errCount, string sourcePhysicalPath)
- {
- try
- {
- var approveStatusList = this.GetStatusViewList();
- if (approveStatusList == null || approveStatusList.Count() <= 0)
- {
- throw new Exception("工作流平台中,科目成绩录入流程未配置,请核查。");
- }
- var startStatusID = this.GetStartStatus();
- if (startStatusID == null)
- {
- throw new Exception("工作流平台中,科目成绩录入流程开始环节未配置,请核查。");
- }
- var correctEndStatusID = this.GetCorrectEndStatus();
- if (correctEndStatusID == null)
- {
- throw new Exception("工作流平台中,科目成绩录入流程结束环节未配置,请核查。");
- }
- StringBuilder errorMsg = new StringBuilder();
- var errList = new List<LevelScoreView>();
- cellheader.Remove("ErrorMessage");
- var enlist = NpoiExcelHelper.ExcelToEntityList<LevelScoreView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
- cellheader.Add("ErrorMessage", "未导入原因");
- //对List集合进行有效性校验
- if (enlist.Count() <= 0)
- {
- throw new Exception("Excel文件数据为空,请检查。");
- }
- Regex reg = null;
- DateTime result;
- decimal isDecimal;
- inCount = 0;
- upCount = 0;
- errCount = 0;
- string errorMsgStr = "";
- List<ER_LevelScore> levelScoreInList = new List<ER_LevelScore>();
- List<ER_LevelScore> levelScoreUpList = new List<ER_LevelScore>();
- //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
- //学号
- var studentNoList = enlist.Where(x => !string.IsNullOrEmpty(x.StudentNo)).Select(x => x.StudentNo).ToList();
- var studentList = LevelScoreDAL.Value.StudentRepository.GetList(x => studentNoList.Contains(x.Sys_User.LoginID), (x => x.Sys_User)).ToList();
- var userIDList = studentList.Select(x => x.UserID).ToList();
- var examinationSubjectNameList = enlist.Where(x => !string.IsNullOrEmpty(x.ExaminationSubjectName)).Select(x => x.ExaminationSubjectName).ToList();
- var examinationSubjectList = LevelScoreDAL.Value.ExaminationSubjectRepository.GetList(x => examinationSubjectNameList.Contains(x.Name)).ToList();
- var examinationSubjectIDList = examinationSubjectList.Select(x => x.ExaminationSubjectID).ToList();
- var schoolyearCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.SchoolyearCode)).Select(x => x.SchoolyearCode).ToList();
- var schoolyearList = LevelScoreDAL.Value.SchoolyearRepository.GetList(x => schoolyearCodeList.Contains(x.Code)).ToList();
- var schoolyearIDList = schoolyearList.Select(x => x.SchoolyearID).ToList();
- var levelScoreList = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => schoolyearIDList.Contains(x.SchoolyearID.Value)).ToList();
- levelScoreList = levelScoreList.Where(x => userIDList.Contains(x.UserID.Value) && examinationSubjectIDList.Contains(x.ExaminationSubjectID.Value)).ToList();
- //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
- for (int i = 0; i < enlist.Count; i++)
- {
- LevelScoreView en = enlist[i];
- ER_LevelScore newLevelScore = new ER_LevelScore();
- //学号
- if (string.IsNullOrEmpty(en.StudentNo))
- {
- errCount++;
- errorMsgStr = "学号不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var student = studentList.Where(x => x.Sys_User.LoginID == en.StudentNo.Trim()).SingleOrDefault();
- if (student == null)
- {
- errCount++;
- errorMsgStr = "学号不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- newLevelScore.UserID = student.UserID;
- }
- }
- //考试科目
- if (string.IsNullOrEmpty(en.ExaminationSubjectName))
- {
- errCount++;
- errorMsgStr = "考试科目不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var examinationSubject = examinationSubjectList.Where(x => x.Name == en.ExaminationSubjectName.Trim()).SingleOrDefault();
- if (examinationSubject == null)
- {
- errCount++;
- errorMsgStr = "考试科目不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- newLevelScore.ExaminationSubjectID = examinationSubject.ExaminationSubjectID;
- }
- }
- //学年学期
- if (string.IsNullOrEmpty(en.SchoolyearCode))
- {
- errCount++;
- errorMsgStr = "学年学期不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var schoolyear = schoolyearList.Where(x => x.Code == en.SchoolyearCode.Trim()).SingleOrDefault();
- if (schoolyear == null)
- {
- errCount++;
- errorMsgStr = "学年学期不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- newLevelScore.SchoolyearID = schoolyear.SchoolyearID;
- }
- }
- //考试日期
- if (string.IsNullOrWhiteSpace(en.ExaminationDateStr))
- {
- errCount++;
- errorMsgStr = "考试日期不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28
- if (!DateTime.TryParse(en.ExaminationDateStr, out result))
- {
- errCount++;
- errorMsgStr = "考试日期格式不正确,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- newLevelScore.ExaminationDate = Convert.ToDateTime(en.ExaminationDateStr);
- }
- }
- //成绩单编号
- if (string.IsNullOrWhiteSpace(en.ScoreNo))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
- if (!reg.IsMatch(en.ScoreNo))
- {
- errCount++;
- errorMsgStr = "成绩单编号格式不正确,请检查(数字或英文字母)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- newLevelScore.ScoreNo = en.ScoreNo.Trim();
- }
- }
- //总成绩
- if (string.IsNullOrEmpty(en.TotalScoreStr))
- {
- errCount++;
- errorMsgStr = "总成绩不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- if (!Decimal.TryParse(en.TotalScoreStr.Trim(), out isDecimal))
- {
- errCount++;
- errorMsgStr = "总成绩格式不正确,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- newLevelScore.TotalScore = Convert.ToDecimal(en.TotalScoreStr.Trim());
- }
- }
- //备注
- if (string.IsNullOrWhiteSpace(en.Remark))
- {
- //不考虑
- }
- else
- {
- newLevelScore.Remark = en.Remark;
- }
- //数据表重复性验证(用户ID、考试科目ID、考试日期唯一)
- var levelScoreVerify = levelScoreList.Where(x => x.UserID == newLevelScore.UserID && x.ExaminationSubjectID == newLevelScore.ExaminationSubjectID && x.ExaminationDate.ToStringEx("yyyyMM") == newLevelScore.ExaminationDate.ToStringEx("yyyyMM")).SingleOrDefault();
- if (levelScoreVerify == null)
- {
- //新增
- if (!levelScoreInList.Any(x => x.UserID == newLevelScore.UserID && x.ExaminationSubjectID == newLevelScore.ExaminationSubjectID && x.ExaminationDate.ToStringEx("yyyyMM") == newLevelScore.ExaminationDate.ToStringEx("yyyyMM")))
- {
- newLevelScore.LevelScoreID = Guid.NewGuid();
- newLevelScore.ApprovalStatus = correctEndStatusID;
- SetNewStatus(newLevelScore);
- levelScoreInList.Add(newLevelScore);
- inCount++;
- }
- else
- {
- //Excel表重复性验证
- //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
- inCount++;
- }
- }
- else
- {
- //更新(Excel有重复时,以最后一条记录的更新为准)
- levelScoreVerify.SchoolyearID = newLevelScore.SchoolyearID;
- levelScoreVerify.ScoreNo = newLevelScore.ScoreNo;
- levelScoreVerify.TotalScore = newLevelScore.TotalScore;
- levelScoreVerify.Remark = newLevelScore.Remark;
- SetModifyStatus(levelScoreVerify);
- levelScoreUpList.Add(levelScoreVerify);
- upCount++;
- }
- }
- using (TransactionScope ts = new TransactionScope())
- {
- UnitOfWork.BulkInsert(levelScoreInList);
- if (levelScoreUpList != null && levelScoreUpList.Count() > 0)
- {
- UnitOfWork.BatchUpdate(levelScoreUpList);
- }
- ts.Complete();
- }
- errdataList = errList.Distinct().ToList();
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 流程结束跳转函数(工作流平台中配置)
- /// </summary>
- /// <param name="levelScoreIDList"></param>
- /// <param name="userID"></param>
- public void OnApproveEnd(List<Guid> levelScoreIDList, Guid? userID)
- {
- throw new NotImplementedException();
- }
- }
- }
|