SpecialtyServices.cs 34 KB

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