ExaminationPlanServices.cs 200 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Data.Entity;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.DataLogic.ExaminationManage;
  10. using EMIS.Entities;
  11. using EMIS.ViewModel;
  12. using EMIS.ViewModel.ExaminationManage;
  13. using EMIS.Utility.FormValidate;
  14. using EMIS.DataLogic.UniversityManage.TeacherManage;
  15. using EMIS.ViewModel.Students;
  16. using EMIS.DataLogic.UniversityManage.ClassroomManage;
  17. using EMIS.DataLogic.Common.Students;
  18. using EMIS.DataLogic.ScoreManage;
  19. using EMIS.CommonLogic.CalendarManage;
  20. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  21. using Bowin.Common.DataTime;
  22. using Bowin.Common.Utility;
  23. using EMIS.Utility;
  24. using EMIS.DataLogic.Repositories;
  25. using AutoMapper;
  26. using System.Text.RegularExpressions;
  27. using System.IO;
  28. using EMIS.DataLogic.UniversityManage.AdministrativeOrgan;
  29. using EMIS.CommonLogic.EducationSchedule;
  30. using EMIS.CommonLogic.SystemServices;
  31. using EMIS.ViewModel.EducationSchedule;
  32. using EMIS.ViewModel.CalendarManage;
  33. using System.Transactions;
  34. using EMIS.ViewModel.UniversityManage.TeacherManage;
  35. namespace EMIS.CommonLogic.ExaminationManage
  36. {
  37. public class ExaminationPlanServices : BaseWorkflowServices<ER_FinalExamination>, IExaminationPlanServices
  38. {
  39. public UserRepository UserRepository { get; set; }
  40. public ExaminationRoomSettingRepository ExaminationRoomSettingRepository { get; set; }
  41. public EducationSchedulingRepository EducationSchedulingRepository { get; set; }
  42. public ExaminationPlanRepository examinationPlanRepository { get; set; }
  43. public ExaminationPlanDAL ExaminationPlanDAL { get; set; }
  44. public ExaminationTeacherDAL ExaminationTeacherDAL { get; set; }
  45. public FinalExaminationDAL FinalExaminationDAL { get; set; }
  46. public RoomSettingDAL RoomSettingDAL { get; set; }
  47. public TimeSegmentDAL TimeSegmentDAL { get; set; }
  48. public StaffDAL StaffDAL { get; set; }
  49. public StudentsDAL StudentsDAL { get; set; }
  50. public ClassroomDAL ClassroomDAL { get; set; }
  51. public CollegeDAL CollegeDAL { get; set; }
  52. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  53. public Lazy<EMIS.CommonLogic.EducationSchedule.IScheduleServices> ScheduleServices { get; set; }
  54. public Lazy<IClassroomExcessiveUseServices> ClassroomExcessiveUseServices { get; set; }
  55. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ExaminationManage.ExaminationPlanView> GetExaminationPlanViewList(
  56. ViewModel.ConfiguretView examinationPlanView,
  57. Guid? schoolyearID, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? starWeek, int? endWeek, int? courseEndWeek, int? statusID,
  58. int pageIndex, int pageSize)
  59. {
  60. Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  61. if (schoolyearID.HasValue)
  62. {
  63. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  64. }
  65. if (collegeID.HasValue)
  66. {
  67. exp = exp.And(x => x.CollegeID == collegeID);
  68. }
  69. if(gradeYearID.HasValue)
  70. {
  71. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
  72. .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
  73. }
  74. if(standardID.HasValue)
  75. {
  76. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
  77. .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
  78. }
  79. if (coursematerialID.HasValue)
  80. {
  81. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  82. }
  83. if (examsCategoryID.HasValue)
  84. {
  85. exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
  86. }
  87. if (examinationModeID.HasValue)
  88. {
  89. exp = exp.And(x => x.ExaminationModeID == examinationModeID);
  90. }
  91. if (examinationStyleID.HasValue)
  92. {
  93. exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
  94. }
  95. if (statusID.HasValue)
  96. {
  97. exp = exp.And(x => x.RecordStatus == statusID);
  98. }
  99. if (starWeek.HasValue)
  100. {
  101. exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum >= starWeek));
  102. }
  103. if(endWeek.HasValue)
  104. {
  105. exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum <= endWeek));
  106. }
  107. var q = ExaminationPlanDAL.GetExaminationPlanView(exp);
  108. if(courseEndWeek.HasValue)
  109. {
  110. q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
  111. }
  112. if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
  113. q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
  114. try
  115. {
  116. return this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToGridResultSet<ExaminationPlanView>(pageIndex, pageSize);
  117. }
  118. catch (Exception ex)
  119. {
  120. throw ex;
  121. }
  122. }
  123. public IGridResultSet<ExaminationPlanView> GetGdssExaminationPlanViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, Guid? classmajorID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? courseEndWeek, int? statusID, int pageIndex, int pageSize)
  124. {
  125. Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  126. if (schoolyearID.HasValue)
  127. {
  128. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  129. }
  130. if (collegeID.HasValue)
  131. {
  132. //原先是用教学任务关联的由于补考记录没有对应的教学任务,所以改用专业课程关联,
  133. //学校那边说不会有多个教研室开同一门可的情况,即使有,那这些教研室同样可以查到,也没有问题
  134. exp = exp.And(x => x.EM_Coursematerial.EM_SpecialtyCourse.Any(w => w.CF_Department.CollegeID == collegeID && w.IsEnable == true));
  135. }
  136. if (gradeYearID.HasValue)
  137. {
  138. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
  139. .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
  140. }
  141. if (standardID.HasValue)
  142. {
  143. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
  144. .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
  145. }
  146. if (coursematerialID.HasValue)
  147. {
  148. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  149. }
  150. if (examsCategoryID.HasValue)
  151. {
  152. exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
  153. }
  154. if (examinationModeID.HasValue)
  155. {
  156. exp = exp.And(x => x.ExaminationModeID == examinationModeID);
  157. }
  158. if (examinationStyleID.HasValue)
  159. {
  160. exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
  161. }
  162. if (classmajorID.HasValue)
  163. {
  164. var classmajor = ExaminationPlanDAL.ClassmajorRepository.GetList(x => x.ClassmajorID == classmajorID).FirstOrDefault();
  165. exp = exp.And(x => x.ClassName == classmajor.Name);
  166. }
  167. if (statusID.HasValue)
  168. {
  169. exp = exp.And(x => x.RecordStatus == statusID);
  170. }
  171. var q = ExaminationPlanDAL.GetExaminationPlanView(exp);
  172. if (courseEndWeek.HasValue)
  173. {
  174. q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
  175. }
  176. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  177. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  178. try
  179. {
  180. var result = this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToGridResultSet<ExaminationPlanView>(pageIndex, pageSize);
  181. var ExaminationPlanID = result.rows.Select(x => x.ExaminationPlanID).ToList();
  182. var ExaminationPlanTeacherList = ExaminationPlanDAL.GetExaminationRoomLayoutView(x => ExaminationPlanID.Contains((Guid)x.ExaminationPlanID)).ToList();
  183. result.rows.ForEach(x => x.ExaminationRoomLayoutView = new HashSet<ExaminationRoomLayoutView>(ExaminationPlanTeacherList.Where(y => y.ExaminationPlanID == x.ExaminationPlanID)));
  184. return result;
  185. }
  186. catch (Exception ex)
  187. {
  188. throw ex;
  189. }
  190. }
  191. public List<ViewModel.ExaminationManage.ExaminationPlanView> GetExaminationPlanViewList(ViewModel.ConfiguretView examinationPlanView,
  192. Guid? schoolyearID, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? starWeek, int? endWeek, int? courseEndWeek, int? statusID, List<Guid?> selectIDlist)
  193. {
  194. Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  195. if (schoolyearID.HasValue)
  196. {
  197. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  198. }
  199. if (collegeID.HasValue)
  200. {
  201. exp = exp.And(x => x.CollegeID == collegeID);
  202. }
  203. if (gradeYearID.HasValue)
  204. {
  205. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
  206. .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
  207. }
  208. if (standardID.HasValue)
  209. {
  210. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
  211. .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
  212. }
  213. if (coursematerialID.HasValue)
  214. {
  215. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  216. }
  217. if (examsCategoryID.HasValue)
  218. {
  219. exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
  220. }
  221. if (examinationModeID.HasValue)
  222. {
  223. exp = exp.And(x => x.ExaminationModeID == examinationModeID);
  224. }
  225. if (examinationStyleID.HasValue)
  226. {
  227. exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
  228. }
  229. if (starWeek.HasValue)
  230. {
  231. exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum >= starWeek));
  232. }
  233. if (endWeek.HasValue)
  234. {
  235. exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum <= endWeek));
  236. }
  237. if (statusID.HasValue)
  238. {
  239. exp = exp.And(x => x.RecordStatus == statusID);
  240. }
  241. if (selectIDlist != null && selectIDlist.Count > 0)
  242. {
  243. exp = exp.And(x => selectIDlist.Contains(x.ExaminationPlanID));
  244. }
  245. var q = ExaminationPlanDAL.GetExaminationPlanView(exp);
  246. if (courseEndWeek.HasValue)
  247. {
  248. q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
  249. }
  250. if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
  251. q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
  252. return this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToList();
  253. }
  254. public List<ViewModel.ExaminationManage.ExaminationPlanView> GetAdultExaminationPlanViewList(ViewModel.ConfiguretView examinationPlanView,
  255. Guid? schoolyearID, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? starWeek, int? endWeek, int? courseEndWeek, int? statusID, List<Guid?> selectIDlist)
  256. {
  257. Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  258. if (schoolyearID.HasValue)
  259. {
  260. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  261. }
  262. if (collegeID.HasValue)
  263. {
  264. exp = exp.And(x => x.CollegeID == collegeID);
  265. }
  266. if (gradeYearID.HasValue)
  267. {
  268. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
  269. .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
  270. }
  271. if (standardID.HasValue)
  272. {
  273. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
  274. .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
  275. }
  276. if (coursematerialID.HasValue)
  277. {
  278. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  279. }
  280. if (examsCategoryID.HasValue)
  281. {
  282. exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
  283. }
  284. if (examinationModeID.HasValue)
  285. {
  286. exp = exp.And(x => x.ExaminationModeID == examinationModeID);
  287. }
  288. if (examinationStyleID.HasValue)
  289. {
  290. exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
  291. }
  292. if (starWeek.HasValue)
  293. {
  294. exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum >= starWeek));
  295. }
  296. if (endWeek.HasValue)
  297. {
  298. exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum <= endWeek));
  299. }
  300. if (statusID.HasValue)
  301. {
  302. exp = exp.And(x => x.RecordStatus == statusID);
  303. }
  304. if (selectIDlist != null && selectIDlist.Count > 0)
  305. {
  306. exp = exp.And(x => selectIDlist.Contains(x.ExaminationPlanID));
  307. }
  308. var q = ExaminationPlanDAL.GetExaminationPlanViewForAdult(exp);
  309. if (courseEndWeek.HasValue)
  310. {
  311. q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
  312. }
  313. if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
  314. q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
  315. return this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToList();
  316. }
  317. public List<ViewModel.ExaminationManage.ExaminationPlanView> GetGdssExaminationPlanViewList(ViewModel.ConfiguretView examinationPlanView,
  318. Guid? schoolyearID, Guid? collegeID, Guid? classmajorID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? courseEndWeek, int? statusID, List<Guid?> selectIDlist)
  319. {
  320. Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  321. if (schoolyearID.HasValue)
  322. {
  323. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  324. }
  325. if (collegeID.HasValue)
  326. {
  327. //原先是用教学任务关联的由于补考记录没有对应的教学任务,所以改用专业课程关联,
  328. //学校那边说不会有多个教研室开同一门可的情况,即使有,那这些教研室同样可以查到,也没有问题
  329. exp = exp.And(x => x.EM_Coursematerial.EM_SpecialtyCourse.Any(w => w.CF_Department.CollegeID == collegeID));
  330. }
  331. if (gradeYearID.HasValue)
  332. {
  333. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
  334. .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
  335. }
  336. if (standardID.HasValue)
  337. {
  338. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
  339. .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
  340. }
  341. if (coursematerialID.HasValue)
  342. {
  343. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  344. }
  345. if (examsCategoryID.HasValue)
  346. {
  347. exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
  348. }
  349. if (examinationModeID.HasValue)
  350. {
  351. exp = exp.And(x => x.ExaminationModeID == examinationModeID);
  352. }
  353. if (examinationStyleID.HasValue)
  354. {
  355. exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
  356. }
  357. if(classmajorID.HasValue)
  358. {
  359. var classmajor = ExaminationPlanDAL.ClassmajorRepository.GetList(x => x.ClassmajorID == classmajorID).FirstOrDefault();
  360. exp = exp.And(x => x.ClassName == classmajor.Name);
  361. }
  362. if (statusID.HasValue)
  363. {
  364. exp = exp.And(x => x.RecordStatus == statusID);
  365. }
  366. if (selectIDlist != null && selectIDlist.Count > 0)
  367. {
  368. exp = exp.And(x => selectIDlist.Contains(x.ExaminationPlanID));
  369. }
  370. var q = ExaminationPlanDAL.GetExaminationPlanViewForAdult(exp);
  371. if (courseEndWeek.HasValue)
  372. {
  373. q = q.Where(x => x.CourseEndWeekNum == courseEndWeek);
  374. }
  375. if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
  376. q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
  377. return this.GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExamsCategoryID).ThenBy(x => x.CourseEndWeekNum).ThenBy(x => x.CoursematerialName).ThenBy(x => x.ClassName).ToList();
  378. }
  379. public IGridResultSet<StaffView> GetExaminationTeacherViewInfo(Guid? examinationRoomLayoutID)
  380. {
  381. return ExaminationPlanDAL.GetExaminationTeacherView(x => x.ExaminationRoomLayoutID == examinationRoomLayoutID, (x => true)).ToGridResultSet();
  382. }
  383. public IGridResultSet<ExaminationRoomStudentView> GetExaminationStudentViewInfo(Guid? examinationRoomLayoutID)
  384. {
  385. var roomLayout = ExaminationPlanDAL.ExaminationRoomLayoutRepository.GetSingle(x => x.ExaminationRoomLayoutID == examinationRoomLayoutID);
  386. var q = ExaminationPlanDAL.GetExaminationRoomStudentView(x => x.ExaminationRoomLayoutID == examinationRoomLayoutID);
  387. if (roomLayout.StudentOrderType == (int)CF_StudentOrderType.StudentNo)
  388. {
  389. return q.OrderBy(x => x.LoginID).ToGridResultSet();
  390. }
  391. else
  392. {
  393. return q.ToGridResultSet();
  394. }
  395. }
  396. public ViewModel.ExaminationManage.ExaminationPlanView GetExaminationPlanViewInfo(Guid? examinationPlanID)
  397. {
  398. return ExaminationPlanDAL.GetExaminationPlanView(x => x.ExaminationPlanID == examinationPlanID).FirstOrDefault();
  399. }
  400. public ExaminationRoomLayoutView GetExaminationRoomLayoutViewInfo(Guid? examinationRoomLayoutID)
  401. {
  402. return ExaminationPlanDAL.GetExaminationRoomLayoutView(x => x.ExaminationRoomLayoutID == examinationRoomLayoutID).FirstOrDefault();
  403. }
  404. public virtual void GenerateExaminationPlan(Guid? schoolyearID, Guid? collegeID, int? gradeID, int? standardID)
  405. {
  406. var nowDate = DateTime.Now;
  407. var recordStatusID = (int)CF_ApprovalStatus.NotSubmitted;
  408. var user = CustomPrincipal.Current;
  409. Expression<Func<EM_EducationMission, bool>> exp = x => true;
  410. Expression<Func<EM_EducationMissionClass, bool>> emcExp = x => true;
  411. //x.SchoolyearID == schoolyearID;
  412. if (schoolyearID.HasValue)
  413. {
  414. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  415. }
  416. if (collegeID.HasValue)
  417. {
  418. exp = exp.And(x => x.CollegeID == collegeID);
  419. }
  420. if (gradeID.HasValue && gradeID != -1)
  421. {
  422. emcExp = emcExp.And(x => x.CF_Classmajor.Any(y => y.CF_Grademajor.GradeID == gradeID));
  423. }
  424. if (standardID.HasValue && standardID != -1)
  425. {
  426. emcExp = emcExp.And(x => x.CF_Classmajor.Any(y => y.CF_Grademajor.CF_Facultymajor.StandardID == standardID));
  427. }
  428. var examinationPlanQuery = ExaminationPlanDAL.GetExaminationPlanByEducationMission(exp, emcExp);
  429. List<ExaminationPlanView> examinationPlanViewList = this.GetQueryByDataRangeByCollege(examinationPlanQuery).ToList();
  430. var dbExaminationPlanList = ExaminationPlanDAL.ExaminationPlanRepository.Entities;
  431. int sameCount = 0;
  432. List<EX_ExaminationPlan> listExaminationPlan = new List<EX_ExaminationPlan>();
  433. foreach (var examinationPlan in examinationPlanViewList)
  434. {
  435. if (dbExaminationPlanList.Any(x => x.ClassName.Contains(examinationPlan.ClassName)))
  436. {
  437. sameCount = dbExaminationPlanList.Where(x => x.ClassName.Contains(examinationPlan.ClassName)).Count();
  438. }
  439. EX_ExaminationPlan newexaminationPlan = new EX_ExaminationPlan();
  440. newexaminationPlan.ExaminationPlanID = Guid.NewGuid();
  441. newexaminationPlan.SchoolyearID = examinationPlan.SchoolyearID;
  442. newexaminationPlan.CollegeID = examinationPlan.CollegeID;
  443. newexaminationPlan.CoursematerialID = examinationPlan.CoursematerialID;
  444. newexaminationPlan.ExaminationModeID = examinationPlan.ExaminationModeID;
  445. newexaminationPlan.ExaminationStyleID = examinationPlan.ExaminationStyleID;
  446. newexaminationPlan.ExamsCategoryID = (int)CF_ExamsCategory.FinalExam;
  447. newexaminationPlan.EducationMissionID = examinationPlan.EducationMissionID;
  448. newexaminationPlan.ClassmajorID = examinationPlan.ClassmajorID;
  449. //if (sameCount > 0)
  450. //{
  451. // examinationPlan.ClassName = examinationPlan.ClassName + sameCount.ToString();
  452. //}
  453. newexaminationPlan.ClassName = examinationPlan.ClassName;
  454. newexaminationPlan.ExaminationDate = examinationPlan.ExaminationDate;
  455. newexaminationPlan.StartTime = examinationPlan.StartTime;
  456. newexaminationPlan.EndTime = examinationPlan.EndTime;
  457. newexaminationPlan.CF_Student = new HashSet<CF_Student>(examinationPlan.Students);
  458. SetNewStatus(newexaminationPlan);
  459. newexaminationPlan.RecordStatus = recordStatusID;
  460. listExaminationPlan.Add(newexaminationPlan);
  461. }
  462. //var examinationPlanList = examinationPlanViewList.Select(x => new EX_ExaminationPlan
  463. //{
  464. // ExaminationPlanID = Guid.NewGuid(),
  465. // SchoolyearID = x.SchoolyearID,
  466. // CollegeID = x.CollegeID,
  467. // CoursematerialID = x.CoursematerialID,
  468. // ExaminationModeID = x.ExaminationModeID,
  469. // ExaminationStyleID = x.ExaminationStyleID,
  470. // ExamsCategoryID = (int)CF_ExamsCategory.FinalExam,
  471. // EducationMissionID = x.EducationMissionID,
  472. // ClassmajorID = x.ClassmajorID,
  473. // ClassName = x.ClassName,
  474. // ExaminationDate = x.ExaminationDate,
  475. // StartTime = x.StartTime,
  476. // EndTime = x.EndTime,
  477. // CF_Student = new HashSet<CF_Student>(x.Students),
  478. // RecordStatus = recordStatusID,
  479. // CreateUserID = user.UserID,
  480. // CreateTime = nowDate,
  481. // ModifyUserID = user.UserID,
  482. // ModifyTime = nowDate
  483. //}).ToList();
  484. this.UnitOfWork.BulkInsert(listExaminationPlan);
  485. this.UnitOfWork.BulkInsert(listExaminationPlan, (x => x.CF_Student));
  486. }
  487. public void GenerateResitPlan(Guid schoolyearID)
  488. {
  489. try
  490. {
  491. var statusList = this.GetStatusViewList();
  492. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  493. var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  494. List<EX_ExaminationPlan> listExaminationPlan = new List<EX_ExaminationPlan>();
  495. var dbExaminationPlanList = ExaminationPlanDAL.ExaminationPlanRepository.Entities;
  496. var resitExaminationPlanList = this.GetQueryByDataRangeByCollege(ExaminationPlanDAL.GetExaminationPlanByResitStudent(schoolyearID, curSchoolyear.SchoolYearID)).ToList();
  497. var resitExaminationPlanByFinalExaminationList = this.GetQueryByDataRangeByCollege(ExaminationPlanDAL.GetExaminationPlanByResitExamination(curSchoolyear.SchoolYearID)).ToList();
  498. resitExaminationPlanList = resitExaminationPlanList.Concat(resitExaminationPlanByFinalExaminationList).ToList();
  499. int sameCount = 0;
  500. foreach (var resitExaminationPlan in resitExaminationPlanList)
  501. {
  502. if (dbExaminationPlanList.Any(x => x.ClassName.Contains(resitExaminationPlan.ClassName)))
  503. {
  504. sameCount = dbExaminationPlanList.Where(x => x.ClassName.Contains(resitExaminationPlan.ClassName)).Count();
  505. }
  506. EX_ExaminationPlan examinationPlan = new EX_ExaminationPlan();
  507. examinationPlan.ExaminationPlanID = Guid.NewGuid();
  508. examinationPlan.SchoolyearID = resitExaminationPlan.SchoolyearID;
  509. examinationPlan.CollegeID = resitExaminationPlan.CollegeID;
  510. examinationPlan.CoursematerialID = resitExaminationPlan.CoursematerialID;
  511. examinationPlan.ExaminationModeID = resitExaminationPlan.ExaminationModeID;
  512. examinationPlan.ExaminationStyleID = resitExaminationPlan.ExaminationStyleID;
  513. examinationPlan.ExamsCategoryID = (int)CF_ExamsCategory.Resit;
  514. //if (sameCount > 0)
  515. //{
  516. // resitExaminationPlan.ClassName = resitExaminationPlan.ClassName + sameCount.ToString();
  517. //}
  518. examinationPlan.ClassName = resitExaminationPlan.ClassName;
  519. examinationPlan.CF_Student = new HashSet<CF_Student>(resitExaminationPlan.Students);
  520. SetNewStatus(examinationPlan);
  521. examinationPlan.RecordStatus = (int)CF_ApprovalStatus.NotSubmitted;
  522. listExaminationPlan.Add(examinationPlan);
  523. }
  524. UnitOfWork.BulkInsert(listExaminationPlan);
  525. this.UnitOfWork.BulkInsert(listExaminationPlan, (x => x.CF_Student));
  526. }
  527. catch (Exception)
  528. {
  529. throw;
  530. }
  531. }
  532. public void GenerateGraduateExamPlan(int year, Guid? collegeID, int? standardID, decimal? learnSystem)
  533. {
  534. try
  535. {
  536. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  537. var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  538. List<EX_ExaminationPlan> listExaminationPlan = new List<EX_ExaminationPlan>();
  539. var dbgraduateExamPlanList = ExaminationPlanDAL.ExaminationPlanRepository.Entities;
  540. var graduateExamPlanList = this.GetQueryByDataRangeByCollege(ExaminationPlanDAL.GetExaminationPlanByGraduateExamStudent(year,collegeID,standardID,learnSystem, curSchoolyear.SchoolYearID)).ToList();
  541. var graduateExamPlanByFinalExaminationList = this.GetQueryByDataRangeByCollege(ExaminationPlanDAL.GetExaminationPlanByGraduateExamination(curSchoolyear.SchoolYearID)).ToList();
  542. graduateExamPlanList = graduateExamPlanList.Concat(graduateExamPlanByFinalExaminationList).ToList();
  543. int sameCount = 0;
  544. foreach (var graduateExamPlan in graduateExamPlanList)
  545. {
  546. if (dbgraduateExamPlanList.Any(x => x.ClassName.Contains(graduateExamPlan.ClassName)))
  547. {
  548. sameCount = dbgraduateExamPlanList.Where(x => x.ClassName.Contains(graduateExamPlan.ClassName)).Count();
  549. }
  550. EX_ExaminationPlan examinationPlan = new EX_ExaminationPlan();
  551. examinationPlan.ExaminationPlanID = Guid.NewGuid();
  552. examinationPlan.SchoolyearID = graduateExamPlan.SchoolyearID;
  553. examinationPlan.CollegeID = graduateExamPlan.CollegeID;
  554. examinationPlan.CoursematerialID = graduateExamPlan.CoursematerialID;
  555. examinationPlan.ExaminationModeID = graduateExamPlan.ExaminationModeID;
  556. examinationPlan.ExaminationStyleID = graduateExamPlan.ExaminationStyleID;
  557. examinationPlan.ExamsCategoryID = (int)CF_ExamsCategory.GraduationExam;
  558. //if (sameCount > 0)
  559. //{
  560. // graduateExamPlan.ClassName = graduateExamPlan.ClassName + sameCount.ToString();
  561. //}
  562. examinationPlan.ClassName = graduateExamPlan.ClassName;
  563. examinationPlan.CF_Student = new HashSet<CF_Student>(graduateExamPlan.Students);
  564. SetNewStatus(examinationPlan);
  565. examinationPlan.RecordStatus = (int)CF_ApprovalStatus.NotSubmitted;
  566. listExaminationPlan.Add(examinationPlan);
  567. }
  568. UnitOfWork.BulkInsert(listExaminationPlan);
  569. this.UnitOfWork.BulkInsert(listExaminationPlan, (x => x.CF_Student));
  570. }
  571. catch (Exception)
  572. {
  573. throw;
  574. }
  575. }
  576. public void Save(ExaminationPlanView examinationPlanView)
  577. {
  578. var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  579. var examinationPlanScheduleView = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlanID)
  580. .Include(x => x.CF_Student)
  581. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  582. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  583. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  584. .ToList()
  585. .Select(x => new ExamiationPlanAutoScheduleView
  586. {
  587. ExaminationPlan = x,
  588. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  589. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  590. }).FirstOrDefault();
  591. var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanScheduleView.ExaminationPlan.ExaminationDate
  592. && x.StartTime <= examinationPlanScheduleView.ExaminationPlan.EndTime && x.EndTime >= examinationPlanScheduleView.ExaminationPlan.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
  593. && x.ExaminationPlanID != examinationPlanScheduleView.ExaminationPlan.ExaminationPlanID)
  594. .Include(x => x.CF_Student)
  595. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  596. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  597. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  598. .ToList()
  599. .Select(x => new ExamiationPlanAutoScheduleView
  600. {
  601. ExaminationPlan = x,
  602. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  603. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  604. }).ToList();
  605. var timeSegment = new TimeSegmentView { ExaminationDate = examinationPlanView.ExaminationDate.Value, StartTime = examinationPlanView.StartTime.Value, EndTime = examinationPlanView.EndTime.Value };
  606. var errorList = new List<string>();
  607. foreach (var classroomLayout in examinationPlanScheduleView.ExaminationPlan.EX_ExaminationRoomLayout)
  608. {
  609. var studentIDList = classroomLayout.EX_ExaminationRoomStudent.Select(x => x.UserID.Value).ToList();
  610. if (IsConflictForSetTime(examinationPlanScheduleView, studentIDList, timeSegment, classroomLayout.CF_Classroom, scheduledPlanViewList))
  611. {
  612. errorList.Add("考场" + classroomLayout.CF_Classroom.Name + "时间安排存在冲突,请重新核对后再进行设置。");
  613. }
  614. }
  615. if (errorList.Count > 0)
  616. {
  617. throw new Exception(string.Join(",", errorList));
  618. }
  619. if (examinationPlanScheduleView != null)
  620. {
  621. examinationPlanScheduleView.ExaminationPlan.ExaminationDate = examinationPlanView.ExaminationDate;
  622. examinationPlanScheduleView.ExaminationPlan.StartTime = examinationPlanView.StartTime;
  623. examinationPlanScheduleView.ExaminationPlan.EndTime = examinationPlanView.EndTime;
  624. this.SetModifyStatus(examinationPlanScheduleView.ExaminationPlan);
  625. }
  626. else
  627. {
  628. throw new Exception("指定的考试计划不存在。");
  629. }
  630. UnitOfWork.Commit();
  631. }
  632. public virtual void Submit(IList<Guid?> examinationPlanIDList)
  633. {
  634. var examinationPlanList = ExaminationPlanDAL.ExaminationPlanRepository
  635. .GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID),
  636. (x => x.EX_ExaminationRoomLayout)).ToList();
  637. var examinationPlanLayoutList = ExaminationPlanDAL.ExaminationRoomLayoutRepository
  638. .GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID),
  639. (x => x.CF_Staff),
  640. (x => x.EX_ExaminationRoomStudent),
  641. (x => x.CF_Classroom));
  642. var submitedPlan = examinationPlanList.Where(x => x.RecordStatus != (int)CF_ApprovalStatus.NotSubmitted).ToList();
  643. if (submitedPlan.Count > 0)
  644. {
  645. string submitedClassNames = string.Join(",", submitedPlan.Select(x => x.ClassName)) + "并不在未提交状态,请选择正确的记录进行提交。";
  646. throw new Exception(submitedClassNames);
  647. }
  648. var noLayoutPlanList = (from ep in examinationPlanList
  649. join epl in examinationPlanLayoutList on ep.ExaminationPlanID equals epl.ExaminationPlanID into depl
  650. from eepl in depl.DefaultIfEmpty()
  651. where eepl == null
  652. select ep).ToList();
  653. if (noLayoutPlanList.Count > 0)
  654. {
  655. string noLayoutPlanClassNames = string.Join(",", noLayoutPlanList.Select(x => x.ClassName)) + "没有设置对应的考场,请先设置再进行提交。";
  656. throw new Exception(noLayoutPlanClassNames);
  657. }
  658. var noTeacherPlanList = (from ep in examinationPlanList
  659. join epl in examinationPlanLayoutList on ep.ExaminationPlanID equals epl.ExaminationPlanID
  660. from s in epl.CF_Staff.DefaultIfEmpty()
  661. where s == null
  662. select new { Plan = ep, Classroom = epl.CF_Classroom }).ToList();
  663. if (noTeacherPlanList.Count > 0)
  664. {
  665. string noTeacherPlanClassNames = string.Join(";", noTeacherPlanList.Select(x => x.Plan.ClassName + ",考场" + x.Classroom.Name)) + "没有设置监考老师,请先设置再进行提交。";
  666. throw new Exception(noTeacherPlanClassNames);
  667. }
  668. var noStudentPlanList = (from ep in examinationPlanList
  669. join epl in examinationPlanLayoutList on ep.ExaminationPlanID equals epl.ExaminationPlanID
  670. from s in epl.EX_ExaminationRoomStudent.DefaultIfEmpty()
  671. where s == null
  672. select new { Plan = ep, Classroom = epl.CF_Classroom }).ToList();
  673. if (noStudentPlanList.Count > 0)
  674. {
  675. string noStudentPlanClassNames = string.Join(";", noStudentPlanList.Select(x => x.Plan.ClassName + ",考场" + x.Classroom.Name)) + "没有设置学生,请先设置再进行提交。";
  676. throw new Exception(noStudentPlanClassNames);
  677. }
  678. if (examinationPlanIDList.Count > 0)
  679. {
  680. UnitOfWork.Update<EX_ExaminationPlan>((x => new EX_ExaminationPlan { RecordStatus = (int)CF_ApprovalStatus.Submitted }), (x => examinationPlanIDList.Contains(x.ExaminationPlanID)));
  681. }
  682. }
  683. public void UnSubmit(IList<Guid?> examinationPlanIDList)
  684. {
  685. var examinationPlanList = ExaminationPlanDAL.ExaminationPlanRepository
  686. .GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID),
  687. (x => x.EX_ExaminationRoomLayout)).ToList();
  688. var submitedPlan = examinationPlanList.Where(x => x.RecordStatus != (int)CF_ApprovalStatus.Submitted).ToList();
  689. if (submitedPlan.Count > 0)
  690. {
  691. string submitedClassNames = string.Join(",", submitedPlan.Select(x => x.ClassName)) + "并不在已提交状态,请选择正确的记录进行撤回。";
  692. throw new Exception(submitedClassNames);
  693. }
  694. if (examinationPlanIDList.Count > 0)
  695. {
  696. UnitOfWork.Update<EX_ExaminationPlan>((x => new EX_ExaminationPlan { RecordStatus = (int)CF_ApprovalStatus.NotSubmitted }), (x => examinationPlanIDList.Contains(x.ExaminationPlanID)));
  697. }
  698. }
  699. public IGridResultSet<ExaminationRoomLayoutView> GetExaminationRoomLayoutViewList(Guid examinationPlanID)
  700. {
  701. return this.ExaminationPlanDAL.GetExaminationRoomLayoutView(x => x.ExaminationPlanID == examinationPlanID).ToGridResultSet();
  702. }
  703. protected List<EX_ExaminationRoomStudent> SetRoomStudentSeats(IList<ExaminationRoomStudentView> studentList, ClassroomView classroom,
  704. int rowSpacing, int columnSpacing, CF_StudentOrderType? orderType = null)
  705. {
  706. var result = new List<EX_ExaminationRoomStudent>();
  707. if (classroom == null) throw new Exception("指定的教室资源不存在。");
  708. int currentIndex = 0;
  709. var firstRowSeatCount = Math.Ceiling((double)classroom.ColumnCount / (double)(columnSpacing + 1));
  710. var rowCount = Math.Ceiling((double)classroom.RowCout / (double)(rowSpacing + 1));
  711. switch (orderType)
  712. {
  713. case CF_StudentOrderType.StudentNo:
  714. studentList = studentList.OrderBy(x => x.LoginID).ToList();
  715. break;
  716. case CF_StudentOrderType.Random:
  717. studentList = studentList.OrderBy(x => Guid.NewGuid()).ToList();
  718. break;
  719. }
  720. for (int i = 0; i < rowCount; i++)
  721. {
  722. for (int j = 0; j < firstRowSeatCount; j++)
  723. {
  724. if (currentIndex >= studentList.Count)
  725. {
  726. break;
  727. }
  728. var roomStudent = new EX_ExaminationRoomStudent();
  729. roomStudent.ExaminationRoomStudentID = Guid.NewGuid();
  730. roomStudent.ExaminationRoomLayoutID = studentList[currentIndex].ExaminationRoomLayoutID;
  731. roomStudent.UserID = studentList[currentIndex].UserID;
  732. roomStudent.Row = i * (rowSpacing + 1) + 1;
  733. roomStudent.Column = j * (columnSpacing + 1) + 1;
  734. roomStudent.Remark = studentList[currentIndex].Remark;
  735. result.Add(roomStudent);
  736. currentIndex++;
  737. }
  738. }
  739. return result;
  740. }
  741. public void SaveClassroomLayout(ViewModel.ExaminationManage.ExaminationRoomLayoutView examinationRoomLayoutView, IList<Guid?> staffIDList, IList<ExaminationRoomStudentView> studentList)
  742. {
  743. var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  744. var examinationRoomLayoutEntity = ExaminationPlanDAL.ExaminationRoomLayoutRepository
  745. .GetSingle(x => x.ExaminationRoomLayoutID == examinationRoomLayoutView.ExaminationRoomLayoutID,
  746. (x => x.CF_Staff),
  747. (x => x.EX_ExaminationRoomStudent));
  748. var examinationPlanView = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationPlanID == examinationRoomLayoutView.ExaminationPlanID)
  749. .Include(x => x.CF_Student)
  750. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  751. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  752. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  753. .ToList()
  754. .Select(x => new ExamiationPlanAutoScheduleView
  755. {
  756. ExaminationPlan = x,
  757. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  758. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  759. }).FirstOrDefault();
  760. if (examinationPlanView == null)
  761. {
  762. throw new Exception("找不到对应的考试计划。");
  763. }
  764. if (examinationRoomLayoutEntity == null && examinationPlanView.ExaminationPlan.EX_ExaminationRoomLayout.Any(x => x.ClassroomID == examinationRoomLayoutView.ClassroomID))
  765. {
  766. throw new Exception("该考试计划已经设置该教室为考场!");
  767. }
  768. var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanView.ExaminationPlan.ExaminationDate
  769. && x.StartTime <= examinationPlanView.ExaminationPlan.EndTime && x.EndTime >= examinationPlanView.ExaminationPlan.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
  770. && x.ExaminationPlanID != examinationPlanView.ExaminationPlan.ExaminationPlanID)
  771. .Include(x => x.CF_Student)
  772. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  773. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  774. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  775. .ToList()
  776. .Select(x => new ExamiationPlanAutoScheduleView
  777. {
  778. ExaminationPlan = x,
  779. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  780. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  781. }).ToList();
  782. var timeSegment = new TimeSegmentView { ExaminationDate = examinationPlanView.ExaminationPlan.ExaminationDate.Value, StartTime = examinationPlanView.ExaminationPlan.StartTime.Value, EndTime = examinationPlanView.ExaminationPlan.EndTime.Value };
  783. var classroomEntity = ExaminationPlanDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == examinationRoomLayoutView.ClassroomID, (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)));
  784. if (IsConflictForSetTime(examinationPlanView, studentList.Select(x => x.UserID.Value).ToList(), timeSegment, classroomEntity, scheduledPlanViewList))
  785. {
  786. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,请重新核对后再进行设置。");
  787. }
  788. if (examinationRoomLayoutEntity != null)
  789. {
  790. examinationRoomLayoutEntity.ExaminationPlanID = examinationRoomLayoutView.ExaminationPlanID;
  791. examinationRoomLayoutEntity.ClassroomID = examinationRoomLayoutView.ClassroomID;
  792. examinationRoomLayoutEntity.RowSpacing = examinationRoomLayoutView.RowSpacing;
  793. examinationRoomLayoutEntity.ColumnSpacing = examinationRoomLayoutView.ColumnSpacing;
  794. examinationRoomLayoutEntity.StudentOrderType = examinationRoomLayoutView.StudentOrderType;
  795. this.SetModifyStatus(examinationRoomLayoutEntity);
  796. }
  797. else
  798. {
  799. examinationRoomLayoutEntity = new EX_ExaminationRoomLayout();
  800. examinationRoomLayoutEntity.ExaminationRoomLayoutID = Guid.NewGuid();
  801. examinationRoomLayoutEntity.ExaminationPlanID = examinationRoomLayoutView.ExaminationPlanID;
  802. examinationRoomLayoutEntity.ClassroomID = examinationRoomLayoutView.ClassroomID;
  803. examinationRoomLayoutEntity.RowSpacing = examinationRoomLayoutView.RowSpacing;
  804. examinationRoomLayoutEntity.ColumnSpacing = examinationRoomLayoutView.ColumnSpacing;
  805. examinationRoomLayoutEntity.StudentOrderType = examinationRoomLayoutView.StudentOrderType;
  806. this.SetModifyStatus(examinationRoomLayoutEntity);
  807. this.UnitOfWork.Add(examinationRoomLayoutEntity);
  808. }
  809. var staffList = this.StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
  810. examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>();
  811. examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>(staffList);
  812. UnitOfWork.Remove<EX_ExaminationRoomStudent>(x => x.ExaminationRoomLayoutID == examinationRoomLayoutEntity.ExaminationRoomLayoutID);
  813. var classroomID = (examinationRoomLayoutEntity.ClassroomID ?? Guid.Empty);
  814. var classroom = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomID).FirstOrDefault();
  815. var roomStudentList = this.SetRoomStudentSeats(studentList, classroom,
  816. examinationRoomLayoutEntity.RowSpacing ?? 0, examinationRoomLayoutEntity.ColumnSpacing ?? 0);
  817. roomStudentList.ForEach(x =>
  818. {
  819. x.ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID;
  820. this.SetNewStatus(x);
  821. this.UnitOfWork.Add(x);
  822. });
  823. UnitOfWork.Commit();
  824. }
  825. /// <summary>
  826. /// 新增保存
  827. /// </summary>
  828. /// <param name="examinationRoomLayoutView"></param>
  829. /// <param name="staffIDList"></param>
  830. /// <param name="studentList"></param>
  831. public void SaveAddClassroomLayout(ExaminationRoomLayoutView examinationRoomLayoutView, IList<Guid?> staffIDList, IList<ExaminationRoomStudentView> studentList)
  832. {
  833. var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  834. var examinationRoomLayoutEntity = ExaminationPlanDAL.ExaminationRoomLayoutRepository
  835. .GetSingle(x => x.ExaminationRoomLayoutID == examinationRoomLayoutView.ExaminationRoomLayoutID,
  836. (x => x.CF_Staff),
  837. (x => x.EX_ExaminationRoomStudent));
  838. var examinationPlanView = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationPlanID == examinationRoomLayoutView.ExaminationPlanID)
  839. .Include(x => x.CF_Student)
  840. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  841. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  842. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  843. .ToList()
  844. .Select(x => new ExamiationPlanAutoScheduleView
  845. {
  846. ExaminationPlan = x,
  847. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  848. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  849. }).FirstOrDefault();
  850. if (examinationPlanView == null)
  851. {
  852. throw new Exception("找不到对应的考试计划。");
  853. }
  854. var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanView.ExaminationPlan.ExaminationDate
  855. && x.StartTime <= examinationPlanView.ExaminationPlan.EndTime && x.EndTime >= examinationPlanView.ExaminationPlan.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
  856. && x.ExaminationPlanID != examinationPlanView.ExaminationPlan.ExaminationPlanID)
  857. .Include(x => x.CF_Student)
  858. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  859. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  860. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  861. .ToList()
  862. .Select(x => new ExamiationPlanAutoScheduleView
  863. {
  864. ExaminationPlan = x,
  865. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  866. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  867. }).ToList();
  868. var timeSegment = new TimeSegmentView { ExaminationDate = examinationPlanView.ExaminationPlan.ExaminationDate.Value, StartTime = examinationPlanView.ExaminationPlan.StartTime.Value, EndTime = examinationPlanView.ExaminationPlan.EndTime.Value };
  869. var classroomEntity = ExaminationPlanDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == examinationRoomLayoutView.ClassroomID, (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)));
  870. if (IsConflictForSetTime(examinationPlanView, studentList.Select(x => x.UserID.Value).ToList(), timeSegment, classroomEntity, scheduledPlanViewList))
  871. {
  872. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,请重新核对后再进行设置。");
  873. }
  874. if (examinationRoomLayoutEntity != null)
  875. {
  876. examinationRoomLayoutEntity.ExaminationPlanID = examinationRoomLayoutView.ExaminationPlanID;
  877. examinationRoomLayoutEntity.ClassroomID = examinationRoomLayoutView.ClassroomID;
  878. examinationRoomLayoutEntity.RowSpacing = examinationRoomLayoutView.RowSpacing;
  879. examinationRoomLayoutEntity.ColumnSpacing = examinationRoomLayoutView.ColumnSpacing;
  880. examinationRoomLayoutEntity.StudentOrderType = examinationRoomLayoutView.StudentOrderType;
  881. this.SetModifyStatus(examinationRoomLayoutEntity);
  882. }
  883. else
  884. {
  885. examinationRoomLayoutEntity = new EX_ExaminationRoomLayout();
  886. examinationRoomLayoutEntity.ExaminationRoomLayoutID = Guid.NewGuid();
  887. examinationRoomLayoutEntity.ExaminationPlanID = examinationRoomLayoutView.ExaminationPlanID;
  888. examinationRoomLayoutEntity.ClassroomID = examinationRoomLayoutView.ClassroomID;
  889. examinationRoomLayoutEntity.RowSpacing = examinationRoomLayoutView.RowSpacing;
  890. examinationRoomLayoutEntity.ColumnSpacing = examinationRoomLayoutView.ColumnSpacing;
  891. examinationRoomLayoutEntity.StudentOrderType = examinationRoomLayoutView.StudentOrderType;
  892. this.SetModifyStatus(examinationRoomLayoutEntity);
  893. this.UnitOfWork.Add(examinationRoomLayoutEntity);
  894. }
  895. var staffList = this.StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
  896. examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>();
  897. examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>(staffList);
  898. UnitOfWork.Remove<EX_ExaminationRoomStudent>(x => x.ExaminationRoomLayoutID == examinationRoomLayoutEntity.ExaminationRoomLayoutID);
  899. var classroomID = (examinationRoomLayoutEntity.ClassroomID ?? Guid.Empty);
  900. var classroom = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomID).FirstOrDefault();
  901. var roomStudentList = this.SetRoomStudentSeats(studentList, classroom,
  902. examinationRoomLayoutEntity.RowSpacing ?? 0, examinationRoomLayoutEntity.ColumnSpacing ?? 0);
  903. roomStudentList.ForEach(x =>
  904. {
  905. x.ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID;
  906. this.SetNewStatus(x);
  907. this.UnitOfWork.Add(x);
  908. });
  909. UnitOfWork.Commit();
  910. }
  911. public Bowin.Common.Linq.Entity.IGridResultSet<StudentsView> GetAvailableStudentViewList(Guid examinationPlanID,
  912. Guid? collegeID, Guid? grademajorID, Guid? classmajorID, CF_StudentOrderType studentOrderType, int? pageIndex, int? pageSize)
  913. {
  914. var inschool = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x=>x.InSchoolStatusID).ToList();
  915. Expression<Func<CF_Student, bool>> studentExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && inschool.Contains(x.InSchoolStatusID));
  916. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  917. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  918. IQueryable<StudentsView> query;
  919. if (collegeID.HasValue || grademajorID.HasValue || classmajorID.HasValue)
  920. {
  921. if (collegeID.HasValue)
  922. {
  923. gradeExp = gradeExp.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  924. }
  925. if (grademajorID.HasValue)
  926. {
  927. classExp = classExp.And(x => x.GrademajorID == grademajorID);
  928. }
  929. if (classmajorID.HasValue)
  930. {
  931. studentExp = studentExp.And(x => x.ClassmajorID == classmajorID);
  932. }
  933. query = StudentsDAL.GetStudentQueryable(studentExp, classExp, gradeExp);
  934. }
  935. else
  936. {
  937. query = ExaminationPlanDAL.GetAvailableStudentView(x => x.ExaminationPlanID == examinationPlanID, studentExp);
  938. }
  939. if (studentOrderType == CF_StudentOrderType.Random)
  940. {
  941. query = query.OrderByNewId();
  942. }
  943. else if (studentOrderType == CF_StudentOrderType.StudentNo)
  944. {
  945. query = query.OrderBy(x => x.LoginID);
  946. }
  947. return query.ToGridResultSet(pageIndex, pageSize);
  948. }
  949. public IGridResultSet<StudentsView> GetAddAvailableStudentViewList(Guid? collegeID, Guid? grademajorID, Guid? classmajorID, CF_StudentOrderType studentOrderType, int? pageIndex, int? pageSize)
  950. {
  951. var inschool = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  952. Expression<Func<CF_Student, bool>> studentExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && inschool.Contains(x.InSchoolStatusID));
  953. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  954. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  955. IQueryable<StudentsView> query;
  956. if (collegeID.HasValue || grademajorID.HasValue || classmajorID.HasValue)
  957. {
  958. if (collegeID.HasValue)
  959. {
  960. gradeExp = gradeExp.And(x => x.CF_Facultymajor.CollegeID == collegeID);
  961. }
  962. if (grademajorID.HasValue)
  963. {
  964. classExp = classExp.And(x => x.GrademajorID == grademajorID);
  965. }
  966. if (classmajorID.HasValue)
  967. {
  968. studentExp = studentExp.And(x => x.ClassmajorID == classmajorID);
  969. }
  970. query = StudentsDAL.GetStudentQueryable(studentExp, classExp, gradeExp);
  971. }
  972. else
  973. {
  974. query = ExaminationPlanDAL.GetAvailableStudentView(x => true, studentExp);
  975. }
  976. if (studentOrderType == CF_StudentOrderType.Random)
  977. {
  978. query = query.OrderByNewId();
  979. }
  980. else if (studentOrderType == CF_StudentOrderType.StudentNo)
  981. {
  982. query = query.OrderBy(x => x.LoginID);
  983. }
  984. return query.ToGridResultSet(pageIndex, pageSize);
  985. }
  986. public void DeleteExaminationClassroomLayout(IList<Guid> examinationRoomLayoutIDs)
  987. {
  988. var examinationLayoutList = this.ExaminationPlanDAL.ExaminationRoomLayoutRepository
  989. .GetList(x => examinationRoomLayoutIDs.Contains(x.ExaminationRoomLayoutID),
  990. (x => x.EX_ExaminationRoomStudent), (x => x.CF_Staff)).ToList();
  991. foreach (var examinationLayout in examinationLayoutList)
  992. {
  993. examinationLayout.CF_Staff = new HashSet<CF_Staff>();
  994. examinationLayout.EX_ExaminationRoomStudent.ToList().ForEach(x => this.UnitOfWork.Remove(x));
  995. this.UnitOfWork.Remove(examinationLayout);
  996. }
  997. this.UnitOfWork.Commit();
  998. }
  999. public void Delete(IList<Guid> examinationPlanIDs)
  1000. {
  1001. try
  1002. {
  1003. var nullableIDs = examinationPlanIDs.Select(x => (Guid?)x).ToList();
  1004. List<EX_ExaminationPlan> ExaminationPlanList = examinationPlanRepository
  1005. .GetList(x => examinationPlanIDs.Contains(x.ExaminationPlanID),
  1006. (x => x.CF_Student), (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))).ToList();
  1007. if (ExaminationPlanList.Any(x => x.RecordStatus != (int)CF_ApprovalStatus.NotSubmitted))
  1008. {
  1009. throw new Exception("要删除的信息只能是未提交的信息。");
  1010. }
  1011. var layoutList = ExaminationPlanList.SelectMany(x => x.EX_ExaminationRoomLayout).ToList();
  1012. var layoutIDList = layoutList.Select(x => (Guid?)x.ExaminationRoomLayoutID).ToList();
  1013. using (var scope = new TransactionScope())
  1014. {
  1015. UnitOfWork.Delete(ExaminationPlanList, (x => x.CF_Student));
  1016. UnitOfWork.Delete(layoutList, (x => x.CF_Staff));
  1017. UnitOfWork.Delete<EX_ExaminationRoomStudent>(x => layoutIDList.Contains(x.ExaminationRoomLayoutID));
  1018. UnitOfWork.Delete<EX_ExaminationRoomLayout>(x => layoutIDList.Contains(x.ExaminationRoomLayoutID));
  1019. UnitOfWork.Delete<EX_ExaminationPlan>(x => examinationPlanIDs.Contains(x.ExaminationPlanID));
  1020. scope.Complete();
  1021. }
  1022. }
  1023. catch (Exception ex)
  1024. {
  1025. throw ex;
  1026. }
  1027. }
  1028. public virtual void AutoGenerateExaminationRoomLayout(IList<Guid?> examinationPlanIDList)
  1029. {
  1030. DateTime today = DateTime.Today;
  1031. var userCollegeIDList = this.GetQueryByDataRangeByCollege(CollegeDAL.GetCollegeViewQueryable()).Select(x => x.CollegeID).ToList();
  1032. var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  1033. var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  1034. //获取可排时间
  1035. var examinationDateList = this.TimeSegmentDAL.GetTimeSegmentView(x => x.ExaminationDate > today)
  1036. .OrderByDescending(x => x.IsForResit).ThenBy(x => x.ExaminationDate).ThenBy(x => x.StartTime).ToList();
  1037. //获取当前学年学期的考试计划(由于要检测冲突,所以不能只拿没排完的,也不要限制数据范围)
  1038. var examinationPlanList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.SchoolyearID == curSchoolyear.SchoolYearID
  1039. //&& (x.ExamsCategoryID == (int)CF_ExamsCategory.Resit || x.ExamsCategoryID == (int)CF_ExamsCategory.GraduationExam)
  1040. )
  1041. .Include(x => x.EM_Coursematerial)
  1042. .Include(x => x.CF_Student.Select(w => w.Sys_User))
  1043. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  1044. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  1045. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  1046. .ToList()
  1047. .Select(x => new ExamiationPlanAutoScheduleView {
  1048. ExaminationPlan = x,
  1049. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  1050. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  1051. }).ToList();
  1052. //获取没排完的考试计划
  1053. var notCompleteExaminationPlanList = examinationPlanList.Where(x => x.StudentCount < x.MissionStudentCount
  1054. && userCollegeIDList.Contains(x.ExaminationPlan.CollegeID.Value)
  1055. && x.ExaminationPlan.RecordStatus == (int)EX_ExaminationPlanStatus.NotSubmitted
  1056. && (examinationPlanIDList.Count == 0 || examinationPlanIDList.Contains(x.ExaminationPlan.ExaminationPlanID))).ToList();
  1057. if (examinationPlanIDList.Where(x => !notCompleteExaminationPlanList
  1058. .Select(w => (Guid?)w.ExaminationPlan.ExaminationPlanID).Contains(x)).Count() > 0)
  1059. {
  1060. throw new Exception("当前选中的考试计划不包含当前学年学期需要排考的计划,请检查选择。");
  1061. }
  1062. //获取已经指定时间的未排考试计划(三部分组成:
  1063. //1、已经指定了时间的未排计划;
  1064. //2、未指定时间但有其他同科目的未排计划已经指定了时间;
  1065. //3、未指定时间但有其他同科目的已派计划已经指定了时间)
  1066. var notCompleteExaminationPlanWithDateList = notCompleteExaminationPlanList.Where(x => x.ExaminationPlan.ExaminationDate.HasValue
  1067. && x.ExaminationPlan.StartTime.HasValue && x.ExaminationPlan.EndTime.HasValue).ToList();
  1068. notCompleteExaminationPlanWithDateList = notCompleteExaminationPlanWithDateList.Concat(
  1069. notCompleteExaminationPlanList.Where(x =>
  1070. !notCompleteExaminationPlanWithDateList.Select(w => w.ExaminationPlan.ExaminationPlanID).Contains(x.ExaminationPlan.ExaminationPlanID)
  1071. && notCompleteExaminationPlanWithDateList.Select(w => w.ExaminationPlan.CoursematerialID).Contains(x.ExaminationPlan.CoursematerialID)
  1072. )
  1073. ).Concat(
  1074. from notComplete in notCompleteExaminationPlanList
  1075. join complete in examinationPlanList.Where(x => x.ExaminationPlan.ExaminationDate.HasValue)
  1076. on notComplete.ExaminationPlan.CoursematerialID equals complete.ExaminationPlan.CoursematerialID
  1077. group notComplete by notComplete.ExaminationPlan.ExaminationPlanID into g
  1078. select g.FirstOrDefault()
  1079. ).ToList();
  1080. //获取排课
  1081. var scheduleDateTimeList = examinationDateList.Select(x => new StartEndTimeView { StartTime = x.ExaminationDate.Add(x.StartTime), EndTime = x.ExaminationDate.Add(x.EndTime) })
  1082. .Concat(notCompleteExaminationPlanWithDateList
  1083. .Where(x => x.ExaminationPlan.ExaminationDate.HasValue && x.ExaminationPlan.StartTime.HasValue && x.ExaminationPlan.EndTime.HasValue)
  1084. .GroupBy(x => new
  1085. {
  1086. StartTime = x.ExaminationPlan.ExaminationDate.Value.Add(x.ExaminationPlan.StartTime.Value),
  1087. EndTime = x.ExaminationPlan.ExaminationDate.Value.Add(x.ExaminationPlan.EndTime.Value)
  1088. }).Select(x => new StartEndTimeView
  1089. {
  1090. StartTime = x.Key.StartTime,
  1091. EndTime = x.Key.EndTime
  1092. }))
  1093. .ToList();
  1094. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
  1095. scheduleDateTimeList);
  1096. var excessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
  1097. curSchoolyear.SchoolYearID.Value,
  1098. scheduleDateTimeList);
  1099. var conflictStudentPlanWithDateList = (from plan in notCompleteExaminationPlanWithDateList
  1100. from student in plan.ExaminationPlan.CF_Student
  1101. from scheduling in schedulingList.Where(x => x.Date == plan.ExaminationPlan.ExaminationDate
  1102. && x.StartTime <= plan.ExaminationPlan.EndTime && x.EndTime >= plan.ExaminationPlan.StartTime)
  1103. from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student.UserID)
  1104. group plan by plan.ExaminationPlan.ExaminationPlanID into g
  1105. select g.FirstOrDefault()
  1106. ).ToList();
  1107. if (conflictStudentPlanWithDateList.Count > 0)
  1108. {
  1109. throw new Exception(string.Format("考试计划{0}由于指定了具体的考试时间,而学生需要上课无法安排,未免影响整体的考试安排,排考中止。",
  1110. string.Join("、", conflictStudentPlanWithDateList.Select(x => x.ExaminationPlan.ClassName))));
  1111. }
  1112. //获取未指定时间的未排考试计划
  1113. var notCompleteExaminationPlanWithOutDateList = notCompleteExaminationPlanList
  1114. .Where(x =>
  1115. !notCompleteExaminationPlanWithDateList.Select(w => w.ExaminationPlan.CoursematerialID).Contains(x.ExaminationPlan.CoursematerialID)
  1116. ).ToList();
  1117. //获取已排完的考试计划
  1118. var scheduledStudentList = (from plan in examinationPlanList.Where(x => x.StudentCount > 0)
  1119. from layout in plan.ExaminationPlan.EX_ExaminationRoomLayout
  1120. from student in layout.EX_ExaminationRoomStudent
  1121. select new StudentClassroomView
  1122. {
  1123. ExaminationDate = plan.ExaminationPlan.ExaminationDate,
  1124. StartTime = plan.ExaminationPlan.StartTime,
  1125. EndTime = plan.ExaminationPlan.EndTime,
  1126. ClassroomID = layout.ClassroomID,
  1127. UserID = student.UserID,
  1128. TeacherIDList = layout.CF_Staff.Select(x => x.UserID).ToList(),
  1129. ExaminationStyleID = plan.ExaminationPlan.ExaminationStyleID,
  1130. ExaminationPlanID = plan.ExaminationPlan.ExaminationPlanID
  1131. }).ToList();
  1132. //获取足够的考室信息
  1133. var examinationRoomList = this.RoomSettingDAL.ExaminationRoomSettingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE,
  1134. (x => x.CF_Classroom.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)),
  1135. (x => x.CF_Classroom.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)),
  1136. (x => x.CF_Classroom.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent))).ToList();
  1137. var classroomIDList = examinationRoomList.Select(x => x.ClassroomID).ToList();
  1138. var classroomViewList = this.ClassroomDAL.GetClassroomViewQueryable(x => classroomIDList.Contains(x.ClassroomID)).ToList();
  1139. //获取足够的监考员信息
  1140. var examinationTeacherList = this.ExaminationTeacherDAL.ExaminationTeacherRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE,
  1141. (x => x.CF_Staff))
  1142. .ToList();
  1143. var existsExaminationDateList = notCompleteExaminationPlanWithDateList.Where(x => x.ExaminationPlan.ExaminationDate.HasValue)
  1144. .Concat(
  1145. from notComplete in notCompleteExaminationPlanWithDateList
  1146. join complete in examinationPlanList.Where(x => x.ExaminationPlan.ExaminationDate.HasValue)
  1147. on notComplete.ExaminationPlan.CoursematerialID equals complete.ExaminationPlan.CoursematerialID
  1148. group complete by new { complete.ExaminationPlan.ExaminationDate, complete.ExaminationPlan.StartTime, complete.ExaminationPlan.EndTime } into g
  1149. select g.FirstOrDefault()
  1150. )
  1151. .GroupBy(x => new { x.ExaminationPlan.ExaminationDate, x.ExaminationPlan.StartTime, x.ExaminationPlan.EndTime })
  1152. .Select(x => new TimeSegmentView
  1153. {
  1154. ExaminationDate = x.Key.ExaminationDate.Value,
  1155. StartTime = x.Key.StartTime.Value,
  1156. EndTime = x.Key.EndTime.Value
  1157. }).OrderBy(x => x.ExaminationDate)
  1158. .ThenBy(x => x.StartTime).ToList();
  1159. //先排指定了日期的考试计划
  1160. foreach (var examinationDate in existsExaminationDateList)
  1161. {
  1162. //先取出指定当前日期的考试计划和它们同科目的考试计划,在这个循环里面,必须排完这些内容,
  1163. //如果排不完,直接抛出异常,结束整个排考
  1164. var notCompleteExaminationPlanCorrectTypeWithDateList = notCompleteExaminationPlanWithDateList
  1165. .Where(x => ((!examinationDate.IsForResit)
  1166. ? x.ExaminationPlan.ExamsCategoryID == (int)CF_ExamsCategory.FinalExam
  1167. : x.ExaminationPlan.ExamsCategoryID != (int)CF_ExamsCategory.FinalExam)).ToList();
  1168. var fixedDateExaminationPlanList = notCompleteExaminationPlanCorrectTypeWithDateList
  1169. .Where(x => x.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
  1170. && x.ExaminationPlan.StartTime == examinationDate.StartTime && x.ExaminationPlan.EndTime == examinationDate.EndTime).ToList();
  1171. fixedDateExaminationPlanList = fixedDateExaminationPlanList.Concat(
  1172. notCompleteExaminationPlanCorrectTypeWithDateList.Where(x => fixedDateExaminationPlanList.Select(w => w.ExaminationPlan.CoursematerialID).Contains(x.ExaminationPlan.CoursematerialID)
  1173. && (!x.ExaminationPlan.ExaminationDate.HasValue || !x.ExaminationPlan.StartTime.HasValue || !x.ExaminationPlan.EndTime.HasValue))
  1174. ).Concat(
  1175. from notComplete in notCompleteExaminationPlanCorrectTypeWithDateList
  1176. join complete in examinationPlanList.Where(x => x.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
  1177. && x.ExaminationPlan.StartTime == examinationDate.StartTime && x.ExaminationPlan.EndTime == examinationDate.EndTime)
  1178. on notComplete.ExaminationPlan.CoursematerialID equals complete.ExaminationPlan.CoursematerialID
  1179. group notComplete by notComplete.ExaminationPlan.ExaminationPlanID into g
  1180. select g.FirstOrDefault()
  1181. ).ToList();
  1182. //按照剩余座位数从多到少排序,拿出可排的教室备用,排考时,目的是为了
  1183. //(由于检查的是剩余座位数,这里已经解决了冲突的问题,没有剩余座位的考室不会被列出)
  1184. var orderedExaminationRoomList = this.GetMaxSeatExaminationRoomList(examinationRoomList,
  1185. examinationDate.ExaminationDate, examinationDate.StartTime, examinationDate.EndTime, scheduledStudentList);
  1186. var result = this.AutoSchedule(fixedDateExaminationPlanList, orderedExaminationRoomList, classroomViewList, examinationDate,
  1187. examinationTeacherList, scheduledStudentList, schedulingList, excessiveUseList);
  1188. //如果排不完,直接抛出异常,结束整个排考
  1189. if (!result)
  1190. {
  1191. throw new Exception("自动排考失败:" + examinationDate.ExaminationDateString
  1192. + "(" + examinationDate.StartTimeString + "-" + examinationDate.EndTimeString + ")无法排完所有指定日期的考试计划以及其相同科目的考试计划,"
  1193. + "排考过程中断,为了不影响后面的考试安排,请先调整好这些考试计划再进行排考。");
  1194. }
  1195. }
  1196. //再排未指定日期的考试计划,这些计划需要一个个课程地排,每个课程必须排在同一时间点,否则失败。
  1197. var courseList = notCompleteExaminationPlanWithOutDateList.GroupBy(x => new { x.ExaminationPlan.CoursematerialID, IsResit = x.ExaminationPlan.ExamsCategoryID != (int)CF_ExamsCategory.FinalExam })
  1198. .Select(x => new { Course = x.FirstOrDefault().ExaminationPlan.EM_Coursematerial, x.Key.IsResit }).ToList();
  1199. foreach (var course in courseList)
  1200. {
  1201. var courseExaminationPlanList = notCompleteExaminationPlanWithOutDateList
  1202. .Where(x => x.ExaminationPlan.CoursematerialID == course.Course.CoursematerialID
  1203. && (course.IsResit ? (x.ExaminationPlan.ExamsCategoryID != (int)CF_ExamsCategory.FinalExam) : (x.ExaminationPlan.ExamsCategoryID == (int)CF_ExamsCategory.FinalExam)))
  1204. .ToList();
  1205. var courseExaminationDateList = examinationDateList.Where(x => x.IsForResit == course.IsResit)
  1206. .OrderBy(x => x.ExaminationDate).ThenBy(x => x.StartTime);
  1207. foreach (var examinationDate in courseExaminationDateList)
  1208. {
  1209. //先检查当时的学生冲突,有冲突的话需要移到下一个时段
  1210. var conflictStudentPlanEnum = (from plan in courseExaminationPlanList
  1211. from student in plan.ExaminationPlan.CF_Student
  1212. from scheduling in schedulingList.Where(x => x.Date == plan.ExaminationPlan.ExaminationDate
  1213. && x.StartTime <= plan.ExaminationPlan.EndTime && x.EndTime >= plan.ExaminationPlan.StartTime)
  1214. from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student.UserID)
  1215. select plan);
  1216. if (conflictStudentPlanEnum.Any())
  1217. {
  1218. continue;
  1219. }
  1220. //按照剩余座位数从多到少排序,拿出可排的教室备用,排考时也先排人数多的考试计划,
  1221. //目的是为了将同一场考试尽量安排在一个考场中
  1222. //(由于检查的是剩余座位数,这里已经解决了冲突的问题,没有剩余座位的考室不会被列出)
  1223. var orderedExaminationRoomList = this.GetMaxSeatExaminationRoomList(examinationRoomList,
  1224. examinationDate.ExaminationDate, examinationDate.StartTime, examinationDate.EndTime, scheduledStudentList);
  1225. var result = this.AutoSchedule(courseExaminationPlanList, orderedExaminationRoomList, classroomViewList, examinationDate,
  1226. examinationTeacherList, scheduledStudentList, schedulingList, excessiveUseList);
  1227. //如果失败,需要从scheduledStudentList撤销这次排的记录,选另一个时间点重新排
  1228. if (!result)
  1229. {
  1230. //如果考试计划没指定日期,那初始状态下应该没有排到任何考场,可以清空排考信息再来过
  1231. scheduledStudentList.RemoveAll(x => courseExaminationPlanList.Select(w => w.ExaminationPlan.ExaminationPlanID).Contains(x.ExaminationPlanID));
  1232. courseExaminationPlanList.ForEach(x => x.StudentCount = 0);
  1233. continue;
  1234. }
  1235. else
  1236. {
  1237. break;
  1238. }
  1239. }
  1240. }
  1241. //(需要增加逻辑显示具体排不进去的提示)
  1242. var notSuccessList = notCompleteExaminationPlanWithOutDateList.Where(x => x.MissionStudentCount > x.StudentCount).ToList();
  1243. var successCount = notCompleteExaminationPlanList.Count - notSuccessList.Count;
  1244. this.UnitOfWork.Commit();
  1245. if (successCount == 0)
  1246. {
  1247. throw new Exception("自动排课失败:" + string.Join("、", notSuccessList.Select(x => x.ExaminationPlan.ClassName)) + "由于时间冲突无法排入。");
  1248. }
  1249. else if (notSuccessList.Count > 0)
  1250. {
  1251. throw new Exception("成功排课" + successCount.ToString() + "条记录,失败" + notSuccessList.Count.ToString() + "条记录,其中"
  1252. + string.Join("、", notSuccessList.Select(x => x.ExaminationPlan.ClassName)) + "由于时间冲突无法排入。");
  1253. }
  1254. }
  1255. //一般情况下传输进来的未排考试必须是同一科目的考试
  1256. protected virtual bool AutoSchedule(List<ExamiationPlanAutoScheduleView> notCompleteExaminationPlanList,
  1257. List<EX_ExaminationRoomSetting> examinationRoomList, List<ClassroomView> classroomViewList, TimeSegmentView examinationDate,
  1258. List<EX_ExaminationTeacher> examinationTeacherList, List<StudentClassroomView> scheduledStudentList,
  1259. List<EducationSchedulingWeekNumView> schedulingList, List<ClassroomExcessiveUseWeekNumView> excessiveUseList)
  1260. {
  1261. var needScheduleCount = notCompleteExaminationPlanList.Count;
  1262. var scheduledCount = 0;
  1263. var needModifyRecordList = new List<AutoScheduleModifyView>();
  1264. foreach (var examinationRoom in examinationRoomList)
  1265. {
  1266. //如果考场在当前时间有排课,跳过
  1267. var schedule = schedulingList.FirstOrDefault(x => x.ClassroomID == examinationRoom.ClassroomID
  1268. && x.Date == examinationDate.ExaminationDate && x.StartTime <= examinationDate.EndTime
  1269. && x.EndTime >= examinationDate.StartTime);
  1270. if (schedule != null)
  1271. {
  1272. continue;
  1273. }
  1274. var excessiveUse = excessiveUseList.FirstOrDefault(x => x.ClassroomID == examinationRoom.ClassroomID
  1275. && x.Date == examinationDate.ExaminationDate && x.StartTime <= examinationDate.EndTime
  1276. && x.EndTime >= examinationDate.StartTime);
  1277. if (excessiveUse != null)
  1278. {
  1279. continue;
  1280. }
  1281. //按照排考人数从多到少排序,第一行拿出未排过的考试计划,然后从第二个计划开始,优先拿出排过考的考试计划,
  1282. //这样做的目的是保证考试计划能排到最少的考场去,不至于学生太过分散
  1283. var orderedExaminationPlanViewList = notCompleteExaminationPlanList
  1284. .Where(x => (x.MissionStudentCount - x.StudentCount) > 0)
  1285. .OrderBy(x => x.MissionStudentCount - x.StudentCount).Take(1).ToList();
  1286. orderedExaminationPlanViewList = orderedExaminationPlanViewList
  1287. .Concat(notCompleteExaminationPlanList.Where(x =>
  1288. !orderedExaminationPlanViewList.Select(w => w.ExaminationPlan.ExaminationPlanID)
  1289. .Contains(x.ExaminationPlan.ExaminationPlanID)
  1290. && (x.MissionStudentCount - x.StudentCount) > 0)
  1291. .OrderBy(x => x.StudentCount > 0 ? 0 : 1)
  1292. .ThenByDescending(x => x.MissionStudentCount - x.StudentCount)).ToList();
  1293. #region 获取目前有空的监考员,并随机抽出两个
  1294. //先找出排课没有冲突的监考员
  1295. var noScheduleTeacherList = (from allteacher in examinationTeacherList
  1296. from scheduling in schedulingList.Where(x => x.TeacherList.Any(w => w.UserID == allteacher.UserID)
  1297. && x.Date == examinationDate.ExaminationDate && x.StartTime <= examinationDate.EndTime
  1298. && x.EndTime >= examinationDate.StartTime).DefaultIfEmpty()
  1299. where scheduling == null
  1300. select allteacher).ToList();
  1301. var teacherList = this.GetAvailableExaminationTeacher(noScheduleTeacherList,
  1302. examinationDate.ExaminationDate, examinationDate.StartTime, examinationDate.EndTime, scheduledStudentList);
  1303. if (teacherList.Count < 2)
  1304. {
  1305. return false;
  1306. }
  1307. #endregion
  1308. //这个循环需要把考室尽量塞满……
  1309. foreach (var orderedExaminationPlanView in orderedExaminationPlanViewList)
  1310. {
  1311. //获取要排考的学生
  1312. var needScheduleStudentList = this.GetNeedScheduleStudentList(orderedExaminationPlanView, scheduledStudentList);
  1313. //首先判断是否指定了考试时间,但并不是当前时间,这些自动排考无法处理
  1314. if (orderedExaminationPlanView.ExaminationPlan.ExaminationDate.HasValue
  1315. && !(orderedExaminationPlanView.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
  1316. && orderedExaminationPlanView.ExaminationPlan.StartTime == examinationDate.StartTime
  1317. && orderedExaminationPlanView.ExaminationPlan.EndTime == examinationDate.EndTime))
  1318. {
  1319. continue;
  1320. }
  1321. //然后判断冲突
  1322. if (IsConflict(orderedExaminationPlanView, needScheduleStudentList.Select(x => x.UserID).ToList(), examinationDate, examinationRoom.CF_Classroom, scheduledStudentList))
  1323. {
  1324. continue;
  1325. }
  1326. var roomRemainSeat = examinationRoom.CF_Classroom.Examinationseating - scheduledStudentList
  1327. .Where(x => x.ExaminationDate == examinationDate.ExaminationDate
  1328. && x.ClassroomID == examinationRoom.ClassroomID
  1329. && x.StartTime <= examinationDate.EndTime
  1330. && x.EndTime >= examinationDate.StartTime).Count();
  1331. var actualScheduleStudentList = needScheduleStudentList.Take(roomRemainSeat ?? 0).ToList();
  1332. //记录住这些数据需要修改,后面所有考场和考试任务都检查完后,再统一修改
  1333. var result = new AutoScheduleModifyView
  1334. {
  1335. ExaminationPlan = orderedExaminationPlanView.ExaminationPlan,
  1336. ExaminationDate = examinationDate.ExaminationDate,
  1337. StartTime = examinationDate.StartTime,
  1338. EndTime = examinationDate.EndTime,
  1339. ExaminationRoom = examinationRoom,
  1340. ScheduleStudentList = actualScheduleStudentList
  1341. };
  1342. var lastExaminationRoomLayout = scheduledStudentList.Where(x => x.ClassroomID == examinationRoom.ClassroomID).FirstOrDefault();
  1343. if (lastExaminationRoomLayout != null)
  1344. {
  1345. result.CF_Staff = new HashSet<CF_Staff>(
  1346. examinationTeacherList.Where(x => lastExaminationRoomLayout.TeacherIDList.Contains(x.UserID ?? Guid.NewGuid())).Select(x => x.CF_Staff)
  1347. );
  1348. }
  1349. else
  1350. {
  1351. result.CF_Staff = new HashSet<CF_Staff>(teacherList);
  1352. }
  1353. needModifyRecordList.Add(result);
  1354. //更新已排完的计划,这样后续的判断才会没问题
  1355. scheduledStudentList.AddRange(actualScheduleStudentList.Select(x => new StudentClassroomView
  1356. {
  1357. UserID = x.UserID,
  1358. ExaminationDate = examinationDate.ExaminationDate,
  1359. StartTime = examinationDate.StartTime,
  1360. EndTime = examinationDate.EndTime,
  1361. ClassroomID = examinationRoom.ClassroomID,
  1362. ExaminationStyleID = orderedExaminationPlanView.ExaminationPlan.ExaminationStyleID,
  1363. TeacherIDList = result.CF_Staff.Select(w => w.UserID).ToList(),
  1364. ExaminationPlanID = orderedExaminationPlanView.ExaminationPlan.ExaminationPlanID
  1365. }));
  1366. orderedExaminationPlanView.StudentCount += actualScheduleStudentList.Count();
  1367. if (actualScheduleStudentList.Count == needScheduleStudentList.Count)
  1368. {
  1369. scheduledCount++;
  1370. }
  1371. //如果教室塞满了,那后面的考试计划也排不动了,需要结束循环并跳转到下一个教室,以防浪费资源
  1372. if (actualScheduleStudentList.Count >= roomRemainSeat)
  1373. {
  1374. break;
  1375. }
  1376. }
  1377. }
  1378. //如果排不完,返回失败,让外部决定如何处理
  1379. if (scheduledCount < needScheduleCount)
  1380. {
  1381. return false;
  1382. }
  1383. foreach (var needModifyRecord in needModifyRecordList)
  1384. {
  1385. #region 判断成功,开始更新数据
  1386. needModifyRecord.ExaminationPlan.ExaminationDate = examinationDate.ExaminationDate;
  1387. needModifyRecord.ExaminationPlan.StartTime = examinationDate.StartTime;
  1388. needModifyRecord.ExaminationPlan.EndTime = examinationDate.EndTime;
  1389. var examinationRoomLayout = new EX_ExaminationRoomLayout
  1390. {
  1391. ExaminationRoomLayoutID = Guid.NewGuid(),
  1392. ExaminationPlanID = needModifyRecord.ExaminationPlan.ExaminationPlanID,
  1393. EX_ExaminationPlan = needModifyRecord.ExaminationPlan,
  1394. ClassroomID = needModifyRecord.ExaminationRoom.ClassroomID,
  1395. RowSpacing = 0,
  1396. ColumnSpacing = 0,
  1397. StudentOrderType = (int)CF_StudentOrderType.StudentNo,
  1398. CF_Staff = needModifyRecord.CF_Staff
  1399. };
  1400. this.SetNewStatus(examinationRoomLayout);
  1401. //这块需要挪到上面检测的地方,在上面如何判断这个考场能容纳多少学生?
  1402. var examinationRoomStudentViewList = needModifyRecord.ScheduleStudentList.Select(x => new ExaminationRoomStudentView
  1403. {
  1404. ExaminationRoomStudentID = Guid.NewGuid(),
  1405. ExaminationRoomLayoutID = examinationRoomLayout.ExaminationRoomLayoutID,
  1406. UserID = x.UserID,
  1407. LoginID = x.Sys_User.LoginID,
  1408. Remark = ""
  1409. }).ToList();
  1410. var classroomView = classroomViewList.FirstOrDefault(x => x.ClassroomID == needModifyRecord.ExaminationRoom.ClassroomID);
  1411. var examinationRoomStudentList = this.SetRoomStudentSeats(examinationRoomStudentViewList, classroomView, 0, 0, CF_StudentOrderType.StudentNo);
  1412. examinationRoomLayout.EX_ExaminationRoomStudent = new HashSet<EX_ExaminationRoomStudent>(examinationRoomStudentList);
  1413. needModifyRecord.ExaminationPlan.EX_ExaminationRoomLayout.Add(examinationRoomLayout);
  1414. needModifyRecord.ExaminationRoom.CF_Classroom.EX_ExaminationRoomLayout.Add(examinationRoomLayout);
  1415. #endregion
  1416. }
  1417. return true;
  1418. }
  1419. protected List<CF_Student> GetNeedScheduleStudentList(ExamiationPlanAutoScheduleView examinationPlanView
  1420. , List<StudentClassroomView> scheduledStudentList)
  1421. {
  1422. //这里只找出在当前考试计划里面排过的学生,这个功能是找需排的学生,如果是其他考试计划排过的话,算冲突
  1423. var needScheduleStudentList = (from student in examinationPlanView.ExaminationPlan.CF_Student
  1424. join roomStudent in scheduledStudentList.Where(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlan.ExaminationPlanID)
  1425. on student.UserID equals roomStudent.UserID into dRoomStudent
  1426. from eRoomStudent in dRoomStudent.DefaultIfEmpty()
  1427. where eRoomStudent == null
  1428. select student).ToList();
  1429. return needScheduleStudentList;
  1430. }
  1431. //判断考试方式是否有冲突
  1432. private bool IsExaminationStyleConflict(ExamiationPlanAutoScheduleView examinationPlanView, CF_Classroom examinationRoom,
  1433. TimeSegmentView examinationDate)
  1434. {
  1435. if (examinationRoom.EX_ExaminationRoomLayout
  1436. .Any(x => x.EX_ExaminationPlan.ExaminationStyleID != examinationPlanView.ExaminationPlan.ExaminationStyleID
  1437. && x.EX_ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
  1438. && x.EX_ExaminationPlan.StartTime <= examinationDate.EndTime
  1439. && x.EX_ExaminationPlan.EndTime >= examinationDate.StartTime))
  1440. {
  1441. return true;
  1442. }
  1443. return false;
  1444. }
  1445. private bool IsExaminationStyleConflictForAuto(ExamiationPlanAutoScheduleView examinationPlanView, CF_Classroom examinationRoom,
  1446. TimeSegmentView examinationDate, IList<StudentClassroomView> scheduledStudentList)
  1447. {
  1448. if (scheduledStudentList
  1449. .Any(x => x.ExaminationStyleID != examinationPlanView.ExaminationPlan.ExaminationStyleID
  1450. && x.ClassroomID == examinationRoom.ClassroomID
  1451. && x.ExaminationDate == examinationDate.ExaminationDate
  1452. && x.StartTime <= examinationDate.EndTime
  1453. && x.EndTime >= examinationDate.StartTime))
  1454. {
  1455. return true;
  1456. }
  1457. return false;
  1458. }
  1459. //判断考生时间有没有冲突
  1460. private bool IsStudentConflict(IList<Guid> needScheduleStudentIDList,
  1461. IList<ExamiationPlanAutoScheduleView> scheduledPlanList, TimeSegmentView examinationDate)
  1462. {
  1463. var conflictStudentList = (from student in needScheduleStudentIDList
  1464. join scheduled in
  1465. (
  1466. from scheduled in scheduledPlanList.Where(x => x.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
  1467. && x.ExaminationPlan.StartTime <= examinationDate.EndTime
  1468. && x.ExaminationPlan.EndTime >= examinationDate.StartTime)
  1469. from layout in scheduled.ExaminationPlan.EX_ExaminationRoomLayout
  1470. from student in layout.EX_ExaminationRoomStudent
  1471. select student.UserID
  1472. ) on student equals scheduled
  1473. select student).ToList();
  1474. if (conflictStudentList.Count > 0)
  1475. {
  1476. return true;
  1477. }
  1478. return false;
  1479. }
  1480. //判断考生时间有没有冲突
  1481. private bool IsStudentConflictForAuto(IList<Guid> needScheduleStudentIDList,
  1482. IList<StudentClassroomView> scheduledStudentList, TimeSegmentView examinationDate)
  1483. {
  1484. var conflictStudentList = (from student in needScheduleStudentIDList
  1485. join scheduled in scheduledStudentList.Where(x => x.ExaminationDate == examinationDate.ExaminationDate
  1486. && x.StartTime <= examinationDate.EndTime
  1487. && x.EndTime >= examinationDate.StartTime) on student equals scheduled.UserID
  1488. select student).ToList();
  1489. if (conflictStudentList.Count > 0)
  1490. {
  1491. return true;
  1492. }
  1493. return false;
  1494. }
  1495. private bool IsClassroomConflictForAuto(CF_Classroom examinationRoom,
  1496. TimeSegmentView examinationDate, IList<StudentClassroomView> scheduledStudentList)
  1497. {
  1498. var conflictRoomList = (from schedule in scheduledStudentList
  1499. where schedule.ClassroomID == examinationRoom.ClassroomID
  1500. && schedule.ExaminationDate == examinationDate.ExaminationDate
  1501. && schedule.StartTime <= examinationDate.EndTime
  1502. && schedule.EndTime >= examinationDate.StartTime
  1503. select schedule).ToList();
  1504. if (conflictRoomList.Count >= examinationRoom.Examinationseating)
  1505. {
  1506. return true;
  1507. }
  1508. return false;
  1509. }
  1510. protected bool IsConflict(ExamiationPlanAutoScheduleView examinationPlanView, IList<Guid> needScheduleStudentIDList,
  1511. TimeSegmentView examinationDate, CF_Classroom examinationRoom, IList<StudentClassroomView> scheduledStudentList)
  1512. {
  1513. if (IsExaminationStyleConflictForAuto(examinationPlanView, examinationRoom, examinationDate, scheduledStudentList))
  1514. {
  1515. return true;
  1516. }
  1517. if (IsClassroomConflictForAuto(examinationRoom, examinationDate, scheduledStudentList))
  1518. {
  1519. return true;
  1520. }
  1521. if (IsStudentConflictForAuto(needScheduleStudentIDList, scheduledStudentList, examinationDate))
  1522. {
  1523. return true;
  1524. }
  1525. return false;
  1526. }
  1527. private bool IsClassroomConflict(ExamiationPlanAutoScheduleView examinationPlanView, TimeSegmentView examinationDate,
  1528. IList<ExamiationPlanAutoScheduleView> scheduledPlanList)
  1529. {
  1530. var conflictRoomList = (from room in examinationPlanView.ExaminationPlan.EX_ExaminationRoomLayout
  1531. join layout in scheduledPlanList.Where(x => x.ExaminationPlan.ExaminationDate == examinationDate.ExaminationDate
  1532. && x.ExaminationPlan.StartTime <= examinationDate.EndTime && x.ExaminationPlan.EndTime >= examinationDate.StartTime
  1533. && x.ExaminationPlan.ExaminationPlanID != examinationPlanView.ExaminationPlan.ExaminationPlanID)
  1534. .SelectMany(x => x.ExaminationPlan.EX_ExaminationRoomLayout) on room.ClassroomID equals layout.ClassroomID
  1535. group new { ExaminationRoom = room, Layout = layout } by new { room.ClassroomID, room.CF_Classroom.Examinationseating } into g
  1536. where (g.Key.Examinationseating ?? 0) < (g.Sum(x => (x.Layout == null) ? 0 : x.Layout.EX_ExaminationRoomStudent.Count())
  1537. + g.Sum(x => x.ExaminationRoom.EX_ExaminationRoomStudent.Count()))
  1538. select g.Select(x => x.ExaminationRoom).FirstOrDefault()).ToList();
  1539. if (conflictRoomList.Count > 0)
  1540. {
  1541. return true;
  1542. }
  1543. return false;
  1544. }
  1545. private bool IsConflictForSetTime(ExamiationPlanAutoScheduleView examinationPlanView, IList<Guid> needScheduleStudentIDList,
  1546. TimeSegmentView examinationDate, CF_Classroom examinationRoom, IList<ExamiationPlanAutoScheduleView> scheduledPlanList)
  1547. {
  1548. if (IsExaminationStyleConflict(examinationPlanView, examinationRoom, examinationDate))
  1549. {
  1550. return true;
  1551. }
  1552. if (IsClassroomConflict(examinationPlanView, examinationDate, scheduledPlanList))
  1553. {
  1554. return true;
  1555. }
  1556. if (IsStudentConflict(needScheduleStudentIDList, scheduledPlanList, examinationDate))
  1557. {
  1558. return true;
  1559. }
  1560. return false;
  1561. }
  1562. protected List<CF_Staff> GetAvailableExaminationTeacher(IList<EX_ExaminationTeacher> examinationTeacherList,
  1563. DateTime examinationDate, TimeSpan startTime, TimeSpan endTime, IList<StudentClassroomView> scheduledStudentList)
  1564. {
  1565. var q = (from teacher in examinationTeacherList
  1566. from plan in scheduledStudentList.Where(x => x.ExaminationDate == examinationDate
  1567. && x.StartTime <= endTime && x.EndTime >= startTime
  1568. && x.TeacherIDList.Contains(teacher.CF_Staff.UserID))
  1569. .DefaultIfEmpty()
  1570. where plan == null
  1571. select teacher.CF_Staff).OrderBy(x => Guid.NewGuid()).ToList();
  1572. return q.Take(2).ToList();
  1573. }
  1574. protected virtual List<EX_ExaminationRoomSetting> GetMaxSeatExaminationRoomList(IList<EX_ExaminationRoomSetting> examinationRoomList,
  1575. DateTime examinationDate, TimeSpan startTime, TimeSpan endTime, IList<StudentClassroomView> scheduledStudentList)
  1576. {
  1577. var examinationRoom = (from room in examinationRoomList
  1578. join layout in scheduledStudentList.Where(x => x.ExaminationDate == examinationDate
  1579. && x.StartTime <= endTime && x.EndTime >= startTime)
  1580. .GroupBy(x => x.ClassroomID) on room.ClassroomID equals layout.Key into dlayout
  1581. from elayout in dlayout.DefaultIfEmpty()
  1582. where (room.CF_Classroom.Examinationseating ?? 0) > (elayout == null ? 0 : elayout.Count())
  1583. orderby ((room.CF_Classroom.Examinationseating ?? 0) - (elayout == null ? 0 : elayout.Count())) descending
  1584. select room);
  1585. return examinationRoom.ToList();
  1586. }
  1587. private List<ExamiationPlanAutoScheduleView> GetOrderedExaminationPlanViewList(IList<ExamiationPlanAutoScheduleView> source, IList<ExamiationPlanAutoScheduleView> scheduledPlanList,
  1588. DateTime examinationDate)
  1589. {
  1590. //优先级顺序:有学生当天排过考的优先(OrderID)、需要排课的学生数大的优先(NeedScheduleCount)、同一课程优先级相同(CoursematerialID)
  1591. var q = (from plan in source
  1592. where plan.MissionStudentCount > plan.StudentCount
  1593. select new {
  1594. ExaminationPlan = plan,
  1595. OrderID = (scheduledPlanList.Any(x => x.ExaminationPlan.ExaminationDate == examinationDate
  1596. && x.ExaminationPlan.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent).Select(w => w.UserID)
  1597. .Intersect(plan.ExaminationPlan.CF_Student.Select(w => (Guid?)w.UserID)).Count() > 0)
  1598. ||
  1599. source.Any(x => x.ExaminationPlan.ExaminationDate == examinationDate
  1600. && x.ExaminationPlan.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent).Select(w => w.UserID)
  1601. .Intersect(plan.ExaminationPlan.CF_Student.Select(w => (Guid?)w.UserID)).Count() > 0)
  1602. ) ? 0 : 1,
  1603. NeedScheduleCount = plan.MissionStudentCount - plan.StudentCount
  1604. }).OrderBy(x => x.ExaminationPlan.ExaminationPlan.CoursematerialID).ThenBy(x => x.OrderID).ThenByDescending(x => x.NeedScheduleCount)
  1605. .Select(x => x.ExaminationPlan).ToList();
  1606. return q;
  1607. }
  1608. public void SetTime(IList<Guid?> examinationPlanIDList, DateTime? examinationDate, TimeSpan? startTime, TimeSpan? endTime)
  1609. {
  1610. if (!examinationDate.HasValue)
  1611. {
  1612. throw new Exception("必须指定考试日期。");
  1613. }
  1614. if (!startTime.HasValue)
  1615. {
  1616. throw new Exception("必须指定开始时间。");
  1617. }
  1618. if (!endTime.HasValue)
  1619. {
  1620. throw new Exception("必须指定结束时间。");
  1621. }
  1622. if (examinationDate.Value.Date < DateTime.Today)
  1623. {
  1624. throw new Exception("考试日期需在当天之后。");
  1625. }
  1626. if (startTime.Value >= endTime.Value)
  1627. {
  1628. throw new Exception("结束时间需在开始时间之后。");
  1629. }
  1630. var errorMessageList = new List<string>();
  1631. var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  1632. if (examinationDate.HasValue && startTime.HasValue && endTime.HasValue)
  1633. {
  1634. var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  1635. var examinationPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => examinationPlanIDList.Contains(x.ExaminationPlanID))
  1636. .Include(x => x.CF_Student)
  1637. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  1638. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  1639. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  1640. .ToList()
  1641. .Select(x => new ExamiationPlanAutoScheduleView {
  1642. ExaminationPlan = x,
  1643. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  1644. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  1645. }).ToList();
  1646. var submitedPlanClassNameList = examinationPlanViewList.Where(x => x.ExaminationPlan.RecordStatus != (int)EX_ExaminationPlanStatus.NotSubmitted).ToList();
  1647. if (submitedPlanClassNameList.Count > 0)
  1648. {
  1649. throw new Exception(string.Join("、", submitedPlanClassNameList.Select(x => x.ExaminationPlan.ClassName)) + "已经提交,不能设置时间。");
  1650. }
  1651. var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationDate
  1652. && x.StartTime <= endTime && x.EndTime >= startTime && x.EX_ExaminationRoomLayout.Count() > 0
  1653. && !examinationPlanIDList.Contains(x.ExaminationPlanID))
  1654. .Include(x => x.CF_Student)
  1655. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff))
  1656. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  1657. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  1658. .ToList()
  1659. .Select(x => new ExamiationPlanAutoScheduleView
  1660. {
  1661. ExaminationPlan = x,
  1662. MissionStudentCount = (x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) != null) ? x.CF_Student.Count(w => inschoolStatusList.Contains(w.InSchoolStatusID)) : 0,
  1663. StudentCount = (x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) != null) ? x.EX_ExaminationRoomLayout.Sum(w => w.EX_ExaminationRoomStudent.Count()) : 0
  1664. }).ToList();
  1665. var timeSegment = new TimeSegmentView { ExaminationDate = examinationDate.Value, StartTime = startTime.Value, EndTime = endTime.Value };
  1666. var classroomIDList = examinationPlanViewList.SelectMany(x => x.ExaminationPlan.EX_ExaminationRoomLayout).Select(x => x.ClassroomID).ToList();
  1667. var classroomList = ClassroomDAL.ClassroomRepository.GetList(x => classroomIDList.Contains(x.ClassroomID)).ToList();
  1668. //获取排课
  1669. var scheduleDateTimeList = new List<StartEndTimeView> {
  1670. new StartEndTimeView { StartTime = examinationDate.Value.Add(startTime.Value),
  1671. EndTime = examinationDate.Value.Add(endTime.Value) } };
  1672. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
  1673. scheduleDateTimeList);
  1674. var classroomExcessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
  1675. curSchoolyear.SchoolYearID.Value,
  1676. scheduleDateTimeList);
  1677. foreach (var examinationPlanView in examinationPlanViewList)
  1678. {
  1679. foreach (var layout in examinationPlanView.ExaminationPlan.EX_ExaminationRoomLayout)
  1680. {
  1681. var studentIDList = layout.EX_ExaminationRoomStudent
  1682. .Select(x => x.UserID).ToList();
  1683. var classroomEntity = classroomList.FirstOrDefault(x => x.ClassroomID == layout.ClassroomID);
  1684. var staffIDList = layout.CF_Staff.Select(x => x.UserID).ToList();
  1685. var existPlanViewList = scheduledPlanViewList
  1686. .Concat(examinationPlanViewList
  1687. .Where(x => x.ExaminationPlan.ExaminationPlanID != examinationPlanView.ExaminationPlan.ExaminationPlanID))
  1688. .ToList();
  1689. if (existPlanViewList.Any(x => x.ExaminationPlan.ExaminationStyleID != examinationPlanView.ExaminationPlan.ExaminationStyleID
  1690. && x.ExaminationPlan.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == layout.ClassroomID)))
  1691. {
  1692. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1693. + "的考场" + classroomEntity.Name + "时间安排存在冲突,存在同一时间不同考试方式的排考,请重新核对后再进行设置。");
  1694. }
  1695. if ((classroomEntity.Examinationseating - existPlanViewList.Sum(x =>
  1696. x.ExaminationPlan.EX_ExaminationRoomLayout.Where(w => w.ClassroomID == layout.ClassroomID).Sum(w => w.EX_ExaminationRoomStudent.Count)))
  1697. < studentIDList.Count)
  1698. {
  1699. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1700. + "的考场" + classroomEntity.Name + "时间安排存在冲突,考场无法容纳该考试任务的学生,请重新核对后再进行设置。");
  1701. }
  1702. if (existPlanViewList.Any(x => x.ExaminationPlan.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent)
  1703. .Any(w => studentIDList.Contains(w.UserID))))
  1704. {
  1705. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1706. + "的考场" + classroomEntity.Name + "时间安排存在冲突,部分考生时间安排冲突,请重新核对后再进行设置。");
  1707. }
  1708. var classroomScheduledTeacher = existPlanViewList.FirstOrDefault(x =>
  1709. x.ExaminationPlan.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == layout.ClassroomID
  1710. && w.CF_Staff.Count != w.CF_Staff.Where(y => staffIDList.Contains(y.UserID)).Count()));
  1711. if (classroomScheduledTeacher != null)
  1712. {
  1713. var scheduledTeacher = string.Join("、", classroomScheduledTeacher.ExaminationPlan.EX_ExaminationRoomLayout.First().
  1714. CF_Staff.Select(x => x.Sys_User.Name).ToList());
  1715. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1716. + "的考场" + classroomEntity.Name + "已由" + scheduledTeacher + "监考,请重新核对后再进行设置。");
  1717. }
  1718. if (existPlanViewList.Any(x => x.ExaminationPlan.EX_ExaminationRoomLayout.Where(w => w.ClassroomID != layout.ClassroomID)
  1719. .SelectMany(w => w.CF_Staff).Any(w => staffIDList.Contains(w.UserID))))
  1720. {
  1721. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1722. + "的监考老师时间安排冲突,请重新核对后再进行设置。");
  1723. }
  1724. var schedulingStudentConflictList = (from student in studentIDList
  1725. from scheduling in schedulingList.Where(x => x.Date == examinationPlanView.ExaminationPlan.ExaminationDate
  1726. && x.StartTime <= examinationPlanView.ExaminationPlan.EndTime && x.EndTime >= examinationPlanView.ExaminationPlan.StartTime)
  1727. from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student)
  1728. group student by student into g
  1729. select g.FirstOrDefault()
  1730. ).ToList();
  1731. if (schedulingStudentConflictList.Count > 0)
  1732. {
  1733. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1734. + "的考试时间安排冲突,部分学生由于需要上课无法安排,请重新核对后再进行设置。");
  1735. }
  1736. var schedulingClassroomConflictList = (from scheduling in schedulingList.Where(x => x.ClassroomID == classroomEntity.ClassroomID)
  1737. select scheduling
  1738. ).ToList();
  1739. if (schedulingClassroomConflictList.Count > 0)
  1740. {
  1741. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1742. + "的考场" + classroomEntity.Name + "时间安排存在冲突,该考场被排课占用,请重新核对后再进行设置。");
  1743. }
  1744. var excessiveUseConflictList = (from excessiveUse in classroomExcessiveUseList.Where(x => x.ClassroomID == classroomEntity.ClassroomID)
  1745. select excessiveUse).ToList();
  1746. if (excessiveUseConflictList.Count > 0)
  1747. {
  1748. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1749. + "的考场" + classroomEntity.Name + "时间安排存在冲突,该考场被其他活动占用,请重新核对后再进行设置。");
  1750. }
  1751. var schedulingTeacherConflictList = (from teacher in staffIDList
  1752. from scheduling in schedulingList
  1753. from schedulingTeacher in scheduling.TeacherList.Where(x => x.UserID == teacher)
  1754. group teacher by teacher into g
  1755. select g.FirstOrDefault()
  1756. ).ToList();
  1757. if (schedulingClassroomConflictList.Count > 0)
  1758. {
  1759. errorMessageList.Add("考试计划:" + examinationPlanView.ExaminationPlan.ClassName
  1760. + "的考试时间安排冲突,部分老师由于需要上课无法安排,请重新核对后再进行设置。");
  1761. }
  1762. }
  1763. }
  1764. }
  1765. if (errorMessageList.Count > 0)
  1766. {
  1767. throw new Exception(string.Join(";", errorMessageList));
  1768. }
  1769. this.UnitOfWork.Update<EX_ExaminationPlan>((x => new EX_ExaminationPlan
  1770. {
  1771. ExaminationDate = examinationDate,
  1772. StartTime = startTime,
  1773. EndTime = endTime
  1774. }), (x => examinationPlanIDList.Contains(x.ExaminationPlanID)));
  1775. }
  1776. public List<AdultExaminationPlanExportView> GetAdultExaminationPlanExportViewList(ConfiguretView examinationPlanView, IList<Guid?> examinationPlanIDList,
  1777. Guid? schoolyearID, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID, int? examsCategoryID, int? examinationModeID, int? examinationStyleID, int? starWeek, int? endWeek, int? courseEndWeek, int? statusID)
  1778. {
  1779. Expression<Func<EX_ExaminationPlan, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  1780. if (examinationPlanIDList.Count > 0)
  1781. {
  1782. exp = exp.And(x => examinationPlanIDList.Contains(x.ExaminationPlanID));
  1783. }
  1784. else
  1785. {
  1786. if (schoolyearID.HasValue)
  1787. {
  1788. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  1789. }
  1790. if (collegeID.HasValue)
  1791. {
  1792. exp = exp.And(x => x.CollegeID == collegeID);
  1793. }
  1794. if (gradeYearID.HasValue)
  1795. {
  1796. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.GradeID == gradeYearID)
  1797. .Select(s => s.CF_Classmajor.CF_Grademajor.GradeID).FirstOrDefault() == gradeYearID);
  1798. }
  1799. if (standardID.HasValue)
  1800. {
  1801. exp = exp.And(x => x.CF_Student.Where(w => w.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID)
  1802. .Select(s => s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID).FirstOrDefault() == standardID);
  1803. }
  1804. if (coursematerialID.HasValue)
  1805. {
  1806. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  1807. }
  1808. if (examsCategoryID.HasValue)
  1809. {
  1810. exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
  1811. }
  1812. if (examinationModeID.HasValue)
  1813. {
  1814. exp = exp.And(x => x.ExaminationModeID == examinationModeID);
  1815. }
  1816. if (examinationStyleID.HasValue)
  1817. {
  1818. exp = exp.And(x => x.ExaminationStyleID == examinationStyleID);
  1819. }
  1820. if (starWeek.HasValue)
  1821. {
  1822. exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum >= starWeek));
  1823. }
  1824. if (endWeek.HasValue)
  1825. {
  1826. exp = exp.And(x => x.EM_EducationMission.EM_EducationMissionExamWeekNum.Any(w => w.WeeklyNum <= endWeek));
  1827. }
  1828. if (statusID.HasValue)
  1829. {
  1830. exp = exp.And(x => x.RecordStatus == statusID);
  1831. }
  1832. }
  1833. var q = ExaminationPlanDAL.GetAdultExaminationPlanExportView(exp);
  1834. if (examinationPlanIDList.Count == 0)
  1835. {
  1836. if (!string.IsNullOrEmpty(examinationPlanView.ConditionValue) && !string.IsNullOrEmpty(examinationPlanView.Attribute))
  1837. q = q.DynamicWhere(examinationPlanView.Attribute, examinationPlanView.Condition, examinationPlanView.ConditionValue);
  1838. }
  1839. return q.OrderByDescending(x => x.SchoolyearCode).OrderBy(x => x.MaxExaminationWeekNum).ThenBy(x => x.ClassName).ToList();
  1840. }
  1841. public virtual string AdultImport(string filePath, out string returnMessage)
  1842. {
  1843. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  1844. List<AdultExaminationPlanImportView> errList = new List<AdultExaminationPlanImportView>(); //错误数据行
  1845. List<AdultExaminationPlanImportView> successList = new List<AdultExaminationPlanImportView>(); //导入的数据行
  1846. DataTimeHelper dth = new DataTimeHelper();
  1847. #region 解析文件,存放到一个List集合里
  1848. Dictionary<string, string> cellheader = new Dictionary<string, string>
  1849. {
  1850. { "CoursematerialName", "考试科目" }, { "ClassName", "考试班级名称" },
  1851. { "MissionStudentCount", "学生数" }, { "StudentCount", "排考人数" },
  1852. { "ExamsCategoryName", "考试性质" }, { "ExaminationModeName", "考试方式" },
  1853. { "ExaminationWeekNumString", "考试周次" }, { "ExaminationDateString", "考试日期" },
  1854. { "StartTimeString", "考试时间起"},{ "EndTimeString", "考试时间止" },
  1855. { "ClassroomName", "考室"},{ "TeacherNames", "监考老师" }
  1856. };
  1857. List<AdultExaminationPlanImportView> importRowlist =
  1858. NpoiExcelHelper.ExcelToEntityList<AdultExaminationPlanImportView>(cellheader, filePath, out errorMsg, out errList);
  1859. File.Delete(filePath);
  1860. cellheader.Add("ErrorMessage", "错误信息");//还原字典项
  1861. #endregion
  1862. #region 清空格
  1863. for (int i = 0; i < importRowlist.Count();i++ )
  1864. {
  1865. if(importRowlist[i].CoursematerialName!=null)
  1866. importRowlist[i].CoursematerialName=importRowlist[i].CoursematerialName.Trim();
  1867. if (importRowlist[i].ClassName != null)
  1868. importRowlist[i].ClassName = importRowlist[i].ClassName.Trim();
  1869. if (importRowlist[i].MissionStudentCount != null)
  1870. importRowlist[i].MissionStudentCount = importRowlist[i].MissionStudentCount.Trim();
  1871. if (importRowlist[i].StudentCount != null)
  1872. importRowlist[i].StudentCount = importRowlist[i].StudentCount.Trim();
  1873. if (importRowlist[i].ExamsCategoryName != null)
  1874. importRowlist[i].ExamsCategoryName = importRowlist[i].ExamsCategoryName.Trim();
  1875. if (importRowlist[i].ExaminationModeName != null)
  1876. importRowlist[i].ExaminationModeName = importRowlist[i].ExaminationModeName.Trim();
  1877. if (importRowlist[i].ExaminationWeekNumString != null)
  1878. importRowlist[i].ExaminationWeekNumString = importRowlist[i].ExaminationWeekNumString.Trim();
  1879. if (importRowlist[i].ExaminationDateString != null)
  1880. importRowlist[i].ExaminationDateString = importRowlist[i].ExaminationDateString.Trim();
  1881. if (importRowlist[i].StartTimeString != null)
  1882. importRowlist[i].StartTimeString = importRowlist[i].StartTimeString.Trim();
  1883. if (importRowlist[i].EndTimeString != null)
  1884. importRowlist[i].EndTimeString = importRowlist[i].EndTimeString.Trim();
  1885. if (importRowlist[i].ClassroomName != null)
  1886. importRowlist[i].ClassroomName = importRowlist[i].ClassroomName.Trim();
  1887. if (importRowlist[i].TeacherNames != null)
  1888. importRowlist[i].TeacherNames = importRowlist[i].TeacherNames.Trim();
  1889. }
  1890. #endregion
  1891. #region 检查文件中的内容
  1892. #region 读取用于校验的数据,便于后续处理
  1893. var coursematerialNameList = importRowlist.Select(x => x.CoursematerialName).ToList();
  1894. var classNameList = importRowlist.Select(x => x.ClassName).ToList();
  1895. //默认排当前学年学期的考试计划
  1896. var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  1897. var classroomNameList = importRowlist.Select(x => x.ClassroomName).ToList();
  1898. var teacherNameList = importRowlist.Where(x => !string.IsNullOrEmpty(x.TeacherNames))
  1899. .SelectMany(x => x.TeacherNames.Split('/').ToList()).Distinct().ToList();
  1900. var coursematerialList = ExaminationPlanDAL.CoursematerialRepository.GetList(x => coursematerialNameList.Contains(x.CourseName)).ToList();
  1901. var examinationPlanList = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => classNameList.Contains(x.ClassName) && x.SchoolyearID == curSchoolyear.SchoolYearID, (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)), (x => x.CF_Student.Select(w => w.Sys_User))).ToList();
  1902. var examsCategoryList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ExamsCategory);
  1903. var examinationModeList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ExaminationMode);
  1904. var classroomList = ExaminationRoomSettingRepository
  1905. .GetList(x => classroomNameList.Contains(x.CF_Classroom.Name))
  1906. .Select(x => x.CF_Classroom).ToList();
  1907. var classroomViewList = ClassroomDAL.GetClassroomViewQueryable(x => classroomNameList.Contains(x.Name)).ToList();
  1908. var teacherList = ExaminationPlanDAL.StaffDAL.staffRepository.GetList(x => teacherNameList.Contains(x.Sys_User.Name), (x => x.Sys_User)).ToList();
  1909. #endregion
  1910. foreach (var importRow in importRowlist)
  1911. {
  1912. string errorMessage = "";
  1913. var errorItem = Mapper.DynamicMap<AdultExaminationPlanImportView>(importRow);
  1914. #region 检查基本录入格式
  1915. var curCoursematerialList = coursematerialList.Where(x => x.CourseName == (importRow.CoursematerialName ?? "").Trim()).ToList();
  1916. var examsCategory = examsCategoryList.FirstOrDefault(x => x.Name == (importRow.ExamsCategoryName ?? "").Trim());
  1917. var examinationMode = examinationModeList.FirstOrDefault(x => x.Name == (importRow.ExaminationModeName ?? "").Trim());
  1918. var classroom = classroomList.FirstOrDefault(x => x.Name == (importRow.ClassroomName ?? "").Trim());
  1919. var curTeacherNameList = (importRow.TeacherNames ?? "").Trim().Split('/').Where(x => !string.IsNullOrEmpty(x)).ToList();
  1920. var teacher = teacherList.Where(x => curTeacherNameList.Contains(x.Sys_User.Name)).ToList();
  1921. if (curCoursematerialList.Count == 0)
  1922. {
  1923. errorMessage += "没有对应的课程名称,请检查输入。";
  1924. }
  1925. if (examsCategory == null)
  1926. {
  1927. errorMessage += "考试性质错误,请检查输入。";
  1928. }
  1929. if (examinationMode == null)
  1930. {
  1931. errorMessage += "考试方式错误,请检查输入。";
  1932. }
  1933. if (importRow.StudentCount == null)
  1934. {
  1935. importRow.StudentCount = importRow.MissionStudentCount;
  1936. }
  1937. if (string.IsNullOrEmpty(importRow.ClassroomName))
  1938. {
  1939. errorMessage += "请填写考室。";
  1940. }
  1941. else if (classroom == null)
  1942. {
  1943. errorMessage += "考室信息错误,并未将" + importRow.ClassroomName + "安排为考室,请检查输入。";
  1944. }
  1945. var errorTeacherList = curTeacherNameList.Where(x => !teacher.Select(w => w.Sys_User.Name).Contains(x)).ToList();
  1946. if (errorTeacherList.Count > 0)
  1947. {
  1948. errorMessage += "监考老师" + string.Join("/", errorTeacherList) + "名字输入错误,请检查输入。";
  1949. }
  1950. else if (teacher.Count == 0)
  1951. {
  1952. errorMessage += "请填写监考老师信息。";
  1953. }
  1954. var coursematerialIDList = curCoursematerialList.Select(x => (Guid?)x.CoursematerialID).ToList();
  1955. var examinationPlan = examinationPlanList.FirstOrDefault(x => x.ClassName == importRow.ClassName
  1956. && coursematerialIDList.Contains(x.CoursematerialID));
  1957. //if (examinationPlanList.Where(x => x.ClassName == importRow.ClassName
  1958. // && coursematerialIDList.Contains(x.CoursematerialID) && x.ExamsCategoryID == examsCategory.Value
  1959. // && x.ExaminationModeID == examinationMode.Value ).Count() >= 2)
  1960. //{
  1961. // errorMessage += "存在考试科目、考试班级名称、考试性质、考试方式相同的两条或以上的数据。";
  1962. //}
  1963. if (examsCategory != null && examinationMode !=null)
  1964. {
  1965. examinationPlan = examinationPlanList.FirstOrDefault(x => x.ClassName == importRow.ClassName
  1966. && coursematerialIDList.Contains(x.CoursematerialID) && x.ExamsCategoryID == examsCategory.Value
  1967. && x.ExaminationModeID == examinationMode.Value);
  1968. }
  1969. if (examinationPlan == null)
  1970. {
  1971. examinationPlan = examinationPlanList.FirstOrDefault(x => x.ClassName == importRow.ClassName
  1972. && coursematerialIDList.Contains(x.CoursematerialID));
  1973. if (examinationPlan == null)
  1974. {
  1975. errorMessage += "当前学年学期并没有该班级名称和课程名称的考试安排,请检查输入。";
  1976. }
  1977. }
  1978. else if(examinationPlan.RecordStatus == (int)CF_ApprovalStatus.Submitted)
  1979. {
  1980. errorMessage += "已存在相同的已提交的考试计划";
  1981. }
  1982. if (classroom != null && examinationPlan != null && classroom.Examinationseating < examinationPlan.CF_Student.Count)
  1983. {
  1984. errorMessage += "所选考室可容纳的座位数不足,无法安排学生进行考试。";
  1985. }
  1986. DateTime examinationDate = default(DateTime);
  1987. if (string.IsNullOrEmpty(importRow.ExaminationDateString))
  1988. {
  1989. errorMessage += "请填写考试日期。";
  1990. }
  1991. else
  1992. {
  1993. try
  1994. {
  1995. DateTime date;
  1996. if (DateTime.TryParse(importRow.ExaminationDateString.Trim().ToString(), out date))
  1997. {
  1998. examinationDate = Convert.ToDateTime(importRow.ExaminationDateString.Trim().ToString());
  1999. }
  2000. else
  2001. {
  2002. var dateTime = DateTime.FromOADate(double.Parse(importRow.ExaminationDateString.Trim().ToString()));
  2003. examinationDate = dateTime;
  2004. }
  2005. }
  2006. catch
  2007. {
  2008. errorMessage += "考试日期必须为年-月-日的日期格式。";
  2009. }
  2010. }
  2011. TimeSpan startTime = default(TimeSpan);
  2012. if (string.IsNullOrEmpty(importRow.StartTimeString))
  2013. {
  2014. errorMessage += "请填写考试时间起。";
  2015. }
  2016. else
  2017. {
  2018. try
  2019. {
  2020. DateTime date;
  2021. if (DateTime.TryParse(importRow.StartTimeString.Trim().ToString(), out date))
  2022. {
  2023. startTime = Convert.ToDateTime(importRow.StartTimeString.Trim().ToString()).TimeOfDay;
  2024. }
  2025. else
  2026. {
  2027. var dateTime = DateTime.FromOADate(double.Parse(importRow.StartTimeString.Trim().ToString()));
  2028. startTime = dateTime.TimeOfDay;
  2029. }
  2030. }
  2031. catch
  2032. {
  2033. errorMessage += "考试时间起必须为时:分的时间格式。";
  2034. }
  2035. }
  2036. TimeSpan endTime = default(TimeSpan);
  2037. if (string.IsNullOrEmpty(importRow.EndTimeString))
  2038. {
  2039. errorMessage += "请填写考试时间止。";
  2040. }
  2041. else
  2042. {
  2043. try
  2044. {
  2045. DateTime date;
  2046. if (DateTime.TryParse(importRow.EndTimeString.Trim().ToString(), out date))
  2047. {
  2048. endTime = Convert.ToDateTime(importRow.EndTimeString.Trim().ToString()).TimeOfDay;
  2049. }
  2050. else
  2051. {
  2052. var dateTime = DateTime.FromOADate(double.Parse(importRow.EndTimeString.Trim().ToString()));
  2053. endTime = dateTime.TimeOfDay;
  2054. }
  2055. }
  2056. catch
  2057. {
  2058. errorMessage += "考试时间止必须为时:分的时间格式。";
  2059. }
  2060. }
  2061. if (startTime >= endTime)
  2062. {
  2063. errorMessage += "结束时间需大于开始时间。";
  2064. }
  2065. #endregion
  2066. if (errorMessage != "")
  2067. {
  2068. errorItem.ErrorMessage = errorMessage;
  2069. if(endTime!=default(TimeSpan)){
  2070. errorItem.EndTimeString = " " + endTime;
  2071. }
  2072. if (startTime!=default(TimeSpan))
  2073. {
  2074. errorItem.StartTimeString = " " + startTime;
  2075. }
  2076. if(examinationDate!=default(DateTime)){
  2077. errorItem.ExaminationDateString = " " + examinationDate;
  2078. }
  2079. errList.Add(errorItem);
  2080. continue;
  2081. }
  2082. else
  2083. {
  2084. importRow.CoursematerialID = examinationPlan.CoursematerialID;
  2085. importRow.ExaminationPlan = examinationPlan;
  2086. importRow.ExamsCategoryID = examsCategory.Value;
  2087. importRow.ExaminationModeID = examinationMode.Value;
  2088. importRow.ExaminationStyleID = examinationPlan.ExaminationStyleID;
  2089. importRow.ExaminationDate = examinationDate;
  2090. importRow.StartTime = startTime;
  2091. importRow.EndTime = endTime;
  2092. importRow.ClassroomID = classroom.ClassroomID;
  2093. importRow.Examinationseating = classroom.Examinationseating;
  2094. importRow.TeacherList = teacher;
  2095. successList.Add(importRow);
  2096. }
  2097. }
  2098. #endregion
  2099. var checkList = successList;
  2100. #region 准备排课数据用于校验
  2101. var scheduleDateTimeList = successList.GroupBy(x => x.ExaminationPlan.SchoolyearID)
  2102. .Select(x => new {
  2103. SchoolyearID = x.Key,
  2104. DataTimeList = x.GroupBy(w => new
  2105. {
  2106. StartTime = w.ExaminationDate.Value.Add(w.StartTime.Value),
  2107. EndTime = w.ExaminationDate.Value.Add(w.EndTime.Value)
  2108. })
  2109. .Select(w => new StartEndTimeView { StartTime = w.Key.StartTime, EndTime = w.Key.EndTime }).ToList()
  2110. }).ToList();
  2111. List<EducationSchedulingWeekNumView> schedulingList = new List<EducationSchedulingWeekNumView>();
  2112. List<ClassroomExcessiveUseWeekNumView> excessiveUseList = new List<ClassroomExcessiveUseWeekNumView>();
  2113. scheduleDateTimeList.ForEach(x =>
  2114. {
  2115. schedulingList.AddRange(this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewForExaminationTeacher(x.SchoolyearID.Value,
  2116. x.DataTimeList));
  2117. excessiveUseList.AddRange(this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
  2118. x.SchoolyearID.Value, x.DataTimeList));
  2119. });
  2120. #endregion
  2121. #region 检查导入文件内部数据的冲突
  2122. #region 检查考室冲突
  2123. //var classroomConflictList = (from source in successList
  2124. // from dest in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2125. // && x.ExaminationDate == source.ExaminationDate
  2126. // && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2127. // && x.ClassroomID == source.ClassroomID)
  2128. // select new { source, dest }).ToList();
  2129. //classroomConflictList.ForEach(x =>
  2130. //{
  2131. // var errorItem = x.source;
  2132. // errorItem.ErrorMessage = "考场安排和其他行存在时间冲突,请检查。";
  2133. // errList.Add(errorItem);
  2134. // successList.Remove(x.source);
  2135. //});
  2136. #endregion
  2137. #region 检查导入文件导入同一考室,并且时间重复的,人数是否超过可排人次
  2138. var classroomstudentCount = (from source in successList
  2139. from studentcount in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2140. && x.ExaminationDate == source.ExaminationDate
  2141. && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2142. && x.ClassroomID == source.ClassroomID)
  2143. group studentcount by studentcount.ExaminationPlan.ExaminationPlanID
  2144. into gstucount
  2145. join succ in successList
  2146. on gstucount.Key equals succ.ExaminationPlan.ExaminationPlanID
  2147. select new
  2148. {
  2149. //source,
  2150. succ
  2151. }).ToList();
  2152. classroomstudentCount.ForEach(x =>
  2153. {
  2154. var count = int.Parse(x.succ.MissionStudentCount);
  2155. var isrepeatList = checkList.Any(y => y.ExaminationPlan.ExaminationPlanID != x.succ.ExaminationPlan.ExaminationPlanID && y.ExaminationDate == x.succ.ExaminationDate
  2156. && y.StartTime <= x.succ.EndTime && y.EndTime >= x.succ.StartTime && y.ClassroomID == x.succ.ClassroomID);
  2157. if (isrepeatList)
  2158. {
  2159. var repeatList = checkList.Where(y => y.ExaminationPlan.ExaminationPlanID != x.succ.ExaminationPlan.ExaminationPlanID && y.ExaminationDate == x.succ.ExaminationDate
  2160. && y.StartTime <= x.succ.EndTime && y.EndTime >= x.succ.StartTime && y.ClassroomID == x.succ.ClassroomID).ToList();
  2161. foreach (var repeat in repeatList)
  2162. {
  2163. count = count + int.Parse(repeat.MissionStudentCount);
  2164. }
  2165. }
  2166. if (count > classroomList.FirstOrDefault(w => w.ClassroomID == x.succ.ClassroomID).Examinationseating)
  2167. {
  2168. var errorItem = x.succ;
  2169. errorItem.ErrorMessage = "考场座位数不足,请检查。";
  2170. errList.Add(errorItem);
  2171. successList.Remove(x.succ);
  2172. }
  2173. });
  2174. #endregion
  2175. #region 检查教师冲突
  2176. var teacherConflictList = (from source in successList
  2177. from dest in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2178. && x.ExaminationDate == source.ExaminationDate
  2179. && x.ClassroomID != source.ClassroomID
  2180. && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2181. && x.TeacherList.Select(w => w.UserID).Intersect(source.TeacherList.Select(w => w.UserID)).Count() > 0).Take(1)
  2182. select source).ToList();
  2183. teacherConflictList.ForEach(x =>
  2184. {
  2185. var errorItem = x;
  2186. errorItem.ErrorMessage = "监考老师和其他行存在时间冲突,请检查。";
  2187. errList.Add(errorItem);
  2188. successList.Remove(x);
  2189. });
  2190. var teacherClassroomConflictList = (from source in successList
  2191. from dest in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2192. && x.ExaminationDate == source.ExaminationDate
  2193. && x.ClassroomID == source.ClassroomID
  2194. && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2195. && x.TeacherList.Select(w => w.UserID).Intersect(source.TeacherList.Select(w => w.UserID)).Count() != x.TeacherList.Count).Take(1)
  2196. select source).ToList();
  2197. teacherClassroomConflictList.ForEach(x =>
  2198. {
  2199. var errorItem = x;
  2200. errorItem.ErrorMessage = "同一考场的监考老师必须相同,请检查考室或监考老师是否存在冲突。";
  2201. errList.Add(errorItem);
  2202. successList.Remove(x);
  2203. });
  2204. #endregion
  2205. #region 检查学生冲突
  2206. //var studentConflictList = (from source in successList
  2207. // from dest in successList.Where(x => x.ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2208. // && x.ExaminationDate == source.ExaminationDate
  2209. // && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2210. // && x.ExaminationPlan.CF_Student.Select(w => w.UserID).Intersect(source.ExaminationPlan.CF_Student.Select(w => w.UserID)).Count() > 0)
  2211. // select new { source, dest }).ToList();
  2212. //studentConflictList.ForEach(x =>
  2213. //{
  2214. // var errorItem = x.source;
  2215. // errorItem.ErrorMessage = "考试学生和其他行存在时间冲突,请检查。";
  2216. // errList.Add(errorItem);
  2217. // successList.Remove(x.source);
  2218. //});
  2219. #endregion
  2220. #endregion
  2221. #region 检查和其他考场安排之间的冲突
  2222. var examinationDateList = successList.Select(x => x.ExaminationDate).Distinct().ToList();
  2223. var sameDateExaminationPlanList = ExaminationPlanDAL.ExaminationRoomLayoutRepository
  2224. .GetList(x => examinationDateList.Contains(x.EX_ExaminationPlan.ExaminationDate),
  2225. (x => x.EX_ExaminationPlan),
  2226. //(x => x.EX_ExaminationPlan.CF_Student),
  2227. (x => x.CF_Staff),
  2228. (x => x.EX_ExaminationRoomStudent)).ToList();
  2229. #region 检查考室冲突
  2230. //var classroomOuterConflictList = (from source in successList
  2231. // from dest in sameDateExaminationPlanList.Where(x => x.EX_ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2232. // && x.EX_ExaminationPlan.ExaminationDate == source.ExaminationDate
  2233. // && x.EX_ExaminationPlan.StartTime <= source.EndTime && x.EX_ExaminationPlan.EndTime >= source.StartTime
  2234. // && x.ClassroomID == source.ClassroomID)
  2235. // select new { source, dest }).ToList();
  2236. //classroomOuterConflictList.ForEach(x =>
  2237. //{
  2238. // var errorItem1 = x.source;
  2239. // errorItem1.ErrorMessage = "考场安排和已有的考试安排存在时间冲突,请检查。";
  2240. // errList.Add(errorItem1);
  2241. // successList.Remove(x.source);
  2242. //});
  2243. #endregion
  2244. #region 检查教师冲突
  2245. var teacherOuterConflictList = (from source in successList
  2246. from dest in sameDateExaminationPlanList.Where(x => x.EX_ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2247. && x.EX_ExaminationPlan.ExaminationDate == source.ExaminationDate
  2248. && x.EX_ExaminationPlan.StartTime <= source.EndTime && x.EX_ExaminationPlan.EndTime >= source.StartTime
  2249. && x.ClassroomID != source.ClassroomID
  2250. && x.CF_Staff.Select(w => w.UserID).Intersect(source.TeacherList.Select(w => w.UserID)).Count() > 0).Take(1)
  2251. select new { source, dest }).ToList();
  2252. teacherOuterConflictList.ForEach(x =>
  2253. {
  2254. var errorItem1 = x.source;
  2255. errorItem1.ErrorMessage = "监考老师和已有的考试安排存在时间冲突,请检查。";
  2256. errList.Add(errorItem1);
  2257. successList.Remove(x.source);
  2258. });
  2259. var teacherOuterClassroomConflictList = (from source in successList
  2260. from dest in sameDateExaminationPlanList.Where(x => x.EX_ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2261. && x.EX_ExaminationPlan.ExaminationDate == source.ExaminationDate
  2262. && x.ClassroomID == source.ClassroomID
  2263. && x.EX_ExaminationPlan.StartTime <= source.EndTime && x.EX_ExaminationPlan.EndTime >= source.StartTime
  2264. && x.CF_Staff.Select(w => w.UserID).Intersect(source.TeacherList.Select(w => w.UserID)).Count() != x.CF_Staff.Count).Take(1)
  2265. select source).ToList();
  2266. teacherOuterClassroomConflictList.ForEach(x =>
  2267. {
  2268. var errorItem = x;
  2269. errorItem.ErrorMessage = "监考老师和已有的考试安排存在冲突,同一考场的监考老师必须相同,请检查。";
  2270. errList.Add(errorItem);
  2271. successList.Remove(x);
  2272. });
  2273. #endregion
  2274. #region 检查学生冲突
  2275. //var studentOuterConflictList = (from source in successList
  2276. // from dest in sameDateExaminationPlanList.Where(x => x.EX_ExaminationPlan.ExaminationPlanID != source.ExaminationPlan.ExaminationPlanID
  2277. // && x.EX_ExaminationPlan.ExaminationDate == source.ExaminationDate
  2278. // && x.EX_ExaminationPlan.StartTime <= source.EndTime && x.EX_ExaminationPlan.EndTime >= source.StartTime
  2279. // && x.EX_ExaminationPlan.CF_Student.Select(w => w.UserID).Intersect(source.ExaminationPlan.CF_Student.Select(w => w.UserID)).Count() > 0)
  2280. // select new { source, dest }).ToList();
  2281. //studentOuterConflictList.ForEach(x =>
  2282. //{
  2283. // var errorItem = x.source;
  2284. // errorItem.ErrorMessage = "考试学生和已有的考试安排存在时间冲突,请检查。";
  2285. // errList.Add(errorItem);
  2286. // successList.Remove(x.source);
  2287. //});
  2288. #endregion
  2289. #endregion
  2290. #region 检查教室占用冲突
  2291. var classroomExcessUseConflictList = (from source in successList
  2292. from dest in excessiveUseList.Where(x =>
  2293. x.Date == source.ExaminationDate
  2294. && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2295. && x.ClassroomID == source.ClassroomID).Take(1)
  2296. select new { source, dest }).ToList();
  2297. classroomExcessUseConflictList.ForEach(x =>
  2298. {
  2299. var errorItem2 = x.source;
  2300. errorItem2.ErrorMessage = "考场已被占用,请检查。";
  2301. errList.Add(errorItem2);
  2302. successList.Remove(x.source);
  2303. });
  2304. #endregion
  2305. #region 检查和课表的冲突
  2306. #region 检查考室冲突
  2307. var classroomScheduleConflictList = (from source in successList
  2308. from dest in schedulingList.Where(x =>
  2309. x.Date == source.ExaminationDate
  2310. && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2311. && x.ClassroomID == source.ClassroomID).Take(1)
  2312. select new { source, dest }).ToList();
  2313. classroomScheduleConflictList.ForEach(x =>
  2314. {
  2315. var errorItem2 = x.source;
  2316. errorItem2.ErrorMessage = "考场安排和已有的排课存在时间冲突,请检查。";
  2317. errList.Add(errorItem2);
  2318. successList.Remove(x.source);
  2319. });
  2320. #endregion
  2321. #region 检查教师冲突
  2322. var teacherScheduleConflictList = (from source in successList
  2323. from dest in schedulingList.Where(x =>
  2324. x.Date == source.ExaminationDate
  2325. && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2326. && x.TeacherList.Select(w => w.UserID)
  2327. .Intersect(source.TeacherList.Select(w => (Guid?)w.UserID)).Count() > 0).Take(1)
  2328. select new { source, dest }).ToList();
  2329. teacherScheduleConflictList.ForEach(x =>
  2330. {
  2331. var errorItem1 = x.source;
  2332. errorItem1.ErrorMessage = "监考老师和已有的排课存在时间冲突,请检查。";
  2333. errList.Add(errorItem1);
  2334. successList.Remove(x.source);
  2335. });
  2336. #endregion
  2337. #region 检查学生冲突
  2338. var studentScheduleConflictList = (from source in successList
  2339. from dest in schedulingList.Where(x =>
  2340. x.Date == source.ExaminationDate
  2341. && x.StartTime <= source.EndTime && x.EndTime >= source.StartTime
  2342. && x.StudentList.Select(w => w.UserID).Intersect(source.ExaminationPlan.CF_Student.Select(w => w.UserID)).Count() > 0).Take(1)
  2343. select new { source, dest }).ToList();
  2344. studentScheduleConflictList.ForEach(x =>
  2345. {
  2346. var errorItem = x.source;
  2347. errorItem.ErrorMessage = "考试学生和已有的排课存在时间冲突,请检查。";
  2348. errList.Add(errorItem);
  2349. successList.Remove(x.source);
  2350. });
  2351. #endregion
  2352. #endregion
  2353. #region 添加数据
  2354. var scheduledStudentList = new List<StudentClassroomView>();
  2355. var deletedExaminationPlanIDList = new List<Guid>();
  2356. foreach (var succesResult in successList)
  2357. {
  2358. succesResult.ExaminationPlan.ExaminationDate = succesResult.ExaminationDate;
  2359. succesResult.ExaminationPlan.StartTime = succesResult.StartTime;
  2360. succesResult.ExaminationPlan.EndTime = succesResult.EndTime;
  2361. succesResult.ExaminationStyleID = succesResult.ExaminationStyleID;
  2362. //succesResult.ExaminationPlan.EX_ExaminationRoomLayout.ForEach(x => this.UnitOfWork.Remove(x));
  2363. //succesResult.ExaminationPlan.EX_ExaminationRoomLayout = new HashSet<EX_ExaminationRoomLayout>();
  2364. EX_ExaminationRoomLayout newLayout = new EX_ExaminationRoomLayout()
  2365. {
  2366. ExaminationRoomLayoutID = Guid.NewGuid(),
  2367. ExaminationPlanID = succesResult.ExaminationPlan.ExaminationPlanID,
  2368. ClassroomID = succesResult.ClassroomID,
  2369. RowSpacing = 0,
  2370. ColumnSpacing = 0,
  2371. StudentOrderType = (int)CF_StudentOrderType.StudentNo,
  2372. CF_Staff = new HashSet<CF_Staff>(succesResult.TeacherList)
  2373. };
  2374. this.SetNewStatus(newLayout);
  2375. var roomRemainSeat = succesResult.Examinationseating - sameDateExaminationPlanList
  2376. .Where(x => x.EX_ExaminationPlan != null
  2377. && x.EX_ExaminationPlan.ExaminationPlanID != succesResult.ExaminationPlan.ExaminationPlanID
  2378. && x.EX_ExaminationPlan.ExaminationDate == succesResult.ExaminationDate
  2379. && x.ClassroomID == succesResult.ClassroomID
  2380. && x.EX_ExaminationPlan.StartTime <= succesResult.EndTime
  2381. && x.EX_ExaminationPlan.EndTime >= succesResult.StartTime).Sum(x => x.EX_ExaminationRoomStudent.Count)
  2382. - scheduledStudentList.Where(x => x.ClassroomID == succesResult.ClassroomID
  2383. && x.ExaminationDate == succesResult.ExaminationDate
  2384. && x.StartTime <= succesResult.EndTime
  2385. && x.EndTime >= succesResult.StartTime)
  2386. .Count();
  2387. if (roomRemainSeat <= 0)
  2388. {
  2389. var errorItem = succesResult;
  2390. errorItem.ErrorMessage = "考场剩余座位不足,无法安排考试,请检查考场的使用情况。";
  2391. errList.Add(errorItem);
  2392. continue;
  2393. }
  2394. var studentList = (from s in succesResult.ExaminationPlan.CF_Student
  2395. join ss in scheduledStudentList.Where(x => x.ExaminationDate == succesResult.ExaminationDate
  2396. && x.StartTime <= succesResult.EndTime
  2397. && x.EndTime >= succesResult.StartTime)
  2398. on s.UserID equals ss.UserID into dss
  2399. from ess in dss.DefaultIfEmpty()
  2400. where ess == null
  2401. select s).ToList();
  2402. var examinationRoomStudentViewList = studentList.Take(roomRemainSeat ?? 0)
  2403. .Select(x => new ExaminationRoomStudentView
  2404. {
  2405. ExaminationRoomStudentID = Guid.NewGuid(),
  2406. ExaminationRoomLayoutID = newLayout.ExaminationRoomLayoutID,
  2407. UserID = x.UserID,
  2408. LoginID = x.Sys_User.LoginID,
  2409. Remark = ""
  2410. }).ToList();
  2411. var classroomView = classroomViewList.FirstOrDefault(x => x.ClassroomID == succesResult.ClassroomID);
  2412. var examinationRoomStudentList = this.SetRoomStudentSeats(examinationRoomStudentViewList, classroomView, 0, 0, CF_StudentOrderType.StudentNo);
  2413. if (!deletedExaminationPlanIDList.Contains(succesResult.ExaminationPlan.ExaminationPlanID))
  2414. {
  2415. UnitOfWork.Remove<EX_ExaminationRoomStudent>(x => x.EX_ExaminationRoomLayout.ExaminationPlanID == succesResult.ExaminationPlan.ExaminationPlanID);
  2416. UnitOfWork.Remove<EX_ExaminationRoomLayout>(x => x.ExaminationPlanID == succesResult.ExaminationPlan.ExaminationPlanID);
  2417. deletedExaminationPlanIDList.Add(succesResult.ExaminationPlan.ExaminationPlanID);
  2418. }
  2419. newLayout.EX_ExaminationRoomStudent = new HashSet<EX_ExaminationRoomStudent>(examinationRoomStudentList);
  2420. scheduledStudentList.AddRange(newLayout.EX_ExaminationRoomStudent.Select(x => new StudentClassroomView
  2421. {
  2422. ExaminationDate = succesResult.ExaminationDate,
  2423. StartTime = succesResult.StartTime,
  2424. EndTime = succesResult.EndTime,
  2425. ClassroomID = newLayout.ClassroomID,
  2426. UserID = x.UserID
  2427. }));
  2428. this.UnitOfWork.Add(newLayout);
  2429. succesResult.ExaminationPlan.EX_ExaminationRoomLayout.Add(newLayout);
  2430. }
  2431. #endregion
  2432. this.UnitOfWork.Commit();
  2433. returnMessage = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。",
  2434. (importRowlist.Count - errList.Count), errList.Count);
  2435. if (errList.Count > 0)
  2436. {
  2437. return NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "导入问题列表", "");
  2438. }
  2439. else
  2440. {
  2441. return "";
  2442. }
  2443. }
  2444. /// <summary>
  2445. /// 获取期末设定学生
  2446. /// </summary>
  2447. /// <param name="finalExaminationID"></param>
  2448. /// <param name="pageIndex"></param>
  2449. /// <param name="pageSize"></param>
  2450. /// <returns></returns>
  2451. public IGridResultSet<BaseStudentView> GetExaminationPlanStudentList(Guid examinationPlanID)
  2452. {
  2453. return ExaminationPlanDAL.GetExaminationPlanStudentList(examinationPlanID).OrderBy(x => x.LoginID).ToGridResultSet<BaseStudentView>();
  2454. }
  2455. /// <summary>
  2456. /// 新增考试安排
  2457. /// </summary>
  2458. /// <param name="examinationPlanView"></param>
  2459. public void AddExaminationPlan(ExaminationPlanView examinationPlanView)
  2460. {
  2461. try
  2462. {
  2463. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  2464. var curSchoolyear = SchoolYearServices.Value.GetCurrentSchoolYear();
  2465. EX_ExaminationPlan examinationPlan = new EX_ExaminationPlan();
  2466. examinationPlan.ExaminationPlanID = Guid.NewGuid();
  2467. examinationPlan.SchoolyearID = examinationPlanView.SchoolyearID;
  2468. examinationPlan.CollegeID = examinationPlanView.CollegeID;
  2469. examinationPlan.CoursematerialID = examinationPlanView.CoursematerialID;
  2470. examinationPlan.ExaminationModeID = examinationPlanView.ExaminationModeID;
  2471. examinationPlan.ExaminationStyleID = examinationPlanView.ExaminationStyleID;
  2472. examinationPlan.ExamsCategoryID = examinationPlanView.ExamsCategoryID;
  2473. examinationPlan.ClassName = examinationPlanView.ClassName;
  2474. examinationPlan.ExaminationDate = examinationPlanView.ExaminationDate;
  2475. examinationPlan.StartTime = examinationPlanView.StartTime;
  2476. examinationPlan.EndTime = examinationPlanView.EndTime;
  2477. //examinationPlan.CF_Student = new HashSet<CF_Student>(graduateExamPlan.Students);
  2478. SetNewStatus(examinationPlan);
  2479. examinationPlan.RecordStatus = (int)CF_ApprovalStatus.NotSubmitted;
  2480. UnitOfWork.Add(examinationPlan);
  2481. UnitOfWork.Commit();
  2482. //this.UnitOfWork.BulkInsert(examinationPlan, (x => x.CF_Student));
  2483. }
  2484. catch (Exception)
  2485. {
  2486. throw;
  2487. }
  2488. //return null;
  2489. }
  2490. public ExaminationPlanView GetExaminationPlanView(Guid? examinationPlanID)
  2491. {
  2492. ExaminationPlanView examinationPlanView = null;
  2493. if (examinationPlanID.HasValue)
  2494. {
  2495. examinationPlanView = ExaminationPlanDAL.GetExaminationPlanView(x => x.ExaminationPlanID == examinationPlanID).ToList().FirstOrDefault();
  2496. }
  2497. return examinationPlanView;
  2498. }
  2499. /// <summary>
  2500. /// 考试安排增加学生
  2501. /// </summary>
  2502. /// <param name="finalExaminationID"></param>
  2503. /// <param name="userIDs"></param>
  2504. public void ExaminationPlanStudentAdd(Guid? examinationPlanID, List<BaseStudentView> listBaseStudentView)
  2505. {
  2506. try
  2507. {
  2508. }
  2509. catch (Exception)
  2510. {
  2511. throw;
  2512. }
  2513. }
  2514. /// <summary>
  2515. /// 查询考试安排实体
  2516. /// </summary>
  2517. /// <param name="finalExaminationID"></param>
  2518. /// <returns></returns>
  2519. public EX_ExaminationPlan GetExaminationPlan(Guid? examinationPlanID)
  2520. {
  2521. return ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanID, (x => x.CF_Student), (x => x.EX_ExaminationRoomLayout));
  2522. }
  2523. /// <summary>
  2524. /// 重置考试安排
  2525. /// </summary>
  2526. /// <param name="examinationPlanIDs"></param>
  2527. public void ResettingExaminationPlans(List<Guid> examinationPlanIDs)
  2528. {
  2529. try
  2530. {
  2531. if (examinationPlanIDs != null)
  2532. {
  2533. DeleteExaminationClassroomLayoutByPlanID(examinationPlanIDs);
  2534. List<EX_ExaminationPlan> ExaminationPlans = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => examinationPlanIDs.Contains(x.ExaminationPlanID)).ToList();
  2535. foreach (EX_ExaminationPlan examinationPlan in ExaminationPlans)
  2536. {
  2537. if (examinationPlan.RecordStatus == (int)CF_ApprovalStatus.Submitted)
  2538. {
  2539. throw new Exception("选中数据包括已提交数据,不能进行重置");
  2540. }
  2541. examinationPlan.ExaminationDate = null;
  2542. examinationPlan.StartTime = null;
  2543. examinationPlan.EndTime = null;
  2544. UnitOfWork.Update<EX_ExaminationPlan>(examinationPlan);
  2545. }
  2546. UnitOfWork.Commit();
  2547. }
  2548. }
  2549. catch (Exception ex)
  2550. {
  2551. throw ex;
  2552. }
  2553. }
  2554. public void DeleteExaminationClassroomLayoutByPlanID(List<Guid> examinationPlanIDs)
  2555. {
  2556. var examinationLayoutList = this.ExaminationPlanDAL.ExaminationRoomLayoutRepository
  2557. .GetList(x => examinationPlanIDs.Contains(x.ExaminationPlanID.Value),
  2558. (x => x.EX_ExaminationRoomStudent), (x => x.CF_Staff)).ToList();
  2559. foreach (var examinationLayout in examinationLayoutList)
  2560. {
  2561. examinationLayout.CF_Staff = new HashSet<CF_Staff>();
  2562. examinationLayout.EX_ExaminationRoomStudent.ToList().ForEach(x => this.UnitOfWork.Remove(x));
  2563. this.UnitOfWork.Remove(examinationLayout);
  2564. }
  2565. this.UnitOfWork.Commit();
  2566. }
  2567. /// <summary>
  2568. /// 撤销考试安排
  2569. /// </summary>
  2570. /// <param name="examinationPlanIDs"></param>
  2571. public void CancelExaminationPlans(List<Guid> examinationPlanIDs)
  2572. {
  2573. try
  2574. {
  2575. if (examinationPlanIDs != null)
  2576. {
  2577. //DeleteExaminationClassroomLayout(examinationPlanIDs);
  2578. List<EX_ExaminationPlan> ExaminationPlans = ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => examinationPlanIDs.Contains(x.ExaminationPlanID), (x => x.EX_ExaminationRoomLayout)).ToList();
  2579. foreach (EX_ExaminationPlan examinationPlan in ExaminationPlans)
  2580. {
  2581. examinationPlan.RecordStatus = (int)CF_ApprovalStatus.NotSubmitted;
  2582. UnitOfWork.Update<EX_ExaminationPlan>(examinationPlan);
  2583. }
  2584. UnitOfWork.Commit();
  2585. }
  2586. }
  2587. catch (Exception ex)
  2588. {
  2589. throw ex;
  2590. }
  2591. }
  2592. public void CheckStudentSchedule(Guid examinationPlanID, IList<Guid> studentUserIDList)
  2593. {
  2594. var examinationPlan = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanID);
  2595. var scheduleDateTimeList = new List<StartEndTimeView> {
  2596. new StartEndTimeView { StartTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.StartTime.Value)
  2597. , EndTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.EndTime.Value) }
  2598. };
  2599. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(examinationPlan.SchoolyearID.Value,
  2600. scheduleDateTimeList);
  2601. var scheduledUserIDList = schedulingList.SelectMany(x => x.StudentList)
  2602. .Where(x => studentUserIDList.Contains(x.UserID))
  2603. .GroupBy(x => x.UserID)
  2604. .Select(x => x.Key).ToList();
  2605. if (scheduledUserIDList.Count > 0)
  2606. {
  2607. var userList = UserRepository.GetList(x => scheduledUserIDList.Contains(x.UserID)).ToList();
  2608. throw new Exception(string.Format("学生{0}在该时段有课,不能参加考试,请检查考试时间设置。",
  2609. string.Join("、", userList.Select(x => x.Name))));
  2610. }
  2611. }
  2612. public void SaveGdss(ExaminationPlanGdssView examinationPlanView, IList<Guid?> staffIDList, IList<Guid?> studentIDList)
  2613. {
  2614. if (!examinationPlanView.ExaminationDate.HasValue)
  2615. {
  2616. throw new Exception("必须指定考试日期。");
  2617. }
  2618. if (!examinationPlanView.StartTime.HasValue)
  2619. {
  2620. throw new Exception("必须指定开始时间。");
  2621. }
  2622. if (!examinationPlanView.EndTime.HasValue)
  2623. {
  2624. throw new Exception("必须指定结束时间。");
  2625. }
  2626. if (examinationPlanView.ExaminationDate.Value.Date < DateTime.Today)
  2627. {
  2628. throw new Exception("考试日期需在当天之后。");
  2629. }
  2630. if (examinationPlanView.StartTime.Value >= examinationPlanView.EndTime.Value)
  2631. {
  2632. throw new Exception("结束时间需在开始时间之后。");
  2633. }
  2634. var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  2635. var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  2636. var examinationPlanEntity = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlanID,
  2637. (x => x.CF_Student),
  2638. (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)),
  2639. (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student))));
  2640. if (examinationPlanEntity == null)
  2641. {
  2642. throw new Exception("指定的考试计划不存在。");
  2643. }
  2644. else
  2645. {
  2646. this.SetModifyStatus(examinationPlanEntity);
  2647. }
  2648. examinationPlanEntity.ExaminationDate = examinationPlanView.ExaminationDate;
  2649. examinationPlanEntity.StartTime = examinationPlanView.StartTime;
  2650. examinationPlanEntity.EndTime = examinationPlanView.EndTime;
  2651. var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanView.ExaminationDate
  2652. && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
  2653. && x.ExaminationPlanID != examinationPlanView.ExaminationPlanID)
  2654. .Include(x => x.CF_Student)
  2655. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff.Select(e => e.Sys_User)))
  2656. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  2657. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  2658. .ToList();
  2659. var classroomEntity = ExaminationPlanDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == examinationPlanView.ClassroomID, (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)));
  2660. if (scheduledPlanViewList.Any(x => x.ExaminationStyleID != examinationPlanEntity.ExaminationStyleID
  2661. && x.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == examinationPlanView.ClassroomID)))
  2662. {
  2663. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,存在同一时间不同考试方式的排考,请重新核对后再进行设置。");
  2664. }
  2665. if ((classroomEntity.Examinationseating - scheduledPlanViewList.Sum(x =>
  2666. x.EX_ExaminationRoomLayout.Where(w => w.ClassroomID == examinationPlanView.ClassroomID).Sum(w => w.EX_ExaminationRoomStudent.Count)))
  2667. < studentIDList.Count)
  2668. {
  2669. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,考场无法容纳该考试任务的学生,请重新核对后再进行设置。");
  2670. }
  2671. if (scheduledPlanViewList.Any(x => x.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent)
  2672. .Any(w => studentIDList.Contains(w.UserID))))
  2673. {
  2674. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,部分考生时间安排冲突,请重新核对后再进行设置。");
  2675. }
  2676. var classroomScheduledTeacher = scheduledPlanViewList.FirstOrDefault(x => x.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == examinationPlanView.ClassroomID
  2677. && w.CF_Staff.Count != w.CF_Staff.Where(y => staffIDList.Contains(y.UserID)).Count()));
  2678. if (classroomScheduledTeacher != null)
  2679. {
  2680. var scheduledTeacher = string.Join("、", classroomScheduledTeacher.EX_ExaminationRoomLayout.First().CF_Staff.Select(x => x.Sys_User.Name).ToList());
  2681. throw new Exception("考场" + classroomEntity.Name + "已由" + scheduledTeacher + "监考,请重新核对后再进行设置。");
  2682. }
  2683. if (scheduledPlanViewList.Any(x => x.EX_ExaminationRoomLayout.Where(w => w.ClassroomID != examinationPlanView.ClassroomID)
  2684. .SelectMany(w => w.CF_Staff).Any(w => staffIDList.Contains(w.UserID))))
  2685. {
  2686. throw new Exception("监考老师时间安排冲突,请重新核对后再进行设置。");
  2687. }
  2688. //获取排课
  2689. var scheduleDateTimeList = new List<StartEndTimeView> {
  2690. new StartEndTimeView { StartTime = examinationPlanEntity.ExaminationDate.Value.Add(examinationPlanEntity.StartTime.Value),
  2691. EndTime = examinationPlanEntity.ExaminationDate.Value.Add(examinationPlanEntity.EndTime.Value) } };
  2692. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
  2693. scheduleDateTimeList);
  2694. var classroomExcessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
  2695. curSchoolyear.SchoolYearID.Value,
  2696. scheduleDateTimeList);
  2697. var schedulingStudentConflictList = (from student in studentIDList
  2698. from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
  2699. && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime)
  2700. from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student)
  2701. group student by student into g
  2702. select g.FirstOrDefault()
  2703. ).ToList();
  2704. if (schedulingStudentConflictList.Count > 0)
  2705. {
  2706. throw new Exception("考试时间安排冲突,部分学生由于需要上课无法安排,请重新核对后再进行设置。");
  2707. }
  2708. var schedulingClassroomConflictList = (from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
  2709. && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime
  2710. && x.ClassroomID == classroomEntity.ClassroomID)
  2711. select scheduling
  2712. ).ToList();
  2713. if (schedulingClassroomConflictList.Count > 0)
  2714. {
  2715. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,该考场被排课占用,请重新核对后再进行设置。");
  2716. }
  2717. var excessiveUseConflictList = (from excessiveUse in classroomExcessiveUseList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
  2718. && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime
  2719. && x.ClassroomID == classroomEntity.ClassroomID)
  2720. select excessiveUse).ToList();
  2721. if (excessiveUseConflictList.Count > 0)
  2722. {
  2723. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,该考场被其他活动占用,请重新核对后再进行设置。");
  2724. }
  2725. var schedulingTeacherConflictList = (from teacher in staffIDList
  2726. from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
  2727. && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime)
  2728. from schedulingTeacher in scheduling.TeacherList.Where(x => x.UserID == teacher)
  2729. group teacher by teacher into g
  2730. select g.FirstOrDefault()
  2731. ).ToList();
  2732. if (schedulingClassroomConflictList.Count > 0)
  2733. {
  2734. throw new Exception("考试时间安排冲突,部分老师由于需要上课无法安排,请重新核对后再进行设置。");
  2735. }
  2736. examinationPlanEntity.EX_ExaminationRoomLayout.ForEach(x => {
  2737. x.CF_Staff = new HashSet<CF_Staff>();
  2738. UnitOfWork.RemoveRange(x.EX_ExaminationRoomStudent);
  2739. });
  2740. UnitOfWork.RemoveRange(examinationPlanEntity.EX_ExaminationRoomLayout);
  2741. examinationPlanEntity.EX_ExaminationRoomLayout = new HashSet<EX_ExaminationRoomLayout>();
  2742. var examinationRoomLayoutEntity = new EX_ExaminationRoomLayout();
  2743. examinationRoomLayoutEntity.ExaminationRoomLayoutID = Guid.NewGuid();
  2744. examinationRoomLayoutEntity.ExaminationPlanID = examinationPlanEntity.ExaminationPlanID;
  2745. examinationRoomLayoutEntity.ClassroomID = classroomEntity.ClassroomID;
  2746. examinationRoomLayoutEntity.RowSpacing = 0;
  2747. examinationRoomLayoutEntity.ColumnSpacing = 0;
  2748. examinationRoomLayoutEntity.StudentOrderType = examinationPlanView.StudentOrderType;
  2749. var staffList = this.StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
  2750. examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>(staffList);
  2751. this.SetNewStatus(examinationRoomLayoutEntity);
  2752. this.UnitOfWork.Add(examinationRoomLayoutEntity);
  2753. var classroom = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomEntity.ClassroomID).FirstOrDefault();
  2754. var studentList = StudentsDAL.StudentRepository.GetList(x => studentIDList.Contains(x.UserID), (x => x.Sys_User)).ToList();
  2755. var roomStudentList = this.SetRoomStudentSeats(studentList.Select(x => new ExaminationRoomStudentView
  2756. {
  2757. LoginID = x.Sys_User.LoginID,
  2758. UserID = x.UserID,
  2759. ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID
  2760. }).ToList(), classroom, 0, 0);
  2761. roomStudentList.ForEach(x =>
  2762. {
  2763. x.ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID;
  2764. this.SetNewStatus(x);
  2765. this.UnitOfWork.Add(x);
  2766. });
  2767. //考试计划对应的学生同步修改
  2768. examinationPlanEntity.CF_Student = new HashSet<CF_Student>();
  2769. roomStudentList.ForEach(x =>
  2770. {
  2771. CF_Student stu = studentList.Where(y => y.UserID == x.UserID).FirstOrDefault();
  2772. examinationPlanEntity.CF_Student.Add(stu);
  2773. });
  2774. UnitOfWork.Commit();
  2775. }
  2776. public List<StudentAndCourseForExcelView> CheckBeforeGdssSave(ExaminationPlanGdssView examinationPlanView, IList<Guid?> staffIDList, IList<Guid?> studentIDList)
  2777. {
  2778. //如果是补考学生和排课存在冲突的话提醒是否强行排考
  2779. var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  2780. List<StudentAndCourseForExcelView> studentViewList = new List<StudentAndCourseForExcelView>();
  2781. var examinationPlanEntity = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlanID,
  2782. (x => x.CF_Student),
  2783. (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)),
  2784. (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student))));
  2785. if (examinationPlanEntity.ExamsCategoryID == (int)CF_ExamsCategory.Resit || examinationPlanEntity.ExamsCategoryID == (int)CF_ExamsCategory.GraduationExam)
  2786. {
  2787. var scheduleDateTimeListforResit = new List<StartEndTimeView> {
  2788. new StartEndTimeView { StartTime = examinationPlanView.ExaminationDate.Value.Add(examinationPlanView.StartTime.Value),
  2789. EndTime = examinationPlanView.ExaminationDate.Value.Add(examinationPlanView.EndTime.Value) } };
  2790. var schedulingListforResit = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
  2791. scheduleDateTimeListforResit);
  2792. var schedulingStudentConflictListforResit = (from student in studentIDList
  2793. from scheduling in schedulingListforResit.Where(x => x.Date == examinationPlanView.ExaminationDate
  2794. && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime)
  2795. from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student)
  2796. group student by student into g
  2797. select g.FirstOrDefault()
  2798. ).ToList();
  2799. if (schedulingStudentConflictListforResit.Count > 0)
  2800. {
  2801. //studentViewList = StudentsDAL.GetStudentQueryable(x => schedulingStudentConflictListforResit.Contains(x.UserID)).ToList();
  2802. var schedulingID = schedulingListforResit.Where(x => x.Date == examinationPlanView.ExaminationDate && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime).Select(x => x.EducationSchedulingID).ToList();
  2803. var query = ExaminationPlanDAL.GetStudentAndCourseList(schedulingID, schedulingStudentConflictListforResit);
  2804. studentViewList = query.Distinct().ToList();
  2805. //studentViewList = schedulingStudentConflictListforResit;
  2806. }
  2807. }
  2808. return studentViewList;
  2809. }
  2810. /// <summary>
  2811. /// 补考排考学生和排课冲突,强行排考(不考虑学生与排课的冲突)
  2812. /// </summary>
  2813. /// <param name="examinationPlanView"></param>
  2814. /// <param name="staffIDList"></param>
  2815. /// <param name="studentIDList"></param>
  2816. public void SaveGdssNotClashingStudent(ExaminationPlanGdssView examinationPlanView, IList<Guid?> staffIDList, IList<Guid?> studentIDList)
  2817. {
  2818. if (!examinationPlanView.ExaminationDate.HasValue)
  2819. {
  2820. throw new Exception("必须指定考试日期。");
  2821. }
  2822. if (!examinationPlanView.StartTime.HasValue)
  2823. {
  2824. throw new Exception("必须指定开始时间。");
  2825. }
  2826. if (!examinationPlanView.EndTime.HasValue)
  2827. {
  2828. throw new Exception("必须指定结束时间。");
  2829. }
  2830. if (examinationPlanView.ExaminationDate.Value.Date < DateTime.Today)
  2831. {
  2832. throw new Exception("考试日期需在当天之后。");
  2833. }
  2834. if (examinationPlanView.StartTime.Value >= examinationPlanView.EndTime.Value)
  2835. {
  2836. throw new Exception("结束时间需在开始时间之后。");
  2837. }
  2838. var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  2839. var inschoolStatusList = StudentsDAL.InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  2840. var examinationPlanEntity = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanView.ExaminationPlanID,
  2841. (x => x.CF_Student),
  2842. (x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff)),
  2843. (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student))));
  2844. if (examinationPlanEntity == null)
  2845. {
  2846. throw new Exception("指定的考试计划不存在。");
  2847. }
  2848. else
  2849. {
  2850. this.SetModifyStatus(examinationPlanEntity);
  2851. }
  2852. examinationPlanEntity.ExaminationDate = examinationPlanView.ExaminationDate;
  2853. examinationPlanEntity.StartTime = examinationPlanView.StartTime;
  2854. examinationPlanEntity.EndTime = examinationPlanView.EndTime;
  2855. var scheduledPlanViewList = this.ExaminationPlanDAL.ExaminationPlanRepository.GetList(x => x.ExaminationDate == examinationPlanView.ExaminationDate
  2856. && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime && x.EX_ExaminationRoomLayout.Count() > 0
  2857. && x.ExaminationPlanID != examinationPlanView.ExaminationPlanID)
  2858. .Include(x => x.CF_Student)
  2859. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Staff.Select(e => e.Sys_User)))
  2860. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.CF_Classroom.EX_ExaminationRoomLayout.Select(e => e.EX_ExaminationPlan)))
  2861. .Include(x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationRoomStudent.Select(e => e.CF_Student)))
  2862. .ToList();
  2863. var classroomEntity = ExaminationPlanDAL.ClassroomRepository.GetSingle(x => x.ClassroomID == examinationPlanView.ClassroomID, (x => x.EX_ExaminationRoomLayout.Select(w => w.EX_ExaminationPlan)));
  2864. if (scheduledPlanViewList.Any(x => x.ExaminationStyleID != examinationPlanEntity.ExaminationStyleID
  2865. && x.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == examinationPlanView.ClassroomID)))
  2866. {
  2867. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,存在同一时间不同考试方式的排考,请重新核对后再进行设置。");
  2868. }
  2869. if ((classroomEntity.Examinationseating - scheduledPlanViewList.Sum(x =>
  2870. x.EX_ExaminationRoomLayout.Where(w => w.ClassroomID == examinationPlanView.ClassroomID).Sum(w => w.EX_ExaminationRoomStudent.Count)))
  2871. < studentIDList.Count)
  2872. {
  2873. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,考场无法容纳该考试任务的学生,请重新核对后再进行设置。");
  2874. }
  2875. if (scheduledPlanViewList.Any(x => x.EX_ExaminationRoomLayout.SelectMany(w => w.EX_ExaminationRoomStudent)
  2876. .Any(w => studentIDList.Contains(w.UserID))))
  2877. {
  2878. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,部分考生时间安排冲突,请重新核对后再进行设置。");
  2879. }
  2880. var classroomScheduledTeacher = scheduledPlanViewList.FirstOrDefault(x => x.EX_ExaminationRoomLayout.Any(w => w.ClassroomID == examinationPlanView.ClassroomID
  2881. && w.CF_Staff.Count != w.CF_Staff.Where(y => staffIDList.Contains(y.UserID)).Count()));
  2882. if (classroomScheduledTeacher != null)
  2883. {
  2884. var scheduledTeacher = string.Join("、", classroomScheduledTeacher.EX_ExaminationRoomLayout.First().CF_Staff.Select(x => x.Sys_User.Name).ToList());
  2885. throw new Exception("考场" + classroomEntity.Name + "已由" + scheduledTeacher + "监考,请重新核对后再进行设置。");
  2886. }
  2887. if (scheduledPlanViewList.Any(x => x.EX_ExaminationRoomLayout.Where(w => w.ClassroomID != examinationPlanView.ClassroomID)
  2888. .SelectMany(w => w.CF_Staff).Any(w => staffIDList.Contains(w.UserID))))
  2889. {
  2890. throw new Exception("监考老师时间安排冲突,请重新核对后再进行设置。");
  2891. }
  2892. //获取排课
  2893. var scheduleDateTimeList = new List<StartEndTimeView> {
  2894. new StartEndTimeView { StartTime = examinationPlanEntity.ExaminationDate.Value.Add(examinationPlanEntity.StartTime.Value),
  2895. EndTime = examinationPlanEntity.ExaminationDate.Value.Add(examinationPlanEntity.EndTime.Value) } };
  2896. var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
  2897. scheduleDateTimeList);
  2898. var classroomExcessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
  2899. curSchoolyear.SchoolYearID.Value,
  2900. scheduleDateTimeList);
  2901. var schedulingClassroomConflictList = (from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
  2902. && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime
  2903. && x.ClassroomID == classroomEntity.ClassroomID)
  2904. select scheduling
  2905. ).ToList();
  2906. if (schedulingClassroomConflictList.Count > 0)
  2907. {
  2908. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,该考场被排课占用,请重新核对后再进行设置。");
  2909. }
  2910. var excessiveUseConflictList = (from excessiveUse in classroomExcessiveUseList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
  2911. && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime
  2912. && x.ClassroomID == classroomEntity.ClassroomID)
  2913. select excessiveUse).ToList();
  2914. if (excessiveUseConflictList.Count > 0)
  2915. {
  2916. throw new Exception("考场" + classroomEntity.Name + "时间安排存在冲突,该考场被其他活动占用,请重新核对后再进行设置。");
  2917. }
  2918. var schedulingTeacherConflictList = (from teacher in staffIDList
  2919. from scheduling in schedulingList.Where(x => x.Date == examinationPlanEntity.ExaminationDate
  2920. && x.StartTime <= examinationPlanEntity.EndTime && x.EndTime >= examinationPlanEntity.StartTime)
  2921. from schedulingTeacher in scheduling.TeacherList.Where(x => x.UserID == teacher)
  2922. group teacher by teacher into g
  2923. select g.FirstOrDefault()
  2924. ).ToList();
  2925. if (schedulingClassroomConflictList.Count > 0)
  2926. {
  2927. throw new Exception("考试时间安排冲突,部分老师由于需要上课无法安排,请重新核对后再进行设置。");
  2928. }
  2929. examinationPlanEntity.EX_ExaminationRoomLayout.ForEach(x =>
  2930. {
  2931. x.CF_Staff = new HashSet<CF_Staff>();
  2932. UnitOfWork.RemoveRange(x.EX_ExaminationRoomStudent);
  2933. });
  2934. UnitOfWork.RemoveRange(examinationPlanEntity.EX_ExaminationRoomLayout);
  2935. examinationPlanEntity.EX_ExaminationRoomLayout = new HashSet<EX_ExaminationRoomLayout>();
  2936. var examinationRoomLayoutEntity = new EX_ExaminationRoomLayout();
  2937. examinationRoomLayoutEntity.ExaminationRoomLayoutID = Guid.NewGuid();
  2938. examinationRoomLayoutEntity.ExaminationPlanID = examinationPlanEntity.ExaminationPlanID;
  2939. examinationRoomLayoutEntity.ClassroomID = classroomEntity.ClassroomID;
  2940. examinationRoomLayoutEntity.RowSpacing = 0;
  2941. examinationRoomLayoutEntity.ColumnSpacing = 0;
  2942. examinationRoomLayoutEntity.StudentOrderType = examinationPlanView.StudentOrderType;
  2943. var staffList = this.StaffDAL.staffRepository.GetList(x => staffIDList.Contains(x.UserID)).ToList();
  2944. examinationRoomLayoutEntity.CF_Staff = new HashSet<CF_Staff>(staffList);
  2945. this.SetNewStatus(examinationRoomLayoutEntity);
  2946. this.UnitOfWork.Add(examinationRoomLayoutEntity);
  2947. var classroom = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomEntity.ClassroomID).FirstOrDefault();
  2948. var studentList = StudentsDAL.StudentRepository.GetList(x => studentIDList.Contains(x.UserID), (x => x.Sys_User)).ToList();
  2949. var roomStudentList = this.SetRoomStudentSeats(studentList.Select(x => new ExaminationRoomStudentView
  2950. {
  2951. LoginID = x.Sys_User.LoginID,
  2952. UserID = x.UserID,
  2953. ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID
  2954. }).ToList(), classroom, 0, 0);
  2955. roomStudentList.ForEach(x =>
  2956. {
  2957. x.ExaminationRoomLayoutID = examinationRoomLayoutEntity.ExaminationRoomLayoutID;
  2958. this.SetNewStatus(x);
  2959. this.UnitOfWork.Add(x);
  2960. });
  2961. //考试计划对应的学生同步修改
  2962. examinationPlanEntity.CF_Student = new HashSet<CF_Student>();
  2963. roomStudentList.ForEach(x =>
  2964. {
  2965. CF_Student stu = studentList.Where(y => y.UserID == x.UserID).FirstOrDefault();
  2966. examinationPlanEntity.CF_Student.Add(stu);
  2967. });
  2968. UnitOfWork.Commit();
  2969. }
  2970. public IGridResultSet<StaffView> GetExaminationTeacherViewInfoGdss(Guid? examinationPlanID)
  2971. {
  2972. return ExaminationPlanDAL.GetExaminationTeacherView(x => x.ExaminationPlanID == examinationPlanID, (x => true)).ToGridResultSet();
  2973. }
  2974. public ExaminationPlanGdssView GetExaminationPlanGdssViewInfo(Guid? examinationPlanID)
  2975. {
  2976. return ExaminationPlanDAL.GetExaminationPlanGdssView(x => x.ExaminationPlanID == examinationPlanID).FirstOrDefault();
  2977. }
  2978. public IGridResultSet<StudentsView> GetGdssStudentListForSelect(ConfiguretView configuretView, Guid? examinationPlanID, Guid? collegeID, Guid? grademajorID, Guid? classmajorID, int pageIndex, int pageSize)
  2979. {
  2980. Expression<Func<CF_Student, bool>> exp = x => true;
  2981. if(collegeID.HasValue)
  2982. {
  2983. exp = exp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  2984. }
  2985. if(grademajorID.HasValue)
  2986. {
  2987. exp = exp.And(x => x.CF_Classmajor.GrademajorID == grademajorID);
  2988. }
  2989. if(classmajorID.HasValue)
  2990. {
  2991. exp = exp.And(x => x.ClassmajorID == classmajorID);
  2992. }
  2993. var query = ExaminationPlanDAL.GetGdssStudentListView(examinationPlanID, exp);
  2994. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  2995. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  2996. return query.OrderByDescending(x => x.LoginID).ToGridResultSet<StudentsView>(pageIndex, pageSize);
  2997. //return null;
  2998. }
  2999. //public List<StudentsView> GetClashingStudentView(ExaminationPlanGdssView examinationPlanView, IList<Guid?> studentIDList)
  3000. //{
  3001. // var curSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  3002. // var scheduleDateTimeList = new List<StartEndTimeView> {
  3003. // new StartEndTimeView { StartTime = examinationPlanView.ExaminationDate.Value.Add(examinationPlanView.StartTime.Value),
  3004. // EndTime = examinationPlanView.ExaminationDate.Value.Add(examinationPlanView.EndTime.Value) } };
  3005. // var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewByDateTimeList(curSchoolyear.SchoolYearID.Value,
  3006. // scheduleDateTimeList);
  3007. // var classroomExcessiveUseList = this.ClassroomExcessiveUseServices.Value.GetClassroomExcessiveUseWeekNumViewByDateTimeList(
  3008. // curSchoolyear.SchoolYearID.Value,
  3009. // scheduleDateTimeList);
  3010. // var schedulingStudentConflictList = (from student in studentIDList
  3011. // from scheduling in schedulingList.Where(x => x.Date == examinationPlanView.ExaminationDate
  3012. // && x.StartTime <= examinationPlanView.EndTime && x.EndTime >= examinationPlanView.StartTime)
  3013. // from schedulingStudent in scheduling.StudentList.Where(x => x.UserID == student)
  3014. // group student by student into g
  3015. // select g.FirstOrDefault()
  3016. // ).ToList();
  3017. // var studentViewList = StudentsDAL.GetStudentQueryable(x => schedulingStudentConflictList.Contains(x.UserID)).ToList();
  3018. // return studentViewList;
  3019. //}
  3020. }
  3021. public class StudentClassroomView
  3022. {
  3023. public DateTime? ExaminationDate { get; set; }
  3024. public TimeSpan? StartTime { get; set; }
  3025. public TimeSpan? EndTime { get; set; }
  3026. public Guid? ClassroomID { get; set; }
  3027. public Guid ExaminationPlanID { get; set; }
  3028. public Guid? UserID { get; set; }
  3029. public List<Guid> TeacherIDList { get; set; }
  3030. public int? ExaminationStyleID { get; set; }
  3031. }
  3032. public class AutoScheduleModifyView
  3033. {
  3034. public EX_ExaminationPlan ExaminationPlan { get; set; }
  3035. public HashSet<CF_Staff> CF_Staff { get; set; }
  3036. public DateTime? ExaminationDate { get; set; }
  3037. public TimeSpan? StartTime { get; set; }
  3038. public TimeSpan? EndTime { get; set; }
  3039. public EX_ExaminationRoomSetting ExaminationRoom { get; set; }
  3040. public List<CF_Student> ScheduleStudentList { get; set; }
  3041. }
  3042. }