StudentsServices.cs 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.DataLogic.Repositories;
  9. using System.Linq.Expressions;
  10. using EMIS.Entities;
  11. using EMIS.DataLogic.SystemDAL;
  12. using EMIS.ViewModel.Students;
  13. using EMIS.ViewModel.SystemView;
  14. using EMIS.Utility;
  15. using EMIS.DataLogic.UniversityManage.AdministrativeOrgan;
  16. using EMIS.DataLogic.Common.Students;
  17. using EMIS.ViewModel;
  18. using System.Data;
  19. using EMIS.ViewModel.CacheManage;
  20. using System.IO;
  21. using System.Text.RegularExpressions;
  22. using Bowin.Common.Utility;
  23. using Bowin.Common.DataTime;
  24. using System.Globalization;
  25. using EMIS.CommonLogic.CalendarManage;
  26. using EMIS.Utility.FormValidate;
  27. using System.Web;
  28. using System.Transactions;
  29. using EMIS.DataLogic;
  30. using System.Data.OleDb;
  31. namespace EMIS.CommonLogic.Students
  32. {
  33. public class StudentsServices : BaseServices, IStudentsServices
  34. {
  35. public Lazy<StudentsDAL> StudentsDAL { get; set; }
  36. public Lazy<RoleDAL> RoleDAL { get; set; }
  37. public Lazy<InSchoolSettingRepository> InSchoolSettingRepository { get; set; }
  38. public Lazy<StudentProfileRepository> StudentProfileRepository { get; set; }
  39. public Lazy<StudentContactRepository> StudentContactRepository { get; set; }
  40. public Lazy<UserRepository> UserRepository { get; set; }
  41. public Lazy<RecruitstudentsRepository> RecruitstudentsRepository { get; set; }
  42. public Lazy<StudentAccountRepository> StudentAccountRepository { get; set; }
  43. public Lazy<NewStudentRepository> NewStudentRepository { get; set; }
  44. public Lazy<ClassmajorRepository> ClassmajorRepository { get; set; }
  45. public Lazy<SchoolyearRepository> SchoolyearRepository { get; set; }
  46. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  47. public ParameterDAL ParameterDAL { get; set; }
  48. public DataRangeDAL DataRangeDAL { get; set; }
  49. public IGridResultSet<StudentsView> GetStudentUserViewList(ViewModel.ConfiguretView configuretView,
  50. Guid? campusID, Guid? collegeID, int? years, int? standardID, int? learningformID, Guid? classmajorID, int? IsGraduation,
  51. int? inSchoolStatusID, int? isPhotos, int? isDream, string planningGraduateDate, string LearnSystem,int? education,
  52. int? reportStatusID, int pageIndex, int pageSize)
  53. {
  54. Expression<Func<CF_Student, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  55. Expression<Func<CF_Classmajor, bool>> classexp = (x => true);
  56. Expression<Func<CF_Grademajor, bool>> gradeexp = (x => true);
  57. Expression<Func<EM_StudentReport, bool>> reportExp = (x => x.CF_Schoolyear.IsCurrent == true);
  58. if (isPhotos.HasValue)
  59. {
  60. if (isPhotos.Value == (int)CF_GeneralPurpose.IsYes)
  61. {
  62. exp = exp.And(x => x.PhotoUrl != null);
  63. }
  64. else
  65. {
  66. exp = exp.And(x => x.PhotoUrl == null);
  67. }
  68. }
  69. if (campusID.HasValue)
  70. gradeexp = gradeexp.And(x => x.CF_Facultymajor.CF_College.CampusID == campusID);
  71. if (collegeID.HasValue)
  72. gradeexp = gradeexp.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  73. if (years.HasValue)
  74. gradeexp = gradeexp.And(x => x.GradeID == years);
  75. if (standardID.HasValue)
  76. gradeexp = gradeexp.And(x => x.CF_Facultymajor.StandardID == standardID);
  77. if (learningformID.HasValue)
  78. gradeexp = gradeexp.And(x => x.CF_Facultymajor.LearningformID == learningformID);
  79. if (classmajorID.HasValue)
  80. exp = exp.And(x => x.ClassmajorID == classmajorID);
  81. if (inSchoolStatusID.HasValue)
  82. exp = exp.And(x => x.InSchoolStatusID == inSchoolStatusID);
  83. if (IsGraduation.HasValue)
  84. {
  85. if (IsGraduation != (int)EMIS.ViewModel.CF_GeneralPurpose.IsYes)
  86. exp = exp.And(x => x.StudentStatus != (int)EMIS.ViewModel.CF_StudentStatus.Graduation);
  87. else
  88. exp = exp.And(x => x.StudentStatus == (int)EMIS.ViewModel.CF_StudentStatus.Graduation);
  89. }
  90. if(isDream.HasValue){
  91. if(isDream.Value==(int)CF_GeneralPurpose.IsYes){
  92. exp = exp.And(x => x.CF_StudentProfile.IsDreamProject != null);
  93. }
  94. else
  95. {
  96. exp=exp.And(x=>x.CF_StudentProfile.IsDreamProject==null);
  97. }
  98. }
  99. if (planningGraduateDate != "" && !String.IsNullOrEmpty(planningGraduateDate) && planningGraduateDate != "-1")
  100. {
  101. //DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
  102. //dtFormat.ShortDatePattern = "yyyyMMdd";
  103. DateTime date = DateTime.ParseExact(planningGraduateDate, "yyyyMMdd", CultureInfo.CurrentCulture);
  104. //string datestr = date.ToString("u");
  105. //dtFormat.ShortDatePattern = "yyyy-MM-dd";
  106. //dtFormat.DateSeparator = "-";
  107. //DateTime dates = Convert.ToDateTime(datestr, dtFormat);
  108. exp = exp.And(x => DateTime.Compare((DateTime)x.PlanningGraduateDate, date) == 0);
  109. }
  110. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  111. {
  112. var LearnSystems = Convert.ToDecimal(LearnSystem);
  113. exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  114. }
  115. if (education.HasValue)
  116. {
  117. exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  118. }
  119. var query = StudentsDAL.Value.GetStudentQueryable(exp, classexp, gradeexp, reportExp);
  120. if (reportStatusID.HasValue)
  121. {
  122. query = query.Where(x => x.ReportStatusID == reportStatusID);
  123. }
  124. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  125. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  126. return this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
  127. .ThenBy(x => x.ClassMajorCode).ThenBy(x => x.LoginID).ToGridResultSet<StudentsView>(pageIndex, pageSize);
  128. }
  129. public IList<StudentsView> GetStudentViewList(ViewModel.ConfiguretView configuretView,
  130. Guid? campusID, Guid? collegeID, int? years, int? standardID, int? learningformID, Guid? classmajorID, int? IsGraduation,
  131. int? inSchoolStatusID, int? isPhotos, int? isDream, string planningGraduateDate, string LearnSystem, int? education,
  132. int? reportStatusID, List<Guid?> UserIDsIDList)
  133. {
  134. Expression<Func<CF_Student, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  135. Expression<Func<CF_Classmajor, bool>> classexp = (x => true);
  136. Expression<Func<CF_Grademajor, bool>> gradeexp = (x => true);
  137. if (UserIDsIDList != null)
  138. {
  139. exp = exp.And(x => UserIDsIDList.Contains(x.UserID));
  140. }
  141. else
  142. {
  143. if (isPhotos.HasValue)
  144. {
  145. if (isPhotos.Value == (int)CF_GeneralPurpose.IsYes)
  146. {
  147. exp = exp.And(x => x.PhotoUrl != null);
  148. }
  149. else
  150. {
  151. exp = exp.And(x => x.PhotoUrl == null);
  152. }
  153. }
  154. if (campusID.HasValue)
  155. gradeexp = gradeexp.And(x => x.CF_Facultymajor.CF_College.CampusID == campusID);
  156. if (collegeID.HasValue)
  157. gradeexp = gradeexp.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  158. if (years.HasValue)
  159. gradeexp = gradeexp.And(x => x.GradeID == years);
  160. if (standardID.HasValue)
  161. gradeexp = gradeexp.And(x => x.CF_Facultymajor.StandardID == standardID);
  162. if (learningformID.HasValue)
  163. gradeexp = gradeexp.And(x => x.CF_Facultymajor.LearningformID == learningformID);
  164. if (classmajorID.HasValue)
  165. exp = exp.And(x => x.ClassmajorID == classmajorID);
  166. if (inSchoolStatusID.HasValue)
  167. exp = exp.And(x => x.InSchoolStatusID == inSchoolStatusID);
  168. if (IsGraduation.HasValue)
  169. {
  170. if (IsGraduation != (int)EMIS.ViewModel.CF_StudentStatus.Graduation)
  171. exp = exp.And(x => x.StudentStatus != (int)EMIS.ViewModel.CF_StudentStatus.Graduation);
  172. else
  173. exp = exp.And(x => x.StudentStatus == (int)EMIS.ViewModel.CF_StudentStatus.Graduation);
  174. }
  175. if (isDream.HasValue)
  176. {
  177. if (isDream.Value == (int)CF_GeneralPurpose.IsYes)
  178. {
  179. exp = exp.And(x => x.CF_StudentProfile.IsDreamProject != null);
  180. }
  181. else
  182. {
  183. exp = exp.And(x => x.CF_StudentProfile.IsDreamProject == null);
  184. }
  185. }
  186. if (planningGraduateDate != "" && !String.IsNullOrEmpty(planningGraduateDate) && planningGraduateDate != "-1")
  187. {
  188. //DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
  189. //dtFormat.ShortDatePattern = "yyyyMMdd";
  190. DateTime date = DateTime.ParseExact(planningGraduateDate, "yyyyMMdd", CultureInfo.CurrentCulture);
  191. //string datestr = date.ToString("u");
  192. //dtFormat.ShortDatePattern = "yyyy-MM-dd";
  193. //dtFormat.DateSeparator = "-";
  194. //DateTime dates = Convert.ToDateTime(datestr, dtFormat);
  195. exp = exp.And(x => DateTime.Compare((DateTime)x.PlanningGraduateDate, date) == 0);
  196. }
  197. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  198. {
  199. var LearnSystems = Convert.ToDecimal(LearnSystem);
  200. exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  201. }
  202. if (education.HasValue)
  203. {
  204. exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  205. }
  206. }
  207. var query = StudentsDAL.Value.GetStudentQueryable(exp, classexp, gradeexp);
  208. if (reportStatusID.HasValue)
  209. {
  210. query = query.Where(x => x.ReportStatusID == reportStatusID);
  211. }
  212. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  213. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  214. return this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
  215. .ThenBy(x => x.ClassMajorCode).ThenBy(x => x.LoginID).ToList();
  216. }
  217. public IGridResultSet<StudentsView> GetStudentUserViewList(ConfiguretView configuretView,
  218. Guid? campusID, Guid? collegeID, int? education, int? years, int? standardID, int? learningformID, int? classNum, int? studentStatusID, bool? isPhotos,
  219. bool? isOnlyGraduation, bool? isPreviousNotGraduated, int pageIndex, int pageSize)
  220. {
  221. var currentSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  222. var inschoolStatusList = InSchoolSettingRepository.Value.GetList(x => x.IsSelected == true)
  223. .Select(x => x.InSchoolStatusID).Distinct().ToList();
  224. Expression<Func<CF_Student, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && inschoolStatusList.Contains(x.InSchoolStatusID));
  225. Expression<Func<CF_Classmajor, bool>> classexp = (x => true);
  226. Expression<Func<CF_Grademajor, bool>> gradeexp = (x => true);
  227. Expression<Func<EM_StudentReport, bool>> reportExp = (x => x.CF_Schoolyear.IsCurrent == true);
  228. if (campusID.HasValue)
  229. {
  230. gradeexp = gradeexp.And(x => x.CF_Facultymajor.CF_College.CampusID == campusID);
  231. }
  232. if (collegeID.HasValue)
  233. {
  234. gradeexp = gradeexp.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  235. }
  236. if (education.HasValue)
  237. {
  238. gradeexp = gradeexp.And(x => x.CF_Facultymajor.EducationID == education.Value);
  239. }
  240. if (years.HasValue)
  241. {
  242. gradeexp = gradeexp.And(x => x.GradeID == years);
  243. }
  244. if (standardID.HasValue)
  245. {
  246. gradeexp = gradeexp.And(x => x.CF_Facultymajor.StandardID == standardID);
  247. }
  248. if (learningformID.HasValue)
  249. {
  250. gradeexp = gradeexp.And(x => x.CF_Facultymajor.LearningformID == learningformID);
  251. }
  252. if (classNum.HasValue)
  253. {
  254. classexp = classexp.And(x => x.ClassNum == classNum);
  255. }
  256. if (studentStatusID.HasValue)
  257. {
  258. exp = exp.And(x => x.StudentStatus == studentStatusID);
  259. }
  260. if (isPhotos.HasValue)
  261. {
  262. if (isPhotos.Value)
  263. {
  264. exp = exp.And(x => x.PhotoUrl != null);
  265. }
  266. else
  267. {
  268. exp = exp.And(x => x.PhotoUrl == null);
  269. }
  270. }
  271. if (isOnlyGraduation == true)
  272. {
  273. gradeexp = gradeexp.And(x => x.GraduateSchoolyearID == currentSchoolyear.SchoolYearID);
  274. }
  275. if (isPreviousNotGraduated == true)
  276. {
  277. gradeexp = gradeexp.And(x => x.CF_Schoolyear.Value < currentSchoolyear.Value);
  278. exp = exp.And(x => x.StudentStatus == (int)CF_StudentStatus.Complete && x.InSchoolStatusID == (int)CF_InschoolStatus.Complete);
  279. }
  280. var query = StudentsDAL.Value.GetStudentQueryable(exp, classexp, gradeexp, reportExp);
  281. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  282. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  283. return this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
  284. .ThenBy(x => x.ClassMajorCode).ThenBy(x => x.LoginID).ToGridResultSet<StudentsView>(pageIndex, pageSize);
  285. }
  286. public IList<StudentsView> GetStudentViewListByIDList(IList<Guid?> studentUserIDList)
  287. {
  288. return StudentsDAL.Value.GetStudentQueryable(x => studentUserIDList.Contains(x.UserID)).ToList();
  289. }
  290. /// <summary>
  291. /// 获取可进行异动申请的学生。
  292. /// </summary>
  293. /// <returns></returns>
  294. public IGridResultSet<StudentsView> GetAbleDifferentDynamicApplyStudentList(ConfiguretView configuretView, int pageIndex, int pageSize)
  295. {
  296. Expression<Func<CF_Student, bool>> filter = w => w.RecordStatus > (int)SYS_STATUS.UNUSABLE;
  297. //为何和学籍状态有关?
  298. //var studentStatus = new[]
  299. //{
  300. // (int?)CF_StudentStatus.Whodid,
  301. // (int?)CF_StudentStatus.Thegraduation,
  302. // (int?)CF_StudentStatus.Graduation
  303. //};
  304. //filter = filter.And(w => !studentStatus.Contains(w.StudentStatus));
  305. //2016年10月13日14:53:40
  306. //PS:异动申请,新增异动的时候,这个异动权限要放开。现在只有在校生能学籍异动,非在校生也能异动才行。【相当于权限放开,可以添加任何在校状态的学生】
  307. // var inSchoolStatusIDs = InSchoolSettingRepository.Value.GetList(w => w.IsSelected == true).Select(s => s.InSchoolStatusID).ToArray();
  308. //filter = filter.And(w => inSchoolStatusIDs.Contains(w.InSchoolStatusID));
  309. var query = StudentsDAL.Value.GetStudentQueryable(filter);
  310. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  311. {
  312. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  313. }
  314. query = this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderByDescending(x => x.LoginID);
  315. return query.ToGridResultSet(pageIndex, pageSize);
  316. }
  317. /// <summary>
  318. /// 导出excel和dbf
  319. /// </summary>
  320. /// <param name="configuretView"></param>
  321. /// <param name="campusID"></param>
  322. /// <param name="collegeID"></param>
  323. /// <param name="years"></param>
  324. /// <param name="standardID"></param>
  325. /// <param name="learningformID"></param>
  326. /// <param name="classmajorID"></param>
  327. /// <param name="IsGraduation"></param>
  328. /// <param name="inSchoolStatusID"></param>
  329. /// <param name="isPhotos"></param>
  330. /// <param name="isDream"></param>
  331. /// <param name="planningGraduateDate"></param>
  332. /// <param name="LearnSystem"></param>
  333. /// <param name="education"></param>
  334. /// <param name="reportStatusID"></param>
  335. /// <returns></returns>
  336. public IList<StudentsView> GetStudentExportList(ViewModel.ConfiguretView configuretView,
  337. Guid? campusID, Guid? collegeID, int? years, int? standardID, int? learningformID, Guid? classmajorID, int? IsGraduation, int? inSchoolStatusID, int? isPhotos, int? isDream, string planningGraduateDate, string LearnSystem, int? education, int? reportStatusID)
  338. {
  339. Expression<Func<CF_Student, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  340. Expression<Func<CF_Classmajor, bool>> classexp = (x => true);
  341. Expression<Func<CF_Grademajor, bool>> gradeexp = (x => true);
  342. if (isPhotos.HasValue)
  343. {
  344. if (isPhotos.Value == (int)CF_GeneralPurpose.IsYes)
  345. {
  346. exp = exp.And(x => x.PhotoUrl != null);
  347. }
  348. else
  349. {
  350. exp = exp.And(x => x.PhotoUrl == null);
  351. }
  352. }
  353. if (campusID.HasValue)
  354. gradeexp = gradeexp.And(x => x.CF_Facultymajor.CF_College.CampusID == campusID);
  355. if (collegeID.HasValue)
  356. gradeexp = gradeexp.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  357. if (years.HasValue)
  358. gradeexp = gradeexp.And(x => x.GradeID == years);
  359. if (standardID.HasValue)
  360. gradeexp = gradeexp.And(x => x.CF_Facultymajor.StandardID == standardID);
  361. if (learningformID.HasValue)
  362. gradeexp = gradeexp.And(x => x.CF_Facultymajor.LearningformID == learningformID);
  363. if (classmajorID.HasValue)
  364. exp = exp.And(x => x.ClassmajorID == classmajorID);
  365. if (inSchoolStatusID.HasValue)
  366. exp = exp.And(x => x.InSchoolStatusID == inSchoolStatusID);
  367. if (IsGraduation.HasValue)
  368. {
  369. if (IsGraduation != (int)EMIS.ViewModel.CF_StudentStatus.Graduation)
  370. exp = exp.And(x => x.StudentStatus != (int)EMIS.ViewModel.CF_StudentStatus.Graduation);
  371. else
  372. exp = exp.And(x => x.StudentStatus == (int)EMIS.ViewModel.CF_StudentStatus.Graduation);
  373. }
  374. if (isDream.HasValue)
  375. {
  376. if (isDream.Value == (int)CF_GeneralPurpose.IsYes)
  377. {
  378. exp = exp.And(x => x.CF_StudentProfile.IsDreamProject != null);
  379. }
  380. else
  381. {
  382. exp = exp.And(x => x.CF_StudentProfile.IsDreamProject == null);
  383. }
  384. }
  385. if (planningGraduateDate != "" && !String.IsNullOrEmpty(planningGraduateDate) && planningGraduateDate != "-1")
  386. {
  387. //DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
  388. //dtFormat.ShortDatePattern = "yyyyMMdd";
  389. DateTime date = DateTime.ParseExact(planningGraduateDate, "yyyyMMdd", CultureInfo.CurrentCulture);
  390. //string datestr = date.ToString("u");
  391. //dtFormat.ShortDatePattern = "yyyy-MM-dd";
  392. //dtFormat.DateSeparator = "-";
  393. //DateTime dates = Convert.ToDateTime(datestr, dtFormat);
  394. exp = exp.And(x => DateTime.Compare((DateTime)x.PlanningGraduateDate, date) == 0);
  395. }
  396. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  397. {
  398. var LearnSystems = Convert.ToDecimal(LearnSystem);
  399. exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  400. }
  401. if (education.HasValue)
  402. {
  403. exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  404. }
  405. var query = StudentsDAL.Value.GetStudentForExcel(exp, classexp, gradeexp);
  406. if (reportStatusID.HasValue)
  407. {
  408. query = query.Where(x => x.ReportStatusID == reportStatusID);
  409. }
  410. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  411. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  412. return this.GetQueryByAssistant(query, (x => x.ClassMajorID), this.GetQueryByDataRangeByCollege(query)).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
  413. .ThenBy(x => x.ClassMajorCode).ThenBy(x => x.LoginID).ToList();
  414. }
  415. public IGridResultSet<BaseStudentView> GetBaseStudentView(ViewModel.ConfiguretView configuretView, Guid? collegeID, Guid? grademajorID, Guid? classmajorID, Guid? userID, int pageIndex, int pageSize)
  416. {
  417. Expression<Func<CF_Student, bool>> filter = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  418. if (collegeID.HasValue)
  419. filter = filter.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  420. if (grademajorID.HasValue)
  421. filter = filter.And(x => x.CF_Classmajor.GrademajorID == grademajorID);
  422. if (classmajorID.HasValue)
  423. filter = filter.And(x => x.ClassmajorID == classmajorID);
  424. if (userID.HasValue)
  425. {
  426. filter = filter.And(x => x.UserID == userID);
  427. }
  428. var query = StudentsDAL.Value.GetBaseStudentViewQueryable(filter);
  429. //查询条件
  430. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  431. {
  432. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  433. }
  434. return this.GetQueryByDataRangeByCollege(query)
  435. .OrderByDescending(x => x.LoginID.Length).ThenBy(x => x.LoginID)
  436. .ThenBy(x => x.ClassmajorCode.Length).ThenBy(x => x.ClassmajorCode)
  437. .ToGridResultSet<BaseStudentView>(pageIndex, pageSize);
  438. }
  439. /// <summary>
  440. ///
  441. /// </summary>
  442. /// <param name="configuretView"></param>
  443. /// <param name="pageIndex"></param>
  444. /// <param name="pageSize"></param>
  445. /// <returns></returns>
  446. public IGridResultSet<BaseStudentView> GetStudentOnlyInSchool(ConfiguretView configuretView, int pageIndex, int pageSize)
  447. {
  448. Expression<Func<CF_Student, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.InSchoolStatusID == (int)CF_InschoolStatus.InSchool);
  449. Expression<Func<CF_Classmajor, bool>> classexp = (x => true);
  450. Expression<Func<CF_Grademajor, bool>> gradeexp = (x => true);
  451. Expression<Func<EM_StudentReport, bool>> reportExp = (x => x.CF_Schoolyear.IsCurrent == true);
  452. var query = StudentsDAL.Value.GetInSchoolStudentViewQueryable(exp);
  453. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  454. {
  455. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  456. }
  457. return query.OrderBy(x => x.ClassmajorCode.Length).ThenBy(x => x.ClassmajorCode).ThenBy(x => x.LoginID).ToGridResultSet<BaseStudentView>(pageIndex, pageSize);
  458. }
  459. public IGridResultSet<StudentsView> GetPlanningGraduateList()
  460. {
  461. Dictionary<int, DateTime?> diction = new Dictionary<int, DateTime?>();
  462. //int key = 0;
  463. var query = StudentsDAL.Value.GetPlanningGraduateDictionary().Where(x => x.PlanningGraduateDate != null);
  464. List<DateTime?> list = query.Select(x => x.PlanningGraduateDate).OrderBy(x => x.Value).ToList();
  465. List<StudentsView> stulist = query.OrderBy(x => x.PlanningGraduateDate).ToList();
  466. List<string> datestr = new List<string>();
  467. for (int i = 0; i < stulist.Count; i++)
  468. {
  469. stulist[i].PlanningGraduateStr = list[i].Value.ToString("yyyyMMdd");
  470. }
  471. //List<string> dictionList = query.Select(x => x.PlanningGraduateStr).ToList();
  472. //foreach(DateTime date in dictionList)
  473. //{
  474. // diction.Add(key, date);
  475. // key++;
  476. //}
  477. return stulist.AsQueryable().ToGridResultSet<StudentsView>();
  478. }
  479. public StudentsView GetStudentViewByLoginID(string loginID)
  480. {
  481. var student = StudentsDAL.Value.GetStudentQueryable(x => x.Sys_User.LoginID == loginID).FirstOrDefault();
  482. return student;
  483. }
  484. public StudentsView GetStudentViewByIDNum(string idNum)
  485. {
  486. var student = StudentsDAL.Value.GetStudentQueryable(x => x.IDNumber == idNum).FirstOrDefault();
  487. return student;
  488. }
  489. /// <summary>
  490. /// 将数据表写入到DBF文件中
  491. /// </summary>
  492. /// <param name="dt"></param>
  493. public void WriteToDbf(DataTable dt, List<string> colList)
  494. {
  495. string filePath = Const.LOCAL_SETTING_UPLOAD_FILEPATH;
  496. string physicalPath = HttpContext.Current.Server.MapPath(filePath);
  497. string newfilePath = (physicalPath.EndsWith("\\") ? physicalPath : physicalPath + "\\") + "StudentInfoExcel";
  498. //连接字符串
  499. string sConn =
  500. "Provider=Microsoft.Jet.OLEDB.4.0; " +
  501. "Data Source=" + newfilePath + "; " +
  502. "Extended Properties=dBASE IV;";
  503. OleDbConnection conn = new OleDbConnection(sConn);
  504. conn.Open();
  505. var fileName = "Info.dbf";
  506. var filePathAndFile = (physicalPath.EndsWith("\\") ? physicalPath : physicalPath + "\\") + "StudentInfoExcel\\" + fileName;
  507. try
  508. {
  509. //如果存在同名文件则先删除
  510. if (File.Exists(filePathAndFile))
  511. {
  512. File.Delete(filePathAndFile);
  513. }
  514. //建立新表
  515. StringBuilder sbCreate = new StringBuilder();
  516. sbCreate.Append("CREATE TABLE " + fileName + " (");
  517. for (int i = 0; i < colList.Count; i++)
  518. {
  519. //根据需求不同字段要求字段长度不同——20190923兵良哥要求
  520. sbCreate.Append(colList[i]);
  521. if (colList[i].Equals("KSH",StringComparison.OrdinalIgnoreCase))
  522. sbCreate.Append(" char(18)");
  523. else if (colList[i].Equals("XM", StringComparison.OrdinalIgnoreCase))
  524. sbCreate.Append(" char(40)");
  525. else if (colList[i].Equals("XB", StringComparison.OrdinalIgnoreCase))
  526. sbCreate.Append(" char(2)");
  527. else if (colList[i].Equals("CSRQ", StringComparison.OrdinalIgnoreCase))
  528. sbCreate.Append(" char(8)");
  529. else if (colList[i].Equals("SFZH", StringComparison.OrdinalIgnoreCase))
  530. sbCreate.Append(" char(18)");
  531. else if (colList[i].Equals("YXDM", StringComparison.OrdinalIgnoreCase))
  532. sbCreate.Append(" char(5)");
  533. else if (colList[i].Equals("YXMC", StringComparison.OrdinalIgnoreCase))
  534. sbCreate.Append(" char(60)");
  535. else if (colList[i].Equals("ZYDM", StringComparison.OrdinalIgnoreCase))
  536. sbCreate.Append(" char(8)");
  537. else if (colList[i].Equals("ZYMC", StringComparison.OrdinalIgnoreCase))
  538. sbCreate.Append(" char(50)");
  539. else if (colList[i].Equals("XZ", StringComparison.OrdinalIgnoreCase))
  540. sbCreate.Append(" char(3)");
  541. else if (colList[i].Equals("XXXS", StringComparison.OrdinalIgnoreCase))
  542. sbCreate.Append(" char(10)");
  543. else if (colList[i].Equals("CC", StringComparison.OrdinalIgnoreCase))
  544. sbCreate.Append(" char(12)");
  545. else if (colList[i].Equals("RXRQ", StringComparison.OrdinalIgnoreCase))
  546. sbCreate.Append(" char(8)");
  547. else if (colList[i].Equals("BYRQ", StringComparison.OrdinalIgnoreCase))
  548. sbCreate.Append(" char(8)");
  549. else if (colList[i].Equals("BJYJL", StringComparison.OrdinalIgnoreCase))
  550. sbCreate.Append(" char(4)");
  551. else if (colList[i].Equals("ZSBH", StringComparison.OrdinalIgnoreCase))
  552. sbCreate.Append(" char(18)");
  553. else if (colList[i].Equals("XZM", StringComparison.OrdinalIgnoreCase))
  554. sbCreate.Append(" char(40)");
  555. else if (colList[i].Equals("SYSSDM", StringComparison.OrdinalIgnoreCase))
  556. sbCreate.Append(" char(2)");
  557. else if (colList[i].Equals("XH", StringComparison.OrdinalIgnoreCase))
  558. sbCreate.Append(" char(15)");
  559. else if (colList[i].Equals("ZZMM", StringComparison.OrdinalIgnoreCase))
  560. sbCreate.Append(" char(16)");
  561. else if (colList[i].Equals("MZ", StringComparison.OrdinalIgnoreCase))
  562. sbCreate.Append(" char(24)");
  563. else if (colList[i].Equals("FY", StringComparison.OrdinalIgnoreCase))
  564. sbCreate.Append(" char(24)");
  565. else if (colList[i].Equals("XSH", StringComparison.OrdinalIgnoreCase))
  566. sbCreate.Append(" char(24)");
  567. else if (colList[i].Equals("BH", StringComparison.OrdinalIgnoreCase))
  568. sbCreate.Append(" char(24)");
  569. //if (colList[i].Equals("BM", StringComparison.OrdinalIgnoreCase))
  570. // sbCreate.Append(" char(24)");
  571. else if (colList[i].Equals("YJBYRQ", StringComparison.OrdinalIgnoreCase))
  572. sbCreate.Append(" char(8)");
  573. else if (colList[i].Equals("BZ", StringComparison.OrdinalIgnoreCase))
  574. sbCreate.Append(" char(50)");
  575. else
  576. sbCreate.Append(" char(50)");
  577. if (i != colList.Count - 1)
  578. {
  579. sbCreate.Append(", ");
  580. }
  581. else
  582. {
  583. sbCreate.Append(')');
  584. }
  585. }
  586. OleDbCommand cmd;
  587. cmd = new OleDbCommand(sbCreate.ToString(), conn);
  588. cmd.ExecuteNonQuery();
  589. //插入各行
  590. StringBuilder sbInsert = new StringBuilder();
  591. foreach (DataRow dr in dt.Rows)
  592. {
  593. sbInsert.Clear();
  594. sbInsert.Append("INSERT INTO " + fileName + " (");
  595. for (int i = 0; i < colList.Count; i++)
  596. {
  597. sbInsert.Append(colList[i]);
  598. if (i != colList.Count - 1)
  599. {
  600. sbInsert.Append(", ");
  601. }
  602. }
  603. sbInsert.Append(") VALUES (");
  604. for (int i = 0; i < dt.Columns.Count; i++)
  605. {
  606. sbInsert.Append("'" + dr[i].ToString() + "'");
  607. if (i != dt.Columns.Count - 1)
  608. {
  609. sbInsert.Append(", ");
  610. }
  611. }
  612. sbInsert.Append(')');
  613. cmd = new OleDbCommand(sbInsert.ToString(), conn);
  614. cmd.ExecuteNonQuery();
  615. }
  616. }
  617. catch (Exception ex)
  618. {
  619. throw ex;
  620. }
  621. conn.Close();
  622. //var physicalPath = System.IO.Directory.GetCurrentDirectory() + "\\" + dt.TableName + ".dbf";
  623. //FileInfo finfo = new FileInfo(physicalPath);
  624. //return finfo;
  625. }
  626. /// <summary>
  627. /// 获取信息
  628. /// </summary>
  629. /// <param name="userID">用户ID</param>
  630. /// <returns></returns>
  631. public Entities.Sys_User GetUser(Guid? userID)
  632. {
  633. //查询条件
  634. Expression<Func<Sys_User, bool>> expression = x => x.UserID == userID;
  635. return UserRepository.Value.GetSingle(expression, (x => x.Sys_Role));
  636. }
  637. /// <summary>
  638. /// 获取学生扩展表信息
  639. /// </summary>
  640. /// <param name="userID">用户ID</param>
  641. /// <returns></returns>
  642. public Entities.CF_StudentProfile GetProfile(Guid? userID)
  643. {
  644. //查询条件
  645. Expression<Func<CF_StudentProfile, bool>> expression = x => x.UserID == userID;
  646. return StudentProfileRepository.Value.GetSingle(expression);
  647. }
  648. /// <summary>
  649. /// 获取学生信息
  650. /// </summary>
  651. /// <param name="userID">用户ID</param>
  652. /// <returns></returns>
  653. public Entities.CF_Student GetStudent(Guid? userID)
  654. {
  655. //查询条件
  656. Expression<Func<CF_Student, bool>> expression = x => x.UserID == userID;
  657. return StudentsDAL.Value.StudentRepository.GetSingle(expression);
  658. }
  659. /// <summary>
  660. /// 高考招生表
  661. /// </summary>
  662. /// <param name="userID">用户ID</param>
  663. /// <returns></returns>
  664. public Entities.CF_Recruitstudents GetRecruit(Guid? userID)
  665. {
  666. //查询条件
  667. Expression<Func<CF_Recruitstudents, bool>> expression = x => x.UserID == userID;
  668. return RecruitstudentsRepository.Value.GetSingle(expression);
  669. }
  670. /// <summary>
  671. /// 学生缴费表
  672. /// </summary>
  673. /// <param name="userID">用户ID</param>
  674. /// <returns></returns>
  675. public Entities.CF_StudentAccount GetAccount(Guid? userID)
  676. {
  677. //查询条件
  678. Expression<Func<CF_StudentAccount, bool>> expression = x => x.UserID == userID;
  679. return StudentAccountRepository.Value.GetSingle(expression);
  680. }
  681. /// <summary>
  682. /// 学生联系表
  683. /// </summary>
  684. /// <param name="userID">用户ID</param>
  685. /// <returns></returns>
  686. public Entities.CF_StudentContact GetContact(Guid? userID)
  687. {
  688. //查询条件
  689. Expression<Func<CF_StudentContact, bool>> expression = x => x.UserID == userID;
  690. return StudentContactRepository.Value.GetSingle(expression);
  691. }
  692. /// <summary>
  693. /// 获取学生表列表信息
  694. /// </summary>
  695. /// <returns></returns>
  696. public Entities.CF_Student GetStudenter(Guid? userID)
  697. {
  698. //查询条件
  699. Expression<Func<CF_Student, bool>> expression = x => x.UserID == userID;
  700. return StudentsDAL.Value.StudentRepository.GetSingle(expression);
  701. }
  702. public CF_Student GetReplaceGraduateNo(string ReplaceGraduateNo, Guid? userID)
  703. {
  704. //查询条件
  705. Expression<Func<CF_Student, bool>> expression = x => x.ReplaceGraduateNo == ReplaceGraduateNo;
  706. expression = expression.And(x => x.UserID != userID);
  707. return StudentsDAL.Value.StudentRepository.GetSingle(expression);
  708. }
  709. public Entities.Sys_User GetUserByLoginID(Guid userid)
  710. {
  711. Expression<Func<Sys_User, bool>> user = p => p.UserID == userid;
  712. return UserRepository.Value.GetSingle(user);
  713. }
  714. /// <summary>
  715. /// 查询用户ID
  716. /// </summary>
  717. /// <param name="userId"></param>
  718. /// <returns></returns>
  719. public StudentsView GetStudentfileView(Guid? userId)
  720. {
  721. //查询条件
  722. var query = StudentsDAL.Value.GetStudentQueryable(x => x.UserID == userId);
  723. //if (userId.HasValue)
  724. // query = query.Where(x => x.UserID == userId);
  725. return query.FirstOrDefault();
  726. }
  727. /// <summary>
  728. /// 添加
  729. /// </summary>
  730. /// <param name="studentfileView"></param>
  731. public void Save(StudentsView studentfileView)
  732. {
  733. BaseStudentView tempView = StudentsDAL.Value.GetBaseStudentViewQueryable(x => x.Sys_User.UserID == studentfileView.UserID).FirstOrDefault();
  734. var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)CF_ParameterType.StudentInitPassword);
  735. var roleList = RoleDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Student && x.CF_StudentRole.StudentType == studentfileView.StudentType,(x=>x.CF_StudentRole)).ToList();
  736. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateSpringMonth == null)
  737. throw new Exception("请先设置配置文件的预计毕业月份(春季入学)。");
  738. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateSpringDay == null)
  739. throw new Exception("请先设置配置文件的预计毕业日期(春季入学)。");
  740. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateAutumnMonth == null)
  741. throw new Exception("请先设置配置文件的预计毕业月份(秋季入学)。");
  742. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateAutumnDay == null)
  743. throw new Exception("请先设置配置文件的预计毕业日期(秋季入学)。");
  744. if (studentfileView.GradeMajorID==null)
  745. {
  746. var GradeMajorID=ClassmajorRepository.Value.Entities.Where(x => x.ClassmajorID == (Guid)studentfileView.ClassMajorID).Select(w => w.GrademajorID).FirstOrDefault();
  747. studentfileView.GradeMajorID = (Guid)GradeMajorID;
  748. }
  749. studentfileView.PlanningGraduateDate = Convert.ToDateTime(GetPlanningGraduate((Guid)studentfileView.GradeMajorID));
  750. SaveOrUpdateInternal(studentfileView, tempView, parameter, roleList);
  751. this.UnitOfWork.Commit();
  752. }
  753. private void SaveOrUpdateInternal(StudentsView studentfileView, BaseStudentView tempView, CF_Parameter parameter,
  754. IList<Sys_Role> roleList)
  755. {
  756. Sys_User user;
  757. CF_Student student; //获取学生信息
  758. CF_StudentProfile studentProfile;
  759. CF_StudentContact studentContact;
  760. CF_StudentAccount studentAccount;
  761. CF_Recruitstudents recruitstudents;
  762. List<Guid> StudentID = new List<Guid>();
  763. //以导入信息中的学号查找学生,当没有该学生时新增,否则修改学生信息
  764. if (tempView == null) //studentfileView.UserID == Guid.Empty
  765. {
  766. user = new Sys_User();
  767. user.UserID = Guid.NewGuid();
  768. StudentID.Add(user.UserID);
  769. if (parameter == null)
  770. {
  771. user.Password = ("A" + studentfileView.LoginID).MD5();
  772. }
  773. else
  774. {
  775. if (parameter.Value != null)
  776. {
  777. user.Password = parameter.Value;
  778. }
  779. else
  780. {
  781. user.Password = ("A" + studentfileView.LoginID).MD5();
  782. }
  783. }
  784. user.CreateTime = DateTime.Now;
  785. UnitOfWork.Add(user);
  786. SetNewStatus(user);
  787. //添加学生表
  788. student = new CF_Student();
  789. student.UserID = user.UserID;
  790. student.CreateTime = DateTime.Now;
  791. UnitOfWork.Add(student);
  792. SetNewStatus(student);
  793. //学生扩展信息表
  794. studentProfile = new CF_StudentProfile();
  795. studentProfile.UserID = student.UserID;
  796. studentProfile.CreateTime = DateTime.Now;
  797. UnitOfWork.Add(studentProfile);
  798. SetNewStatus(studentProfile);
  799. studentContact = new CF_StudentContact();
  800. studentContact.UserID = student.UserID;
  801. studentContact.CreateTime = DateTime.Now;
  802. UnitOfWork.Add(studentContact);
  803. SetNewStatus(studentContact);
  804. studentAccount = new CF_StudentAccount();
  805. studentAccount.UserID = student.UserID;
  806. studentAccount.CreateTime = DateTime.Now;
  807. UnitOfWork.Add(studentAccount);
  808. SetNewStatus(studentAccount);
  809. recruitstudents = new CF_Recruitstudents();
  810. recruitstudents.UserID = student.UserID;
  811. recruitstudents.CreateTime = DateTime.Now;
  812. UnitOfWork.Add(recruitstudents);
  813. SetNewStatus(recruitstudents);
  814. }
  815. else
  816. {
  817. user = GetUser(tempView.UserID); //studentfileView.UserID
  818. SetModifyStatus(user);
  819. student = GetStudent(tempView.UserID); //studentfileView.UserID
  820. SetModifyStatus(student);
  821. studentProfile = GetProfile(tempView.UserID); //studentfileView.UserID
  822. SetModifyStatus(studentProfile);
  823. studentContact = GetContact(tempView.UserID); //studentfileView.UserID
  824. SetModifyStatus(studentContact);
  825. studentAccount = GetAccount(tempView.UserID); //studentfileView.UserID
  826. SetModifyStatus(studentAccount);
  827. recruitstudents = GetRecruit(tempView.UserID); //studentfileView.UserID
  828. SetModifyStatus(recruitstudents);
  829. }
  830. user.LoginID = studentfileView.LoginID;
  831. if (!string.IsNullOrEmpty(studentfileView.UserName))
  832. user.Name = studentfileView.UserName;
  833. if (studentfileView.ClassMajorID != null)
  834. student.ClassmajorID = studentfileView.ClassMajorID;
  835. if (studentfileView.SexID != null)
  836. student.SexID = (int)studentfileView.SexID;
  837. if (studentfileView.CertificatesType != null)
  838. student.CertificatesType = studentfileView.CertificatesType;
  839. if (!string.IsNullOrEmpty(studentfileView.IDNumber))
  840. student.IDNumber = studentfileView.IDNumber;
  841. if (studentfileView.IsDreamProject)
  842. student.CF_StudentProfile.IsDreamProject = studentfileView.IsDreamProject;
  843. student.Career = studentfileView.Career;
  844. if (!string.IsNullOrEmpty(studentfileView.PhotoUrl))
  845. {
  846. student.PhotoUrl = studentfileView.PhotoUrl;
  847. }
  848. student.PlanningGraduateDate = studentfileView.PlanningGraduateDate ?? studentfileView.PlanningGraduateDateStr;
  849. //if (student.PlanningGraduateDate == null)
  850. //{
  851. // var GradeMajorID = ClassmajorRepository.Value.Entities.Where(x => x.ClassmajorID == studentfileView.ClassMajorID).FirstOrDefault().GrademajorID;
  852. // student.PlanningGraduateDate = Convert.ToDateTime(GetPlanningGraduate(GradeMajorID.Value));
  853. //}
  854. student.StudentCardNo = studentfileView.StudentCardNo;
  855. //毕、结业证书编号
  856. student.GraduateCardNo = studentfileView.GraduateCardNo;
  857. studentProfile.CultureModelID = studentfileView.CultureModel;
  858. if (studentfileView.StudentType != null)
  859. student.StudentType = studentfileView.StudentType;
  860. if (studentfileView.StudentStatus != null)
  861. student.StudentStatus = studentfileView.StudentStatus;
  862. if (studentfileView.InSchoolStatusID != null)
  863. student.InSchoolStatusID = studentfileView.InSchoolStatusID;
  864. if (studentfileView.ReplaceGraduateNo != null)
  865. student.ReplaceGraduateNo = studentfileView.ReplaceGraduateNo;
  866. user.Sys_Role = new HashSet<Sys_Role>();
  867. roleList = roleList.Where(x => x.CF_StudentRole.StudentType == student.StudentType).ToList();
  868. roleList.ForEach(x => user.Sys_Role.Add(x));
  869. if (!string.IsNullOrEmpty(studentfileView.GraduationPictureUrl))
  870. {
  871. student.GraduationPictureUrl = studentfileView.GraduationPictureUrl;
  872. }
  873. studentProfile.UsedName = studentfileView.UsedName;
  874. studentProfile.DirectorName = studentfileView.DirectorName;
  875. student.BirthDate = studentfileView.BirthDate;
  876. studentProfile.Country = studentfileView.Country;
  877. if (studentfileView.Politics != null)
  878. student.PoliticsID = studentfileView.Politics;
  879. student.NationID = studentfileView.Nation;
  880. studentProfile.Place = studentfileView.Place;
  881. studentProfile.HealthStateID = studentfileView.Healthy;
  882. studentProfile.BloodGroup = studentfileView.BloodGroup;
  883. //studentProfile.BornPlace = studentfileView.BornPlace;
  884. studentProfile.Specialty = studentfileView.Specialty;
  885. studentProfile.Height = studentfileView.Height;
  886. studentProfile.Weight = studentfileView.Weight;
  887. student.Remark = studentfileView.Remarks;
  888. studentContact.Email = studentfileView.Email;
  889. studentContact.QQ = studentfileView.QQ;
  890. studentContact.Mobile = studentfileView.Mobile;
  891. studentContact.Telephone = studentfileView.Telephone;
  892. studentContact.WeChatNum = studentfileView.MicroMsgNo;
  893. studentContact.ZIPCode = studentfileView.ZipCode;
  894. studentContact.Address = studentfileView.Address;
  895. studentContact.WorkUnit = studentfileView.WorkUnit;
  896. studentContact.HomeAddress = studentfileView.HomeAddress;
  897. studentContact.Recipient = studentfileView.Recipient;
  898. studentContact.Dormitory = studentfileView.Dormitory;
  899. studentAccount.CardNo = studentfileView.CardNo;
  900. studentAccount.BankName = studentfileView.BankName;
  901. recruitstudents.EntranceDate = studentfileView.EntranceDate;
  902. recruitstudents.EntranceWayID = studentfileView.EntranceWay;
  903. recruitstudents.ExamineeNum = studentfileView.ExamineeNum;
  904. studentProfile.BornPlace = studentfileView.Placebirth;
  905. recruitstudents.ExamineeType = studentfileView.ExamineeType;
  906. recruitstudents.FeaturesID = studentfileView.Features;
  907. recruitstudents.Score = studentfileView.Score;
  908. recruitstudents.TerritorialID = studentfileView.Territorial;
  909. recruitstudents.Area = studentfileView.Area;
  910. recruitstudents.EnteringSchoolYearID = studentfileView.EnteringSchoolYearID;
  911. UnitOfWork.Commit();
  912. if (StudentID.Count > 0)
  913. {
  914. AddStudentEnd(StudentID);
  915. }
  916. }
  917. /// <summary>
  918. /// 导入更新
  919. /// </summary>
  920. /// <param name="studentfileView"></param>
  921. /// <param name="student"></param>
  922. /// <param name="parameter"></param>
  923. /// <param name="roleList"></param>
  924. private void UpdateInternalForImport(StudentsView studentfileView, CF_Student student, CF_Parameter parameter,
  925. IList<Sys_Role> roleList)
  926. {
  927. SetModifyStatus(student.Sys_User);
  928. SetModifyStatus(student);
  929. SetModifyStatus(student.CF_StudentProfile);
  930. SetModifyStatus(student.CF_StudentContact);
  931. SetModifyStatus(student.CF_StudentAccount);
  932. SetModifyStatus(student.CF_Recruitstudents);
  933. student.Sys_User.LoginID = studentfileView.LoginID;
  934. if (!string.IsNullOrEmpty(studentfileView.UserName))
  935. student.Sys_User.Name = studentfileView.UserName;
  936. if (studentfileView.ClassMajorID != null)
  937. student.ClassmajorID = student.ClassmajorID;
  938. if (studentfileView.SexID != null)
  939. student.SexID = (int)studentfileView.SexID;
  940. if (studentfileView.CertificatesType != null)
  941. student.CertificatesType = studentfileView.CertificatesType;
  942. if (!string.IsNullOrEmpty(studentfileView.IDNumber))
  943. student.IDNumber = studentfileView.IDNumber;
  944. if (studentfileView.IsDreamProject)
  945. student.CF_StudentProfile.IsDreamProject = studentfileView.IsDreamProject;
  946. if (!string.IsNullOrEmpty(studentfileView.Career))
  947. student.Career = studentfileView.Career;
  948. if (!string.IsNullOrEmpty(studentfileView.PhotoUrl))
  949. {
  950. student.PhotoUrl = studentfileView.PhotoUrl;
  951. }
  952. student.PlanningGraduateDate = studentfileView.PlanningGraduateDate ?? studentfileView.PlanningGraduateDateStr;
  953. //if (student.PlanningGraduateDate == null)
  954. //{
  955. // var GradeMajorID = ClassmajorRepository.Value.Entities.Where(x => x.ClassmajorID == studentfileView.ClassMajorID).FirstOrDefault().GrademajorID;
  956. // student.PlanningGraduateDate = Convert.ToDateTime(GetPlanningGraduate(GradeMajorID.Value));
  957. //}
  958. if (!string.IsNullOrEmpty(studentfileView.StudentCardNo))
  959. student.StudentCardNo = studentfileView.StudentCardNo;
  960. //毕、结业证书编号
  961. if (!string.IsNullOrEmpty(studentfileView.GraduateCardNo))
  962. student.GraduateCardNo = studentfileView.GraduateCardNo;
  963. if (studentfileView.CultureModel != null)
  964. student.CF_StudentProfile.CultureModelID = studentfileView.CultureModel;
  965. if (studentfileView.StudentType != null)
  966. student.StudentType = studentfileView.StudentType;
  967. if (studentfileView.StudentStatus != null)
  968. student.StudentStatus = studentfileView.StudentStatus;
  969. if (studentfileView.InSchoolStatusID != null)
  970. student.InSchoolStatusID = studentfileView.InSchoolStatusID;
  971. student.Sys_User.Sys_Role = new HashSet<Sys_Role>();
  972. roleList = roleList.Where(x => x.CF_StudentRole.StudentType == student.StudentType).ToList();
  973. roleList.ForEach(x => student.Sys_User.Sys_Role.Add(x));
  974. if (!string.IsNullOrEmpty(studentfileView.GraduationPictureUrl))
  975. {
  976. student.GraduationPictureUrl = studentfileView.GraduationPictureUrl;
  977. }
  978. if (!string.IsNullOrEmpty(studentfileView.UsedName))
  979. student.CF_StudentProfile.UsedName = studentfileView.UsedName;
  980. if (!string.IsNullOrEmpty(studentfileView.DirectorName))
  981. student.CF_StudentProfile.DirectorName = studentfileView.DirectorName;
  982. if (studentfileView.BirthDate != null)
  983. student.BirthDate = studentfileView.BirthDate;
  984. if (!string.IsNullOrEmpty(studentfileView.Country))
  985. student.CF_StudentProfile.Country = studentfileView.Country;
  986. if (studentfileView.Politics != null)
  987. student.PoliticsID = studentfileView.Politics;
  988. if (studentfileView.Nation != null)
  989. student.NationID = studentfileView.Nation;
  990. if (!string.IsNullOrEmpty(studentfileView.Place))
  991. student.CF_StudentProfile.Place = studentfileView.Place;
  992. if (studentfileView.Healthy != null)
  993. student.CF_StudentProfile.HealthStateID = studentfileView.Healthy;
  994. if (studentfileView.BloodGroup != null)
  995. student.CF_StudentProfile.BloodGroup = studentfileView.BloodGroup;
  996. //studentProfile.BornPlace = studentfileView.BornPlace;
  997. if (!string.IsNullOrEmpty(studentfileView.Specialty))
  998. student.CF_StudentProfile.Specialty = studentfileView.Specialty;
  999. if (!string.IsNullOrEmpty(studentfileView.Height))
  1000. student.CF_StudentProfile.Height = studentfileView.Height;
  1001. if (!string.IsNullOrEmpty(studentfileView.Weight))
  1002. student.CF_StudentProfile.Weight = studentfileView.Weight;
  1003. if (!string.IsNullOrEmpty(studentfileView.Remarks))
  1004. student.Remark = studentfileView.Remarks;
  1005. if (!string.IsNullOrEmpty(studentfileView.Email))
  1006. student.CF_StudentContact.Email = studentfileView.Email;
  1007. if (!string.IsNullOrEmpty(studentfileView.QQ))
  1008. student.CF_StudentContact.QQ = studentfileView.QQ;
  1009. if (!string.IsNullOrEmpty(studentfileView.Mobile))
  1010. student.CF_StudentContact.Mobile = studentfileView.Mobile;
  1011. if (!string.IsNullOrEmpty(studentfileView.Telephone))
  1012. student.CF_StudentContact.Telephone = studentfileView.Telephone;
  1013. if (!string.IsNullOrEmpty(studentfileView.MicroMsgNo))
  1014. student.CF_StudentContact.WeChatNum = studentfileView.MicroMsgNo;
  1015. if (!string.IsNullOrEmpty(studentfileView.ZipCode))
  1016. student.CF_StudentContact.ZIPCode = studentfileView.ZipCode;
  1017. if (!string.IsNullOrEmpty(studentfileView.Address))
  1018. student.CF_StudentContact.Address = studentfileView.Address;
  1019. if (!string.IsNullOrEmpty(studentfileView.WorkUnit))
  1020. student.CF_StudentContact.WorkUnit = studentfileView.WorkUnit;
  1021. if (!string.IsNullOrEmpty(studentfileView.HomeAddress))
  1022. student.CF_StudentContact.HomeAddress = studentfileView.HomeAddress;
  1023. if (!string.IsNullOrEmpty(studentfileView.Recipient))
  1024. student.CF_StudentContact.Recipient = studentfileView.Recipient;
  1025. if (!string.IsNullOrEmpty(studentfileView.Dormitory))
  1026. student.CF_StudentContact.Dormitory = studentfileView.Dormitory;
  1027. if (!string.IsNullOrEmpty(studentfileView.CardNo))
  1028. student.CF_StudentAccount.CardNo = studentfileView.CardNo;
  1029. if (!string.IsNullOrEmpty(studentfileView.BankName))
  1030. student.CF_StudentAccount.BankName = studentfileView.BankName;
  1031. if (studentfileView.EntranceDate != null)
  1032. student.CF_Recruitstudents.EntranceDate = studentfileView.EntranceDate;
  1033. if (studentfileView.EntranceWay != null)
  1034. student.CF_Recruitstudents.EntranceWayID = studentfileView.EntranceWay;
  1035. if (!string.IsNullOrEmpty(studentfileView.ExamineeNum))
  1036. student.CF_Recruitstudents.ExamineeNum = studentfileView.ExamineeNum;
  1037. if (!string.IsNullOrEmpty(studentfileView.Placebirth))
  1038. student.CF_StudentProfile.BornPlace = studentfileView.Placebirth;
  1039. if (studentfileView.ExamineeType != null)
  1040. student.CF_Recruitstudents.ExamineeType = studentfileView.ExamineeType;
  1041. if (studentfileView.Features != null)
  1042. student.CF_Recruitstudents.FeaturesID = studentfileView.Features;
  1043. if (studentfileView.Score != null)
  1044. student.CF_Recruitstudents.Score = studentfileView.Score;
  1045. if (studentfileView.Territorial != null)
  1046. student.CF_Recruitstudents.TerritorialID = studentfileView.Territorial;
  1047. if (!string.IsNullOrEmpty(studentfileView.Area))
  1048. student.CF_Recruitstudents.Area = studentfileView.Area;
  1049. if (studentfileView.EnteringSchoolYearID != null)
  1050. student.CF_Recruitstudents.EnteringSchoolYearID = studentfileView.EnteringSchoolYearID;
  1051. }
  1052. /// <summary>
  1053. /// 导入新增
  1054. /// </summary>
  1055. /// <param name="studentfileView"></param>
  1056. /// <param name="tempView"></param>
  1057. /// <param name="parameter"></param>
  1058. /// <param name="roleList"></param>
  1059. private void SaveInternalForImport(List<StudentsView> studentfileView, BaseStudentView tempView, CF_Parameter parameter,
  1060. IList<Sys_Role> roleList)
  1061. {
  1062. List<Guid> StudentID = new List<Guid>();
  1063. List<Sys_User> userList = new List<Sys_User>();
  1064. List<CF_Student> studentList = new List<CF_Student>(); //获取学生信息
  1065. List<CF_StudentProfile> studentProfileList = new List<CF_StudentProfile>();
  1066. List<CF_StudentContact> studentContactList = new List<CF_StudentContact>();
  1067. List<CF_StudentAccount> studentAccountList = new List<CF_StudentAccount>();
  1068. List<CF_Recruitstudents> recruitstudentsList = new List<CF_Recruitstudents>();
  1069. for (int i = 0; i < studentfileView.Count(); i++)
  1070. {
  1071. var pwd = "";
  1072. if (parameter == null)
  1073. {
  1074. pwd = ("A" + studentfileView[i].LoginID).MD5();
  1075. }
  1076. else
  1077. {
  1078. if (parameter.Value != null)
  1079. {
  1080. pwd = parameter.Value;
  1081. }
  1082. else
  1083. {
  1084. pwd = ("A" + studentfileView[i].LoginID).MD5();
  1085. }
  1086. }
  1087. Sys_User user = new Sys_User();
  1088. int? tpye = null;
  1089. user.LoginID = studentfileView[i].LoginID;
  1090. if (!string.IsNullOrEmpty(studentfileView[i].UserName))
  1091. user.Name = studentfileView[i].UserName;
  1092. if (studentfileView[i].StudentType != null)
  1093. tpye = studentfileView[i].StudentType;
  1094. user.Sys_Role = new HashSet<Sys_Role>();
  1095. roleList = roleList.Where(x => x.CF_StudentRole.StudentType == tpye).ToList();
  1096. roleList.ForEach(x => user.Sys_Role.Add(x));
  1097. userList.Add(new Sys_User
  1098. {
  1099. UserID = Guid.NewGuid(),
  1100. Password = pwd,
  1101. CreateTime = DateTime.Now,
  1102. LoginID = user.LoginID,
  1103. Name = user.Name,
  1104. RecordStatus = (int)SYS_STATUS.USABLE,
  1105. Sys_Role = user.Sys_Role
  1106. });
  1107. StudentID.Add(userList[i].UserID);
  1108. CF_Student students = new CF_Student();
  1109. students.UserID = userList[i].UserID;
  1110. if (studentfileView[i].ClassMajorID != null)
  1111. students.ClassmajorID = studentfileView[i].ClassMajorID;
  1112. if (studentfileView[i].SexID != null)
  1113. students.SexID = (int)studentfileView[i].SexID;
  1114. if (studentfileView[i].BirthDate != null)
  1115. students.BirthDate = studentfileView[i].BirthDate;
  1116. if (studentfileView[i].Politics != null)
  1117. students.PoliticsID = studentfileView[i].Politics;
  1118. if (studentfileView[i].Nation != null)
  1119. students.NationID = studentfileView[i].Nation;
  1120. if (studentfileView[i].CertificatesType != null)
  1121. students.CertificatesType = studentfileView[i].CertificatesType;
  1122. if (!string.IsNullOrEmpty(studentfileView[i].IDNumber))
  1123. students.IDNumber = studentfileView[i].IDNumber;
  1124. if (!string.IsNullOrEmpty(studentfileView[i].GraduationPictureUrl))
  1125. {
  1126. students.GraduationPictureUrl = studentfileView[i].GraduationPictureUrl;
  1127. } if (!string.IsNullOrEmpty(studentfileView[i].Career))
  1128. students.Career = studentfileView[i].Career;
  1129. if (!string.IsNullOrEmpty(studentfileView[i].PhotoUrl))
  1130. {
  1131. students.PhotoUrl = studentfileView[i].PhotoUrl;
  1132. }
  1133. students.PlanningGraduateDate = studentfileView[i].PlanningGraduateDate ?? studentfileView[i].PlanningGraduateDateStr;
  1134. //if (students.PlanningGraduateDate == null)
  1135. //{
  1136. // var GradeMajorID = ClassmajorRepository.Value.Entities.Where(x => x.ClassmajorID == studentfileView[i].ClassMajorID).FirstOrDefault().GrademajorID;
  1137. // students.PlanningGraduateDate = Convert.ToDateTime(GetPlanningGraduate(GradeMajorID.Value));
  1138. //}
  1139. if (!string.IsNullOrEmpty(studentfileView[i].StudentCardNo))
  1140. students.StudentCardNo = studentfileView[i].StudentCardNo;
  1141. //毕、结业证书编号
  1142. if (!string.IsNullOrEmpty(studentfileView[i].GraduateCardNo))
  1143. students.GraduateCardNo = studentfileView[i].GraduateCardNo;
  1144. if (studentfileView[i].StudentType != null)
  1145. students.StudentType = studentfileView[i].StudentType;
  1146. if (studentfileView[i].StudentStatus != null)
  1147. students.StudentStatus = studentfileView[i].StudentStatus;
  1148. if (studentfileView[i].InSchoolStatusID != null)
  1149. students.InSchoolStatusID = studentfileView[i].InSchoolStatusID;
  1150. studentList.Add(new CF_Student
  1151. {
  1152. UserID = students.UserID,
  1153. ClassmajorID = students.ClassmajorID,
  1154. SexID = students.SexID,
  1155. CertificatesType = students.CertificatesType,
  1156. IDNumber = students.IDNumber,
  1157. //IsDreamProject = students.IsDreamProject,
  1158. Career = students.Career,
  1159. PhotoUrl = students.PhotoUrl,
  1160. PlanningGraduateDate = students.PlanningGraduateDate,
  1161. StudentCardNo = students.StudentCardNo,
  1162. GraduateCardNo = students.GraduateCardNo,
  1163. //CultureModel = students.CultureModel,
  1164. StudentType = students.StudentType,
  1165. StudentStatus = students.StudentStatus,
  1166. InSchoolStatusID = students.InSchoolStatusID,
  1167. CreateTime = DateTime.Now,
  1168. RecordStatus = (int)SYS_STATUS.USABLE
  1169. });
  1170. CF_StudentProfile studentProfile = new CF_StudentProfile();
  1171. if (studentfileView[i].IsDreamProject)
  1172. studentProfile.IsDreamProject = studentfileView[i].IsDreamProject;
  1173. if (studentfileView[i].CultureModel != null)
  1174. studentProfile.CultureModelID = studentfileView[i].CultureModel;
  1175. if (!string.IsNullOrEmpty(studentfileView[i].UsedName))
  1176. studentProfile.UsedName = studentfileView[i].UsedName;
  1177. if (!string.IsNullOrEmpty(studentfileView[i].DirectorName))
  1178. studentProfile.DirectorName = studentfileView[i].DirectorName;
  1179. if (!string.IsNullOrEmpty(studentfileView[i].Country))
  1180. studentProfile.Country = studentfileView[i].Country;
  1181. if (!string.IsNullOrEmpty(studentfileView[i].Place))
  1182. studentProfile.Place = studentfileView[i].Place;
  1183. if (studentfileView[i].Healthy != null)
  1184. studentProfile.HealthStateID = studentfileView[i].Healthy;
  1185. if (studentfileView[i].BloodGroup != null)
  1186. studentProfile.BloodGroup = studentfileView[i].BloodGroup;
  1187. //studentProfile.BornPlace = studentfileView.BornPlace;
  1188. if (!string.IsNullOrEmpty(studentfileView[i].Specialty))
  1189. studentProfile.Specialty = studentfileView[i].Specialty;
  1190. if (!string.IsNullOrEmpty(studentfileView[i].Height))
  1191. studentProfile.Height = studentfileView[i].Height;
  1192. if (!string.IsNullOrEmpty(studentfileView[i].Weight))
  1193. studentProfile.Weight = studentfileView[i].Weight;
  1194. if (!string.IsNullOrEmpty(studentfileView[i].Remarks))
  1195. students.Remark = studentfileView[i].Remarks;
  1196. studentProfileList.Add(new CF_StudentProfile
  1197. {
  1198. UserID = students.UserID,
  1199. UsedName = studentProfile.UsedName,
  1200. //GraduationPictureUrl=studentProfile.GraduationPictureUrl,
  1201. DirectorName = studentProfile.DirectorName,
  1202. //BirthDate=studentProfile.BirthDate,
  1203. Country = studentProfile.Country,
  1204. //Politics=studentProfile.Politics,
  1205. //Nation=studentProfile.Nation,
  1206. Place = studentProfile.Place,
  1207. HealthStateID = studentProfile.HealthStateID,
  1208. BloodGroup = studentProfile.BloodGroup,
  1209. Specialty = studentProfile.Specialty,
  1210. Height = studentProfile.Height,
  1211. Weight = studentProfile.Weight,
  1212. //Remarks = studentProfile.Remarks,
  1213. CreateTime = DateTime.Now,
  1214. RecordStatus = (int)SYS_STATUS.USABLE
  1215. });
  1216. CF_StudentContact studentContact = new CF_StudentContact();
  1217. if (!string.IsNullOrEmpty(studentfileView[i].Email))
  1218. studentContact.Email = studentfileView[i].Email;
  1219. if (!string.IsNullOrEmpty(studentfileView[i].QQ))
  1220. studentContact.QQ = studentfileView[i].QQ;
  1221. if (!string.IsNullOrEmpty(studentfileView[i].Mobile))
  1222. studentContact.Mobile = studentfileView[i].Mobile;
  1223. if (!string.IsNullOrEmpty(studentfileView[i].Telephone))
  1224. studentContact.Telephone = studentfileView[i].Telephone;
  1225. if (!string.IsNullOrEmpty(studentfileView[i].MicroMsgNo))
  1226. studentContact.WeChatNum = studentfileView[i].MicroMsgNo;
  1227. if (!string.IsNullOrEmpty(studentfileView[i].ZipCode))
  1228. studentContact.ZIPCode = studentfileView[i].ZipCode;
  1229. if (!string.IsNullOrEmpty(studentfileView[i].Address))
  1230. studentContact.Address = studentfileView[i].Address;
  1231. if (!string.IsNullOrEmpty(studentfileView[i].WorkUnit))
  1232. studentContact.WorkUnit = studentfileView[i].WorkUnit;
  1233. if (!string.IsNullOrEmpty(studentfileView[i].HomeAddress))
  1234. studentContact.HomeAddress = studentfileView[i].HomeAddress;
  1235. if (!string.IsNullOrEmpty(studentfileView[i].Recipient))
  1236. studentContact.Recipient = studentfileView[i].Recipient;
  1237. if (!string.IsNullOrEmpty(studentfileView[i].Dormitory))
  1238. studentContact.Dormitory = studentfileView[i].Dormitory;
  1239. studentContactList.Add(new CF_StudentContact
  1240. {
  1241. UserID = students.UserID,
  1242. Email = studentContact.Email,
  1243. QQ = studentContact.QQ,
  1244. Mobile = studentContact.Mobile,
  1245. Telephone = studentContact.Telephone,
  1246. WeChatNum = studentContact.WeChatNum,
  1247. ZIPCode = studentContact.ZIPCode,
  1248. Address = studentContact.Address,
  1249. WorkUnit = studentContact.WorkUnit,
  1250. HomeAddress = studentContact.HomeAddress,
  1251. Recipient = studentContact.Recipient,
  1252. Dormitory = studentContact.Dormitory,
  1253. CreateTime = DateTime.Now,
  1254. RecordStatus = (int)SYS_STATUS.USABLE
  1255. });
  1256. CF_StudentAccount studentAccount = new CF_StudentAccount();
  1257. if (!string.IsNullOrEmpty(studentfileView[i].CardNo))
  1258. studentAccount.CardNo = studentfileView[i].CardNo;
  1259. if (!string.IsNullOrEmpty(studentfileView[i].BankName))
  1260. studentAccount.BankName = studentfileView[i].BankName;
  1261. studentAccountList.Add(new CF_StudentAccount
  1262. {
  1263. UserID = students.UserID,
  1264. CardNo = studentAccount.CardNo,
  1265. BankName = studentAccount.BankName,
  1266. CreateTime = DateTime.Now,
  1267. RecordStatus = (int)SYS_STATUS.USABLE
  1268. });
  1269. CF_Recruitstudents recruitstudents = new CF_Recruitstudents();
  1270. if (studentfileView[i].EntranceDate != null)
  1271. recruitstudents.EntranceDate = studentfileView[i].EntranceDate;
  1272. if (studentfileView[i].EntranceWay != null)
  1273. recruitstudents.EntranceWayID = studentfileView[i].EntranceWay;
  1274. if (!string.IsNullOrEmpty(studentfileView[i].ExamineeNum))
  1275. recruitstudents.ExamineeNum = studentfileView[i].ExamineeNum;
  1276. //if (!string.IsNullOrEmpty(studentfileView[i].Placebirth))
  1277. // recruitstudents.PlaceBirth = studentfileView[i].Placebirth;
  1278. if (studentfileView[i].ExamineeType != null)
  1279. recruitstudents.ExamineeType = studentfileView[i].ExamineeType;
  1280. if (studentfileView[i].Features != null)
  1281. recruitstudents.FeaturesID = studentfileView[i].Features;
  1282. if (studentfileView[i].Score != null)
  1283. recruitstudents.Score = studentfileView[i].Score;
  1284. if (studentfileView[i].Territorial != null)
  1285. recruitstudents.TerritorialID = studentfileView[i].Territorial;
  1286. if (!string.IsNullOrEmpty(studentfileView[i].Area))
  1287. recruitstudents.Area = studentfileView[i].Area;
  1288. if (studentfileView[i].EnteringSchoolYearID != null)
  1289. recruitstudents.EnteringSchoolYearID = studentfileView[i].EnteringSchoolYearID;
  1290. recruitstudentsList.Add(new CF_Recruitstudents
  1291. {
  1292. UserID = students.UserID,
  1293. EntranceDate = recruitstudents.EntranceDate,
  1294. EntranceWayID = recruitstudents.EntranceWayID,
  1295. ExamineeNum = recruitstudents.ExamineeNum,
  1296. //PlaceBirth=recruitstudents.PlaceBirth,
  1297. ExamineeType = recruitstudents.ExamineeType,
  1298. FeaturesID = recruitstudents.FeaturesID,
  1299. Score = recruitstudents.Score,
  1300. TerritorialID = recruitstudents.TerritorialID,
  1301. Area = recruitstudents.Area,
  1302. EnteringSchoolYearID = recruitstudents.EnteringSchoolYearID,
  1303. CreateTime = DateTime.Now,
  1304. RecordStatus = (int)SYS_STATUS.USABLE
  1305. });
  1306. }
  1307. UnitOfWork.BulkInsert(userList);
  1308. UnitOfWork.BulkInsert(userList, (x => x.Sys_Role));
  1309. UnitOfWork.BulkInsert(studentList);
  1310. UnitOfWork.BulkInsert(studentProfileList);
  1311. UnitOfWork.BulkInsert(studentContactList);
  1312. UnitOfWork.BulkInsert(studentAccountList);
  1313. UnitOfWork.BulkInsert(recruitstudentsList);
  1314. //UnitOfWork.Commit();
  1315. AddStudentEnd(StudentID);
  1316. }
  1317. /// <summary>
  1318. /// 学生添加后进行数据插入
  1319. /// </summary>
  1320. /// <param name="studentID"></param>
  1321. public virtual void AddStudentEnd(List<Guid> studentID)
  1322. {
  1323. var inschoolStatusList = InSchoolSettingRepository.Value.GetList(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  1324. var schoolYear = SchoolYearServices.Value.GetCurrentSchoolYear();
  1325. Expression<Func<CF_Student, bool>> exp = x => studentID.Contains(x.UserID);
  1326. //要新增的学生
  1327. var studentEntityList = StudentsDAL.Value.StudentRepository.GetList(exp).ToList();
  1328. var classIDs = studentEntityList.Select(x => x.ClassmajorID).Distinct().ToList();
  1329. var ClassmajorList = StudentsDAL.Value.ClassmajorRepository.GetList(w => classIDs.Contains(w.ClassmajorID), i => i.CF_Grademajor.CF_Schoolyear).ToList();
  1330. var grademajorIDList = ClassmajorList.Select(x => x.GrademajorID).Distinct().ToList();
  1331. var grademajorList = StudentsDAL.Value.GrademajorRepository.GetList(w => grademajorIDList.Contains(w.GrademajorID)).ToList();
  1332. //修改教学数据只需要修改在校的学生
  1333. exp = exp.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  1334. #region 5.0 教学任务插入异动学生代码段......
  1335. var studentSchedulingClassList = StudentsDAL.Value.GetStudentRelateCourseViewQueryable(exp).ToList();
  1336. List<StudentsView> educationSchedulingClassStudentInsert = new List<StudentsView>();
  1337. foreach (var studentSchedulingClass in studentSchedulingClassList)
  1338. {
  1339. //情况1:找到同班同学,并且自己学号最小,塞同班同学的第一个班
  1340. var classmateSchdulingList = studentSchedulingClass
  1341. .StudentRelateSchedulingClassViewList
  1342. .Where(x => x.ClassmajorIDList.Contains(studentSchedulingClass.ClassmajorID))
  1343. .OrderBy(x => x.EducationMissionClassName)
  1344. .ToList();
  1345. if (classmateSchdulingList.Count > 0 && studentSchedulingClass.LoginID.CompareTo(classmateSchdulingList.Max(x => x.MinLoginID)) < 0)
  1346. {
  1347. var minMissionClassName = classmateSchdulingList.Min(x => x.EducationMissionClassName);
  1348. var minSchedulingClassID = classmateSchdulingList.Where(x => x.EducationMissionClassName == minMissionClassName).Select(x => x.EducationSchedulingClassID).FirstOrDefault();
  1349. if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == minSchedulingClassID))
  1350. {
  1351. educationSchedulingClassStudentInsert.Add(new StudentsView
  1352. {
  1353. UserID = studentSchedulingClass.UserID ?? Guid.Empty,
  1354. TepTableID = minSchedulingClassID
  1355. });
  1356. }
  1357. }
  1358. //情况2:找到同班同学,并且自己学号不是最小,塞第一个自己不是最大的班,如果没有,塞最后一个班
  1359. else if (classmateSchdulingList.Count > 0 && studentSchedulingClass.LoginID.CompareTo(classmateSchdulingList.Max(x => x.MinLoginID)) >= 0)
  1360. {
  1361. foreach (var classmateScheduling in classmateSchdulingList)
  1362. {
  1363. if (studentSchedulingClass.LoginID.CompareTo(classmateScheduling.MaxLoginID) <= 0)
  1364. {
  1365. if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == classmateScheduling.EducationSchedulingClassID))
  1366. {
  1367. educationSchedulingClassStudentInsert.Add(new StudentsView
  1368. {
  1369. UserID = studentSchedulingClass.UserID ?? Guid.Empty,
  1370. TepTableID = classmateScheduling.EducationSchedulingClassID
  1371. });
  1372. break;
  1373. }
  1374. }
  1375. if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == classmateScheduling.EducationSchedulingClassID))
  1376. {
  1377. educationSchedulingClassStudentInsert.Add(new StudentsView
  1378. {
  1379. UserID = studentSchedulingClass.UserID ?? Guid.Empty,
  1380. TepTableID = classmateScheduling.EducationSchedulingClassID
  1381. });
  1382. }
  1383. }
  1384. }
  1385. //情况3:找不到同班同学,但排课班已经有人,塞顺序下来人最少的班
  1386. else if (classmateSchdulingList.Count == 0 && studentSchedulingClass.StudentRelateSchedulingClassViewList.Any(x => x.StudentCount > 0))
  1387. {
  1388. var minStudentCount = studentSchedulingClass.StudentRelateSchedulingClassViewList.Min(x => x.StudentCount);
  1389. var minSchedulingClassID = studentSchedulingClass.StudentRelateSchedulingClassViewList.Where(x => x.StudentCount == minStudentCount)
  1390. .OrderBy(x => x.EducationMissionClassName)
  1391. .Select(x => x.EducationSchedulingClassID).FirstOrDefault();
  1392. if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == minSchedulingClassID))
  1393. {
  1394. educationSchedulingClassStudentInsert.Add(new StudentsView
  1395. {
  1396. UserID = studentSchedulingClass.UserID ?? Guid.Empty,
  1397. TepTableID = minSchedulingClassID
  1398. });
  1399. }
  1400. }
  1401. //情况4:找不到同班同学,而且排课班没人,塞第一个班
  1402. else if (classmateSchdulingList.Count == 0 && !studentSchedulingClass.StudentRelateSchedulingClassViewList.Any(x => x.StudentCount > 0))
  1403. {
  1404. var minSchedulingClassID = studentSchedulingClass.StudentRelateSchedulingClassViewList
  1405. .OrderBy(x => x.EducationMissionClassName)
  1406. .Select(x => x.EducationSchedulingClassID).FirstOrDefault();
  1407. if (!educationSchedulingClassStudentInsert.Any(x => x.UserID == studentSchedulingClass.UserID && x.TepTableID == minSchedulingClassID))
  1408. {
  1409. educationSchedulingClassStudentInsert.Add(new StudentsView
  1410. {
  1411. UserID = studentSchedulingClass.UserID ?? Guid.Empty,
  1412. TepTableID = minSchedulingClassID
  1413. });
  1414. }
  1415. }
  1416. }
  1417. //var educationSchedulingClassStudentInsert = StudentsDAL.Value.GetEducationSchedulingClassStudentInsert(exp).Distinct().ToList();
  1418. var educationSchedulingClassIDInsertList = educationSchedulingClassStudentInsert.Select(x => x.TepTableID).Distinct().ToList();
  1419. var educationSchedulingClassEntityList = StudentsDAL.Value.EducationSchedulingClassRepository
  1420. .GetList(x => educationSchedulingClassIDInsertList.Contains(x.EducationSchedulingClassID), (x => x.CF_Student)).ToList();
  1421. //批量插入准备
  1422. var educationSchedulingClassStudentInsertList = new List<Relation2KeyTable>();
  1423. foreach (var educationScheduling in educationSchedulingClassStudentInsert)
  1424. {
  1425. Guid? educationSchedulingClassID = educationScheduling.TepTableID;
  1426. EM_EducationSchedulingClass educationSchedulingClassEntity = educationSchedulingClassEntityList.Where(x => x.EducationSchedulingClassID == educationSchedulingClassID).FirstOrDefault();
  1427. if (educationSchedulingClassEntity != null && educationScheduling.UserID != null)
  1428. {
  1429. if (!educationSchedulingClassEntity.CF_Student.Where(x => x.UserID == educationScheduling.UserID).Any())
  1430. {
  1431. //var student = studentEntityList.Where(x => x.UserID == educationScheduling.UserID).FirstOrDefault();
  1432. //if(student!=null){
  1433. //educationSchedulingClassEntity.CF_Student.Add(student);
  1434. educationSchedulingClassStudentInsertList.Add(new Relation2KeyTable { Key1 = educationSchedulingClassEntity.EducationSchedulingClassID, Key2 = educationScheduling.UserID });
  1435. //}
  1436. }
  1437. }
  1438. }
  1439. #endregion
  1440. #region 6.0 考场安排插入异动学生代码段......
  1441. //var educationPlanInsertList = StudentsDAL.Value.GetExaminationPlanStudentInsert(educationSchedulingClassStudentInsert).ToList();
  1442. //var educationPlanStudentList = educationPlanInsertList.Select(x => x.CF_Student).ToList();
  1443. ////批量插入准备
  1444. //var educationSchedulingClassStudentList = new List<Relation2KeyTable>();
  1445. ////因为导入学生会有不同的班所以要通过班来循环
  1446. //foreach (var classID in classIDs)
  1447. //{
  1448. // foreach (var educationPlanStudent in educationPlanStudentList)
  1449. // {
  1450. // //找到考场安排对应的班
  1451. // var educationPlanStudentClass = educationPlanStudent.Where(x => x.ClassmajorID == classID);
  1452. // var educationPlanStudents = educationPlanInsertList.Where(x => x.CF_Student == educationPlanStudentClass);
  1453. // //找到对应班里的学生
  1454. // var studentList=studentEntityList.Where(x=>x.ClassmajorID==classID).ToList();
  1455. // //添加学生
  1456. // foreach(var student in studentList)
  1457. // {
  1458. // educationPlanStudents.ForEach(x => x.CF_Student.Add(student));
  1459. // }
  1460. // }
  1461. //}
  1462. // var examinationPlanStudentInsert = DifferentDynamicDAL.GetExaminationPlanStudentInsert(x => x.SchoolyearID == schoolYear).ToList();
  1463. //2016年11月8日11:32:50 zhanghl
  1464. //TODO: 由于考场安排涉及座位安排、暂时不做插入数据处理......
  1465. #endregion
  1466. #region 7.0 成绩管理插入异动学生代码段......
  1467. var scoreStudentInsert = StudentsDAL.Value.GetScoreStudentInsert(exp, (x => x.EM_EducationSchedulingClass
  1468. .Any(w => educationSchedulingClassIDInsertList.Contains(w.EducationSchedulingClassID)))).Distinct().ToList();
  1469. var TepTableID = scoreStudentInsert.Select(x => x.TepTableID).Distinct().ToList();
  1470. var finalExaminationList = StudentsDAL.Value.FinalExaminationRepository.GetList(x => TepTableID.Contains(x.FinalExaminationID),
  1471. (x => x.ER_FinalExaminationStudent)).ToList();
  1472. var finalExaminationStudentInsertList = new List<ER_FinalExaminationStudent>();
  1473. foreach (var scoreStudent in scoreStudentInsert)
  1474. {
  1475. ER_FinalExamination finalExaminationEntity = finalExaminationList.Where(x => x.FinalExaminationID == scoreStudent.TepTableID).FirstOrDefault();
  1476. if (finalExaminationEntity != null)
  1477. {
  1478. if (!finalExaminationEntity.ER_FinalExaminationStudent.Where(x => x.UserID == scoreStudent.UserID).Any())
  1479. {
  1480. var Students = studentEntityList.Where(x => x.UserID == scoreStudent.UserID).FirstOrDefault();
  1481. finalExaminationStudentInsertList.Add(new ER_FinalExaminationStudent
  1482. {
  1483. FinalExaminationStudentID = Guid.NewGuid(),
  1484. FinalExaminationID = finalExaminationEntity.FinalExaminationID,
  1485. SchoolyearNumID = (schoolYear.Value - ((Students.CF_Classmajor.CF_Grademajor.GradeID * 2) - 1 + (Students.CF_Classmajor.CF_Grademajor.SemesterID - 1)) - (schoolYear.SchoolcodeID == Students.CF_Classmajor.CF_Grademajor.SemesterID ? 0 : 1)) / 2 + 1,
  1486. StarttermID = schoolYear.Value - ((Students.CF_Classmajor.CF_Grademajor.GradeID * 2) - 1 + (Students.CF_Classmajor.CF_Grademajor.SemesterID - 1)) + 1,
  1487. UserID = scoreStudent.UserID,
  1488. RecordStatus = (int)SYS_STATUS.USABLE,
  1489. CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
  1490. CreateTime = DateTime.Now,
  1491. ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
  1492. ModifyTime = DateTime.Now
  1493. });
  1494. }
  1495. }
  1496. }
  1497. #endregion
  1498. #region 8.0 教学评价插入异动学生代码段......
  1499. var evaluationSettingStudentInsert = StudentsDAL.Value.GetEvaluationSettingStudentInsert(exp).Distinct().ToList();
  1500. var evaluationSettingIDList = evaluationSettingStudentInsert.Select(x => x.TepTableID).Distinct().ToList();
  1501. var evaluationSettingStudentID = evaluationSettingStudentInsert.Select(x => x.UserID).Distinct().ToList();
  1502. var evaluationSettingEntityList = StudentsDAL.Value.EvaluationSettingRepository
  1503. .GetList(x => evaluationSettingIDList.Contains(x.EvaluationSettingID) && x.OpenStatus == (int)CF_YesOrNoStatus.No, (x => x.CF_Student)).ToList();
  1504. var evaluationSettingStudentInsertList = new List<Relation2KeyTable>();
  1505. foreach (var evaluationSettingID in evaluationSettingIDList)
  1506. {
  1507. EM_EvaluationSetting evaluationSettingEntity = evaluationSettingEntityList.Where(x => x.EvaluationSettingID == evaluationSettingID).FirstOrDefault();
  1508. if (evaluationSettingEntity != null)
  1509. {
  1510. foreach (var student in studentID)
  1511. {
  1512. if (evaluationSettingStudentID.Contains(student))
  1513. {
  1514. if (!evaluationSettingEntity.CF_Student.Where(x => x.UserID == student).Any())
  1515. {
  1516. evaluationSettingStudentInsertList.Add(new Relation2KeyTable { Key1 = evaluationSettingEntity.EvaluationSettingID, Key2 = student });
  1517. //var Students = studentEntityList.Where(x => x.UserID == student).FirstOrDefault();
  1518. //evaluationSettingEntity.CF_Student.Add(Students);
  1519. }
  1520. }
  1521. }
  1522. }
  1523. }
  1524. #endregion
  1525. #region 9.0学生征订
  1526. var studentOrderAddList = StudentsDAL.Value.GetAddStudentsOrder(exp).ToList();
  1527. studentOrderAddList.ForEach(x => x.OrderQty++);
  1528. #endregion
  1529. #region 10.0学生发放
  1530. var studentDistributeAddList = StudentsDAL.Value.GetAddStudentDistribute(exp).ToList();
  1531. studentDistributeAddList.ForEach(x => x.DistributeQty++);
  1532. #endregion
  1533. UnitOfWork.BulkInsert<EM_EducationSchedulingClass, CF_Student>(educationSchedulingClassStudentInsertList);
  1534. UnitOfWork.BulkInsert(finalExaminationStudentInsertList);
  1535. UnitOfWork.BulkInsert<EM_EvaluationSetting, CF_Student>(evaluationSettingStudentInsertList);
  1536. UnitOfWork.Commit();
  1537. }
  1538. /// <summary>
  1539. /// 删除(删除成功后,对相应的录取名单信息进行更新--提交状态)
  1540. /// </summary>
  1541. /// <param name="userIDs"></param>
  1542. /// <returns></returns>
  1543. public bool UserDelete(List<Guid> userIDs)
  1544. {
  1545. try
  1546. {
  1547. List<CF_NewStudent> newStudentUpList = new List<CF_NewStudent>();
  1548. //查询对应的学生信息List
  1549. var studentList = StudentsDAL.Value.StudentRepository
  1550. .GetList(x => userIDs.Contains(x.UserID), (x => x.Sys_User)).ToList();
  1551. //对应的身份证号List
  1552. var iDNumberList = studentList.Where(x => !string.IsNullOrEmpty(x.IDNumber))
  1553. .Select(x => x.IDNumber.Trim()).ToList();
  1554. //根据身份证号查询对应的录取名单信息List
  1555. var newStudentList = NewStudentRepository.Value
  1556. .GetList(x => iDNumberList.Contains(x.IDNumber)).ToList();
  1557. foreach (var student in studentList)
  1558. {
  1559. var newStudent = newStudentList.Where(x => x.IDNumber == student.IDNumber
  1560. && x.StudentNo == student.Sys_User.LoginID).SingleOrDefault();
  1561. if (newStudent != null)
  1562. {
  1563. newStudent.RecordStatus = (int)CF_NewStudentEnterStatus.NotSubmitted;
  1564. SetModifyStatus(newStudent);
  1565. newStudentUpList.Add(newStudent);
  1566. }
  1567. }
  1568. UnitOfWork.Remove<CF_StudentExperience>(x => userIDs.Contains((Guid)x.UserID));
  1569. UnitOfWork.Remove<CF_StudentFamily>(x => userIDs.Contains((Guid)x.UserID));
  1570. UnitOfWork.Remove<CF_StudentContact>(x => userIDs.Contains(x.UserID));
  1571. UnitOfWork.Remove<CF_StudentAccount>(x => userIDs.Contains(x.UserID));
  1572. UnitOfWork.Remove<CF_Recruitstudents>(x => userIDs.Contains(x.UserID));
  1573. UnitOfWork.Remove<CF_StudentProfile>(x => userIDs.Contains(x.UserID));
  1574. UnitOfWork.Remove<CF_Student>(x => userIDs.Contains(x.UserID));
  1575. var userList = this.UserRepository.Value.GetList(x => userIDs.Contains(x.UserID), (x => x.Sys_Role)).ToList();
  1576. userList.ForEach(x => x.Sys_Role = new HashSet<Sys_Role>());
  1577. UnitOfWork.Remove<Sys_User>(x => userIDs.Contains(x.UserID));
  1578. UnitOfWork.Commit();
  1579. return true;
  1580. }
  1581. catch (Exception)
  1582. {
  1583. throw;
  1584. }
  1585. }
  1586. /// <summary>
  1587. /// Excel导入
  1588. /// </summary>
  1589. /// <param name="dataSource"></param>
  1590. /// <returns></returns>
  1591. public virtual DataTable Import(DataTable dataSource)
  1592. {
  1593. var errorSource = dataSource.Clone();
  1594. errorSource.Columns.Add("错误信息");
  1595. //添加错误并且排除必填字段为空的记录行
  1596. var errorList = AddErrorAndExceptEmptyDataRow(dataSource);
  1597. //添加错误并且排除重复的记录行
  1598. errorList.AddRange(AddErrorAndExceptRepetitiveDataRow(dataSource));
  1599. //现改为可重复导入学生,并以学号关键字修改学生相关信息表,因此注释掉排除重复学号方法:邓智荣
  1600. //添加错误并且排除已存在的记录
  1601. //AddErrorAndExceptExistingDataRow(dataSource);
  1602. var views = MapToStudentsView(dataSource, errorList);
  1603. errorList.ForEach(x =>
  1604. AddError(errorSource, x.Row, x.Error)
  1605. );
  1606. if (errorSource.Rows.Count == 0)
  1607. {
  1608. SaveOrUpdate(views);
  1609. }
  1610. return errorSource;
  1611. }
  1612. /// <summary>
  1613. /// 添加错误并且排除必填字段为空的记录行
  1614. /// </summary>
  1615. /// <param name="dataSource"></param>
  1616. /// <returns></returns>
  1617. private List<ImportErrorRowView> AddErrorAndExceptEmptyDataRow(DataTable dataSource)
  1618. {
  1619. var dic = new Dictionary<string, string>
  1620. {
  1621. {"学号","学号不能为空"},
  1622. {"姓名","姓名不能为空"},
  1623. {"性别","性别不能为空"},
  1624. {"证件类型","证件类型不能为空"},
  1625. {"证件号码","证件号码不能为空"},
  1626. {"班级名称","班级名称不能为空"},
  1627. {"学籍状态","学籍状态不能为空"},
  1628. {"在校状态","在校状态不能为空"},
  1629. {"入学学年学期","入学学年学期不能为空"},
  1630. };
  1631. var errorRowList = (from ds in dataSource.AsEnumerable()
  1632. from pair in dic
  1633. where string.IsNullOrEmpty(ds.Field<string>(pair.Key))
  1634. group pair by ds into g
  1635. select new ImportErrorRowView { Row = g.Key, Error = string.Join(",", g.Select(x => x.Value)) })
  1636. .ToList();
  1637. //foreach (var errorRow in errorRowList)
  1638. //{
  1639. // AddError(errorSource, errorRow.Row, errorRow.Error);
  1640. // dataSource.Rows.Remove(errorRow.Row);
  1641. //}
  1642. return errorRowList;
  1643. //foreach (var pair in dic)
  1644. //{
  1645. // var query = dataSource.AsEnumerable().Where(w => string.IsNullOrEmpty(w.Field<string>(pair.Key))).ToArray();
  1646. // foreach (var dr in query)
  1647. // {
  1648. // AddError(errorSource, dr, pair.Value);
  1649. // dataSource.Rows.Remove(dr);
  1650. // }
  1651. //}
  1652. }
  1653. /// <summary>
  1654. /// 添加错误并且排除重复的记录行
  1655. /// </summary>
  1656. /// <param name="dataSource"></param>
  1657. /// <returns></returns>
  1658. private List<ImportErrorRowView> AddErrorAndExceptRepetitiveDataRow(DataTable dataSource)
  1659. {
  1660. var query = dataSource.AsEnumerable()
  1661. .GroupBy(key => key.Field<string>("学号"))
  1662. .Where(w => w.Count() > 1 && !string.IsNullOrEmpty(w.Key))
  1663. .SelectMany(s => s)
  1664. .Select(x => new ImportErrorRowView { Row = x, Error = "学号重复" }).ToList();
  1665. //foreach (var dr in query)
  1666. //{
  1667. // AddError(errorSource, dr, "学号重复");
  1668. // dataSource.Rows.Remove(dr);
  1669. //}
  1670. return query;
  1671. }
  1672. /// <summary>
  1673. /// 添加错误并且排除已存在的记录
  1674. /// </summary>
  1675. /// <param name="dataSource"></param>
  1676. /// <returns></returns>
  1677. private List<ImportErrorRowView> AddErrorAndExceptExistingDataRow(DataTable dataSource)
  1678. {
  1679. var loginIDs = dataSource.AsEnumerable().Select(s => s.Field<string>("学号")).ToArray();
  1680. var hasLoginIds = UserRepository.Value.GetList(w => loginIDs.Contains(w.LoginID)).Select(s => s.LoginID).ToArray();
  1681. var query = dataSource.AsEnumerable().Where(w => hasLoginIds.Contains(w.Field<string>("学号")))
  1682. .Select(x => new ImportErrorRowView { Row = x, Error = "该学号已存在" }).ToList();
  1683. return query;
  1684. //foreach (var dr in query)
  1685. //{
  1686. // AddError(errorSource, dr, "该学号已存在");
  1687. // dataSource.Rows.Remove(dr);
  1688. //}
  1689. }
  1690. /// <summary>
  1691. /// Excel导入判断
  1692. /// </summary>
  1693. /// <param name="dataSource"></param>
  1694. /// <param name="errorList"></param>
  1695. /// <returns></returns>
  1696. private StudentsView[] MapToStudentsView(DataTable dataSource, List<ImportErrorRowView> errorList)
  1697. {
  1698. var views = new List<StudentsView>();
  1699. var classNames = dataSource.AsEnumerable().Select(s => s.Field<string>("班级名称").Trim()).Distinct().ToArray();
  1700. var classes = ClassmajorRepository.Value.GetList(w => classNames.Contains(w.Name.Trim()), i => i.CF_Grademajor.CF_Schoolyear).ToArray();
  1701. var schoolYearCodes = dataSource.AsEnumerable().Select(s => s.Field<string>("入学学年学期").Trim()).Distinct().ToArray();
  1702. var schoolYears = SchoolyearRepository.Value.GetList(w => schoolYearCodes.Contains(w.Code.Trim())).ToArray();
  1703. var dictionarySex = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex);
  1704. var dictionaryCertificatesType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType);
  1705. var dictionaryStudentStatus = IdNameExt.GetDictionaryItem(DictionaryItem.CF_StudentStatus);
  1706. var dictionaryInschoolStatus = IdNameExt.GetDictionaryItem(DictionaryItem.CF_InschoolStatus);
  1707. var dictionaryStudentType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_STUDENTTYPE);
  1708. var dictionaryCultureModel = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CULTUREMODEL);
  1709. var dictionaryExamineeType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EXAMINEETYPE);
  1710. var dictionaryEntranceWay = IdNameExt.GetDictionaryItem(DictionaryItem.CF_EntranceWay);
  1711. var dictionaryFeatures = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Features);
  1712. var dictionaryTerritorial = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Province);
  1713. var dictionaryNation = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation);
  1714. var dictionaryHealthy = IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState);
  1715. var dictionaryBloodGroup = IdNameExt.GetDictionaryItem(DictionaryItem.CF_BLOODGROUP);
  1716. var dictionaryPolitics = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Politics);
  1717. var dictionaryIsDreamProject = IdNameExt.GetDictionaryItem(DictionaryItem.CF_YesOrNoStatus);
  1718. DataTimeHelper dth = new DataTimeHelper();
  1719. string temp;
  1720. string isDreamProject;
  1721. foreach (DataRow dr in dataSource.Rows)
  1722. {
  1723. List<string> errorMessageList = new List<string>();
  1724. var view = new StudentsView();
  1725. view.LoginID = (dr.Field<string>("学号") ?? "").Trim();
  1726. view.UserName = (dr.Field<string>("姓名") ?? "").Trim();
  1727. view.Career = (dr.Field<string>("在校经历") ?? "").Trim();
  1728. #region 性别
  1729. var sexField = dr.Field<string>("性别");
  1730. if (!string.IsNullOrEmpty(sexField))
  1731. {
  1732. var sex = dictionarySex.SingleOrDefault(w => w.Name.Trim() == sexField.Trim());
  1733. if (sex == null)
  1734. {
  1735. errorMessageList.Add("性别数据格式不正确");
  1736. //AddError(errorSource, dr, "性别数据格式不正确");
  1737. //continue;
  1738. }
  1739. else
  1740. {
  1741. view.SexID = sex.Value;
  1742. }
  1743. }
  1744. #endregion
  1745. #region 是否是圆梦计划
  1746. isDreamProject = (dr.Field<string>("是否是圆梦计划") ?? "").Trim();
  1747. if (!string.IsNullOrEmpty(isDreamProject))
  1748. {
  1749. var IsDreamProject = dictionaryIsDreamProject.SingleOrDefault(w => w.Name.Trim() == isDreamProject);
  1750. if (IsDreamProject == null)
  1751. {
  1752. errorMessageList.Add("是否是圆梦计划数据格式不正确");
  1753. //AddError(errorSource, dr, "是否是圆梦计划数据格式不正确");
  1754. //continue;
  1755. }
  1756. else
  1757. {
  1758. view.IsDreamProject = IsDreamProject.Value == 0 ? false : true;
  1759. }
  1760. }
  1761. #endregion
  1762. #region 证件类型
  1763. var certificatesTypeField = dr.Field<string>("证件类型");
  1764. if (!string.IsNullOrEmpty(certificatesTypeField))
  1765. {
  1766. var certificatesType = dictionaryCertificatesType.SingleOrDefault(w => w.Name.Trim() == certificatesTypeField.Trim());
  1767. if (certificatesType == null)
  1768. {
  1769. errorMessageList.Add("证件类型数据格式不正确");
  1770. //AddError(errorSource, dr, "证件类型数据格式不正确");
  1771. //continue;
  1772. }
  1773. else
  1774. {
  1775. view.CertificatesType = certificatesType.Value;
  1776. }
  1777. }
  1778. #endregion
  1779. view.IDNumber = (dr.Field<string>("证件号码") ?? "");
  1780. #region 班级名称
  1781. var classField = dr.Field<string>("班级名称");
  1782. if (!string.IsNullOrEmpty(classField))
  1783. {
  1784. var @class = classes.SingleOrDefault(w => w.Name.Trim() == classField.Trim());
  1785. if (@class == null)
  1786. {
  1787. errorMessageList.Add("班级名称不存在");
  1788. //AddError(errorSource, dr, "班级名称不存在");
  1789. //continue;
  1790. }
  1791. else
  1792. {
  1793. view.ClassMajorID = @class.ClassmajorID;
  1794. view.PlanningGraduateDate = PlanningGraduateDateHelper.GetPlanningGraduateDate(@class.CF_Grademajor.CF_Schoolyear.FirstWeek);
  1795. //string PlanningGraduateDate = GetPlanningGraduate(@class.CF_Grademajor.GrademajorID);
  1796. //view.PlanningGraduateDate = GetPlanningGraduate(@class.CF_Grademajor.GrademajorID);//设置预计毕业时间
  1797. }
  1798. }
  1799. #endregion
  1800. #region 学籍状态
  1801. var studentStatusField = dr.Field<string>("学籍状态");
  1802. if (!string.IsNullOrEmpty(studentStatusField))
  1803. {
  1804. var studentStatus = dictionaryStudentStatus.SingleOrDefault(w => w.Name.Trim() == studentStatusField.Trim());
  1805. if (studentStatus == null)
  1806. {
  1807. errorMessageList.Add("学籍状态数据格式不正确");
  1808. //AddError(errorSource, dr, "学籍状态数据格式不正确");
  1809. //continue;
  1810. }
  1811. else
  1812. {
  1813. view.StudentStatus = studentStatus.Value;
  1814. }
  1815. }
  1816. #endregion
  1817. #region 在校状态
  1818. var inschoolStatusField = dr.Field<string>("在校状态");
  1819. if (!string.IsNullOrEmpty(inschoolStatusField))
  1820. {
  1821. var inschoolStatus = dictionaryInschoolStatus.SingleOrDefault(w => w.Name.Trim() == inschoolStatusField.Trim());
  1822. if (inschoolStatus == null)
  1823. {
  1824. errorMessageList.Add("在校状态数据格式不正确");
  1825. //AddError(errorSource, dr, "在校状态数据格式不正确");
  1826. //continue;
  1827. }
  1828. else
  1829. {
  1830. view.InSchoolStatusID = inschoolStatus.Value;
  1831. }
  1832. }
  1833. #endregion
  1834. #region 入学学年学期
  1835. var schoolYearField = dr.Field<string>("入学学年学期");
  1836. if (!string.IsNullOrEmpty(schoolYearField))
  1837. {
  1838. var schoolYear = schoolYears.SingleOrDefault(w => w.Code.Trim() == schoolYearField.Trim());
  1839. if (schoolYear == null)
  1840. {
  1841. errorMessageList.Add("入学学年学期不存在");
  1842. //AddError(errorSource, dr, "入学学年学期不存在");
  1843. //continue;
  1844. }
  1845. else
  1846. {
  1847. view.EnteringSchoolYearID = schoolYear.SchoolyearID;
  1848. }
  1849. }
  1850. #endregion
  1851. #region 学生类别
  1852. temp = (dr.Field<string>("学生类别") ?? "").Trim();
  1853. if (!string.IsNullOrEmpty(temp))
  1854. {
  1855. var ent = dictionaryStudentType.SingleOrDefault(w => w.Name.Trim() == temp);
  1856. if (ent == null)
  1857. {
  1858. errorMessageList.Add("学生类别不存在");
  1859. //AddError(errorSource, dr, "学生类别不存在");
  1860. //continue;
  1861. }
  1862. else
  1863. {
  1864. view.StudentType = ent.Value;
  1865. }
  1866. }
  1867. #endregion
  1868. #region 培养方式
  1869. temp = (dr.Field<string>("培养方式") ?? "").Trim();
  1870. if (!string.IsNullOrEmpty(temp))
  1871. {
  1872. var ent = dictionaryCultureModel.SingleOrDefault(w => w.Name.Trim() == temp);
  1873. if (ent == null)
  1874. {
  1875. errorMessageList.Add("培养方式不存在");
  1876. //AddError(errorSource, dr, "培养方式不存在");
  1877. //continue;
  1878. }
  1879. else
  1880. {
  1881. view.CultureModel = ent.Value;
  1882. }
  1883. }
  1884. #endregion
  1885. view.StudentCardNo = (dr.Field<string>("学籍卡编号") ?? "").Trim();
  1886. view.GraduateCardNo = (dr.Field<string>("毕结业证书编号") ?? "").Trim();
  1887. view.ExamineeNum = (dr.Field<string>("教育部考生号") ?? "").Trim();
  1888. #region 考生类别
  1889. temp = (dr.Field<string>("考生类别") ?? "").Trim();
  1890. if (!string.IsNullOrEmpty(temp))
  1891. {
  1892. var ent = dictionaryExamineeType.SingleOrDefault(w => w.Name.Trim() == temp);
  1893. if (ent == null)
  1894. {
  1895. errorMessageList.Add("考生类别不存在");
  1896. //AddError(errorSource, dr, "考生类别不存在");
  1897. //continue;
  1898. }
  1899. else
  1900. {
  1901. view.ExamineeType = ent.Value;
  1902. }
  1903. }
  1904. #endregion
  1905. #region 入学日期
  1906. temp = (dr.Field<string>("入学日期") ?? "").Trim();
  1907. if (!string.IsNullOrEmpty(temp))
  1908. {
  1909. DateTime dt;
  1910. if (!DateTime.TryParseExact(temp, "yyyyMMdd", null, 0, out dt))
  1911. {
  1912. if (!DateTime.TryParse(temp, out dt))
  1913. {
  1914. errorMessageList.Add("入学日期数据格式不正确");
  1915. //AddError(errorSource, dr, "入学日期数据格式不正确");
  1916. //continue;
  1917. }
  1918. else
  1919. {
  1920. view.EntranceDate = dt;
  1921. }
  1922. }
  1923. else
  1924. {
  1925. view.EntranceDate = dt;
  1926. }
  1927. }
  1928. #endregion
  1929. #region 入学方式
  1930. temp = (dr.Field<string>("入学方式") ?? "").Trim();
  1931. if (!string.IsNullOrEmpty(temp))
  1932. {
  1933. var ent = dictionaryEntranceWay.SingleOrDefault(w => w.Name.Trim() == temp);
  1934. if (ent == null)
  1935. {
  1936. errorMessageList.Add("入学方式不存在");
  1937. //AddError(errorSource, dr, "入学方式不存在");
  1938. //continue;
  1939. }
  1940. else
  1941. {
  1942. view.EntranceWay = ent.Value;
  1943. }
  1944. }
  1945. #endregion
  1946. view.Placebirth = (dr.Field<string>("出生地") ?? "").Trim();
  1947. #region 考生特征
  1948. temp = (dr.Field<string>("考生特征") ?? "").Trim();
  1949. if (!string.IsNullOrEmpty(temp))
  1950. {
  1951. var ent = dictionaryFeatures.SingleOrDefault(w => w.Name.Trim() == temp);
  1952. if (ent == null)
  1953. {
  1954. errorMessageList.Add("考生特征不存在");
  1955. //AddError(errorSource, dr, "考生特征不存在");
  1956. //continue;
  1957. }
  1958. else
  1959. {
  1960. view.Features = ent.Value;
  1961. }
  1962. }
  1963. #endregion
  1964. #region 高考总分
  1965. temp = (dr.Field<string>("高考总分") ?? "").Trim();
  1966. if (!string.IsNullOrEmpty(temp))
  1967. {
  1968. decimal d;
  1969. if (!decimal.TryParse(temp, out d))
  1970. {
  1971. errorMessageList.Add("高考总分数据格式不正确");
  1972. //AddError(errorSource, dr, "高考总分数据格式不正确");
  1973. //continue;
  1974. }
  1975. else
  1976. {
  1977. view.Score = d;
  1978. }
  1979. }
  1980. #endregion
  1981. #region 生源所属地
  1982. temp = (dr.Field<string>("生源所属地") ?? "").Trim();
  1983. if (!string.IsNullOrEmpty(temp))
  1984. {
  1985. var ent = dictionaryTerritorial.SingleOrDefault(w => w.Name.Trim() == temp);
  1986. if (ent == null)
  1987. {
  1988. errorMessageList.Add("生源所属地不存在");
  1989. //AddError(errorSource, dr, "生源所属地不存在");
  1990. //continue;
  1991. }
  1992. else
  1993. {
  1994. view.Territorial = ent.Value;
  1995. }
  1996. }
  1997. #endregion
  1998. view.Area = (dr.Field<string>("来源地区") ?? "").Trim();
  1999. view.UsedName = (dr.Field<string>("曾用名") ?? "").Trim();
  2000. view.DirectorName = (dr.Field<string>("导师姓名") ?? "").Trim();
  2001. #region 出生日期
  2002. temp = (dr.Field<string>("出生日期") ?? "").Trim();
  2003. if (!string.IsNullOrEmpty(temp))
  2004. {
  2005. DateTime dt;
  2006. if (!DateTime.TryParseExact(temp, "yyyyMMdd", null, 0, out dt))
  2007. {
  2008. if (!DateTime.TryParse(temp, out dt))
  2009. {
  2010. errorMessageList.Add("出生日期数据格式不正确");
  2011. //AddError(errorSource, dr, "出生日期数据格式不正确");
  2012. //continue;
  2013. }
  2014. else
  2015. {
  2016. view.BirthDate = dt;
  2017. }
  2018. }
  2019. else
  2020. {
  2021. view.BirthDate = dt;
  2022. }
  2023. }
  2024. #endregion
  2025. view.Country = (dr.Field<string>("国籍") ?? "").Trim();
  2026. // view.Politics = (dr.Field<string>("政治面貌") ?? "").Trim();
  2027. #region 政治面貌
  2028. temp = (dr.Field<string>("政治面貌") ?? "").Trim();
  2029. if (!string.IsNullOrEmpty(temp))
  2030. {
  2031. var politics = dictionaryPolitics.SingleOrDefault(w => w.Name.Trim() == temp);
  2032. if (politics == null)
  2033. {
  2034. errorMessageList.Add("政治面貌不存在");
  2035. //AddError(errorSource, dr, "政治面貌不存在");
  2036. //continue;
  2037. }
  2038. else
  2039. {
  2040. view.Politics = politics.Value;
  2041. }
  2042. }
  2043. #endregion
  2044. #region 民族
  2045. temp = (dr.Field<string>("民族") ?? "").Trim();
  2046. if (!string.IsNullOrEmpty(temp))
  2047. {
  2048. var ent = dictionaryNation.SingleOrDefault(w => w.Name.Trim() == temp);
  2049. if (ent == null)
  2050. {
  2051. errorMessageList.Add("民族不存在");
  2052. //AddError(errorSource, dr, "民族不存在");
  2053. //continue;
  2054. }
  2055. else
  2056. {
  2057. view.Nation = ent.Value;
  2058. }
  2059. }
  2060. #endregion
  2061. view.Place = (dr.Field<string>("籍贯") ?? "").Trim();
  2062. #region 健康状态
  2063. temp = (dr.Field<string>("健康状态") ?? "").Trim();
  2064. if (!string.IsNullOrEmpty(temp))
  2065. {
  2066. var ent = dictionaryHealthy.SingleOrDefault(w => w.Name.Trim() == temp);
  2067. if (ent == null)
  2068. {
  2069. errorMessageList.Add("健康状态不存在");
  2070. //AddError(errorSource, dr, "健康状态不存在");
  2071. //continue;
  2072. }
  2073. else
  2074. {
  2075. view.Healthy = ent.Value;
  2076. }
  2077. }
  2078. #endregion
  2079. #region 血型
  2080. temp = (dr.Field<string>("血型") ?? "").Trim();
  2081. if (!string.IsNullOrEmpty(temp))
  2082. {
  2083. var ent = dictionaryBloodGroup.SingleOrDefault(w => w.Name.Trim() == temp);
  2084. if (ent == null)
  2085. {
  2086. errorMessageList.Add("血型不存在");
  2087. //AddError(errorSource, dr, "血型不存在");
  2088. //continue;
  2089. }
  2090. else
  2091. {
  2092. view.BloodGroup = ent.Value;
  2093. }
  2094. }
  2095. #endregion
  2096. view.Specialty = (dr.Field<string>("特长") ?? "").Trim();
  2097. view.Height = (dr.Field<string>("身高") ?? "").Trim();
  2098. view.Weight = (dr.Field<string>("体重") ?? "").Trim();
  2099. view.Remarks = (dr.Field<string>("备注") ?? "").Trim();
  2100. view.CardNo = (dr.Field<string>("银行卡号") ?? "").Trim();
  2101. view.BankName = (dr.Field<string>("开户银行") ?? "").Trim();
  2102. view.Email = (dr.Field<string>("电子邮件") ?? "").Trim();
  2103. view.QQ = (dr.Field<string>("QQ") ?? "").Trim();
  2104. view.Mobile = (dr.Field<string>("移动电话") ?? "").Trim();
  2105. view.Telephone = (dr.Field<string>("固定电话") ?? "").Trim();
  2106. view.MicroMsgNo = (dr.Field<string>("微信号") ?? "").Trim();
  2107. view.ZipCode = (dr.Field<string>("邮编") ?? "").Trim();
  2108. view.Address = (dr.Field<string>("通信地址") ?? "").Trim();
  2109. view.WorkUnit = (dr.Field<string>("工作单位") ?? "").Trim();
  2110. view.HomeAddress = (dr.Field<string>("家庭地址") ?? "").Trim();
  2111. view.Recipient = (dr.Field<string>("收件人") ?? "").Trim();
  2112. view.Dormitory = (dr.Field<string>("宿舍编号") ?? "").Trim();
  2113. if (errorMessageList.Count > 0)
  2114. {
  2115. if (errorList.Any(x => x.Row == dr))
  2116. {
  2117. var errorRow = errorList.First(x => x.Row == dr);
  2118. errorRow.Error += "," + string.Join(",", errorMessageList);
  2119. }
  2120. else
  2121. {
  2122. errorList.Add(new ImportErrorRowView { Row = dr, Error = string.Join(",", errorMessageList) });
  2123. }
  2124. }
  2125. else if (!errorList.Any(x => x.Row == dr))
  2126. {
  2127. views.Add(view);
  2128. }
  2129. }
  2130. return views.ToArray();
  2131. }
  2132. /// <summary>
  2133. ///
  2134. /// </summary>
  2135. /// <param name="dtError"></param>
  2136. /// <param name="dataRow"></param>
  2137. /// <param name="message"></param>
  2138. private void AddError(DataTable dtError, DataRow dataRow, string message)
  2139. {
  2140. var dr = dtError.NewRow();
  2141. if (dataRow != null)
  2142. {
  2143. dr.ItemArray = dataRow.ItemArray;
  2144. }
  2145. dr["错误信息"] = message;
  2146. dtError.Rows.Add(dr);
  2147. }
  2148. /// <summary>
  2149. /// 新增、修改
  2150. /// </summary>
  2151. /// <param name="studentsViews"></param>
  2152. private void SaveOrUpdate(params StudentsView[] studentsViews)
  2153. {
  2154. var loginIDList = studentsViews.Select(x => x.LoginID).ToList();
  2155. var existsStudentViewList = StudentsDAL.Value.StudentRepository.GetList(x => loginIDList.Contains(x.Sys_User.LoginID),
  2156. (x => x.Sys_User.Sys_Role),
  2157. (x => x.CF_StudentProfile),
  2158. (x => x.CF_StudentContact),
  2159. (x => x.CF_StudentAccount),
  2160. (x => x.CF_Recruitstudents)).ToList();
  2161. var needAddList = existsStudentViewList.Select(x => x.Sys_User.LoginID).ToList();
  2162. var addStudentsViews = studentsViews.Where(x => !needAddList.Contains(x.LoginID)).ToList();
  2163. var parameter = ParameterDAL.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)ViewModel.CF_ParameterType.StudentInitPassword);
  2164. var roleList = RoleDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Student, (x => x.CF_StudentRole)).ToList();
  2165. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateSpringMonth == null)
  2166. throw new Exception("请先设置配置文件的预计毕业月份(春季入学)。");
  2167. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateSpringDay == null)
  2168. throw new Exception("请先设置配置文件的预计毕业日期(春季入学)。");
  2169. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateAutumnMonth == null)
  2170. throw new Exception("请先设置配置文件的预计毕业月份(秋季入学)。");
  2171. if (EMIS.Utility.Const.LOCAL_SETTING_PlanningGraduateDateAutumnDay == null)
  2172. throw new Exception("请先设置配置文件的预计毕业日期(秋季入学)。");
  2173. SaveInternalForImport(addStudentsViews, null, parameter, roleList);
  2174. UnitOfWork.Delete(existsStudentViewList.Select(x => x.Sys_User).ToList(), (x => x.Sys_Role));
  2175. foreach (var item in studentsViews)
  2176. {
  2177. var student = existsStudentViewList.FirstOrDefault(x => x.Sys_User.LoginID == item.LoginID);
  2178. if (student != null)
  2179. {
  2180. UpdateInternalForImport(item, student, parameter, roleList);
  2181. }
  2182. }
  2183. UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.Sys_User).ToList());
  2184. UnitOfWork.BatchUpdate(existsStudentViewList);
  2185. UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.CF_StudentProfile).ToList());
  2186. UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.CF_StudentContact).ToList());
  2187. UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.CF_StudentAccount).ToList());
  2188. UnitOfWork.BatchUpdate(existsStudentViewList.Select(x => x.CF_Recruitstudents).ToList());
  2189. UnitOfWork.BulkInsert(existsStudentViewList.Select(x => x.Sys_User).ToList(), (x => x.Sys_Role));
  2190. //UnitOfWork.Commit();
  2191. }
  2192. public void GraduationPicImport(IList<string> photoPaths)
  2193. {
  2194. var map = photoPaths
  2195. .Select(s => new
  2196. {
  2197. IDNum = Path.GetFileNameWithoutExtension(s).Trim(),
  2198. PhotoPath = s,
  2199. })
  2200. .ToArray();
  2201. var idNums = map.Select(s => s.IDNum).Distinct().ToArray();
  2202. var studentList = StudentsDAL.Value.StudentRepository.GetList(w => idNums.Contains(w.IDNumber), (x => x.CF_StudentProfile)).ToList();
  2203. foreach (var idNum in idNums)
  2204. {
  2205. var student = studentList.FirstOrDefault(w => w.IDNumber == idNum);
  2206. if (student == null)
  2207. {
  2208. throw new Exception("导入照片中存在无法匹对信息,请检查文件名是否正确。");
  2209. }
  2210. }
  2211. foreach (var m in map)
  2212. {
  2213. var student = studentList.FirstOrDefault(w => w.IDNumber == m.IDNum);
  2214. if (student != null)
  2215. {
  2216. student.GraduationPictureUrl = m.PhotoPath;
  2217. }
  2218. }
  2219. UnitOfWork.Commit();
  2220. }
  2221. public virtual void PicImport(IList<string> photoPaths)
  2222. {
  2223. var map = photoPaths
  2224. .Select(s => new
  2225. {
  2226. LoginID = Path.GetFileNameWithoutExtension(s).Trim(),
  2227. PhotoPath = s,
  2228. })
  2229. .ToArray();
  2230. var loginIds = map.Select(s => s.LoginID).Distinct().ToArray();
  2231. var users = UserRepository.Value.GetList(w => loginIds.Contains(w.LoginID), i => i.CF_Student).ToList();
  2232. foreach (var loginId in loginIds)
  2233. {
  2234. var user = users.FirstOrDefault(w => w.LoginID == loginId);
  2235. if (user == null)
  2236. {
  2237. throw new Exception("导入照片中存在无法匹对信息,请检查文件名是否正确。");
  2238. }
  2239. }
  2240. foreach (var m in map)
  2241. {
  2242. var user = users.FirstOrDefault(w => w.LoginID == m.LoginID);
  2243. if (user != null)
  2244. {
  2245. user.CF_Student.PhotoUrl = m.PhotoPath;
  2246. }
  2247. }
  2248. UnitOfWork.Commit();
  2249. }
  2250. public DateTime? ReckonPlanningGraduateDate(Guid GrademajorID)
  2251. {
  2252. //由于LINQ不识别方法的系统的时间 ToDateTime(系统,字符串)的方法、将计算时间移至外围
  2253. StudentsView studentsEntity = StudentsDAL.Value.GetPlanningGraduateDate(GrademajorID);
  2254. return studentsEntity.PlanningGraduateDate.Value.AddDays(studentsEntity.WeeksNum);
  2255. }
  2256. //private DateTime GetPlanningGraduate(DateTime firstWeek)
  2257. //{
  2258. // if (firstWeek.Month >= 1 && firstWeek.Month <= 6)
  2259. // {
  2260. // return new DateTime(firstWeek.Year, 6, 30);
  2261. // }
  2262. // else
  2263. // {
  2264. // return new DateTime((firstWeek.Year + 1), 1, 31);
  2265. // }
  2266. //}
  2267. public string GetPlanningGraduate(Guid GrademajorID)
  2268. {
  2269. var graduationSchoolyear = this.SchoolyearRepository.Value.GetSingle(x => x.CF_Grademajor.Any(w => w.GrademajorID == GrademajorID));
  2270. var date = PlanningGraduateDateHelper.GetPlanningGraduateDate(graduationSchoolyear.FirstWeek);
  2271. return date.ToString("yyyy-MM-dd");
  2272. //return GetPlanningGraduate(graduationSchoolyear.FirstWeek).ToString("yyyy-MM-dd");
  2273. //StudentsView studentsEntity = StudentsDAL.Value.GetPlanningGraduate(GrademajorID);
  2274. //int PlanningGraduate = (int)studentsEntity.Years;
  2275. //try
  2276. //{
  2277. // string SetPlanningGraduate;
  2278. // if (studentsEntity.PlanningGraduateSchoolCode == (int)EMIS.ViewModel.CF_Schoolcode.Spring)
  2279. // {
  2280. // SetPlanningGraduate = studentsEntity.PlanningGraduateYear.ToString() + "-06-30";
  2281. // }
  2282. // else if (studentsEntity.PlanningGraduateSchoolCode == (int)EMIS.ViewModel.CF_Schoolcode.Autumn)
  2283. // { //因秋季是跨年,毕业年份需要+1年
  2284. // SetPlanningGraduate = (studentsEntity.PlanningGraduateYear + 1).ToString() + "-01-31";
  2285. // }
  2286. // else
  2287. // throw new Exception("学期设置有问题,请核查");
  2288. // return SetPlanningGraduate;
  2289. //}
  2290. //catch
  2291. //{
  2292. // return "";
  2293. //}
  2294. //预计毕业时间,原来逻辑有问题,默认值为2016-01-31+30个月也就是2018-07-31,当学制不为3或2.5时,返回2018-07-31+学制年数:邓智荣
  2295. //DateTime SetPlanningGraduate = Convert.ToDateTime("2016-01-31").AddMonths(30);
  2296. //DateTime SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate.ToString() + "-06-30");
  2297. //if (studentsEntity.LearnSystem == 3)
  2298. //{
  2299. // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-06-30");
  2300. // // SetPlanningGraduate.AddYears((int)studentsEntity.LearnSystem);
  2301. //}
  2302. //if (studentsEntity.LearnSystem == (Decimal)2.5)
  2303. //{
  2304. // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-01-31");
  2305. // // SetPlanningGraduate.AddMonths((int)studentsEntity.LearnSystem * 12);
  2306. //}
  2307. ////原逻辑只有学制2.5和3的判断,现加上2和4
  2308. //if (studentsEntity.LearnSystem == 2 || studentsEntity.LearnSystem == 4)
  2309. //{
  2310. // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-06-30");
  2311. //}
  2312. //if (Convert.ToInt32(studentsEntity.LearnSystem) == studentsEntity.LearnSystem)
  2313. //{ //2、3或4年制
  2314. // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-06-30");
  2315. //}
  2316. //else
  2317. //{ //2.5或3.5年制
  2318. // SetPlanningGraduate = Convert.ToDateTime(PlanningGraduate + "-01-31");
  2319. //}
  2320. //return SetPlanningGraduate.AddYears((int)studentsEntity.LearnSystem);//2.5 转int 2
  2321. }
  2322. public void ClearPhotoUrl(IList<Guid> studentIDList)
  2323. {
  2324. this.UnitOfWork.Update<CF_Student>((x => new CF_Student { PhotoUrl = null }), (x => studentIDList.Contains(x.UserID)));
  2325. }
  2326. public virtual int? GetDefaultLearnformForList()
  2327. {
  2328. return null;
  2329. }
  2330. /// <summary>
  2331. ///
  2332. /// </summary>
  2333. /// <returns></returns>
  2334. public int GetDataRange()
  2335. {
  2336. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  2337. var curUserID = curUser.UserID;
  2338. if (curUser.IsStudent)
  2339. {
  2340. return 6;
  2341. }
  2342. var menuNo = HttpHelper.GetMenuNo();
  2343. if (string.IsNullOrEmpty(menuNo))
  2344. {
  2345. menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
  2346. }
  2347. SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo);
  2348. switch (dataRange)
  2349. {
  2350. case SYS_DataRange.All:
  2351. default:
  2352. return (int)SYS_DataRange.All;
  2353. case SYS_DataRange.Campus:
  2354. return (int)SYS_DataRange.Campus;
  2355. case SYS_DataRange.College:
  2356. return (int)SYS_DataRange.College;
  2357. case SYS_DataRange.Department:
  2358. return (int)SYS_DataRange.Department;
  2359. case SYS_DataRange.Teacher:
  2360. return (int)SYS_DataRange.Teacher;
  2361. case SYS_DataRange.Assistant:
  2362. return (int)SYS_DataRange.Assistant;
  2363. }
  2364. }
  2365. }
  2366. }