EducationMissionClassScheduleAdultServices.cs 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using EMIS.Entities;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.ViewModel;
  10. using EMIS.DataLogic.EducationManage;
  11. using EMIS.DataLogic.EducationSchedule;
  12. using EMIS.DataLogic.SchedulingManage.SchedulingSettings;
  13. using EMIS.ViewModel.EducationManagement;
  14. using Bowin.Common.Utility;
  15. using EMIS.Utility;
  16. using Bowin.Common.DataTime;
  17. using EMIS.DataLogic.Repositories;
  18. using EMIS.ViewModel.CacheManage;
  19. using EMIS.ViewModel.SchedulingManage.SchedulingSettings;
  20. using EMIS.DataLogic.UniversityManage.TeacherManage;
  21. using EMIS.DataLogic;
  22. using EMIS.ViewModel.EducationManage;
  23. using System.Data.Entity;
  24. namespace EMIS.CommonLogic.EducationSchedule
  25. {
  26. public class EducationMissionClassScheduleAdultServices : BaseServices, IEducationMissionClassScheduleAdultServices
  27. {
  28. public AdultEducationMissionClassDAL educationMissionClassDAL { get; set; }
  29. public EducationSchedulingClassRepository educationSchedulingClassRepository { get; set; }
  30. public EducationMissionClassScheduleDAL educationMissionClassScheduleDAL { get; set; }
  31. public EducationMissionClassSchedulingASdultDAL EducationMissionClassSchedulingASdultDAL { get; set; }
  32. public CollegePriorityDAL collegePriorityDAL { get; set; }
  33. public CoursematerialRepository coursematerialRepository { get; set; }
  34. public ClassmajorRepository classmajorRepository { get; set; }
  35. public ClassroomRepository classroomRepository { get; set; }
  36. public SchoolyearRepository SchoolyearRepository { get; set; }
  37. public CoursesTimeRepository coursesTimeRepository { get; set; }
  38. public CourseTimeHoursDAL CourseTimeHoursDAL { get; set; }
  39. public EducationMissionClassRepository educationMissionClassRepository { get; set; }
  40. public EducationMissionRepository educationMissionRepository { get; set; }
  41. public StaffDAL staffDAL { get; set; }
  42. public CollegeRepository CollegeRepository { get; set; }
  43. public AdultEducationScheduleRepository adultEducationScheduleRepository { get; set; }
  44. public AdultEducationScheduleTeacherRepository AdultEducationScheduleTeacherRepository { get; set; }
  45. public EducationSchedulingClassDAL EducationSchedulingClassDAL { get; set; }
  46. /// <summary>
  47. /// 列表查询
  48. /// </summary>
  49. /// <param name="configuretView"></param>
  50. /// <param name="campusID"></param>
  51. /// <param name="collegeID"></param>
  52. /// <param name="schoolyearID"></param>
  53. /// <param name="departmentID"></param>
  54. /// <param name="coursematerialID"></param>
  55. /// <param name="approvalStatus"></param>
  56. /// <param name="teachingModeID"></param>
  57. /// <param name="grademajorID"></param>
  58. /// <param name="gradeYearID"></param>
  59. /// <param name="StandardID"></param>
  60. /// <param name="pageIndex"></param>
  61. /// <param name="pageSize"></param>
  62. /// <returns></returns>
  63. public Bowin.Common.Linq.Entity.IGridResultSet<EducationMissionImportClassView> GetEducationMissionClassScheduleViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? grademajorID, int? gradeYearID, int? StandardID, Guid? CoursesTimeID,int? learningformID, int? education, string LearnSystem, int pageIndex, int pageSize)
  64. {
  65. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => true);
  66. Expression<Func<EM_ExecutablePlan, bool>> executablePlanExp = (x => true);
  67. Expression<Func<EM_ExecutableOptionalCourse, bool>> executableOptionalCourseExp = (x => true);
  68. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> executableFreeSelectionCourseCourseExp = (x => true);
  69. //if(StandardID.HasValue)
  70. //{
  71. // executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == StandardID);
  72. //}
  73. if (campusID.HasValue)
  74. {
  75. exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
  76. }
  77. if (collegeID.HasValue)
  78. {
  79. exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
  80. }
  81. if (departmentID.HasValue)
  82. {
  83. exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
  84. }
  85. if (gradeYearID.HasValue)
  86. {
  87. //exp = exp.And(x => x.EM_ExecutablePlan.CF_Grademajor.SchoolyearID == gradeYearID);
  88. executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  89. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  90. }
  91. //if (grademajorID.HasValue)
  92. //{
  93. // //exp = exp.And(x => x.EM_ExecutablePlan.GrademajorID == grademajorID);
  94. // executablePlanExp = executablePlanExp.And(x => x.GrademajorID == grademajorID);
  95. // executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.GrademajorID == grademajorID);
  96. //}
  97. if (schoolyearID.HasValue)
  98. {
  99. exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
  100. }
  101. if (coursematerialID.HasValue)
  102. {
  103. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  104. executablePlanExp = executablePlanExp.And(x => x.CoursematerialID == coursematerialID);
  105. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID);
  106. executableFreeSelectionCourseCourseExp = executableFreeSelectionCourseCourseExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID);
  107. }
  108. if (approvalStatus.HasValue)
  109. {
  110. exp = exp.And(x => x.RecordStatus == approvalStatus);
  111. }
  112. if (teachingModeID.HasValue)
  113. {
  114. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  115. }
  116. if (CoursesTimeID.HasValue)
  117. {
  118. exp = exp.And(x => x.EM_CoursesTime.Any(c => c.CoursesTimeID == CoursesTimeID));
  119. }
  120. if (learningformID.HasValue)
  121. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID));
  122. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  123. {
  124. var LearnSystems = Convert.ToDecimal(LearnSystem);
  125. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems));
  126. }
  127. if (education.HasValue)
  128. {
  129. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.EducationID == education.Value));
  130. }
  131. var query = EducationMissionClassSchedulingASdultDAL.GetEducationMissionClassViewQuery(exp, executablePlanExp,
  132. executableOptionalCourseExp, executableFreeSelectionCourseCourseExp);
  133. if (StandardID.HasValue)
  134. {
  135. query = query.Where(x => x.StandardID == StandardID);
  136. }
  137. if (grademajorID.HasValue)
  138. {
  139. query = query.Where(x => x.GrademajorID == grademajorID);
  140. }
  141. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  142. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  143. var resultQuery = query.OrderByDescending(x => x.SchoolyearCode)
  144. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  145. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name);
  146. var result = resultQuery.ToGridResultSet<EducationMissionImportClassView>(pageIndex, pageSize);
  147. var educationMissionClassID = result.rows.Select(x => x.EducationMissionClassID).ToList();
  148. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  149. result.rows.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  150. return result;
  151. }
  152. /// <summary>
  153. /// 导出查询
  154. /// </summary>
  155. /// <param name="configuretView"></param>
  156. /// <param name="campusID"></param>
  157. /// <param name="collegeID"></param>
  158. /// <param name="schoolyearID"></param>
  159. /// <param name="departmentID"></param>
  160. /// <param name="coursematerialID"></param>
  161. /// <param name="approvalStatus"></param>
  162. /// <param name="teachingModeID"></param>
  163. /// <param name="grademajorID"></param>
  164. /// <param name="gradeYearID"></param>
  165. /// <param name="StandardID"></param>
  166. /// <param name="pageIndex"></param>
  167. /// <param name="pageSize"></param>
  168. /// <returns></returns>
  169. public List<EducationMissionImportClassView> GetEducationMissionClassScheduleViewGridExcel(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? schoolyearID, Guid? departmentID, Guid? coursematerialID, int? approvalStatus, int? teachingModeID, Guid? grademajorID, int? gradeYearID, int? StandardID, List<Guid?> EducationMissionClassList, Guid? CoursesTimeID, int? learningformID, int? education, string LearnSystem)
  170. {
  171. Expression<Func<EM_EducationMissionClass, bool>> exp = (x => true);
  172. Expression<Func<EM_ExecutablePlan, bool>> executablePlanExp = (x => true);
  173. Expression<Func<EM_ExecutableOptionalCourse, bool>> executableOptionalCourseExp = (x => true);
  174. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> executableFreeSelectionCourseCourseExp = (x => true);
  175. if (EducationMissionClassList != null)
  176. {
  177. exp = exp.And(x => EducationMissionClassList.Contains(x.EducationMissionClassID));
  178. }
  179. else{
  180. if (campusID.HasValue)
  181. {
  182. exp = exp.And(x => x.EM_EducationMission.CF_College.CampusID == campusID);
  183. }
  184. if (collegeID.HasValue)
  185. {
  186. exp = exp.And(x => x.EM_EducationMission.CollegeID == collegeID);
  187. }
  188. if (departmentID.HasValue)
  189. {
  190. exp = exp.And(x => x.EM_EducationMission.DepartmentID == departmentID);
  191. }
  192. if (gradeYearID.HasValue)
  193. {
  194. executablePlanExp = executablePlanExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  195. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.CF_Grademajor.GradeID == gradeYearID);
  196. }
  197. if (grademajorID.HasValue)
  198. {
  199. executablePlanExp = executablePlanExp.And(x => x.GrademajorID == grademajorID);
  200. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.GrademajorID == grademajorID);
  201. }
  202. if (schoolyearID.HasValue)
  203. {
  204. exp = exp.And(x => x.EM_EducationMission.SchoolyearID == schoolyearID);
  205. }
  206. if (coursematerialID.HasValue)
  207. {
  208. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  209. executablePlanExp = executablePlanExp.And(x => x.CoursematerialID == coursematerialID);
  210. executableOptionalCourseExp = executableOptionalCourseExp.And(x => x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID);
  211. executableFreeSelectionCourseCourseExp = executableFreeSelectionCourseCourseExp.And(x => x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID);
  212. }
  213. if (approvalStatus.HasValue)
  214. {
  215. exp = exp.And(x => x.RecordStatus == approvalStatus);
  216. }
  217. if (teachingModeID.HasValue)
  218. {
  219. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  220. }
  221. if (CoursesTimeID.HasValue)
  222. {
  223. exp = exp.And(x => x.EM_CoursesTime.Any(c => c.CoursesTimeID == CoursesTimeID));
  224. }
  225. if (learningformID.HasValue)
  226. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID));
  227. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  228. {
  229. var LearnSystems = Convert.ToDecimal(LearnSystem);
  230. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems));
  231. }
  232. if (education.HasValue)
  233. {
  234. exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.EducationID == education.Value));
  235. }
  236. }
  237. var query = EducationMissionClassSchedulingASdultDAL.GetEducationMissionClassViewQueryblExcel(exp, executablePlanExp,
  238. executableOptionalCourseExp, executableFreeSelectionCourseCourseExp);
  239. //if (EducationMissionClassList != null)
  240. //{
  241. // query.Where(x => EducationMissionClassList.Contains(x.EducationMissionClassID));
  242. //}
  243. if (StandardID.HasValue)
  244. {
  245. query = query.Where(x => x.StandardID == StandardID);
  246. }
  247. var educationMissionClassID = query.Select(x => x.EducationMissionClassID).ToList();
  248. var missionClassTeacherList = educationMissionClassDAL.GetMissionClassTeacherQuery(x => educationMissionClassID.Contains(x.EducationMissionClassID)).ToList();
  249. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  250. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  251. var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode)
  252. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenByDescending(x => x.GradeYearID)
  253. .ThenBy(x => x.StandardID).ThenBy(x => x.CourseName).ThenBy(x => x.OrderNo).ThenBy(x => x.Name)
  254. .ToList();
  255. result.ForEach(x => x.MissionClassTeacherView = new HashSet<MissionClassTeacherView>(missionClassTeacherList.Where(y => y.EducationMissionClassID == x.EducationMissionClassID)));
  256. return result;
  257. }
  258. public void EducationMissionClassScheduleDelete(List<Guid?> missionClassID)
  259. {
  260. var missionClassList = educationMissionClassDAL.educationMissionClassRepository.GetList(x => missionClassID.Contains(x.EducationMissionClassID),
  261. (x => x.CF_Classmajor),
  262. (x => x.EM_EducationMission),
  263. (x => x.EM_EducationMissionClassSettings),
  264. (x => x.EM_EducationMissionClassTeachingSetting),
  265. (x => x.EM_EducationSchedulingClass),
  266. (x => x.EM_EducationSchedulingClass.Select(w => w.CF_Student)),
  267. (x => x.EM_MissionClassTeacher),
  268. (x => x.EM_CourseProcess),
  269. (x => x.EM_CoursesTime),
  270. (x => x.EM_CourseProcess.Select(y => y.EM_CourseProcessTeacher))).ToList();
  271. var adultEducationScheduleIDList = adultEducationScheduleRepository.GetList(x=>missionClassID.Contains(x.EM_EducationSchedulingClass.EM_EducationMissionClass.EducationMissionClassID)).Select(w=>w.AdultEducationScheduleID).ToList();
  272. foreach (var mid in missionClassID)
  273. {
  274. UnitOfWork.Delete<EM_MissionClassTeacher>(x => x.MissionClassID==mid);
  275. }
  276. foreach(var missionClass in missionClassList)
  277. {
  278. missionClass.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Submitted;
  279. this.SetModifyStatus(missionClass);
  280. UnitOfWork.Delete<EM_EducationMissionExamTime>(x => x.EducationMissionID == missionClass.EducationMissionID);
  281. UnitOfWork.Delete<EM_EducationMissionExamWeekNum>(x => x.EducationMissionID == missionClass.EducationMissionID);
  282. }
  283. foreach (var mid in adultEducationScheduleIDList)
  284. {
  285. UnitOfWork.Delete<ES_AdultEducationScheduleTeacher>(x => x.AdultEducationScheduleID == mid);
  286. UnitOfWork.Delete<ES_AdultEducationSchedule>(x =>x.AdultEducationScheduleID==mid);
  287. }
  288. UnitOfWork.Commit();
  289. }
  290. /// <summary>
  291. /// 教学任务导入
  292. /// </summary>
  293. /// <param name="dataList">导入的数据集合</param>
  294. /// <param name="errdataList">返回的操作失败集合</param>
  295. /// <param name="successCount">操作成功记录条数</param>
  296. /// <returns></returns>
  297. public void EducationMissionClassImport(out int OkCount, out List<EducationMissionImportClassView> errdataList, out int successCount, string sourcePhysicalPath, string sourceWebPath, out string errorWebPath, out string Errinfo, Guid schoolyear)
  298. {
  299. var excel = new NpoiExcelHelper();
  300. #region 1.0 单元格抬头
  301. Dictionary<string, string> cellheader = new Dictionary<string, string>
  302. {
  303. { "CollegeName", RSL.Get("College") }, { "Education", RSL.Get("CultureModel") },
  304. { "Learningform","学习形式" },{ "ClassNumStr", "班级人数" },
  305. { "Name", "任务班名称" },{ "CourseName", "课程名称" },
  306. { "TotalhoursStr", "总学时" },{ "ReferenceDays", "参考天数" },
  307. { "TeachingTime", "上课时间" },{ "ClassroomName", "课室" },
  308. { "TeacherNameString", "授课教师" },{"ExaminationModeStr","考试方式"},
  309. { "ExamWeek", "考试周次" },{ "ExamTime", "考试时间" },
  310. { "Assistant", "班主任" },{ "StandardName", "年级专业" },
  311. { "CourseCode", "课程代码" },{ "CourseTime", "课时类别" },
  312. { "TheoryCourseStr", "理论学时" },{ "PracticehoursStr", "实践学时" },
  313. { "TeachingDay", "执行天数" }, { "TeachingHours", "执行学时" },
  314. { "ErrorMessage", "错误信息" }
  315. };
  316. #endregion
  317. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  318. List<EducationMissionImportClassView> errList = new List<EducationMissionImportClassView>();
  319. DataTimeHelper dth = new DataTimeHelper();
  320. #region 1.1解析文件,存放到一个List集合里
  321. // 1.1解析文件,存放到一个List集合里
  322. cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要
  323. List<EducationMissionImportClassView> enlist =
  324. NpoiExcelHelper.ExcelToEntityList<EducationMissionImportClassView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  325. cellheader.Add("ErrorMessage", "错误信息");//还原字典项
  326. #endregion
  327. #region 读取校验数据
  328. if (enlist.Count() <= 0)
  329. {
  330. throw new Exception("请填写Excel模板信息数据。");
  331. }
  332. //任务班
  333. var missionClassNameList = enlist.Select(x => x.Name).ToList();
  334. var missionClassList = educationMissionClassDAL.educationMissionClassRepository.GetList(x => missionClassNameList.Contains(x.Name),
  335. (x => x.CF_Classmajor),
  336. (x => x.EM_EducationMission),
  337. (x => x.EM_EducationMissionClassTeachingSetting),
  338. (x => x.EM_EducationMissionClassSettings),
  339. (x => x.EM_EducationSchedulingClass),
  340. (x => x.EM_EducationSchedulingClass.Select(w => w.CF_Student)),
  341. (x => x.EM_MissionClassTeacher),
  342. (x => x.EM_CourseProcess),
  343. (x => x.EM_CoursesTime),
  344. (x => x.EM_CourseProcess.Select(y => y.EM_CourseProcessTeacher))).ToList();
  345. var classmajorIDList = missionClassList.Select(w => w.MainScheduleClassID).ToList();
  346. var classmajorList = this.classmajorRepository.GetList(x => classmajorIDList.Contains(x.ClassmajorID), (x => x.CF_Grademajor)).ToList();
  347. //任务班年级
  348. var gradeyearList = classmajorList.Select(x => x.CF_Grademajor.GradeID).Distinct().ToList();
  349. //教师
  350. var teacherNameList = enlist.Where(x => !string.IsNullOrEmpty(x.TeacherNameString))
  351. .SelectMany(x => x.TeacherNameString.Split('\\').ToList()).Distinct().ToList();
  352. var teacherList = staffDAL.staffRepository.GetList(x => teacherNameList.Contains(x.Sys_User.Name));
  353. //教室
  354. var ClassroomNameList = enlist.Select(x => x.ClassroomName);
  355. var ClassroomName = classroomRepository.GetList(x => ClassroomNameList.Contains(x.Name),(x=>x.CF_ClassroomType)).ToList();
  356. //课时类别
  357. List<CourseTimeHoursView> CourseTimeHoursList = CourseTimeHoursDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int?)SYS_STATUS.UNUSABLE, w => w.RecordStatus > (int?)SYS_STATUS.UNUSABLE
  358. && (gradeyearList.Contains(w.Years))
  359. ).ToList();
  360. //任务班ID
  361. var missionClassIDList = missionClassList.Select(x=>x.EducationMissionClassID).ToList();
  362. //排课班
  363. var educationSchedulingClassIDList= educationSchedulingClassRepository.GetList(x=> missionClassIDList.Contains(x.EM_EducationMissionClass.EducationMissionClassID)).ToList();
  364. //已排的课
  365. var EducationScheduleList = adultEducationScheduleRepository.GetList(x => x.SchoolyearID == schoolyear, (x => x.EM_EducationSchedulingClass)).ToList();
  366. //学年学期
  367. var school= SchoolyearRepository.Entities.Where(x => x.SchoolyearID == schoolyear).FirstOrDefault();
  368. #endregion
  369. #region 1.2 将Excel数据写入数据库中
  370. #region 1.2.1 对List集合进行有效性校验
  371. #region 1.2.1.1检测必填项是否必填
  372. for (int i = 0; i < enlist.Count; i++)
  373. {
  374. EducationMissionImportClassView en = enlist[i];
  375. string errorMsgStr = "第" + (i + 2) + "行数据检测异常:";
  376. en.ErrorMessage = errorMsgStr;
  377. bool isHaveNoInputValue = false; // 是否含有未输入项
  378. en.IsExcelVaildateOK = true;
  379. if (string.IsNullOrEmpty(en.Name))
  380. {
  381. errorMsgStr += "任务班名称不能为空;";
  382. isHaveNoInputValue = true;
  383. }
  384. if (string.IsNullOrEmpty(en.ClassroomName))
  385. {
  386. errorMsgStr += "课室不能为空;";
  387. isHaveNoInputValue = true;
  388. }
  389. if (string.IsNullOrEmpty(en.TeacherNameString))
  390. {
  391. errorMsgStr += "授课教师不能为空;";
  392. isHaveNoInputValue = true;
  393. }
  394. if (string.IsNullOrEmpty(en.TeachingTime))
  395. {
  396. errorMsgStr += "上课时间不能为空;";
  397. isHaveNoInputValue = true;
  398. }
  399. #region 1.2.1.2 检测(数据唯一性、)
  400. var missionClass = missionClassList.Where(x => x.Name == en.Name).FirstOrDefault();
  401. var missionClassYear = missionClassList.Where(x => x.Name == en.Name && x.EM_EducationMission.SchoolyearID == schoolyear).FirstOrDefault();
  402. //var missionStates
  403. #region 任务班
  404. if (!string.IsNullOrEmpty(en.Name))
  405. {
  406. if (missionClass==null)
  407. {
  408. errorMsgStr += "任务班不存在;";
  409. en.ErrorMessage = errorMsgStr;
  410. isHaveNoInputValue = true;
  411. }
  412. if (missionClassYear == null)
  413. {
  414. errorMsgStr += "任务班的学年学期不是当前选中的学年学期;";
  415. en.ErrorMessage = errorMsgStr;
  416. isHaveNoInputValue = true;
  417. }
  418. else
  419. {
  420. if (missionClassYear.EM_CoursesTime==null)
  421. {
  422. errorMsgStr += "请设置课时类别;";
  423. en.ErrorMessage = errorMsgStr;
  424. isHaveNoInputValue = true;
  425. }
  426. }
  427. //if (missionClass.ApprovalStatus == (int)EM_EducationMissionClassStatus.Scheduled)
  428. //{
  429. // errorMsgStr += "任务班状态为以排课状态,不能导入;";
  430. // en.ErrorMessage = errorMsgStr;
  431. // isHaveNoInputValue = true;
  432. //}
  433. //if (missionClass.ApprovalStatus == (int)EM_EducationMissionClassStatus.NotSubmitted)
  434. //{
  435. // errorMsgStr += "任务班状态为未提交状态,不能导入;";
  436. // en.ErrorMessage = errorMsgStr;
  437. // isHaveNoInputValue = true;
  438. //}
  439. }
  440. #endregion
  441. #region 课时类别
  442. if (missionClassYear!=null)
  443. {
  444. if (missionClassYear.EM_CoursesTime.Count()!=0)
  445. {
  446. if (!string.IsNullOrEmpty(en.CourseTime))
  447. {
  448. var missionClassMainClassmajor = classmajorList.FirstOrDefault(x => x.ClassmajorID == missionClassYear.MainScheduleClassID);
  449. var gradeYear = missionClassMainClassmajor.CF_Grademajor.GradeID;
  450. if (CourseTimeHoursList.Count(x => x.Year == gradeYear) != 0)
  451. {
  452. var CourseTimeHours = CourseTimeHoursList.Where(x => x.time_starTime_endTime == en.CourseTime && x.Year == gradeYear).FirstOrDefault();
  453. if(CourseTimeHours!=null){
  454. en.CourseTimeID=CourseTimeHours.CoursesTimeID;
  455. }
  456. else
  457. {
  458. errorMsgStr += "请填写正确的课时类别;";
  459. isHaveNoInputValue = true;
  460. }
  461. }
  462. else
  463. {
  464. errorMsgStr += "该年级的课时类别找不到对应的学时转换设置,请检查学时转换设置;";
  465. isHaveNoInputValue = true;
  466. }
  467. }
  468. else
  469. {
  470. errorMsgStr += "课时类别不能为空;";
  471. isHaveNoInputValue = true;
  472. }
  473. }
  474. else
  475. {
  476. errorMsgStr += "任务班未设置课时类别,请去教学任务设置;";
  477. isHaveNoInputValue = true;
  478. }
  479. }
  480. #endregion
  481. #region 课室
  482. if (missionClassYear != null)
  483. {
  484. if (!string.IsNullOrEmpty(en.ClassroomName))
  485. {
  486. var ClassID = Guid.Empty;
  487. var Classroom = ClassroomName.Where(x => x.Name == en.ClassroomName.Trim()).FirstOrDefault();
  488. if (Classroom != null)
  489. {
  490. ClassID = ClassroomName.Where(x => x.CF_ClassroomType.Any(w => w.ClassroomID == Classroom.ClassroomID && w.ClassroomType == missionClassYear.ClassroomTypeID)).Select(t => t.ClassroomID).FirstOrDefault();
  491. }
  492. if (Classroom == null)
  493. {
  494. errorMsgStr += "课室不存在;";
  495. en.ErrorMessage = errorMsgStr;
  496. isHaveNoInputValue = true;
  497. }
  498. else
  499. {
  500. if (ClassID == Guid.Empty)
  501. {
  502. errorMsgStr += "课室类型与任务班设置的教室类型不一致;";
  503. en.ErrorMessage = errorMsgStr;
  504. isHaveNoInputValue = true;
  505. }
  506. else
  507. {
  508. en.ClassroomID = Classroom.ClassroomID;
  509. }
  510. }
  511. }
  512. }
  513. #endregion
  514. #region 上课时间
  515. if (!string.IsNullOrEmpty(en.TeachingTime))
  516. {
  517. if (en.TeachingTime.Contains("日"))
  518. {
  519. en.TeachingTime.TrimEnd("日");
  520. }
  521. if (en.TeachingTime.Contains("月"))
  522. {
  523. List<string> TimesSegment = en.TeachingTime.Split(',').ToList();
  524. if (en.TeachingTime.Contains(",") && !en.TeachingTime.Contains(","))
  525. {
  526. TimesSegment = en.TeachingTime.Split(',').ToList();
  527. }
  528. List<string> teachtingTime = new List<string>();
  529. for (int t = 0; t < TimesSegment.Count(); t++)
  530. {
  531. List<string> month = TimesSegment[t].Split('月').ToList();
  532. for (int m = 1; m < month.Count(); m++)
  533. {
  534. List<string> day = month[m].Split('、').ToList();
  535. for (int d = 0; d < day.Count(); d++)
  536. {
  537. teachtingTime.Add(month[0] + "月");
  538. int index = teachtingTime.Count()-1;
  539. teachtingTime[index] += day[d];
  540. }
  541. }
  542. }
  543. DateTime Date;
  544. en.Time = new List<string>();
  545. foreach (var date in teachtingTime)
  546. {
  547. if (!DateTime.TryParse(date, out Date))
  548. {
  549. errorMsgStr += "上课时间格式不正确;";
  550. en.ErrorMessage = errorMsgStr;
  551. isHaveNoInputValue = true;
  552. break;
  553. }
  554. else
  555. {
  556. en.Time.Add(date);
  557. if (dth.ToDateTimeValue(date) != string.Empty)
  558. {
  559. Date = Convert.ToDateTime(dth.ToDateTimeValue(date));
  560. }
  561. else
  562. {
  563. Date = Convert.ToDateTime(date);
  564. }
  565. if (missionClassYear != null && en.CourseTimeID != null)
  566. {
  567. var isok = EducationScheduleList.Where(x => x.ScheduleDate == Date && x.ClassroomID == en.ClassroomID && x.CoursesTimeID == en.CourseTimeID && x.EM_EducationSchedulingClass.EducationMissionClassID != missionClassYear.EducationMissionClassID).ToList();
  568. if (isok.Count() != 0)
  569. {
  570. errorMsgStr += "该教室在该时间段已被使用;";
  571. en.ErrorMessage = errorMsgStr;
  572. isHaveNoInputValue = true;
  573. break;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. if (!en.TeachingTime.Contains("月"))
  580. {
  581. errorMsgStr += "上课时间格式不正确;";
  582. en.ErrorMessage = errorMsgStr;
  583. isHaveNoInputValue = true;
  584. }
  585. if (en.TeachingTime.Contains(",") && en.TeachingTime.Contains(","))
  586. {
  587. errorMsgStr += "上课时间分割月份的逗号只能选择中文或英文逗号的一种;";
  588. en.ErrorMessage = errorMsgStr;
  589. isHaveNoInputValue = true;
  590. }
  591. }
  592. #endregion
  593. #region 授课教师
  594. if (!string.IsNullOrEmpty(en.TeacherNameString))
  595. {
  596. List<Guid> userID=new List<Guid>();
  597. string[] TName=null;
  598. if (en.TeacherNameString.Contains("\\"))
  599. {
  600. TName = en.TeacherNameString.Split('\\');
  601. }
  602. if(TName!=null){
  603. var teacher = teacherList.Where(x => TName.Contains(x.Sys_User.Name)).Select(x=>x.UserID).ToList();
  604. userID=teacher;
  605. if(teacher.Count()!=TName.Count())
  606. {
  607. errorMsgStr += "授课教师不存在;";
  608. en.ErrorMessage = errorMsgStr;
  609. isHaveNoInputValue = true;
  610. }
  611. en.UserID=userID.Distinct().ToList();
  612. }
  613. else
  614. {
  615. userID = teacherList.Where(x=>x.Sys_User.Name==en.TeacherNameString).Select(w => w.UserID).ToList();
  616. if(userID.Count==0){
  617. errorMsgStr += "授课教师不存在;";
  618. en.ErrorMessage = errorMsgStr;
  619. isHaveNoInputValue = true;
  620. }
  621. DateTime date;
  622. if(en.Time!=null){
  623. foreach(var datetime in en.Time){
  624. if (dth.ToDateTimeValue(datetime) != string.Empty){
  625. date=Convert.ToDateTime(dth.ToDateTimeValue(datetime));
  626. }
  627. else
  628. {
  629. date = Convert.ToDateTime(datetime);
  630. }
  631. if(userID.Count!=0){
  632. if (en.CourseTimeID != null && en.ClassroomID == Guid.Empty)
  633. {
  634. foreach(var staffid in userID){
  635. var staffOnWork = EducationMissionClassSchedulingASdultDAL.CheckTeacherIsOnWork(x => x.CoursesTimeID == en.CourseTimeID && x.ScheduleDate == date, w => w.UserID == staffid).Select(x => x.AdultUserId).FirstOrDefault();
  636. if(staffOnWork==null){
  637. errorMsgStr += "授课教师在"+date.Month+"月"+date.Day+"日已有排课安排;";
  638. en.ErrorMessage = errorMsgStr;
  639. isHaveNoInputValue = true;
  640. break;
  641. }
  642. }
  643. }
  644. }
  645. }
  646. }
  647. en.UserID = userID.Distinct().ToList();
  648. }
  649. }
  650. #endregion
  651. #region 考试周次
  652. if (!string.IsNullOrEmpty(en.ExamWeek))
  653. {
  654. int isok = 0;
  655. List<string> week = en.ExamWeek.Split('\\').ToList();
  656. List<int?> weeks = new List<int?>();
  657. if (week!=null)
  658. {
  659. for (int w = 0; w < week.Count(); w++)
  660. {
  661. if (int.TryParse(week[w], out isok))
  662. {
  663. int day = Convert.ToInt32(week[w]);
  664. var weeknum = school;
  665. if (day > weeknum.WeeksNum || day < 0)
  666. {
  667. errorMsgStr += "考试周次输入的格式不正确;";
  668. en.ErrorMessage = errorMsgStr;
  669. isHaveNoInputValue = true;
  670. }
  671. else
  672. {
  673. weeks.Add(day);
  674. }
  675. }
  676. else
  677. {
  678. errorMsgStr += "考试周次输入的格式不正确;";
  679. en.ErrorMessage = errorMsgStr;
  680. isHaveNoInputValue = true;
  681. }
  682. }
  683. en.ExaWeek = weeks;
  684. }
  685. }
  686. #endregion
  687. #region 考试时间
  688. if(!string.IsNullOrEmpty(en.ExamTime)){
  689. List<string> year = en.ExamTime.Split('日').ToList();
  690. if (year.Count == 2)
  691. {
  692. List<string> times = year[1].Trim().Split('-').ToList();
  693. if (times.Count == 2)
  694. {
  695. DateTime date;
  696. TimeSpan timespan;
  697. string years = year[0] + "日";
  698. if (DateTime.TryParse(years, out date))
  699. {
  700. en.ExamDate = Convert.ToDateTime(years);
  701. }
  702. else
  703. {
  704. errorMsgStr += "考试时间输入的格式不正确;";
  705. en.ErrorMessage = errorMsgStr;
  706. isHaveNoInputValue = true;
  707. }
  708. List<string> Star = times[0].Split(':').ToList();
  709. if (Star.Count() == 2)
  710. {
  711. int isok = 0;
  712. if (int.TryParse(Star[0], out isok) && int.TryParse(Star[1], out isok))
  713. {
  714. timespan = new TimeSpan(Convert.ToInt32(Star[0]), Convert.ToInt32(Star[1]), 0);
  715. en.StarTime = timespan;
  716. }
  717. else
  718. {
  719. errorMsgStr += "考试时间输入的格式不正确;";
  720. en.ErrorMessage = errorMsgStr;
  721. isHaveNoInputValue = true;
  722. }
  723. }
  724. else
  725. {
  726. errorMsgStr += "考试时间输入的格式不正确;";
  727. en.ErrorMessage = errorMsgStr;
  728. isHaveNoInputValue = true;
  729. }
  730. List<string> end=times[1].Split(':').ToList();
  731. if(end.Count()==2){
  732. int isok = 0;
  733. if (int.TryParse(end[0], out isok) && int.TryParse(end[1], out isok))
  734. {
  735. timespan = new TimeSpan(Convert.ToInt32(end[0]), Convert.ToInt32(end[1]), 0);
  736. en.EndTime = timespan;
  737. }
  738. else
  739. {
  740. errorMsgStr += "考试时间输入的格式不正确;";
  741. en.ErrorMessage = errorMsgStr;
  742. isHaveNoInputValue = true;
  743. }
  744. }
  745. else
  746. {
  747. errorMsgStr += "考试时间输入的格式不正确;";
  748. en.ErrorMessage = errorMsgStr;
  749. isHaveNoInputValue = true;
  750. }
  751. }
  752. else
  753. {
  754. errorMsgStr += "考试时间输入的格式不正确;";
  755. en.ErrorMessage = errorMsgStr;
  756. isHaveNoInputValue = true;
  757. }
  758. }
  759. else
  760. {
  761. errorMsgStr += "考试时间输入的格式不正确;";
  762. en.ErrorMessage = errorMsgStr;
  763. isHaveNoInputValue = true;
  764. }
  765. }
  766. for (int j = i + 1; j < enlist.Count; j++)
  767. {
  768. EducationMissionImportClassView enB = enlist[j];
  769. // 判断必填列是否全部重复
  770. if (
  771. !string.IsNullOrEmpty(en.Name) && !string.IsNullOrEmpty(enB.Name)&&
  772. !string.IsNullOrEmpty(en.TeachingTime) && !string.IsNullOrEmpty(enB.TeachingTime) &&
  773. !string.IsNullOrEmpty(en.ClassroomName) && !string.IsNullOrEmpty(enB.ClassroomName) &&
  774. !string.IsNullOrEmpty(en.CourseTime) && !string.IsNullOrEmpty(enB.CourseTime)
  775. )
  776. {
  777. if (
  778. en.Name == enB.Name&&
  779. en.TeachingTime==enB.TeachingTime&&
  780. en.ClassroomName == enB.ClassroomName
  781. )
  782. {
  783. isHaveNoInputValue = true;
  784. errorMsgStr += "第" + (i + 2) + "行与第" + (j + 2) + "行的必填列重复了";
  785. en.ErrorMessage = errorMsgStr;
  786. }
  787. if (
  788. en.Name == enB.Name &&
  789. en.CourseTime != enB.CourseTime
  790. )
  791. {
  792. isHaveNoInputValue = true;
  793. errorMsgStr += "第" + (i + 2) + "行与第" + (j + 2) + "行的课时类别不同";
  794. en.ErrorMessage = errorMsgStr;
  795. }
  796. }
  797. if (!string.IsNullOrEmpty(en.TeachingTime) && !string.IsNullOrEmpty(enB.TeachingTime) && !string.IsNullOrEmpty(en.ClassroomName) && !string.IsNullOrEmpty(enB.ClassroomName))
  798. {
  799. if (en.TeachingTime.Contains("月") && enB.TeachingTime.Contains("月"))
  800. {
  801. string[] TName = en.TeacherNameString.Split('\\');
  802. List<string> TimesSegment = en.TeachingTime.Split(',').ToList();
  803. List<string> TimesSegmentB = enB.TeachingTime.Split(',').ToList();
  804. List<string> teachtingTimeA = new List<string>();
  805. for (int t = 0; t < TimesSegment.Count(); t++)
  806. {
  807. List<string> month = TimesSegment[t].Split('月').ToList();
  808. for (int m = 1; m < month.Count(); m++)
  809. {
  810. List<string> day = month[m].Split('、').ToList();
  811. for (int d = 0; d < day.Count(); d++)
  812. {
  813. teachtingTimeA.Add(month[0] + "月");
  814. int index = teachtingTimeA.Count() - 1;
  815. teachtingTimeA[index] += day[d];
  816. }
  817. }
  818. }
  819. List<string> teachtingTimeB = new List<string>();
  820. for (int t = 0; t < TimesSegmentB.Count(); t++)
  821. {
  822. List<string> month = TimesSegmentB[t].Split('月').ToList();
  823. for (int m = 1; m < month.Count(); m++)
  824. {
  825. List<string> day = month[m].Split('、').ToList();
  826. for (int d = 0; d < day.Count(); d++)
  827. {
  828. teachtingTimeB.Add(month[0] + "月");
  829. int index = teachtingTimeB.Count() - 1;
  830. teachtingTimeB[index] += day[d];
  831. }
  832. }
  833. }
  834. for (int c = 0; c < TimesSegmentB.Count(); c++)
  835. {
  836. foreach (var n in TName)
  837. {
  838. if (enB.TeacherNameString.Contains(n) && teachtingTimeA.Contains(teachtingTimeB[c]) && en.CourseTime == enB.CourseTime)
  839. {
  840. isHaveNoInputValue = true;
  841. errorMsgStr += "第" + (i + 2) + "行与第" + (j + 2) + "行的同一个老师在同一天同一个时间段内有不同的安排";
  842. break;
  843. }
  844. }
  845. if (teachtingTimeA.Contains(teachtingTimeB[c]) && en.ClassroomName == enB.ClassroomName && en.CourseTime == enB.CourseTime)
  846. {
  847. isHaveNoInputValue = true;
  848. errorMsgStr += "第" + (i + 2) + "行与第" + (j + 2) + "行的同一个教室在同一天同一个时间段内有不同的安排";
  849. break;
  850. }
  851. }
  852. }
  853. }
  854. }
  855. #endregion
  856. #endregion
  857. if (isHaveNoInputValue) // 若必填项有值未填
  858. {
  859. en.IsExcelVaildateOK = false;
  860. en.ErrorMessage = errorMsgStr;
  861. errList.Add(en);
  862. errorMsg.AppendLine(errorMsgStr);
  863. }
  864. }
  865. #endregion
  866. // TODO:其他检测
  867. #region 1.2.1.3 循环写入验证成功的数据
  868. List<EducationMissionImportClassView> className = new List<EducationMissionImportClassView>();
  869. for (int i = 0; i < enlist.Count; i++)
  870. {
  871. EducationMissionImportClassView enA = enlist[i];
  872. enA.OrderNo = i;
  873. if (enA.IsExcelVaildateOK == false) // 上面验证不通过,不进行此步验证
  874. {
  875. continue;
  876. }
  877. for (int j = i + 1; j < enlist.Count; j++)
  878. {
  879. EducationMissionImportClassView enB = enlist[j];
  880. // 判断必填列是否全部重复
  881. if (
  882. !string.IsNullOrEmpty(enA.Name) && !string.IsNullOrEmpty(enB.Name)
  883. )
  884. {
  885. if (
  886. enA.Name == enB.Name
  887. )
  888. {
  889. className.Add(enA);
  890. }
  891. }
  892. }
  893. try
  894. {
  895. var educationMissionClass = missionClassList.Where(x => x.Name == enA.Name).FirstOrDefault(); //educationMissionClassDAL.GetEducationMissionClassViewQueryble(x => x.Name == enA.Name && x.EM_EducationMission.SchoolyearID == schoolyear, w => true, c => true, a => true).FirstOrDefault();
  896. var classrommId = ClassroomName.Where(x => x.Name == enA.ClassroomName).FirstOrDefault();
  897. var educationMissionClassID = educationMissionClass.EducationMissionClassID;
  898. List<Guid> educationSchedulingClassID = educationSchedulingClassIDList.Where(x => x.EducationMissionClassID == educationMissionClassID).Select(w=>w.EducationSchedulingClassID).ToList();
  899. var e = className.OrderBy(w => w.OrderNo).Where(x => x.Name == enA.Name).FirstOrDefault();
  900. int errornums = 0;
  901. foreach(var edID in educationSchedulingClassID){
  902. if (errornums==0)
  903. {
  904. foreach(var datetime in enA.Time){
  905. DateTime t = Convert.ToDateTime(datetime);
  906. var studentQuery = this.EducationSchedulingClassDAL.GetStudentQueryable(x => x.EducationSchedulingClassID == edID);
  907. var studentIsBusy = (from es in adultEducationScheduleRepository.GetList(
  908. x => x.SchoolyearID == schoolyear && x.EducationSchedulingClassID != edID)
  909. from s in es.EM_EducationSchedulingClass.CF_Student
  910. .Join(studentQuery, (x => x.UserID), (x => x.UserID), (x, y) => x)
  911. where es.ScheduleDate == t && es.CoursesTimeID == enA.CourseTimeID
  912. select s).Include(x => x.Sys_User).ToList();
  913. if (studentIsBusy.Count > 0)
  914. {
  915. errornums = studentIsBusy.Count;
  916. enA.ErrorMessage += "部分学生在"+t.Month+"月"+t.Day+"日有课,不能上课;";
  917. errList.Add(enA);
  918. break;
  919. }
  920. }
  921. }
  922. List<Guid> adultEducationScheduleID = EducationScheduleList.Where(x => x.EducationSchedulingClassID == edID).Select(w => w.AdultEducationScheduleID).ToList();
  923. if (e==null)
  924. {
  925. if (adultEducationScheduleID.Count() != 0 && errornums == 0)
  926. {
  927. //先删除旧数据、重新创建新数据
  928. UnitOfWork.Delete<EM_EducationMissionExamTime>(x => x.EducationMissionID == educationMissionClass.EducationMissionID);
  929. UnitOfWork.Delete<EM_MissionClassTeacher>(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
  930. UnitOfWork.Delete<EM_EducationMissionExamWeekNum>(x => x.EducationMissionID == educationMissionClass.EducationMissionID);
  931. UnitOfWork.Delete<ES_AdultEducationScheduleTeacher>(x => adultEducationScheduleID.Contains((Guid)x.AdultEducationScheduleID));
  932. UnitOfWork.Delete<ES_AdultEducationSchedule>(x => educationSchedulingClassID.Contains((Guid)x.EducationSchedulingClassID));
  933. }
  934. if (educationMissionClass.EM_MissionClassTeacher.Count > 0)
  935. {
  936. UnitOfWork.Delete<EM_MissionClassTeacher>(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
  937. }
  938. }
  939. else
  940. {
  941. if(e.OrderNo==enA.OrderNo){
  942. if (adultEducationScheduleID.Count() != 0 && errornums == 0)
  943. {
  944. //先删除旧数据、重新创建新数据
  945. UnitOfWork.Delete<EM_EducationMissionExamTime>(x => x.EducationMissionID == educationMissionClass.EducationMissionID);
  946. UnitOfWork.Delete<EM_MissionClassTeacher>(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
  947. UnitOfWork.Delete<EM_EducationMissionExamWeekNum>(x => x.EducationMissionID == educationMissionClass.EducationMissionID);
  948. UnitOfWork.Delete<ES_AdultEducationScheduleTeacher>(x => adultEducationScheduleID.Contains((Guid)x.AdultEducationScheduleID));
  949. UnitOfWork.Delete<ES_AdultEducationSchedule>(x => educationSchedulingClassID.Contains((Guid)x.EducationSchedulingClassID));
  950. }
  951. if (educationMissionClass.EM_MissionClassTeacher.Count > 0)
  952. {
  953. UnitOfWork.Delete<EM_MissionClassTeacher>(x => x.MissionClassID == educationMissionClass.EducationMissionClassID);
  954. }
  955. }
  956. }
  957. }
  958. if (enA != null&&errornums==0) //有数据开始组装数据
  959. {
  960. if(enA.CourseTimeID!=null){
  961. EM_CoursesTime c =coursesTimeRepository.Entities.Where(x=>x.CoursesTimeID==(Guid)enA.CourseTimeID).FirstOrDefault();
  962. if(c!=null){
  963. EM_EducationMissionClass ec = new EM_EducationMissionClass();
  964. ec = educationMissionClass;
  965. ec.ClassroomID = enA.ClassroomID;
  966. ec.EM_CoursesTime = new HashSet<EM_CoursesTime>();
  967. ec.EM_CoursesTime.Add(c);
  968. this.SetNewStatus(ec);
  969. ec.RecordStatus = (int)EMIS.ViewModel.EM_EducationMissionClassStatus.Scheduled;
  970. UnitOfWork.Update(ec);
  971. }
  972. }
  973. if (enA.ExamDate!=null&&enA.EndTime!=null&&enA.StarTime != null)
  974. {
  975. if (e == null)
  976. {
  977. EM_EducationMissionExamTime Examtime = new EM_EducationMissionExamTime();
  978. Examtime.EducationMissionExamTimeID = Guid.NewGuid();
  979. Examtime.EducationMissionID = educationMissionClass.EducationMissionID;
  980. if (enA.ExamDate.ToLongDateString().ToString() == "0001年1月1日")
  981. {
  982. Examtime.ExamDate = null;
  983. Examtime.StartTime = null;
  984. Examtime.EndTime = null;
  985. }
  986. else
  987. {
  988. Examtime.ExamDate = enA.ExamDate;
  989. TimeSpan tt = new TimeSpan(enA.ExamDate.Hour, enA.ExamDate.Minute, enA.ExamDate.Second);
  990. Examtime.StartTime = enA.StarTime;
  991. Examtime.EndTime = enA.EndTime;
  992. }
  993. this.SetNewStatus(Examtime);
  994. UnitOfWork.Add(Examtime);
  995. }
  996. else
  997. {
  998. if (e.OrderNo == enA.OrderNo)
  999. {
  1000. EM_EducationMissionExamTime Examtime = new EM_EducationMissionExamTime();
  1001. Examtime.EducationMissionExamTimeID = Guid.NewGuid();
  1002. Examtime.EducationMissionID = educationMissionClass.EducationMissionID;
  1003. if (enA.ExamDate.ToLongDateString().ToString() == "0001年1月1日")
  1004. {
  1005. Examtime.ExamDate = null;
  1006. Examtime.StartTime = null;
  1007. Examtime.EndTime = null;
  1008. }
  1009. else
  1010. {
  1011. Examtime.ExamDate = enA.ExamDate;
  1012. TimeSpan tt = new TimeSpan(enA.ExamDate.Hour, enA.ExamDate.Minute, enA.ExamDate.Second);
  1013. Examtime.StartTime = enA.StarTime;
  1014. Examtime.EndTime = enA.EndTime;
  1015. }
  1016. this.SetNewStatus(Examtime);
  1017. UnitOfWork.Add(Examtime);
  1018. }
  1019. }
  1020. }
  1021. if(enA.ExaWeek!=null){
  1022. if (e == null)
  1023. {
  1024. foreach (var week in enA.ExaWeek)
  1025. {
  1026. EM_EducationMissionExamWeekNum ExamWeekNum = new EM_EducationMissionExamWeekNum();
  1027. ExamWeekNum.EducationMissionExamWeekNumID = Guid.NewGuid();
  1028. ExamWeekNum.EducationMissionID = educationMissionClass.EducationMissionID;
  1029. ExamWeekNum.WeeklyNum = week;
  1030. this.SetNewStatus(ExamWeekNum);
  1031. UnitOfWork.Add(ExamWeekNum);
  1032. }
  1033. }
  1034. else
  1035. {
  1036. if (e.OrderNo == enA.OrderNo)
  1037. {
  1038. foreach (var week in enA.ExaWeek)
  1039. {
  1040. EM_EducationMissionExamWeekNum ExamWeekNum = new EM_EducationMissionExamWeekNum();
  1041. ExamWeekNum.EducationMissionExamWeekNumID = Guid.NewGuid();
  1042. ExamWeekNum.EducationMissionID = educationMissionClass.EducationMissionID;
  1043. ExamWeekNum.WeeklyNum = week;
  1044. this.SetNewStatus(ExamWeekNum);
  1045. UnitOfWork.Add(ExamWeekNum);
  1046. }
  1047. }
  1048. }
  1049. }
  1050. foreach(var staffID in enA.UserID){
  1051. UnitOfWork.Delete<EM_MissionClassTeacher>(x => x.MissionClassID == educationMissionClass.EducationMissionClassID && x.UserID == staffID);
  1052. EM_MissionClassTeacher teacher = new EM_MissionClassTeacher();
  1053. teacher.MissionClassTeacherID = Guid.NewGuid();
  1054. teacher.MissionClassID = educationMissionClass.EducationMissionClassID;
  1055. teacher.UserID = staffID;
  1056. teacher.TeachType = (int?)EM_TeachingMethod.Lecturer;
  1057. this.SetNewStatus(teacher);
  1058. UnitOfWork.Add(teacher);
  1059. }
  1060. foreach (var schedulingClass in educationSchedulingClassID)
  1061. {
  1062. foreach (var times in enA.Time)
  1063. {
  1064. ES_AdultEducationSchedule EducationScheduling = new ES_AdultEducationSchedule();
  1065. EducationScheduling.AdultEducationScheduleID = Guid.NewGuid();
  1066. EducationScheduling.EducationSchedulingClassID = schedulingClass;
  1067. EducationScheduling.ClassroomID = enA.ClassroomID;
  1068. EducationScheduling.SchoolyearID = schoolyear;
  1069. EducationScheduling.CoursesTimeID = enA.CourseTimeID;
  1070. if (dth.ToDateTimeValue(times) != string.Empty)
  1071. EducationScheduling.ScheduleDate = Convert.ToDateTime(dth.ToDateTimeValue(times));
  1072. else
  1073. EducationScheduling.ScheduleDate = Convert.ToDateTime(times);
  1074. SetNewStatus(EducationScheduling);
  1075. UnitOfWork.Add(EducationScheduling);
  1076. if (enA.UserID != null)
  1077. {
  1078. foreach (var user in enA.UserID)
  1079. {
  1080. ES_AdultEducationScheduleTeacher EducationSchedulingTeacher = new ES_AdultEducationScheduleTeacher();
  1081. EducationSchedulingTeacher.AdultEducationScheduleTeacherID = Guid.NewGuid();
  1082. EducationSchedulingTeacher.AdultEducationScheduleID = EducationScheduling.AdultEducationScheduleID;
  1083. EducationSchedulingTeacher.UserID = user;
  1084. EducationSchedulingTeacher.TeachingMethod = (int?)EM_TeachingMethod.Lecturer;
  1085. SetNewStatus(EducationSchedulingTeacher);
  1086. UnitOfWork.Add(EducationSchedulingTeacher);
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. UnitOfWork.Commit();
  1093. }
  1094. catch (Exception)
  1095. {
  1096. throw;
  1097. }
  1098. }
  1099. #endregion
  1100. #endregion
  1101. #endregion
  1102. #region 1.3 返回各项数据值
  1103. errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "教学任务课程安排操作失败文件", sourceWebPath));
  1104. successCount = enlist.Distinct().Count() - errList.Distinct().Count();//共条数减去失败条数
  1105. errdataList = errList.Distinct().ToList();
  1106. OkCount = errList.Distinct().Count();
  1107. Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", successCount < 1 ? 0 : successCount, OkCount < 1 ? 0 : OkCount);
  1108. #endregion
  1109. }
  1110. }
  1111. }