GrademajorServices.cs 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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.Linq;
  9. using Bowin.Common.Linq.Entity;
  10. using Bowin.Common.Utility;
  11. using EMIS.Entities;
  12. using EMIS.ViewModel;
  13. using EMIS.ViewModel.CacheManage;
  14. using EMIS.ViewModel.StudentManage.StudentProfile;
  15. using EMIS.ViewModel.UniversityManage.SpecialtyClassManage;
  16. using EMIS.DataLogic.UniversityManage.SpecialtyClassManage;
  17. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  18. namespace EMIS.CommonLogic.UniversityManage.SpecialtyClassManage
  19. {
  20. public class GrademajorServices : BaseServices, IGrademajorServices
  21. {
  22. public GrademajorDAL GrademajorDAL { get; set; }
  23. public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
  24. /// <summary>
  25. /// 查询对应的年级专业信息GrademajorView
  26. /// </summary>
  27. /// <param name="configuretView"></param>
  28. /// <param name="campusID"></param>
  29. /// <param name="collegeID"></param>
  30. /// <param name="gradeID"></param>
  31. /// <param name="standardID"></param>
  32. /// <param name="educationID"></param>
  33. /// <param name="learningformID"></param>
  34. /// <param name="learnSystem"></param>
  35. /// <param name="inSchoolStatus"></param>
  36. /// <param name="pageIndex"></param>
  37. /// <param name="pageSize"></param>
  38. /// <returns></returns>
  39. public IGridResultSet<GrademajorView> GetGrademajorViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  40. int? educationID, int? learningformID, string learnSystem, int? inSchoolStatus, int pageIndex, int pageSize)
  41. {
  42. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  43. if (gradeID.HasValue)
  44. {
  45. expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
  46. }
  47. //学生信息
  48. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  49. if (inSchoolStatus != null && inSchoolStatus > -1)
  50. {
  51. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  52. if (inSchoolStatus == 1)
  53. {
  54. //表示在校
  55. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  56. }
  57. if (inSchoolStatus == 0)
  58. {
  59. //不在校
  60. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  61. }
  62. }
  63. var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor, expStudent);
  64. if (campusID.HasValue)
  65. {
  66. //校区
  67. query = query.Where(x => x.CampusID == campusID);
  68. }
  69. if (collegeID.HasValue)
  70. {
  71. //院系所
  72. query = query.Where(x => x.CollegeID == collegeID);
  73. }
  74. if (standardID.HasValue)
  75. {
  76. //专业ID(Value)
  77. query = query.Where(x => x.StandardID == standardID);
  78. }
  79. if (educationID.HasValue)
  80. {
  81. //培养层次
  82. query = query.Where(x => x.EducationID == educationID);
  83. }
  84. if (learningformID.HasValue)
  85. {
  86. //学习形式
  87. query = query.Where(x => x.LearningformID == learningformID);
  88. }
  89. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  90. {
  91. //学制
  92. var LearnSystems = Convert.ToDecimal(learnSystem);
  93. query = query.Where(x => x.LearnSystem == LearnSystems);
  94. }
  95. //if (inSchoolStatus != null && inSchoolStatus > -1)
  96. //{
  97. // //排除人数为0的信息
  98. // query = query.Where(x => x.StudentCount > 0);
  99. //}
  100. //查询条件
  101. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  102. {
  103. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  104. }
  105. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID)
  106. .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet<GrademajorView>(pageIndex, pageSize);
  107. }
  108. /// <summary>
  109. /// 查询对应的年级专业信息List
  110. /// </summary>
  111. /// <param name="configuretView"></param>
  112. /// <param name="campusID"></param>
  113. /// <param name="collegeID"></param>
  114. /// <param name="gradeID"></param>
  115. /// <param name="standardID"></param>
  116. /// <param name="educationID"></param>
  117. /// <param name="learningformID"></param>
  118. /// <param name="learnSystem"></param>
  119. /// <param name="inSchoolStatus"></param>
  120. /// <returns></returns>
  121. public IList<GrademajorView> GetGrademajorViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID,
  122. int? educationID, int? learningformID, string learnSystem, int? inSchoolStatus)
  123. {
  124. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  125. if (gradeID.HasValue)
  126. {
  127. expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
  128. }
  129. //学生信息
  130. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  131. if (inSchoolStatus != null && inSchoolStatus > -1)
  132. {
  133. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  134. if (inSchoolStatus == 1)
  135. {
  136. //表示在校
  137. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  138. }
  139. if (inSchoolStatus == 0)
  140. {
  141. //不在校
  142. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  143. }
  144. }
  145. var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor, expStudent);
  146. if (campusID.HasValue)
  147. {
  148. //校区
  149. query = query.Where(x => x.CampusID == campusID);
  150. }
  151. if (collegeID.HasValue)
  152. {
  153. //院系所
  154. query = query.Where(x => x.CollegeID == collegeID);
  155. }
  156. if (standardID.HasValue)
  157. {
  158. //专业ID(Value)
  159. query = query.Where(x => x.StandardID == standardID);
  160. }
  161. if (educationID.HasValue)
  162. {
  163. //培养层次
  164. query = query.Where(x => x.EducationID == educationID);
  165. }
  166. if (learningformID.HasValue)
  167. {
  168. //学习形式
  169. query = query.Where(x => x.LearningformID == learningformID);
  170. }
  171. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  172. {
  173. //学制
  174. var LearnSystems = Convert.ToDecimal(learnSystem);
  175. query = query.Where(x => x.LearnSystem == LearnSystems);
  176. }
  177. //if (inSchoolStatus != null && inSchoolStatus > -1)
  178. //{
  179. // //排除人数为0的信息
  180. // query = query.Where(x => x.StudentCount > 0);
  181. //}
  182. //查询条件
  183. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  184. {
  185. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  186. }
  187. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID)
  188. .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
  189. }
  190. /// <summary>
  191. /// 查询对应的年级专业信息GrademajorView(无数据范围)
  192. /// </summary>
  193. /// <param name="configuretView"></param>
  194. /// <param name="campusID"></param>
  195. /// <param name="collegeID"></param>
  196. /// <param name="gradeID"></param>
  197. /// <param name="standardID"></param>
  198. /// <param name="educationID"></param>
  199. /// <param name="learningformID"></param>
  200. /// <param name="learnSystem"></param>
  201. /// <param name="pageIndex"></param>
  202. /// <param name="pageSize"></param>
  203. /// <returns></returns>
  204. public IGridResultSet<GrademajorView> GetGrademajorViewWithoutRangeGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID,
  205. int? standardID, int? educationID, int? learningformID, string learnSystem, int pageIndex, int pageSize)
  206. {
  207. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  208. if (gradeID.HasValue)
  209. {
  210. expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
  211. }
  212. var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor);
  213. if (campusID.HasValue)
  214. {
  215. //校区
  216. query = query.Where(x => x.CampusID == campusID);
  217. }
  218. if (collegeID.HasValue)
  219. {
  220. //院系所
  221. query = query.Where(x => x.CollegeID == collegeID);
  222. }
  223. if (standardID.HasValue)
  224. {
  225. //专业ID(Value)
  226. query = query.Where(x => x.StandardID == standardID);
  227. }
  228. if (educationID.HasValue)
  229. {
  230. //培养层次
  231. query = query.Where(x => x.EducationID == educationID);
  232. }
  233. if (learningformID.HasValue)
  234. {
  235. //学习形式
  236. query = query.Where(x => x.LearningformID == learningformID);
  237. }
  238. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  239. {
  240. //学制
  241. var LearnSystems = Convert.ToDecimal(learnSystem);
  242. query = query.Where(x => x.LearnSystem == LearnSystems);
  243. }
  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.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet<GrademajorView>(pageIndex, pageSize);
  250. }
  251. /// <summary>
  252. /// 查询年级专业中的专业名称信息FacultymajorView(去重)
  253. /// </summary>
  254. /// <param name="configuretView"></param>
  255. /// <param name="collegeID"></param>
  256. /// <param name="gradeID"></param>
  257. /// <param name="pageIndex"></param>
  258. /// <param name="pageSize"></param>
  259. /// <returns></returns>
  260. public IGridResultSet<FacultymajorView> GetStandardViewGrid(ConfiguretView configuretView, Guid? collegeID, int? gradeID, int pageIndex, int pageSize)
  261. {
  262. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  263. if (collegeID.HasValue)
  264. {
  265. expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  266. }
  267. if (gradeID.HasValue)
  268. {
  269. expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
  270. }
  271. var query = GrademajorDAL.GetStandardViewQueryable(expGrademajor);
  272. //查询条件
  273. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  274. {
  275. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  276. }
  277. return query.OrderBy(x => x.StandardName).ToGridResultSet<FacultymajorView>(pageIndex, pageSize);
  278. }
  279. /// <summary>
  280. /// 查询年级专业中的专业名称信息List(去重)
  281. /// </summary>
  282. /// <param name="configuretView"></param>
  283. /// <param name="collegeID"></param>
  284. /// <param name="gradeID"></param>
  285. /// <returns></returns>
  286. public IList<FacultymajorView> GetStandardViewList(ConfiguretView configuretView, Guid? collegeID, int? gradeID)
  287. {
  288. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  289. if (collegeID.HasValue)
  290. {
  291. expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  292. }
  293. if (gradeID.HasValue)
  294. {
  295. expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
  296. }
  297. var query = GrademajorDAL.GetStandardViewQueryable(expGrademajor);
  298. //查询条件
  299. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  300. {
  301. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  302. }
  303. return query.OrderBy(x => x.StandardName).ToList();
  304. }
  305. /// <summary>
  306. /// 查询年级专业中的年级信息GrademajorView(去重)
  307. /// </summary>
  308. /// <param name="configuretView"></param>
  309. /// <param name="collegeID"></param>
  310. /// <param name="standardID"></param>
  311. /// <param name="pageIndex"></param>
  312. /// <param name="pageSize"></param>
  313. /// <returns></returns>
  314. public IGridResultSet<GrademajorView> GetGradeViewGrid(ConfiguretView configuretView, Guid? collegeID, int? standardID, int pageIndex, int pageSize)
  315. {
  316. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  317. if (collegeID.HasValue)
  318. {
  319. expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  320. }
  321. if (standardID.HasValue)
  322. {
  323. expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.StandardID == standardID);
  324. }
  325. var query = GrademajorDAL.GetGradeViewQueryable(expGrademajor);
  326. //查询条件
  327. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  328. {
  329. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  330. }
  331. return query.OrderByDescending(x => x.GradeID).ToGridResultSet<GrademajorView>(pageIndex, pageSize);
  332. }
  333. /// <summary>
  334. /// 查询年级专业中的年级信息List(去重)
  335. /// </summary>
  336. /// <param name="configuretView"></param>
  337. /// <param name="collegeID"></param>
  338. /// <param name="standardID"></param>
  339. /// <returns></returns>
  340. public IList<GrademajorView> GetGradeViewList(ConfiguretView configuretView, Guid? collegeID, int? standardID)
  341. {
  342. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  343. if (collegeID.HasValue)
  344. {
  345. expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  346. }
  347. if (standardID.HasValue)
  348. {
  349. expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.StandardID == standardID);
  350. }
  351. var query = GrademajorDAL.GetGradeViewQueryable(expGrademajor);
  352. //查询条件
  353. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  354. {
  355. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  356. }
  357. return query.OrderByDescending(x => x.GradeID).ToList();
  358. }
  359. /// <summary>
  360. /// 查询对应的年级专业信息CF_Grademajor
  361. /// </summary>
  362. /// <param name="grademajorID"></param>
  363. /// <returns></returns>
  364. public CF_Grademajor GetGrademajorInfo(Guid? grademajorID)
  365. {
  366. try
  367. {
  368. var query = GrademajorDAL.GrademajorRepository.GetList(x => x.GrademajorID == grademajorID).SingleOrDefault();
  369. return query;
  370. }
  371. catch (Exception ex)
  372. {
  373. throw new Exception(ex.Message);
  374. }
  375. }
  376. /// <summary>
  377. /// 查询对应的年级专业信息GrademajorView
  378. /// </summary>
  379. /// <param name="grademajorID"></param>
  380. /// <returns></returns>
  381. public GrademajorView GetGrademajorView(Guid? grademajorID)
  382. {
  383. try
  384. {
  385. var query = GrademajorDAL.GetGrademajorViwQueryable(x => x.GrademajorID == grademajorID).SingleOrDefault();
  386. return query;
  387. }
  388. catch (Exception ex)
  389. {
  390. throw new Exception(ex.Message);
  391. }
  392. }
  393. /// <summary>
  394. /// 查询对应的年级专业信息List
  395. /// </summary>
  396. /// <param name="collegeID"></param>
  397. /// <param name="gradeID"></param>
  398. /// <returns></returns>
  399. public IList<GrademajorView> GetGrademajorViewList(Guid? collegeID, int? gradeID)
  400. {
  401. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  402. if (gradeID.HasValue)
  403. {
  404. expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
  405. }
  406. var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor);
  407. if (collegeID.HasValue)
  408. {
  409. query = query.Where(x => x.CollegeID == collegeID);
  410. }
  411. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
  412. }
  413. /// <summary>
  414. /// 编辑(新增、修改,业务主键:年级专业编号或年级专业名称唯一)
  415. /// </summary>
  416. /// <param name="grademajorView"></param>
  417. public void GrademajorEdit(GrademajorView grademajorView)
  418. {
  419. try
  420. {
  421. //查询数据库进行验证
  422. var grademajorVerify = GrademajorDAL.GrademajorRepository.GetList(x => x.GrademajorID != grademajorView.GrademajorID && (x.Code == grademajorView.Code || x.Name == grademajorView.Name)).FirstOrDefault();
  423. if (grademajorVerify == null)
  424. {
  425. //计算相应的毕业学年学期Value
  426. var facultymajor = GrademajorDAL.FacultymajorRepository.GetSingle(x => x.FacultymajorID == grademajorView.FacultymajorID);
  427. var graduateSchoolyearValue = (grademajorView.GradeID.Value * 2) - 1 + (grademajorView.SemesterID.Value - 1);
  428. graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(facultymajor.LearnSystem.Value * 2 - 1));
  429. var graduateSchoolyear = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
  430. if (graduateSchoolyear == null)
  431. {
  432. throw new Exception("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
  433. }
  434. //数据有误验证
  435. if (grademajorView.GrademajorID != Guid.Empty)
  436. {
  437. var grademajor = GrademajorDAL.GrademajorRepository.GetList(x => x.GrademajorID == grademajorView.GrademajorID).SingleOrDefault();
  438. if (grademajor == null)
  439. {
  440. throw new Exception("数据有误,请核查。");
  441. }
  442. else
  443. {
  444. //表示修改(暂时不考虑对应的班级信息下的学生拟毕业日期的更新,后续再处理)
  445. //目前通过修改对应的班级信息来更新
  446. grademajor.FacultymajorID = grademajorView.FacultymajorID;
  447. grademajor.Code = grademajorView.Code.Trim();
  448. grademajor.Name = grademajorView.Name;
  449. grademajor.Abbreviation = grademajorView.Abbreviation;
  450. grademajor.GradeID = grademajorView.GradeID;
  451. grademajor.SemesterID = grademajorView.SemesterID;
  452. grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
  453. grademajor.Professional = grademajorView.Professional;
  454. grademajor.Remark = grademajorView.Remark;
  455. SetModifyStatus(grademajor);
  456. }
  457. }
  458. else
  459. {
  460. //表示新增
  461. CF_Grademajor grademajor = new CF_Grademajor();
  462. grademajor.GrademajorID = Guid.NewGuid();
  463. grademajor.FacultymajorID = grademajorView.FacultymajorID;
  464. grademajor.Code = grademajorView.Code.Trim();
  465. grademajor.Name = grademajorView.Name;
  466. grademajor.Abbreviation = grademajorView.Abbreviation;
  467. grademajor.GradeID = grademajorView.GradeID;
  468. grademajor.SemesterID = grademajorView.SemesterID;
  469. grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
  470. grademajor.Professional = grademajorView.Professional;
  471. grademajor.Remark = grademajorView.Remark;
  472. SetNewStatus(grademajor);
  473. UnitOfWork.Add(grademajor);
  474. }
  475. }
  476. else
  477. {
  478. throw new Exception("已存在相同的年级专业编号或年级专业名称,请核查。");
  479. }
  480. //事务提交
  481. UnitOfWork.Commit();
  482. }
  483. catch (Exception ex)
  484. {
  485. throw new Exception(ex.Message);
  486. }
  487. }
  488. /// <summary>
  489. /// 批量新增
  490. /// </summary>
  491. /// <param name="grademajorView"></param>
  492. /// <returns></returns>
  493. public int GrademajorBatchAdd(GrademajorView grademajorView)
  494. {
  495. try
  496. {
  497. List<CF_Grademajor> grade = new List<CF_Grademajor>();
  498. //获取源数据
  499. var Grademajor = GrademajorDAL.GetGrademajorViwQueryable(x => x.GradeID == grademajorView.GradeID);
  500. if (grademajorView.CollegeID != null)
  501. {
  502. Grademajor = Grademajor.Where(x => x.CollegeID == grademajorView.CollegeID);
  503. }
  504. if (grademajorView.StandardID != null && grademajorView.StandardID != -1)
  505. {
  506. Grademajor = Grademajor.Where(x => x.StandardID == grademajorView.StandardID);
  507. }
  508. //获取年级专业
  509. var GrademajorList = Grademajor.ToList();
  510. //获取学年学期
  511. var SchoolYearList = GrademajorDAL.SchoolyearRepository.GetList(x => x.RecordStatus == (int)SYS_STATUS.USABLE).ToList();
  512. //获取院系专业
  513. var FacultymajorIDList = GrademajorList.Select(x => x.FacultymajorID).ToList();
  514. var Facultymajorlist = GrademajorDAL.FacultymajorRepository.GetList(x => FacultymajorIDList.Contains(x.FacultymajorID)).ToList();
  515. //获取目标年级已存在数据
  516. var BatchGrademajor = GrademajorDAL.GetGrademajorViwQueryable(x => x.GradeID == grademajorView.BatchGradeID);
  517. if (grademajorView.CollegeID != null)
  518. {
  519. BatchGrademajor = BatchGrademajor.Where(x => x.CollegeID == grademajorView.CollegeID);
  520. }
  521. if (grademajorView.StandardID != null && grademajorView.StandardID != -1)
  522. {
  523. BatchGrademajor = BatchGrademajor.Where(x => x.StandardID == grademajorView.StandardID);
  524. }
  525. var BatchGrademajorList = BatchGrademajor.ToList();
  526. //插入数据
  527. foreach (var g in GrademajorList)
  528. {
  529. CF_Facultymajor facultymajor = new CF_Facultymajor();
  530. facultymajor = Facultymajorlist.Where(x => x.FacultymajorID == g.FacultymajorID).FirstOrDefault();
  531. var graduateSchoolyearValue = (grademajorView.BatchGradeID.Value * 2) - 1 + (g.SemesterID.Value - 1);
  532. graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(facultymajor.LearnSystem.Value * 2 - 1));
  533. var graduateSchoolyear = SchoolYearList.Where(x => x.Value == graduateSchoolyearValue).FirstOrDefault();
  534. CF_Grademajor grademajor = new CF_Grademajor();
  535. if (graduateSchoolyear == null)
  536. {
  537. throw new Exception("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
  538. }
  539. string gradeID = g.GradeID.ToString();
  540. string batchGradeID = grademajorView.BatchGradeID.Value.ToString();
  541. //替换复制的年级专业代码
  542. string Code = g.Code.Trim().Replace(gradeID, batchGradeID);
  543. //替换复制的年级专业名称
  544. string Name = g.Name.Trim().Replace(gradeID, batchGradeID);
  545. //替换复制的年级专业简称
  546. string Abbreviation = g.Abbreviation;
  547. if (g.Abbreviation != null)
  548. {
  549. Abbreviation = g.Abbreviation.Trim().Replace(gradeID, batchGradeID);
  550. }
  551. grademajor.GrademajorID = Guid.NewGuid();
  552. grademajor.Code = Code;
  553. grademajor.Name = Name;
  554. grademajor.Abbreviation = Abbreviation;
  555. grademajor.GradeID = grademajorView.BatchGradeID;
  556. grademajor.Professional = g.Professional;
  557. grademajor.SemesterID = g.SemesterID;
  558. grademajor.FacultymajorID = g.FacultymajorID;
  559. grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
  560. grademajor.Remark = g.Remark;
  561. SetNewStatus(grademajor);
  562. if (!grademajorView.IsOverwrite)
  563. {
  564. var batch = BatchGrademajorList.Where(x => x.Code == Code && x.GradeID == grademajorView.BatchGradeID && x.FacultymajorID == g.FacultymajorID).FirstOrDefault();
  565. if (batch == null)
  566. {
  567. grade.Add(grademajor);
  568. }
  569. }
  570. else
  571. {
  572. var BatchGrademajorIDList = BatchGrademajorList.Select(x => x.GrademajorID).ToList();
  573. List<Guid> ids = new List<Guid>();
  574. if (BatchGrademajorIDList.Count > 0)
  575. {
  576. foreach (var id in BatchGrademajorIDList)
  577. {
  578. ids.Add(id);
  579. }
  580. UnitOfWork.Remove<CF_Grademajor>(x => ids.Contains(x.GrademajorID));
  581. }
  582. grade.Add(grademajor);
  583. }
  584. }
  585. UnitOfWork.BulkInsert(grade);
  586. UnitOfWork.Commit();
  587. return grade.Count();
  588. }
  589. catch (Exception ex)
  590. {
  591. throw new Exception(ex.Message);
  592. }
  593. }
  594. /// <summary>
  595. /// 删除
  596. /// </summary>
  597. /// <param name="grademajorIDList"></param>
  598. /// <returns></returns>
  599. public bool GrademajorDelete(List<Guid?> grademajorIDList)
  600. {
  601. try
  602. {
  603. UnitOfWork.Delete<CF_Grademajor>(x => grademajorIDList.Contains(x.GrademajorID));
  604. return true;
  605. }
  606. catch (Exception)
  607. {
  608. throw;
  609. }
  610. }
  611. /// <summary>
  612. /// 查询年级专业对应的班级信息ClassmajorView(带对应的在校状态学生人数)
  613. /// </summary>
  614. /// <param name="configuretView"></param>
  615. /// <param name="grademajorID"></param>
  616. /// <param name="inSchoolStatus"></param>
  617. /// <param name="pageIndex"></param>
  618. /// <param name="pageSize"></param>
  619. /// <returns></returns>
  620. public IGridResultSet<ClassmajorView> GetClassmajorViewGrid(ConfiguretView configuretView, Guid? grademajorID, int? inSchoolStatus, int pageIndex, int pageSize)
  621. {
  622. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  623. expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
  624. //学生信息
  625. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  626. if (inSchoolStatus != null && inSchoolStatus > -1)
  627. {
  628. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  629. if (inSchoolStatus == 1)
  630. {
  631. //表示在校
  632. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  633. }
  634. if (inSchoolStatus == 0)
  635. {
  636. //不在校
  637. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  638. }
  639. }
  640. var query = GrademajorDAL.GetClassmajorViewQueryable(expGrademajor, expStudent);
  641. //if (inSchoolStatus != null && inSchoolStatus > -1)
  642. //{
  643. // //排除人数为0的信息
  644. // query = query.Where(x => x.StudentCount > 0);
  645. //}
  646. //查询条件
  647. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  648. {
  649. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  650. }
  651. return query.OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID).ThenBy(x => x.No.Length)
  652. .ThenBy(x => x.No).ThenBy(x => x.ClassNum).ToGridResultSet<ClassmajorView>(pageIndex, pageSize);
  653. }
  654. /// <summary>
  655. /// 查询年级专业对应的班级信息List(带对应的在校状态学生人数)
  656. /// </summary>
  657. /// <param name="configuretView"></param>
  658. /// <param name="grademajorID"></param>
  659. /// <param name="inSchoolStatus"></param>
  660. /// <returns></returns>
  661. public IList<ClassmajorView> GetClassmajorViewList(ConfiguretView configuretView, Guid? grademajorID, int? inSchoolStatus)
  662. {
  663. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  664. expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
  665. //学生信息
  666. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  667. if (inSchoolStatus != null && inSchoolStatus > -1)
  668. {
  669. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  670. if (inSchoolStatus == 1)
  671. {
  672. //表示在校
  673. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  674. }
  675. if (inSchoolStatus == 0)
  676. {
  677. //不在校
  678. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  679. }
  680. }
  681. var query = GrademajorDAL.GetClassmajorViewQueryable(expGrademajor, expStudent);
  682. //if (inSchoolStatus != null && inSchoolStatus > -1)
  683. //{
  684. // //排除人数为0的信息
  685. // query = query.Where(x => x.StudentCount > 0);
  686. //}
  687. //查询条件
  688. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  689. {
  690. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  691. }
  692. return query.OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID).ThenBy(x => x.No.Length)
  693. .ThenBy(x => x.No).ThenBy(x => x.ClassNum).ToList();
  694. }
  695. /// <summary>
  696. /// 查询年级专业对应的学生信息BaseStudentView
  697. /// </summary>
  698. /// <param name="configuretView"></param>
  699. /// <param name="grademajorID"></param>
  700. /// <param name="inSchoolStatus"></param>
  701. /// <param name="pageIndex"></param>
  702. /// <param name="pageSize"></param>
  703. /// <returns></returns>
  704. public IGridResultSet<StudentBaseView> GetStudentBaseViewGrid(ConfiguretView configuretView, Guid? grademajorID, int? inSchoolStatus, int pageIndex, int pageSize)
  705. {
  706. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  707. expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
  708. //学生信息
  709. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  710. if (inSchoolStatus != null && inSchoolStatus > -1)
  711. {
  712. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  713. if (inSchoolStatus == 1)
  714. {
  715. //表示在校
  716. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  717. }
  718. if (inSchoolStatus == 0)
  719. {
  720. //不在校
  721. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  722. }
  723. }
  724. var query = GrademajorDAL.GetStudentBaseViewQueryable(expGrademajor, expStudent);
  725. //查询条件
  726. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  727. {
  728. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  729. }
  730. return query.OrderBy(x => x.LoginID).ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo).ToGridResultSet<StudentBaseView>(pageIndex, pageSize);
  731. }
  732. /// <summary>
  733. /// 查询年级专业对应的学生信息List
  734. /// </summary>
  735. /// <param name="configuretView"></param>
  736. /// <param name="grademajorID"></param>
  737. /// <param name="inSchoolStatus"></param>
  738. /// <returns></returns>
  739. public IList<StudentBaseView> GetStudentBaseViewList(ConfiguretView configuretView, Guid? grademajorID, int? inSchoolStatus)
  740. {
  741. Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  742. expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
  743. //学生信息
  744. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  745. if (inSchoolStatus != null && inSchoolStatus > -1)
  746. {
  747. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  748. if (inSchoolStatus == 1)
  749. {
  750. //表示在校
  751. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  752. }
  753. if (inSchoolStatus == 0)
  754. {
  755. //不在校
  756. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  757. }
  758. }
  759. var query = GrademajorDAL.GetStudentBaseViewQueryable(expGrademajor, expStudent);
  760. //查询条件
  761. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  762. {
  763. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  764. }
  765. return query.OrderBy(x => x.LoginID).ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo).ToList();
  766. }
  767. /// <summary>
  768. /// 批量修改(重写)
  769. /// 暂时不考虑对应的班级信息下的学生拟毕业日期的更新,后续再处理
  770. /// 目前通过修改对应的班级信息来更新
  771. /// </summary>
  772. /// <param name="grademajorIDs"></param>
  773. /// <param name="gradeID"></param>
  774. /// <param name="semesterID"></param>
  775. /// <returns></returns>
  776. public string BatchModify(string grademajorIDs, int? gradeID, int? semesterID)
  777. {
  778. List<Guid> list = new List<Guid>();
  779. HashSet<string> hs = new HashSet<string>();
  780. for (int i = 0; i < grademajorIDs.Split(',').Length; i++)
  781. {
  782. string id = grademajorIDs.Split(',')[i];
  783. if (!string.IsNullOrEmpty(id))
  784. {
  785. Guid grademajorID = new Guid(id);
  786. list.Add(grademajorID);
  787. }
  788. }
  789. int sCount = 0;
  790. int lCount = 0;
  791. foreach (Guid li in list)
  792. {
  793. GrademajorView grademajorView = GrademajorDAL.GetGrademajorViwQueryable(x => x.GrademajorID == li).FirstOrDefault();
  794. CF_Grademajor grademajor = new CF_Grademajor();
  795. grademajor = GrademajorDAL.GrademajorRepository.GetSingle(x => x.GrademajorID == li);
  796. if (gradeID != null)
  797. {
  798. sCount++;
  799. grademajor.GradeID = gradeID;
  800. var graduateSchoolyearValue = (gradeID * 2) - 1 + ((int)grademajor.SemesterID - 1);
  801. graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling((double)grademajorView.LearnSystem * 2 - 1));
  802. var graduateSchoolyear = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
  803. if (graduateSchoolyear == null)
  804. {
  805. lCount++;
  806. hs.Add("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
  807. continue;
  808. }
  809. else
  810. {
  811. grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
  812. }
  813. }
  814. if (semesterID != null)
  815. {
  816. sCount++;
  817. grademajor.SemesterID = semesterID;
  818. var graduateSchoolyearValue = (grademajor.GradeID * 2) - 1 + ((int)semesterID - 1);
  819. graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling((double)grademajorView.LearnSystem * 2 - 1));
  820. var graduateSchoolyear = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
  821. if (graduateSchoolyear == null)
  822. {
  823. lCount++;
  824. hs.Add("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
  825. continue;
  826. }
  827. else
  828. {
  829. grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
  830. }
  831. }
  832. SetModifyStatus(grademajor);
  833. UnitOfWork.Commit();
  834. }
  835. StringBuilder sb = new StringBuilder();
  836. int s = hs.Count();
  837. foreach (string li in hs)
  838. {
  839. sb.Append(li);
  840. }
  841. if (lCount > 0)
  842. {
  843. return "批量修改成功" + (grademajorIDs.Split(',').Length - lCount) + "条,批量修改失败" + lCount + "条,失败原因:" + sb;
  844. }
  845. else
  846. {
  847. return "批量修改成功" + (grademajorIDs.Split(',').Length - lCount) + "条";
  848. }
  849. }
  850. /// <summary>
  851. /// 年级专业信息Excel导入
  852. /// </summary>
  853. /// <param name="cellheader"></param>
  854. /// <param name="inCount"></param>
  855. /// <param name="upCount"></param>
  856. /// <param name="errdataList"></param>
  857. /// <param name="errCount"></param>
  858. /// <param name="sourcePhysicalPath"></param>
  859. public void GrademajorImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<GrademajorView> errdataList, out int? errCount, string sourcePhysicalPath)
  860. {
  861. try
  862. {
  863. StringBuilder errorMsg = new StringBuilder();
  864. List<GrademajorView> errList = new List<GrademajorView>();
  865. cellheader.Remove("ErrorMessage");
  866. List<GrademajorView> enlist = NpoiExcelHelper.ExcelToEntityList<GrademajorView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  867. cellheader.Add("ErrorMessage", "未导入原因");
  868. //对List集合进行有效性校验
  869. if (enlist.Count() <= 0)
  870. {
  871. throw new Exception("Excel文件数据为空,请检查。");
  872. }
  873. Regex reg = null; //正则表达式
  874. //DateTime result; //用于返回判断日期字段格式
  875. inCount = 0; //导入个数
  876. upCount = 0; //更新个数
  877. errCount = 0; //失败个数
  878. string errorMsgStr = ""; //错误信息
  879. List<CF_Grademajor> newGrademajorInList = new List<CF_Grademajor>();
  880. List<CF_Grademajor> newGrademajorUpList = new List<CF_Grademajor>();
  881. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  882. //年级专业信息
  883. var grademajorList = GrademajorDAL.GrademajorRepository.GetList(x => true).ToList();
  884. //年级专业编号
  885. var grademajorCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).ToList();
  886. //年级专业名称
  887. var grademajorNameList = enlist.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).ToList();
  888. //对比后的newGrademajorList
  889. var newGrademajorList = grademajorList.Where(x => grademajorCodeList.Contains(x.Code) || grademajorNameList.Contains(x.Name)).ToList();
  890. //院系专业信息
  891. var facultymajorList = GrademajorDAL.FacultymajorRepository.GetList(x => true).ToList();
  892. //院系专业编号
  893. var facultymajorCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.FacultymajorCode)).Select(x => x.FacultymajorCode).ToList();
  894. //对比后的newFacultymajorList
  895. var newFacultymajorList = facultymajorList.Where(x => facultymajorCodeList.Contains(x.Code)).ToList();
  896. //年级
  897. var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList();
  898. //学期
  899. var semesterList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester).ToList();
  900. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  901. for (int i = 0; i < enlist.Count; i++)
  902. {
  903. GrademajorView en = enlist[i]; //Excel表数据视图
  904. CF_Grademajor newGrademajor = new CF_Grademajor();
  905. //年级专业编号
  906. if (string.IsNullOrEmpty(en.Code))
  907. {
  908. errCount++;
  909. errorMsgStr = "年级专业编号不能为空";
  910. en.ErrorMessage = errorMsgStr;
  911. errList.Add(en);
  912. errorMsg.AppendLine(errorMsgStr);
  913. continue;
  914. }
  915. else
  916. {
  917. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  918. if (!reg.IsMatch(en.Code))
  919. {
  920. errCount++;
  921. errorMsgStr = "年级专业编号格式不正确,请检查(数字或英文字母)";
  922. en.ErrorMessage = errorMsgStr;
  923. errList.Add(en);
  924. errorMsg.AppendLine(errorMsgStr);
  925. continue;
  926. }
  927. else
  928. {
  929. //年级专业编号
  930. newGrademajor.Code = en.Code.Trim();
  931. }
  932. }
  933. //年级专业名称
  934. if (string.IsNullOrEmpty(en.Name))
  935. {
  936. errCount++;
  937. errorMsgStr = "年级专业名称不能为空";
  938. en.ErrorMessage = errorMsgStr;
  939. errList.Add(en);
  940. errorMsg.AppendLine(errorMsgStr);
  941. continue;
  942. }
  943. else
  944. {
  945. //年级专业名称
  946. newGrademajor.Name = en.Name.Trim();
  947. }
  948. //简称
  949. if (string.IsNullOrEmpty(en.Abbreviation))
  950. {
  951. //不考虑
  952. }
  953. else
  954. {
  955. newGrademajor.Abbreviation = en.Abbreviation;
  956. }
  957. //院系专业编号
  958. if (string.IsNullOrEmpty(en.FacultymajorCode))
  959. {
  960. errCount++;
  961. errorMsgStr = "院系专业编号不能为空";
  962. en.ErrorMessage = errorMsgStr;
  963. errList.Add(en);
  964. errorMsg.AppendLine(errorMsgStr);
  965. continue;
  966. }
  967. else
  968. {
  969. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  970. if (!reg.IsMatch(en.FacultymajorCode))
  971. {
  972. errCount++;
  973. errorMsgStr = "院系专业编号格式不正确,请检查(数字或英文字母)";
  974. en.ErrorMessage = errorMsgStr;
  975. errList.Add(en);
  976. errorMsg.AppendLine(errorMsgStr);
  977. continue;
  978. }
  979. else
  980. {
  981. //暂时不考虑院系专业编号有相同的情况
  982. var facultymajor = newFacultymajorList.Where(x => x.Code == en.FacultymajorCode.Trim()).SingleOrDefault();
  983. if (facultymajor == null)
  984. {
  985. errCount++;
  986. errorMsgStr = "院系专业编号不存在,请检查";
  987. en.ErrorMessage = errorMsgStr;
  988. errList.Add(en);
  989. errorMsg.AppendLine(errorMsgStr);
  990. continue;
  991. }
  992. else
  993. {
  994. //院系专业信息ID
  995. newGrademajor.FacultymajorID = facultymajor.FacultymajorID;
  996. //学制(用于计算毕业学期)
  997. en.LearnSystem = facultymajor.LearnSystem;
  998. }
  999. }
  1000. }
  1001. //年级
  1002. if (string.IsNullOrEmpty(en.GradeStr))
  1003. {
  1004. errCount++;
  1005. errorMsgStr = "年级不能为空";
  1006. en.ErrorMessage = errorMsgStr;
  1007. errList.Add(en);
  1008. errorMsg.AppendLine(errorMsgStr);
  1009. continue;
  1010. }
  1011. else
  1012. {
  1013. var grade = gradeList.Where(x => x.Name == en.GradeStr.Trim()).SingleOrDefault();
  1014. if (grade == null)
  1015. {
  1016. errCount++;
  1017. errorMsgStr = "年级不存在,请检查";
  1018. en.ErrorMessage = errorMsgStr;
  1019. errList.Add(en);
  1020. errorMsg.AppendLine(errorMsgStr);
  1021. continue;
  1022. }
  1023. else
  1024. {
  1025. //年级
  1026. newGrademajor.GradeID = grade.Value;
  1027. }
  1028. }
  1029. //入学学期
  1030. if (string.IsNullOrEmpty(en.SemesterStr))
  1031. {
  1032. errCount++;
  1033. errorMsgStr = "入学学期不能为空";
  1034. en.ErrorMessage = errorMsgStr;
  1035. errList.Add(en);
  1036. errorMsg.AppendLine(errorMsgStr);
  1037. continue;
  1038. }
  1039. else
  1040. {
  1041. var semester = semesterList.Where(x => x.Name == en.SemesterStr.Trim()).SingleOrDefault();
  1042. if (semester == null)
  1043. {
  1044. errCount++;
  1045. errorMsgStr = "入学学期不存在,请检查";
  1046. en.ErrorMessage = errorMsgStr;
  1047. errList.Add(en);
  1048. errorMsg.AppendLine(errorMsgStr);
  1049. continue;
  1050. }
  1051. else
  1052. {
  1053. //入学学期
  1054. newGrademajor.SemesterID = semester.Value;
  1055. }
  1056. }
  1057. //专业方向
  1058. if (string.IsNullOrEmpty(en.Professional))
  1059. {
  1060. //不考虑
  1061. }
  1062. else
  1063. {
  1064. newGrademajor.Professional = en.Professional;
  1065. }
  1066. //备注
  1067. if (string.IsNullOrEmpty(en.Remark))
  1068. {
  1069. //不考虑
  1070. }
  1071. else
  1072. {
  1073. newGrademajor.Remark = en.Remark;
  1074. }
  1075. //学制
  1076. if (en.LearnSystem == null)
  1077. {
  1078. errCount++;
  1079. errorMsgStr = "院系专业编号中对应的学制有误(不能为空),请检查";
  1080. en.ErrorMessage = errorMsgStr;
  1081. errList.Add(en);
  1082. errorMsg.AppendLine(errorMsgStr);
  1083. continue;
  1084. }
  1085. else
  1086. {
  1087. //计算相应的毕业学年学期Value
  1088. var graduateSchoolyearValue = (newGrademajor.GradeID.Value * 2) - 1 + (newGrademajor.SemesterID.Value - 1);
  1089. graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(en.LearnSystem.Value * 2 - 1));
  1090. var graduateSchoolyear = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
  1091. if (graduateSchoolyear == null)
  1092. {
  1093. errCount++;
  1094. errorMsgStr = "预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作,请检查";
  1095. en.ErrorMessage = errorMsgStr;
  1096. errList.Add(en);
  1097. errorMsg.AppendLine(errorMsgStr);
  1098. continue;
  1099. }
  1100. else
  1101. {
  1102. newGrademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
  1103. }
  1104. }
  1105. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  1106. //for (int j = i + 1; j < enlist.Count; j++)
  1107. //{
  1108. // NewGrademajorView enA = enlist[j];
  1109. // //根据Excel表中的业务主键进行去重(年级专业编号或年级专业名称唯一)
  1110. // if (en.No == enA.No && en.Name == enA.Name)
  1111. // {
  1112. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  1113. // }
  1114. //}
  1115. //数据表重复性验证(年级专业编号或年级专业名称唯一)
  1116. var grademajorVerify = newGrademajorList.Where(x => x.Code == newGrademajor.Code || x.Name == newGrademajor.Name).FirstOrDefault();
  1117. if (grademajorVerify == null)
  1118. {
  1119. //新增
  1120. if (!newGrademajorInList.Any(x => x.Code == newGrademajor.Code || x.Name == newGrademajor.Name))
  1121. {
  1122. //CF_Grademajor表
  1123. newGrademajor.GrademajorID = Guid.NewGuid();
  1124. SetNewStatus(newGrademajor);
  1125. newGrademajorInList.Add(newGrademajor);
  1126. inCount++;
  1127. }
  1128. else
  1129. {
  1130. //Excel表重复性验证
  1131. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  1132. inCount++;
  1133. }
  1134. }
  1135. else
  1136. {
  1137. //更新(Excel有重复时,以最后一条记录的更新为准)
  1138. grademajorVerify.Abbreviation = newGrademajor.Abbreviation;
  1139. grademajorVerify.FacultymajorID = newGrademajor.FacultymajorID;
  1140. grademajorVerify.GradeID = newGrademajor.GradeID;
  1141. grademajorVerify.SemesterID = newGrademajor.SemesterID;
  1142. grademajorVerify.GraduateSchoolyearID = newGrademajor.GraduateSchoolyearID;
  1143. grademajorVerify.Professional = newGrademajor.Professional;
  1144. grademajorVerify.Remark = newGrademajor.Remark;
  1145. SetModifyStatus(grademajorVerify);
  1146. newGrademajorUpList.Add(grademajorVerify);
  1147. upCount++;
  1148. }
  1149. }
  1150. using (TransactionScope ts = new TransactionScope())
  1151. {
  1152. UnitOfWork.BulkInsert(newGrademajorInList);
  1153. //批量统一提交更新
  1154. if (newGrademajorUpList != null && newGrademajorUpList.Count() > 0)
  1155. {
  1156. UnitOfWork.BatchUpdate(newGrademajorUpList);
  1157. }
  1158. ts.Complete();
  1159. }
  1160. errdataList = errList.Distinct().ToList(); //错误列表List
  1161. }
  1162. catch (Exception)
  1163. {
  1164. throw;
  1165. }
  1166. }
  1167. }
  1168. }