SOCServices.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.DQPSystem;
  7. using EMIS.ViewModel;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using Bowin.Common.Linq;
  11. using EMIS.DataLogic.DQPSystem;
  12. using EMIS.CommonLogic.CalendarManage;
  13. using EMIS.CommonLogic.SystemServices;
  14. using EMIS.Utility.FormValidate;
  15. using EMIS.ViewModel.Students;
  16. using EMIS.ViewModel.EducationManage;
  17. using EMIS.DataLogic.EducationManage;
  18. using EMIS.ViewModel.UniversityManage.SpecialtyClassManage;
  19. using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
  20. namespace EMIS.CommonLogic.DQPSystem
  21. {
  22. public partial class SOCServices : BaseServices, ISOCServices, IFileUploadServices
  23. {
  24. public SOCDAL SOCDAL { get; set; }
  25. public SOCTemplateDAL SOCTemplateDAL { get; set; }
  26. public ISchoolYearServices SchoolYearServices { get; set; }
  27. public IRoleServices RoleServices { get; set; }
  28. public EducationMissionClassDAL EducationMissionClassDAL { get; set; }
  29. public IGridResultSet<SOCView> GetSOCViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, int pageIndex, int pageSize)
  30. {
  31. Expression<Func<DQP_SOC, bool>> exp = x => true;
  32. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  33. if (schoolyearID.HasValue)
  34. {
  35. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  36. }
  37. if (coursematerialID.HasValue)
  38. {
  39. exp = exp.And(x => x.CoursematerialID == coursematerialID);
  40. }
  41. if (collegeID.HasValue)
  42. {
  43. exp = exp.And(x => x.CF_Department.CollegeID == collegeID);
  44. }
  45. var role = RoleServices.GetEnabledTeacherRoleViewList();
  46. var teacherRole = role.Where(x => x.RoleName == "教师");
  47. var query = SOCDAL.GetSOCViewQueryable(exp, null);
  48. if (curUser.RoleID == teacherRole.FirstOrDefault().RoleID)
  49. {
  50. query = SOCDAL.GetSOCViewQueryable(exp, curUser.UserID);
  51. }
  52. else
  53. {
  54. query = this.GetQueryByDataRangeByDepartment(query);
  55. }
  56. //查询条件
  57. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  58. {
  59. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  60. }
  61. var result = query
  62. .OrderBy(x => x.SchoolyearCode.Length)
  63. .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.EducationMissionName)
  64. .ToGridResultSet<SOCView>(pageIndex, pageSize);
  65. return result;
  66. }
  67. public IGridResultSet<SOCView> GetSOCViewByTeacherIDGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? userID, int pageIndex, int pageSize)
  68. {
  69. Expression<Func<DQP_SOC, bool>> exp = x => true;
  70. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  71. if (schoolyearID.HasValue)
  72. {
  73. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  74. }
  75. var query = SOCDAL.GetSOCViewQueryable(exp, userID);
  76. //查询条件
  77. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  78. {
  79. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  80. }
  81. var result = query
  82. .OrderBy(x => x.SchoolyearCode.Length)
  83. .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.EducationMissionName)
  84. .ToGridResultSet<SOCView>(pageIndex, pageSize);
  85. return result;
  86. }
  87. public SOCView GetSOCViewByID(Guid? SOCID)
  88. {
  89. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  90. return SOCDAL.GetSOCViewQueryable(x => x.SOCID == SOCID, curUser.UserID).FirstOrDefault();
  91. }
  92. public IGridResultSet<SOCDetailView> GetSOCDetailViewGridByID(Guid? SOCID)
  93. {
  94. Expression<Func<DQP_SOCDetail, bool>> exp = x => true;
  95. if (SOCID.HasValue)
  96. {
  97. exp = exp.And(x => x.SOCID == SOCID);
  98. }
  99. var query = SOCDAL.GetSOCDetailViewQueryable(exp);
  100. return query.OrderBy(x => x.Name).ToGridResultSet<SOCDetailView>();
  101. }
  102. public SOCDetailView GetSOCDetailViewByID(Guid? SOCDetailID)
  103. {
  104. var query = SOCDAL.GetSOCDetailViewQueryable(x => x.SOCDetailID == SOCDetailID);
  105. return query.FirstOrDefault();
  106. }
  107. public void GenerateSOC()
  108. {
  109. try
  110. {
  111. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  112. var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  113. var dbSOCViewList = SOCDAL.GetSOCViewQueryable(x => true, curUser.UserID).ToList();//获取已有的SOC
  114. var query = SOCDAL.GetSOCGenerateViewQueryble(schoolYear.SchoolyearID, curUser.UserID).ToList();//根据教学任务生成
  115. var educationIDList = query.Select(x => x.EducationMissionID).ToList();//获取教学任务ID
  116. var emquery = SOCDAL.GetEducationMissionMassageByID(x => educationIDList.Contains(x.EducationMissionID)).ToList();//根据教学任务ID获取相关信息(学生)
  117. List<DQP_SOC> socList = new List<DQP_SOC>();
  118. List<DQP_SOCDetail> detailList = new List<DQP_SOCDetail>();
  119. //List<DQP_SOCStaff> staffList = new List<DQP_SOCStaff>();
  120. List<DQP_SOCStaff> addStaffList = new List<DQP_SOCStaff>();
  121. List<DQP_SOCDetailAttachment> attachmentList = new List<DQP_SOCDetailAttachment>();
  122. foreach (var edu in query)
  123. {
  124. if (!dbSOCViewList.Any(x => x.SchoolyearID == edu.SOCView.SchoolyearID && x.CoursematerialID == edu.SOCView.CoursematerialID && x.DepartmentID == edu.SOCView.DepartmentID
  125. && x.HandleModeID == edu.HandleModeID))
  126. {
  127. List<DQP_SOCStaff> staffList = new List<DQP_SOCStaff>();
  128. DQP_SOC soc = new DQP_SOC();
  129. soc.SOCID = Guid.NewGuid();
  130. soc.EducationMissionID = edu.EducationMissionID;
  131. soc.SchoolyearID = edu.SOCView.SchoolyearID;
  132. soc.CoursematerialID = edu.SOCView.CoursematerialID;
  133. soc.DepartmentID = edu.SOCView.DepartmentID;
  134. soc.Credit = edu.SOCView.Credit;
  135. soc.HandleModeID = edu.HandleModeID;
  136. soc.OptionalCourseTypeID = edu.OptionalCourseTypeID;
  137. this.SetNewStatus(soc);
  138. var edumassage = emquery.Distinct().Where(x => x.EducationMissionID == edu.EducationMissionID).ToList();
  139. foreach (var massage in edumassage)
  140. {
  141. foreach (var teacher in massage.MissionClassTeacherViewList)
  142. {
  143. DQP_SOCStaff staff = new DQP_SOCStaff();
  144. staff.SOCStaffID = Guid.NewGuid();
  145. staff.SOCID = soc.SOCID;
  146. staff.UserID = teacher.UserID.Value;
  147. staff.TeachingMethod = teacher.TeachingMethod;
  148. this.SetNewStatus(staff);
  149. foreach (var student in massage.StudentList)
  150. {
  151. staff.CF_Student.Add(student);
  152. }
  153. //soc.DQP_SOCStaff.Add(staff);
  154. staffList.Add(staff);
  155. }
  156. foreach (var classmajor in massage.ClassmajorList)
  157. {
  158. soc.CF_Classmajor.Add(classmajor);
  159. }
  160. foreach (var student in massage.StudentList)
  161. {
  162. soc.CF_Student.Add(student);
  163. }
  164. }
  165. var staffListIn = staffList.GroupBy(x => new { x.SOCID, x.UserID, x.TeachingMethod }).Select(x => new { x.Key.SOCID, x.Key.UserID, x.Key.TeachingMethod }).ToList();
  166. //staffList = new List<DQP_SOCStaff>();
  167. foreach (var i in staffListIn)
  168. {
  169. DQP_SOCStaff staff = new DQP_SOCStaff();
  170. staff.SOCStaffID = Guid.NewGuid();
  171. staff.SOCID = i.SOCID;
  172. staff.UserID = i.UserID;
  173. staff.TeachingMethod = i.TeachingMethod;
  174. this.SetNewStatus(staff);
  175. Expression<Func<EM_EducationMission, bool>> exp = x => x.EducationMissionID == edu.EducationMissionID;
  176. //查找老师对应的学生
  177. var studentList = SOCDAL.GetStudentByTeacher(exp, i.UserID, edu.SOCView.CoursematerialID).Distinct().ToList();
  178. foreach (var stu in studentList)
  179. {
  180. staff.CF_Student.Add(stu);
  181. }
  182. addStaffList.Add(staff);
  183. }
  184. socList.Add(soc);
  185. }
  186. }
  187. UnitOfWork.BulkInsert(socList);
  188. UnitOfWork.BulkInsert(socList, x => x.CF_Classmajor);
  189. UnitOfWork.BulkInsert(socList, x => x.CF_Student);
  190. UnitOfWork.BulkInsert(detailList);
  191. UnitOfWork.BulkInsert(attachmentList);
  192. UnitOfWork.BulkInsert(addStaffList);
  193. UnitOfWork.BulkInsert(addStaffList, x => x.CF_Student);
  194. //var socTemplatequery = SOCTemplateDAL.GetSOCTemplateViewQueryable(x => x.RecordStatus == (int)SYS_STATUS.USABLE, x => true);
  195. //var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  196. //var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
  197. //var dbSOCViewList = SOCDAL.GetSOCViewQueryable(x => true, curUser.UserID).ToList();
  198. //var query = SOCDAL.GetSOCGenerateViewQueryble(schoolYear.SchoolyearID, curUser.UserID).ToList();
  199. //var CoursematerialIDList = query.Select(x => x.SOCView.CoursematerialID).ToList();
  200. ////var eduIDList = query.Select(x => x.EducationMissionID).ToList();
  201. //var soctemIDList = query.Select(x => x.SOCTemplateID).ToList();
  202. //var emquery = SOCDAL.GetEducationMissionMassageForSOCGenerate(x => x.SchoolyearID == schoolYear.SchoolyearID, CoursematerialIDList).ToList();
  203. //var socquery = SOCDAL.GetSOCTemplateForSOCGenerate(x => soctemIDList.Contains(x.SOCTemplateID)).ToList();
  204. //List<DQP_SOC> socList = new List<DQP_SOC>();
  205. //List<DQP_SOCDetail> detailList = new List<DQP_SOCDetail>();
  206. //List<DQP_SOCStaff> staffList = new List<DQP_SOCStaff>();
  207. //List<DQP_SOCStaff> addStaffList = new List<DQP_SOCStaff>();
  208. ////List<DQP_SOCStaff> staffListIn = new List<DQP_SOCStaff>();
  209. //List<DQP_SOCDetailAttachment> attachmentList = new List<DQP_SOCDetailAttachment>();
  210. //var queryList = query.GroupBy(x => x.SOCTemplateID).ToList();
  211. //var SOCGenerateList = new List<SOCGenerateView>();
  212. //foreach (var qu in query)
  213. //{
  214. // if (SOCGenerateList.Any(x => x.SOCView.CoursematerialID == qu.SOCView.CoursematerialID && x.SOCView.DepartmentID == qu.SOCView.DepartmentID))
  215. // {
  216. // continue;
  217. // }
  218. // if (query.Any(x => x.SOCTemplateID != qu.SOCTemplateID && x.SOCView.CoursematerialID == qu.SOCView.CoursematerialID && x.SOCView.DepartmentID == qu.SOCView.DepartmentID))
  219. // {
  220. // //if (qu.FacultymajorID != null && qu.SchoolcodeID != null && qu.SchoolyearNumID != null)
  221. // ////&& qu.HandleModeID != null
  222. // //{
  223. // // SOCGenerateList.Add(qu);
  224. // //}
  225. // //else
  226. // //{
  227. // Dictionary<Guid, int> dictionary = new Dictionary<Guid, int>();
  228. // var sameTemplate = query.Where(x => x.SOCView.CoursematerialID == qu.SOCView.CoursematerialID && x.SOCView.DepartmentID == qu.SOCView.DepartmentID);
  229. // if (sameTemplate.Any(x => x.FacultymajorID != null && x.SchoolcodeID != null && x.SchoolyearNumID != null))
  230. // //&& x.HandleModeID != null
  231. // {
  232. // SOCGenerateList.Add(sameTemplate.FirstOrDefault(x => x.FacultymajorID != null && x.SchoolcodeID != null && x.SchoolyearNumID != null));
  233. // //&& x.HandleModeID != null
  234. // }
  235. // else if (sameTemplate.Any(x => x.FacultymajorID != null))
  236. // {
  237. // SOCGenerateList.Add(sameTemplate.FirstOrDefault(x => x.FacultymajorID != null));
  238. // }
  239. // else if (sameTemplate.Any(x => x.SchoolyearNumID != null && x.SchoolcodeID != null))
  240. // {
  241. // SOCGenerateList.Add(sameTemplate.FirstOrDefault(x => x.SchoolyearNumID != null && x.SchoolcodeID != null));
  242. // }
  243. // else if (sameTemplate.Any(x => x.SchoolcodeID != null))
  244. // {
  245. // SOCGenerateList.Add(sameTemplate.FirstOrDefault(x => x.SchoolcodeID != null));
  246. // }
  247. // else if (sameTemplate.Any(x => x.SchoolyearNumID != null))
  248. // {
  249. // SOCGenerateList.Add(sameTemplate.FirstOrDefault(x => x.SchoolyearNumID != null));
  250. // }
  251. // else if (sameTemplate.Any(x => x.FacultymajorID == null && x.SchoolyearNumID == null && x.SchoolcodeID == null))
  252. // {
  253. // SOCGenerateList.Add(sameTemplate.FirstOrDefault(x => x.FacultymajorID == null && x.SchoolyearNumID == null && x.SchoolcodeID == null));
  254. // }
  255. // //}
  256. // }
  257. // else {
  258. // SOCGenerateList.Add(qu);
  259. // }
  260. //}
  261. //foreach (var edu in SOCGenerateList)
  262. //{
  263. // if (!dbSOCViewList.Any(x => x.SchoolyearID == edu.SOCView.SchoolyearID && x.CoursematerialID == edu.SOCView.CoursematerialID && x.DepartmentID == edu.SOCView.DepartmentID
  264. // && x.HandleModeID == edu.HandleModeID))
  265. // {
  266. // DQP_SOC soc = new DQP_SOC();
  267. // soc.SOCID = Guid.NewGuid();
  268. // soc.SchoolyearID = edu.SOCView.SchoolyearID;
  269. // soc.CoursematerialID = edu.SOCView.CoursematerialID;
  270. // soc.DepartmentID = edu.SOCView.DepartmentID;
  271. // soc.Credit = edu.SOCView.Credit;
  272. // soc.HandleModeID = edu.HandleModeID;
  273. // soc.OptionalCourseTypeID = edu.OptionalCourseTypeID;
  274. // this.SetNewStatus(soc);
  275. // var edumassage = emquery.Distinct().Where(x => x.SOCView.CoursematerialID == edu.SOCView.CoursematerialID
  276. // //&& x.MissionClassTeacherViewList.Any(y => x)
  277. // && x.SOCView.DepartmentID == edu.SOCView.DepartmentID
  278. // && (x.SOCView.SchoolyearID == edu.SOCView.SchoolyearID || edu.SOCView.SchoolyearID == null)).ToList();
  279. // var socmassage = socquery.Where(x => x.SOCTemplateID == edu.SOCTemplateID);
  280. // foreach(var massage in edumassage)
  281. // {
  282. // foreach (var teacher in massage.MissionClassTeacherViewList)
  283. // {
  284. // DQP_SOCStaff staff = new DQP_SOCStaff();
  285. // staff.SOCStaffID = Guid.NewGuid();
  286. // staff.SOCID = soc.SOCID;
  287. // staff.UserID = teacher.UserID.Value;
  288. // staff.TeachingMethod = teacher.TeachingMethod;
  289. // this.SetNewStatus(staff);
  290. // foreach (var student in massage.StudentList)
  291. // {
  292. // staff.CF_Student.Add(student);
  293. // }
  294. // //soc.DQP_SOCStaff.Add(staff);
  295. // staffList.Add(staff);
  296. // }
  297. // foreach (var classmajor in massage.ClassmajorList)
  298. // {
  299. // soc.CF_Classmajor.Add(classmajor);
  300. // }
  301. // foreach (var student in massage.StudentList)
  302. // {
  303. // soc.CF_Student.Add(student);
  304. // }
  305. // }
  306. // foreach (var socm in socmassage)
  307. // {
  308. // foreach (var detail in socm.SOCDetailViewList)
  309. // {
  310. // DQP_SOCDetail SOCdetail = new DQP_SOCDetail();
  311. // SOCdetail.SOCDetailID = Guid.NewGuid();
  312. // SOCdetail.SOCID = soc.SOCID;
  313. // SOCdetail.Name = detail.Name;
  314. // SOCdetail.Weight = detail.Weight;
  315. // SOCdetail.IsGroup = detail.IsGroup ?? false;
  316. // SOCdetail.Description = detail.Description;
  317. // SOCdetail.Credit = detail.Credit;
  318. // this.SetNewStatus(SOCdetail);
  319. // foreach (var att in detail.AttachmentList)
  320. // {
  321. // DQP_SOCDetailAttachment attachment = new DQP_SOCDetailAttachment();
  322. // attachment.SOCDetailAttachmentID = Guid.NewGuid();
  323. // attachment.SOCDetailID = SOCdetail.SOCDetailID;
  324. // attachment.Name = att.Name;
  325. // attachment.Url = att.Url;
  326. // this.SetNewStatus(attachment);
  327. // attachmentList.Add(attachment);
  328. // }
  329. // soc.DQP_SOCDetail.Add(SOCdetail);
  330. // detailList.Add(SOCdetail);
  331. // }
  332. // }
  333. // socList.Add(soc);
  334. // }
  335. // var staffListIn = staffList.GroupBy(x => new { x.SOCID, x.UserID, x.TeachingMethod }).Select(x => new { x.Key.SOCID, x.Key.UserID, x.Key.TeachingMethod }).ToList();
  336. // //staffList = new List<DQP_SOCStaff>();
  337. // foreach (var i in staffListIn)
  338. // {
  339. // DQP_SOCStaff staff = new DQP_SOCStaff();
  340. // staff.SOCStaffID = Guid.NewGuid();
  341. // staff.SOCID = i.SOCID;
  342. // staff.UserID = i.UserID;
  343. // staff.TeachingMethod = i.TeachingMethod;
  344. // this.SetNewStatus(staff);
  345. // Expression<Func<EM_EducationMission, bool>> exp = x => x.SchoolyearID == schoolYear.SchoolyearID;
  346. // //查找老师对应的学生
  347. // var studentList = SOCDAL.GetStudentByTeacher(exp, i.UserID, edu.SOCView.CoursematerialID).Distinct().ToList();
  348. // foreach (var stu in studentList)
  349. // {
  350. // staff.CF_Student.Add(stu);
  351. // }
  352. // addStaffList.Add(staff);
  353. // }
  354. //}
  355. //UnitOfWork.BulkInsert(socList);
  356. //UnitOfWork.BulkInsert(socList, x => x.CF_Classmajor);
  357. //UnitOfWork.BulkInsert(socList, x => x.CF_Student);
  358. ////UnitOfWork.BulkInsert(socList, x => x.DQP_SOCStaff);
  359. //UnitOfWork.BulkInsert(detailList);
  360. //UnitOfWork.BulkInsert(attachmentList);
  361. //UnitOfWork.BulkInsert(addStaffList);
  362. //UnitOfWork.BulkInsert(addStaffList, x => x.CF_Student);
  363. }
  364. catch (Exception)
  365. {
  366. throw;
  367. }
  368. }
  369. public void SOCEdit(SOCView SOCView, List<SOCDetailView> SOCDetailViewList, List<FileUploadView> fileList, List<Guid?> socIDList)
  370. {
  371. try
  372. {
  373. DQP_SOC SOC = new DQP_SOC();
  374. var dbAttachmentList = SOCDAL.SOCDetailAttachmentRepository.GetList(x => x.DQP_SOCDetail.DQP_SOC.SOCID == SOCView.SOCID).ToList();
  375. List<DQP_SOCDetail> updetailList = new List<DQP_SOCDetail>();
  376. //新增
  377. if (SOCView.SOCID == null || SOCView.SOCID == Guid.Empty)
  378. {
  379. SOC = SOCDAL.SOCRepository.GetSingle(x => x.SchoolyearID == SOCView.SchoolyearID && x.CoursematerialID == SOCView.CoursematerialID
  380. && x.DepartmentID == SOCView.DepartmentID && x.HandleModeID == SOCView.HandleModeID && x.OptionalCourseTypeID == SOCView.OptionalCourseTypeID);
  381. if (SOC != null)
  382. {
  383. throw new Exception("已存在相同的课程SOC设置信息");
  384. }
  385. SOC = new DQP_SOC();
  386. List<DQP_SOCDetail> SOCDetailList = new List<DQP_SOCDetail>();
  387. SOC.SOCID = Guid.NewGuid();
  388. SOC.SchoolyearID = SOCView.SchoolyearID;
  389. SOC.CoursematerialID = SOCView.CoursematerialID;
  390. SOC.Credit = SOCView.Credit;
  391. SOC.DepartmentID = SOCView.DepartmentID;
  392. SOC.HandleModeID = SOCView.HandleModeID;
  393. SOC.OptionalCourseTypeID = SOCView.OptionalCourseTypeID;
  394. this.SetNewStatus(SOC);
  395. foreach (var view in SOCDetailViewList)
  396. {
  397. if (view.Weight >= 0 && view.Weight <= 100)
  398. {
  399. DQP_SOCDetail detail = new DQP_SOCDetail();
  400. detail.SOCDetailID = view.SOCDetailID;
  401. detail.SOCID = SOC.SOCID;
  402. detail.Name = view.Name;
  403. detail.Credit = view.Credit;
  404. detail.Weight = view.Weight;
  405. detail.Description = view.Description;
  406. detail.IsGroup = view.IsGroup;
  407. detail.StartTime = view.StartTime;
  408. detail.EndTime = view.EndTime;
  409. this.SetNewStatus(detail);
  410. List<DQP_SOCDetailAttachment> attachmentList = new List<DQP_SOCDetailAttachment>();
  411. foreach (var file in fileList)
  412. {
  413. if (file.FormID == detail.SOCDetailID)
  414. {
  415. DQP_SOCDetailAttachment attachment = new DQP_SOCDetailAttachment();
  416. attachment.SOCDetailAttachmentID = Guid.NewGuid();
  417. attachment.SOCDetailID = file.FormID;
  418. attachment.Name = file.FileName;
  419. attachment.Url = file.FileUrl;
  420. this.SetNewStatus(attachment);
  421. detail.DQP_SOCDetailAttachment.Add(attachment);
  422. }
  423. }
  424. SOC.DQP_SOCDetail.Add(detail);
  425. }
  426. else
  427. {
  428. throw new Exception("权重只能是0-100之间的数字");
  429. }
  430. }
  431. UnitOfWork.Commit();
  432. }
  433. else
  434. {//修改
  435. if (socIDList.Count == 1)//单个修改
  436. {
  437. SOC = SOCDAL.SOCRepository.GetSingle(x => x.SOCID != SOCView.SOCID && x.EducationMissionID == SOCView.EducationMissionID && x.CoursematerialID == SOCView.CoursematerialID
  438. && x.SchoolyearID == SOCView.SchoolyearID && x.HandleModeID == SOCView.HandleModeID && x.OptionalCourseTypeID == SOCView.OptionalCourseTypeID
  439. && x.DepartmentID == SOCView.DepartmentID);
  440. if (SOC != null)
  441. {
  442. throw new Exception("已存在相同的课程SOC设置信息");
  443. }
  444. SOC = SOCDAL.SOCRepository.GetSingle(x => x.SOCID == SOCView.SOCID, (x => x.DQP_SOCDetail));
  445. List<DQP_SOCDetail> SOCTemplateDetailList = new List<DQP_SOCDetail>();
  446. List<DQP_SOCDetailAttachment> attachmentList = new List<DQP_SOCDetailAttachment>();
  447. SOC.Credit = SOCView.Credit;
  448. this.SetModifyStatus(SOC);
  449. var dbDetailIDList = SOC.DQP_SOCDetail.Select(x => x.SOCDetailID);
  450. var newDetailIDList = SOCDetailViewList.Select(x => x.SOCDetailID);
  451. var deleteDetailIDList = new List<Guid?>();
  452. foreach (var did in dbDetailIDList)
  453. {
  454. if (!newDetailIDList.Contains(did))
  455. {
  456. deleteDetailIDList.Add(did);
  457. }
  458. }
  459. UnitOfWork.Remove<DQP_SOCDetailAttachment>(x => dbDetailIDList.Contains(x.SOCDetailID.Value) && x.DQP_SOCDetail.SOCID == SOC.SOCID);
  460. UnitOfWork.Remove<DQP_SOCDetail>(x => deleteDetailIDList.Contains(x.SOCDetailID) && x.SOCID == SOC.SOCID);
  461. foreach (var view in SOCDetailViewList)
  462. {
  463. if (view.Weight >= 0 && view.Weight <= 100)
  464. {
  465. DQP_SOCDetail detail = new DQP_SOCDetail();
  466. if (SOC.DQP_SOCDetail.Any(x => x.SOCDetailID == view.SOCDetailID))
  467. {
  468. //修改原来存在的
  469. detail = SOC.DQP_SOCDetail.FirstOrDefault(x => x.SOCDetailID == view.SOCDetailID);
  470. //detail.SOCDetailID = view.SOCDetailID;
  471. detail.SOCID = SOC.SOCID;
  472. detail.Name = view.Name;
  473. detail.Credit = view.Credit;
  474. detail.Weight = view.Weight;
  475. detail.Description = view.Description;
  476. detail.IsGroup = view.IsGroupin;
  477. detail.StartTime = view.StartTime;
  478. detail.EndTime = view.EndTime;
  479. this.SetModifyStatus(detail);
  480. updetailList.Add(detail);
  481. }
  482. else
  483. {
  484. //新增
  485. detail.SOCDetailID = view.SOCDetailID;
  486. //Guid.NewGuid();
  487. detail.SOCID = SOC.SOCID;
  488. detail.Name = view.Name;
  489. detail.Credit = view.Credit;
  490. detail.Weight = view.Weight;
  491. detail.Description = view.Description;
  492. detail.IsGroup = view.IsGroupin;
  493. detail.StartTime = view.StartTime;
  494. detail.EndTime = view.EndTime;
  495. this.SetNewStatus(detail);
  496. SOC.DQP_SOCDetail.Add(detail);
  497. }
  498. var fileIDList = fileList.Select(x => x.FileID).ToList();
  499. //UnitOfWork.Remove<DQP_SOCDetailAttachment>(x => x.SOCDetailID == detail.SOCDetailID);
  500. foreach (var file in fileList)
  501. {
  502. if (file.FormID == detail.SOCDetailID)
  503. {
  504. DQP_SOCDetailAttachment attachment = new DQP_SOCDetailAttachment();
  505. attachment.SOCDetailAttachmentID = Guid.NewGuid();
  506. attachment.SOCDetailID = file.FormID;
  507. attachment.Name = file.FileName;
  508. attachment.Url = file.FileUrl;
  509. this.SetNewStatus(attachment);
  510. attachmentList.Add(attachment);
  511. }
  512. }
  513. }
  514. else
  515. {
  516. throw new Exception("权重只能是0-100之前的数字");
  517. }
  518. }
  519. UnitOfWork.BatchUpdate<DQP_SOCDetail>(updetailList);
  520. UnitOfWork.Commit();
  521. //UnitOfWork.BulkInsert(SOCTemplateDetailList);
  522. UnitOfWork.BulkInsert(attachmentList);
  523. }
  524. else if (socIDList.Count > 1)
  525. {
  526. foreach (var id in socIDList)
  527. {
  528. SOC = SOCDAL.SOCRepository.GetSingle(x => x.SOCID == id, (x => x.DQP_SOCDetail));
  529. List<DQP_SOCDetail> SOCTemplateDetailList = new List<DQP_SOCDetail>();
  530. List<DQP_SOCDetailAttachment> attachmentList = new List<DQP_SOCDetailAttachment>();
  531. SOC.Credit = SOCView.Credit;
  532. this.SetModifyStatus(SOC);
  533. var dbDetailIDList = SOC.DQP_SOCDetail.Select(x => x.SOCDetailID);
  534. UnitOfWork.Remove<DQP_SOCDetailStudentAttachment>(x => dbDetailIDList.Contains(x.DQP_SOCDetailStudent.SOCDetailID.Value));
  535. var socdetailGroup = SOCDAL.SOCDetailGroupRepository.GetList(x => dbDetailIDList.Contains(x.SOCDetailID.Value),x => x.CF_Student);
  536. foreach (var socdetail in socdetailGroup)
  537. {
  538. socdetail.CF_Student = new HashSet<CF_Student>();
  539. }
  540. UnitOfWork.Remove<DQP_SOCDetailGroup>(x => dbDetailIDList.Contains(x.SOCDetailID.Value));
  541. UnitOfWork.Remove<DQP_SOCDetailStudent>(x => dbDetailIDList.Contains(x.SOCDetailID.Value));
  542. UnitOfWork.Remove<DQP_SOCDetailStudentScore>(x => dbDetailIDList.Contains(x.SOCDetailID.Value));
  543. UnitOfWork.Remove<DQP_SOCDetailAttachment>(x => dbDetailIDList.Contains(x.SOCDetailID.Value));
  544. UnitOfWork.Remove<DQP_SOCDetail>(x => dbDetailIDList.Contains(x.SOCDetailID));
  545. SOC.DQP_SOCDetail = new HashSet<DQP_SOCDetail>();//删掉原来的明细再新加进去
  546. foreach (var view in SOCDetailViewList)
  547. {
  548. //UnitOfWork.Delete<DQP_SOCDetail>(x => x.SOCID == SOC.SOCID);
  549. if (view.Weight >= 0 && view.Weight <= 100)
  550. {
  551. //SOC.DQP_SOCDetail = new HashSet<DQP_SOCDetail>();
  552. DQP_SOCDetail detail = new DQP_SOCDetail();
  553. //新增
  554. detail.SOCDetailID = Guid.NewGuid();
  555. detail.SOCID = SOC.SOCID;
  556. detail.Name = view.Name;
  557. detail.Credit = view.Credit;
  558. detail.Weight = view.Weight;
  559. detail.Description = view.Description;
  560. detail.IsGroup = view.IsGroupin;
  561. detail.StartTime = view.StartTime;
  562. detail.EndTime = view.EndTime;
  563. this.SetNewStatus(detail);
  564. SOC.DQP_SOCDetail.Add(detail);
  565. var fileIDList = fileList.Select(x => x.FileID).ToList();
  566. foreach (var file in fileList)
  567. {
  568. if (file.FormID == view.SOCDetailID)
  569. {
  570. DQP_SOCDetailAttachment attachment = new DQP_SOCDetailAttachment();
  571. attachment.SOCDetailAttachmentID = Guid.NewGuid();
  572. attachment.SOCDetailID = detail.SOCDetailID;
  573. attachment.Name = file.FileName;
  574. attachment.Url = file.FileUrl;
  575. this.SetNewStatus(attachment);
  576. attachmentList.Add(attachment);
  577. //detail.DQP_SOCTemplateDetailAttachment.Add(attachment);
  578. }
  579. }
  580. //}
  581. //SOCTemplateDetailList.Add(detail);
  582. }
  583. else
  584. {
  585. throw new Exception("权重只能是0-100之前的数字");
  586. }
  587. }
  588. UnitOfWork.BatchUpdate<DQP_SOCDetail>(updetailList);
  589. UnitOfWork.Commit();
  590. //UnitOfWork.BulkInsert(SOCTemplateDetailList);
  591. UnitOfWork.BulkInsert(attachmentList);
  592. }
  593. }
  594. }
  595. }
  596. catch (Exception)
  597. {
  598. throw;
  599. }
  600. }
  601. public IGridResultSet<BaseStudentView> GetSOCStudent(Guid? SOCID, int pageIndex, int pageSize)
  602. {
  603. return SOCDAL.GetSOCStudentList(SOCID).OrderBy(x => x.ClassmajorCode).ThenBy(x => x.LoginID).ToGridResultSet<BaseStudentView>(pageIndex, pageSize);
  604. }
  605. public List<FileUploadView> GetFileList(Guid? formID)
  606. {
  607. //var socDetailAttachment = SOCDAL.SOCDetailAttachmentRepository.GetSingle(x => x.SOCDetailID == formID);
  608. var fileList = SOCDAL.GetSOCDetailAttachmentView(x => x.SOCDetailID == formID).ToList();
  609. return fileList;
  610. }
  611. public bool CheckDetailIsHaveMessage(List<Guid?> detailIDList)
  612. {
  613. var detail = SOCDAL.SOCDetailRepository.GetList(x => detailIDList.Contains(x.SOCDetailID), (x => x.DQP_SOCDetailGroup), (x => x.DQP_SOCDetailStudent), (x => x.DQP_SOCDetailStudentScore));
  614. if (detail.Any(x => x.DQP_SOCDetailGroup.Count > 0 || x.DQP_SOCDetailStudent.Count > 0 || x.DQP_SOCDetailStudentScore.Count > 0))
  615. {
  616. return true;
  617. }
  618. else {
  619. return false;
  620. }
  621. }
  622. public bool CheckSOCIsHaveMessage(List<Guid?> socIDList)
  623. {
  624. var detail = SOCDAL.SOCRepository.GetList(x => socIDList.Contains(x.SOCID), (x => x.DQP_SOCDetail));
  625. if (detail.Any(x => x.DQP_SOCDetail.Count > 0))
  626. {
  627. return true;
  628. }
  629. else
  630. {
  631. return false;
  632. }
  633. }
  634. public IGridResultSet<EducationMissionView> GetEducationMissionViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
  635. {
  636. Expression<Func<EM_EducationMission, bool>> exp = x => true;
  637. var query = EducationMissionClassDAL.GetEducationMissionView(exp);
  638. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  639. {
  640. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  641. }
  642. var result = query
  643. .OrderBy(x => x.SchoolyearCode.Length)
  644. .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.ClassName)
  645. .ToGridResultSet<EducationMissionView>(pageIndex, pageSize);
  646. return result;
  647. }
  648. public IGridResultSet<CollegeView> GetTeacherCollegeViewGrid(ConfiguretView configuretView, Guid? schoolyearID, int pageIndex, int pageSize)
  649. {
  650. var userID = CustomPrincipal.Current.UserID;
  651. Expression<Func<DQP_SOC, bool>> exp = x => true;
  652. Expression<Func<CF_Staff, bool>> staffexp = x => true;
  653. if(schoolyearID.HasValue)
  654. {
  655. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  656. }
  657. staffexp = staffexp.And(x => x.UserID == userID);
  658. var query = SOCDAL.GetCollegeViewList(exp, staffexp);
  659. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  660. {
  661. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  662. }
  663. var result = query
  664. .OrderBy(x => x.Name)
  665. .ToGridResultSet<CollegeView>(pageIndex, pageSize);
  666. return result;
  667. }
  668. public IGridResultSet<ClassmajorView> GetTeacherClassmajorViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, int pageIndex, int pageSize)
  669. {
  670. var userID = CustomPrincipal.Current.UserID;
  671. Expression<Func<DQP_SOC, bool>> exp = x => true;
  672. Expression<Func<CF_Staff, bool>> staffexp = x => true;
  673. Expression<Func<CF_Classmajor, bool>> classexp = x => true;
  674. if (schoolyearID.HasValue)
  675. {
  676. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  677. }
  678. if (collegeID.HasValue)
  679. {
  680. classexp = classexp.And(x => x.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  681. }
  682. if (year.HasValue)
  683. {
  684. classexp = classexp.And(x => x.CF_Grademajor.GradeID == year);
  685. }
  686. if (standardID.HasValue)
  687. {
  688. classexp = classexp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  689. }
  690. staffexp = staffexp.And(x => x.UserID == userID);
  691. var query = SOCDAL.GetClassmajorViewList(exp, staffexp, classexp);
  692. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  693. {
  694. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  695. }
  696. var result = query
  697. .OrderBy(x => x.Name)
  698. .ToGridResultSet<ClassmajorView>(pageIndex, pageSize);
  699. return result;
  700. }
  701. }
  702. }