LevelScoreServices.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Transactions;
  8. using Bowin.Common.Linq;
  9. using Bowin.Common.Linq.Entity;
  10. using Bowin.Common.Utility;
  11. using EMIS.Entities;
  12. using EMIS.ViewModel;
  13. using EMIS.ViewModel.ScoreManage.LevelScoreManage;
  14. using EMIS.DataLogic.ScoreManage.LevelScoreManage;
  15. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  16. using EMIS.CommonLogic.SystemServices;
  17. namespace EMIS.CommonLogic.ScoreManage.LevelScoreManage
  18. {
  19. public class LevelScoreServices : BaseWorkflowServices<ER_LevelScore>, ILevelScoreServices
  20. {
  21. public Lazy<LevelScoreDAL> LevelScoreDAL { get; set; }
  22. public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
  23. /// <summary>
  24. /// 数据范围
  25. /// </summary>
  26. public LevelScoreServices()
  27. {
  28. DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege<ER_LevelScore>(x, y, (w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID)));
  29. }
  30. /// <summary>
  31. /// 查询对应的等级成绩信息LevelScoreView
  32. /// </summary>
  33. /// <param name="configuretView"></param>
  34. /// <param name="schoolyearID"></param>
  35. /// <param name="campusID"></param>
  36. /// <param name="collegeID"></param>
  37. /// <param name="gradeID"></param>
  38. /// <param name="standardID"></param>
  39. /// <param name="educationID"></param>
  40. /// <param name="learningformID"></param>
  41. /// <param name="learnSystem"></param>
  42. /// <param name="classmajorID"></param>
  43. /// <param name="examinationSubjectID"></param>
  44. /// <param name="inSchoolStatus"></param>
  45. /// <param name="approvalStatus"></param>
  46. /// <param name="pageIndex"></param>
  47. /// <param name="pageSize"></param>
  48. /// <returns></returns>
  49. public IGridResultSet<LevelScoreView> GetLevelScoreViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  50. int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? examinationSubjectID, int? inSchoolStatus, int? approvalStatus, int pageIndex, int pageSize)
  51. {
  52. var approveStatusList = this.GetStatusViewList();
  53. Expression<Func<ER_LevelScore, bool>> expLevelScore = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  54. if (schoolyearID.HasValue)
  55. {
  56. expLevelScore = expLevelScore.And(x => x.SchoolyearID == schoolyearID);
  57. }
  58. if (examinationSubjectID.HasValue)
  59. {
  60. expLevelScore = expLevelScore.And(x => x.ExaminationSubjectID == examinationSubjectID);
  61. }
  62. if (approvalStatus.HasValue)
  63. {
  64. expLevelScore = expLevelScore.And(x => x.ApprovalStatus == approvalStatus);
  65. }
  66. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  67. if (classmajorID.HasValue)
  68. {
  69. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  70. }
  71. if (inSchoolStatus != null && inSchoolStatus > -1)
  72. {
  73. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  74. if (inSchoolStatus == 1)
  75. {
  76. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  77. }
  78. if (inSchoolStatus == 0)
  79. {
  80. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  81. }
  82. }
  83. var query = LevelScoreDAL.Value.GetLevelScoreViewQueryable(expLevelScore, expStudent);
  84. if (campusID.HasValue)
  85. {
  86. query = query.Where(x => x.CampusID == campusID);
  87. }
  88. if (collegeID.HasValue)
  89. {
  90. query = query.Where(x => x.CollegeID == collegeID);
  91. }
  92. if (gradeID.HasValue)
  93. {
  94. query = query.Where(x => x.GradeID == gradeID);
  95. }
  96. if (standardID.HasValue)
  97. {
  98. query = query.Where(x => x.StandardID == standardID);
  99. }
  100. if (educationID.HasValue)
  101. {
  102. query = query.Where(x => x.EducationID == educationID);
  103. }
  104. if (learningformID.HasValue)
  105. {
  106. query = query.Where(x => x.LearningformID == learningformID);
  107. }
  108. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  109. {
  110. var LearnSystems = Convert.ToDecimal(learnSystem);
  111. query = query.Where(x => x.LearnSystem == LearnSystems);
  112. }
  113. //查询条件
  114. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  115. {
  116. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  117. }
  118. var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.ClassmajorNo.Length)
  119. .ThenBy(x => x.ClassmajorNo).ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToGridResultSet<LevelScoreView>(pageIndex, pageSize);
  120. result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  121. return result;
  122. }
  123. /// <summary>
  124. /// 查询对应的等级成绩信息List
  125. /// </summary>
  126. /// <param name="configuretView"></param>
  127. /// <param name="schoolyearID"></param>
  128. /// <param name="campusID"></param>
  129. /// <param name="collegeID"></param>
  130. /// <param name="gradeID"></param>
  131. /// <param name="standardID"></param>
  132. /// <param name="educationID"></param>
  133. /// <param name="learningformID"></param>
  134. /// <param name="learnSystem"></param>
  135. /// <param name="classmajorID"></param>
  136. /// <param name="examinationSubjectID"></param>
  137. /// <param name="inSchoolStatus"></param>
  138. /// <param name="approvalStatus"></param>
  139. /// <returns></returns>
  140. public IList<LevelScoreView> GetLevelScoreViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  141. int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? examinationSubjectID, int? inSchoolStatus, int? approvalStatus)
  142. {
  143. var approveStatusList = this.GetStatusViewList();
  144. Expression<Func<ER_LevelScore, bool>> expLevelScore = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  145. if (schoolyearID.HasValue)
  146. {
  147. expLevelScore = expLevelScore.And(x => x.SchoolyearID == schoolyearID);
  148. }
  149. if (examinationSubjectID.HasValue)
  150. {
  151. expLevelScore = expLevelScore.And(x => x.ExaminationSubjectID == examinationSubjectID);
  152. }
  153. if (approvalStatus.HasValue)
  154. {
  155. expLevelScore = expLevelScore.And(x => x.ApprovalStatus == approvalStatus);
  156. }
  157. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  158. if (classmajorID.HasValue)
  159. {
  160. expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
  161. }
  162. if (inSchoolStatus != null && inSchoolStatus > -1)
  163. {
  164. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  165. if (inSchoolStatus == 1)
  166. {
  167. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  168. }
  169. if (inSchoolStatus == 0)
  170. {
  171. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  172. }
  173. }
  174. var query = LevelScoreDAL.Value.GetLevelScoreViewQueryable(expLevelScore, expStudent);
  175. if (campusID.HasValue)
  176. {
  177. query = query.Where(x => x.CampusID == campusID);
  178. }
  179. if (collegeID.HasValue)
  180. {
  181. query = query.Where(x => x.CollegeID == collegeID);
  182. }
  183. if (gradeID.HasValue)
  184. {
  185. query = query.Where(x => x.GradeID == gradeID);
  186. }
  187. if (standardID.HasValue)
  188. {
  189. query = query.Where(x => x.StandardID == standardID);
  190. }
  191. if (educationID.HasValue)
  192. {
  193. query = query.Where(x => x.EducationID == educationID);
  194. }
  195. if (learningformID.HasValue)
  196. {
  197. query = query.Where(x => x.LearningformID == learningformID);
  198. }
  199. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  200. {
  201. var LearnSystems = Convert.ToDecimal(learnSystem);
  202. query = query.Where(x => x.LearnSystem == LearnSystems);
  203. }
  204. //查询条件
  205. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  206. {
  207. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  208. }
  209. var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.ClassmajorNo.Length)
  210. .ThenBy(x => x.ClassmajorNo).ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToList();
  211. result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
  212. return result;
  213. }
  214. /// <summary>
  215. /// 查询对应的等级成绩信息View
  216. /// </summary>
  217. /// <param name="levelScoreID"></param>
  218. /// <returns></returns>
  219. public LevelScoreView GetLevelScoreView(Guid? levelScoreID)
  220. {
  221. try
  222. {
  223. var query = LevelScoreDAL.Value.GetLevelScoreViewQueryable(x => x.LevelScoreID == levelScoreID).SingleOrDefault();
  224. return query;
  225. }
  226. catch (Exception ex)
  227. {
  228. throw new Exception(ex.Message);
  229. }
  230. }
  231. /// <summary>
  232. /// 编辑
  233. /// </summary>
  234. /// <param name="levelScoreView"></param>
  235. public virtual void LevelScoreEdit(LevelScoreView levelScoreView)
  236. {
  237. try
  238. {
  239. var approveStatusList = this.GetStatusViewList();
  240. if (approveStatusList == null || approveStatusList.Count() <= 0)
  241. {
  242. throw new Exception("工作流平台中,科目成绩录入流程未配置,请核查。");
  243. }
  244. var startStatusID = this.GetStartStatus();
  245. if (startStatusID == null)
  246. {
  247. throw new Exception("工作流平台中,科目成绩录入流程开始环节未配置,请核查。");
  248. }
  249. var correctEndStatusID = this.GetCorrectEndStatus();
  250. if (correctEndStatusID == null)
  251. {
  252. throw new Exception("工作流平台中,科目成绩录入流程结束环节未配置,请核查。");
  253. }
  254. ER_LevelScore levelScoreVerify = null;
  255. var levelScoreList = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => x.LevelScoreID != levelScoreView.LevelScoreID && x.UserID == levelScoreView.UserID && x.ExaminationSubjectID == levelScoreView.ExaminationSubjectID).ToList();
  256. if (levelScoreList != null && levelScoreList.Count() > 0)
  257. {
  258. levelScoreVerify = levelScoreList.Where(x => x.ExaminationDate.ToStringEx("yyyyMM") == levelScoreView.ExaminationDate.ToStringEx("yyyyMM")).SingleOrDefault();
  259. }
  260. if (levelScoreVerify == null)
  261. {
  262. if (levelScoreView.LevelScoreID != Guid.Empty)
  263. {
  264. var levelScore = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => x.LevelScoreID == levelScoreView.LevelScoreID).SingleOrDefault();
  265. if (levelScore == null)
  266. {
  267. throw new Exception("数据有误,请核查。");
  268. }
  269. else
  270. {
  271. //表示修改
  272. levelScore.UserID = levelScoreView.UserID;
  273. levelScore.ExaminationSubjectID = levelScoreView.ExaminationSubjectID;
  274. levelScore.SchoolyearID = levelScoreView.SchoolyearID;
  275. levelScore.ExaminationDate = levelScoreView.ExaminationDate;
  276. levelScore.ScoreNo = levelScoreView.ScoreNo;
  277. levelScore.TotalScore = levelScoreView.TotalScore;
  278. levelScore.Remark = levelScoreView.Remark;
  279. SetModifyStatus(levelScore);
  280. }
  281. }
  282. else
  283. {
  284. //表示新增
  285. var newLevelScore = new ER_LevelScore();
  286. newLevelScore.LevelScoreID = Guid.NewGuid();
  287. newLevelScore.UserID = levelScoreView.UserID;
  288. newLevelScore.ExaminationSubjectID = levelScoreView.ExaminationSubjectID;
  289. newLevelScore.SchoolyearID = levelScoreView.SchoolyearID;
  290. newLevelScore.ExaminationDate = levelScoreView.ExaminationDate;
  291. newLevelScore.ScoreNo = levelScoreView.ScoreNo.Trim();
  292. newLevelScore.TotalScore = levelScoreView.TotalScore;
  293. newLevelScore.Remark = levelScoreView.Remark;
  294. newLevelScore.ApprovalStatus = correctEndStatusID;
  295. SetNewStatus(newLevelScore);
  296. UnitOfWork.Add(newLevelScore);
  297. }
  298. }
  299. else
  300. {
  301. throw new Exception("已存在相同的科目成绩信息(学生信息、考试科目、考试日期唯一),请核查。");
  302. }
  303. UnitOfWork.Commit();
  304. }
  305. catch (Exception ex)
  306. {
  307. throw new Exception(ex.Message);
  308. }
  309. }
  310. /// <summary>
  311. /// 删除
  312. /// </summary>
  313. /// <param name="levelScoreIDs"></param>
  314. /// <returns></returns>
  315. public bool LevelScoreDelete(List<Guid?> levelScoreIDs)
  316. {
  317. try
  318. {
  319. UnitOfWork.Delete<ER_LevelScore>(x => levelScoreIDs.Contains(x.LevelScoreID));
  320. return true;
  321. }
  322. catch (Exception)
  323. {
  324. throw;
  325. }
  326. }
  327. /// <summary>
  328. /// 提交
  329. /// </summary>
  330. /// <param name="levelScoreIDs"></param>
  331. /// <param name="userID"></param>
  332. /// <param name="comment"></param>
  333. /// <returns></returns>
  334. public string LevelScoreSubmit(List<Guid> levelScoreIDs, Guid userID, string comment = "")
  335. {
  336. try
  337. {
  338. var startStatusID = this.GetStartStatus();
  339. if (startStatusID == null)
  340. {
  341. throw new Exception("工作流平台中,科目成绩录入流程开始环节流程未配置,请核查。");
  342. }
  343. var levelScoreList = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => levelScoreIDs.Contains(x.LevelScoreID)).ToList();
  344. int success = 0;
  345. string tipMessage = null;
  346. var submitIDList = new List<Guid>();
  347. var approveIDList = new List<Guid>();
  348. foreach (var levelScore in levelScoreList)
  349. {
  350. if (levelScore.ExaminationDate == null || levelScore.TotalScore == null)
  351. {
  352. throw new Exception("提交失败,原因:选择提交的数据有误,考试日期或总成绩不能为空,请核查。");
  353. }
  354. if (levelScore.ApprovalStatus == startStatusID)
  355. {
  356. submitIDList.Add(levelScore.LevelScoreID);
  357. }
  358. else
  359. {
  360. approveIDList.Add(levelScore.LevelScoreID);
  361. }
  362. success++;
  363. }
  364. if (submitIDList.Count > 0)
  365. {
  366. this.StartUp(submitIDList, userID, comment);
  367. }
  368. if (approveIDList.Count > 0)
  369. {
  370. this.Approve(approveIDList, userID, Guid.Empty, comment);
  371. }
  372. tipMessage = success + "条";
  373. return tipMessage;
  374. }
  375. catch (Exception ex)
  376. {
  377. throw new Exception(ex.Message);
  378. }
  379. }
  380. /// <summary>
  381. /// 审核确定(批量)
  382. /// </summary>
  383. /// <param name="levelScoreIDs"></param>
  384. /// <param name="userID"></param>
  385. /// <param name="actionID"></param>
  386. /// <param name="comment"></param>
  387. public void LevelScoreApproveConfirm(List<Guid?> levelScoreIDs, Guid userID, Guid actionID, string comment)
  388. {
  389. try
  390. {
  391. var levelScoreList = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => levelScoreIDs.Contains(x.LevelScoreID)).ToList();
  392. foreach (var levelScoreID in levelScoreIDs)
  393. {
  394. var levelScore = levelScoreList.Where(x => x.LevelScoreID == levelScoreID).SingleOrDefault();
  395. if (levelScore == null)
  396. {
  397. throw new Exception("数据有误,请核查。");
  398. }
  399. if (levelScore.ExaminationDate == null || levelScore.TotalScore == null)
  400. {
  401. throw new Exception("审核失败,原因:提交审核的数据有误,考试日期或总成绩不能为空,请核查。");
  402. }
  403. }
  404. this.Approve(levelScoreIDs.Select(x => x.Value).ToList(), userID, actionID, comment);
  405. }
  406. catch (Exception ex)
  407. {
  408. throw new Exception(ex.Message);
  409. }
  410. }
  411. /// <summary>
  412. /// 等级成绩Excel导入
  413. /// </summary>
  414. /// <param name="cellheader"></param>
  415. /// <param name="inCount"></param>
  416. /// <param name="upCount"></param>
  417. /// <param name="errdataList"></param>
  418. /// <param name="errCount"></param>
  419. /// <param name="sourcePhysicalPath"></param>
  420. public virtual void LevelScoreImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<LevelScoreView> errdataList, out int? errCount, string sourcePhysicalPath)
  421. {
  422. try
  423. {
  424. var approveStatusList = this.GetStatusViewList();
  425. if (approveStatusList == null || approveStatusList.Count() <= 0)
  426. {
  427. throw new Exception("工作流平台中,科目成绩录入流程未配置,请核查。");
  428. }
  429. var startStatusID = this.GetStartStatus();
  430. if (startStatusID == null)
  431. {
  432. throw new Exception("工作流平台中,科目成绩录入流程开始环节未配置,请核查。");
  433. }
  434. var correctEndStatusID = this.GetCorrectEndStatus();
  435. if (correctEndStatusID == null)
  436. {
  437. throw new Exception("工作流平台中,科目成绩录入流程结束环节未配置,请核查。");
  438. }
  439. StringBuilder errorMsg = new StringBuilder();
  440. var errList = new List<LevelScoreView>();
  441. cellheader.Remove("ErrorMessage");
  442. var enlist = NpoiExcelHelper.ExcelToEntityList<LevelScoreView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  443. cellheader.Add("ErrorMessage", "未导入原因");
  444. //对List集合进行有效性校验
  445. if (enlist.Count() <= 0)
  446. {
  447. throw new Exception("Excel文件数据为空,请检查。");
  448. }
  449. Regex reg = null;
  450. DateTime result;
  451. decimal isDecimal;
  452. inCount = 0;
  453. upCount = 0;
  454. errCount = 0;
  455. string errorMsgStr = "";
  456. List<ER_LevelScore> levelScoreInList = new List<ER_LevelScore>();
  457. List<ER_LevelScore> levelScoreUpList = new List<ER_LevelScore>();
  458. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  459. //学号
  460. var studentNoList = enlist.Where(x => !string.IsNullOrEmpty(x.StudentNo)).Select(x => x.StudentNo).ToList();
  461. var studentList = LevelScoreDAL.Value.StudentRepository.GetList(x => studentNoList.Contains(x.Sys_User.LoginID), (x => x.Sys_User)).ToList();
  462. var userIDList = studentList.Select(x => x.UserID).ToList();
  463. var examinationSubjectNameList = enlist.Where(x => !string.IsNullOrEmpty(x.ExaminationSubjectName)).Select(x => x.ExaminationSubjectName).ToList();
  464. var examinationSubjectList = LevelScoreDAL.Value.ExaminationSubjectRepository.GetList(x => examinationSubjectNameList.Contains(x.Name)).ToList();
  465. var examinationSubjectIDList = examinationSubjectList.Select(x => x.ExaminationSubjectID).ToList();
  466. var schoolyearCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.SchoolyearCode)).Select(x => x.SchoolyearCode).ToList();
  467. var schoolyearList = LevelScoreDAL.Value.SchoolyearRepository.GetList(x => schoolyearCodeList.Contains(x.Code)).ToList();
  468. var schoolyearIDList = schoolyearList.Select(x => x.SchoolyearID).ToList();
  469. var levelScoreList = LevelScoreDAL.Value.LevelScoreRepository.GetList(x => schoolyearIDList.Contains(x.SchoolyearID.Value)).ToList();
  470. levelScoreList = levelScoreList.Where(x => userIDList.Contains(x.UserID.Value) && examinationSubjectIDList.Contains(x.ExaminationSubjectID.Value)).ToList();
  471. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  472. for (int i = 0; i < enlist.Count; i++)
  473. {
  474. LevelScoreView en = enlist[i];
  475. ER_LevelScore newLevelScore = new ER_LevelScore();
  476. //学号
  477. if (string.IsNullOrEmpty(en.StudentNo))
  478. {
  479. errCount++;
  480. errorMsgStr = "学号不能为空";
  481. en.ErrorMessage = errorMsgStr;
  482. errList.Add(en);
  483. errorMsg.AppendLine(errorMsgStr);
  484. continue;
  485. }
  486. else
  487. {
  488. var student = studentList.Where(x => x.Sys_User.LoginID == en.StudentNo.Trim()).SingleOrDefault();
  489. if (student == null)
  490. {
  491. errCount++;
  492. errorMsgStr = "学号不存在,请检查";
  493. en.ErrorMessage = errorMsgStr;
  494. errList.Add(en);
  495. errorMsg.AppendLine(errorMsgStr);
  496. continue;
  497. }
  498. else
  499. {
  500. newLevelScore.UserID = student.UserID;
  501. }
  502. }
  503. //考试科目
  504. if (string.IsNullOrEmpty(en.ExaminationSubjectName))
  505. {
  506. errCount++;
  507. errorMsgStr = "考试科目不能为空";
  508. en.ErrorMessage = errorMsgStr;
  509. errList.Add(en);
  510. errorMsg.AppendLine(errorMsgStr);
  511. continue;
  512. }
  513. else
  514. {
  515. var examinationSubject = examinationSubjectList.Where(x => x.Name == en.ExaminationSubjectName.Trim()).SingleOrDefault();
  516. if (examinationSubject == null)
  517. {
  518. errCount++;
  519. errorMsgStr = "考试科目不存在,请检查";
  520. en.ErrorMessage = errorMsgStr;
  521. errList.Add(en);
  522. errorMsg.AppendLine(errorMsgStr);
  523. continue;
  524. }
  525. else
  526. {
  527. newLevelScore.ExaminationSubjectID = examinationSubject.ExaminationSubjectID;
  528. }
  529. }
  530. //学年学期
  531. if (string.IsNullOrEmpty(en.SchoolyearCode))
  532. {
  533. errCount++;
  534. errorMsgStr = "学年学期不能为空";
  535. en.ErrorMessage = errorMsgStr;
  536. errList.Add(en);
  537. errorMsg.AppendLine(errorMsgStr);
  538. continue;
  539. }
  540. else
  541. {
  542. var schoolyear = schoolyearList.Where(x => x.Code == en.SchoolyearCode.Trim()).SingleOrDefault();
  543. if (schoolyear == null)
  544. {
  545. errCount++;
  546. errorMsgStr = "学年学期不存在,请检查";
  547. en.ErrorMessage = errorMsgStr;
  548. errList.Add(en);
  549. errorMsg.AppendLine(errorMsgStr);
  550. continue;
  551. }
  552. else
  553. {
  554. newLevelScore.SchoolyearID = schoolyear.SchoolyearID;
  555. }
  556. }
  557. //考试日期
  558. if (string.IsNullOrWhiteSpace(en.ExaminationDateStr))
  559. {
  560. errCount++;
  561. errorMsgStr = "考试日期不能为空";
  562. en.ErrorMessage = errorMsgStr;
  563. errList.Add(en);
  564. errorMsg.AppendLine(errorMsgStr);
  565. continue;
  566. }
  567. else
  568. {
  569. //reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28
  570. if (!DateTime.TryParse(en.ExaminationDateStr, out result))
  571. {
  572. errCount++;
  573. errorMsgStr = "考试日期格式不正确,请检查";
  574. en.ErrorMessage = errorMsgStr;
  575. errList.Add(en);
  576. errorMsg.AppendLine(errorMsgStr);
  577. continue;
  578. }
  579. else
  580. {
  581. newLevelScore.ExaminationDate = Convert.ToDateTime(en.ExaminationDateStr);
  582. }
  583. }
  584. //成绩单编号
  585. if (string.IsNullOrWhiteSpace(en.ScoreNo))
  586. {
  587. //不考虑
  588. }
  589. else
  590. {
  591. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  592. if (!reg.IsMatch(en.ScoreNo))
  593. {
  594. errCount++;
  595. errorMsgStr = "成绩单编号格式不正确,请检查(数字或英文字母)";
  596. en.ErrorMessage = errorMsgStr;
  597. errList.Add(en);
  598. errorMsg.AppendLine(errorMsgStr);
  599. continue;
  600. }
  601. else
  602. {
  603. newLevelScore.ScoreNo = en.ScoreNo.Trim();
  604. }
  605. }
  606. //总成绩
  607. if (string.IsNullOrEmpty(en.TotalScoreStr))
  608. {
  609. errCount++;
  610. errorMsgStr = "总成绩不能为空";
  611. en.ErrorMessage = errorMsgStr;
  612. errList.Add(en);
  613. errorMsg.AppendLine(errorMsgStr);
  614. continue;
  615. }
  616. else
  617. {
  618. if (!Decimal.TryParse(en.TotalScoreStr.Trim(), out isDecimal))
  619. {
  620. errCount++;
  621. errorMsgStr = "总成绩格式不正确,请检查";
  622. en.ErrorMessage = errorMsgStr;
  623. errList.Add(en);
  624. errorMsg.AppendLine(errorMsgStr);
  625. continue;
  626. }
  627. else
  628. {
  629. newLevelScore.TotalScore = Convert.ToDecimal(en.TotalScoreStr.Trim());
  630. }
  631. }
  632. //备注
  633. if (string.IsNullOrWhiteSpace(en.Remark))
  634. {
  635. //不考虑
  636. }
  637. else
  638. {
  639. newLevelScore.Remark = en.Remark;
  640. }
  641. //数据表重复性验证(用户ID、考试科目ID、考试日期唯一)
  642. var levelScoreVerify = levelScoreList.Where(x => x.UserID == newLevelScore.UserID && x.ExaminationSubjectID == newLevelScore.ExaminationSubjectID && x.ExaminationDate.ToStringEx("yyyyMM") == newLevelScore.ExaminationDate.ToStringEx("yyyyMM")).SingleOrDefault();
  643. if (levelScoreVerify == null)
  644. {
  645. //新增
  646. if (!levelScoreInList.Any(x => x.UserID == newLevelScore.UserID && x.ExaminationSubjectID == newLevelScore.ExaminationSubjectID && x.ExaminationDate.ToStringEx("yyyyMM") == newLevelScore.ExaminationDate.ToStringEx("yyyyMM")))
  647. {
  648. newLevelScore.LevelScoreID = Guid.NewGuid();
  649. newLevelScore.ApprovalStatus = correctEndStatusID;
  650. SetNewStatus(newLevelScore);
  651. levelScoreInList.Add(newLevelScore);
  652. inCount++;
  653. }
  654. else
  655. {
  656. //Excel表重复性验证
  657. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  658. inCount++;
  659. }
  660. }
  661. else
  662. {
  663. //更新(Excel有重复时,以最后一条记录的更新为准)
  664. levelScoreVerify.SchoolyearID = newLevelScore.SchoolyearID;
  665. levelScoreVerify.ScoreNo = newLevelScore.ScoreNo;
  666. levelScoreVerify.TotalScore = newLevelScore.TotalScore;
  667. levelScoreVerify.Remark = newLevelScore.Remark;
  668. SetModifyStatus(levelScoreVerify);
  669. levelScoreUpList.Add(levelScoreVerify);
  670. upCount++;
  671. }
  672. }
  673. using (TransactionScope ts = new TransactionScope())
  674. {
  675. UnitOfWork.BulkInsert(levelScoreInList);
  676. if (levelScoreUpList != null && levelScoreUpList.Count() > 0)
  677. {
  678. UnitOfWork.BatchUpdate(levelScoreUpList);
  679. }
  680. ts.Complete();
  681. }
  682. errdataList = errList.Distinct().ToList();
  683. }
  684. catch (Exception)
  685. {
  686. throw;
  687. }
  688. }
  689. /// <summary>
  690. /// 流程结束跳转函数(工作流平台中配置)
  691. /// </summary>
  692. /// <param name="levelScoreIDList"></param>
  693. /// <param name="userID"></param>
  694. public void OnApproveEnd(List<Guid> levelScoreIDList, Guid? userID)
  695. {
  696. throw new NotImplementedException();
  697. }
  698. }
  699. }