SOCDetailScoreServices.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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.ViewModel.DQPSystem;
  9. using EMIS.ViewModel;
  10. using EMIS.DataLogic.DQPSystem;
  11. using EMIS.Entities;
  12. using System.Transactions;
  13. using EMIS.Utility.FormValidate;
  14. using EMIS.CommonLogic.SystemServices;
  15. using EMIS.DataLogic.Common.Students;
  16. using EMIS.ViewModel.Students;
  17. using EMIS.ViewModel.SystemView;
  18. using EMIS.DataLogic.SystemDAL;
  19. using EMIS.Utility;
  20. namespace EMIS.CommonLogic.DQPSystem
  21. {
  22. public class SOCDetailScoreServices : BaseServices, ISOCDetailScoreServices, IFileUploadServices
  23. {
  24. public SOCDetailScoreDAL SOCDetailScoreDAL { get; set; }
  25. public StudentsDAL StudentsDAL { get; set; }
  26. public AnnouncementDAL AnnouncementDAL { get; set; }
  27. public IRoleServices RoleServices { get; set; }
  28. public IGridResultSet<SOCDetailStudentScoreView> GetSOCDetailStudentScoreViewList(ConfiguretView studentScoreConditionView, Guid? schoolyearID,
  29. Guid? collegeID, int? year, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus, int? pageIndex, int? pageSize)
  30. {
  31. var userID = CustomPrincipal.Current.UserID;
  32. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  33. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  34. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  35. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  36. if (schoolyearID.HasValue)
  37. {
  38. socExp = socExp.And(x => x.SchoolyearID == schoolyearID);
  39. }
  40. if (collegeID.HasValue)
  41. {
  42. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  43. }
  44. if (year.HasValue)
  45. {
  46. gradeExp = gradeExp.And(x => x.GradeID == year);
  47. }
  48. if (standardID.HasValue)
  49. {
  50. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  51. }
  52. if (classmajorID.HasValue)
  53. {
  54. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  55. }
  56. if (coursematerialID.HasValue)
  57. {
  58. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  59. }
  60. var query = SOCDetailScoreDAL.GetSOCDetailStudentScoreView(userID, socExp, facultyExp, gradeExp, classExp);
  61. if (recordStatus.HasValue)
  62. {
  63. query = query.Where(x => x.RecordStatus == recordStatus);
  64. }
  65. if (!string.IsNullOrEmpty(studentScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(studentScoreConditionView.Attribute))
  66. query = query.DynamicWhere(studentScoreConditionView.Attribute, studentScoreConditionView.Condition, studentScoreConditionView.ConditionValue);
  67. query = query.OrderByDescending(x => x.SchoolyearCode)
  68. .ThenBy(x => x.CourseCode)
  69. .ThenBy(x => x.SOCDetailName)
  70. .ThenBy(x => x.LoginID);
  71. return query.ToGridResultSet(pageIndex, pageSize);
  72. }
  73. public IGridResultSet<SOCDetailStudentScoreView> GetSOCDetailStudentScoreViewByIDList(ConfiguretView configuretView, Guid? socDetailID, Guid? userID, int? pageIndex, int? pageSize)
  74. {
  75. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  76. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  77. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  78. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  79. var query = SOCDetailScoreDAL.GetSOCDetailStudentScoreView(userID.Value, socExp, facultyExp, gradeExp, classExp);
  80. if (socDetailID.HasValue)
  81. {
  82. query = query.Where(x => x.SOCDetailID == socDetailID);
  83. }
  84. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  85. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  86. query = query.OrderByDescending(x => x.SchoolyearCode)
  87. .ThenBy(x => x.CourseCode)
  88. .ThenBy(x => x.SOCDetailName)
  89. .ThenBy(x => x.LoginID);
  90. return query.ToGridResultSet(pageIndex, pageSize);
  91. }
  92. public List<SOCDetailStudentScoreView> GetSOCDetailStudentScoreViewList(ConfiguretView studentScoreConditionView, Guid? schoolyearID,
  93. Guid? collegeID, int? year, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus)
  94. {
  95. var userID = CustomPrincipal.Current.UserID;
  96. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  97. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  98. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  99. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  100. if (schoolyearID.HasValue)
  101. {
  102. socExp = socExp.And(x => x.SchoolyearID == schoolyearID);
  103. }
  104. if (collegeID.HasValue)
  105. {
  106. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  107. }
  108. if (year.HasValue)
  109. {
  110. gradeExp = gradeExp.And(x => x.GradeID == year);
  111. }
  112. if (standardID.HasValue)
  113. {
  114. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  115. }
  116. if (classmajorID.HasValue)
  117. {
  118. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  119. }
  120. if (coursematerialID.HasValue)
  121. {
  122. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  123. }
  124. var query = SOCDetailScoreDAL.GetSOCDetailStudentScoreView(userID, socExp, facultyExp, gradeExp, classExp);
  125. if (recordStatus.HasValue)
  126. {
  127. query = query.Where(x => x.RecordStatus == recordStatus);
  128. }
  129. if (!string.IsNullOrEmpty(studentScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(studentScoreConditionView.Attribute))
  130. query = query.DynamicWhere(studentScoreConditionView.Attribute, studentScoreConditionView.Condition, studentScoreConditionView.ConditionValue);
  131. query = query.OrderByDescending(x => x.SchoolyearCode)
  132. .ThenBy(x => x.CourseCode)
  133. .ThenBy(x => x.SOCDetailName)
  134. .ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo)
  135. .ThenBy(x => x.LoginID);
  136. return query.ToList();
  137. }
  138. public List<SOCDetailStudentScoreView> GetSOCDetailStudentScoreViewList(ConfiguretView studentScoreConditionView, Guid? socDetailID, Guid? userID)
  139. {
  140. //var userID = CustomPrincipal.Current.UserID;
  141. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  142. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  143. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  144. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  145. var query = SOCDetailScoreDAL.GetSOCDetailStudentScoreView(userID.Value, socExp, facultyExp, gradeExp, classExp);
  146. if (socDetailID.HasValue)
  147. {
  148. query = query.Where(x => x.SOCDetailID == socDetailID);
  149. }
  150. if (!string.IsNullOrEmpty(studentScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(studentScoreConditionView.Attribute))
  151. query = query.DynamicWhere(studentScoreConditionView.Attribute, studentScoreConditionView.Condition, studentScoreConditionView.ConditionValue);
  152. query = query.OrderByDescending(x => x.SchoolyearCode)
  153. .ThenBy(x => x.CourseCode)
  154. .ThenBy(x => x.SOCDetailName)
  155. .ThenBy(x => x.LoginID);
  156. return query.ToList();
  157. }
  158. public void StudentSave(IList<SOCDetailStudentScoreView> socDetailStudentScoreViewList)
  159. {
  160. var creUser = CustomPrincipal.Current;
  161. var detailUserIDList = socDetailStudentScoreViewList.Select(x => new { x.SOCDetailID, x.UserID }).ToList();
  162. //DQP_SOCDetailStudent表的数据在上传成果时插入的,这个时候一定会有。
  163. var detailStudentList = SOCDetailScoreDAL.SOCDetailStudentRepository.Entities.SelectByKeys(detailUserIDList);
  164. var studentScoreList = SOCDetailScoreDAL.SOCDetailStudentScoreRepository.Entities.SelectByKeys(detailUserIDList);
  165. var detailStudentHasScoreUpdateList = (from student in detailStudentList
  166. from score in socDetailStudentScoreViewList.Where(x => x.SOCDetailID == student.SOCDetailID && x.UserID == student.UserID)
  167. where score.Score.HasValue
  168. select student).ToList();
  169. detailStudentHasScoreUpdateList.ForEach(x => x.RecordStatus = (int)DQP_SOCDetailSubmitStatus.HasScore);
  170. var detailStudentHasNotScoreUpdateList = (from student in detailStudentList
  171. from score in socDetailStudentScoreViewList.Where(x => x.SOCDetailID == student.SOCDetailID && x.UserID == student.UserID)
  172. where !score.Score.HasValue
  173. select student).ToList();
  174. detailStudentHasNotScoreUpdateList.ForEach(x => x.RecordStatus = (int)DQP_SOCDetailSubmitStatus.Submited);
  175. var detailStudentUpdateList = detailStudentHasScoreUpdateList.Concat(detailStudentHasNotScoreUpdateList).ToList();
  176. #region 要使用批量更新,需要用EF读出来一次,不用理他……
  177. var detailStudentEntityIDList = detailStudentUpdateList.Select(x => x.SOCDetailStudentID).ToList();
  178. var detailStudentEntityList = SOCDetailScoreDAL.SOCDetailStudentRepository.GetList(x => detailStudentEntityIDList.Contains(x.SOCDetailStudentID)).ToList();
  179. #endregion
  180. var insertList = socDetailStudentScoreViewList
  181. .Where(x => x.Score.HasValue)
  182. .Select(x => new DQP_SOCDetailStudentScore
  183. {
  184. SOCDetailStudentScoreID = Guid.NewGuid(),
  185. SOCDetailID = x.SOCDetailID,
  186. UserID = x.UserID,
  187. Score = x.Score,
  188. Credit = (x.Score >= 60 ? x.SOCDetailCredit : 0),
  189. CreateTime = DateTime.Now,
  190. CreateUserID = creUser.UserID
  191. }).ToList();
  192. insertList.ForEach(x => this.SetNewStatus(x));
  193. using (var scope = new TransactionScope(TransactionScopeOption.Required))
  194. {
  195. UnitOfWork.Delete<DQP_SOCDetailStudentScore>(studentScoreList);
  196. UnitOfWork.BulkInsert(insertList);
  197. UnitOfWork.BatchUpdate(detailStudentUpdateList);
  198. scope.Complete();
  199. }
  200. }
  201. public IGridResultSet<FileUploadView> GetSOCDetailStudentAttachmentViewList(ConfiguretView studentAttachmentConditionView, Guid? socDetailID, Guid? userID, int? pageIndex, int? pageSize)
  202. {
  203. if (!socDetailID.HasValue || !userID.HasValue)
  204. {
  205. return new GridResultSet<FileUploadView>();
  206. }
  207. Expression<Func<DQP_SOCDetailStudent, bool>> exp = (x => (x.RecordStatus == (int)DQP_SOCDetailSubmitStatus.Submited || x.RecordStatus == (int)DQP_SOCDetailSubmitStatus.HasScore)
  208. && x.SOCDetailID == socDetailID && x.UserID == userID);
  209. var query = SOCDetailScoreDAL.GetSOCDetailStudentAttachmentView(exp);
  210. return query.ToGridResultSet(pageIndex, pageSize);
  211. }
  212. public IGridResultSet<SOCDetailGroupScoreView> GetSOCDetailGroupScoreViewList(ConfiguretView groupScoreConditionView, Guid? schoolyearID, Guid? collegeID,
  213. int? year, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus, int? pageIndex, int? pageSize)
  214. {
  215. var userID = CustomPrincipal.Current.UserID;
  216. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  217. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  218. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  219. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  220. if (schoolyearID.HasValue)
  221. {
  222. socExp = socExp.And(x => x.SchoolyearID == schoolyearID);
  223. }
  224. if (collegeID.HasValue)
  225. {
  226. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  227. }
  228. if (year.HasValue)
  229. {
  230. gradeExp = gradeExp.And(x => x.GradeID == year);
  231. }
  232. if (standardID.HasValue)
  233. {
  234. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  235. }
  236. if (classmajorID.HasValue)
  237. {
  238. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  239. }
  240. if (coursematerialID.HasValue)
  241. {
  242. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  243. }
  244. var query = SOCDetailScoreDAL.GetSOCDetailGroupScoreView(userID, socExp, facultyExp, gradeExp, classExp);
  245. if (recordStatus.HasValue)
  246. {
  247. query = query.Where(x => x.RecordStatus == recordStatus);
  248. }
  249. if (!string.IsNullOrEmpty(groupScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(groupScoreConditionView.Attribute))
  250. query = query.DynamicWhere(groupScoreConditionView.Attribute, groupScoreConditionView.Condition, groupScoreConditionView.ConditionValue);
  251. query = query.OrderByDescending(x => x.SchoolyearCode)
  252. .ThenBy(x => x.CourseCode)
  253. .ThenBy(x=>x.EducationMissionName)
  254. .ThenBy(x => x.SOCDetailName)
  255. .ThenBy(x => x.No);
  256. return query.ToGridResultSet(pageIndex, pageSize);
  257. }
  258. public IGridResultSet<SOCDetailGroupScoreView> GetSOCDetailGroupScoreViewByIDList(ConfiguretView groupScoreConditionView, Guid? socDetailID, Guid? userID, int? pageIndex, int? pageSize)
  259. {
  260. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  261. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  262. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  263. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  264. var query = SOCDetailScoreDAL.GetSOCDetailGroupScoreView(userID.Value, socExp, facultyExp, gradeExp, classExp);
  265. if (socDetailID.HasValue)
  266. {
  267. query = query.Where(x => x.SOCDetailID == socDetailID);
  268. }
  269. if (!string.IsNullOrEmpty(groupScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(groupScoreConditionView.Attribute))
  270. query = query.DynamicWhere(groupScoreConditionView.Attribute, groupScoreConditionView.Condition, groupScoreConditionView.ConditionValue);
  271. query = query.OrderByDescending(x => x.SchoolyearCode)
  272. .ThenBy(x => x.CourseCode)
  273. .ThenBy(x => x.EducationMissionName)
  274. .ThenBy(x => x.SOCDetailName)
  275. .ThenBy(x => x.No);
  276. return query.ToGridResultSet(pageIndex, pageSize);
  277. }
  278. public List<SOCDetailGroupScoreView> GetSOCDetailGroupScoreViewList(ConfiguretView groupScoreConditionView, Guid? schoolyearID, Guid? collegeID,
  279. int? year, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus)
  280. {
  281. var userID = CustomPrincipal.Current.UserID;
  282. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  283. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  284. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  285. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  286. if (schoolyearID.HasValue)
  287. {
  288. socExp = socExp.And(x => x.SchoolyearID == schoolyearID);
  289. }
  290. if (collegeID.HasValue)
  291. {
  292. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  293. }
  294. if (year.HasValue)
  295. {
  296. gradeExp = gradeExp.And(x => x.GradeID == year);
  297. }
  298. if (standardID.HasValue)
  299. {
  300. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  301. }
  302. if (classmajorID.HasValue)
  303. {
  304. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  305. }
  306. if (coursematerialID.HasValue)
  307. {
  308. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  309. }
  310. var query = SOCDetailScoreDAL.GetSOCDetailGroupScoreView(userID, socExp, facultyExp, gradeExp, classExp);
  311. if (recordStatus.HasValue)
  312. {
  313. query = query.Where(x => x.RecordStatus == recordStatus);
  314. }
  315. if (!string.IsNullOrEmpty(groupScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(groupScoreConditionView.Attribute))
  316. query = query.DynamicWhere(groupScoreConditionView.Attribute, groupScoreConditionView.Condition, groupScoreConditionView.ConditionValue);
  317. query = query.OrderByDescending(x => x.SchoolyearCode)
  318. .ThenBy(x => x.CourseCode)
  319. .ThenBy(x => x.SOCDetailName)
  320. .ThenBy(x => x.No);
  321. return query.ToList();
  322. }
  323. public List<SOCDetailGroupScoreView> GetSOCDetailGroupScoreViewByIDList(ConfiguretView groupScoreConditionView, Guid? socDetailID, Guid? userID)
  324. {
  325. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  326. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  327. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  328. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  329. var query = SOCDetailScoreDAL.GetSOCDetailGroupScoreView(userID.Value, socExp, facultyExp, gradeExp, classExp);
  330. if (socDetailID.HasValue)
  331. {
  332. query = query.Where(x => x.SOCDetailID == socDetailID);
  333. }
  334. if (!string.IsNullOrEmpty(groupScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(groupScoreConditionView.Attribute))
  335. query = query.DynamicWhere(groupScoreConditionView.Attribute, groupScoreConditionView.Condition, groupScoreConditionView.ConditionValue);
  336. query = query.OrderByDescending(x => x.SchoolyearCode)
  337. .ThenBy(x => x.CourseCode)
  338. .ThenBy(x => x.SOCDetailName)
  339. .ThenBy(x => x.No);
  340. return query.ToList();
  341. }
  342. [Obsolete]
  343. public void GroupSave(IList<SOCDetailGroupScoreView> socDetailGroupScoreViewList)
  344. {
  345. var userID = CustomPrincipal.Current.UserID;
  346. var groupIDList = socDetailGroupScoreViewList.Select(x => x.SOCDetailGroupID).ToList();
  347. var studentGroupList = SOCDetailScoreDAL.SOCDetailGroupRepository.GetList(x => groupIDList.Contains(x.SOCDetailGroupID), (x => x.CF_Student)).ToList();
  348. var detailUserList = (from studentGroup in studentGroupList
  349. from student in studentGroup.CF_Student
  350. select new { studentGroup.SOCDetailID, student.UserID }).ToList();
  351. var studentScoreList = SOCDetailScoreDAL.SOCDetailStudentScoreRepository.Entities.SelectByKeys(detailUserList);
  352. studentGroupList.ForEach(x =>
  353. {
  354. var socDetailGroupScoreView = socDetailGroupScoreViewList.FirstOrDefault(w => w.SOCDetailGroupID == x.SOCDetailGroupID);
  355. if (socDetailGroupScoreView != null)
  356. {
  357. x.Score = socDetailGroupScoreView.Score;
  358. this.SetModifyStatus(x);
  359. if (socDetailGroupScoreView.Score.HasValue)
  360. {
  361. x.RecordStatus = (int)DQP_SOCDetailSubmitStatus.HasScore;
  362. }
  363. else
  364. {
  365. x.RecordStatus = (int)DQP_SOCDetailSubmitStatus.Submited;
  366. }
  367. }
  368. });
  369. var insertList = (from studentGroup in studentGroupList
  370. join view in socDetailGroupScoreViewList on studentGroup.SOCDetailGroupID equals view.SOCDetailGroupID
  371. from student in studentGroup.CF_Student
  372. where studentGroup.Score.HasValue
  373. select new DQP_SOCDetailStudentScore
  374. {
  375. SOCDetailStudentScoreID = Guid.NewGuid(),
  376. SOCDetailID = studentGroup.SOCDetailID,
  377. UserID = student.UserID,
  378. Score = studentGroup.Score,
  379. Credit = (studentGroup.Score >= 60 ? view.SOCDetailCredit : 0),
  380. CreateTime = DateTime.Now,
  381. CreateUserID = userID,
  382. }).ToList();
  383. using (var scope = new TransactionScope(TransactionScopeOption.Required))
  384. {
  385. UnitOfWork.BatchUpdate(studentGroupList);
  386. UnitOfWork.Delete(studentScoreList);
  387. UnitOfWork.BulkInsert(insertList);
  388. scope.Complete();
  389. }
  390. }
  391. public IGridResultSet<FileUploadView> GetSOCDetailGroupAttachmentViewList(ConfiguretView studentAttachmentConditionView, Guid? socDetailID, Guid? socDetailGroupID, int? pageIndex, int? pageSize)
  392. {
  393. if (!socDetailID.HasValue || !socDetailGroupID.HasValue)
  394. {
  395. return new GridResultSet<FileUploadView>();
  396. }
  397. Expression<Func<DQP_SOCDetailGroup, bool>> exp = (x => (x.RecordStatus == (int)DQP_SOCDetailSubmitStatus.Submited || x.RecordStatus == (int)DQP_SOCDetailSubmitStatus.HasScore)
  398. && x.SOCDetailID == socDetailID && x.SOCDetailGroupID == socDetailGroupID);
  399. var query = SOCDetailScoreDAL.GetSOCDetailGroupAttachmentView(exp);
  400. return query.ToGridResultSet(pageIndex, pageSize);
  401. }
  402. public IGridResultSet<BaseStudentView> GetSOCDetailGroupStudentViewList(ConfiguretView studentAttachmentConditionView,
  403. Guid? socDetailGroupID, int? pageIndex, int? pageSize)
  404. {
  405. if (!socDetailGroupID.HasValue)
  406. {
  407. return new GridResultSet<BaseStudentView>();
  408. }
  409. Expression<Func<DQP_SOCDetailGroup, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  410. && x.SOCDetailGroupID == socDetailGroupID);
  411. var query = SOCDetailScoreDAL.GetSOCDetailGroupStudentView(exp);
  412. return query.OrderBy(x => x.ClassmajorCode).ToGridResultSet(pageIndex, pageSize);
  413. }
  414. public IGridResultSet<BaseStudentView> GetSOCDetailGroupStudentViewList(ConfiguretView studentAttachmentConditionView,
  415. Guid socDetailID, Guid userID, int? pageIndex, int? pageSize)
  416. {
  417. Expression<Func<DQP_SOCDetailGroup, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  418. && x.SOCDetailID == socDetailID && x.CF_Student.Any(w => w.UserID == userID));
  419. var query = SOCDetailScoreDAL.GetSOCDetailGroupStudentView(exp);
  420. return query.OrderBy(x => x.ClassmajorCode).ToGridResultSet(pageIndex, pageSize);
  421. }
  422. public IGridResultSet<SOCDetailRawScoreView> GetSOCDetailRawScoreViewList(ConfiguretView studentScoreConditionView, Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? pageIndex, int? pageSize)
  423. {
  424. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  425. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  426. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  427. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  428. Expression<Func<Sys_User, bool>> userExp = (x => true);
  429. Expression<Func<DQP_SOCDetail, bool>> detailExp = (x => true);
  430. if (schoolyearID.HasValue)
  431. {
  432. socExp = socExp.And(x => x.SchoolyearID == schoolyearID);
  433. }
  434. if (collegeID.HasValue)
  435. {
  436. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  437. }
  438. if (year.HasValue)
  439. {
  440. gradeExp = gradeExp.And(x => x.GradeID == year);
  441. }
  442. if (standardID.HasValue)
  443. {
  444. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  445. }
  446. if (classmajorID.HasValue)
  447. {
  448. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  449. }
  450. if (coursematerialID.HasValue)
  451. {
  452. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  453. }
  454. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  455. var role = RoleServices.GetEnabledTeacherRoleViewList();
  456. var teacherRole = role.Where(x => x.RoleName == "教师");
  457. if (curUser.RoleID == teacherRole.FirstOrDefault().RoleID)
  458. {
  459. detailExp = detailExp.And(x => x.CreateUserID == curUser.UserID);
  460. }
  461. var query = SOCDetailScoreDAL.GetSOCDetailRawScoreView(socExp, detailExp, facultyExp, gradeExp, classExp, userExp);
  462. if (!string.IsNullOrEmpty(studentScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(studentScoreConditionView.Attribute))
  463. query = query.DynamicWhere(studentScoreConditionView.Attribute, studentScoreConditionView.Condition, studentScoreConditionView.ConditionValue);
  464. query = this.GetQueryByDataRangeByDepartment(query);
  465. query = query.OrderByDescending(x => x.SchoolyearCode)
  466. .ThenBy(x => x.CourseCode)
  467. .ThenBy(x => x.SOCDetailName)
  468. .ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo)
  469. .ThenBy(x => x.LoginID);
  470. return query.ToGridResultSet(pageIndex, pageSize);
  471. }
  472. public List<SOCDetailRawScoreView> GetSOCDetailRawScoreViewList(ConfiguretView studentScoreConditionView, Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, Guid? coursematerialID)
  473. {
  474. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  475. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  476. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  477. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  478. Expression<Func<Sys_User, bool>> userExp = (x => true);
  479. Expression<Func<DQP_SOCDetail, bool>> detailExp = (x => true);
  480. if (schoolyearID.HasValue)
  481. {
  482. socExp = socExp.And(x => x.SchoolyearID == schoolyearID);
  483. }
  484. if (collegeID.HasValue)
  485. {
  486. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  487. }
  488. if (year.HasValue)
  489. {
  490. gradeExp = gradeExp.And(x => x.GradeID == year);
  491. }
  492. if (standardID.HasValue)
  493. {
  494. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  495. }
  496. if (classmajorID.HasValue)
  497. {
  498. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  499. }
  500. if (coursematerialID.HasValue)
  501. {
  502. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  503. }
  504. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  505. var role = RoleServices.GetEnabledTeacherRoleViewList();
  506. var teacherRole = role.Where(x => x.RoleName == "教师");
  507. if (curUser.RoleID == teacherRole.FirstOrDefault().RoleID)
  508. {
  509. detailExp = detailExp.And(x => x.CreateUserID == curUser.UserID);
  510. }
  511. var query = SOCDetailScoreDAL.GetSOCDetailRawScoreView(socExp, detailExp, facultyExp, gradeExp, classExp, userExp);
  512. if (!string.IsNullOrEmpty(studentScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(studentScoreConditionView.Attribute))
  513. query = query.DynamicWhere(studentScoreConditionView.Attribute, studentScoreConditionView.Condition, studentScoreConditionView.ConditionValue);
  514. query = this.GetQueryByDataRangeByDepartment(query);
  515. query = query.OrderByDescending(x => x.SchoolyearCode)
  516. .ThenBy(x => x.CourseCode)
  517. .ThenBy(x => x.SOCDetailName)
  518. .ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo)
  519. .ThenBy(x => x.LoginID);
  520. return query.ToList();
  521. }
  522. public void StudentSubmit(Guid userID, IList<SOCDetailStudentKeyView> socDetailStudentKeyViewList)
  523. {
  524. var nowTime = DateTime.Now;
  525. var studentSubmitList = socDetailStudentKeyViewList.Where(x => !x.SOCDetailGroupID.HasValue).Select(x => x.SOCDetailID).ToList();
  526. var groupSubmitList = socDetailStudentKeyViewList.Where(x => x.SOCDetailGroupID.HasValue).Select(x => x.SOCDetailGroupID).ToList();
  527. var studentDetailList = SOCDetailScoreDAL.SOCDetailRepository.GetList(x => studentSubmitList.Contains(x.SOCDetailID),
  528. (x => x.DQP_SOC.EM_Coursematerial),
  529. (x => x.DQP_SOCDetailStudent),
  530. (x => x.DQP_SOCDetailStudent.Select(w => w.DQP_SOCDetailStudentAttachment))).ToList();
  531. var groupDetailList = SOCDetailScoreDAL.SOCDetailGroupRepository.GetList(x => groupSubmitList.Contains(x.SOCDetailGroupID),
  532. (x => x.DQP_SOCDetail.DQP_SOC.EM_Coursematerial),
  533. (x => x.CF_Student),
  534. (x => x.DQP_SOCDetailStudentAttachment)).ToList();
  535. var noAttachmentList = studentDetailList.Where(x => !x.DQP_SOCDetailStudent.Any(w => w.UserID == userID && w.DQP_SOCDetailStudentAttachment.Count > 0))
  536. .Concat(groupDetailList.Where(x => x.CF_Student.Any(w => w.UserID == userID) && x.DQP_SOCDetailStudentAttachment.Count == 0)
  537. .Select(x => x.DQP_SOCDetail)).ToList();
  538. if (noAttachmentList.Count > 0)
  539. {
  540. throw new Exception(string.Join("、", noAttachmentList.Select(x => x.DQP_SOC.EM_Coursematerial.CourseName + "的" + x.Name).ToList())
  541. + "没有上传附件,不能提交。");
  542. }
  543. var errorStatusList = studentDetailList.Where(x => x.DQP_SOCDetailStudent.Where(w => w.UserID == userID)
  544. .Any(w => w.RecordStatus != (int)DQP_SOCDetailSubmitStatus.NotSubmit
  545. && w.RecordStatus != (int)DQP_SOCDetailSubmitStatus.Canceled))
  546. .Concat(groupDetailList.Where(x => x.RecordStatus != (int)DQP_SOCDetailSubmitStatus.NotSubmit
  547. && x.RecordStatus != (int)DQP_SOCDetailSubmitStatus.Canceled)
  548. .Select(x => x.DQP_SOCDetail)).ToList();
  549. if (errorStatusList.Count > 0)
  550. {
  551. throw new Exception(string.Join("、", errorStatusList.Select(x => x.DQP_SOC.EM_Coursematerial.CourseName + "的" + x.Name).ToList())
  552. + "已经提交,不能再次提交。");
  553. }
  554. if (studentSubmitList.Count > 0)
  555. {
  556. this.UnitOfWork.Update<DQP_SOCDetailStudent>((x => new DQP_SOCDetailStudent
  557. {
  558. RecordStatus = (int)DQP_SOCDetailSubmitStatus.Submited,
  559. ModifyUserID = userID,
  560. ModifyTime = nowTime
  561. }),
  562. (x => studentSubmitList.Contains(x.SOCDetailID) && x.UserID == userID));
  563. }
  564. if (groupSubmitList.Count > 0)
  565. {
  566. this.UnitOfWork.Update<DQP_SOCDetailGroup>((x => new DQP_SOCDetailGroup
  567. {
  568. RecordStatus = (int)DQP_SOCDetailSubmitStatus.Submited,
  569. ModifyUserID = userID,
  570. ModifyTime = nowTime
  571. }),
  572. (x => groupSubmitList.Contains(x.SOCDetailGroupID)));
  573. }
  574. }
  575. public List<FileUploadView> GetFileList(Guid? formID)
  576. {
  577. var socDetailGroup = this.SOCDetailScoreDAL.SOCDetailGroupRepository.GetSingle(x => x.SOCDetailGroupID == formID);
  578. if (socDetailGroup != null)
  579. {
  580. return SOCDetailScoreDAL.GetSOCDetailGroupAttachmentView(x => x.SOCDetailGroupID == formID).ToList();
  581. }
  582. else
  583. {
  584. var userID = CustomPrincipal.Current.UserID;
  585. return SOCDetailScoreDAL.GetSOCDetailStudentAttachmentView(x => x.SOCDetailID == formID && x.UserID == userID).ToList();
  586. }
  587. }
  588. public void SaveFile(Guid userID, SOCDetailStudentKeyView socDetailStudentKeyView, IList<FileUploadView> fileList)
  589. {
  590. var socDetailGroup = this.SOCDetailScoreDAL.SOCDetailGroupRepository.GetSingle(x => x.SOCDetailGroupID == socDetailStudentKeyView.SOCDetailGroupID);
  591. if (socDetailGroup != null)
  592. {
  593. var insertList = fileList.Select(x => new DQP_SOCDetailStudentAttachment
  594. {
  595. SOCDetailStudentAttachmentID = Guid.NewGuid(),
  596. SOCDetailGroupID = socDetailStudentKeyView.SOCDetailGroupID,
  597. Name = x.FileName,
  598. Url = x.FileUrl
  599. }).ToList();
  600. insertList.ForEach(x => this.SetNewStatus(x));
  601. using (var scope = new TransactionScope())
  602. {
  603. UnitOfWork.Delete<DQP_SOCDetailStudentAttachment>(x => x.SOCDetailGroupID == socDetailStudentKeyView.SOCDetailGroupID);
  604. UnitOfWork.BulkInsert(insertList);
  605. scope.Complete();
  606. }
  607. }
  608. else
  609. {
  610. bool hasDetailStudent = true;
  611. var socDetailStudent = this.SOCDetailScoreDAL.SOCDetailStudentRepository.GetSingle(x => x.SOCDetailID == socDetailStudentKeyView.SOCDetailID && x.UserID == userID);
  612. if (socDetailStudent == null)
  613. {
  614. hasDetailStudent = false;
  615. socDetailStudent = new DQP_SOCDetailStudent()
  616. {
  617. SOCDetailStudentID = Guid.NewGuid(),
  618. SOCDetailID = socDetailStudentKeyView.SOCDetailID,
  619. UserID = userID
  620. };
  621. this.SetNewStatus(socDetailStudent);
  622. }
  623. var insertList = fileList.Select(x => new DQP_SOCDetailStudentAttachment
  624. {
  625. SOCDetailStudentAttachmentID = Guid.NewGuid(),
  626. SOCDetailStudentID = socDetailStudent.SOCDetailStudentID,
  627. Name = x.FileName,
  628. Url = x.FileUrl
  629. }).ToList();
  630. insertList.ForEach(x => this.SetNewStatus(x));
  631. using (var scope = new TransactionScope())
  632. {
  633. if (!hasDetailStudent)
  634. {
  635. UnitOfWork.BulkInsert(new List<DQP_SOCDetailStudent> { socDetailStudent });
  636. }
  637. else
  638. {
  639. UnitOfWork.Delete<DQP_SOCDetailStudentAttachment>(x => x.SOCDetailStudentID == socDetailStudent.SOCDetailStudentID);
  640. }
  641. UnitOfWork.BulkInsert(insertList);
  642. scope.Complete();
  643. }
  644. }
  645. }
  646. public IList<SOCStudentScoreItemView> GetStudentScoreItemViewList(Guid userID)
  647. {
  648. return this.SOCDetailScoreDAL.GetSOCStudentScoreItemViewQueryable(userID);
  649. }
  650. /// <summary>
  651. /// 获取学生个人成绩预览信息
  652. /// </summary>
  653. /// <param name="userID"></param>
  654. /// <returns></returns>
  655. public SOCStudentScoreTotalView GetStudentScoreTotalView(Guid userID)
  656. {
  657. var student = this.SOCDetailScoreDAL.GetSOCStudentScoreItemView(userID);
  658. return student;
  659. }
  660. public ReturnMessage IsStudentCanUpload(Guid userID, SOCDetailStudentKeyView socDetailStudentKeyView)
  661. {
  662. var nowDate = DateTime.Today;
  663. var socDetailGroup = this.SOCDetailScoreDAL.SOCDetailGroupRepository.GetSingle(x => x.SOCDetailGroupID == socDetailStudentKeyView.SOCDetailGroupID, (x => x.DQP_SOCDetail));
  664. if (socDetailGroup != null)
  665. {
  666. if (socDetailGroup.RecordStatus != (int)DQP_SOCDetailSubmitStatus.NotSubmit && socDetailGroup.RecordStatus != (int)DQP_SOCDetailSubmitStatus.Canceled)
  667. {
  668. return new ReturnMessage { IsSuccess = false, Message = "成果已提交,无法上传。" };
  669. }
  670. if (!(socDetailGroup.DQP_SOCDetail.StartTime <= nowDate && socDetailGroup.DQP_SOCDetail.EndTime >= nowDate))
  671. {
  672. return new ReturnMessage { IsSuccess = false, Message = "现在不是成果上传的时间,暂时无法上传。" };
  673. }
  674. }
  675. else
  676. {
  677. var socDetail = this.SOCDetailScoreDAL.SOCDetailRepository.GetSingle(x => x.SOCDetailID == socDetailStudentKeyView.SOCDetailID, (x => x.DQP_SOCDetailStudent));
  678. if (socDetail != null)
  679. {
  680. if (socDetail.DQP_SOCDetailStudent.Any(w => w.UserID == userID && w.RecordStatus != (int)DQP_SOCDetailSubmitStatus.NotSubmit && w.RecordStatus != (int)DQP_SOCDetailSubmitStatus.Canceled))
  681. {
  682. return new ReturnMessage { IsSuccess = false, Message = "成果已提交,无法上传。" };
  683. }
  684. if (!(socDetail.StartTime <= nowDate && socDetail.EndTime >= nowDate))
  685. {
  686. return new ReturnMessage { IsSuccess = false, Message = "现在不是成果上传的时间,暂时无法上传。" };
  687. }
  688. }
  689. else
  690. {
  691. return new ReturnMessage { IsSuccess = false, Message = "现在不是成果上传的时间,暂时无法上传。" };
  692. }
  693. }
  694. return new ReturnMessage { IsSuccess = true };
  695. }
  696. public IGridResultSet<SOCDetailRawScoreView> GetSOCDetailRawScoreViewList(Guid? coursematerialID, int? startTermID, Guid userID)
  697. {
  698. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  699. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  700. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  701. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  702. Expression<Func<Sys_User, bool>> userExp = (x => true);
  703. Expression<Func<DQP_SOCDetail, bool>> detailExp = (x => true);
  704. if (coursematerialID.HasValue)
  705. {
  706. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  707. }
  708. if (startTermID.HasValue)
  709. {
  710. var student = SOCDetailScoreDAL.StudentRepository.GetSingle(x => x.UserID == userID, (x => x.CF_Classmajor.CF_Grademajor));
  711. var schoolyear = SOCDetailScoreDAL.SchoolyearRepository.GetSingle(x => x.Years == student.CF_Classmajor.CF_Grademajor.GradeID && x.SchoolcodeID == student.CF_Classmajor.CF_Grademajor.SemesterID);
  712. var newSchoolyearValue = schoolyear.Value + startTermID.Value - 1;
  713. var newSchoolyear = SOCDetailScoreDAL.SchoolyearRepository.GetSingle(x => x.Value == newSchoolyearValue);
  714. socExp = socExp.And(x => x.SchoolyearID == newSchoolyear.SchoolyearID);
  715. }
  716. userExp = userExp.And(x => x.UserID == userID);
  717. var query = SOCDetailScoreDAL.GetSOCDetailRawScoreView(socExp, detailExp, facultyExp, gradeExp, classExp, userExp);
  718. query = query.OrderByDescending(x => x.SchoolyearCode)
  719. .ThenBy(x => x.CourseCode)
  720. .ThenBy(x => x.SOCDetailName)
  721. .ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo)
  722. .ThenBy(x => x.LoginID);
  723. return query.ToGridResultSet();
  724. }
  725. public void StudentCancel(IList<Guid> socDetailStudentIDList, string remark)
  726. {
  727. var detailStudentUpdateList = SOCDetailScoreDAL.SOCDetailStudentRepository.GetList(x => socDetailStudentIDList.Contains(x.SOCDetailStudentID)).ToList();
  728. var detailStudentScoreList = SOCDetailScoreDAL.GetStudentScoreBySOCDetailStudent(x => socDetailStudentIDList.Contains(x.SOCDetailStudentID)).ToList();
  729. detailStudentUpdateList.ForEach(x => {
  730. this.SetModifyStatus(x);
  731. x.Remark = remark;
  732. x.RecordStatus = (int)DQP_SOCDetailSubmitStatus.Canceled;
  733. });
  734. using (var scope = new TransactionScope())
  735. {
  736. UnitOfWork.BatchUpdate(detailStudentUpdateList);
  737. UnitOfWork.Delete(detailStudentScoreList);
  738. scope.Complete();
  739. }
  740. }
  741. public void GroupCancel(IList<Guid> socDetailGroupIDList, string remark)
  742. {
  743. var studentGroupList = SOCDetailScoreDAL.SOCDetailGroupRepository.GetList(x => socDetailGroupIDList.Contains(x.SOCDetailGroupID), (x => x.CF_Student)).ToList();
  744. var detailStudentScoreList = SOCDetailScoreDAL.GetStudentScoreBySOCDetailGroup(x => socDetailGroupIDList.Contains(x.SOCDetailGroupID)).ToList();
  745. studentGroupList.ForEach(x =>
  746. {
  747. x.Score = null;
  748. this.SetModifyStatus(x);
  749. x.Remark = remark;
  750. x.RecordStatus = (int)DQP_SOCDetailSubmitStatus.Canceled;
  751. });
  752. using (var scope = new TransactionScope())
  753. {
  754. UnitOfWork.BatchUpdate(studentGroupList);
  755. UnitOfWork.Delete(detailStudentScoreList);
  756. scope.Complete();
  757. }
  758. }
  759. public void SendMessage(List<Guid> userIDList, AnnouncementView announcement)
  760. {
  761. var announcementEntity = AnnouncementDAL.AnnouncementRepository.GetSingle
  762. (x => x.AnnouncementID == announcement.AnnouncementID, (x => x.Sys_User));
  763. if (announcementEntity != null)
  764. {
  765. announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID;
  766. announcementEntity.Title = announcement.Title;
  767. announcementEntity.Content = announcement.Content;
  768. announcementEntity.StartTime = announcement.StartTime;
  769. announcementEntity.EndTime = announcement.EndTime;
  770. this.SetModifyStatus(announcementEntity);
  771. }
  772. else
  773. {
  774. announcementEntity = new Sys_Announcement();
  775. announcementEntity.AnnouncementID = Guid.NewGuid();
  776. announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID;
  777. announcementEntity.Title = announcement.Title;
  778. announcementEntity.Content = announcement.Content;
  779. announcementEntity.StartTime = announcement.StartTime;
  780. announcementEntity.EndTime = announcement.EndTime;
  781. this.SetNewStatus(announcementEntity);
  782. UnitOfWork.Add(announcementEntity);
  783. }
  784. var userList = StudentsDAL.UserRepository.GetList(x => userIDList.Contains(x.UserID)).ToList();
  785. announcementEntity.Sys_User = new HashSet<Sys_User>();
  786. userList.ForEach(x => announcementEntity.Sys_User.Add(x));
  787. UnitOfWork.Commit();
  788. }
  789. public IGridResultSet<SOCDetailRawScoreView> GetSOCDetailGroupRawScoreViewList(ConfiguretView studentScoreConditionView,
  790. Guid socDetailGroupID, int? pageIndex, int? pageSize)
  791. {
  792. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  793. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  794. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  795. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  796. Expression<Func<Sys_User, bool>> userExp = (x => x.CF_Student.DQP_SOCDetailGroup.Any(w => w.SOCDetailGroupID == socDetailGroupID));
  797. Expression<Func<DQP_SOCDetail, bool>> detailExp = (x => x.DQP_SOCDetailGroup.Any(w => w.SOCDetailGroupID == socDetailGroupID));
  798. var query = SOCDetailScoreDAL.GetSOCDetailRawScoreView(socExp, detailExp, facultyExp, gradeExp, classExp, userExp);
  799. query = query.OrderByDescending(x => x.SchoolyearCode)
  800. .ThenBy(x => x.CourseCode)
  801. .ThenBy(x => x.SOCDetailName)
  802. .ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo)
  803. .ThenBy(x => x.LoginID);
  804. return query.ToGridResultSet();
  805. }
  806. public void GroupScoreSave(Guid socDetailGroupID, IList<SOCDetailRawScoreView> socDetailRawScoreViewList)
  807. {
  808. var userID = CustomPrincipal.Current.UserID;
  809. var studentGroup = SOCDetailScoreDAL.SOCDetailGroupRepository.GetSingle(x => x.SOCDetailGroupID == socDetailGroupID, (x => x.CF_Student));
  810. var detailUserList = (from student in studentGroup.CF_Student
  811. select new { studentGroup.SOCDetailID, student.UserID }).ToList();
  812. var studentScoreList = SOCDetailScoreDAL.SOCDetailStudentScoreRepository.Entities.SelectByKeys(detailUserList);
  813. if (!socDetailRawScoreViewList.Any(x => !x.Score.HasValue))
  814. {
  815. studentGroup.RecordStatus = (int)DQP_SOCDetailSubmitStatus.HasScore;
  816. }
  817. else
  818. {
  819. studentGroup.RecordStatus = (int)DQP_SOCDetailSubmitStatus.Submited;
  820. }
  821. this.SetModifyStatus(studentGroup);
  822. var updateGroupList = new List<DQP_SOCDetailGroup>() { studentGroup };
  823. var insertList = (from view in socDetailRawScoreViewList
  824. where view.Score.HasValue
  825. select new DQP_SOCDetailStudentScore
  826. {
  827. SOCDetailStudentScoreID = Guid.NewGuid(),
  828. SOCDetailID = studentGroup.SOCDetailID,
  829. UserID = view.UserID,
  830. Score = view.Score,
  831. Credit = (view.Score >= 60 ? view.SOCDetailCredit : 0),
  832. CreateTime = DateTime.Now,
  833. CreateUserID = userID,
  834. }).ToList();
  835. using (var scope = new TransactionScope(TransactionScopeOption.Required))
  836. {
  837. UnitOfWork.BatchUpdate(updateGroupList);
  838. UnitOfWork.Delete(studentScoreList);
  839. UnitOfWork.BulkInsert(insertList);
  840. scope.Complete();
  841. }
  842. }
  843. public SOCDetailStudentScoreView GetSOCDetialView(Guid? SOCDetailID)
  844. {
  845. Expression<Func<DQP_SOCDetail, bool>> socExp = (x => x.SOCDetailID==SOCDetailID);
  846. var userID = CustomPrincipal.Current.UserID;
  847. var q = SOCDetailScoreDAL.GetSOCDetailView(socExp, userID);
  848. return q.FirstOrDefault();
  849. }
  850. public List<SOCDetailStudentScoreView> Download(ConfiguretView studentScoreConditionView, Guid? schoolyearID,
  851. Guid? collegeID, int? year, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus,List<Guid?> IDList)
  852. {
  853. var userID = CustomPrincipal.Current.UserID;
  854. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  855. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  856. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  857. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  858. if (schoolyearID.HasValue)
  859. {
  860. socExp = socExp.And(x => x.SchoolyearID == schoolyearID);
  861. }
  862. if (collegeID.HasValue)
  863. {
  864. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  865. }
  866. if (year.HasValue)
  867. {
  868. gradeExp = gradeExp.And(x => x.GradeID == year);
  869. }
  870. if (standardID.HasValue)
  871. {
  872. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  873. }
  874. if (classmajorID.HasValue)
  875. {
  876. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  877. }
  878. if (coursematerialID.HasValue)
  879. {
  880. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  881. }
  882. var query = SOCDetailScoreDAL.GetSOCDetailView(userID, socExp, facultyExp, gradeExp, classExp);
  883. if (IDList != null)
  884. {
  885. query = query.Where(x => IDList.Contains(x.UserID));
  886. }
  887. if (recordStatus.HasValue)
  888. {
  889. query = query.Where(x => x.RecordStatus == recordStatus);
  890. }
  891. if (!string.IsNullOrEmpty(studentScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(studentScoreConditionView.Attribute))
  892. query = query.DynamicWhere(studentScoreConditionView.Attribute, studentScoreConditionView.Condition, studentScoreConditionView.ConditionValue);
  893. query = query.OrderByDescending(x => x.SchoolyearCode)
  894. .ThenBy(x => x.CourseCode)
  895. .ThenBy(x => x.SOCDetailName)
  896. .ThenBy(x => x.LoginID);
  897. var socDetailList= query.ToList();
  898. return socDetailList;
  899. }
  900. public List<SOCDetailStudentScoreView> GroupListDownload(ConfiguretView studentScoreConditionView,
  901. Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, Guid? coursematerialID, int? recordStatus,List<Guid?> IDList)
  902. {
  903. var userID = CustomPrincipal.Current.UserID;
  904. List<SOCDetailStudentScoreView> DetailList = new List<SOCDetailStudentScoreView>();
  905. Expression<Func<DQP_SOC, bool>> socExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  906. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  907. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  908. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  909. if (schoolyearID.HasValue)
  910. {
  911. socExp = socExp.And(x => x.SchoolyearID == schoolyearID);
  912. }
  913. if (collegeID.HasValue)
  914. {
  915. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  916. }
  917. if (year.HasValue)
  918. {
  919. gradeExp = gradeExp.And(x => x.GradeID == year);
  920. }
  921. if (standardID.HasValue)
  922. {
  923. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  924. }
  925. if (classmajorID.HasValue)
  926. {
  927. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  928. }
  929. if (coursematerialID.HasValue)
  930. {
  931. socExp = socExp.And(x => x.CoursematerialID == coursematerialID);
  932. }
  933. var query = SOCDetailScoreDAL.GetSOCDetailGroup(userID, socExp, facultyExp, gradeExp, classExp);
  934. if (recordStatus.HasValue)
  935. {
  936. query = query.Where(x => x.RecordStatus == recordStatus);
  937. }
  938. if (IDList != null)
  939. {
  940. query = query.Where(x => IDList.Contains(x.SOCDetailGroupID));
  941. }
  942. if (!string.IsNullOrEmpty(studentScoreConditionView.ConditionValue) && !string.IsNullOrEmpty(studentScoreConditionView.Attribute))
  943. query = query.DynamicWhere(studentScoreConditionView.Attribute, studentScoreConditionView.Condition, studentScoreConditionView.ConditionValue);
  944. query = query.OrderByDescending(x => x.SchoolyearCode)
  945. .ThenBy(x => x.CourseCode)
  946. .ThenBy(x => x.SOCDetailName);
  947. var socDetailList = query.ToList();
  948. foreach(var soc in socDetailList)
  949. {
  950. SOCDetailStudentScoreView Detail = new SOCDetailStudentScoreView();
  951. Detail.EducationMissionName = soc.EducationMissionName;
  952. Detail.CourseName = soc.CourseName;
  953. Detail.SOCDetailName = soc.SOCDetailName;
  954. Detail.LoginID = soc.LoginID;
  955. Detail.Name = soc.Name;
  956. Detail.SOCDetailUrl = soc.SOCDetailUrl;
  957. Detail.FileName = soc.FileName;
  958. DetailList.Add(Detail);
  959. }
  960. return DetailList;
  961. }
  962. }
  963. }