CustomStandardSettingServices.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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.Utility;
  9. using Bowin.Common.Linq;
  10. using Bowin.Common.Linq.Entity;
  11. using EMIS.Utility;
  12. using EMIS.Entities;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.CacheManage;
  15. using EMIS.ViewModel.EnrollManage.SpecialtyManage;
  16. using EMIS.DataLogic.EnrollManage.SpecialtyManage;
  17. namespace EMIS.CommonLogic.EnrollManage.SpecialtyManage
  18. {
  19. public class CustomStandardSettingServices : BaseServices, ICustomStandardSettingServices
  20. {
  21. public CustomStandardSettingDAL customStandardSettingDAL { get; set; }
  22. /// <summary>
  23. /// 查询对应的省招专业信息View
  24. /// </summary>
  25. /// <param name="configuretView"></param>
  26. /// <param name="campusID"></param>
  27. /// <param name="collegeID"></param>
  28. /// <param name="yearID"></param>
  29. /// <param name="standardID"></param>
  30. /// <param name="educationID"></param>
  31. /// <param name="learningformID"></param>
  32. /// <param name="learnSystem"></param>
  33. /// <param name="semesterID"></param>
  34. /// <param name="pageIndex"></param>
  35. /// <param name="pageSize"></param>
  36. /// <returns></returns>
  37. public IGridResultSet<CustomStandardSettingView> GetCustomStandardSettingViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? yearID,
  38. int? standardID, int? educationID, int? learningformID, string learnSystem, int? semesterID, int pageIndex, int pageSize)
  39. {
  40. Expression<Func<CF_CustomStandardSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  41. if (collegeID.HasValue)
  42. {
  43. exp = exp.And(x => x.CollegeID == collegeID);
  44. }
  45. if (yearID.HasValue)
  46. {
  47. exp = exp.And(x => x.YearID == yearID);
  48. }
  49. if (semesterID.HasValue)
  50. {
  51. exp = exp.And(x => x.SemesterID == semesterID);
  52. }
  53. var query = customStandardSettingDAL.GetCustomStandardSettingViewQueryable(exp);
  54. if (campusID.HasValue)
  55. {
  56. query = query.Where(x => x.CampusID == campusID);
  57. }
  58. if (standardID.HasValue)
  59. {
  60. query = query.Where(x => x.StandardID == standardID);
  61. }
  62. if (educationID.HasValue)
  63. {
  64. query = query.Where(x => x.EducationID == educationID);
  65. }
  66. if (learningformID.HasValue)
  67. {
  68. query = query.Where(x => x.LearningformID == learningformID);
  69. }
  70. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  71. {
  72. var LearnSystems = Convert.ToDecimal(learnSystem);
  73. query = query.Where(x => x.LearnSystem == LearnSystems);
  74. }
  75. //查询条件
  76. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  77. {
  78. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  79. }
  80. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenByDescending(x => x.YearID)
  81. .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet<CustomStandardSettingView>(pageIndex, pageSize);
  82. }
  83. /// <summary>
  84. /// 查询对应的省招专业信息List
  85. /// </summary>
  86. /// <param name="configuretView"></param>
  87. /// <param name="campusID"></param>
  88. /// <param name="collegeID"></param>
  89. /// <param name="yearID"></param>
  90. /// <param name="standardID"></param>
  91. /// <param name="educationID"></param>
  92. /// <param name="learningformID"></param>
  93. /// <param name="learnSystem"></param>
  94. /// <param name="semesterID"></param>
  95. /// <returns></returns>
  96. public IList<CustomStandardSettingView> GetCustomStandardSettingViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? yearID,
  97. int? standardID, int? educationID, int? learningformID, string learnSystem, int? semesterID)
  98. {
  99. Expression<Func<CF_CustomStandardSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  100. if (collegeID.HasValue)
  101. {
  102. exp = exp.And(x => x.CollegeID == collegeID);
  103. }
  104. if (yearID.HasValue)
  105. {
  106. exp = exp.And(x => x.YearID == yearID);
  107. }
  108. if (semesterID.HasValue)
  109. {
  110. exp = exp.And(x => x.SemesterID == semesterID);
  111. }
  112. var query = customStandardSettingDAL.GetCustomStandardSettingViewQueryable(exp);
  113. if (campusID.HasValue)
  114. {
  115. query = query.Where(x => x.CampusID == campusID);
  116. }
  117. if (standardID.HasValue)
  118. {
  119. query = query.Where(x => x.StandardID == standardID);
  120. }
  121. if (educationID.HasValue)
  122. {
  123. query = query.Where(x => x.EducationID == educationID);
  124. }
  125. if (learningformID.HasValue)
  126. {
  127. query = query.Where(x => x.LearningformID == learningformID);
  128. }
  129. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  130. {
  131. var LearnSystems = Convert.ToDecimal(learnSystem);
  132. query = query.Where(x => x.LearnSystem == LearnSystems);
  133. }
  134. //查询条件
  135. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  136. {
  137. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  138. }
  139. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenByDescending(x => x.YearID)
  140. .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToList();
  141. }
  142. /// <summary>
  143. /// 查询对应的省招专业信息CustomStandardSettingView
  144. /// </summary>
  145. /// <param name="customStandardSettingID"></param>
  146. /// <returns></returns>
  147. public CustomStandardSettingView GetCustomStandardSettingView(Guid? customStandardSettingID)
  148. {
  149. try
  150. {
  151. var query = customStandardSettingDAL.GetCustomStandardSettingViewQueryable(x => x.CustomStandardSettingID == customStandardSettingID).SingleOrDefault();
  152. return query;
  153. }
  154. catch (Exception ex)
  155. {
  156. throw new Exception(ex.Message);
  157. }
  158. }
  159. /// <summary>
  160. /// 编辑(新增、修改,业务主键:省招代码或学年、学期、院系所、专业信息ID唯一)
  161. /// </summary>
  162. /// <param name="customStandardSettingView"></param>
  163. public void CustomStandardSettingEdit(CustomStandardSettingView customStandardSettingView)
  164. {
  165. try
  166. {
  167. var customStandardSettingVerification = customStandardSettingDAL.customStandardSettingRepository.GetList(x => x.CustomStandardSettingID != customStandardSettingView.CustomStandardSettingID
  168. && ((x.YearID == customStandardSettingView.YearID && x.SemesterID == customStandardSettingView.SemesterID
  169. && x.CollegeID == customStandardSettingView.CollegeID && x.SpecialtyID == customStandardSettingView.SpecialtyID)
  170. || (x.Code == customStandardSettingView.Code))).FirstOrDefault();
  171. if (customStandardSettingVerification == null)
  172. {
  173. //数据有误验证
  174. if (customStandardSettingView.CustomStandardSettingID != Guid.Empty)
  175. {
  176. var customStandardSetting = customStandardSettingDAL.customStandardSettingRepository
  177. .GetList(x => x.CustomStandardSettingID == customStandardSettingView.CustomStandardSettingID).SingleOrDefault();
  178. if (customStandardSetting == null)
  179. {
  180. throw new Exception("数据有误,请核查。");
  181. }
  182. else
  183. {
  184. //表示修改
  185. customStandardSetting.Code = customStandardSettingView.Code;
  186. customStandardSetting.SpecialtyID = customStandardSettingView.SpecialtyID;
  187. customStandardSetting.CollegeID = customStandardSettingView.CollegeID;
  188. customStandardSetting.YearID = customStandardSettingView.YearID;
  189. customStandardSetting.SemesterID = customStandardSettingView.SemesterID;
  190. customStandardSetting.Remark = customStandardSettingView.Remark;
  191. SetModifyStatus(customStandardSetting);
  192. }
  193. }
  194. else
  195. {
  196. //表示新增
  197. CF_CustomStandardSetting customStandardSetting = new CF_CustomStandardSetting();
  198. customStandardSetting.CustomStandardSettingID = Guid.NewGuid();
  199. customStandardSetting.Code = customStandardSettingView.Code;
  200. customStandardSetting.SpecialtyID = customStandardSettingView.SpecialtyID;
  201. customStandardSetting.CollegeID = customStandardSettingView.CollegeID;
  202. customStandardSetting.YearID = customStandardSettingView.YearID;
  203. customStandardSetting.SemesterID = customStandardSettingView.SemesterID;
  204. customStandardSetting.Remark = customStandardSettingView.Remark;
  205. SetNewStatus(customStandardSetting);
  206. UnitOfWork.Add(customStandardSetting);
  207. }
  208. }
  209. else
  210. {
  211. throw new Exception("存在相同的省招专业信息(省招代码唯一或学年、学期、" + RSL.Get("CollegeName") + "专业信息唯一)。");
  212. }
  213. //事务提交
  214. UnitOfWork.Commit();
  215. }
  216. catch (Exception ex)
  217. {
  218. throw new Exception(ex.Message);
  219. }
  220. }
  221. /// <summary>
  222. /// 删除
  223. /// </summary>
  224. /// <param name="customStandardSettingIDList"></param>
  225. /// <returns></returns>
  226. public bool CustomStandardSettingDelete(List<Guid?> customStandardSettingIDList)
  227. {
  228. try
  229. {
  230. UnitOfWork.Delete<CF_CustomStandardSetting>(x => customStandardSettingIDList.Contains(x.CustomStandardSettingID));
  231. return true;
  232. }
  233. catch (Exception)
  234. {
  235. throw;
  236. }
  237. }
  238. /// <summary>
  239. /// Excel导入
  240. /// </summary>
  241. /// <param name="cellheader"></param>
  242. /// <param name="inCount"></param>
  243. /// <param name="upCount"></param>
  244. /// <param name="errdataList"></param>
  245. /// <param name="errCount"></param>
  246. /// <param name="sourcePhysicalPath"></param>
  247. public void CustomStandardSettingImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<CustomStandardSettingView> errdataList, out int? errCount, string sourcePhysicalPath)
  248. {
  249. try
  250. {
  251. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  252. List<CustomStandardSettingView> errList = new List<CustomStandardSettingView>();
  253. // 1.1解析文件,存放到一个List集合里
  254. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  255. List<CustomStandardSettingView> enlist = NpoiExcelHelper.ExcelToEntityList<CustomStandardSettingView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  256. cellheader.Add("ErrorMessage", "未导入原因");
  257. //对List集合进行有效性校验
  258. if (enlist.Count() <= 0)
  259. {
  260. throw new Exception("Excel文件数据为空,请检查。");
  261. }
  262. Regex reg = null; //正则表达式
  263. inCount = 0; //导入个数
  264. upCount = 0; //更新个数
  265. errCount = 0; //失败个数
  266. string errorMsgStr = ""; //错误信息
  267. //省招专业insert实体List
  268. List<CF_CustomStandardSetting> customStandardSettingInList = new List<CF_CustomStandardSetting>();
  269. //省招专业update实体List
  270. List<CF_CustomStandardSetting> customStandardSettingUpList = new List<CF_CustomStandardSetting>();
  271. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  272. //省招代码
  273. var codeList = enlist.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).ToList();
  274. //省招专业(由于需要和Excel中数据进行比对,数据太多就会报异常,所以需要先查询出来)
  275. var customStandardSettingAllList = customStandardSettingDAL.customStandardSettingRepository.GetList(x => true).ToList();
  276. //省招代码对比后的List(省招代码唯一)
  277. var newCodeList = customStandardSettingAllList.Where(x => codeList.Contains(x.Code)).ToList();
  278. //学年
  279. var yearList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Year).ToList();
  280. //学期
  281. var semesterList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester).ToList();
  282. //院系所代码
  283. var collegeCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeCode)).Select(x => x.CollegeCode).ToList();
  284. //对应的院系所信息
  285. var collegeList = customStandardSettingDAL.collegeRepository.GetList(x => collegeCodeList.Contains(x.No), x => x.CF_CollegeProfile).ToList();
  286. //专业代码、专业名称、专业ID(Value)
  287. var standardList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard).ToList();
  288. //培养层次(所修学历)
  289. var educationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Education).ToList();
  290. //学习形式
  291. var learningFormList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Learningform).ToList();
  292. //专业信息
  293. var specialtyList = customStandardSettingDAL.specialtyRepository.GetList(x => true).ToList();
  294. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  295. for (int i = 0; i < enlist.Count; i++)
  296. {
  297. CustomStandardSettingView en = enlist[i]; //Excel表数据视图
  298. CF_CustomStandardSetting newCustomStandardSetting = new CF_CustomStandardSetting(); //省招专业实体
  299. //省招代码(唯一)
  300. if (string.IsNullOrEmpty(en.Code))
  301. {
  302. errCount++;
  303. errorMsgStr = "省招代码不能为空";
  304. en.ErrorMessage = errorMsgStr;
  305. errList.Add(en);
  306. errorMsg.AppendLine(errorMsgStr);
  307. continue;
  308. }
  309. else
  310. {
  311. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  312. if (!reg.IsMatch(en.Code.Trim()))
  313. {
  314. errCount++;
  315. errorMsgStr = "省招代码格式不正确,请检查";
  316. en.ErrorMessage = errorMsgStr;
  317. errList.Add(en);
  318. errorMsg.AppendLine(errorMsgStr);
  319. continue;
  320. }
  321. else
  322. {
  323. //省招代码
  324. newCustomStandardSetting.Code = en.Code.Trim();
  325. }
  326. }
  327. //学年
  328. if (string.IsNullOrEmpty(en.YearStr))
  329. {
  330. errCount++;
  331. errorMsgStr = "学年不能为空";
  332. en.ErrorMessage = errorMsgStr;
  333. errList.Add(en);
  334. errorMsg.AppendLine(errorMsgStr);
  335. continue;
  336. }
  337. else
  338. {
  339. var year = yearList.Where(x => x.Name == en.YearStr.Trim()).SingleOrDefault();
  340. if (year == null)
  341. {
  342. errCount++;
  343. errorMsgStr = "学年不存在,请检查";
  344. en.ErrorMessage = errorMsgStr;
  345. errList.Add(en);
  346. errorMsg.AppendLine(errorMsgStr);
  347. continue;
  348. }
  349. else
  350. {
  351. //学年
  352. newCustomStandardSetting.YearID = year.Value;
  353. }
  354. }
  355. //学期
  356. if (string.IsNullOrEmpty(en.SemesterStr))
  357. {
  358. errCount++;
  359. errorMsgStr = "学期不能为空";
  360. en.ErrorMessage = errorMsgStr;
  361. errList.Add(en);
  362. errorMsg.AppendLine(errorMsgStr);
  363. continue;
  364. }
  365. else
  366. {
  367. var semester = semesterList.Where(x => x.Name == en.SemesterStr.Trim()).SingleOrDefault();
  368. if (semester == null)
  369. {
  370. errCount++;
  371. errorMsgStr = "学期不存在,请检查";
  372. en.ErrorMessage = errorMsgStr;
  373. errList.Add(en);
  374. errorMsg.AppendLine(errorMsgStr);
  375. continue;
  376. }
  377. else
  378. {
  379. //学期
  380. newCustomStandardSetting.SemesterID = semester.Value;
  381. }
  382. }
  383. //院系所代码
  384. if (string.IsNullOrEmpty(en.CollegeCode))
  385. {
  386. errCount++;
  387. errorMsgStr = RSL.Get("CollegeCode") + "不能为空";
  388. en.ErrorMessage = errorMsgStr;
  389. errList.Add(en);
  390. errorMsg.AppendLine(errorMsgStr);
  391. continue;
  392. }
  393. else
  394. {
  395. var college = collegeList.Where(x => x.No == en.CollegeCode.Trim()).SingleOrDefault();
  396. if (college == null)
  397. {
  398. errCount++;
  399. errorMsgStr = RSL.Get("CollegeCode") + "不存在,请检查";
  400. en.ErrorMessage = errorMsgStr;
  401. errList.Add(en);
  402. errorMsg.AppendLine(errorMsgStr);
  403. continue;
  404. }
  405. else
  406. {
  407. if (college.CF_CollegeProfile == null)
  408. {
  409. errCount++;
  410. errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查";
  411. en.ErrorMessage = errorMsgStr;
  412. errList.Add(en);
  413. errorMsg.AppendLine(errorMsgStr);
  414. continue;
  415. }
  416. else if (college.CF_CollegeProfile.UnitCategoryID != (int)CF_UnitCategory.College)
  417. {
  418. errCount++;
  419. errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查";
  420. en.ErrorMessage = errorMsgStr;
  421. errList.Add(en);
  422. errorMsg.AppendLine(errorMsgStr);
  423. continue;
  424. }
  425. //院系所ID
  426. newCustomStandardSetting.CollegeID = college.CollegeID;
  427. }
  428. }
  429. //专业代码
  430. if (string.IsNullOrEmpty(en.StandardCodeStr))
  431. {
  432. errCount++;
  433. errorMsgStr = "专业代码不能为空";
  434. en.ErrorMessage = errorMsgStr;
  435. errList.Add(en);
  436. errorMsg.AppendLine(errorMsgStr);
  437. continue;
  438. }
  439. else
  440. {
  441. var standardCode = standardList.Where(x => x.Code == en.StandardCodeStr.Trim()).FirstOrDefault();
  442. if (standardCode == null)
  443. {
  444. errCount++;
  445. errorMsgStr = "专业代码不存在,请检查";
  446. en.ErrorMessage = errorMsgStr;
  447. errList.Add(en);
  448. errorMsg.AppendLine(errorMsgStr);
  449. continue;
  450. }
  451. else
  452. {
  453. //专业代码
  454. }
  455. }
  456. //专业名称
  457. if (string.IsNullOrEmpty(en.StandardNameStr))
  458. {
  459. errCount++;
  460. errorMsgStr = "专业名称不能为空";
  461. en.ErrorMessage = errorMsgStr;
  462. errList.Add(en);
  463. errorMsg.AppendLine(errorMsgStr);
  464. continue;
  465. }
  466. else
  467. {
  468. var standardName = standardList.Where(x => x.Name == en.StandardNameStr.Trim()).FirstOrDefault();
  469. if (standardName == null)
  470. {
  471. errCount++;
  472. errorMsgStr = "专业名称不存在,请检查";
  473. en.ErrorMessage = errorMsgStr;
  474. errList.Add(en);
  475. errorMsg.AppendLine(errorMsgStr);
  476. continue;
  477. }
  478. else
  479. {
  480. //专业名称
  481. }
  482. }
  483. //专业代码与专业名称查询专业ID(Value)
  484. if (string.IsNullOrEmpty(en.StandardCodeStr.Trim()) || string.IsNullOrEmpty(en.StandardNameStr.Trim()))
  485. {
  486. errCount++;
  487. errorMsgStr = "专业代码或专业名称不能为空";
  488. en.ErrorMessage = errorMsgStr;
  489. errList.Add(en);
  490. errorMsg.AppendLine(errorMsgStr);
  491. continue;
  492. }
  493. else
  494. {
  495. var standardID = standardList.Where(x => x.Code == en.StandardCodeStr.Trim() && x.Name == en.StandardNameStr.Trim()).SingleOrDefault();
  496. if (standardID == null)
  497. {
  498. errCount++;
  499. errorMsgStr = "专业代码与专业名称对应的元素值不存在,请检查";
  500. en.ErrorMessage = errorMsgStr;
  501. errList.Add(en);
  502. errorMsg.AppendLine(errorMsgStr);
  503. continue;
  504. }
  505. else
  506. {
  507. //专业ID(Value)
  508. en.StandardID = standardID.Value;
  509. }
  510. }
  511. //培养层次(所修学历)
  512. if (string.IsNullOrEmpty(en.EducationStr))
  513. {
  514. errCount++;
  515. errorMsgStr = RSL.Get("EducationID") + "不能为空";
  516. en.ErrorMessage = errorMsgStr;
  517. errList.Add(en);
  518. errorMsg.AppendLine(errorMsgStr);
  519. continue;
  520. }
  521. else
  522. {
  523. var education = educationList.Where(x => x.Name == en.EducationStr.Trim()).SingleOrDefault();
  524. if (education == null)
  525. {
  526. errCount++;
  527. errorMsgStr = RSL.Get("EducationID") + "不存在,请检查";
  528. en.ErrorMessage = errorMsgStr;
  529. errList.Add(en);
  530. errorMsg.AppendLine(errorMsgStr);
  531. continue;
  532. }
  533. else
  534. {
  535. //培养层次
  536. en.EducationID = education.Value;
  537. }
  538. }
  539. //学习形式
  540. if (string.IsNullOrEmpty(en.LearningformStr))
  541. {
  542. errCount++;
  543. errorMsgStr = "学习形式不能为空";
  544. en.ErrorMessage = errorMsgStr;
  545. errList.Add(en);
  546. errorMsg.AppendLine(errorMsgStr);
  547. continue;
  548. }
  549. else
  550. {
  551. var learningForm = learningFormList.Where(x => x.Name == en.LearningformStr.Trim()).SingleOrDefault();
  552. if (learningForm == null)
  553. {
  554. errCount++;
  555. errorMsgStr = "学习形式不存在,请检查";
  556. en.ErrorMessage = errorMsgStr;
  557. errList.Add(en);
  558. errorMsg.AppendLine(errorMsgStr);
  559. continue;
  560. }
  561. else
  562. {
  563. //学习形式
  564. en.LearningformID = learningForm.Value;
  565. }
  566. }
  567. //学制
  568. if (string.IsNullOrEmpty(en.LearnSystemStr))
  569. {
  570. errCount++;
  571. errorMsgStr = "学制不能为空";
  572. en.ErrorMessage = errorMsgStr;
  573. errList.Add(en);
  574. errorMsg.AppendLine(errorMsgStr);
  575. continue;
  576. }
  577. else
  578. {
  579. reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式()
  580. if (!reg.IsMatch(en.LearnSystemStr.Trim()))
  581. {
  582. errCount++;
  583. errorMsgStr = "学制格式不正确,请检查";
  584. en.ErrorMessage = errorMsgStr;
  585. errList.Add(en);
  586. errorMsg.AppendLine(errorMsgStr);
  587. continue;
  588. }
  589. else
  590. {
  591. //学制
  592. en.LearnSystem = Convert.ToDecimal(en.LearnSystemStr);
  593. }
  594. }
  595. //专业信息查询
  596. var specialty = specialtyList.Where(x => x.StandardID == en.StandardID && x.EducationID == en.EducationID && x.LearningformID == en.LearningformID && x.LearnSystem == en.LearnSystem).SingleOrDefault();
  597. //专业信息ID
  598. if (specialty == null)
  599. {
  600. errCount++;
  601. errorMsgStr = "专业信息不存在,请检查";
  602. en.ErrorMessage = errorMsgStr;
  603. errList.Add(en);
  604. errorMsg.AppendLine(errorMsgStr);
  605. continue;
  606. }
  607. else
  608. {
  609. //查询专业信息(启用、禁用状态)
  610. if (specialty.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  611. {
  612. newCustomStandardSetting.SpecialtyID = specialty.SpecialtyID;
  613. }
  614. else
  615. {
  616. newCustomStandardSetting.SpecialtyID = specialty.SpecialtyID;
  617. errCount++;
  618. errorMsgStr = "专业信息为禁用状态,请检查";
  619. en.ErrorMessage = errorMsgStr;
  620. errList.Add(en);
  621. errorMsg.AppendLine(errorMsgStr);
  622. continue;
  623. }
  624. }
  625. //备注
  626. if (string.IsNullOrEmpty(en.Remark))
  627. {
  628. //不考虑
  629. }
  630. else
  631. {
  632. newCustomStandardSetting.Remark = en.Remark;
  633. }
  634. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  635. //for (int j = i + 1; j < enlist.Count; j++)
  636. //{
  637. // CustomStandardSettingView enA = enlist[j];
  638. // //根据Excel表中的业务主键进行去重(省招代码唯一或学年、学期、院系所ID、专业信息唯一)
  639. // if (en.Code == enA.Code ||
  640. // (
  641. // en.YearStr == enA.YearStr
  642. // && en.SemesterID == enA.SemesterID
  643. // && en.CollegeCode == enA.CollegeCode
  644. // && en.SpecialtyID == enA.SpecialtyID
  645. // )
  646. // )
  647. // {
  648. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  649. // }
  650. //}
  651. //数据表重复性验证(省招代码唯一)
  652. var codeVerification = newCodeList.Where(x => x.Code == newCustomStandardSetting.Code).FirstOrDefault();
  653. if (codeVerification == null)
  654. {
  655. //Excel表重复验证
  656. if (!customStandardSettingInList.Any(x => x.Code == newCustomStandardSetting.Code))
  657. {
  658. //数据表重复性验证(学年、学期、院系所ID、专业信息唯一)
  659. var cusVerification = customStandardSettingAllList.Where(x => x.SpecialtyID == newCustomStandardSetting.SpecialtyID
  660. && x.CollegeID == newCustomStandardSetting.CollegeID && x.YearID == newCustomStandardSetting.YearID
  661. && x.SemesterID == newCustomStandardSetting.SemesterID).FirstOrDefault();
  662. //新增
  663. if (cusVerification == null)
  664. {
  665. //Excel表重复验证
  666. if (!customStandardSettingInList.Any(x => x.YearID == newCustomStandardSetting.YearID
  667. && x.SemesterID == newCustomStandardSetting.SemesterID
  668. && x.CollegeID == newCustomStandardSetting.CollegeID
  669. && x.SpecialtyID == newCustomStandardSetting.SpecialtyID))
  670. {
  671. newCustomStandardSetting.CustomStandardSettingID = Guid.NewGuid();
  672. SetNewStatus(newCustomStandardSetting);
  673. customStandardSettingInList.Add(newCustomStandardSetting);
  674. inCount++;
  675. }
  676. else
  677. {
  678. //Excel表重复性验证
  679. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  680. inCount++;
  681. }
  682. }
  683. else
  684. {
  685. //更新(Excel有重复时,以最后一条记录的更新为准)
  686. //cusVerification.Remark = newCustomStandardSetting.Remark;
  687. //SetModifyStatus(cusVerification);
  688. //customStandardSettingUpList.Add(cusVerification);
  689. //upCount++;
  690. //(此处暂时以抛出失败数据文件中的方式进行处理)
  691. errCount++;
  692. errorMsgStr = "导入失败,已存在相同学年、学期、" + RSL.Get("CollegeCode") + "、专业信息的数据(数据重复)";
  693. en.ErrorMessage = errorMsgStr;
  694. errList.Add(en);
  695. errorMsg.AppendLine(errorMsgStr);
  696. continue;
  697. }
  698. }
  699. else
  700. {
  701. //Excel表重复性验证
  702. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  703. inCount++;
  704. }
  705. }
  706. else
  707. {
  708. //更新(Excel有重复时,以最后一条记录的更新为准)
  709. //codeVerification.Remark = newCustomStandardSetting.Remark;
  710. //SetModifyStatus(codeVerification);
  711. //customStandardSettingUpList.Add(codeVerification);
  712. //upCount++;
  713. //(此处暂时以抛出失败数据文件中的方式进行处理)
  714. errCount++;
  715. errorMsgStr = "导入失败,已存在相同的省招代码(数据重复)";
  716. en.ErrorMessage = errorMsgStr;
  717. errList.Add(en);
  718. errorMsg.AppendLine(errorMsgStr);
  719. continue;
  720. }
  721. }
  722. using (TransactionScope ts = new TransactionScope())
  723. {
  724. if (customStandardSettingInList != null && customStandardSettingInList.Count() > 0)
  725. {
  726. UnitOfWork.BulkInsert(customStandardSettingInList);
  727. }
  728. if (customStandardSettingUpList != null && customStandardSettingUpList.Count() > 0)
  729. {
  730. UnitOfWork.BatchUpdate(customStandardSettingUpList);
  731. }
  732. ts.Complete();
  733. }
  734. errdataList = errList.Distinct().ToList(); //错误列表List
  735. }
  736. catch (Exception)
  737. {
  738. throw;
  739. }
  740. }
  741. }
  742. }