ClassmajorServices.cs 58 KB

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