OptionalCoursePlanServices.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.DataLogic.CultureplanManage.PlanManagement;
  9. using EMIS.ViewModel.SelectCourse;
  10. using EMIS.ViewModel;
  11. using EMIS.Entities;
  12. using EMIS.ViewModel.CultureplanManage.PlanManagement;
  13. using EMIS.CommonLogic.CalendarManage;
  14. using EMIS.ViewModel.UniversityManage.SpecialtyClassManage;
  15. using Bowin.Common.DataTime;
  16. using Bowin.Common.Utility;
  17. using System.Text.RegularExpressions;
  18. using EMIS.ViewModel.CacheManage;
  19. using EMIS.DataLogic.UniversityManage.AdministrativeOrgan;
  20. using EMIS.DataLogic.Common.Cultureplan;
  21. using EMIS.DataLogic.Repositories;
  22. using EMIS.CommonLogic.UniversityManage.SpecialtyClassManage;
  23. namespace EMIS.CommonLogic.CultureplanManage.PlanManagement
  24. {
  25. public class OptionalCoursePlanServices : BaseServices, IOptionalCoursePlanServices
  26. {
  27. public OptionalCoursePlanDAL OptionalCoursePlanDAL { get; set; }
  28. public IGrademajorServices grademajorServices { get; set; }
  29. public IFacultymajorServices facultymajorServices { get; set; }
  30. public ISchoolYearServices schoolYearServices { get; set; }
  31. public ISpecialtyCourseServices specialtyCourseServices { get; set; }
  32. public DepartmentDAL departmentDAL { get; set; }
  33. public CoursematerialDAL coursematerialDAL { get; set; }
  34. public OptionalCoursePlanTeachingSettingRepository optionalCoursePlanTeachingSettingRepository { get; set; }
  35. /// <summary>
  36. /// 查询限选计划
  37. /// </summary>
  38. /// <param name="configuretView"></param>
  39. /// <param name="standardID"></param>
  40. /// <param name="coursematerialID"></param>
  41. /// <param name="startYearID"></param>
  42. /// <param name="schoolcodeID"></param>
  43. /// <param name="isEnable"></param>
  44. /// <param name="isOpened"></param>
  45. /// <param name="pageIndex"></param>
  46. /// <param name="pageSize"></param>
  47. /// <returns></returns>
  48. public IGridResultSet<OptionalCoursePlanView> GetOptionalCourseSettingViewGrid(ConfiguretView configuretView, int? standardID, Guid? coursematerialID, int? schoolYearNumID, int? schoolCodeID, int? isEnable, int? isOpened, int? educationID, int? learningFormID, string LearnSystem, int pageIndex, int pageSize)
  49. {
  50. Expression<Func<EM_OptionalCoursePlan, bool>> exp = (x => true);
  51. var query = OptionalCoursePlanDAL.GetOptionalCourseSettingViewQueryable(exp);
  52. if (standardID.HasValue)
  53. query = query.Where(x => x.StandardID == standardID);
  54. if (coursematerialID.HasValue)
  55. query = query.Where(x => x.CoursematerialID == coursematerialID);
  56. if (schoolYearNumID.HasValue)
  57. query = query.Where(x => x.SchoolyearNumID == schoolYearNumID);
  58. if (schoolCodeID.HasValue)
  59. query = query.Where(x => x.SchoolcodeID == schoolCodeID);
  60. if (isEnable.HasValue)
  61. query = query.Where(x => x.IsEnable == (isEnable == 1 ? true : false));
  62. if (isOpened.HasValue)
  63. query = query.Where(x => x.IsOpened == (isOpened == 1 ? true : false));
  64. if (educationID.HasValue)
  65. query = query.Where(x => x.EducationID == educationID);
  66. if (learningFormID.HasValue)
  67. query = query.Where(x => x.LearningformID == learningFormID);
  68. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  69. {
  70. var LearnSystems = Convert.ToDecimal(LearnSystem);
  71. query = query.Where(x => x.LearnSystem == LearnSystems);
  72. }
  73. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  74. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  75. //var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x=>x.CollegeID).ToGridResultSet<OptionalCoursePlanView>(pageIndex, pageSize);
  76. var result = query.OrderBy(x => x.IsEnable).ThenByDescending(x => x.StandardCode).ThenBy(x => x.SchoolyearNumID).ThenBy(x => x.SchoolcodeID).ThenBy(x => x.CourseCode).ToGridResultSet<OptionalCoursePlanView>(pageIndex, pageSize);
  77. //return this.GetOptionalCourseSettingView(configuretView, exp, pageIndex, pageSize);
  78. return result;
  79. }
  80. public List<OptionalCoursePlanView> GetOptionalCourseSettingViewList(ConfiguretView configuretView, int? standardID, Guid? coursematerialID, int? schoolYearNumID, int? schoolCodeID, int? isEnable, int? isOpened, int? educationID, int? learningFormID, string LearnSystem)
  81. {
  82. Expression<Func<EM_OptionalCoursePlan, bool>> exp = (x => true);
  83. var query = OptionalCoursePlanDAL.GetOptionalCourseSettingViewQueryable(exp);
  84. if (standardID.HasValue)
  85. query = query.Where(x => x.StandardID == standardID);
  86. if (coursematerialID.HasValue)
  87. query = query.Where(x => x.CoursematerialID == coursematerialID);
  88. if (schoolYearNumID.HasValue)
  89. query = query.Where(x => x.SchoolyearNumID == schoolYearNumID);
  90. if (schoolCodeID.HasValue)
  91. query = query.Where(x => x.SchoolcodeID == schoolCodeID);
  92. if (isEnable.HasValue)
  93. query = query.Where(x => x.IsEnable == (isEnable == 1 ? true : false));
  94. if (isOpened.HasValue)
  95. query = query.Where(x => x.IsOpened == (isOpened == 1 ? true : false));
  96. if (educationID.HasValue)
  97. query = query.Where(x => x.EducationID == educationID);
  98. if (learningFormID.HasValue)
  99. query = query.Where(x => x.LearningformID == learningFormID);
  100. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  101. {
  102. var LearnSystems = Convert.ToDecimal(LearnSystem);
  103. query = query.Where(x => x.LearnSystem == LearnSystems);
  104. }
  105. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  106. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  107. //var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x=>x.CollegeID).ToGridResultSet<OptionalCoursePlanView>(pageIndex, pageSize);
  108. var result = query.OrderByDescending(x => x.StandardCode).ThenBy(x => x.SchoolyearNumID).ThenBy(x => x.SchoolcodeID).ThenBy(x => x.CourseCode).ToList();
  109. //return this.GetOptionalCourseSettingView(configuretView, exp, pageIndex, pageSize);
  110. return result;
  111. }
  112. /// <summary>
  113. /// 获取选修计划视图
  114. /// </summary>
  115. /// <param name="optionalCourseID"></param>
  116. /// <returns></returns>
  117. public OptionalCoursePlanView GetOptionalCourseSettingView(Guid? optionalCourseID)
  118. {
  119. return OptionalCoursePlanDAL.GetOptionalCourseSettingViewQueryable(x => x.OptionalCourseID == optionalCourseID).FirstOrDefault();
  120. }
  121. /// <summary>
  122. /// 添加选修计划
  123. /// </summary>
  124. /// <param name="optionalCourseSettingView"></param>
  125. /// <returns></returns>
  126. public void OptionalCourseAdd(OptionalCoursePlanView optionalCourseSettingView)
  127. {
  128. try
  129. {
  130. var repeatOptionalCoursePlan = OptionalCoursePlanDAL.OptionalCoursePlanRepository.Entities.Where(x =>
  131. x.CoursematerialID == optionalCourseSettingView.CoursematerialID &&
  132. x.CourseTypeID == optionalCourseSettingView.CourseTypeID &&
  133. x.SchoolcodeID == optionalCourseSettingView.SchoolcodeID &&
  134. x.SchoolyearNumID == optionalCourseSettingView.SchoolyearNumID &&
  135. x.SpecialtyID == optionalCourseSettingView.SpecialtyID).FirstOrDefault();
  136. if (repeatOptionalCoursePlan != null)
  137. { //同专业同学期同课程类型同课程ID是否有重复
  138. throw new Exception("已存在相同的限选计划,请核查。");
  139. }
  140. EM_OptionalCoursePlan optionalCoursePlan = new EM_OptionalCoursePlan();
  141. optionalCoursePlan.OptionalCourseID = Guid.NewGuid();
  142. optionalCoursePlan.DepartmentID = optionalCourseSettingView.DepartmentID;
  143. optionalCoursePlan.SpecialtyID = optionalCourseSettingView.SpecialtyID;
  144. optionalCoursePlan.CoursematerialID = optionalCourseSettingView.CoursematerialID;
  145. optionalCoursePlan.CourseStructureID = optionalCourseSettingView.CourseStructureID;
  146. optionalCoursePlan.CourseCategoryID = optionalCourseSettingView.CourseCategoryID;
  147. optionalCoursePlan.CourseTypeID = optionalCourseSettingView.CourseTypeID;
  148. optionalCoursePlan.CourseQualityID = optionalCourseSettingView.CourseQualityID;
  149. optionalCoursePlan.PracticeTypeID = optionalCourseSettingView.PracticeTypeID;
  150. optionalCoursePlan.ExaminationModeID = optionalCourseSettingView.ExaminationModeID;
  151. optionalCoursePlan.TeachinglanguageID = optionalCourseSettingView.TeachinglanguageID;
  152. optionalCoursePlan.SchoolyearNumID = optionalCourseSettingView.SchoolyearNumID;
  153. optionalCoursePlan.SchoolcodeID = optionalCourseSettingView.SchoolcodeID;
  154. optionalCoursePlan.IsEnable = optionalCourseSettingView.IsEnable;
  155. optionalCoursePlan.PeopleNumlower = optionalCourseSettingView.PeopleNumlower;
  156. optionalCoursePlan.PeopleNumlimit = optionalCourseSettingView.PeopleNumlimit;
  157. optionalCoursePlan.IsOpened = optionalCourseSettingView.IsOpened;
  158. optionalCoursePlan.ResultTypeID = optionalCourseSettingView.ResultTypeID;
  159. optionalCoursePlan.Remarks = optionalCourseSettingView.Remarks;
  160. SetNewStatus(optionalCoursePlan);
  161. UnitOfWork.Add(optionalCoursePlan);
  162. EM_OptionalCoursePlanTeachingSetting optionalCourseTeachingSetting = new EM_OptionalCoursePlanTeachingSetting();
  163. //教学设置表
  164. optionalCourseTeachingSetting.OptionalCourseID = optionalCoursePlan.OptionalCourseID;
  165. optionalCourseTeachingSetting.Credit = optionalCourseSettingView.Credit;
  166. optionalCourseTeachingSetting.TheoryCourse = optionalCourseSettingView.TheoryCourse;
  167. optionalCourseTeachingSetting.Practicehours = optionalCourseSettingView.Practicehours;
  168. optionalCourseTeachingSetting.Trialhours = optionalCourseSettingView.Trialhours;
  169. optionalCourseTeachingSetting.WeeklyNum = optionalCourseSettingView.WeeklyNum;
  170. //if (optionalCourseSettingView.WeeklyNum == 0 || optionalCourseSettingView.WeeklyNum == null)
  171. //{
  172. // var t = (optionalCourseSettingView.TheoryCourse.Value + optionalCourseSettingView.Practicehours.Value);
  173. // var w = (optionalCourseSettingView.TheoryWeeklyNum.Value + optionalCourseSettingView.PracticeWeeklyNum.Value);
  174. // if (w != 0 && t != 0)
  175. // optionalCourseTeachingSetting.WeeklyNum = t / w / 2;
  176. //}
  177. optionalCourseTeachingSetting.TheoryWeeklyNum = optionalCourseSettingView.TheoryWeeklyNum;
  178. optionalCourseTeachingSetting.PracticeWeeklyNum = optionalCourseSettingView.PracticeWeeklyNum;
  179. optionalCourseTeachingSetting.TrialWeeklyNum = optionalCourseSettingView.TrialWeeklyNum;
  180. optionalCourseTeachingSetting.StartWeeklyNum = optionalCourseSettingView.StartWeeklyNum;
  181. optionalCourseTeachingSetting.EndWeeklyNum = optionalCourseSettingView.EndWeeklyNum;
  182. optionalCourseTeachingSetting.WeeklyHours = optionalCourseSettingView.WeeklyHours;
  183. UnitOfWork.Add(optionalCourseTeachingSetting);
  184. //授课方式
  185. if (optionalCourseSettingView.TeachingModeID != null)
  186. {
  187. //UnitOfWork.Delete<EM_OptionalCoursePlanTeachingMode>(x => x.OptionalCourseID == optionalCourseSettingView.OptionalCourseID);
  188. foreach (var i in optionalCourseSettingView.TeachingModeID)
  189. {
  190. EM_OptionalCoursePlanTeachingMode optionalCourseTeachingMode = new EM_OptionalCoursePlanTeachingMode();
  191. optionalCourseTeachingMode.OptionalCoursePlanTeachingModeID = Guid.NewGuid();
  192. optionalCourseTeachingMode.OptionalCourseID = optionalCoursePlan.OptionalCourseID;
  193. optionalCourseTeachingMode.TeachingModeID = i;
  194. SetNewStatus(optionalCourseTeachingMode);
  195. UnitOfWork.Add(optionalCourseTeachingMode);
  196. }
  197. }
  198. UnitOfWork.Commit();
  199. }
  200. catch (Exception)
  201. {
  202. throw;
  203. }
  204. }
  205. /// <summary>
  206. /// 更新
  207. /// </summary>
  208. /// <param name="optionalCourseSettingView"></param>
  209. /// <returns></returns>
  210. public void OptionalCourseUpdate(OptionalCoursePlanView optionalCourseSettingView)
  211. {
  212. try
  213. {
  214. var repeatOptionalCoursePlan = OptionalCoursePlanDAL.OptionalCoursePlanRepository.Entities.Where(x =>
  215. x.CoursematerialID == optionalCourseSettingView.CoursematerialID &&
  216. x.CourseTypeID == optionalCourseSettingView.CourseTypeID &&
  217. x.SchoolcodeID == optionalCourseSettingView.SchoolcodeID &&
  218. x.SchoolyearNumID == optionalCourseSettingView.SchoolyearNumID &&
  219. x.SpecialtyID == optionalCourseSettingView.SpecialtyID).FirstOrDefault();
  220. if (repeatOptionalCoursePlan != null && repeatOptionalCoursePlan.OptionalCourseID != optionalCourseSettingView.OptionalCourseID)
  221. { //同专业同学期同课程类型同课程ID是否有重复
  222. throw new Exception("已存在相同的限选计划,请核查。");
  223. }
  224. EM_OptionalCoursePlan optionalCoursePlan = GetOptionalCoursePlan(optionalCourseSettingView.OptionalCourseID);
  225. EM_OptionalCoursePlanTeachingSetting optionalCourseTeachingSetting = optionalCoursePlanTeachingSettingRepository.Entities.Where(x => x.OptionalCourseID == optionalCoursePlan.OptionalCourseID).SingleOrDefault();
  226. if (optionalCoursePlan != null)
  227. {
  228. optionalCoursePlan.DepartmentID = optionalCourseSettingView.DepartmentID;
  229. optionalCoursePlan.SpecialtyID = optionalCourseSettingView.SpecialtyID;
  230. optionalCoursePlan.CoursematerialID = optionalCourseSettingView.CoursematerialID;
  231. optionalCoursePlan.CourseStructureID = optionalCourseSettingView.CourseStructureID;
  232. optionalCoursePlan.CourseCategoryID = optionalCourseSettingView.CourseCategoryID;
  233. optionalCoursePlan.CourseTypeID = optionalCourseSettingView.CourseTypeID;
  234. optionalCoursePlan.CourseQualityID = optionalCourseSettingView.CourseQualityID;
  235. optionalCoursePlan.PracticeTypeID = optionalCourseSettingView.PracticeTypeID;
  236. optionalCoursePlan.ExaminationModeID = optionalCourseSettingView.ExaminationModeID;
  237. optionalCoursePlan.TeachinglanguageID = optionalCourseSettingView.TeachinglanguageID;
  238. optionalCoursePlan.SchoolyearNumID = optionalCourseSettingView.SchoolyearNumID;
  239. optionalCoursePlan.SchoolcodeID = optionalCourseSettingView.SchoolcodeID;
  240. optionalCoursePlan.IsEnable = optionalCourseSettingView.IsEnable;
  241. //optionalCoursePlan.No = optionalCourseSettingView.No;
  242. //optionalCoursePlan.HandleModeID = optionalCourseSettingView.HandleModeID;
  243. //optionalCoursePlan.IsNeedMaterial = optionalCourseSettingView.IsNeedMaterial;
  244. optionalCoursePlan.PeopleNumlower = optionalCourseSettingView.PeopleNumlower;
  245. optionalCoursePlan.PeopleNumlimit = optionalCourseSettingView.PeopleNumlimit;
  246. optionalCoursePlan.IsOpened = optionalCourseSettingView.IsOpened;
  247. optionalCoursePlan.ResultTypeID = optionalCourseSettingView.ResultTypeID;
  248. optionalCoursePlan.Remarks = optionalCourseSettingView.Remarks;
  249. //教学设置表
  250. if (optionalCourseTeachingSetting != null)
  251. {
  252. UnitOfWork.Update(optionalCourseTeachingSetting);
  253. }
  254. else
  255. {
  256. optionalCourseTeachingSetting = new EM_OptionalCoursePlanTeachingSetting();
  257. optionalCourseTeachingSetting.OptionalCourseID = optionalCourseSettingView.OptionalCourseID;
  258. UnitOfWork.Add(optionalCourseTeachingSetting);
  259. }
  260. optionalCourseTeachingSetting.Credit = optionalCourseSettingView.Credit;
  261. optionalCourseTeachingSetting.TheoryCourse = optionalCourseSettingView.TheoryCourse;
  262. optionalCourseTeachingSetting.Practicehours = optionalCourseSettingView.Practicehours;
  263. optionalCourseTeachingSetting.Trialhours = optionalCourseSettingView.Trialhours;
  264. optionalCourseTeachingSetting.WeeklyNum = optionalCourseSettingView.WeeklyNum;
  265. if (optionalCourseSettingView.WeeklyNum == 0 || optionalCourseSettingView.WeeklyNum == null)
  266. {
  267. var t = (optionalCourseSettingView.TheoryCourse.Value + optionalCourseSettingView.Practicehours.Value);
  268. var w = (optionalCourseSettingView.TheoryWeeklyNum.Value + optionalCourseSettingView.PracticeWeeklyNum.Value);
  269. if (w != 0 && t != 0)
  270. optionalCourseTeachingSetting.WeeklyNum = t / w / 2;
  271. }
  272. optionalCourseTeachingSetting.TheoryWeeklyNum = optionalCourseSettingView.TheoryWeeklyNum;
  273. optionalCourseTeachingSetting.PracticeWeeklyNum = optionalCourseSettingView.PracticeWeeklyNum;
  274. optionalCourseTeachingSetting.TrialWeeklyNum = optionalCourseSettingView.TrialWeeklyNum;
  275. optionalCourseTeachingSetting.StartWeeklyNum = optionalCourseSettingView.StartWeeklyNum;
  276. optionalCourseTeachingSetting.EndWeeklyNum = optionalCourseSettingView.EndWeeklyNum;
  277. optionalCourseTeachingSetting.WeeklyHours = optionalCourseSettingView.WeeklyHours;
  278. //授课方式
  279. if (optionalCourseSettingView.TeachingModeID != null)
  280. {
  281. UnitOfWork.Delete<EM_OptionalCoursePlanTeachingMode>(x => x.OptionalCourseID == optionalCourseSettingView.OptionalCourseID);
  282. foreach (var i in optionalCourseSettingView.TeachingModeID)
  283. {
  284. EM_OptionalCoursePlanTeachingMode optionalCourseTeachingMode = new EM_OptionalCoursePlanTeachingMode();
  285. optionalCourseTeachingMode.OptionalCoursePlanTeachingModeID = Guid.NewGuid();
  286. optionalCourseTeachingMode.OptionalCourseID = optionalCoursePlan.OptionalCourseID;
  287. optionalCourseTeachingMode.TeachingModeID = i;
  288. SetNewStatus(optionalCourseTeachingMode);
  289. UnitOfWork.Add(optionalCourseTeachingMode);
  290. }
  291. }
  292. this.SetModifyStatus(optionalCoursePlan);
  293. UnitOfWork.Commit();
  294. }
  295. }
  296. catch (Exception)
  297. {
  298. throw;
  299. }
  300. }
  301. public List<string> GetTeachingModeType(Guid? OptionalCourseID)
  302. {
  303. return OptionalCoursePlanDAL.GetTeachingModeTypeQueryble(OptionalCourseID);
  304. }
  305. /// <summary>
  306. /// 删除
  307. /// </summary>
  308. /// <param name="optionalCourseIDs"></param>
  309. /// <returns></returns>
  310. public bool OptionalCourseDelete(List<Guid> optionalCourseIDs)
  311. {
  312. try
  313. {
  314. if (optionalCourseIDs.Count > 0)
  315. {
  316. UnitOfWork.Delete<EM_OptionalCoursePlan>(x => optionalCourseIDs.Contains(x.OptionalCourseID));
  317. return true;
  318. }
  319. return false;
  320. }
  321. catch (Exception)
  322. {
  323. throw;
  324. }
  325. }
  326. /// <summary>
  327. /// 获取选修计划实体
  328. /// </summary>
  329. /// <param name="optionalCourseID"></param>
  330. /// <returns></returns>
  331. public EM_OptionalCoursePlan GetOptionalCoursePlan(Guid? optionalCourseID)
  332. {
  333. return OptionalCoursePlanDAL.OptionalCoursePlanRepository.GetSingle(x => x.OptionalCourseID == optionalCourseID);
  334. }
  335. //public void OptionalCoursePlanImport(Dictionary<string, string> cellheader, out int OkCount, out List<OptionalCoursePlanView> errdataList, out int ErrCount, string sourcePhysicalPath)
  336. //{
  337. // StringBuilder errorMsg = new StringBuilder(); // 错误信息
  338. // List<OptionalCoursePlanView> errList = new List<OptionalCoursePlanView>(); //错误数据行
  339. // DataTimeHelper dth = new DataTimeHelper();
  340. // Sys_DictionaryItem standardID = null; //专业
  341. // Sys_DictionaryItem educationID = null; //所修学历
  342. // Sys_DictionaryItem learningformID = null; //学习形式
  343. // #region 1.1解析文件,存放到一个List集合里
  344. // // 1.1解析文件,存放到一个List集合里
  345. // cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要
  346. // List<OptionalCoursePlanView> enlist =
  347. // NpoiExcelHelper.ExcelToEntityList<OptionalCoursePlanView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  348. // cellheader.Add("ErrorMessage", "错误信息");//还原字典项
  349. // #endregion
  350. // #region 1.2 将Excel数据写入数据库中
  351. // #region 1.2.1 对List集合进行有效性校验
  352. // if (enlist.Count() <= 0)
  353. // {
  354. // throw new Exception("请填写Excel模板信息数据。");
  355. // }
  356. // #region 1.2.1.1数据逻辑验证
  357. // for (int i = 0; i < enlist.Count; i++)
  358. // {
  359. // OptionalCoursePlanView en = enlist[i];
  360. // string errorMsgStr = "第" + (i + 1) + "行数据检测异常:";
  361. // bool isHaveNoInputValue = false; // 是否含有未输入项
  362. // #region 检测必填项是否必填
  363. // if (Guid.Empty == en.CoursematerialID)
  364. // {
  365. // errorMsgStr += "课程资料不能为空;";
  366. // en.ErrorMessage = errorMsgStr;
  367. // isHaveNoInputValue = true;
  368. // }
  369. // #endregion
  370. // #region 验证数据格式
  371. // //
  372. // Regex reg = new Regex(@"^[0-9]*$");
  373. // if (!string.IsNullOrEmpty(en.PeopleNumlimit.ToString()))
  374. // {
  375. // if (!reg.IsMatch(en.PeopleNumlimit + ""))
  376. // {
  377. // errorMsgStr += "人数上限;";
  378. // en.ErrorMessage = errorMsgStr;
  379. // isHaveNoInputValue = true;
  380. // }
  381. // }
  382. // if (!string.IsNullOrEmpty(en.PeopleNumlimit.ToString()))
  383. // {
  384. // if (!reg.IsMatch(en.PeopleNumlower + ""))
  385. // {
  386. // errorMsgStr += "人数下限;";
  387. // en.ErrorMessage = errorMsgStr;
  388. // isHaveNoInputValue = true;
  389. // }
  390. // }
  391. // //实践类型名称
  392. // Sys_DictionaryItem practiceType;
  393. // if (!string.IsNullOrEmpty(en.PracticeTypeName))
  394. // {
  395. // practiceType = IdNameExt.GetDictionaryItem(DictionaryItem.EM_PracticeType.ToString())
  396. // .Where(x => x.Name == en.PracticeTypeName.Trim()).FirstOrDefault();
  397. // if (practiceType == null)
  398. // {
  399. // errorMsgStr += "实践类型名称不存在;";
  400. // en.ErrorMessage = errorMsgStr;
  401. // isHaveNoInputValue = true;
  402. // }
  403. // else
  404. // en.PracticeTypeID = practiceType.Value.Value;
  405. // }
  406. // //考试方式名称
  407. // Sys_DictionaryItem examinationMode;
  408. // if (!string.IsNullOrEmpty(en.ExaminationModeDesc))
  409. // {
  410. // examinationMode = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ExaminationMode.ToString())
  411. // .Where(x => x.Name == en.ExaminationModeDesc.Trim()).FirstOrDefault();
  412. // if (examinationMode == null)
  413. // {
  414. // errorMsgStr += "考试方式名称不存在;";
  415. // en.ErrorMessage = errorMsgStr;
  416. // isHaveNoInputValue = true;
  417. // }
  418. // else
  419. // en.PracticeTypeID = examinationMode.Value.Value;
  420. // }
  421. // //课程结构
  422. // Sys_DictionaryItem courseStructure;
  423. // if (!string.IsNullOrEmpty(en.CourseStructureName))
  424. // {
  425. // courseStructure = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseStructure.ToString())
  426. // .Where(x => x.Name == en.CourseStructureName.Trim()).FirstOrDefault();
  427. // if (courseStructure == null)
  428. // {
  429. // errorMsgStr += "课程结构不存在;";
  430. // en.ErrorMessage = errorMsgStr;
  431. // isHaveNoInputValue = true;
  432. // }
  433. // else
  434. // en.PracticeTypeID = courseStructure.Value.Value;
  435. // }
  436. // //课程类型
  437. // Sys_DictionaryItem courseType;
  438. // if (!string.IsNullOrEmpty(en.CourseTypeName))
  439. // {
  440. // courseType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseType.ToString())
  441. // .Where(x => x.Name == en.CourseTypeName.Trim()).FirstOrDefault();
  442. // if (courseType == null)
  443. // {
  444. // errorMsgStr += "课程类型不存在;";
  445. // en.ErrorMessage = errorMsgStr;
  446. // isHaveNoInputValue = true;
  447. // }
  448. // else
  449. // en.PracticeTypeID = courseType.Value.Value;
  450. // }
  451. // //课程属性
  452. // Sys_DictionaryItem courseCategory;
  453. // if (!string.IsNullOrEmpty(en.CourseCategoryName))
  454. // {
  455. // courseCategory = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseCategory.ToString())
  456. // .Where(x => x.Name == en.CourseCategoryName.Trim()).FirstOrDefault();
  457. // if (courseCategory == null)
  458. // {
  459. // errorMsgStr += "课程属性不存在;";
  460. // en.ErrorMessage = errorMsgStr;
  461. // isHaveNoInputValue = true;
  462. // }
  463. // else
  464. // en.PracticeTypeID = courseCategory.Value.Value;
  465. // }
  466. // //授课语言
  467. // Sys_DictionaryItem teachinglanguage;
  468. // if (!string.IsNullOrEmpty(en.TeachinglanguageName))
  469. // {
  470. // teachinglanguage = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Teachinglanguage.ToString())
  471. // .Where(x => x.Name == en.TeachinglanguageName.Trim()).FirstOrDefault();
  472. // if (teachinglanguage == null)
  473. // {
  474. // errorMsgStr += "授课语言不存在;";
  475. // en.ErrorMessage = errorMsgStr;
  476. // isHaveNoInputValue = true;
  477. // }
  478. // else
  479. // en.PracticeTypeID = teachinglanguage.Value.Value;
  480. // }
  481. // //学年数
  482. // Sys_DictionaryItem schoolyearNum;
  483. // if (!string.IsNullOrEmpty(en.SchoolyearNumName))
  484. // {
  485. // schoolyearNum = IdNameExt.GetDictionaryItem(DictionaryItem.CF_SchoolyearNum.ToString())
  486. // .Where(x => x.Name == en.SchoolyearNumName.Trim()).FirstOrDefault();
  487. // if (schoolyearNum == null)
  488. // {
  489. // errorMsgStr += "学年数不存在;";
  490. // en.ErrorMessage = errorMsgStr;
  491. // isHaveNoInputValue = true;
  492. // }
  493. // else
  494. // en.PracticeTypeID = schoolyearNum.Value.Value;
  495. // }
  496. // //学期
  497. // Sys_DictionaryItem schoolcode;
  498. // if (!string.IsNullOrEmpty(en.SchoolcodeName))
  499. // {
  500. // schoolcode = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester.ToString())
  501. // .Where(x => x.Name == en.SchoolcodeName.Trim()).FirstOrDefault();
  502. // if (schoolcode == null)
  503. // {
  504. // errorMsgStr += "学期不存在;";
  505. // en.ErrorMessage = errorMsgStr;
  506. // isHaveNoInputValue = true;
  507. // }
  508. // else
  509. // en.PracticeTypeID = schoolcode.Value.Value;
  510. // }
  511. // //课程性质
  512. // Sys_DictionaryItem courseQuality;
  513. // if (!string.IsNullOrEmpty(en.CourseQualityName))
  514. // {
  515. // courseQuality = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseQuality.ToString())
  516. // .Where(x => x.Name == en.CourseQualityName.Trim()).FirstOrDefault();
  517. // if (courseQuality == null)
  518. // {
  519. // errorMsgStr += "课程性质不存在;";
  520. // en.ErrorMessage = errorMsgStr;
  521. // isHaveNoInputValue = true;
  522. // }
  523. // else
  524. // en.PracticeTypeID = courseQuality.Value.Value;
  525. // }
  526. // #region 信息是否存在
  527. // if (en.DepartmentID != Guid.Empty)
  528. // {
  529. // CF_Department department = departmentDAL.departmentRepository.GetSingle(x => x.DepartmentID == en.DepartmentID && x.RecordStatus > 0);
  530. // if (department == null)
  531. // {
  532. // errorMsgStr += "教研室不存在;";
  533. // en.ErrorMessage = errorMsgStr;
  534. // isHaveNoInputValue = true;
  535. // }
  536. // else
  537. // en.DepartmentID = department.DepartmentID;
  538. // }
  539. // if (en.CoursematerialID != Guid.Empty)
  540. // {
  541. // EM_Coursematerial coursematerial = coursematerialDAL.coursematerialRepository.GetSingle(x => x.CoursematerialID == en.CoursematerialID && x.RecordStatus > 0);
  542. // if (coursematerial == null)
  543. // {
  544. // errorMsgStr += "课程资料不存在;";
  545. // en.ErrorMessage = errorMsgStr;
  546. // isHaveNoInputValue = true;
  547. // }
  548. // else
  549. // en.CoursematerialID = coursematerial.CoursematerialID;
  550. // }
  551. // #endregion
  552. // if (isHaveNoInputValue) // 若必填项有值未填
  553. // {
  554. // en.IsExcelVaildateOK = false;
  555. // en.ErrorMessage = errorMsgStr;
  556. // errList.Add(en);
  557. // errorMsg.AppendLine(errorMsgStr);
  558. // }
  559. // }
  560. // #endregion
  561. // // TODO:其他检测
  562. // #region 1.2.1.3 循环写入验证成功的数据
  563. // List<EM_OptionalCoursePlan> newOptionalCoursePlanList = new List<EM_OptionalCoursePlan>();
  564. // for (int i = 0; i < enlist.Count; i++)
  565. // {
  566. // OptionalCoursePlanView enA = enlist[i];
  567. // if (enA.IsExcelVaildateOK == false) // 上面验证不通过,不进行此步验证
  568. // {
  569. // continue;
  570. // }
  571. // var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  572. // EM_OptionalCoursePlan optionalCoursePlan = new EM_OptionalCoursePlan();
  573. // optionalCoursePlan.OptionalCourseID = Guid.NewGuid();
  574. // optionalCoursePlan.DepartmentID = enA.DepartmentID;
  575. // optionalCoursePlan.SpecialtyID = enA.SpecialtyID;
  576. // optionalCoursePlan.CoursematerialID = enA.CoursematerialID;
  577. // optionalCoursePlan.CourseStructureID = enA.CourseStructureID;
  578. // optionalCoursePlan.CourseCategoryID = enA.CourseCategoryID;
  579. // optionalCoursePlan.CourseTypeID = enA.CourseTypeID;
  580. // optionalCoursePlan.CourseQualityID = enA.CourseQualityID;
  581. // optionalCoursePlan.PracticeTypeID = enA.PracticeTypeID;
  582. // optionalCoursePlan.ExaminationModeID = enA.ExaminationModeID;
  583. // optionalCoursePlan.TeachinglanguageID = enA.TeachinglanguageID;
  584. // optionalCoursePlan.SchoolyearNumID = enA.SchoolyearNumID;
  585. // optionalCoursePlan.SchoolcodeID = enA.SchoolcodeID;
  586. // optionalCoursePlan.IsEnable = enA.IsEnable;
  587. // optionalCoursePlan.PeopleNumlower = enA.PeopleNumlower;
  588. // optionalCoursePlan.PeopleNumlimit = enA.PeopleNumlimit;
  589. // optionalCoursePlan.IsOpened = enA.IsOpened;
  590. // optionalCoursePlan.Remarks = enA.Remarks;
  591. // SetNewStatus(optionalCoursePlan);
  592. // newOptionalCoursePlanList.Add(optionalCoursePlan);
  593. // }
  594. // #endregion
  595. // UnitOfWork.BulkInsert(newOptionalCoursePlanList);//统一写入
  596. // #endregion
  597. // #endregion
  598. // #endregion
  599. // #region 1.3 返回各项数据值
  600. // OkCount = enlist.Distinct().Count() - errList.Distinct().Count();//共条数减去失败条数
  601. // errdataList = errList.Distinct().ToList();
  602. // ErrCount = errList.Distinct().Count();
  603. // #endregion
  604. //}
  605. }
  606. }