SpecialityScoreSumServices.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.ScoreManage;
  6. using System.Data;
  7. using EMIS.Utility;
  8. using EMIS.ViewModel;
  9. using System.Dynamic;
  10. using EMIS.ViewModel.ScoreManage;
  11. using System.Linq.Expressions;
  12. using EMIS.Entities;
  13. using Bowin.Common.Linq;
  14. using EMIS.DataLogic.Common.Students;
  15. using EMIS.ViewModel.Students;
  16. using EMIS.ViewModel.CacheManage;
  17. using Bowin.Common.Utility;
  18. using System.Text.RegularExpressions;
  19. using NPOI.SS.UserModel;
  20. using NPOI.HSSF.UserModel;
  21. using NPOI.HSSF.Util;
  22. namespace EMIS.CommonLogic.ScoreManage
  23. {
  24. public class SpecialityScoreSumServices : BaseServices, ISpecialityScoreSumServices
  25. {
  26. public SpecialityScoreSumDAL specialityScoreSumDAL { get; set; }
  27. public StudentsDAL StudentsDAL { get; set; }
  28. public SpecialityScoreSummaryView SpecialityScoreSumTable(Guid? collegeID, int? years, int? standardID, int? schoolyearNumID, int? schoolcodeID, Guid? classmajorID, int? inSchoolStatus)
  29. {
  30. Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  31. Expression<Func<CF_Student, bool>> studentExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  32. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  33. SpecialityScoreSummaryView summaryView = new SpecialityScoreSummaryView();
  34. if (collegeID.HasValue)
  35. {
  36. classmajorExp = classmajorExp.And(x => x.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  37. studentExp = studentExp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  38. }
  39. if (years.HasValue)
  40. {
  41. classmajorExp = classmajorExp.And(x => x.CF_Grademajor.GradeID == years);
  42. studentExp = studentExp.And(x => x.CF_Classmajor.CF_Grademajor.GradeID == years);
  43. }
  44. if (standardID.HasValue)
  45. {
  46. classmajorExp = classmajorExp.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  47. studentExp = studentExp.And(x => x.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  48. }
  49. if (classmajorID.HasValue)
  50. {
  51. classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
  52. studentExp = studentExp.And(x => x.ClassmajorID == classmajorID);
  53. }
  54. if (inSchoolStatus.HasValue)
  55. {
  56. studentExp = studentExp.And(x => x.InSchoolStatusID == inSchoolStatus);
  57. }
  58. var courseQuery = specialityScoreSumDAL.GetCoursematerialPlanViewQueryable(classmajorExp, missionClassExp);
  59. if (schoolyearNumID.HasValue)
  60. {
  61. courseQuery = courseQuery.Where(x => x.SchoolyearNumID == schoolyearNumID);
  62. }
  63. if (schoolcodeID.HasValue)
  64. {
  65. courseQuery = courseQuery.Where(x => x.SchoolcodeID == schoolcodeID);
  66. }
  67. courseQuery = courseQuery.OrderBy(x => x.StartTermID).ThenBy(x => x.CourseName);
  68. //先获取当前院系所、学年、专业、学年数、学期
  69. var queryCoursematerialPlan = courseQuery.ToList();
  70. var queryFinallyScore = specialityScoreSumDAL.GetStudentScoreViewQueryable(collegeID, years, schoolyearNumID, schoolcodeID, classmajorID).ToList();
  71. var studentList = StudentsDAL.GetBaseStudentViewQueryable(studentExp).ToList();
  72. summaryView.StudentList = studentList.OrderBy(x => x.LoginID).ToList();
  73. summaryView.SchoolyearNums = new List<SpecialityScoreSummaryYearView>();
  74. //开始建立树形结构,顶层是学年数,从大到小排序
  75. var schoolyearNums = queryCoursematerialPlan.Select(x => x.SchoolyearNumID).Distinct().OrderBy(x => x).ToList();
  76. foreach (var schoolyearNum in schoolyearNums)
  77. {
  78. SpecialityScoreSummaryYearView schoolyearNumView = new SpecialityScoreSummaryYearView();
  79. schoolyearNumView.Title = IdNameExt.GetName(DictionaryItem.CF_SchoolyearNum, schoolyearNum);
  80. schoolyearNumView.SchoolyearNum = schoolyearNum;
  81. schoolyearNumView.CoursematerialNum = 0;
  82. //第二层,学期,按开课学期排序,不是按学期ID
  83. schoolyearNumView.SchoolCodeView = new List<SpecialityScoreSummarySchoolcodeView>();
  84. var schoolcodeList = queryCoursematerialPlan.Where(x => x.SchoolyearNumID == schoolyearNum)
  85. .GroupBy(x => new { x.StartTermID, x.SchoolcodeID })
  86. .Select(x => x.Key).OrderBy(x => x.StartTermID).ToList();
  87. foreach (var schoolCode in schoolcodeList)
  88. {
  89. SpecialityScoreSummarySchoolcodeView schoolCodeView = new SpecialityScoreSummarySchoolcodeView();
  90. schoolCodeView.Title = IdNameExt.GetName(DictionaryItem.CF_Semester, schoolCode.SchoolcodeID);
  91. schoolCodeView.SchoolCodeID = schoolCode.SchoolcodeID;
  92. schoolCodeView.StartTermID = schoolCode.StartTermID;
  93. //第三层,课程,按名称排序
  94. schoolCodeView.CoursematerialList = new List<SpecialityScoreSummaryCoursematerialView>();
  95. var coursematerialList = queryCoursematerialPlan.Where(x => x.SchoolyearNumID == schoolyearNum
  96. && x.SchoolcodeID == schoolCode.SchoolcodeID)
  97. .GroupBy(x => new { x.CoursematerialID, x.CourseName })
  98. .Select(x => x.Key).OrderBy(x => x.CourseName).ToList();
  99. foreach (var coursematerial in coursematerialList)
  100. {
  101. SpecialityScoreSummaryCoursematerialView coursematerialView = new SpecialityScoreSummaryCoursematerialView();
  102. coursematerialView.Title = coursematerial.CourseName;
  103. coursematerialView.CoursematerialID = coursematerial.CoursematerialID;
  104. //该课程所有学生均未录入成绩时,不汇总到专业成绩里
  105. var scoreCount = queryFinallyScore.Where(x => x.SchoolyearNumID == schoolyearNum
  106. && x.StarttermID == schoolCode.StartTermID && x.CoursematerialID == coursematerialView.CoursematerialID).ToList().Count();
  107. if (scoreCount == 0)
  108. continue;
  109. //最后一层,成绩,按学生学号排序
  110. var scoreList = (from s in studentList
  111. join fs in queryFinallyScore.Where(x => x.SchoolyearNumID == schoolyearNum
  112. && x.StarttermID == schoolCode.StartTermID && x.CoursematerialID == coursematerialView.CoursematerialID)
  113. on s.UserID equals fs.UserID into dfs
  114. from efs in dfs.DefaultIfEmpty()
  115. orderby s.LoginID
  116. select new SpecialityScoreSummaryScoreView
  117. {
  118. UserID = s.UserID,
  119. Score = (efs == null ) ?null:efs.TotalScoreStr,
  120. //Score = (efs == null ) ? (int?)null : Convert.ToInt32(Math.Round((Convert.ToDecimal(efs.TotalScore)), 0))
  121. }).ToList();
  122. coursematerialView.ScoreList = scoreList;
  123. schoolCodeView.CoursematerialList.Add(coursematerialView);
  124. schoolyearNumView.CoursematerialNum += 1;
  125. }
  126. //schoolyearNumView.SchoolCodeView.Add(schoolCodeView);
  127. //因为某课程所有学生均未录入成绩时,不汇总到专业成绩里,如果某学期和学年数所有课程没有录入成绩时,不显示一二层学期和学年标题
  128. if (schoolCodeView.CoursematerialList.Count > 0)
  129. schoolyearNumView.SchoolCodeView.Add(schoolCodeView);
  130. }
  131. //summaryView.SchoolyearNums.Add(schoolyearNumView);
  132. //因为某课程所有学生均未录入成绩时,不汇总到专业成绩里,如果某学期和学年数所有课程没有录入成绩时,不显示一二层学期和学年标题
  133. if (schoolyearNumView.SchoolCodeView.Count > 0)
  134. summaryView.SchoolyearNums.Add(schoolyearNumView);
  135. }
  136. return summaryView;
  137. }
  138. /// <summary>
  139. /// 获取标题
  140. /// </summary>
  141. /// <param name="collegeID"></param>
  142. /// <param name="years"></param>
  143. /// <param name="specialtyID"></param>
  144. /// <param name="schoolyearNumID"></param>
  145. /// <param name="schoolcodeID"></param>
  146. /// <param name="classmajorID"></param>
  147. /// <returns></returns>
  148. public List<string> SpecialityScoreSumTableTitle(Guid? collegeID, int? years, Guid? specialtyID, int? schoolyearNumID, int? schoolcodeID, Guid? classmajorID)
  149. {
  150. List<string> list = new List<string>();
  151. //var dynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_SchoolyearNum);
  152. //if (schoolyearNumID.HasValue)
  153. // dynamicTypes = dynamicTypes.Where(x => x.Value == schoolyearNumID);
  154. ////先获取当前院系所、学年、专业、学年数、学期
  155. //var queryCoursematerialPlan = specialityScoreSumDAL.GetCoursematerialPlanViewQueryable(collegeID, years, specialtyID, schoolyearNumID, schoolcodeID).ToList();
  156. //list.Add("次序");
  157. //list.Add("学号");
  158. //list.Add("姓名");
  159. ////按学年数来分课程列
  160. //foreach (var dynamicType in dynamicTypes)
  161. //{
  162. // var queryCoursematerial = queryCoursematerialPlan.Where(x => x.SchoolyearNumID == dynamicType.Value).ToList();
  163. // foreach (var coursematerial in queryCoursematerial)
  164. // {
  165. // list.Add(coursematerial.CourseName);
  166. // }
  167. //}
  168. return list;
  169. }
  170. public List<CoursematerialPlanView> DynamicTypesCount(Guid? collegeID, int? years, Guid? specialtyID, int? schoolyearNumID, int? schoolcodeID, Guid? classmajorID)
  171. {
  172. //先获取当前院系所、学年、专业、学年数、学期
  173. //var queryCoursematerialPlan = specialityScoreSumDAL.GetCoursematerialPlanViewQueryable(collegeID, years, specialtyID, schoolyearNumID, schoolcodeID).ToList();
  174. //return queryCoursematerialPlan;
  175. return new List<CoursematerialPlanView>();
  176. }
  177. /// <summary>
  178. /// 获取学年学期
  179. /// </summary>
  180. /// <param name="collegeID"></param>
  181. /// <param name="years"></param>
  182. /// <param name="specialtyID"></param>
  183. /// <param name="schoolyearNumID"></param>
  184. /// <param name="schoolcodeID"></param>
  185. /// <param name="classmajorID"></param>
  186. /// <returns></returns>
  187. public List<EMIS.Entities.CF_Schoolyear> ScoreSchoolyear(Guid? collegeID, int? years, Guid? specialtyID, int? schoolyearNumID, int? schoolcodeID, Guid? classmajorID)
  188. {
  189. var querySchoolyear = specialityScoreSumDAL.GetFinallyScoreQueryable(collegeID, years, schoolyearNumID, schoolcodeID, classmajorID).OrderBy(x => x.CF_Schoolyear.Code).Select(x => x.CF_Schoolyear).Distinct().ToList();
  190. return querySchoolyear;
  191. }
  192. public void ExportSpecialityScoreSumTable(Guid? collegeID, int? years, int? standardID, int? schoolyearNumID, int? schoolcodeID, Guid? classmajorID, int? inSchoolStatus)
  193. {
  194. string html = "";
  195. NpoiExcelHelper neh = new NpoiExcelHelper();
  196. var specialtyScoreSummaryView = this.SpecialityScoreSumTable(collegeID, years, standardID, schoolyearNumID, schoolcodeID, classmajorID, inSchoolStatus);
  197. Func<IWorkbook, HSSFCellStyle> noPassStyleFunc = (x =>
  198. {
  199. var style = (HSSFCellStyle)x.CreateCellStyle();
  200. style.BorderBottom = BorderStyle.THIN;
  201. style.BorderLeft = BorderStyle.THIN;
  202. style.BorderRight = BorderStyle.THIN;
  203. style.BorderTop = BorderStyle.THIN;
  204. style.Alignment = HorizontalAlignment.CENTER;
  205. style.VerticalAlignment = VerticalAlignment.CENTER;
  206. var font = (HSSFFont)x.CreateFont();
  207. font.FontHeightInPoints = 12;
  208. font.Boldweight = (short)FontBoldWeight.BOLD;
  209. font.Color = HSSFColor.RED.index;
  210. style.SetFont(font);
  211. return style;
  212. });
  213. List<NpoiExcelCellStyle> styleList = new List<NpoiExcelCellStyle>();
  214. var dtResult = new DataTable();
  215. if (specialtyScoreSummaryView != null)
  216. {
  217. var detail = new List<string>();
  218. var firstRow = new List<string>();
  219. var secondRow = new List<string>();
  220. var thirdRow = new List<string>();
  221. var forthRow = new List<List<string>>();
  222. var detailRow = new List<string>();
  223. //生成第一、二、三行表头,学年和学期和课程
  224. //第一行开头
  225. firstRow.Add("<tr>");
  226. firstRow.Add("<td rowspan=\"2\" colspan=\"3\" row=\"0\" col=\"0\">学期</td>");
  227. //第二行开头
  228. secondRow.Add("<tr>");
  229. //第三行开头
  230. thirdRow.Add("<tr>");
  231. thirdRow.Add("<td rowspan=\"0\" colspan=\"0\" row=\"2\" col=\"0\">次序</td>");
  232. thirdRow.Add("<td rowspan=\"0\" colspan=\"0\" row=\"2\" col=\"1\">学号</td>");
  233. thirdRow.Add("<td rowspan=\"0\" colspan=\"0\" row=\"2\" col=\"2\">姓名</td>");
  234. for (var i = 0; i < specialtyScoreSummaryView.StudentList.Count; i++)
  235. {
  236. var student = specialtyScoreSummaryView.StudentList[i];
  237. var studentColumns = new List<string>();
  238. studentColumns.Add("<tr>");
  239. studentColumns.Add("<td rowspan=\"0\" colspan=\"0\" row=\"" + (5 + i).ToString() + "\" col=\"0\">" + (i + 1).ToString() + "</td>");
  240. studentColumns.Add("<td rowspan=\"0\" colspan=\"0\" row=\"" + (5 + i).ToString() + "\" col=\"1\">" + student.LoginID + "</td>");
  241. studentColumns.Add("<td rowspan=\"0\" colspan=\"0\" row=\"" + (5 + i).ToString() + "\" col=\"2\">" + student.UserName + "</td>");
  242. forthRow.Add(studentColumns);
  243. }
  244. //前三行明细
  245. var index = 3;
  246. for (var i = 0; i < specialtyScoreSummaryView.SchoolyearNums.Count; i++)
  247. {
  248. var schoolyearNum = specialtyScoreSummaryView.SchoolyearNums[i];
  249. firstRow.Add("<td rowspan=\"1\" colspan=\"" + schoolyearNum.CoursematerialNum + "\" row=\"0\" col=\"" + index.ToString() + "\">" + schoolyearNum.Title + "</td>");
  250. for (var j = 0; j < schoolyearNum.SchoolCodeView.Count; j++)
  251. {
  252. var schoolcode = schoolyearNum.SchoolCodeView[j];
  253. secondRow.Add("<td rowspan=\"1\" colspan=\"" + schoolcode.CoursematerialList.Count + "\" row=\"1\" col=\"" + index.ToString() + "\">" + schoolcode.Title + "</td>");
  254. for (var k = 0; k < schoolcode.CoursematerialList.Count; k++)
  255. {
  256. var coursematerial = schoolcode.CoursematerialList[k];
  257. thirdRow.Add("<td rowspan=\"0\" colspan=\"0\" row=\"2\" col=\"" + index.ToString() + "\">" + coursematerial.Title + "</td>");
  258. for (var l = 0; l < coursematerial.ScoreList.Count; l++)
  259. {
  260. var score = coursematerial.ScoreList[l];
  261. if (score.Score != "" && score.Score != null)
  262. {
  263. decimal tmpScore;
  264. if (decimal.TryParse(score.Score, out tmpScore))
  265. {
  266. if (tmpScore < 60)
  267. {
  268. styleList.Add(new NpoiExcelCellStyle { ColumnIndex = index, RowIndex = l + 3, StyleFunc = noPassStyleFunc });
  269. }
  270. }
  271. else
  272. {
  273. styleList.Add(new NpoiExcelCellStyle { ColumnIndex = index, RowIndex = l + 3, StyleFunc = noPassStyleFunc });
  274. }
  275. forthRow[l].Add("<td rowspan=\"0\" colspan=\"0\" row=\"" + (l + 3).ToString() + "\" col=\"" + index.ToString() + "\">" + score.Score.ToString() + "</td>");
  276. }
  277. else
  278. {
  279. forthRow[l].Add("<td rowspan=\"0\" colspan=\"0\" row=\"" + (l + 3).ToString() + "\" col=\"" + index.ToString() + "\"></td>");
  280. }
  281. }
  282. index++;
  283. }
  284. }
  285. }
  286. //第一行结尾
  287. firstRow.Add("</tr>");
  288. //第二行结尾
  289. secondRow.Add("</tr>");
  290. //第三行结尾
  291. thirdRow.Add("</tr>");
  292. html += string.Join("", firstRow);
  293. html += string.Join("", secondRow);
  294. html += string.Join("", thirdRow);
  295. for (var i = 0; i < specialtyScoreSummaryView.StudentList.Count; i++)
  296. {
  297. html += string.Join("", forthRow[i]);
  298. html += "</tr>";
  299. }
  300. }
  301. neh.PresetCellStyle(styleList);
  302. neh.ExportTable(html, "专业成绩汇总");
  303. }
  304. }
  305. }