NewStudentServices.cs 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  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.Data;
  8. using System.IO;
  9. using System.Transactions;
  10. using Bowin.Common.Utility;
  11. using Bowin.Common.Linq;
  12. using Bowin.Common.Linq.Entity;
  13. using EMIS.Entities;
  14. using EMIS.Utility;
  15. using EMIS.ViewModel;
  16. using EMIS.ViewModel.CacheManage;
  17. using EMIS.ViewModel.EnrollManage.NewStudentManage;
  18. using EMIS.DataLogic.EnrollManage.NewStudentManage;
  19. namespace EMIS.CommonLogic.EnrollManage.NewStudentManage
  20. {
  21. public class NewStudentServices : BaseServices, INewStudentServices
  22. {
  23. public NewStudentDAL NewStudentDAL { get; set; }
  24. /// <summary>
  25. /// 查询对应的新生名单信息View
  26. /// </summary>
  27. /// <param name="configuretView"></param>
  28. /// <param name="gradeID"></param>
  29. /// <param name="standardID"></param>
  30. /// <param name="educationID"></param>
  31. /// <param name="learningformID"></param>
  32. /// <param name="learnSystem"></param>
  33. /// <param name="isPhoto"></param>
  34. /// <param name="pageIndex"></param>
  35. /// <param name="pageSize"></param>
  36. /// <returns></returns>
  37. public IGridResultSet<NewStudentView> GetNewStudentViewGrid(ConfiguretView configuretView, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? isPhoto, int pageIndex, int pageSize)
  38. {
  39. Expression<Func<CF_NewStudent, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  40. exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
  41. if (gradeID.HasValue)
  42. {
  43. exp = exp.And(x => x.GradeID == gradeID);
  44. }
  45. if (isPhoto.HasValue)
  46. {
  47. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  48. {
  49. exp = exp.And(x => x.RecruitPictureUrl != null && x.RecruitPictureUrl != "");
  50. }
  51. if (isPhoto.Value == (int)CF_GeneralExist.No)
  52. {
  53. exp = exp.And(x => x.RecruitPictureUrl == null || x.RecruitPictureUrl == "");
  54. }
  55. }
  56. var query = NewStudentDAL.GetNewStudentViewQueryable(exp);
  57. if (standardID.HasValue)
  58. {
  59. query = query.Where(x => x.StandardID == standardID);
  60. }
  61. if (educationID.HasValue)
  62. {
  63. query = query.Where(x => x.EducationID == educationID);
  64. }
  65. if (learningformID.HasValue)
  66. {
  67. query = query.Where(x => x.LearningformID == learningformID);
  68. }
  69. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  70. {
  71. var LearnSystems = Convert.ToDecimal(learnSystem);
  72. query = query.Where(x => x.LearnSystem == LearnSystems);
  73. }
  74. //查询条件
  75. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  76. {
  77. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  78. }
  79. return query.OrderByDescending(x => x.GradeID).ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID)
  80. .ThenBy(x => x.LearnSystem).ToGridResultSet<NewStudentView>(pageIndex, pageSize);
  81. }
  82. /// <summary>
  83. /// 查询对应的新生名单信息List
  84. /// </summary>
  85. /// <param name="configuretView"></param>
  86. /// <param name="gradeID"></param>
  87. /// <param name="standardID"></param>
  88. /// <param name="educationID"></param>
  89. /// <param name="learningformID"></param>
  90. /// <param name="learnSystem"></param>
  91. /// <param name="isPhoto"></param>
  92. /// <returns></returns>
  93. public IList<NewStudentView> GetNewStudentViewList(ConfiguretView configuretView, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? isPhoto)
  94. {
  95. Expression<Func<CF_NewStudent, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  96. exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
  97. if (gradeID.HasValue)
  98. {
  99. exp = exp.And(x => x.GradeID == gradeID);
  100. }
  101. if (isPhoto.HasValue)
  102. {
  103. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  104. {
  105. exp = exp.And(x => x.RecruitPictureUrl != null && x.RecruitPictureUrl != "");
  106. }
  107. if (isPhoto.Value == (int)CF_GeneralExist.No)
  108. {
  109. exp = exp.And(x => x.RecruitPictureUrl == null || x.RecruitPictureUrl == "");
  110. }
  111. }
  112. var query = NewStudentDAL.GetNewStudentViewQueryable(exp);
  113. if (standardID.HasValue)
  114. {
  115. query = query.Where(x => x.StandardID == standardID);
  116. }
  117. if (educationID.HasValue)
  118. {
  119. query = query.Where(x => x.EducationID == educationID);
  120. }
  121. if (learningformID.HasValue)
  122. {
  123. query = query.Where(x => x.LearningformID == learningformID);
  124. }
  125. if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
  126. {
  127. var LearnSystems = Convert.ToDecimal(learnSystem);
  128. query = query.Where(x => x.LearnSystem == LearnSystems);
  129. }
  130. //查询条件
  131. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  132. {
  133. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  134. }
  135. return query.OrderByDescending(x => x.GradeID).ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID)
  136. .ThenBy(x => x.LearnSystem).ToList();
  137. }
  138. /// <summary>
  139. /// 查询对应的新生名单信息NewStudentView
  140. /// </summary>
  141. /// <param name="newStudentID"></param>
  142. /// <returns></returns>
  143. public NewStudentView GetNewStudentView(Guid? newStudentID)
  144. {
  145. try
  146. {
  147. Expression<Func<CF_NewStudent, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  148. exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
  149. exp = exp.And(x => x.NewStudentID == newStudentID);
  150. var query = NewStudentDAL.GetNewStudentViewQueryable(exp).SingleOrDefault();
  151. return query;
  152. }
  153. catch (Exception ex)
  154. {
  155. throw new Exception(ex.Message);
  156. }
  157. }
  158. /// <summary>
  159. /// 编辑(新增、修改,业务主键:考生号唯一)
  160. /// </summary>
  161. /// <param name="newStudentView"></param>
  162. /// <param name="photoUrl"></param>
  163. public void NewStudentEdit(NewStudentView newStudentView, string photoUrl)
  164. {
  165. try
  166. {
  167. var examineeNumVerify = NewStudentDAL.NewStudentRepository.GetList(x => x.NewStudentID != newStudentView.NewStudentID
  168. && x.ExamineeNum == newStudentView.ExamineeNum.Trim()).SingleOrDefault();
  169. if (examineeNumVerify == null)
  170. {
  171. //if (!string.IsNullOrEmpty(newStudentView.AdmissionTicketNo))
  172. //{
  173. // var admissionTicketNoVerify = NewStudentDAL.NewStudentRepository.GetList(x => x.NewStudentID != newStudentView.NewStudentID
  174. // && x.AdmissionTicketNo == newStudentView.AdmissionTicketNo.Trim()).SingleOrDefault();
  175. // if (admissionTicketNoVerify != null)
  176. // {
  177. // if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
  178. // {
  179. // throw new Exception("新生分配信息中已存在此准考证号(准考证号重复),请核查。");
  180. // }
  181. // else if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
  182. // {
  183. // throw new Exception("录取名单信息中已存在此准考证号(准考证号重复),请核查。");
  184. // }
  185. // else
  186. // {
  187. // throw new Exception("已存在相同的准考证号(准考证号重复),请核查。");
  188. // }
  189. // }
  190. //}
  191. if (newStudentView.NewStudentID != Guid.Empty)
  192. {
  193. var newStudent = NewStudentDAL.NewStudentRepository.GetList(x => x.NewStudentID == newStudentView.NewStudentID
  194. && x.AssignStatus == (int)CF_AssignStatus.NotAssigned).SingleOrDefault();
  195. if (newStudent == null)
  196. {
  197. throw new Exception("数据有误,请核查。");
  198. }
  199. else
  200. {
  201. //表示修改
  202. newStudent.ExamineeNum = newStudentView.ExamineeNum.Trim();
  203. if (!string.IsNullOrEmpty(newStudentView.AdmissionTicketNo))
  204. {
  205. newStudent.AdmissionTicketNo = newStudentView.AdmissionTicketNo.Trim();
  206. }
  207. else
  208. {
  209. newStudent.AdmissionTicketNo = newStudentView.AdmissionTicketNo;
  210. }
  211. newStudent.Name = newStudentView.Name;
  212. newStudent.SexID = newStudentView.SexID;
  213. newStudent.NationID = newStudentView.NationID;
  214. newStudent.PoliticsID = newStudentView.PoliticsID;
  215. newStudent.BirthDate = newStudentView.BirthDate;
  216. newStudent.CertificatesType = newStudentView.CertificatesType;
  217. newStudent.IDNumber = newStudentView.IDNumber;
  218. newStudent.GradeID = newStudentView.GradeID;
  219. newStudent.SemesterID = newStudentView.SemesterID;
  220. newStudent.SpecialtyID = newStudentView.SpecialtyID;
  221. newStudent.EntranceDate = newStudentView.EntranceDate;
  222. newStudent.Score = newStudentView.Score;
  223. newStudent.Telephone = newStudentView.Telephone;
  224. newStudent.ZIPCode = newStudentView.ZIPCode;
  225. newStudent.EntranceWayID = newStudentView.EntranceWayID;
  226. newStudent.FeaturesID = newStudentView.FeaturesID;
  227. newStudent.TerritorialID = newStudentView.TerritorialID;
  228. newStudent.Address = newStudentView.Address;
  229. newStudent.Dormitory = newStudentView.Dormitory;
  230. if (!string.IsNullOrEmpty(photoUrl))
  231. {
  232. newStudent.RecruitPictureUrl = photoUrl;
  233. }
  234. newStudent.Remark = newStudentView.Remark;
  235. SetModifyStatus(newStudent);
  236. }
  237. }
  238. else
  239. {
  240. //表示新增
  241. var newStudent = new CF_NewStudent();
  242. newStudent.NewStudentID = Guid.NewGuid();
  243. newStudent.ExamineeNum = newStudentView.ExamineeNum.Trim();
  244. if (!string.IsNullOrEmpty(newStudentView.AdmissionTicketNo))
  245. {
  246. newStudent.AdmissionTicketNo = newStudentView.AdmissionTicketNo.Trim();
  247. }
  248. else
  249. {
  250. newStudent.AdmissionTicketNo = newStudentView.AdmissionTicketNo;
  251. }
  252. newStudent.Name = newStudentView.Name;
  253. newStudent.SexID = newStudentView.SexID;
  254. newStudent.NationID = newStudentView.NationID;
  255. newStudent.PoliticsID = newStudentView.PoliticsID;
  256. newStudent.BirthDate = newStudentView.BirthDate;
  257. newStudent.CertificatesType = newStudentView.CertificatesType;
  258. newStudent.IDNumber = newStudentView.IDNumber;
  259. newStudent.GradeID = newStudentView.GradeID;
  260. newStudent.SemesterID = newStudentView.SemesterID;
  261. newStudent.SpecialtyID = newStudentView.SpecialtyID;
  262. newStudent.EntranceDate = newStudentView.EntranceDate;
  263. newStudent.Score = newStudentView.Score;
  264. newStudent.Telephone = newStudentView.Telephone;
  265. newStudent.ZIPCode = newStudentView.ZIPCode;
  266. newStudent.EntranceWayID = newStudentView.EntranceWayID;
  267. newStudent.FeaturesID = newStudentView.FeaturesID;
  268. newStudent.TerritorialID = newStudentView.TerritorialID;
  269. newStudent.Address = newStudentView.Address;
  270. newStudent.Dormitory = newStudentView.Dormitory;
  271. if (!string.IsNullOrEmpty(photoUrl))
  272. {
  273. newStudent.RecruitPictureUrl = photoUrl;
  274. }
  275. newStudent.IsDoubt = false;
  276. newStudent.AssignStatus = (int)CF_AssignStatus.NotAssigned;
  277. newStudent.Remark = newStudentView.Remark;
  278. SetNewStatus(newStudent, (int)CF_NewStudentEnterStatus.NotSubmitted);
  279. UnitOfWork.Add(newStudent);
  280. }
  281. }
  282. else
  283. {
  284. if (examineeNumVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
  285. {
  286. throw new Exception("新生分配信息中已存在此考生号(考生号重复),请核查。");
  287. }
  288. else if (examineeNumVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
  289. {
  290. throw new Exception("录取名单信息中已存在此考生号(考生号重复),请核查。");
  291. }
  292. else
  293. {
  294. throw new Exception("已存在相同的考生号(考生号重复),请核查。");
  295. }
  296. }
  297. UnitOfWork.Commit();
  298. }
  299. catch (Exception ex)
  300. {
  301. throw new Exception(ex.Message);
  302. }
  303. }
  304. /// <summary>
  305. /// 删除
  306. /// </summary>
  307. /// <param name="newStudentIDList"></param>
  308. /// <returns></returns>
  309. public bool NewStudentDelete(List<Guid?> newStudentIDList)
  310. {
  311. try
  312. {
  313. UnitOfWork.Delete<CF_NewStudent>(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
  314. return true;
  315. }
  316. catch (Exception)
  317. {
  318. throw;
  319. }
  320. }
  321. /// <summary>
  322. /// 删除照片(单个删除)
  323. /// </summary>
  324. /// <param name="newStudentID"></param>
  325. public void DeletePhoto(Guid? newStudentID)
  326. {
  327. try
  328. {
  329. var newStudent = NewStudentDAL.NewStudentRepository.GetList(x => x.NewStudentID == newStudentID && x.AssignStatus == (int)CF_AssignStatus.NotAssigned).SingleOrDefault();
  330. if (newStudent != null)
  331. {
  332. if (!string.IsNullOrEmpty(newStudent.RecruitPictureUrl))
  333. {
  334. FileUploadHelper.DeleteFile(newStudent.RecruitPictureUrl);
  335. newStudent.RecruitPictureUrl = null;
  336. this.UnitOfWork.Commit();
  337. }
  338. else
  339. {
  340. throw new Exception("对应的照片不存在。");
  341. }
  342. }
  343. else
  344. {
  345. throw new Exception("对应的信息未保存,数据有误。");
  346. }
  347. }
  348. catch (Exception ex)
  349. {
  350. throw new Exception(ex.Message);
  351. }
  352. }
  353. /// <summary>
  354. /// 删除照片(批量删除)
  355. /// </summary>
  356. /// <param name="newStudentIDs"></param>
  357. /// <returns></returns>
  358. public bool PicDelete(List<Guid?> newStudentIDs)
  359. {
  360. try
  361. {
  362. List<string> photoUrlList = new List<string>();
  363. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  364. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDs.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.NotAssigned).ToList();
  365. foreach (var newStudent in newStudentList)
  366. {
  367. if (newStudent != null)
  368. {
  369. if (!string.IsNullOrEmpty(newStudent.RecruitPictureUrl))
  370. {
  371. photoUrlList.Add(newStudent.RecruitPictureUrl);
  372. newStudent.RecruitPictureUrl = null;
  373. newStudentUpList.Add(newStudent);
  374. }
  375. }
  376. }
  377. using (TransactionScope ts = new TransactionScope())
  378. {
  379. foreach (var photoUrl in photoUrlList)
  380. {
  381. FileUploadHelper.DeleteFile(photoUrl);
  382. }
  383. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  384. {
  385. UnitOfWork.BatchUpdate(newStudentUpList);
  386. }
  387. //this.UnitOfWork.Commit();
  388. ts.Complete();
  389. }
  390. return true;
  391. }
  392. catch (Exception)
  393. {
  394. throw;
  395. }
  396. }
  397. /// <summary>
  398. /// 导入照片
  399. /// </summary>
  400. /// <param name="photoPaths"></param>
  401. /// <param name="importPicType"></param>
  402. /// <param name="inCount"></param>
  403. /// <param name="errCount"></param>
  404. /// <param name="errDataTable"></param>
  405. public void NewStudentPicImport(IList<string> photoPaths, string importPicType, out int? inCount, out int? errCount, out DataTable errDataTable)
  406. {
  407. try
  408. {
  409. var mapList = photoPaths.Select(s => new
  410. {
  411. PhotoInfo = Path.GetFileName(s).Trim(),
  412. PhotoName = Path.GetFileNameWithoutExtension(s).Trim(),
  413. PhotoPath = s,
  414. }).ToArray();
  415. var photoNameList = mapList.Select(s => s.PhotoName).Distinct().ToList();
  416. inCount = 0;
  417. errCount = 0;
  418. errDataTable = new DataTable();
  419. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  420. if (importPicType.Equals("ExamineeNum"))
  421. {
  422. var newPhotoNameList = new List<string>();
  423. foreach (var photoName in photoNameList)
  424. {
  425. var photoNameStart = photoName.Substring(0, 1);
  426. if (photoNameStart.Equals("F") || photoNameStart.Equals("Z"))
  427. {
  428. newPhotoNameList.Add(photoName.Substring(1));
  429. }
  430. }
  431. errDataTable.Columns.Add("PhotoInfo", typeof(string));
  432. errDataTable.Columns.Add("ExamineeNum", typeof(string));
  433. errDataTable.Columns.Add("ErrorMessage", typeof(string));
  434. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned && (photoNameList.Contains(x.ExamineeNum) || newPhotoNameList.Contains(x.ExamineeNum))).ToList();
  435. foreach (var map in mapList)
  436. {
  437. var photoNameStart = map.PhotoName.Substring(0, 1);
  438. if (photoNameStart.Equals("F") || photoNameStart.Equals("Z"))
  439. {
  440. var newStudent = newStudentList.Where(x => x.ExamineeNum == map.PhotoName || x.ExamineeNum == map.PhotoName.Substring(1)).SingleOrDefault();
  441. if (newStudent == null)
  442. {
  443. DataRow errDataRow = errDataTable.NewRow();
  444. errDataRow["PhotoInfo"] = map.PhotoInfo;
  445. errDataRow["ExamineeNum"] = map.PhotoName;
  446. errDataRow["ErrorMessage"] = "不存在对应的考生号(" + map.PhotoName + ")";
  447. errDataTable.Rows.Add(errDataRow);
  448. errCount++;
  449. }
  450. else
  451. {
  452. newStudent.RecruitPictureUrl = map.PhotoPath;
  453. this.SetModifyStatus(newStudent);
  454. newStudentUpList.Add(newStudent);
  455. inCount++;
  456. }
  457. }
  458. else
  459. {
  460. var newStudent = newStudentList.Where(x => x.ExamineeNum == map.PhotoName).SingleOrDefault();
  461. if (newStudent == null)
  462. {
  463. DataRow errDataRow = errDataTable.NewRow();
  464. errDataRow["PhotoInfo"] = map.PhotoInfo;
  465. errDataRow["ExamineeNum"] = map.PhotoName;
  466. errDataRow["ErrorMessage"] = "不存在对应的考生号(" + map.PhotoName + ")";
  467. errDataTable.Rows.Add(errDataRow);
  468. errCount++;
  469. }
  470. else
  471. {
  472. newStudent.RecruitPictureUrl = map.PhotoPath;
  473. this.SetModifyStatus(newStudent);
  474. newStudentUpList.Add(newStudent);
  475. inCount++;
  476. }
  477. }
  478. }
  479. }
  480. else if (importPicType.Equals("IDNumber"))
  481. {
  482. errDataTable.Columns.Add("PhotoInfo", typeof(string));
  483. errDataTable.Columns.Add("IDNumber", typeof(string));
  484. errDataTable.Columns.Add("ErrorMessage", typeof(string));
  485. var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned && photoNameList.Contains(x.IDNumber)).ToList();
  486. foreach (var map in mapList)
  487. {
  488. var newStudentVerifyList = newStudentList.Where(x => x.IDNumber == map.PhotoName).ToList();
  489. if (newStudentVerifyList != null && newStudentVerifyList.Count() > 1)
  490. {
  491. DataRow errDataRow = errDataTable.NewRow();
  492. errDataRow["PhotoInfo"] = map.PhotoInfo;
  493. errDataRow["IDNumber"] = map.PhotoName;
  494. errDataRow["ErrorMessage"] = "存在多个对应的证件号码(" + map.PhotoName + ")";
  495. errDataTable.Rows.Add(errDataRow);
  496. errCount++;
  497. }
  498. else
  499. {
  500. if (newStudentVerifyList != null && newStudentVerifyList.Count() == 1)
  501. {
  502. var newStudent = newStudentVerifyList.Where(x => x.IDNumber == map.PhotoName).SingleOrDefault();
  503. if (newStudent == null)
  504. {
  505. DataRow errDataRow = errDataTable.NewRow();
  506. errDataRow["PhotoInfo"] = map.PhotoInfo;
  507. errDataRow["IDNumber"] = map.PhotoName;
  508. errDataRow["ErrorMessage"] = "不存在对应的证件号码(" + map.PhotoName + ")";
  509. errDataTable.Rows.Add(errDataRow);
  510. errCount++;
  511. }
  512. else
  513. {
  514. newStudent.RecruitPictureUrl = map.PhotoPath;
  515. this.SetModifyStatus(newStudent);
  516. newStudentUpList.Add(newStudent);
  517. inCount++;
  518. }
  519. }
  520. else
  521. {
  522. DataRow errDataRow = errDataTable.NewRow();
  523. errDataRow["PhotoInfo"] = map.PhotoInfo;
  524. errDataRow["IDNumber"] = map.PhotoName;
  525. errDataRow["ErrorMessage"] = "不存在对应的证件号码(" + map.PhotoName + ")";
  526. errDataTable.Rows.Add(errDataRow);
  527. errCount++;
  528. }
  529. }
  530. }
  531. }
  532. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  533. {
  534. UnitOfWork.BatchUpdate(newStudentUpList);
  535. }
  536. }
  537. catch (Exception)
  538. {
  539. throw;
  540. }
  541. }
  542. /// <summary>
  543. /// Excel导入
  544. /// </summary>
  545. /// <param name="cellheader"></param>
  546. /// <param name="inCount"></param>
  547. /// <param name="upCount"></param>
  548. /// <param name="errdataList"></param>
  549. /// <param name="errCount"></param>
  550. /// <param name="sourcePhysicalPath"></param>
  551. public void NewStudentImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<NewStudentView> errdataList, out int? errCount, string sourcePhysicalPath)
  552. {
  553. try
  554. {
  555. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  556. List<NewStudentView> errList = new List<NewStudentView>();
  557. // 1.1解析文件,存放到一个List集合里
  558. cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
  559. List<NewStudentView> enlist = NpoiExcelHelper.ExcelToEntityList<NewStudentView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  560. cellheader.Add("ErrorMessage", "未导入原因");
  561. //对List集合进行有效性校验
  562. if (enlist.Count() <= 0)
  563. {
  564. throw new Exception("Excel文件数据为空,请检查。");
  565. }
  566. Regex reg = null; //正则表达式
  567. DateTime result; //用于返回判断日期字段格式
  568. inCount = 0; //导入个数
  569. upCount = 0; //更新个数
  570. errCount = 0; //失败个数
  571. string errorMsgStr = ""; //错误信息
  572. List<CF_NewStudent> newStudentInList = new List<CF_NewStudent>();
  573. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  574. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  575. //性别
  576. var sexList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex).ToList();
  577. //民族
  578. var nationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation).ToList();
  579. //政治面貌
  580. var politicsList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Politics).ToList();
  581. //年级
  582. var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList();
  583. //学期
  584. var semesterList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester).ToList();
  585. //专业代码、专业名称、专业ID(Value)
  586. var standardList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard).ToList();
  587. //培养层次(所修学历)
  588. var educationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Education).ToList();
  589. //学习形式
  590. var learningFormList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Learningform).ToList();
  591. //证件类型
  592. var certificatesTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType).ToList();
  593. //专业信息
  594. var specialtyList = NewStudentDAL.SpecialtyRepository.GetList(x => true).ToList();
  595. //考生号
  596. var examineeNumList = enlist.Where(x => !string.IsNullOrEmpty(x.ExamineeNum)).Select(x => x.ExamineeNum.Trim()).ToList();
  597. //新生名单
  598. var newStudentAllList = NewStudentDAL.NewStudentRepository.GetList(x => true).ToList();
  599. //对比后的newStudentList
  600. var newStudentList = newStudentAllList.Where(x => examineeNumList.Contains(x.ExamineeNum)).ToList();
  601. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  602. for (int i = 0; i < enlist.Count; i++)
  603. {
  604. NewStudentView en = enlist[i]; //Excel表数据视图
  605. CF_NewStudent newStudent = new CF_NewStudent();
  606. //考生号
  607. if (string.IsNullOrEmpty(en.ExamineeNum))
  608. {
  609. errCount++;
  610. errorMsgStr = "考生号不能为空";
  611. en.ErrorMessage = errorMsgStr;
  612. errList.Add(en);
  613. errorMsg.AppendLine(errorMsgStr);
  614. continue;
  615. }
  616. else
  617. {
  618. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //考生号正则表达式
  619. if (!reg.IsMatch(en.ExamineeNum))
  620. {
  621. errCount++;
  622. errorMsgStr = "考生号格式不正确,请检查";
  623. en.ErrorMessage = errorMsgStr;
  624. errList.Add(en);
  625. errorMsg.AppendLine(errorMsgStr);
  626. continue;
  627. }
  628. else
  629. {
  630. //考生号
  631. newStudent.ExamineeNum = en.ExamineeNum.Trim();
  632. }
  633. }
  634. //准考证号
  635. if (!string.IsNullOrEmpty(en.AdmissionTicketNo))
  636. {
  637. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //准考证号正则表达式
  638. if (!reg.IsMatch(en.AdmissionTicketNo))
  639. {
  640. errCount++;
  641. errorMsgStr = "准考证号格式不正确,请检查";
  642. en.ErrorMessage = errorMsgStr;
  643. errList.Add(en);
  644. errorMsg.AppendLine(errorMsgStr);
  645. continue;
  646. }
  647. else
  648. {
  649. //准考证号
  650. newStudent.AdmissionTicketNo = en.AdmissionTicketNo.Trim();
  651. }
  652. }
  653. else
  654. {
  655. //为空
  656. }
  657. //姓名
  658. if (string.IsNullOrEmpty(en.Name))
  659. {
  660. errCount++;
  661. errorMsgStr = "姓名不能为空";
  662. en.ErrorMessage = errorMsgStr;
  663. errList.Add(en);
  664. errorMsg.AppendLine(errorMsgStr);
  665. continue;
  666. }
  667. else
  668. {
  669. //姓名
  670. newStudent.Name = en.Name.Trim();
  671. }
  672. //性别
  673. if (string.IsNullOrEmpty(en.SexStr))
  674. {
  675. errCount++;
  676. errorMsgStr = "性别不能为空";
  677. en.ErrorMessage = errorMsgStr;
  678. errList.Add(en);
  679. errorMsg.AppendLine(errorMsgStr);
  680. continue;
  681. }
  682. else
  683. {
  684. var sex = sexList.Where(x => x.Name == en.SexStr.Trim()).SingleOrDefault();
  685. if (sex == null)
  686. {
  687. errCount++;
  688. errorMsgStr = "性别不存在,请检查";
  689. en.ErrorMessage = errorMsgStr;
  690. errList.Add(en);
  691. errorMsg.AppendLine(errorMsgStr);
  692. continue;
  693. }
  694. else
  695. {
  696. //性别
  697. newStudent.SexID = sex.Value;
  698. }
  699. }
  700. //民族
  701. if (string.IsNullOrEmpty(en.NationStr))
  702. {
  703. errCount++;
  704. errorMsgStr = "民族不能为空";
  705. en.ErrorMessage = errorMsgStr;
  706. errList.Add(en);
  707. errorMsg.AppendLine(errorMsgStr);
  708. continue;
  709. }
  710. else
  711. {
  712. var nation = nationList.Where(x => x.Name == en.NationStr.Trim()).SingleOrDefault();
  713. if (nation == null)
  714. {
  715. errCount++;
  716. errorMsgStr = "民族不存在,请检查";
  717. en.ErrorMessage = errorMsgStr;
  718. errList.Add(en);
  719. errorMsg.AppendLine(errorMsgStr);
  720. continue;
  721. }
  722. else
  723. {
  724. //民族
  725. newStudent.NationID = nation.Value;
  726. }
  727. }
  728. //政治面貌
  729. if (string.IsNullOrEmpty(en.PoliticsStr))
  730. {
  731. errCount++;
  732. errorMsgStr = "政治面貌不能为空";
  733. en.ErrorMessage = errorMsgStr;
  734. errList.Add(en);
  735. errorMsg.AppendLine(errorMsgStr);
  736. continue;
  737. }
  738. else
  739. {
  740. var politics = politicsList.Where(x => x.Name == en.PoliticsStr.Trim()).SingleOrDefault();
  741. if (politics == null)
  742. {
  743. errCount++;
  744. errorMsgStr = "政治面貌不存在,请检查";
  745. en.ErrorMessage = errorMsgStr;
  746. errList.Add(en);
  747. errorMsg.AppendLine(errorMsgStr);
  748. continue;
  749. }
  750. else
  751. {
  752. //政治面貌
  753. newStudent.PoliticsID = politics.Value;
  754. }
  755. }
  756. //出生日期
  757. if (!string.IsNullOrEmpty(en.BirthDateStr))
  758. {
  759. //reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28
  760. if (!DateTime.TryParse(en.BirthDateStr, out result))
  761. {
  762. errCount++;
  763. errorMsgStr = "出生日期格式不正确,请检查";
  764. en.ErrorMessage = errorMsgStr;
  765. errList.Add(en);
  766. errorMsg.AppendLine(errorMsgStr);
  767. continue;
  768. }
  769. else
  770. {
  771. //出生日期
  772. newStudent.BirthDate = Convert.ToDateTime(en.BirthDateStr);
  773. }
  774. }
  775. else
  776. {
  777. //为空
  778. }
  779. //证件类型
  780. if (string.IsNullOrEmpty(en.CertificatesTypeStr))
  781. {
  782. errCount++;
  783. errorMsgStr = "证件类型不能为空";
  784. en.ErrorMessage = errorMsgStr;
  785. errList.Add(en);
  786. errorMsg.AppendLine(errorMsgStr);
  787. continue;
  788. }
  789. else
  790. {
  791. var certificatesType = certificatesTypeList.Where(x => x.Name == en.CertificatesTypeStr.Trim()).SingleOrDefault();
  792. if (certificatesType == null)
  793. {
  794. errCount++;
  795. errorMsgStr = "证件类型不存在,请检查";
  796. en.ErrorMessage = errorMsgStr;
  797. errList.Add(en);
  798. errorMsg.AppendLine(errorMsgStr);
  799. continue;
  800. }
  801. else
  802. {
  803. //证件类型
  804. newStudent.CertificatesType = certificatesType.Value;
  805. }
  806. }
  807. //身份证号
  808. if (string.IsNullOrEmpty(en.IDNumber))
  809. {
  810. errCount++;
  811. errorMsgStr = "身份证号不能为空";
  812. en.ErrorMessage = errorMsgStr;
  813. errList.Add(en);
  814. errorMsg.AppendLine(errorMsgStr);
  815. continue;
  816. }
  817. else
  818. {
  819. //reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //身份证号正则表达式
  820. //if (!reg.IsMatch(en.IDNumber))
  821. //{
  822. // errCount++;
  823. // errorMsgStr = "身份证号格式不正确,请检查";
  824. // en.ErrorMessage = errorMsgStr;
  825. // errList.Add(en);
  826. // errorMsg.AppendLine(errorMsgStr);
  827. // continue;
  828. //}
  829. //else
  830. //{
  831. // //身份证号
  832. // newStudent.IDNumber = en.IDNumber.Trim();
  833. //}
  834. newStudent.IDNumber = en.IDNumber.Trim();
  835. }
  836. //年级
  837. if (string.IsNullOrEmpty(en.GradeStr))
  838. {
  839. errCount++;
  840. errorMsgStr = "年级不能为空";
  841. en.ErrorMessage = errorMsgStr;
  842. errList.Add(en);
  843. errorMsg.AppendLine(errorMsgStr);
  844. continue;
  845. }
  846. else
  847. {
  848. var grade = gradeList.Where(x => x.Name == en.GradeStr.Trim()).SingleOrDefault();
  849. if (grade == null)
  850. {
  851. errCount++;
  852. errorMsgStr = "年级不存在,请检查";
  853. en.ErrorMessage = errorMsgStr;
  854. errList.Add(en);
  855. errorMsg.AppendLine(errorMsgStr);
  856. continue;
  857. }
  858. else
  859. {
  860. newStudent.GradeID = grade.Value;
  861. }
  862. }
  863. //学期
  864. if (string.IsNullOrEmpty(en.SemesterStr))
  865. {
  866. errCount++;
  867. errorMsgStr = "学期不能为空";
  868. en.ErrorMessage = errorMsgStr;
  869. errList.Add(en);
  870. errorMsg.AppendLine(errorMsgStr);
  871. continue;
  872. }
  873. else
  874. {
  875. var semester = semesterList.Where(x => x.Name == en.SemesterStr.Trim()).SingleOrDefault();
  876. if (semester == null)
  877. {
  878. errCount++;
  879. errorMsgStr = "学期不存在,请检查";
  880. en.ErrorMessage = errorMsgStr;
  881. errList.Add(en);
  882. errorMsg.AppendLine(errorMsgStr);
  883. continue;
  884. }
  885. else
  886. {
  887. //学期
  888. newStudent.SemesterID = semester.Value;
  889. }
  890. }
  891. //专业代码
  892. if (string.IsNullOrEmpty(en.StandardCode))
  893. {
  894. errCount++;
  895. errorMsgStr = "专业代码不能为空";
  896. en.ErrorMessage = errorMsgStr;
  897. errList.Add(en);
  898. errorMsg.AppendLine(errorMsgStr);
  899. continue;
  900. }
  901. else
  902. {
  903. var standardCode = standardList.Where(x => x.Code == en.StandardCode.Trim()).FirstOrDefault();
  904. if (standardCode == null)
  905. {
  906. errCount++;
  907. errorMsgStr = "专业代码不存在,请检查";
  908. en.ErrorMessage = errorMsgStr;
  909. errList.Add(en);
  910. errorMsg.AppendLine(errorMsgStr);
  911. continue;
  912. }
  913. else
  914. {
  915. //专业代码
  916. }
  917. }
  918. //专业名称
  919. if (string.IsNullOrEmpty(en.StandardName))
  920. {
  921. errCount++;
  922. errorMsgStr = "专业名称不能为空";
  923. en.ErrorMessage = errorMsgStr;
  924. errList.Add(en);
  925. errorMsg.AppendLine(errorMsgStr);
  926. continue;
  927. }
  928. else
  929. {
  930. var standardName = standardList.Where(x => x.Name == en.StandardName.Trim()).FirstOrDefault();
  931. if (standardName == null)
  932. {
  933. errCount++;
  934. errorMsgStr = "专业名称不存在,请检查";
  935. en.ErrorMessage = errorMsgStr;
  936. errList.Add(en);
  937. errorMsg.AppendLine(errorMsgStr);
  938. continue;
  939. }
  940. else
  941. {
  942. //专业名称
  943. }
  944. }
  945. //专业代码与专业名称查询专业ID(Value)
  946. if (string.IsNullOrEmpty(en.StandardCode) || string.IsNullOrEmpty(en.StandardName))
  947. {
  948. errCount++;
  949. errorMsgStr = "专业代码或专业名称不能为空";
  950. en.ErrorMessage = errorMsgStr;
  951. errList.Add(en);
  952. errorMsg.AppendLine(errorMsgStr);
  953. continue;
  954. }
  955. else
  956. {
  957. var standardID = standardList.Where(x => x.Code == en.StandardCode.Trim() && x.Name == en.StandardName.Trim()).SingleOrDefault();
  958. if (standardID == null)
  959. {
  960. errCount++;
  961. errorMsgStr = "专业代码与专业名称对应的元素值不存在,请检查";
  962. en.ErrorMessage = errorMsgStr;
  963. errList.Add(en);
  964. errorMsg.AppendLine(errorMsgStr);
  965. continue;
  966. }
  967. else
  968. {
  969. //专业ID(Value)
  970. en.StandardID = standardID.Value.Value;
  971. }
  972. }
  973. //培养层次(所修学历)
  974. if (string.IsNullOrEmpty(en.EducationStr))
  975. {
  976. errCount++;
  977. errorMsgStr = RSL.Get("EducationID") + "不能为空";
  978. en.ErrorMessage = errorMsgStr;
  979. errList.Add(en);
  980. errorMsg.AppendLine(errorMsgStr);
  981. continue;
  982. }
  983. else
  984. {
  985. var education = educationList.Where(x => x.Name == en.EducationStr.Trim()).SingleOrDefault();
  986. if (education == null)
  987. {
  988. errCount++;
  989. errorMsgStr = RSL.Get("EducationID") + "不存在,请检查";
  990. en.ErrorMessage = errorMsgStr;
  991. errList.Add(en);
  992. errorMsg.AppendLine(errorMsgStr);
  993. continue;
  994. }
  995. else
  996. {
  997. en.EducationID = education.Value.Value;
  998. }
  999. }
  1000. //学习形式
  1001. if (string.IsNullOrEmpty(en.LearningformStr))
  1002. {
  1003. errCount++;
  1004. errorMsgStr = "学习形式不能为空";
  1005. en.ErrorMessage = errorMsgStr;
  1006. errList.Add(en);
  1007. errorMsg.AppendLine(errorMsgStr);
  1008. continue;
  1009. }
  1010. else
  1011. {
  1012. var learningForm = learningFormList.Where(x => x.Name == en.LearningformStr.Trim()).SingleOrDefault();
  1013. if (learningForm == null)
  1014. {
  1015. errCount++;
  1016. errorMsgStr = "学习形式不存在,请检查";
  1017. en.ErrorMessage = errorMsgStr;
  1018. errList.Add(en);
  1019. errorMsg.AppendLine(errorMsgStr);
  1020. continue;
  1021. }
  1022. else
  1023. {
  1024. en.LearningformID = learningForm.Value.Value;
  1025. }
  1026. }
  1027. //学制
  1028. if (string.IsNullOrEmpty(en.LearnSystemStr))
  1029. {
  1030. errCount++;
  1031. errorMsgStr = "学制不能为空";
  1032. en.ErrorMessage = errorMsgStr;
  1033. errList.Add(en);
  1034. errorMsg.AppendLine(errorMsgStr);
  1035. continue;
  1036. }
  1037. else
  1038. {
  1039. reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式()
  1040. if (!reg.IsMatch(en.LearnSystemStr))
  1041. {
  1042. errCount++;
  1043. errorMsgStr = "学制格式不正确,请检查";
  1044. en.ErrorMessage = errorMsgStr;
  1045. errList.Add(en);
  1046. errorMsg.AppendLine(errorMsgStr);
  1047. continue;
  1048. }
  1049. else
  1050. {
  1051. //学制
  1052. en.LearnSystem = Convert.ToDecimal(en.LearnSystemStr);
  1053. }
  1054. }
  1055. //入学日期
  1056. if (!string.IsNullOrEmpty(en.EntranceDateStr))
  1057. {
  1058. //reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28
  1059. if (!DateTime.TryParse(en.EntranceDateStr, out result))
  1060. {
  1061. errCount++;
  1062. errorMsgStr = "入学日期格式不正确,请检查";
  1063. en.ErrorMessage = errorMsgStr;
  1064. errList.Add(en);
  1065. errorMsg.AppendLine(errorMsgStr);
  1066. continue;
  1067. }
  1068. else
  1069. {
  1070. //入学日期
  1071. newStudent.EntranceDate = Convert.ToDateTime(en.EntranceDateStr);
  1072. }
  1073. }
  1074. else
  1075. {
  1076. //为空
  1077. }
  1078. //总分
  1079. if (!string.IsNullOrEmpty(en.ScoreStr))
  1080. {
  1081. reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //数字正则表达式
  1082. if (!reg.IsMatch(en.ScoreStr))
  1083. {
  1084. errCount++;
  1085. errorMsgStr = "总分格式不正确,请检查";
  1086. en.ErrorMessage = errorMsgStr;
  1087. errList.Add(en);
  1088. errorMsg.AppendLine(errorMsgStr);
  1089. continue;
  1090. }
  1091. else
  1092. {
  1093. //总分
  1094. newStudent.Score = Convert.ToDecimal(en.ScoreStr);
  1095. }
  1096. }
  1097. else
  1098. {
  1099. //为空
  1100. }
  1101. //联系电话
  1102. if (string.IsNullOrEmpty(en.Telephone))
  1103. {
  1104. //暂不考虑
  1105. }
  1106. else
  1107. {
  1108. reg = new Regex(@"^[-0-9]+$"); //联系电话正则表达式
  1109. if (!reg.IsMatch(en.Telephone))
  1110. {
  1111. errCount++;
  1112. errorMsgStr = "联系电话格式不正确,请检查";
  1113. en.ErrorMessage = errorMsgStr;
  1114. errList.Add(en);
  1115. errorMsg.AppendLine(errorMsgStr);
  1116. continue;
  1117. }
  1118. else
  1119. {
  1120. //联系电话
  1121. newStudent.Telephone = en.Telephone;
  1122. }
  1123. }
  1124. //通讯地址
  1125. if (string.IsNullOrEmpty(en.Address))
  1126. {
  1127. //暂不考虑
  1128. }
  1129. else
  1130. {
  1131. newStudent.Address = en.Address;
  1132. }
  1133. //宿舍地址
  1134. if (string.IsNullOrEmpty(en.Dormitory))
  1135. {
  1136. //暂不考虑
  1137. }
  1138. else
  1139. {
  1140. newStudent.Dormitory = en.Dormitory;
  1141. }
  1142. //备注
  1143. if (string.IsNullOrEmpty(en.Remark))
  1144. {
  1145. //暂不考虑
  1146. }
  1147. else
  1148. {
  1149. newStudent.Remark = en.Remark;
  1150. }
  1151. //专业信息查询
  1152. var specialty = specialtyList.Where(x => x.StandardID == en.StandardID && x.LearnSystem == en.LearnSystem && x.EducationID == en.EducationID
  1153. && x.LearningformID == en.LearningformID).SingleOrDefault();
  1154. //专业信息ID
  1155. if (specialty == null)
  1156. {
  1157. errCount++;
  1158. errorMsgStr = "专业信息不存在,请检查";
  1159. en.ErrorMessage = errorMsgStr;
  1160. errList.Add(en);
  1161. errorMsg.AppendLine(errorMsgStr);
  1162. continue;
  1163. }
  1164. else
  1165. {
  1166. //查询专业信息(启用、禁用状态)
  1167. if (specialty.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  1168. {
  1169. newStudent.SpecialtyID = specialty.SpecialtyID;
  1170. }
  1171. else
  1172. {
  1173. newStudent.SpecialtyID = specialty.SpecialtyID;
  1174. errCount++;
  1175. errorMsgStr = "专业信息为禁用状态,请检查";
  1176. en.ErrorMessage = errorMsgStr;
  1177. errList.Add(en);
  1178. errorMsg.AppendLine(errorMsgStr);
  1179. continue;
  1180. }
  1181. }
  1182. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  1183. //for (int j = i + 1; j < enlist.Count; j++)
  1184. //{
  1185. // NewStudentView enA = enlist[j];
  1186. // //根据Excel表中的业务主键进行去重(考生号唯一)
  1187. // if (en.ExamineeNum == enA.ExamineeNum)
  1188. // {
  1189. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  1190. // }
  1191. //}
  1192. //由于新生管理模块中存在新生分配的业务,在进行新生信息新增时,
  1193. //需要对新生分配、录取名单中的信息进行提示性验证(业务主键:考生号唯一)
  1194. //处理方法:进行Excel导入时,对新生分配、录取名单中的信息提示性验证(当错误信息抛出)
  1195. //注:(未分配-1,预分配-2,已分配-3)
  1196. //数据表重复性验证(考生号唯一)
  1197. var examineeNumVerify = newStudentList.Where(x => x.ExamineeNum == newStudent.ExamineeNum).SingleOrDefault();
  1198. if (examineeNumVerify == null)
  1199. {
  1200. //if (!string.IsNullOrEmpty(newStudent.AdmissionTicketNo))
  1201. //{
  1202. // if (!newStudentUpList.Any(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo))
  1203. // {
  1204. // if (!newStudentInList.Any(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo))
  1205. // {
  1206. // var admissionTicketNoVerify = newStudentList.Where(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo).SingleOrDefault();
  1207. // if (admissionTicketNoVerify != null)
  1208. // {
  1209. // if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
  1210. // {
  1211. // errCount++;
  1212. // errorMsgStr = "新生分配信息中已存在此准考证号(准考证号重复),请核查";
  1213. // en.ErrorMessage = errorMsgStr;
  1214. // errList.Add(en);
  1215. // errorMsg.AppendLine(errorMsgStr);
  1216. // continue;
  1217. // }
  1218. // else if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
  1219. // {
  1220. // errCount++;
  1221. // errorMsgStr = "录取名单信息中已存在此准考证号(准考证号重复),请核查";
  1222. // en.ErrorMessage = errorMsgStr;
  1223. // errList.Add(en);
  1224. // errorMsg.AppendLine(errorMsgStr);
  1225. // continue;
  1226. // }
  1227. // else
  1228. // {
  1229. // errCount++;
  1230. // errorMsgStr = "已存在相同的准考证号(准考证号重复),请核查";
  1231. // en.ErrorMessage = errorMsgStr;
  1232. // errList.Add(en);
  1233. // errorMsg.AppendLine(errorMsgStr);
  1234. // continue;
  1235. // }
  1236. // }
  1237. // }
  1238. // else
  1239. // {
  1240. // errCount++;
  1241. // errorMsgStr = "准考证号重复(Excel中),请检查";
  1242. // en.ErrorMessage = errorMsgStr;
  1243. // errList.Add(en);
  1244. // errorMsg.AppendLine(errorMsgStr);
  1245. // continue;
  1246. // }
  1247. // }
  1248. // else
  1249. // {
  1250. // errCount++;
  1251. // errorMsgStr = "准考证号重复(Excel中),请检查";
  1252. // en.ErrorMessage = errorMsgStr;
  1253. // errList.Add(en);
  1254. // errorMsg.AppendLine(errorMsgStr);
  1255. // continue;
  1256. // }
  1257. //}
  1258. //新增
  1259. if (!newStudentInList.Any(x => x.ExamineeNum == newStudent.ExamineeNum))
  1260. {
  1261. newStudent.NewStudentID = Guid.NewGuid();
  1262. newStudent.IsDoubt = false;
  1263. newStudent.AssignStatus = (int)CF_AssignStatus.NotAssigned;
  1264. SetNewStatus(newStudent, (int)CF_NewStudentEnterStatus.NotSubmitted);
  1265. newStudentInList.Add(newStudent);
  1266. inCount++;
  1267. }
  1268. else
  1269. {
  1270. //Excel表重复性验证
  1271. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中)
  1272. errCount++;
  1273. errorMsgStr = "考生号重复(Excel中),请检查";
  1274. en.ErrorMessage = errorMsgStr;
  1275. errList.Add(en);
  1276. errorMsg.AppendLine(errorMsgStr);
  1277. continue;
  1278. }
  1279. }
  1280. else
  1281. {
  1282. //由于新生管理模块中存在新生分配的业务,只更新分配状态为:未分配-1
  1283. //分配状态为:预分配-2,已分配-3
  1284. if (examineeNumVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
  1285. {
  1286. errCount++;
  1287. errorMsgStr = "导入失败,新生分配信息中已存在此考生号(考生号重复)";
  1288. en.ErrorMessage = errorMsgStr;
  1289. errList.Add(en);
  1290. errorMsg.AppendLine(errorMsgStr);
  1291. continue;
  1292. }
  1293. else if (examineeNumVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
  1294. {
  1295. errCount++;
  1296. errorMsgStr = "导入失败,录取名单信息中已存在此考生号(考生号重复)";
  1297. en.ErrorMessage = errorMsgStr;
  1298. errList.Add(en);
  1299. errorMsg.AppendLine(errorMsgStr);
  1300. continue;
  1301. }
  1302. else
  1303. {
  1304. //更新(Excel有重复时,以最后一条记录的更新为准)
  1305. //if (!string.IsNullOrEmpty(newStudent.AdmissionTicketNo))
  1306. //{
  1307. // if (!newStudentInList.Any(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo))
  1308. // {
  1309. // if (!newStudentUpList.Any(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo))
  1310. // {
  1311. // var admissionTicketNoVerify = newStudentList.Where(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo).SingleOrDefault();
  1312. // if (admissionTicketNoVerify != null)
  1313. // {
  1314. // if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
  1315. // {
  1316. // errCount++;
  1317. // errorMsgStr = "新生分配信息中已存在此准考证号(准考证号重复),请核查";
  1318. // en.ErrorMessage = errorMsgStr;
  1319. // errList.Add(en);
  1320. // errorMsg.AppendLine(errorMsgStr);
  1321. // continue;
  1322. // }
  1323. // else if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
  1324. // {
  1325. // errCount++;
  1326. // errorMsgStr = "录取名单信息中已存在此准考证号(准考证号重复),请核查";
  1327. // en.ErrorMessage = errorMsgStr;
  1328. // errList.Add(en);
  1329. // errorMsg.AppendLine(errorMsgStr);
  1330. // continue;
  1331. // }
  1332. // else
  1333. // {
  1334. // errCount++;
  1335. // errorMsgStr = "已存在相同的准考证号(准考证号重复),请核查";
  1336. // en.ErrorMessage = errorMsgStr;
  1337. // errList.Add(en);
  1338. // errorMsg.AppendLine(errorMsgStr);
  1339. // continue;
  1340. // }
  1341. // }
  1342. // }
  1343. // else
  1344. // {
  1345. // errCount++;
  1346. // errorMsgStr = "准考证号重复(Excel中),请检查";
  1347. // en.ErrorMessage = errorMsgStr;
  1348. // errList.Add(en);
  1349. // errorMsg.AppendLine(errorMsgStr);
  1350. // continue;
  1351. // }
  1352. // }
  1353. // else
  1354. // {
  1355. // errCount++;
  1356. // errorMsgStr = "准考证号重复(Excel中),请检查";
  1357. // en.ErrorMessage = errorMsgStr;
  1358. // errList.Add(en);
  1359. // errorMsg.AppendLine(errorMsgStr);
  1360. // continue;
  1361. // }
  1362. //}
  1363. examineeNumVerify.ExamineeNum = newStudent.ExamineeNum;
  1364. examineeNumVerify.AdmissionTicketNo = newStudent.AdmissionTicketNo;
  1365. examineeNumVerify.Name = newStudent.Name;
  1366. examineeNumVerify.SexID = newStudent.SexID;
  1367. examineeNumVerify.NationID = newStudent.NationID;
  1368. examineeNumVerify.PoliticsID = newStudent.PoliticsID;
  1369. examineeNumVerify.BirthDate = newStudent.BirthDate;
  1370. examineeNumVerify.CertificatesType = newStudent.CertificatesType;
  1371. examineeNumVerify.IDNumber = newStudent.IDNumber;
  1372. examineeNumVerify.GradeID = newStudent.GradeID;
  1373. examineeNumVerify.SemesterID = newStudent.SemesterID;
  1374. examineeNumVerify.SpecialtyID = newStudent.SpecialtyID;
  1375. examineeNumVerify.EntranceDate = newStudent.EntranceDate;
  1376. examineeNumVerify.Score = newStudent.Score;
  1377. examineeNumVerify.Telephone = newStudent.Telephone;
  1378. examineeNumVerify.Address = newStudent.Address;
  1379. examineeNumVerify.Dormitory = newStudent.Dormitory;
  1380. examineeNumVerify.Remark = newStudent.Remark;
  1381. SetModifyStatus(examineeNumVerify);
  1382. newStudentUpList.Add(examineeNumVerify);
  1383. upCount++;
  1384. }
  1385. }
  1386. }
  1387. using (TransactionScope ts = new TransactionScope())
  1388. {
  1389. UnitOfWork.BulkInsert(newStudentInList);
  1390. if (newStudentUpList != null && newStudentUpList.Count() > 0)
  1391. {
  1392. UnitOfWork.BatchUpdate(newStudentUpList);
  1393. }
  1394. ts.Complete();
  1395. }
  1396. errdataList = errList.Distinct().ToList();
  1397. }
  1398. catch (Exception)
  1399. {
  1400. throw;
  1401. }
  1402. }
  1403. }
  1404. }