SpecialtyServices.cs 37 KB

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