ExaminationScoreServices.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. 
  2. using Bowin.Common.Linq.Entity;
  3. using EMIS.DataLogic.ScoreManage;
  4. using EMIS.Entities;
  5. using EMIS.ViewModel;
  6. using EMIS.ViewModel.ScoreManage;
  7. using System;
  8. using Bowin.Common.Linq;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Linq.Expressions;
  12. using System.Text;
  13. using Bowin.Common.Utility;
  14. using System.Data;
  15. using EMIS.DataLogic.Common.Students;
  16. using EMIS.Utility;
  17. using System.Web;
  18. using System.IO;
  19. using System.Web.Mvc;
  20. using EMIS.DataLogic.ExamManage;
  21. using System.Transactions;
  22. using EMIS.DataLogic.Repositories;
  23. using System.Threading;
  24. using System.Globalization;
  25. namespace EMIS.CommonLogic.ScoreManage
  26. {
  27. public class ExaminationScoreServices:BaseServices, IExaminationScoreServices
  28. {
  29. public LevelSettingSubjectDAL levelSettingSubjectDAL { get; set; }
  30. public ExaminationScoreDAL examinationScoreDAL { get; set; }
  31. public StudentsDAL studentsDAL { get; set; }
  32. public ExaminationRegistrationRepository examinationRegistrationRepository { get; set; }
  33. public ExaminationProjectFeeTypeRepository examinationProjectFeeTypeRepository { get; set; }
  34. public LevelSettingRepository levelSettingRepository { get; set; }
  35. public LevelSettingSubjectRepository levelSettingSubjectRepository { get; set; }
  36. public ExaminationProjectRepository examinationProjectRepository { get; set; }
  37. public ProjectFeeDAL ProjectFeeDAL { get; set; }
  38. public IGridResultSet<ExaminationScoreView> GetExaminationScoreViewGrid(ConfiguretView configuretView, Guid? schoolYearID, Guid? examinationBatchID,
  39. Guid? examinationTypeID, Guid? examinationProjectID, int? campusID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID,
  40. int pageIndex, int pageSize)
  41. {
  42. Expression<Func<ER_ExaminationScore, bool>> esexp = x => true;
  43. Expression< Func < EX_ExaminationBatchProject, bool>> ebrexp = x => true;
  44. Expression<Func<EX_ExaminationBatch, bool>> ebexp = x => true;
  45. Expression<Func<EX_ExaminationProject, bool>> epexp = x => true;
  46. Expression<Func<CF_Classmajor, bool>> claexp = x => true;
  47. Expression< Func < CF_Grademajor, bool>> graexp = x => true;
  48. Expression<Func<CF_Facultymajor, bool>> facexp = x => true;
  49. Expression< Func < CF_College, bool>> colexp = x => true;
  50. if (schoolYearID.HasValue)
  51. ebexp = ebexp.And(x => x.SchoolyearID == schoolYearID);
  52. if (examinationBatchID.HasValue)
  53. ebrexp = ebrexp.And(x => x.ExaminationBatchID == examinationBatchID);
  54. if (examinationTypeID.HasValue)
  55. epexp = epexp.And(x => x.ExaminationTypeID == examinationTypeID);
  56. if (examinationProjectID.HasValue)
  57. ebrexp = ebrexp.And(x => x.ExaminationProjectID == examinationProjectID);
  58. if (campusID.HasValue)
  59. graexp = graexp.And(x => x.SchoolAreaID == campusID);
  60. if (collegeID.HasValue)
  61. colexp = colexp.And(x => x.CollegeID == collegeID);
  62. if (year.HasValue)
  63. graexp = graexp.And(x => x.SchoolyearID == year);
  64. if (standardID.HasValue)
  65. facexp = facexp.And(x => x.StandardID == standardID);
  66. if (classmajorID.HasValue)
  67. claexp = claexp.And(x => x.ClassmajorID == classmajorID);
  68. var query = examinationScoreDAL.GetExaminationScoreView(esexp, ebrexp, ebexp, epexp, claexp, graexp, facexp, colexp);
  69. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  70. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  71. return this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExaminationBatchID).ThenBy(x => x.ExaminationTypeID).ThenBy(x => x.ExaminationProjectID)
  72. .ThenBy(x => x.ExaminationSubjectID).ThenByDescending(x => x.SchoolyearNumID).ThenBy(x => x.CollegeID).ThenBy(x => x.StandardID).ThenBy(x => x.ClassmajorID)
  73. .ThenBy(x => x.StudentNo).ToGridResultSet<ExaminationScoreView>(pageIndex, pageSize);
  74. }
  75. public List<ExaminationScoreView> GetExaminationScoreViewList(ConfiguretView configuretView, Guid? schoolYearID, Guid? examinationBatchID,
  76. Guid? examinationTypeID, Guid? examinationProjectID, int? campusID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID,
  77. List<Guid?> idList)
  78. {
  79. Expression<Func<ER_ExaminationScore, bool>> esexp = x => true;
  80. Expression<Func<EX_ExaminationBatchProject, bool>> ebrexp = x => true;
  81. Expression<Func<EX_ExaminationBatch, bool>> ebexp = x => true;
  82. Expression<Func<EX_ExaminationProject, bool>> epexp = x => true;
  83. Expression<Func<CF_Classmajor, bool>> claexp = x => true;
  84. Expression<Func<CF_Grademajor, bool>> graexp = x => true;
  85. Expression<Func<CF_Facultymajor, bool>> facexp = x => true;
  86. Expression<Func<CF_College, bool>> colexp = x => true;
  87. if (schoolYearID.HasValue)
  88. ebexp = ebexp.And(x => x.SchoolyearID == schoolYearID);
  89. if (examinationBatchID.HasValue)
  90. ebrexp = ebrexp.And(x => x.ExaminationBatchID == examinationBatchID);
  91. if (examinationTypeID.HasValue)
  92. epexp = epexp.And(x => x.ExaminationTypeID == examinationTypeID);
  93. if (examinationProjectID.HasValue)
  94. ebrexp = ebrexp.And(x => x.ExaminationProjectID == examinationProjectID);
  95. if (campusID.HasValue)
  96. graexp = graexp.And(x => x.SchoolAreaID == campusID);
  97. if (collegeID.HasValue)
  98. colexp = colexp.And(x => x.CollegeID == collegeID);
  99. if (year.HasValue)
  100. graexp = graexp.And(x => x.SchoolyearID == year);
  101. if (standardID.HasValue)
  102. facexp = facexp.And(x => x.StandardID == standardID);
  103. if (classmajorID.HasValue)
  104. claexp = claexp.And(x => x.ClassmajorID == classmajorID);
  105. if (idList.Count > 0)
  106. {
  107. esexp = esexp.And(x => idList.Contains(x.ExaminationScoreID));
  108. }
  109. var query = examinationScoreDAL.GetExaminationScoreView(esexp, ebrexp, ebexp, epexp, claexp, graexp, facexp, colexp);
  110. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  111. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  112. return query.OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExaminationBatchID).ThenBy(x => x.ExaminationTypeID).ThenBy(x => x.ExaminationProjectID)
  113. .ThenBy(x => x.ExaminationSubjectID).ThenByDescending(x => x.SchoolyearNumID).ThenBy(x => x.CollegeID).ThenBy(x => x.StandardID).ThenBy(x => x.ClassmajorID)
  114. .ThenBy(x => x.StudentNo).ToList();
  115. }
  116. public ExaminationScoreView GetExaminationScoreView(Guid? examinationScoreID)
  117. {
  118. try
  119. {
  120. var examinationScoreView = examinationScoreDAL.GetExaminationScoreView(x => x.ExaminationScoreID == examinationScoreID, x => true, x => true, x => true, x => true, x => true, x => true, x => true).FirstOrDefault();
  121. return examinationScoreView;
  122. }
  123. catch (Exception)
  124. {
  125. throw;
  126. }
  127. }
  128. public void Edit(ExaminationScoreView examinationScoreView)
  129. {
  130. try
  131. {
  132. var ExaminationBatchProject = examinationScoreDAL.examinationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchID == examinationScoreView.ExaminationBatchID && x.ExaminationProjectID == examinationScoreView.ExaminationProjectID).FirstOrDefault();
  133. var user = examinationScoreDAL.studentRepository.Entities.Where(x => x.UserID == examinationScoreView.UserID).FirstOrDefault();
  134. var examinationRegistration = examinationRegistrationRepository.Entities.Where(x => x.ExaminationBatchProjectID == ExaminationBatchProject.ExaminationBatchProjectID && x.UserID == examinationScoreView.UserID).FirstOrDefault();
  135. if (examinationRegistration == null)
  136. {
  137. throw new Exception("该学生尚未报名该项目");
  138. }
  139. var examinationProjectFeeType = examinationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == examinationRegistration.ExaminationProjectFeeTypeID).FirstOrDefault();
  140. //var levelSettingList = levelSettingRepository.Entities.Where(x => x.ExaminationProjectID == examinationScoreView.ExaminationProjectID).ToList();
  141. //var passline = levelSettingList.FirstOrDefault(x => x.IsPassLine.Value);
  142. //if (passline == null)
  143. //{
  144. // throw new Exception("该项目未设置及格线");
  145. //}
  146. //var levelSettingSubject = levelSettingSubjectRepository.Entities.Where(x => x.LevelSettingID == passline.LevelSettingID && x.ExaminationSubjectID == examinationScoreView.ExaminationSubjectID).FirstOrDefault();
  147. // if (examinationScoreView.Score >= levelSettingSubject.PassScore && examinationScoreView.Expire == null)
  148. // {
  149. // throw new Exception("分数已经达到及格线,有效期必须填值");
  150. // }
  151. // else if(examinationScoreView.Score < levelSettingSubject.PassScore && examinationScoreView.Expire != null)
  152. // {
  153. // throw new Exception("分数未达到及格线,有效期不需要填值");
  154. // }
  155. if (ExaminationBatchProject == null)
  156. {
  157. throw new Exception("找不到对应的批次项目");
  158. }
  159. if (user == null)
  160. {
  161. throw new Exception("系统不存在该学生,请核实");
  162. }
  163. if (examinationScoreView.ExaminationScoreID.HasValue && examinationScoreView.ExaminationScoreID != Guid.Empty)
  164. {
  165. var examinationScore = examinationScoreDAL.examinationScoreRepository.Entities.Where(x => x.ExaminationScoreID == examinationScoreView.ExaminationScoreID).FirstOrDefault();
  166. if (examinationScore == null)
  167. {
  168. throw new Exception("该项目成绩已经不存在");
  169. }
  170. examinationScore.ExaminationBatchProjectID = ExaminationBatchProject.ExaminationBatchProjectID;
  171. examinationScore.UserID = user.UserID;
  172. examinationScore.ExaminationSubjectID = examinationScoreView.ExaminationSubjectID;
  173. examinationScore.Score = examinationScoreView.Score;
  174. examinationScore.Expire = examinationScoreView.Expire;
  175. examinationScore.Remark = examinationScoreView.Remark;
  176. examinationScore.IsResit = examinationProjectFeeType.IsResit;
  177. SetModifyStatus(examinationScore);
  178. UnitOfWork.Commit();
  179. }
  180. else
  181. {
  182. ER_ExaminationScore examinationScore = new ER_ExaminationScore();
  183. examinationScore.ExaminationScoreID = Guid.NewGuid();
  184. examinationScore.ExaminationBatchProjectID = ExaminationBatchProject.ExaminationBatchProjectID;
  185. examinationScore.UserID = user.UserID;
  186. examinationScore.ExaminationSubjectID = examinationScoreView.ExaminationSubjectID;
  187. examinationScore.Score = examinationScoreView.Score;
  188. examinationScore.Expire = examinationScoreView.Expire;
  189. examinationScore.Remark = examinationScoreView.Remark;
  190. examinationScore.IsResit = examinationProjectFeeType.IsResit;
  191. SetNewStatus(examinationScore);
  192. UnitOfWork.Add(examinationScore);
  193. UnitOfWork.Commit();
  194. }
  195. }
  196. catch (Exception)
  197. {
  198. throw;
  199. }
  200. }
  201. public void Delete(List<Guid?> ExaminationScoreIDList)
  202. {
  203. try
  204. {
  205. if (examinationScoreDAL.resitRepository.Entities.Any(x => ExaminationScoreIDList.Contains(x.ExaminationScoreID)))
  206. {
  207. throw new Exception("选择要删除的数据存在对应的补考名单,无法删除");
  208. }
  209. if (examinationScoreDAL.GetProjectScoreByExaminationScore(x => ExaminationScoreIDList.Contains(x.ExaminationScoreID)).Any())
  210. {
  211. throw new Exception("选择要删除的数据存在对应的认定成绩,无法删除");
  212. }
  213. UnitOfWork.Delete<ER_ExaminationScore>(x => ExaminationScoreIDList.Contains(x.ExaminationScoreID));
  214. }
  215. catch (Exception)
  216. {
  217. throw;
  218. }
  219. }
  220. public void Import(Dictionary<string, string> cellheader, out int OkCount, out DataTable errdataList, out int ErrCount, DataTable dt, string sourcePhysicalPath,
  221. Guid? schoolyearID, Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID)
  222. {
  223. DataTable errdt = dt.Clone();
  224. //errdt.Rows.RemoveAt(0);
  225. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  226. var result = new ExcelImportResult();
  227. var excel = new NpoiExcelHelper();
  228. var errorTable = new DataTable();
  229. List<ExaminationScoreView> errList = new List<ExaminationScoreView>();
  230. cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要
  231. // 1.1解析文件,存放到一个List集合里
  232. List <ExaminationScoreView> enlist =
  233. NpoiExcelHelper.ExcelToEntityList<ExaminationScoreView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  234. Expression<Func<CF_Student, bool>> filter = x => true;
  235. List<ER_ExaminationScore> insertList = new List<ER_ExaminationScore>();
  236. var subjectList = this.GetSubjectByProject(examinationProjectID);
  237. var inSchoolStatusIDList = studentsDAL.InSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(w => w.InSchoolStatusID).ToList();
  238. //filter = filter.And(x => inSchoolStatusIDList.Contains(x.InSchoolStatusID));读取所有学生
  239. //节省点网络传输……
  240. var studentIDNumberList = enlist.Select(x => (x.IDNumber ?? "").Trim()).ToList();
  241. filter = filter.And(x => studentIDNumberList.Contains(x.IDNumber));
  242. var studentList = studentsDAL.GetInSchoolStudentViewQueryable(filter).ToList();
  243. var schoolYearList = examinationScoreDAL.schoolyearRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  244. var ExaminationBatchProjectList = examinationScoreDAL.examinationBatchProjectRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE, x => x.EX_ExaminationBatch, x => x.EX_ExaminationProject).ToList();
  245. var ExaminationSubjectList = levelSettingSubjectDAL.dictionaryItemRepository.GetList(x => x.DictionaryCode == "EX_ExaminationSubject").ToList();
  246. var ExaminationScoreList = examinationScoreDAL.GetExaminationScoreView(x => true, x => true, x => true, x => true, x => true, x => true, x => true, x => true).ToList();
  247. var examinationRegistrationList = examinationRegistrationRepository.Entities.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  248. var examinationProjectFeeTypeList = examinationProjectFeeTypeRepository.Entities.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  249. var examinationProjectList = examinationProjectRepository.Entities.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  250. var levelSettingList = levelSettingRepository.Entities.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  251. var levelSettingSubjectList = levelSettingSubjectRepository.Entities.Where(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
  252. cellheader.Add("ErrorMessage", "错误信息");
  253. cellheader.ForEach(x => errorTable.Columns.Add(x.Value));
  254. if (enlist.Count() <= 0)
  255. {
  256. throw new Exception("请填写Excel模板信息数据。");
  257. }
  258. errdt.Clear();
  259. errdt.Columns.Add("错误信息");
  260. dt.Columns.Add("错误信息");
  261. for (int i = 0; i < enlist.Count(); i++)
  262. {
  263. var rows = dt.Rows[i + 1];
  264. string errorMsgStr = "第" + (i + 1) + "行数据检测异常:";
  265. ExaminationScoreView en = enlist[i];
  266. bool isHaveNoInputValue = false;
  267. en.IsExcelVaildateOK = true;
  268. Type enType = en.GetType();
  269. Dictionary<int?, decimal?> dic = new Dictionary<int?, decimal?>();
  270. int? subjectNotScoreCount = 0;
  271. #region 检查是否有未填的值
  272. if (string.IsNullOrEmpty(en.SchoolyearCode))
  273. {
  274. errorMsgStr += "学年学期不能为空;";
  275. isHaveNoInputValue = true;
  276. }
  277. if (string.IsNullOrEmpty(en.ExaminationBatchName))
  278. {
  279. errorMsgStr += "考试批次不能为空;";
  280. isHaveNoInputValue = true;
  281. }
  282. if (string.IsNullOrEmpty(en.ExaminationProjectName))
  283. {
  284. errorMsgStr += "考试项目不能为空;";
  285. isHaveNoInputValue = true;
  286. }
  287. if (string.IsNullOrEmpty(en.IDNumber.Trim()))
  288. {
  289. errorMsgStr += "证件号不能为空;";
  290. isHaveNoInputValue = true;
  291. }
  292. foreach (var subject in subjectList)
  293. {
  294. dic.Add(subject.ExaminationSubjectID,dt.Rows[i+1][subject.ExaminationSubject].ToString().ParseStrTo<decimal>());
  295. en.ExaminationSubjectIDAndScore = dic;
  296. //foreach (var pi in enType.GetProperties())
  297. //{
  298. // if (pi.Name == subject.SubjectCode)
  299. // {
  300. // if (pi.GetValue(en, null) == null || pi.GetValue(en, null).ToString() == "")
  301. // {
  302. // subjectNotScoreCount++;
  303. // //errorMsgStr += subject.ExaminationSubject + "的成绩不能为空;";
  304. // //isHaveNoInputValue = true;
  305. // dic.Add(subject.ExaminationSubjectID, null);
  306. // }
  307. // else
  308. // {
  309. // dic.Add(subject.ExaminationSubjectID, decimal.Parse(pi.GetValue(en, null).ToString()));
  310. // }
  311. // en.ExaminationSubjectIDAndScore = dic;
  312. // }
  313. //}
  314. }
  315. if (subjectNotScoreCount == subjectList.Count)
  316. {
  317. errorMsgStr += "成绩不能为空;";
  318. isHaveNoInputValue = true;
  319. }
  320. if (!string.IsNullOrEmpty(en.ExpireImport))
  321. {
  322. try
  323. {
  324. DateTime date;
  325. IFormatProvider ifp = new CultureInfo("zh-CN", true);
  326. var expire = en.ExpireImport.Replace("/", "-");
  327. //if (expire.IndexOf("-") == -1)
  328. //{
  329. // expireDate = DateTime.ParseExact(expire, "yyyyMMdd", Thread.CurrentThread.CurrentCulture);
  330. //}
  331. if (DateTime.TryParse(expire, out date))
  332. {
  333. en.Expire = Convert.ToDateTime(en.ExpireImport);
  334. }
  335. else if (DateTime.TryParseExact(expire, "yyyyMMdd", ifp, DateTimeStyles.None, out date))
  336. {
  337. en.Expire = DateTime.ParseExact(expire, "yyyyMMdd", Thread.CurrentThread.CurrentCulture);
  338. }
  339. else
  340. {
  341. en.Expire = DateTime.FromOADate(double.Parse(expire.Trim().ToString()));
  342. }
  343. }
  344. catch
  345. {
  346. errorMsgStr += "有效期格式不正确;";
  347. isHaveNoInputValue = true;
  348. }
  349. }
  350. #endregion
  351. #region 检查数据是否存在
  352. if (!schoolYearList.Any(x => x.Code == en.SchoolyearCode))
  353. {
  354. errorMsgStr += "学年学期不存在;";
  355. isHaveNoInputValue = true;
  356. }
  357. else {
  358. en.SchoolyearID = schoolYearList.FirstOrDefault(x => x.Code == en.SchoolyearCode).SchoolyearID;
  359. }
  360. if (!ExaminationBatchProjectList.Any(x => x.EX_ExaminationBatch.Name == en.ExaminationBatchName && x.EX_ExaminationProject.Name == en.ExaminationProjectName && x.EX_ExaminationBatch.SchoolyearID == en.SchoolyearID))
  361. {
  362. errorMsgStr += "考试批次项目不存在;";
  363. isHaveNoInputValue = true;
  364. }
  365. else{
  366. en.ExaminationBatchProjectID = ExaminationBatchProjectList.FirstOrDefault(x => x.EX_ExaminationBatch.Name == en.ExaminationBatchName && x.EX_ExaminationProject.Name == en.ExaminationProjectName && x.EX_ExaminationBatch.SchoolyearID == en.SchoolyearID).ExaminationBatchProjectID;
  367. en.ExaminationProjectID = examinationProjectList.FirstOrDefault(x => x.Name == en.ExaminationProjectName).ExaminationProjectID;
  368. }
  369. if (!studentList.Any(x => x.IDNumber.ToLower() == en.IDNumber.Trim().ToLower()))
  370. {
  371. errorMsgStr += "学生不存在;";
  372. isHaveNoInputValue = true;
  373. }
  374. else{
  375. en.UserID = studentList.FirstOrDefault(x => x.IDNumber.ToLower() == en.IDNumber.Trim().ToLower()).UserID;
  376. }
  377. #endregion
  378. foreach (var examinationSubjectID in en.ExaminationSubjectIDAndScore.Keys)
  379. {
  380. //if(en.ExaminationSubjectIDAndScore[examinationSubjectID].HasValue)
  381. //{
  382. if (en.ExaminationSubjectIDAndScore[examinationSubjectID].HasValue && ExaminationScoreList.Any(x => x.ExaminationBatchProjectID == en.ExaminationBatchProjectID && x.ExaminationSubjectID == examinationSubjectID
  383. && x.UserID == en.UserID))
  384. {
  385. errorMsgStr += "该学生 考试项目“" + en.ExaminationProjectName + "” 科目考核项“" + ExaminationSubjectList.FirstOrDefault(x => x.Value == examinationSubjectID).Name + "”的成绩已存在;";
  386. isHaveNoInputValue = true;
  387. }
  388. //}
  389. }
  390. //if (ExaminationScoreList.Any(x => x.ExaminationBatchProjectID == en.ExaminationBatchProjectID && x.ExaminationSubjectID == en.ExaminationSubjectID
  391. // && x.UserID == en.UserID))
  392. //{
  393. // errorMsgStr += "该学生 考试项目“" + en.ExaminationProjectName + "” 科目考核项“" + en.ExaminationSubjectName + "”的成绩已存在;";
  394. // isHaveNoInputValue = true;
  395. //}
  396. var examinationRegistration = examinationRegistrationList.Where(x => x.ExaminationBatchProjectID == en.ExaminationBatchProjectID && x.UserID == en.UserID).FirstOrDefault();
  397. var examinationProjectFeeType = examinationProjectFeeTypeList.FirstOrDefault();
  398. if (examinationRegistration == null)
  399. {
  400. errorMsgStr += "该学生尚未报名该项目,无法录入成绩;";
  401. isHaveNoInputValue = true;
  402. }
  403. else
  404. {
  405. examinationProjectFeeType = examinationProjectFeeTypeList.Where(x => x.ExaminationProjectFeeTypeID == examinationRegistration.ExaminationProjectFeeTypeID).FirstOrDefault();
  406. }
  407. //var checkLevelSettingList = levelSettingList.Where(x => x.ExaminationProjectID == en.ExaminationProjectID).ToList();
  408. //var passLineSetting = checkLevelSettingList.FirstOrDefault(x => x.IsPassLine.Value);
  409. //if (passLineSetting == null)
  410. //{
  411. // errorMsgStr += "该项目没有设置及格线";
  412. // isHaveNoInputValue = true;
  413. //}
  414. //else {
  415. // var passScore = levelSettingSubjectList.Where(x => x.LevelSettingID == passLineSetting.LevelSettingID && x.ExaminationSubjectID == en.ExaminationSubjectID).FirstOrDefault();
  416. // if (en.Score >= passScore.PassScore && en.Expire == null)
  417. // {
  418. // errorMsgStr += "分数已经达到及格线,有效期必须填值;";
  419. // isHaveNoInputValue = true;
  420. // }
  421. // else if (en.Score < passScore.PassScore && en.Expire != null)
  422. // {
  423. // errorMsgStr += "分数未达到及格线,有效期不需要填值;";
  424. // isHaveNoInputValue = true;
  425. // }
  426. //}
  427. if (isHaveNoInputValue)
  428. {
  429. en.IsExcelVaildateOK = false;
  430. en.ErrorMessage = errorMsgStr;
  431. rows["错误信息"] = errorMsgStr;
  432. errdt.Rows.Add(rows.ItemArray);
  433. errList.Add(en);
  434. }
  435. else{
  436. //enlist[i].IsExcelVaildateOK = true;
  437. foreach(var score in en.ExaminationSubjectIDAndScore)
  438. {
  439. if(score.Value.HasValue)
  440. {
  441. ER_ExaminationScore examinationScore = new ER_ExaminationScore();
  442. examinationScore.ExaminationScoreID = Guid.NewGuid();
  443. examinationScore.ExaminationBatchProjectID = en.ExaminationBatchProjectID;
  444. examinationScore.ExaminationSubjectID = score.Key;
  445. examinationScore.UserID = en.UserID;
  446. examinationScore.Score = score.Value;
  447. examinationScore.Expire = en.Expire;
  448. examinationScore.Remark = en.Remark;
  449. examinationScore.IsResit = examinationProjectFeeType.IsResit;
  450. SetNewStatus(examinationScore);
  451. if (examinationScore != null)
  452. {
  453. insertList.Add(examinationScore);
  454. }
  455. }
  456. }
  457. }
  458. }
  459. ErrCount = errList.Distinct().Count();
  460. // errdt.Rows.RemoveAt(0);
  461. errdataList = errdt;
  462. //errList.Distinct().ToList();
  463. OkCount = insertList.Count;
  464. //if (ErrCount > 0)
  465. //{
  466. // errList.ForEach(x => errorTable.Rows.Add(x));
  467. // var errorCellHeader = cellheader;
  468. //}
  469. //else
  470. //{
  471. using (TransactionScope ts = new TransactionScope())
  472. {
  473. //批量插入
  474. UnitOfWork.BulkInsert(insertList);
  475. ts.Complete();
  476. }
  477. //}
  478. }
  479. private string WriteErrorFile(NpoiExcelHelper excel, IEnumerable<string> errorCellheader, DataTable errorTable)
  480. {
  481. var errorExcelBuff = excel.ExportMemoryStream(errorTable, "", errorCellheader.ToArray());
  482. var logicalPath = Const.LOCAL_SETTING_UPLOAD_FILEPATH + "/" + Guid.NewGuid().ToString() + ".xls";
  483. var physicalPath = HttpContext.Current.Server.MapPath(logicalPath);
  484. var fs = File.Create(physicalPath);
  485. fs.Write(errorExcelBuff, 0, errorExcelBuff.Length);
  486. fs.Flush();
  487. fs.Close();
  488. return UrlHelper.GenerateContentUrl(logicalPath, HttpContext.Current.Request.RequestContext.HttpContext);
  489. }
  490. public List<ExaminationProjectSubjectView> GetSubjectByProject(Guid? examinationProjectID)
  491. {
  492. Expression<Func<EX_ExaminationProjectSubject, bool>> exp = (x => x.RecordStatus > (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE);
  493. if (examinationProjectID.HasValue)
  494. {
  495. exp = exp.And(x => x.ExaminationProjectID == examinationProjectID);
  496. }
  497. var query = ProjectFeeDAL.GetProjectSubjectList(exp).GroupBy(x => x.ExaminationSubjectID).Select(x => x.FirstOrDefault());
  498. return query.OrderBy(x => x.ExaminationSubjectID).ToList();
  499. }
  500. public IGridResultSet<ExaminationProjectSubjectView> GetSubjectByProjectGrid(ConfiguretView configuretView, Guid? examinationProjectID, int pageIndex, int pageSize)
  501. {
  502. Expression<Func<EX_ExaminationProjectSubject, bool>> exp = (x => x.RecordStatus > (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE);
  503. if (examinationProjectID.HasValue)
  504. {
  505. exp = exp.And(x => x.ExaminationProjectID == examinationProjectID);
  506. }
  507. var query = ProjectFeeDAL.GetProjectSubjectList(exp).GroupBy(x => x.ExaminationSubjectID).Select(x => x.FirstOrDefault());
  508. return query.OrderBy(x => x.ExaminationSubjectID).ToGridResultSet<ExaminationProjectSubjectView>(pageIndex, pageSize);
  509. }
  510. public IQueryable<ExaminationProjectSubjectView> GetSubjectByProjectList(params EMIS.ViewModel.ConfiguretView[] configuretViews)
  511. {
  512. Expression<Func<EX_ExaminationProjectSubject, bool>> exp = (x => x.RecordStatus > (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE);
  513. var query = ProjectFeeDAL.GetProjectSubjectList(exp);
  514. //查询条件
  515. foreach (var configuretView in configuretViews)
  516. {
  517. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  518. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  519. }
  520. return query
  521. .OrderBy(x => x.ExaminationProjectID).AsQueryable();
  522. }
  523. }
  524. }