CoursematerialServices.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Text.RegularExpressions;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using Bowin.Common.Exceptions;
  10. using Bowin.Common.Utility;
  11. using EMIS.Entities;
  12. using EMIS.ViewModel;
  13. using EMIS.ViewModel.CacheManage;
  14. using EMIS.ViewModel.Cultureplan;
  15. using EMIS.DataLogic.Repositories;
  16. using EMIS.DataLogic.Common.Cultureplan;
  17. using EMIS.CommonLogic.EducationManagement;
  18. namespace EMIS.CommonLogic.Cultureplan
  19. {
  20. public class CoursematerialServices : BaseServices, ICoursematerialServices
  21. {
  22. public CoursematerialDAL CoursematerialDAL { get; set; }
  23. /// <summary>
  24. /// 查询课程信息CoursematerialView
  25. /// </summary>
  26. /// <param name="configuretView"></param>
  27. /// <param name="courseLevelID"></param>
  28. /// <param name="courseScienceID"></param>
  29. /// <param name="classGroupingID"></param>
  30. /// <param name="isEnable"></param>
  31. /// <param name="pageIndex"></param>
  32. /// <param name="pageSize"></param>
  33. /// <returns></returns>
  34. public IGridResultSet<CoursematerialView> GetCoursematerialViewGrid(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID,
  35. Guid? classGroupingID, int? isEnable, int pageIndex, int pageSize)
  36. {
  37. //课程信息
  38. Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  39. if (courseLevelID.HasValue)
  40. {
  41. exp = exp.And(x => x.CourseLevelID == courseLevelID);
  42. }
  43. if (courseScienceID.HasValue)
  44. {
  45. exp = exp.And(x => x.CourseScienceID == courseScienceID);
  46. }
  47. if (classGroupingID.HasValue)
  48. {
  49. exp = exp.And(x => x.ClassGroupingID == classGroupingID);
  50. }
  51. if (isEnable.HasValue)
  52. {
  53. if (isEnable == 1)
  54. {
  55. exp = exp.And(x => x.IsEnable == true);
  56. }
  57. if (isEnable == 0)
  58. {
  59. exp = exp.And(x => x.IsEnable != true);
  60. }
  61. }
  62. var query = CoursematerialDAL.GetCoursematerialViewQueryable(exp);
  63. //查询条件
  64. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  65. {
  66. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  67. }
  68. return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  69. .ToGridResultSet<CoursematerialView>(pageIndex, pageSize);
  70. }
  71. /// <summary>
  72. /// 查询课程信息List
  73. /// </summary>
  74. /// <param name="configuretView"></param>
  75. /// <param name="courseLevelID"></param>
  76. /// <param name="courseScienceID"></param>
  77. /// <param name="classGroupingID"></param>
  78. /// <param name="isEnable"></param>
  79. /// <returns></returns>
  80. public IList<CoursematerialView> GetCoursematerialViewList(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID,
  81. Guid? classGroupingID, int? isEnable)
  82. {
  83. //课程信息
  84. Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  85. if (courseLevelID.HasValue)
  86. {
  87. exp = exp.And(x => x.CourseLevelID == courseLevelID);
  88. }
  89. if (courseScienceID.HasValue)
  90. {
  91. exp = exp.And(x => x.CourseScienceID == courseScienceID);
  92. }
  93. if (classGroupingID.HasValue)
  94. {
  95. exp = exp.And(x => x.ClassGroupingID == classGroupingID);
  96. }
  97. if (isEnable.HasValue)
  98. {
  99. if (isEnable == 1)
  100. {
  101. exp = exp.And(x => x.IsEnable == true);
  102. }
  103. if (isEnable == 0)
  104. {
  105. exp = exp.And(x => x.IsEnable != true);
  106. }
  107. }
  108. var query = CoursematerialDAL.GetCoursematerialViewQueryable(exp);
  109. //查询条件
  110. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  111. {
  112. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  113. }
  114. return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ToList();
  115. }
  116. /// <summary>
  117. /// 查询课程信息CoursematerialView(启用状态为是或已使用的信息)
  118. /// </summary>
  119. /// <param name="configuretView"></param>
  120. /// <param name="coursematerialID"></param>
  121. /// <param name="isEnable"></param>
  122. /// <param name="pageIndex"></param>
  123. /// <param name="pageSize"></param>
  124. /// <returns></returns>
  125. public IGridResultSet<CoursematerialView> GetEnableAndUseCoursematerialViewGrid(ConfiguretView configuretView, Guid? coursematerialID, int? isEnable, int pageIndex, int pageSize)
  126. {
  127. //课程信息
  128. Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  129. if (isEnable.HasValue)
  130. {
  131. if (isEnable == 1)
  132. {
  133. if (coursematerialID.HasValue)
  134. {
  135. exp = exp.And(x => x.IsEnable == true || x.CoursematerialID == coursematerialID);
  136. }
  137. else
  138. {
  139. exp = exp.And(x => x.IsEnable == true);
  140. }
  141. }
  142. if (isEnable == 0)
  143. {
  144. if (coursematerialID.HasValue)
  145. {
  146. exp = exp.And(x => x.IsEnable != true || x.CoursematerialID == coursematerialID);
  147. }
  148. else
  149. {
  150. exp = exp.And(x => x.IsEnable != true);
  151. }
  152. }
  153. }
  154. var query = CoursematerialDAL.GetCoursematerialViewQueryable(exp);
  155. //查询条件
  156. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  157. {
  158. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  159. }
  160. return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  161. .ToGridResultSet<CoursematerialView>(pageIndex, pageSize);
  162. }
  163. /// <summary>
  164. /// 查询课程信息List(启用状态为是或已使用的信息)
  165. /// </summary>
  166. /// <param name="configuretView"></param>
  167. /// <param name="coursematerialID"></param>
  168. /// <param name="isEnable"></param>
  169. /// <returns></returns>
  170. public IList<CoursematerialView> GetEnableAndUseCoursematerialViewList(ConfiguretView configuretView, Guid? coursematerialID, int? isEnable)
  171. {
  172. //课程信息
  173. Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  174. if (coursematerialID.HasValue)
  175. {
  176. exp = exp.Or(x => x.CoursematerialID == coursematerialID);
  177. }
  178. if (isEnable.HasValue)
  179. {
  180. if (isEnable == 1)
  181. {
  182. exp = exp.Or(x => x.IsEnable == true);
  183. }
  184. if (isEnable == 0)
  185. {
  186. exp = exp.Or(x => x.IsEnable != true);
  187. }
  188. }
  189. var query = CoursematerialDAL.GetCoursematerialViewQueryable(exp);
  190. //查询条件
  191. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  192. {
  193. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  194. }
  195. return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ToList();
  196. }
  197. /// <summary>
  198. /// 查询对应的课程信息CoursematerialView
  199. /// </summary>
  200. /// <param name="coursematerialID"></param>
  201. /// <returns></returns>
  202. public CoursematerialView GetCoursematerialView(Guid? coursematerialID)
  203. {
  204. try
  205. {
  206. var coursematerialView = CoursematerialDAL.GetCoursematerialViewQueryable(x => x.CoursematerialID == coursematerialID).SingleOrDefault();
  207. return coursematerialView;
  208. }
  209. catch (Exception ex)
  210. {
  211. throw new Exception(ex.Message);
  212. }
  213. }
  214. /// <summary>
  215. /// 编辑(新增、修改)
  216. /// 注:个性化配置(业务主键默认为课程代码或课程名称唯一)
  217. /// </summary>
  218. /// <param name="coursematerialView"></param>
  219. public virtual void CoursematerialEdit(CoursematerialView coursematerialView)
  220. {
  221. try
  222. {
  223. //查询数据库进行验证
  224. var courseCodeVerify = CoursematerialDAL.CoursematerialRepository
  225. .GetList(x => x.CoursematerialID != coursematerialView.CoursematerialID
  226. && x.CourseCode == coursematerialView.CourseCode).SingleOrDefault();
  227. var courseNameVerify = CoursematerialDAL.CoursematerialRepository
  228. .GetList(x => x.CoursematerialID != coursematerialView.CoursematerialID
  229. && x.CourseName == coursematerialView.CourseName).FirstOrDefault();
  230. if (courseCodeVerify == null && courseNameVerify == null)
  231. {
  232. //数据有误验证
  233. if (coursematerialView.CoursematerialID != Guid.Empty)
  234. {
  235. var course = CoursematerialDAL.CoursematerialRepository
  236. .GetList(x => x.CoursematerialID == coursematerialView.CoursematerialID).SingleOrDefault();
  237. if (course == null)
  238. {
  239. throw new Exception("数据有误,请核查。");
  240. }
  241. else
  242. {
  243. //表示修改
  244. course.CourseCode = coursematerialView.CourseCode;
  245. course.CourseName = coursematerialView.CourseName;
  246. course.Abbreviation = coursematerialView.Abbreviation;
  247. course.EnglishName = coursematerialView.EnglishName;
  248. course.StandardName = coursematerialView.StandardName;
  249. course.CourseEdition = coursematerialView.CourseEdition;
  250. course.CourseLevelID = coursematerialView.CourseLevelID;
  251. course.CourseScienceID = coursematerialView.CourseScienceID;
  252. course.ClassGroupingID = coursematerialView.ClassGroupingID;
  253. course.CourseSynopsis = coursematerialView.CourseSynopsis;
  254. course.CourseReserve = coursematerialView.CourseReserve;
  255. course.IsEnable = coursematerialView.IsEnable;
  256. course.Remark = coursematerialView.Remark;
  257. SetModifyStatus(course);
  258. }
  259. }
  260. else
  261. {
  262. //表示新增
  263. var newCourse = new EM_Coursematerial();
  264. newCourse.CoursematerialID = Guid.NewGuid();
  265. newCourse.CourseCode = coursematerialView.CourseCode;
  266. newCourse.CourseName = coursematerialView.CourseName;
  267. newCourse.Abbreviation = coursematerialView.Abbreviation;
  268. newCourse.EnglishName = coursematerialView.EnglishName;
  269. newCourse.StandardName = coursematerialView.StandardName;
  270. newCourse.CourseEdition = coursematerialView.CourseEdition;
  271. newCourse.CourseLevelID = coursematerialView.CourseLevelID;
  272. newCourse.CourseScienceID = coursematerialView.CourseScienceID;
  273. newCourse.ClassGroupingID = coursematerialView.ClassGroupingID;
  274. newCourse.CourseSynopsis = coursematerialView.CourseSynopsis;
  275. newCourse.CourseReserve = coursematerialView.CourseReserve;
  276. newCourse.IsEnable = coursematerialView.IsEnable;
  277. newCourse.Remark = coursematerialView.Remark;
  278. SetNewStatus(newCourse);
  279. UnitOfWork.Add(newCourse);
  280. }
  281. //事务提交
  282. UnitOfWork.Commit();
  283. }
  284. else
  285. {
  286. if (courseCodeVerify != null && courseNameVerify != null)
  287. {
  288. throw new Exception("已存在相同的课程代码、课程名称,请核查。");
  289. }
  290. else if (courseCodeVerify != null)
  291. {
  292. throw new Exception("已存在相同的课程代码,请核查。");
  293. }
  294. else
  295. {
  296. throw new Exception("已存在相同的课程名称,请核查。");
  297. }
  298. }
  299. }
  300. catch (Exception ex)
  301. {
  302. throw new Exception(ex.Message);
  303. }
  304. }
  305. /// <summary>
  306. /// 删除
  307. /// </summary>
  308. /// <param name="coursematerialIDs"></param>
  309. /// <returns></returns>
  310. public bool CoursematerialDelete(List<Guid?> coursematerialIDs)
  311. {
  312. try
  313. {
  314. if (coursematerialIDs.Count() > 0)
  315. {
  316. UnitOfWork.Delete<EM_Coursematerial>(x => coursematerialIDs.Contains(x.CoursematerialID));
  317. }
  318. return true;
  319. }
  320. catch (Exception)
  321. {
  322. throw;
  323. }
  324. }
  325. /// <summary>
  326. /// 课程信息导入(个性化配置)
  327. /// 注:业务主键默认为课程代码或课程名称唯一
  328. /// </summary>
  329. /// <param name="cellheader"></param>
  330. /// <param name="inCount"></param>
  331. /// <param name="upCount"></param>
  332. /// <param name="errdataList"></param>
  333. /// <param name="errCount"></param>
  334. /// <param name="sourcePhysicalPath"></param>
  335. public virtual void CoursematerialImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<CoursematerialView> errdataList, out int? errCount, string sourcePhysicalPath)
  336. {
  337. try
  338. {
  339. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  340. List<CoursematerialView> errList = new List<CoursematerialView>();
  341. // 1.1解析文件,存放到一个List集合里
  342. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  343. List<CoursematerialView> enlist = NpoiExcelHelper.ExcelToEntityList<CoursematerialView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  344. cellheader.Add("ErrorMessage", "未导入原因");
  345. //对List集合进行有效性校验
  346. if (enlist.Count() <= 0)
  347. {
  348. throw new Exception("Excel文件数据为空,请检查。");
  349. }
  350. Regex reg = null; //正则表达式
  351. //DateTime result; //用于返回判断日期字段格式
  352. //bool isListPass = true; //List判断标识
  353. inCount = 0; //导入个数
  354. upCount = 0; //更新个数
  355. errCount = 0; //失败个数
  356. string errorMsgStr = ""; //错误信息
  357. List<EM_Coursematerial> newCoursematerialInList = new List<EM_Coursematerial>();
  358. List<EM_Coursematerial> newCoursematerialUpList = new List<EM_Coursematerial>();
  359. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  360. //课程信息
  361. var courseList = CoursematerialDAL.CoursematerialRepository.GetList(x => true).ToList();
  362. //课程代码
  363. var courseCodeList = enlist.Where(x => !string.IsNullOrWhiteSpace(x.CourseCode)).Select(x => x.CourseCode.Trim()).ToList();
  364. //课程名称
  365. var courseNameList = enlist.Where(x => !string.IsNullOrWhiteSpace(x.CourseName)).Select(x => x.CourseName.Trim()).ToList();
  366. //对比后的newCourseList
  367. var newCourseList = courseList.Where(x => courseCodeList.Contains(x.CourseCode) || courseNameList.Contains(x.CourseName)).ToList();
  368. //课程级别
  369. var courseLevelList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseLevel).ToList();
  370. //课程科类
  371. var courseScienceList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseScience).ToList();
  372. //上课类型信息
  373. var classGroupingList = CoursematerialDAL.ClassGroupingRepository.GetList(x => true).ToList();
  374. //上课类型
  375. var classNameList = enlist.Where(x => !string.IsNullOrWhiteSpace(x.ClassName)).Select(x => x.ClassName.Trim()).ToList();
  376. //对比后的newClassGroupingList
  377. var newClassGroupingList = classGroupingList.Where(x => classNameList.Contains(x.ClassName)).ToList();
  378. //是否启用
  379. var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList();
  380. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  381. for (int i = 0; i < enlist.Count; i++)
  382. {
  383. CoursematerialView en = enlist[i]; //Excel表数据视图
  384. EM_Coursematerial newCoursematerial = new EM_Coursematerial();
  385. //课程代码
  386. if (string.IsNullOrWhiteSpace(en.CourseCode))
  387. {
  388. errCount++;
  389. errorMsgStr = "课程代码不能为空";
  390. en.ErrorMessage = errorMsgStr;
  391. errList.Add(en);
  392. errorMsg.AppendLine(errorMsgStr);
  393. continue;
  394. }
  395. else
  396. {
  397. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  398. if (!reg.IsMatch(en.CourseCode.Trim()))
  399. {
  400. errCount++;
  401. errorMsgStr = "课程代码格式不正确,请检查(数字或英文字母)";
  402. en.ErrorMessage = errorMsgStr;
  403. errList.Add(en);
  404. errorMsg.AppendLine(errorMsgStr);
  405. continue;
  406. }
  407. else
  408. {
  409. //课程代码
  410. newCoursematerial.CourseCode = en.CourseCode.Trim();
  411. }
  412. }
  413. //课程名称
  414. if (string.IsNullOrWhiteSpace(en.CourseName))
  415. {
  416. errCount++;
  417. errorMsgStr = "课程名称不能为空";
  418. en.ErrorMessage = errorMsgStr;
  419. errList.Add(en);
  420. errorMsg.AppendLine(errorMsgStr);
  421. continue;
  422. }
  423. else
  424. {
  425. //课程名称
  426. newCoursematerial.CourseName = en.CourseName.Trim();
  427. }
  428. //课程简称
  429. if (string.IsNullOrWhiteSpace(en.Abbreviation))
  430. {
  431. //默认
  432. newCoursematerial.Abbreviation = en.CourseName.Trim();
  433. }
  434. else
  435. {
  436. newCoursematerial.Abbreviation = en.Abbreviation.Trim();
  437. }
  438. //英文名称
  439. if (string.IsNullOrWhiteSpace(en.EnglishName))
  440. {
  441. //暂不考虑
  442. }
  443. else
  444. {
  445. newCoursematerial.EnglishName = en.EnglishName.Trim();
  446. }
  447. //课程规范名
  448. if (string.IsNullOrWhiteSpace(en.StandardName))
  449. {
  450. //默认
  451. newCoursematerial.StandardName = en.CourseName.Trim();
  452. }
  453. else
  454. {
  455. newCoursematerial.StandardName = en.StandardName.Trim();
  456. }
  457. //课程版本
  458. if (string.IsNullOrWhiteSpace(en.CourseEdition))
  459. {
  460. //暂不考虑
  461. }
  462. else
  463. {
  464. newCoursematerial.CourseEdition = en.CourseEdition.Trim();
  465. }
  466. //课程级别
  467. if (string.IsNullOrWhiteSpace(en.CourseLevelStr))
  468. {
  469. //暂不考虑
  470. }
  471. else
  472. {
  473. var courseLevel = courseLevelList.Where(x => x.Name == en.CourseLevelStr.Trim()).SingleOrDefault();
  474. if (courseLevel == null)
  475. {
  476. errCount++;
  477. errorMsgStr = "课程级别不存在,请检查";
  478. en.ErrorMessage = errorMsgStr;
  479. errList.Add(en);
  480. errorMsg.AppendLine(errorMsgStr);
  481. continue;
  482. }
  483. else
  484. {
  485. //课程级别
  486. newCoursematerial.CourseLevelID = courseLevel.Value;
  487. }
  488. }
  489. //课程科类
  490. if (string.IsNullOrWhiteSpace(en.CourseScienceStr))
  491. {
  492. //暂不考虑
  493. }
  494. else
  495. {
  496. var courseScience = courseScienceList.Where(x => x.Name == en.CourseScienceStr.Trim()).SingleOrDefault();
  497. if (courseScience == null)
  498. {
  499. errCount++;
  500. errorMsgStr = "课程科类不存在,请检查";
  501. en.ErrorMessage = errorMsgStr;
  502. errList.Add(en);
  503. errorMsg.AppendLine(errorMsgStr);
  504. continue;
  505. }
  506. else
  507. {
  508. //课程科类
  509. newCoursematerial.CourseScienceID = courseScience.Value;
  510. }
  511. }
  512. //上课类型
  513. if (string.IsNullOrWhiteSpace(en.ClassName))
  514. {
  515. //暂不考虑
  516. }
  517. else
  518. {
  519. var classGrouping = newClassGroupingList.Where(x => x.ClassName == en.ClassName.Trim()).SingleOrDefault();
  520. if (classGrouping == null)
  521. {
  522. errCount++;
  523. errorMsgStr = "上课类型不存在,请检查";
  524. en.ErrorMessage = errorMsgStr;
  525. errList.Add(en);
  526. errorMsg.AppendLine(errorMsgStr);
  527. continue;
  528. }
  529. else
  530. {
  531. //上课类型ID
  532. newCoursematerial.ClassGroupingID = classGrouping.ClassGroupingID;
  533. }
  534. }
  535. //课程简介
  536. if (string.IsNullOrWhiteSpace(en.CourseSynopsis))
  537. {
  538. //暂不考虑
  539. }
  540. else
  541. {
  542. newCoursematerial.CourseSynopsis = en.CourseSynopsis.Trim();
  543. }
  544. //预修课程集
  545. if (string.IsNullOrWhiteSpace(en.CourseReserve))
  546. {
  547. //暂不考虑
  548. }
  549. else
  550. {
  551. newCoursematerial.CourseReserve = en.CourseReserve.Trim();
  552. }
  553. //是否启用
  554. if (string.IsNullOrWhiteSpace(en.IsEnableStr))
  555. {
  556. errCount++;
  557. errorMsgStr = "是否启用不能为空";
  558. en.ErrorMessage = errorMsgStr;
  559. errList.Add(en);
  560. errorMsg.AppendLine(errorMsgStr);
  561. continue;
  562. }
  563. else
  564. {
  565. var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsEnableStr.Trim()).SingleOrDefault();
  566. if (generalPurpose == null)
  567. {
  568. errCount++;
  569. errorMsgStr = "是否启用不存在,请检查";
  570. en.ErrorMessage = errorMsgStr;
  571. errList.Add(en);
  572. errorMsg.AppendLine(errorMsgStr);
  573. continue;
  574. }
  575. else
  576. {
  577. //是否启用
  578. newCoursematerial.IsEnable = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
  579. }
  580. }
  581. //备注
  582. if (string.IsNullOrWhiteSpace(en.Remark))
  583. {
  584. //不考虑
  585. }
  586. else
  587. {
  588. newCoursematerial.Remark = en.Remark.Trim();
  589. }
  590. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  591. //for (int j = i + 1; j < enlist.Count; j++)
  592. //{
  593. // CoursematerialView enA = enlist[j];
  594. // //根据Excel表中的业务主键进行去重(课程代码或课程名称唯一)
  595. // if (en.No == enA.No && en.Name == enA.Name)
  596. // {
  597. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  598. // }
  599. //}
  600. //数据表重复性验证(课程代码或课程名称唯一)
  601. var courseCodeVerify = newCourseList.Where(x => x.CourseCode == newCoursematerial.CourseCode).SingleOrDefault();
  602. var courseNameVerifyList = newCourseList.Where(x => x.CourseName == newCoursematerial.CourseName).ToList();
  603. var courseVerify = newCourseList.Where(x => x.CourseCode == newCoursematerial.CourseCode
  604. && x.CourseName == newCoursematerial.CourseName).SingleOrDefault();
  605. if (courseCodeVerify == null && courseNameVerifyList.Count() <= 0)
  606. {
  607. //新增
  608. if (!newCoursematerialInList.Any(x => x.CourseCode == newCoursematerial.CourseCode
  609. || x.CourseName == newCoursematerial.CourseName))
  610. {
  611. newCoursematerial.CoursematerialID = Guid.NewGuid();
  612. SetNewStatus(newCoursematerial);
  613. newCoursematerialInList.Add(newCoursematerial);
  614. inCount++;
  615. }
  616. else
  617. {
  618. //Excel表重复性验证
  619. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  620. inCount++;
  621. }
  622. }
  623. else
  624. {
  625. //更新(Excel有重复时,以最后一条记录的更新为准)
  626. if (courseCodeVerify != null && courseNameVerifyList.Count() > 0)
  627. {
  628. if (courseVerify == null)
  629. {
  630. errCount++;
  631. errorMsgStr = "课程代码、课程名称已存在且无法匹配(不为同一课程信息),请检查";
  632. en.ErrorMessage = errorMsgStr;
  633. errList.Add(en);
  634. errorMsg.AppendLine(errorMsgStr);
  635. continue;
  636. }
  637. else
  638. {
  639. //courseVerify.CourseCode = newCoursematerial.CourseCode;
  640. //courseVerify.CourseName = newCoursematerial.CourseName;
  641. courseVerify.Abbreviation = newCoursematerial.Abbreviation;
  642. courseVerify.EnglishName = newCoursematerial.EnglishName;
  643. courseVerify.StandardName = newCoursematerial.StandardName;
  644. courseVerify.CourseEdition = newCoursematerial.CourseEdition;
  645. courseVerify.CourseLevelID = newCoursematerial.CourseLevelID;
  646. courseVerify.CourseScienceID = newCoursematerial.CourseScienceID;
  647. courseVerify.ClassGroupingID = newCoursematerial.ClassGroupingID;
  648. courseVerify.CourseSynopsis = newCoursematerial.CourseSynopsis;
  649. courseVerify.CourseReserve = newCoursematerial.CourseReserve;
  650. courseVerify.IsEnable = newCoursematerial.IsEnable;
  651. courseVerify.Remark = newCoursematerial.Remark;
  652. SetModifyStatus(courseVerify);
  653. newCoursematerialUpList.Add(courseVerify);
  654. upCount++;
  655. }
  656. }
  657. else if (courseCodeVerify != null)
  658. {
  659. //courseCodeVerify.CourseCode = newCoursematerial.CourseCode;
  660. courseCodeVerify.CourseName = newCoursematerial.CourseName;
  661. courseCodeVerify.Abbreviation = newCoursematerial.Abbreviation;
  662. courseCodeVerify.EnglishName = newCoursematerial.EnglishName;
  663. courseCodeVerify.StandardName = newCoursematerial.StandardName;
  664. courseCodeVerify.CourseEdition = newCoursematerial.CourseEdition;
  665. courseCodeVerify.CourseLevelID = newCoursematerial.CourseLevelID;
  666. courseCodeVerify.CourseScienceID = newCoursematerial.CourseScienceID;
  667. courseCodeVerify.ClassGroupingID = newCoursematerial.ClassGroupingID;
  668. courseCodeVerify.CourseSynopsis = newCoursematerial.CourseSynopsis;
  669. courseCodeVerify.CourseReserve = newCoursematerial.CourseReserve;
  670. courseCodeVerify.IsEnable = newCoursematerial.IsEnable;
  671. courseCodeVerify.Remark = newCoursematerial.Remark;
  672. SetModifyStatus(courseCodeVerify);
  673. newCoursematerialUpList.Add(courseCodeVerify);
  674. upCount++;
  675. }
  676. else
  677. {
  678. if (courseNameVerifyList.Count() > 1)
  679. {
  680. errCount++;
  681. errorMsgStr = "课程名称已存在且无法匹配(课程名称多个重复),请检查";
  682. en.ErrorMessage = errorMsgStr;
  683. errList.Add(en);
  684. errorMsg.AppendLine(errorMsgStr);
  685. continue;
  686. }
  687. else
  688. {
  689. var courseNameVerify = courseNameVerifyList.Where(x => x.CourseName == newCoursematerial.CourseName).SingleOrDefault();
  690. if (courseNameVerify == null)
  691. {
  692. errCount++;
  693. errorMsgStr = "数据有误(课程名称对应的课程信息不存在),请检查";
  694. en.ErrorMessage = errorMsgStr;
  695. errList.Add(en);
  696. errorMsg.AppendLine(errorMsgStr);
  697. continue;
  698. }
  699. else
  700. {
  701. courseNameVerify.CourseCode = newCoursematerial.CourseCode;
  702. //courseNameVerify.CourseName = newCoursematerial.CourseName;
  703. courseNameVerify.Abbreviation = newCoursematerial.Abbreviation;
  704. courseNameVerify.EnglishName = newCoursematerial.EnglishName;
  705. courseNameVerify.StandardName = newCoursematerial.StandardName;
  706. courseNameVerify.CourseEdition = newCoursematerial.CourseEdition;
  707. courseNameVerify.CourseLevelID = newCoursematerial.CourseLevelID;
  708. courseNameVerify.CourseScienceID = newCoursematerial.CourseScienceID;
  709. courseNameVerify.ClassGroupingID = newCoursematerial.ClassGroupingID;
  710. courseNameVerify.CourseSynopsis = newCoursematerial.CourseSynopsis;
  711. courseNameVerify.CourseReserve = newCoursematerial.CourseReserve;
  712. courseNameVerify.IsEnable = newCoursematerial.IsEnable;
  713. courseNameVerify.Remark = newCoursematerial.Remark;
  714. SetModifyStatus(courseNameVerify);
  715. newCoursematerialUpList.Add(courseNameVerify);
  716. upCount++;
  717. }
  718. }
  719. }
  720. }
  721. }
  722. //批量插入
  723. UnitOfWork.BulkInsert(newCoursematerialInList);
  724. //批量统一提交更新
  725. if (newCoursematerialUpList != null && newCoursematerialUpList.Count() > 0)
  726. {
  727. UnitOfWork.BatchUpdate(newCoursematerialUpList);
  728. }
  729. errdataList = errList.Distinct().ToList(); //错误列表List
  730. }
  731. catch (Exception)
  732. {
  733. throw;
  734. }
  735. }
  736. }
  737. }