NewReportServices.cs 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  1. using Aspose.Cells;
  2. using EMIS.CommonLogic.UniversityManage.SpecialtyClassManage;
  3. using EMIS.DataLogic.Repositories;
  4. using EMIS.DataLogic.UniversityManage.SpecialtyClassManage;
  5. using EMIS.Utility;
  6. using EMIS.ViewModel.Report;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Data.SqlClient;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. namespace EMIS.CommonLogic.Report
  15. {
  16. public class NewReportServices: BaseServices, INewReportServices
  17. {
  18. public ClassmajorDAL ClassmajorDAL { get; set; }
  19. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  20. public MemoryStream TeacherselfSchedulingPDF(Guid SchoolyearID, Guid? UserID)
  21. {
  22. ReportHelper rh = new ReportHelper();
  23. MemoryStream ms = new MemoryStream();
  24. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  25. string sql2 = rh.GetReportSql("EducationScheduling/TeacherselfSchedulingView.sql");
  26. List<SqlParameter> sParams = new List<SqlParameter>();
  27. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  28. if (UserID.HasValue)
  29. {
  30. sParams.Add(new SqlParameter("@UserID", UserID));
  31. }
  32. else
  33. {
  34. sParams.Add(new SqlParameter("@UserID", DBNull.Value));
  35. }
  36. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  37. var wk = rh.GetReportTemple("EducationScheduling/TeacherselfSchedulingView.xlsx");
  38. var ws = wk.Worksheets[0];
  39. string title = "{0}{1}学期课程表-{2}", code = "", staffName = "";
  40. if (ds.Tables[1].Rows.Count > 0)
  41. {
  42. code = ds.Tables[1].Rows[0]["Code"].ToString();
  43. staffName = ds.Tables[1].Rows[0]["StaffName"].ToString();
  44. }
  45. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, staffName);
  46. //聚合唯一
  47. //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
  48. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
  49. dtShow.DefaultView.Sort = "StartTimes asc";
  50. dtShow = dtShow.DefaultView.ToTable();
  51. int lineEnd = 2;
  52. for (int i = 0; i < dtShow.Rows.Count; i++)
  53. {
  54. string col1Format = "{0}\n{1}";
  55. ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
  56. string condition = "StartTimes='{0}'";
  57. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "MinWeekNum asc");
  58. int lineMax = 0;
  59. for (int j = 0; j < weekRows.Count(); j++)
  60. {
  61. int weekDay = (int)weekRows[j]["Weekday"];
  62. //weekDay += 1;
  63. var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
  64. try
  65. {
  66. StringBuilder sbCell = new StringBuilder();
  67. sbCell.AppendLine(weekRows[j]["Name"].ToString());
  68. if (weekRows[j]["StudentCount"] != DBNull.Value)
  69. {
  70. sbCell.Append("(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
  71. }
  72. sbCell.AppendLine(weekRows[j]["ClassroomName"].ToString());
  73. if (weekRows[j]["WeekNums"] != DBNull.Value)
  74. {
  75. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  76. sbCell.AppendFormat("第{0}周\n", weekNum);
  77. }
  78. if (weekRows[j]["TeacherName"] != DBNull.Value)
  79. {
  80. sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
  81. }
  82. curCell.Value += sbCell.ToString();
  83. if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
  84. {
  85. string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  86. curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
  87. }
  88. //curCell.PutValue(sbCell.ToString());
  89. }
  90. catch
  91. {
  92. }
  93. }
  94. var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
  95. mergeRange.Merge();
  96. var style1 = rh.BuildBorderStyle(wk);
  97. StyleFlag stFlag1 = new StyleFlag();
  98. stFlag1.Borders = true;
  99. mergeRange.ApplyStyle(style1, stFlag1);
  100. var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
  101. StyleFlag stFlag2 = new StyleFlag();
  102. stFlag2.LeftBorder = true;
  103. stFlag2.RightBorder = true;
  104. weekRange.ApplyStyle(style1, stFlag2);
  105. StyleFlag stFlag3 = new StyleFlag();
  106. stFlag3.BottomBorder = true;
  107. ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
  108. lineEnd = lineEnd + lineMax + 1;
  109. }
  110. ws.AutoFitRows();
  111. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  112. return ms;
  113. }
  114. public MemoryStream StudentForTeacherSchedulingPDF(Guid SchoolyearID, Guid StudentNo)
  115. {
  116. ReportHelper rh = new ReportHelper();
  117. MemoryStream ms = new MemoryStream();
  118. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  119. string sql2 = rh.GetReportSql("EducationScheduling/StudentForTeacherSchedulingView.sql");
  120. List<SqlParameter> sParams = new List<SqlParameter>();
  121. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  122. sParams.Add(new SqlParameter("@StudentNo", StudentNo));
  123. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  124. var wk = rh.GetReportTemple("EducationScheduling/StudentForTeacherSchedulingView.xlsx");
  125. var ws = wk.Worksheets[0];
  126. string title = "{0}{1}学期课程表-{2}", code = "", classMajorName = "";
  127. if (ds.Tables[1].Rows.Count > 0)
  128. {
  129. code = ds.Tables[1].Rows[0]["Code"].ToString();
  130. classMajorName = ds.Tables[1].Rows[0]["ClassmajorName"].ToString();
  131. }
  132. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classMajorName);
  133. //聚合唯一
  134. //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
  135. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
  136. dtShow.DefaultView.Sort = "StartTimes asc";
  137. dtShow = dtShow.DefaultView.ToTable();
  138. int lineEnd = 2;
  139. for (int i = 0; i < dtShow.Rows.Count; i++)
  140. {
  141. string col1Format = "{0}\n{1}";
  142. ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
  143. string condition = "StartTimes='{0}'";
  144. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "MinWeekNum asc");
  145. int lineMax = 0;
  146. for (int j = 0; j < weekRows.Count(); j++)
  147. {
  148. int weekDay = (int)weekRows[j]["Weekday"];
  149. //weekDay += 1;
  150. var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
  151. try
  152. {
  153. StringBuilder sbCell = new StringBuilder();
  154. sbCell.AppendLine(weekRows[j]["Name"].ToString());
  155. if (weekRows[j]["ClassroomName"] != DBNull.Value)
  156. {
  157. sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
  158. }
  159. if (weekRows[j]["WeekNums"] != DBNull.Value)
  160. {
  161. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  162. sbCell.AppendFormat("第{0}周\n", weekNum);
  163. }
  164. if (weekRows[j]["TeacherName"] != DBNull.Value)
  165. {
  166. sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
  167. }
  168. curCell.Value += sbCell.ToString();
  169. if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
  170. {
  171. string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  172. curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
  173. }
  174. //curCell.PutValue(sbCell.ToString());
  175. }
  176. catch
  177. {
  178. }
  179. }
  180. var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
  181. mergeRange.Merge();
  182. var style1 = rh.BuildBorderStyle(wk);
  183. StyleFlag stFlag1 = new StyleFlag();
  184. stFlag1.Borders = true;
  185. mergeRange.ApplyStyle(style1, stFlag1);
  186. var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
  187. StyleFlag stFlag2 = new StyleFlag();
  188. stFlag2.LeftBorder = true;
  189. stFlag2.RightBorder = true;
  190. weekRange.ApplyStyle(style1, stFlag2);
  191. StyleFlag stFlag3 = new StyleFlag();
  192. stFlag3.BottomBorder = true;
  193. ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
  194. lineEnd = lineEnd + lineMax + 1;
  195. }
  196. ws.AutoFitRows();
  197. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  198. return ms;
  199. }
  200. public MemoryStream TeacherSchedulingPDF(Guid SchoolyearID, Guid? CollegeID, Guid? UserID)
  201. {
  202. ReportHelper rh = new ReportHelper();
  203. MemoryStream ms = new MemoryStream();
  204. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  205. string sql2 = rh.GetReportSql("EducationScheduling/TeacherSchedulingView.sql");
  206. List<SqlParameter> sParams = new List<SqlParameter>();
  207. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  208. if (CollegeID.HasValue)
  209. {
  210. sParams.Add(new SqlParameter("@CollegeID", CollegeID));
  211. }
  212. else
  213. {
  214. sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
  215. }
  216. if (UserID.HasValue)
  217. {
  218. sParams.Add(new SqlParameter("@UserID", UserID));
  219. }
  220. else
  221. {
  222. sParams.Add(new SqlParameter("@UserID", DBNull.Value));
  223. }
  224. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  225. var wk = rh.GetReportTemple("EducationScheduling/TeacherSchedulingView.xlsx");
  226. var ws = wk.Worksheets[0];
  227. string title = "{0}{1}学期课程表-{2}", code = "", staffName = "";
  228. if (ds.Tables[1].Rows.Count > 0)
  229. {
  230. code = ds.Tables[1].Rows[0]["Code"].ToString();
  231. staffName = ds.Tables[1].Rows[0]["StaffName"].ToString();
  232. }
  233. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, staffName);
  234. //聚合唯一
  235. //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
  236. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
  237. dtShow.DefaultView.Sort = "StartTimes asc";
  238. dtShow = dtShow.DefaultView.ToTable();
  239. int lineEnd = 2;
  240. for (int i = 0; i < dtShow.Rows.Count; i++)
  241. {
  242. string col1Format = "{0}\n{1}";
  243. ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
  244. string condition = "StartTimes='{0}'";
  245. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "StartTimes asc");
  246. int lineMax = 0;
  247. for (int j = 0; j < weekRows.Count(); j++)
  248. {
  249. int weekDay = (int)weekRows[j]["Weekday"];
  250. //weekDay += 1;
  251. var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
  252. try
  253. {
  254. StringBuilder sbCell = new StringBuilder();
  255. sbCell.AppendLine(weekRows[j]["Name"].ToString());
  256. sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
  257. if (weekRows[j]["ClassroomName"] != DBNull.Value)
  258. {
  259. sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
  260. }
  261. if (weekRows[j]["WeekNums"] != DBNull.Value)
  262. {
  263. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  264. sbCell.AppendFormat("第{0}周\n", weekNum);
  265. }
  266. if (weekRows[j]["TeacherName"] != DBNull.Value)
  267. {
  268. sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
  269. }
  270. curCell.Value += sbCell.ToString();
  271. if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
  272. {
  273. string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  274. curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
  275. }
  276. //curCell.PutValue(sbCell.ToString());
  277. }
  278. catch
  279. {
  280. }
  281. }
  282. var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
  283. mergeRange.Merge();
  284. var style1 = rh.BuildBorderStyle(wk);
  285. StyleFlag stFlag1 = new StyleFlag();
  286. stFlag1.Borders = true;
  287. mergeRange.ApplyStyle(style1, stFlag1);
  288. var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
  289. StyleFlag stFlag2 = new StyleFlag();
  290. stFlag2.LeftBorder = true;
  291. stFlag2.RightBorder = true;
  292. weekRange.ApplyStyle(style1, stFlag2);
  293. StyleFlag stFlag3 = new StyleFlag();
  294. stFlag3.BottomBorder = true;
  295. ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
  296. lineEnd = lineEnd + lineMax + 1;
  297. }
  298. ws.AutoFitRows();
  299. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  300. return ms;
  301. }
  302. public MemoryStream TeacherPrintingSchedulingPDF(Guid SchoolyearID, Guid? CollegeID)
  303. {
  304. try
  305. {
  306. ReportHelper rh = new ReportHelper();
  307. MemoryStream ms = new MemoryStream();
  308. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  309. string sql2 = rh.GetReportSql("EducationScheduling/TeacherSchedulingView.sql");
  310. var wk = rh.GetReportTemple("EducationScheduling/TeacherSchedulingView.xlsx");
  311. var templateSheetCount = wk.Worksheets.Count;
  312. List<SqlParameter> teacherParams = new List<SqlParameter>();
  313. teacherParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  314. if (CollegeID.HasValue)
  315. {
  316. teacherParams.Add(new SqlParameter("@CollegeID", CollegeID));
  317. }
  318. else
  319. {
  320. teacherParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
  321. }
  322. teacherParams.Add(new SqlParameter("@UserID", DBNull.Value));
  323. var teacherds = this.UnitOfWork.QuerySQL(sql2, teacherParams);
  324. var tsReportViewList = DateTableHelper.DataTableToList<TeacherSchedulingView>(teacherds.Tables[0]);
  325. List<Guid?> teacherIDList = tsReportViewList.Select(x => x.UserID).Distinct().ToList();
  326. for (int i = templateSheetCount; i < teacherIDList.Count; i += templateSheetCount)
  327. {
  328. for (int index = 0; index < templateSheetCount; index++)
  329. {
  330. wk.Worksheets.AddCopy(index); //.CopyTo(wk, "Sheet" + (i + 1).ToString(), true, true);
  331. }
  332. }
  333. for (int m = 0; m < teacherIDList.Count(); m++)
  334. {
  335. var userID = teacherIDList[m];
  336. List<SqlParameter> sParams = new List<SqlParameter>();
  337. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  338. if (CollegeID.HasValue)
  339. {
  340. sParams.Add(new SqlParameter("@CollegeID", CollegeID));
  341. }
  342. else
  343. {
  344. sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
  345. }
  346. sParams.Add(new SqlParameter("@UserID", userID));
  347. //if (UserID.HasValue)
  348. //{
  349. // sParams.Add(new SqlParameter("@UserID", UserID));
  350. //}
  351. //else
  352. //{
  353. // sParams.Add(new SqlParameter("@UserID", DBNull.Value));
  354. //}
  355. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  356. var ws = wk.Worksheets[m];
  357. string title = "{0}{1}学期课程表-{2}", code = "", staffName = "";
  358. if (ds.Tables[1].Rows.Count > 0)
  359. {
  360. code = ds.Tables[1].Rows[0]["Code"].ToString();
  361. staffName = ds.Tables[1].Rows[0]["StaffName"].ToString();
  362. }
  363. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, staffName);
  364. //聚合唯一
  365. //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
  366. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
  367. dtShow.DefaultView.Sort = "StartTimes asc";
  368. dtShow = dtShow.DefaultView.ToTable();
  369. int lineEnd = 2;
  370. for (int i = 0; i < dtShow.Rows.Count; i++)
  371. {
  372. string col1Format = "{0}\n{1}";
  373. ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
  374. string condition = "StartTimes='{0}'";
  375. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "StartTimes asc");
  376. int lineMax = 0;
  377. for (int j = 0; j < weekRows.Count(); j++)
  378. {
  379. int weekDay = (int)weekRows[j]["Weekday"];
  380. //weekDay += 1;
  381. var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
  382. try
  383. {
  384. StringBuilder sbCell = new StringBuilder();
  385. sbCell.AppendLine(weekRows[j]["Name"].ToString());
  386. sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
  387. if (weekRows[j]["ClassroomName"] != DBNull.Value)
  388. {
  389. sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
  390. }
  391. if (weekRows[j]["WeekNums"] != DBNull.Value)
  392. {
  393. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  394. sbCell.AppendFormat("第{0}周\n", weekNum);
  395. }
  396. if (weekRows[j]["TeacherName"] != DBNull.Value)
  397. {
  398. sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
  399. }
  400. curCell.Value += sbCell.ToString();
  401. if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
  402. {
  403. string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  404. curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
  405. }
  406. //curCell.PutValue(sbCell.ToString());
  407. }
  408. catch
  409. {
  410. }
  411. }
  412. var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
  413. mergeRange.Merge();
  414. var style1 = rh.BuildBorderStyle(wk);
  415. StyleFlag stFlag1 = new StyleFlag();
  416. stFlag1.Borders = true;
  417. mergeRange.ApplyStyle(style1, stFlag1);
  418. var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
  419. StyleFlag stFlag2 = new StyleFlag();
  420. stFlag2.LeftBorder = true;
  421. stFlag2.RightBorder = true;
  422. weekRange.ApplyStyle(style1, stFlag2);
  423. StyleFlag stFlag3 = new StyleFlag();
  424. stFlag3.BottomBorder = true;
  425. ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
  426. lineEnd = lineEnd + lineMax + 1;
  427. }
  428. ws.AutoFitRows();
  429. }
  430. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  431. return ms;
  432. }
  433. catch (Exception ex)
  434. {
  435. throw ex;
  436. }
  437. }
  438. public MemoryStream ClassmajorSchedulingPDF(Guid SchoolyearID, Guid? CollegeID, Guid? ClassmajorID, int? Years)
  439. {
  440. ReportHelper rh = new ReportHelper();
  441. MemoryStream ms = new MemoryStream();
  442. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  443. string sql2 = rh.GetReportSql("EducationScheduling/ClassmajorWithSchedule.sql");
  444. List<SqlParameter> sParams = new List<SqlParameter>();
  445. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  446. if (CollegeID.HasValue)
  447. {
  448. sParams.Add(new SqlParameter("@CollegeID", CollegeID));
  449. }
  450. else
  451. {
  452. sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
  453. }
  454. if (ClassmajorID.HasValue)
  455. {
  456. sParams.Add(new SqlParameter("@ClassmajorID", ClassmajorID));
  457. }
  458. else
  459. {
  460. sParams.Add(new SqlParameter("@ClassmajorID", DBNull.Value));
  461. }
  462. if (Years.HasValue)
  463. {
  464. sParams.Add(new SqlParameter("@Years", Years));
  465. }
  466. else
  467. {
  468. sParams.Add(new SqlParameter("@Years", DBNull.Value));
  469. }
  470. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  471. var wk = rh.GetReportTemple("EducationScheduling/ClassmajorSchedulingView.xlsx");
  472. var ws = wk.Worksheets[0];
  473. string title = "{0}{1}学期课程表-{2}", code = "", classMajorName = "";
  474. if (ds.Tables[1].Rows.Count > 0)
  475. {
  476. code = ds.Tables[1].Rows[0]["Code"].ToString();
  477. classMajorName = ds.Tables[1].Rows[0]["ClassMajorName"].ToString();
  478. }
  479. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classMajorName);
  480. //聚合唯一
  481. //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
  482. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
  483. dtShow.DefaultView.Sort = "StartTimes asc";
  484. dtShow = dtShow.DefaultView.ToTable();
  485. int lineEnd = 2;
  486. for (int i = 0; i < dtShow.Rows.Count; i++)
  487. {
  488. string col1Format = "{0}\n{1}";
  489. ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
  490. string condition = "StartTimes='{0}'";
  491. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "MinWeekNum asc");
  492. int lineMax = 0;
  493. for (int j = 0; j < weekRows.Count(); j++)
  494. {
  495. int weekDay = (int)weekRows[j]["Weekday"];
  496. //weekDay += 1;
  497. var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
  498. try
  499. {
  500. StringBuilder sbCell = new StringBuilder();
  501. sbCell.AppendLine(weekRows[j]["Name"].ToString());
  502. sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
  503. if (weekRows[j]["ClassroomName"] != DBNull.Value)
  504. {
  505. sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
  506. }
  507. if (weekRows[j]["WeekNums"] != DBNull.Value)
  508. {
  509. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  510. sbCell.AppendFormat("第{0}周\n", weekNum);
  511. }
  512. if (weekRows[j]["TeacherName"] != DBNull.Value)
  513. {
  514. sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
  515. }
  516. curCell.Value += sbCell.ToString();
  517. if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
  518. {
  519. string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  520. curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
  521. }
  522. //curCell.PutValue(sbCell.ToString());
  523. }
  524. catch
  525. {
  526. }
  527. }
  528. var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
  529. mergeRange.Merge();
  530. var style1 = rh.BuildBorderStyle(wk);
  531. StyleFlag stFlag1 = new StyleFlag();
  532. stFlag1.Borders = true;
  533. mergeRange.ApplyStyle(style1, stFlag1);
  534. var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
  535. StyleFlag stFlag2 = new StyleFlag();
  536. stFlag2.LeftBorder = true;
  537. stFlag2.RightBorder = true;
  538. weekRange.ApplyStyle(style1, stFlag2);
  539. StyleFlag stFlag3 = new StyleFlag();
  540. stFlag3.BottomBorder = true;
  541. ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
  542. lineEnd = lineEnd + lineMax + 1;
  543. }
  544. ws.AutoFitRows();
  545. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  546. return ms;
  547. }
  548. public MemoryStream ClassmajorPrintingSchedulingPDF(Guid SchoolyearID, Guid? CollegeID)
  549. {
  550. try
  551. {
  552. ReportHelper rh = new ReportHelper();
  553. MemoryStream ms = new MemoryStream();
  554. var wk = rh.GetReportTemple("EducationScheduling/ClassmajorSchedulingView.xlsx");
  555. var templateSheetCount = wk.Worksheets.Count;
  556. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  557. string sql2 = rh.GetReportSql("EducationScheduling/ClassmajorWithSchedule.sql");
  558. List<SqlParameter> classParams = new List<SqlParameter>();
  559. classParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  560. if (CollegeID.HasValue)
  561. {
  562. //sParams.Add(new SqlParameter("@CollegeID", CollegeID));
  563. classParams.Add(new SqlParameter("@CollegeID", CollegeID));
  564. }
  565. else
  566. {
  567. //sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
  568. classParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
  569. }
  570. classParams.Add(new SqlParameter("@ClassmajorID", DBNull.Value));
  571. classParams.Add(new SqlParameter("@Years", DBNull.Value));
  572. var classds = this.UnitOfWork.QuerySQL(sql2, classParams);
  573. //var classTable = classds.Tables[0];
  574. var cpsReportViewList = DateTableHelper.DataTableToList<ClassmajorPrintingSchedulingReportView>(classds.Tables[0]);
  575. List<Guid?> classmajorIDList = cpsReportViewList.Select(x => x.ClassmajorID).Distinct().ToList();
  576. for (int i = templateSheetCount; i < classmajorIDList.Count; i += templateSheetCount)
  577. {
  578. for (int index = 0; index < templateSheetCount; index++)
  579. {
  580. wk.Worksheets.AddCopy(index); //.CopyTo(wk, "Sheet" + (i + 1).ToString(), true, true);
  581. }
  582. }
  583. for (int claI = 0; claI < classmajorIDList.Count(); claI++)
  584. {
  585. List<SqlParameter> sParams = new List<SqlParameter>();
  586. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  587. if (CollegeID.HasValue)
  588. {
  589. sParams.Add(new SqlParameter("@CollegeID", CollegeID));
  590. }
  591. else
  592. {
  593. sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
  594. }
  595. var ClassmajorID = classmajorIDList[claI];
  596. var cpsReportListByClassmajorID = cpsReportViewList.Where(x => x.ClassmajorID == ClassmajorID).ToList();
  597. sParams.Add(new SqlParameter("@ClassmajorID", ClassmajorID));
  598. sParams.Add(new SqlParameter("@Years", DBNull.Value));
  599. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  600. var ws = wk.Worksheets[claI];
  601. string title = "{0}{1}学期课程表-{2}", code = "", classMajorName = "";
  602. if(ds.Tables.Count == 0)
  603. {
  604. continue;
  605. }
  606. if (cpsReportListByClassmajorID.Count > 0)
  607. {
  608. code = cpsReportListByClassmajorID.FirstOrDefault().Code.ToString();
  609. classMajorName = cpsReportListByClassmajorID.FirstOrDefault().ClassMajorName.ToString();
  610. }
  611. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classMajorName);
  612. //聚合唯一
  613. //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
  614. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
  615. dtShow.DefaultView.Sort = "StartTimes asc";
  616. dtShow = dtShow.DefaultView.ToTable();
  617. int lineEnd = 2;
  618. for (int i = 0; i < dtShow.Rows.Count; i++)
  619. {
  620. string col1Format = "{0}\n{1}";
  621. ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
  622. string condition = "StartTimes='{0}'";
  623. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "MinWeekNum asc");
  624. int lineMax = 0;
  625. for (int j = 0; j < weekRows.Count(); j++)
  626. {
  627. int weekDay = (int)weekRows[j]["Weekday"];
  628. //weekDay += 1;
  629. var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
  630. try
  631. {
  632. StringBuilder sbCell = new StringBuilder();
  633. sbCell.AppendLine(weekRows[j]["Name"].ToString());
  634. sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
  635. if (weekRows[j]["ClassroomName"] != DBNull.Value)
  636. {
  637. sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
  638. }
  639. if (weekRows[j]["WeekNums"] != DBNull.Value)
  640. {
  641. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  642. sbCell.AppendFormat("第{0}周\n", weekNum);
  643. }
  644. if (weekRows[j]["TeacherName"] != DBNull.Value)
  645. {
  646. sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
  647. }
  648. curCell.Value += sbCell.ToString();
  649. if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
  650. {
  651. string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  652. curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
  653. }
  654. //curCell.PutValue(sbCell.ToString());
  655. }
  656. catch
  657. {
  658. }
  659. }
  660. var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
  661. mergeRange.Merge();
  662. var style1 = rh.BuildBorderStyle(wk);
  663. StyleFlag stFlag1 = new StyleFlag();
  664. stFlag1.Borders = true;
  665. mergeRange.ApplyStyle(style1, stFlag1);
  666. var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
  667. StyleFlag stFlag2 = new StyleFlag();
  668. stFlag2.LeftBorder = true;
  669. stFlag2.RightBorder = true;
  670. weekRange.ApplyStyle(style1, stFlag2);
  671. StyleFlag stFlag3 = new StyleFlag();
  672. stFlag3.BottomBorder = true;
  673. ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
  674. lineEnd = lineEnd + lineMax + 1;
  675. }
  676. ws.AutoFitRows();
  677. }
  678. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  679. return ms;
  680. }
  681. catch (Exception ex)
  682. {
  683. throw ex;
  684. }
  685. }
  686. public MemoryStream ClassroomReportPDF(Guid SchoolyearID, Guid? BuildingsInfoID, Guid? ClassroomID)
  687. {
  688. ReportHelper rh = new ReportHelper();
  689. MemoryStream ms = new MemoryStream();
  690. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  691. string sql2 = rh.GetReportSql("EducationScheduling/ClassroomSchedulingView.sql");
  692. List<SqlParameter> sParams = new List<SqlParameter>();
  693. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  694. if (BuildingsInfoID.HasValue)
  695. {
  696. sParams.Add(new SqlParameter("@BuildingsInfoID", BuildingsInfoID));
  697. }
  698. else
  699. {
  700. sParams.Add(new SqlParameter("@BuildingsInfoID", DBNull.Value));
  701. }
  702. if (ClassroomID.HasValue)
  703. {
  704. sParams.Add(new SqlParameter("@ClassroomID", ClassroomID));
  705. }
  706. else
  707. {
  708. sParams.Add(new SqlParameter("@ClassroomID", DBNull.Value));
  709. }
  710. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  711. var wk = rh.GetReportTemple("EducationScheduling/ClassroomSchedulingView.xlsx");
  712. var ws = wk.Worksheets[0];
  713. string title = "{0}{1}学期课程表-{2}", code = "", classroomName = "";
  714. if (ds.Tables[1].Rows.Count > 0)
  715. {
  716. code = ds.Tables[1].Rows[0]["Code"].ToString();
  717. classroomName = ds.Tables[1].Rows[0]["ClassroomName"].ToString();
  718. }
  719. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classroomName);
  720. //聚合唯一
  721. //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
  722. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
  723. dtShow.DefaultView.Sort = "StartTimes asc";
  724. dtShow = dtShow.DefaultView.ToTable();
  725. int lineEnd = 2;
  726. for (int i = 0; i < dtShow.Rows.Count; i++)
  727. {
  728. string col1Format = "{0}\n{1}";
  729. ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
  730. string condition = "StartTimes='{0}'";
  731. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "StartTimes asc");
  732. int lineMax = 0;
  733. for (int j = 0; j < weekRows.Count(); j++)
  734. {
  735. //Name
  736. int weekDay = (int)weekRows[j]["Weekday"];
  737. //weekDay += 1;
  738. var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
  739. try
  740. {
  741. StringBuilder sbCell = new StringBuilder();
  742. sbCell.AppendLine(weekRows[j]["Name"].ToString());
  743. sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
  744. if (weekRows[j]["Name"] != DBNull.Value)
  745. {
  746. sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
  747. }
  748. if (weekRows[j]["WeekNums"] != DBNull.Value)
  749. {
  750. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  751. sbCell.AppendFormat("第{0}周\n", weekNum);
  752. }
  753. if (weekRows[j]["TeacherName"] != DBNull.Value)
  754. {
  755. sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
  756. }
  757. curCell.Value = sbCell.ToString();
  758. //curCell.PutValue(sbCell.ToString());
  759. }
  760. catch
  761. {
  762. }
  763. }
  764. var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
  765. mergeRange.Merge();
  766. var style1 = rh.BuildBorderStyle(wk);
  767. StyleFlag stFlag1 = new StyleFlag();
  768. stFlag1.Borders = true;
  769. mergeRange.ApplyStyle(style1, stFlag1);
  770. var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
  771. StyleFlag stFlag2 = new StyleFlag();
  772. stFlag2.LeftBorder = true;
  773. stFlag2.RightBorder = true;
  774. weekRange.ApplyStyle(style1, stFlag2);
  775. StyleFlag stFlag3 = new StyleFlag();
  776. stFlag3.BottomBorder = true;
  777. ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
  778. lineEnd = lineEnd + lineMax + 1;
  779. }
  780. ws.AutoFitRows();
  781. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  782. return ms;
  783. }
  784. public MemoryStream ClassroomPrintingReportPDF(Guid SchoolyearID, Guid? BuildingsInfoID)
  785. {
  786. try
  787. {
  788. ReportHelper rh = new ReportHelper();
  789. MemoryStream ms = new MemoryStream();
  790. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  791. string sql2 = rh.GetReportSql("EducationScheduling/ClassroomSchedulingView.sql");
  792. var wk = rh.GetReportTemple("EducationScheduling/ClassroomSchedulingView.xlsx");
  793. var templateSheetCount = wk.Worksheets.Count;
  794. List<SqlParameter> roomParams = new List<SqlParameter>();
  795. roomParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  796. if (BuildingsInfoID.HasValue)
  797. {
  798. roomParams.Add(new SqlParameter("@BuildingsInfoID", BuildingsInfoID));
  799. }
  800. else
  801. {
  802. roomParams.Add(new SqlParameter("@BuildingsInfoID", DBNull.Value));
  803. }
  804. roomParams.Add(new SqlParameter("@ClassroomID", DBNull.Value));
  805. var roomds = this.UnitOfWork.QuerySQL(sql2, roomParams);
  806. var csReportViewList = DateTableHelper.DataTableToList<ClassroomSchedulingReportView>(roomds.Tables[0]);
  807. List<Guid?> roomIDList = csReportViewList.Select(x => x.ClassroomID).Distinct().ToList();
  808. for (int i = templateSheetCount; i < roomIDList.Count; i += templateSheetCount)
  809. {
  810. for (int index = 0; index < templateSheetCount; index++)
  811. {
  812. wk.Worksheets.AddCopy(index); //.CopyTo(wk, "Sheet" + (i + 1).ToString(), true, true);
  813. }
  814. }
  815. for (int m = 0; m < roomIDList.Count(); m++)
  816. {
  817. var roomID = roomIDList[m];
  818. List<SqlParameter> sParams = new List<SqlParameter>();
  819. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  820. if (BuildingsInfoID.HasValue)
  821. {
  822. sParams.Add(new SqlParameter("@BuildingsInfoID", BuildingsInfoID));
  823. }
  824. else
  825. {
  826. sParams.Add(new SqlParameter("@BuildingsInfoID", DBNull.Value));
  827. }
  828. sParams.Add(new SqlParameter("@ClassroomID", roomID));
  829. //if (ClassroomID.HasValue)
  830. //{
  831. // sParams.Add(new SqlParameter("@ClassroomID", ClassroomID));
  832. //}
  833. //else
  834. //{
  835. // sParams.Add(new SqlParameter("@ClassroomID", DBNull.Value));
  836. //}
  837. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  838. var ws = wk.Worksheets[m];
  839. string title = "{0}{1}学期课程表-{2}", code = "", classroomName = "";
  840. if (ds.Tables[1].Rows.Count > 0)
  841. {
  842. code = ds.Tables[1].Rows[0]["Code"].ToString();
  843. classroomName = ds.Tables[1].Rows[0]["ClassroomName"].ToString();
  844. }
  845. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classroomName);
  846. //聚合唯一
  847. //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
  848. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
  849. dtShow.DefaultView.Sort = "StartTimes asc";
  850. dtShow = dtShow.DefaultView.ToTable();
  851. int lineEnd = 2;
  852. for (int i = 0; i < dtShow.Rows.Count; i++)
  853. {
  854. string col1Format = "{0}\n{1}";
  855. ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
  856. string condition = "StartTimes='{0}'";
  857. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "StartTimes asc");
  858. int lineMax = 0;
  859. for (int j = 0; j < weekRows.Count(); j++)
  860. {
  861. //Name
  862. int weekDay = (int)weekRows[j]["Weekday"];
  863. //weekDay += 1;
  864. var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
  865. try
  866. {
  867. StringBuilder sbCell = new StringBuilder();
  868. sbCell.AppendLine(weekRows[j]["Name"].ToString());
  869. sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
  870. if (weekRows[j]["Name"] != DBNull.Value)
  871. {
  872. sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
  873. }
  874. if (weekRows[j]["WeekNums"] != DBNull.Value)
  875. {
  876. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  877. sbCell.AppendFormat("第{0}周\n", weekNum);
  878. }
  879. if (weekRows[j]["TeacherName"] != DBNull.Value)
  880. {
  881. sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
  882. }
  883. curCell.Value = sbCell.ToString();
  884. //curCell.PutValue(sbCell.ToString());
  885. }
  886. catch
  887. {
  888. }
  889. }
  890. var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
  891. mergeRange.Merge();
  892. var style1 = rh.BuildBorderStyle(wk);
  893. StyleFlag stFlag1 = new StyleFlag();
  894. stFlag1.Borders = true;
  895. mergeRange.ApplyStyle(style1, stFlag1);
  896. var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
  897. StyleFlag stFlag2 = new StyleFlag();
  898. stFlag2.LeftBorder = true;
  899. stFlag2.RightBorder = true;
  900. weekRange.ApplyStyle(style1, stFlag2);
  901. StyleFlag stFlag3 = new StyleFlag();
  902. stFlag3.BottomBorder = true;
  903. ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
  904. lineEnd = lineEnd + lineMax + 1;
  905. }
  906. ws.AutoFitRows();
  907. }
  908. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  909. return ms;
  910. }
  911. catch (Exception ex)
  912. {
  913. throw ex;
  914. }
  915. }
  916. public MemoryStream DepartmentSchedulingPDF(Guid SchoolyearID, Guid CollegeID, Guid DepartmentID, Guid? HandleModeID)
  917. {
  918. ReportHelper rh = new ReportHelper();
  919. MemoryStream ms = new MemoryStream();
  920. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  921. string sql2 = rh.GetReportSql("EducationScheduling/DepartmentWithSchedule.sql");
  922. List<SqlParameter> sParams = new List<SqlParameter>();
  923. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  924. sParams.Add(new SqlParameter("@CollegeID ", CollegeID));
  925. sParams.Add(new SqlParameter("@DepartmentID", DepartmentID));
  926. if (HandleModeID.HasValue)
  927. {
  928. sParams.Add(new SqlParameter("@HandleModeID", HandleModeID));
  929. }
  930. else
  931. {
  932. sParams.Add(new SqlParameter("@HandleModeID", DBNull.Value));
  933. }
  934. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  935. var wk = rh.GetReportTemple("EducationScheduling/DepartmentWithSchedule.xlsx");
  936. var ws = wk.Worksheets[0];
  937. string title = "{0}{1}学期-{2}课程表", schoolyearCode = "", DepartmentName = "";
  938. if (ds.Tables[1].Rows.Count > 0)
  939. {
  940. schoolyearCode = ds.Tables[1].Rows[0]["SchoolyearCode"].ToString();
  941. DepartmentName = ds.Tables[1].Rows[0]["DepartmentName"].ToString();
  942. }
  943. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], schoolyearCode, DepartmentName);
  944. //聚合唯一
  945. var dtShow = ds.Tables[1].DefaultView.ToTable(true, "CourseName", "EducationMissionClassName", "TotalHours", "StudentCount", "TeacherName", "TitleDesc");
  946. for (int i = 0; i < dtShow.Rows.Count; i++)
  947. {
  948. ws.Cells[i + 2, 0].PutValue(dtShow.Rows[i]["CourseName"]);
  949. ws.Cells[i + 2, 1].PutValue(dtShow.Rows[i]["EducationMissionClassName"]);
  950. ws.Cells[i + 2, 2].PutValue(dtShow.Rows[i]["TotalHours"]);
  951. ws.Cells[i + 2, 3].PutValue(dtShow.Rows[i]["StudentCount"]);
  952. ws.Cells[i + 2, 4].PutValue(dtShow.Rows[i]["TeacherName"]);
  953. ws.Cells[i + 2, 5].PutValue(dtShow.Rows[i]["TitleDesc"]);
  954. //周几方法
  955. try
  956. {
  957. string condition = "CourseName='{0}' and EducationMissionClassName='{1}' and TotalHours='{2}' and StudentCount='{3}' and TeacherName='{4}' and TitleDesc='{5}' ";
  958. var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i].ItemArray), "StartTimes asc");
  959. for (int j = 0; j < weekRows.Count(); j++)
  960. {
  961. int weekDay = (int)weekRows[j]["Weekday"] == 0 ? 7 : (int)weekRows[j]["Weekday"];
  962. weekDay += 5;
  963. var curCell = ws.Cells[i + 2, weekDay];
  964. if (weekRows[j]["ClassroomID"] != DBNull.Value)
  965. {
  966. string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  967. string timeNum = rh.SetNumberMerge(weekRows[j]["Times"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  968. if (curCell.Value != null && curCell.Value.ToString() != "")
  969. {
  970. curCell.Value += " \n";
  971. }
  972. else
  973. {
  974. curCell.Value = "";
  975. }
  976. curCell.Value += string.Format("第{0}周\n第{1}节\n({2})", weekNum, timeNum, weekRows[j]["ClassroomName"]);
  977. }
  978. if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
  979. {
  980. string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  981. curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
  982. }
  983. }
  984. }
  985. catch (Exception ex)
  986. {
  987. var a = ex;
  988. }
  989. }
  990. var style = rh.BuildBorderStyle(wk);
  991. //style.IsTextWrapped = true;
  992. if (dtShow.Rows.Count > 0)
  993. {
  994. var wstrange = ws.Cells.CreateRange(2, 0, dtShow.Rows.Count, 13);
  995. StyleFlag stFlag = new StyleFlag();
  996. stFlag.Borders = true;
  997. wstrange.ApplyStyle(style, stFlag);
  998. }
  999. ws.AutoFitColumns(0, 5);
  1000. ws.AutoFitRows();
  1001. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  1002. return ms;
  1003. }
  1004. public MemoryStream CollegeSchedulingPDF(Guid SchoolyearID, Guid? CollegeID, int? Years)
  1005. {
  1006. ReportHelper rh = new ReportHelper();
  1007. MemoryStream ms = new MemoryStream();
  1008. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  1009. string sql2 = rh.GetReportSql("EducationScheduling/ClassmajorWithSchedule.sql");
  1010. List<SqlParameter> sParams = new List<SqlParameter>();
  1011. sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
  1012. if (CollegeID.HasValue)
  1013. {
  1014. sParams.Add(new SqlParameter("@CollegeID", CollegeID));
  1015. }
  1016. else
  1017. {
  1018. sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
  1019. }
  1020. sParams.Add(new SqlParameter("@ClassmajorID", DBNull.Value));
  1021. if (Years.HasValue)
  1022. {
  1023. sParams.Add(new SqlParameter("@Years", Years));
  1024. }
  1025. else
  1026. {
  1027. sParams.Add(new SqlParameter("@Years", DBNull.Value));
  1028. }
  1029. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  1030. var wk = rh.GetReportTemple("EducationScheduling/CollegeSchedulingView.xlsx");
  1031. var ws = wk.Worksheets[0];
  1032. string title = "{0}{1}学期课程表-{2}", code = "", classMajorName = "";
  1033. if (ds.Tables[1].Rows.Count > 0)
  1034. {
  1035. code = ds.Tables[1].Rows[0]["Code"].ToString();
  1036. classMajorName = ds.Tables[1].Rows[0]["CollegeName"].ToString();
  1037. }
  1038. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classMajorName);
  1039. var dicWeeks = GetDicWeeks();
  1040. var dtTimes = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times").AsEnumerable().OrderBy(o => o.Field<int>("StartTimes")).ToList();
  1041. //表头
  1042. for (int i = 0; i < dicWeeks.Count; i++)
  1043. {
  1044. var rowFirst = i * dtTimes.Count + 2;
  1045. ws.Cells[1, rowFirst].PutValue(dicWeeks[i].Item2);
  1046. for (int j = 0; j < dtTimes.Count; j++)
  1047. {
  1048. string subTitle = "";
  1049. if (dtTimes[j]["Times"] != DBNull.Value)
  1050. {
  1051. subTitle += "<" + dtTimes[j].Field<string>("Times") + ">\n";
  1052. }
  1053. if (dtTimes[j]["TimeDesc"] != DBNull.Value)
  1054. {
  1055. subTitle += dtTimes[j].Field<string>("TimeDesc");
  1056. }
  1057. ws.Cells[2, rowFirst + j].PutValue(subTitle);
  1058. }
  1059. var subTitleRange = ws.Cells.CreateRange(1, rowFirst, 1, dtTimes.Count);
  1060. subTitleRange.Merge();
  1061. }
  1062. ws.Cells.CreateRange(0, 0, 1, dtTimes.Count * dicWeeks.Count + 2).Merge();
  1063. ws.Cells.CreateRange(1, 0, 2, 2).Merge();
  1064. var titleRange = ws.Cells.CreateRange(0, 0, 3, dtTimes.Count * dicWeeks.Count + 2);
  1065. var style = rh.BuildBorderStyle(wk);
  1066. StyleFlag stFlag = new StyleFlag();
  1067. stFlag.Borders = true;
  1068. titleRange.ApplyStyle(style, stFlag);
  1069. //学年和班级聚合
  1070. var dtSecond = ds.Tables[1].DefaultView.ToTable(true, "GrademajorID", "GrademajorName", "ClassMajorID", "ClassMajorName");
  1071. dtSecond.DefaultView.Sort = "GrademajorName asc";
  1072. var dtFirst = dtSecond.DefaultView.ToTable(true, "GrademajorID", "GrademajorName");
  1073. int lineEnd = 3;
  1074. for (int i = 0; i < dtFirst.Rows.Count; i++)
  1075. {
  1076. string condition = "GrademajorID='{0}'";
  1077. var classRows = dtSecond.Select(string.Format(condition, dtFirst.Rows[i]["GrademajorID"]), "ClassMajorName asc");
  1078. int jLineMax = 0;
  1079. for (int j = 0; j < classRows.Count(); j++)
  1080. {
  1081. string conditionItem = "GrademajorID='{0}' and ClassMajorID='{1}'";
  1082. var cellItems = ds.Tables[1].Select(string.Format(conditionItem, classRows[j]["GrademajorID"], classRows[j]["ClassMajorID"]));
  1083. int klineMax = 0;
  1084. for (int k = 0; k < cellItems.Count(); k++)
  1085. {
  1086. int addCol = 2;
  1087. addCol += dtTimes.FindIndex(w => w.Field<int>("StartTimes") == cellItems[k].Field<int>("StartTimes"));
  1088. var curCell = GetCrossTimeCell(ws, cellItems[k].Field<int>("Weekday"), dtTimes.Count, addCol, lineEnd + jLineMax, ref klineMax);
  1089. //var curCell=GetLastCell(ws,(int)cellItems[k]["Weekday"],
  1090. try
  1091. {
  1092. StringBuilder sbCell = new StringBuilder();
  1093. sbCell.AppendLine(cellItems[k]["Name"].ToString());
  1094. sbCell.Append(cellItems[k]["StudentCount"] == DBNull.Value ? "" : "(" + cellItems[k]["StudentCount"].ToString() + "人)\n");
  1095. if (cellItems[k]["Name"] != DBNull.Value)
  1096. {
  1097. sbCell.Append(cellItems[k].Field<string>("ClassroomName") + "\n");
  1098. }
  1099. if (cellItems[k]["WeekNums"] != DBNull.Value)
  1100. {
  1101. string weekNum = rh.SetNumberMerge(cellItems[k]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  1102. sbCell.AppendFormat("第{0}周\n", weekNum);
  1103. }
  1104. if (cellItems[k]["TeacherName"] != DBNull.Value)
  1105. {
  1106. sbCell.AppendFormat("<{0}>\n", cellItems[k]["TeacherName"]);
  1107. }
  1108. curCell.Value = sbCell.ToString();
  1109. if (cellItems[k]["StopWeekNumStr"] != DBNull.Value)
  1110. {
  1111. string stopStr = rh.SetNumberMerge(cellItems[k]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
  1112. curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
  1113. }
  1114. //curCell.PutValue(sbCell.ToString());
  1115. }
  1116. catch
  1117. {
  1118. }
  1119. }
  1120. //第二格合并
  1121. ws.Cells[lineEnd + jLineMax, 1].Value = classRows[j].Field<string>("ClassMajorName").Replace(classRows[j].Field<string>("GrademajorName"), "");
  1122. ws.Cells.CreateRange(lineEnd + jLineMax, 1, klineMax + 1, 1).Merge();
  1123. StyleFlag jLineFlag = new StyleFlag();
  1124. jLineFlag.LeftBorder = true;
  1125. jLineFlag.RightBorder = true;
  1126. ws.Cells.CreateRange(lineEnd + jLineMax, 0, klineMax + 1, dtTimes.Count * dicWeeks.Count + 2).ApplyStyle(style, jLineFlag);
  1127. StyleFlag jLinebuttFlag = new StyleFlag();
  1128. jLinebuttFlag.BottomBorder = true;
  1129. ws.Cells.CreateRange(lineEnd + jLineMax + klineMax, 1, 1, dtTimes.Count * dicWeeks.Count + 2).ApplyStyle(style, jLinebuttFlag);
  1130. //style
  1131. //lineEnd
  1132. jLineMax += klineMax + 1;
  1133. }
  1134. //第一格合并
  1135. ws.Cells[lineEnd, 0].Value = dtFirst.Rows[i].Field<string>("GrademajorName");
  1136. var gRange = ws.Cells.CreateRange(lineEnd, 0, jLineMax, 1);
  1137. gRange.Merge();
  1138. StyleFlag gFlag = new StyleFlag();
  1139. gFlag.Borders = true;
  1140. gRange.ApplyStyle(style, gFlag);
  1141. lineEnd += jLineMax;
  1142. }
  1143. ws.AutoFitRows();
  1144. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  1145. return ms;
  1146. }
  1147. public MemoryStream StudentCountPDF(int? InSchoolStatusID)
  1148. {
  1149. try
  1150. {
  1151. ReportHelper rh = new ReportHelper();
  1152. MemoryStream ms = new MemoryStream();
  1153. StyleFlag commentFlag = new StyleFlag();
  1154. commentFlag.Borders = true;
  1155. commentFlag.Font = true;
  1156. commentFlag.VerticalAlignment = true;
  1157. commentFlag.HorizontalAlignment = true;
  1158. string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  1159. string sql2 = rh.GetReportSql("StudentManage/StudentCountView.sql");
  1160. List<SqlParameter> sParams = new List<SqlParameter>();
  1161. if (InSchoolStatusID.HasValue)
  1162. {
  1163. sParams.Add(new SqlParameter("@InSchoolStatusID", InSchoolStatusID));
  1164. }
  1165. else
  1166. {
  1167. sParams.Add(new SqlParameter("@InSchoolStatusID", DBNull.Value));
  1168. }
  1169. var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
  1170. var wk = rh.GetReportTemple("StudentManage/StudentCountView.xlsx");
  1171. var ws = wk.Worksheets[0];
  1172. var style = rh.BuildBorderStyle(wk);
  1173. int allRow = 4;
  1174. string title = "{0}{1}学生学籍信息统计表", schoolyearCode = "";
  1175. if (ds.Tables[1].Rows.Count > 0)
  1176. {
  1177. schoolyearCode = ds.Tables[1].Rows[0]["SchoolyearCode"].ToString();
  1178. }
  1179. var table1 = DateTableHelper.DataTableToList<StudentCountReportView>(ds.Tables[1]);
  1180. var gradeYearCount = table1.Select(x => x.GradeYear).Distinct().ToList().Count();
  1181. var educationNameList = table1.Select(x => new { x.EducationID, x.EducationName }).Distinct().OrderBy(x => x.EducationID).ToList();
  1182. var studentTypeList = table1.Select(x => new { x.EducationID, x.EducationName, x.StudentType, x.StudentTypeName }).Distinct().OrderBy(x => x.StudentType).ToList();
  1183. var gGradeYearList = table1.GroupBy(x => new { x.GradeYear, x.EducationID, x.EducationName, x.StudentType, x.StudentTypeName }).Select(x => new
  1184. {
  1185. GradeYear = x.Key.GradeYear,
  1186. StudentMaleCount = x.Sum(y => y.StudentMaleCount),
  1187. StudentFemaleCount = x.Sum(y => y.StudentFemaleCount),
  1188. ClassmajorCount = x.Sum(y => y.ClassmajorCount),
  1189. EducationID = x.Key.EducationID,
  1190. EducationName = x.Key.EducationName,
  1191. StudentType = x.Key.StudentType,
  1192. StudentTypeName = x.Key.StudentTypeName,
  1193. }).OrderBy(x => x.GradeYear).ToList();
  1194. var campusNameList = table1.Select(x => new { x.CampusID, x.CampusNo, x.CampusName }).OrderBy(x => x.CampusID).Distinct().OrderBy(x => x.CampusID).ToList();
  1195. var collegeNameList = table1.Select(x => new { x.CampusID, x.CampusNo, x.CampusName, x.CollegeID, x.CollegeNo, x.CollegeName }).Distinct().OrderBy(x => x.CollegeID).ToList();
  1196. var standardNameList = table1.Select(x => new { x.CampusID, x.CampusNo, x.CampusName, x.CollegeID, x.CollegeNo, x.CollegeName, x.StandardID, x.StandardName }).Distinct().OrderBy(x => x.StandardID).ToList();
  1197. var gGradeYearList2 = table1.GroupBy(x => new
  1198. {
  1199. x.GradeYear,
  1200. x.EducationID,
  1201. x.EducationName,
  1202. x.StudentType,
  1203. x.StudentTypeName,
  1204. x.CampusID,
  1205. x.CampusNo,
  1206. x.CampusName,
  1207. x.CollegeID,
  1208. x.CollegeNo,
  1209. x.CollegeName,
  1210. x.StandardID,
  1211. x.StandardName
  1212. }).Select(x => new
  1213. {
  1214. GradeYear = x.Key.GradeYear,
  1215. StudentMaleCount = x.Sum(y => y.StudentMaleCount),
  1216. StudentFemaleCount = x.Sum(y => y.StudentFemaleCount),
  1217. ClassmajorCount = x.Sum(y => y.ClassmajorCount),
  1218. EducationID = x.Key.EducationID,
  1219. EducationName = x.Key.EducationName,
  1220. StudentType = x.Key.StudentType,
  1221. StudentTypeName = x.Key.StudentTypeName,
  1222. CampusID = x.Key.CampusID,
  1223. CampusNo = x.Key.CampusNo,
  1224. CampusName = x.Key.CampusName,
  1225. CollegeID = x.Key.CollegeID,
  1226. CollegeNo = x.Key.CollegeNo,
  1227. CollegeName = x.Key.CollegeName,
  1228. StandardID = x.Key.StandardID,
  1229. StandardName = x.Key.StandardName,
  1230. }).OrderBy(x => x.CampusID).ThenBy(x => x.CollegeID).ThenBy(x => x.StandardID).ThenBy(x => x.GradeYear).ToList();
  1231. var collegeTotalList = table1.GroupBy(x => new
  1232. {
  1233. x.CollegeID,
  1234. x.CollegeNo,
  1235. x.CollegeName,
  1236. x.GradeYear,
  1237. x.StudentType,
  1238. x.StudentTypeName,
  1239. x.EducationID,
  1240. x.EducationName,
  1241. }).Select(x => new
  1242. {
  1243. GradeYear = x.Key.GradeYear,
  1244. StudentMaleCount = x.Sum(y => y.StudentMaleCount),
  1245. StudentFemaleCount = x.Sum(y => y.StudentFemaleCount),
  1246. ClassmajorCount = x.Sum(y => y.ClassmajorCount),
  1247. CollegeID = x.Key.CollegeID,
  1248. CollegeNo = x.Key.CollegeNo,
  1249. CollegeName = x.Key.CollegeName,
  1250. StudentType = x.Key.StudentType,
  1251. StudentTypeName = x.Key.StudentTypeName,
  1252. EducationID = x.Key.EducationID,
  1253. EducationName = x.Key.EducationName,
  1254. }).OrderBy(x => x.CollegeID).ThenBy(x => x.GradeYear).ToList();
  1255. ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], schoolyearCode);
  1256. var titleRange = ws.Cells.CreateRange(0, 0, 1, 5 * studentTypeList.Count + 5);
  1257. var titlestyle = rh.BuildBorderStyleAndSize(wk);
  1258. titleRange.Merge();
  1259. StyleFlag titleFlag = new StyleFlag();
  1260. titleFlag.Borders = true;
  1261. titleFlag.Font = true;
  1262. titleFlag.VerticalAlignment = true;
  1263. titleFlag.HorizontalAlignment = true;
  1264. titleRange.ApplyStyle(titlestyle, titleFlag);
  1265. var colCount = 4;
  1266. var rowCount = 1;
  1267. for (int i = 0; i < educationNameList.Count; i++)
  1268. {
  1269. var education = educationNameList[i];
  1270. //第一行标题合并
  1271. ws.Cells[rowCount, colCount].Value = education.EducationName;
  1272. var gRange = ws.Cells.CreateRange(rowCount, colCount, 1, 5);
  1273. gRange.Merge();
  1274. gRange.ApplyStyle(style, commentFlag);
  1275. var stCount = colCount;
  1276. var studentTypeListByEducation = studentTypeList.Where(x => x.EducationID == education.EducationID).ToList();
  1277. for (int j = 0; j < studentTypeListByEducation.Count; j++)
  1278. {
  1279. var studentType = studentTypeListByEducation[j];
  1280. //第三行标题
  1281. ws.Cells[rowCount + 2, stCount].Value = "男";
  1282. ws.Cells[rowCount + 2, stCount].SetStyle(style);
  1283. ws.Cells[rowCount + 2, stCount + 1].Value = "女";
  1284. ws.Cells[rowCount + 2, stCount + 1].SetStyle(style);
  1285. ws.Cells[rowCount + 2, stCount + 2].Value = "总人数";
  1286. ws.Cells[rowCount + 2, stCount + 2].SetStyle(style);
  1287. ws.Cells[rowCount + 2, stCount + 3].Value = "班级数";
  1288. ws.Cells[rowCount + 2, stCount + 3].SetStyle(style);
  1289. //第二行标题合并
  1290. ws.Cells[rowCount + 1, stCount].Value = studentType.StudentTypeName;
  1291. var stRange = ws.Cells.CreateRange(rowCount + 1, stCount, 1, 4);
  1292. stRange.Merge();
  1293. stRange.ApplyStyle(style, commentFlag);
  1294. stCount += 4;
  1295. ws.Cells[rowCount + 1, stCount].Value = "小计";
  1296. var xiaojiRange = ws.Cells.CreateRange(rowCount + 1, stCount, 2, 1);
  1297. xiaojiRange.Merge();
  1298. xiaojiRange.ApplyStyle(style, commentFlag);
  1299. stCount += 1;
  1300. var gradeYearListByStudentType = gGradeYearList.Where(x => x.EducationID == education.EducationID && x.StudentType == studentType.StudentType).ToList();
  1301. int? allSchoolMaleCount = 0;
  1302. int? allSchoolFemaleCount = 0;
  1303. int? allSchoolClassCount = 0;
  1304. for (int k = 0; k < gradeYearListByStudentType.Count; k++)
  1305. {
  1306. var gradeYear = gradeYearListByStudentType[k];
  1307. if (j == 0)
  1308. {
  1309. //年级
  1310. ws.Cells[allRow + k, 3].Value = gradeYear.GradeYear.ToString();
  1311. ws.Cells[allRow + k, 3].SetStyle(style);
  1312. }
  1313. //男
  1314. ws.Cells[allRow + k, 4 + j * 4].Value = gradeYear.StudentMaleCount.ToString();
  1315. ws.Cells[allRow + k, 4 + j * 4].SetStyle(style);
  1316. allSchoolMaleCount += gGradeYearList[i].StudentMaleCount;
  1317. //女
  1318. ws.Cells[allRow + k, 5 + j * 4].Value = gradeYear.StudentFemaleCount.ToString();
  1319. ws.Cells[allRow + k, 5 + j * 4].SetStyle(style);
  1320. allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
  1321. //总
  1322. ws.Cells[allRow + k, 6 + j * 4].Value = (gradeYear.StudentMaleCount + gradeYear.StudentFemaleCount).ToString();
  1323. ws.Cells[allRow + k, 6 + j * 4].SetStyle(style);
  1324. //班级数
  1325. ws.Cells[allRow + k, 7 + j * 4].Value = gradeYear.ClassmajorCount.ToString();
  1326. ws.Cells[allRow + k, 7 + j * 4].SetStyle(style);
  1327. allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
  1328. if (j == studentTypeListByEducation.Count - 1)
  1329. {
  1330. //小计
  1331. var xiaojiCount = gGradeYearList.Where(x => x.EducationID == education.EducationID && x.GradeYear == gradeYear.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1332. ws.Cells[allRow + k, 8 + j * 4].Value = xiaojiCount.ToString();
  1333. ws.Cells[allRow + k, 8 + j * 4].SetStyle(style);
  1334. }
  1335. if (i == educationNameList.Count - 1)
  1336. {
  1337. //总计
  1338. var zongjiCount = gGradeYearList2.Where(x => x.GradeYear == gradeYear.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1339. ws.Cells[allRow + k, 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
  1340. ws.Cells[allRow + k, 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
  1341. }
  1342. }
  1343. //总计
  1344. ws.Cells[allRow + gradeYearListByStudentType.Count(), 4 + j * 4].Value = allSchoolMaleCount;
  1345. ws.Cells[allRow + gradeYearListByStudentType.Count(), 4 + j * 4].SetStyle(style);
  1346. ws.Cells[allRow + gradeYearListByStudentType.Count(), 5 + j * 4].Value = allSchoolFemaleCount;
  1347. ws.Cells[allRow + gradeYearListByStudentType.Count(), 5 + j * 4].SetStyle(style);
  1348. ws.Cells[allRow + gradeYearListByStudentType.Count(), 6 + j * 4].Value = allSchoolMaleCount + allSchoolFemaleCount;
  1349. ws.Cells[allRow + gradeYearListByStudentType.Count(), 6 + j * 4].SetStyle(style);
  1350. ws.Cells[allRow + gradeYearListByStudentType.Count(), 7 + j * 4].Value = allSchoolClassCount;
  1351. ws.Cells[allRow + gradeYearListByStudentType.Count(), 7 + j * 4].SetStyle(style);
  1352. if (j == studentTypeListByEducation.Count - 1)
  1353. {
  1354. //总计小计
  1355. var xiaojiCount = gGradeYearList.Where(x => x.EducationID == education.EducationID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1356. ws.Cells[allRow + gradeYearListByStudentType.Count(), 8 + j * 4].Value = xiaojiCount.ToString();
  1357. ws.Cells[allRow + gradeYearListByStudentType.Count(), 8 + j * 4].SetStyle(style);
  1358. }
  1359. if (i == educationNameList.Count - 1)
  1360. {
  1361. //总计小计
  1362. var xiaojiCount = gGradeYearList.Where(x => x.EducationID == education.EducationID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1363. ws.Cells[allRow + gradeYearListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].Value = xiaojiCount.ToString();
  1364. ws.Cells[allRow + gradeYearListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
  1365. }
  1366. allRow += gradeYearListByStudentType.Count + 1;
  1367. }
  1368. colCount += 5;
  1369. }
  1370. for (int i = 0; i < campusNameList.Count(); i++)
  1371. {
  1372. var campus = campusNameList[i];
  1373. int? campusRowCout = 0;
  1374. var collegeListByCampus = collegeNameList.Where(x => x.CampusID == campus.CampusID).OrderBy(x => x.CollegeID).ToList();
  1375. var campusStartRow = allRow;
  1376. for (int j = 0; j < collegeListByCampus.Count(); j++)
  1377. {
  1378. var college = collegeListByCampus[j];
  1379. int? collegeRowCount = 0;
  1380. //var collegeGradeYearCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID).Count();
  1381. //ws.Cells[allRow, 2].Value = college.CollegeName;
  1382. //var collegeRange = ws.Cells.CreateRange(allRow, 2, 1, collegeRowCount.Value);
  1383. //collegeRange.Merge();
  1384. //collegeRange.ApplyStyle(style, commentFlag);
  1385. //campusRowCout += collegeGradeYearCount + 1;
  1386. var startRow = allRow;
  1387. var standardListByCollege = standardNameList.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID).OrderBy(x => x.StandardID).ToList();
  1388. for (int k = 0; k < standardListByCollege.Count(); k++)
  1389. {
  1390. var standard = standardListByCollege[k];
  1391. var standardGradeYearCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
  1392. && x.StandardID == standard.StandardID).Count();
  1393. collegeRowCount += standardGradeYearCount + 1;
  1394. ws.Cells[allRow, 2].Value = standard.StandardName;
  1395. var gRange = ws.Cells.CreateRange(allRow, 2, standardGradeYearCount + 1, 1);
  1396. gRange.Merge();
  1397. gRange.ApplyStyle(style, commentFlag);
  1398. for (int m = 0; m < educationNameList.Count(); m++)
  1399. {
  1400. var education = educationNameList[m];
  1401. var studentTypeListByEducation = studentTypeList.Where(x => x.EducationID == education.EducationID).OrderBy(x => x.StudentType).ToList();
  1402. for (int n = 0; n < studentTypeListByEducation.Count(); n++)
  1403. {
  1404. var studentType = studentTypeListByEducation[n];
  1405. var dbListByStudentType = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
  1406. && x.StandardID == standard.StandardID && x.EducationID == education.EducationID && x.StudentType == studentType.StudentType).OrderBy(x => x.GradeYear).ToList();
  1407. //int? allSchoolMaleCount = 0;
  1408. //int? allSchoolFemaleCount = 0;
  1409. //int? allSchoolClassCount = 0;
  1410. for (int p = 0; p < dbListByStudentType.Count(); p++)
  1411. {
  1412. var db = dbListByStudentType[p];
  1413. if (n == 0)
  1414. {
  1415. ws.Cells[allRow + p, 3].Value = db.GradeYear;
  1416. ws.Cells[allRow + p, 3].SetStyle(style);
  1417. }
  1418. //男
  1419. ws.Cells[allRow + p, 4 + n * 4].Value = db.StudentMaleCount.ToString();
  1420. ws.Cells[allRow + p, 4 + n * 4].SetStyle(style);
  1421. //allSchoolMaleCount += db.StudentMaleCount;
  1422. //女
  1423. ws.Cells[allRow + p, 5 + n * 4].Value = db.StudentFemaleCount.ToString();
  1424. ws.Cells[allRow + p, 5 + n * 4].SetStyle(style);
  1425. //allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
  1426. //总
  1427. ws.Cells[allRow + p, 6 + n * 4].Value = (db.StudentMaleCount + db.StudentFemaleCount).ToString();
  1428. ws.Cells[allRow + p, 6 + n * 4].SetStyle(style);
  1429. //班级数
  1430. ws.Cells[allRow + p, 7 + n * 4].Value = db.ClassmajorCount.ToString();
  1431. ws.Cells[allRow + p, 7 + n * 4].SetStyle(style);
  1432. //allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
  1433. if (n == studentTypeListByEducation.Count - 1)
  1434. {
  1435. //小计
  1436. var xiaojiCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
  1437. && x.StandardID == standard.StandardID && x.EducationID == education.EducationID
  1438. && x.GradeYear == db.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1439. ws.Cells[allRow + p, 8 + n * 4].Value = xiaojiCount.ToString();
  1440. ws.Cells[allRow + p, 8 + n * 4].SetStyle(style);
  1441. }
  1442. if (m == educationNameList.Count - 1)
  1443. {
  1444. //总计
  1445. var zongjiCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
  1446. && x.StandardID == standard.StandardID && x.GradeYear == db.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1447. ws.Cells[allRow + p, 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
  1448. ws.Cells[allRow + p, 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
  1449. }
  1450. }
  1451. if (n == 0)
  1452. {
  1453. ws.Cells[allRow + dbListByStudentType.Count(), 3].Value = "小计";
  1454. ws.Cells[allRow + dbListByStudentType.Count(), 3].SetStyle(style);
  1455. }
  1456. //男
  1457. ws.Cells[allRow + dbListByStudentType.Count(), 4 + n * 4].Value = dbListByStudentType.Sum(x => x.StudentMaleCount).ToString();
  1458. ws.Cells[allRow + dbListByStudentType.Count(), 4 + n * 4].SetStyle(style);
  1459. //allSchoolMaleCount += db.StudentMaleCount;
  1460. //女
  1461. ws.Cells[allRow + dbListByStudentType.Count(), 5 + n * 4].Value = dbListByStudentType.Sum(x => x.StudentFemaleCount).ToString();
  1462. ws.Cells[allRow + dbListByStudentType.Count(), 5 + n * 4].SetStyle(style);
  1463. //allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
  1464. //总
  1465. ws.Cells[allRow + dbListByStudentType.Count(), 6 + n * 4].Value = dbListByStudentType.Sum(x => x.StudentFemaleCount + x.StudentFemaleCount).ToString();
  1466. ws.Cells[allRow + dbListByStudentType.Count(), 6 + n * 4].SetStyle(style);
  1467. //班级数
  1468. ws.Cells[allRow + dbListByStudentType.Count(), 7 + n * 4].Value = dbListByStudentType.Sum(x => x.ClassmajorCount).ToString();
  1469. ws.Cells[allRow + dbListByStudentType.Count(), 7 + n * 4].SetStyle(style);
  1470. //allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
  1471. if (n == studentTypeListByEducation.Count - 1)
  1472. {
  1473. //小计
  1474. var xiaojiCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
  1475. && x.StandardID == standard.StandardID && x.EducationID == education.EducationID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1476. ws.Cells[allRow + dbListByStudentType.Count(), 8 + n * 4].Value = xiaojiCount.ToString();
  1477. ws.Cells[allRow + dbListByStudentType.Count(), 8 + n * 4].SetStyle(style);
  1478. }
  1479. if (m == educationNameList.Count - 1)
  1480. {
  1481. //总计
  1482. var zongjiCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
  1483. && x.StandardID == standard.StandardID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1484. ws.Cells[allRow + dbListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
  1485. ws.Cells[allRow + dbListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
  1486. }
  1487. }
  1488. }
  1489. allRow += standardGradeYearCount + 1;
  1490. }
  1491. var collegeList = collegeTotalList.Where(x => x.CollegeID == college.CollegeID).ToList();
  1492. var gradeYearByCollegeList = collegeList.Select(x => x.GradeYear).Distinct().ToList();
  1493. for (int s = 0; s < educationNameList.Count(); s++)
  1494. {
  1495. var education = educationNameList[s];
  1496. //var collegeTotalListByEducation = collegeList.Where(x => x.EducationID == education.EducationID).ToList();
  1497. var studentTypeListByEducation = studentTypeList.Where(x => x.EducationID == education.EducationID).ToList();
  1498. for (int t = 0; t < studentTypeListByEducation.Count(); t++)
  1499. {
  1500. var studentType = studentTypeListByEducation[t];
  1501. var collegeTotalListByStudentType = collegeList.Where(x => x.EducationID == education.EducationID && x.StudentType == studentType.StudentType).ToList();
  1502. for (int u = 0; u < collegeTotalListByStudentType.Count(); u++)
  1503. {
  1504. var db = collegeTotalListByStudentType[u];
  1505. if (t == 0)
  1506. {
  1507. ws.Cells[allRow + u, 3].Value = db.GradeYear;
  1508. var collegeYearRange = ws.Cells.CreateRange(allRow + u, 2, 1, 2);
  1509. collegeYearRange.Merge();
  1510. collegeYearRange.ApplyStyle(style, commentFlag);
  1511. }
  1512. //男
  1513. ws.Cells[allRow + u, 4 + t * 4].Value = db.StudentMaleCount.ToString();
  1514. ws.Cells[allRow + u, 4 + t * 4].SetStyle(style);
  1515. //allSchoolMaleCount += db.StudentMaleCount;
  1516. //女
  1517. ws.Cells[allRow + u, 5 + t * 4].Value = db.StudentFemaleCount.ToString();
  1518. ws.Cells[allRow + u, 5 + t * 4].SetStyle(style);
  1519. //allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
  1520. //总
  1521. ws.Cells[allRow + u, 6 + t * 4].Value = (db.StudentMaleCount + db.StudentFemaleCount).ToString();
  1522. ws.Cells[allRow + u, 6 + t * 4].SetStyle(style);
  1523. //班级数
  1524. ws.Cells[allRow + u, 7 + t * 4].Value = db.ClassmajorCount.ToString();
  1525. ws.Cells[allRow + u, 7 + t * 4].SetStyle(style);
  1526. //allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
  1527. if (t == studentTypeListByEducation.Count - 1)
  1528. {
  1529. //小计
  1530. var xiaojiCount = collegeList.Where(x => x.EducationID == education.EducationID && x.GradeYear == db.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1531. ws.Cells[allRow + u, 8 + t * 4].Value = xiaojiCount.ToString();
  1532. ws.Cells[allRow + u, 8 + t * 4].SetStyle(style);
  1533. }
  1534. if (s == educationNameList.Count - 1)
  1535. {
  1536. //总计
  1537. var zongjiCount = collegeList.Where(x => x.GradeYear == db.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1538. ws.Cells[allRow + u, 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
  1539. ws.Cells[allRow + u, 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
  1540. }
  1541. }
  1542. if (t == 0)
  1543. {
  1544. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 3].Value = "合计";
  1545. var collegehejiRange = ws.Cells.CreateRange(allRow + collegeTotalListByStudentType.Count(), 2, 1, 2);
  1546. collegehejiRange.Merge();
  1547. collegehejiRange.ApplyStyle(style, commentFlag);
  1548. }
  1549. //男
  1550. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 4 + t * 4].Value = collegeTotalListByStudentType.Sum(x => x.StudentMaleCount).ToString();
  1551. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 4 + t * 4].SetStyle(style);
  1552. //allSchoolMaleCount += db.StudentMaleCount;
  1553. //女
  1554. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 5 + t * 4].Value = collegeTotalListByStudentType.Sum(x => x.StudentFemaleCount).ToString();
  1555. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 5 + t * 4].SetStyle(style);
  1556. //allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
  1557. //总
  1558. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 6 + t * 4].Value = collegeTotalListByStudentType.Sum(x => x.StudentFemaleCount + x.StudentFemaleCount).ToString();
  1559. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 6 + t * 4].SetStyle(style);
  1560. //班级数
  1561. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 7 + t * 4].Value = collegeTotalListByStudentType.Sum(x => x.ClassmajorCount).ToString();
  1562. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 7 + t * 4].SetStyle(style);
  1563. //allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
  1564. if (t == studentTypeListByEducation.Count - 1)
  1565. {
  1566. //小计
  1567. var xiaojiCount = collegeList.Where(x => x.EducationID == education.EducationID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1568. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 8 + t * 4].Value = xiaojiCount.ToString();
  1569. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 8 + t * 4].SetStyle(style);
  1570. }
  1571. if (s == educationNameList.Count - 1)
  1572. {
  1573. //总计
  1574. var zongjiCount = collegeList.Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
  1575. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
  1576. ws.Cells[allRow + collegeTotalListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
  1577. }
  1578. }
  1579. }
  1580. allRow += gradeYearByCollegeList.Count() + 1;
  1581. ws.Cells[startRow, 1].Value = college.CollegeName;
  1582. var collegeRange = ws.Cells.CreateRange(startRow, 1, collegeRowCount.Value, 1);
  1583. collegeRange.Merge();
  1584. collegeRange.ApplyStyle(style, commentFlag);
  1585. ws.Cells[startRow + collegeRowCount.Value + 1, 1].Value = college.CollegeName + "合计";
  1586. var collegeTotalRange = ws.Cells.CreateRange(startRow + collegeRowCount.Value, 1, gradeYearByCollegeList.Count() + 1, 1);
  1587. collegeTotalRange.Merge();
  1588. collegeTotalRange.ApplyStyle(style, commentFlag);
  1589. campusRowCout += collegeRowCount + gradeYearByCollegeList.Count() + 1;
  1590. }
  1591. ws.Cells[campusStartRow, 0].Value = campus.CampusName;
  1592. var campusRange = ws.Cells.CreateRange(campusStartRow, 0, campusRowCout.Value, 1);
  1593. campusRange.Merge();
  1594. campusRange.ApplyStyle(style, commentFlag);
  1595. }
  1596. ws.Cells[rowCount, colCount].Value = "合计";
  1597. var hejiRange = ws.Cells.CreateRange(1, colCount, 3, 1);
  1598. hejiRange.Merge();
  1599. hejiRange.ApplyStyle(style, commentFlag);
  1600. //var gGradeYear = dtGradeYear.GroupBy(x => x.Field<int>("GradeYear")).ToList();
  1601. //校区
  1602. ws.Cells[4, 0].Value = "校区";
  1603. var xiaoquRange = ws.Cells.CreateRange(4, 0, gradeYearCount + 1, 1);
  1604. xiaoquRange.Merge();
  1605. xiaoquRange.ApplyStyle(style, commentFlag);
  1606. //全校
  1607. ws.Cells[4, 1].Value = "全校";
  1608. var quanxiaoRange = ws.Cells.CreateRange(4, 1, gradeYearCount + 1, 2);
  1609. quanxiaoRange.Merge();
  1610. quanxiaoRange.ApplyStyle(style, commentFlag);
  1611. //全校总计
  1612. ws.Cells[4 + gradeYearCount, 3].Value = "总计";
  1613. var quanxiaoHejiRange = ws.Cells.CreateRange(4 + gradeYearCount, 3, 1, 1);
  1614. quanxiaoHejiRange.Merge();
  1615. quanxiaoHejiRange.ApplyStyle(style, commentFlag);
  1616. ws.AutoFitColumns();
  1617. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  1618. return ms;
  1619. }
  1620. catch (Exception ex)
  1621. {
  1622. throw ex;
  1623. }
  1624. }
  1625. public MemoryStream StudentStatisticsPDF(int? InSchoolStatusID)
  1626. {
  1627. try
  1628. {
  1629. ReportHelper rh = new ReportHelper();
  1630. MemoryStream ms = new MemoryStream();
  1631. StyleFlag commentFlag = new StyleFlag();
  1632. commentFlag.Borders = true;
  1633. commentFlag.Font = true;
  1634. commentFlag.VerticalAlignment = true;
  1635. commentFlag.HorizontalAlignment = true;
  1636. //string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
  1637. string sql2 = rh.GetReportSql("StudentManage/StudentStatisticsData.sql");
  1638. List<SqlParameter> sParams = new List<SqlParameter>();
  1639. if (InSchoolStatusID.HasValue)
  1640. {
  1641. sParams.Add(new SqlParameter("@INSchoolStatus", InSchoolStatusID));
  1642. }
  1643. else
  1644. {
  1645. sParams.Add(new SqlParameter("@INSchoolStatus", DBNull.Value));
  1646. }
  1647. var ds = this.UnitOfWork.QuerySQL(sql2, sParams);
  1648. var wk = rh.GetReportTemple("StudentManage/StudentStatisticsData.xlsx");
  1649. var ws = wk.Worksheets[0];
  1650. var style = rh.BuildBorderStyle(wk);
  1651. var table = DateTableHelper.DataTableToList<StudentStatisticsDataView>(ds.Tables[0]);
  1652. var title = table.FirstOrDefault().unicersityName + table.FirstOrDefault().schoolCode + "年级专业学籍统计表";
  1653. var classNoList = table.Select(x => x.classNo).Distinct().ToList();
  1654. var collegeList = table.Select(x => x.collegeName).Distinct().ToList();
  1655. var listByClassNo = table.GroupBy(x => new { x.collegeName, x.StandardsName, x.year, x.classNo }).ToList();
  1656. ws.Cells[0, 0].Value = title;
  1657. var titleRange = ws.Cells.CreateRange(0, 0, 1, classNoList.Count + 4);
  1658. var titlestyle = rh.BuildBorderStyleAndSize(wk);
  1659. titleRange.Merge();
  1660. StyleFlag titleFlag = new StyleFlag();
  1661. titleFlag.Borders = true;
  1662. titleFlag.Font = true;
  1663. titleFlag.VerticalAlignment = true;
  1664. titleFlag.HorizontalAlignment = true;
  1665. titleRange.ApplyStyle(titlestyle, titleFlag);
  1666. ws.Cells[1, 1].Value = "系所函授站";
  1667. ws.Cells[1, 1].SetStyle(style);
  1668. ws.Cells[1, 2].Value = "院系所专业";
  1669. ws.Cells[1, 2].SetStyle(style);
  1670. ws.Cells[1, 3].Value = "年级";
  1671. ws.Cells[1, 3].SetStyle(style);
  1672. ws.Cells[1, 3 + classNoList.Count()].Value = "总计";
  1673. ws.Cells[1, 3 + classNoList.Count()].SetStyle(style);
  1674. for (int i = 0; i < classNoList.Count(); i++)
  1675. {
  1676. ws.Cells[1, 3 + i + 1].Value = classNoList[i] + "班";
  1677. ws.Cells[1, 3 + i + 1].SetStyle(style);
  1678. }
  1679. for (int i = 0; i < collegeList.Count(); i++)
  1680. {
  1681. var college = collegeList[i];
  1682. var standardList = table.Where(x => x.collegeName == college).Select(x => x.StandardsName).Distinct().ToList();
  1683. for (int j = 0; j < standardList.Count(); j++)
  1684. {
  1685. var standard = standardList[j];
  1686. var yearList = table.Where(x => x.collegeName == college && x.StandardsName == standard).Select(x => x.year).Distinct().ToList();
  1687. //ws.Cells[2 + j, 2].Value = standard;
  1688. //var standardRange = ws.Cells.CreateRange(2, 2, 1, 2);
  1689. //standardRange.Merge();
  1690. //standardRange.ApplyStyle(style, commentFlag);
  1691. for (int k = 0; k < yearList.Count(); k++)
  1692. {
  1693. var year = yearList[k];
  1694. var listByYearAndClassNo = listByClassNo.Where(x => x.Key.year == year).Select(x => new { x.Key.classNo, StudentCount = x.Sum(y => y.StudentCount) }).ToList();
  1695. ws.Cells[2 + k, 3].Value = year;
  1696. ws.Cells[2 + k, 3].SetStyle(style);
  1697. for (int m = 0; m < classNoList.Count(); m++)
  1698. {
  1699. var classNo = classNoList[m];
  1700. var listByClass = listByYearAndClassNo.Where(x => x.classNo == classNo).ToList();
  1701. ws.Cells[2 + k, 3 + m + 1].Value = listByClass.Sum(y => y.StudentCount);
  1702. ws.Cells[2 + k, 3 + m + 1].SetStyle(style);
  1703. }
  1704. }
  1705. }
  1706. }
  1707. wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
  1708. return ms;
  1709. }
  1710. catch (Exception)
  1711. {
  1712. throw;
  1713. }
  1714. }
  1715. /// <summary>
  1716. /// 获取空格和当行最大行数
  1717. /// </summary>
  1718. /// <param name="ws"></param>
  1719. /// <param name="weekDay"></param>
  1720. /// <param name="firstCol"></param>
  1721. /// <param name="lineEnd"></param>
  1722. /// <param name="maxRow">最大行数</param>
  1723. /// <returns>空格</returns>
  1724. private Cell GetLastCell(Worksheet ws, int weekDay, int firstCol, int lineEnd, ref int maxRow)
  1725. {
  1726. int curRow = 0;
  1727. int curCol = weekDay == 0 ? 7 : weekDay;
  1728. curCol += firstCol;
  1729. while (ws.Cells[curRow + lineEnd, curCol].Value != null)
  1730. {
  1731. curRow++;
  1732. }
  1733. if (maxRow < curRow)
  1734. {
  1735. maxRow = curRow;
  1736. }
  1737. return ws.Cells[curRow + lineEnd, curCol];
  1738. }
  1739. /// <summary>
  1740. /// 时间段横向计算定位
  1741. /// </summary>
  1742. /// <param name="ws"></param>
  1743. /// <param name="weekDay"></param>
  1744. /// <param name="dayNum"></param>
  1745. /// <param name="addCol">原始偏量+时间段偏量</param>
  1746. /// <param name="lineEnd"></param>
  1747. /// <param name="maxRow"></param>
  1748. /// <returns></returns>
  1749. private Cell GetCrossTimeCell(Worksheet ws, int weekDay, int dayNum, int addCol, int lineEnd, ref int maxRow)
  1750. {
  1751. int curRow = 0;
  1752. var dicWeeks = GetDicWeeks();
  1753. int curCol = dicWeeks.FindIndex(w => w.Item1 == weekDay) * dayNum;
  1754. curCol += addCol;
  1755. while (ws.Cells[curRow + lineEnd, curCol].Value != null)
  1756. {
  1757. curRow++;
  1758. }
  1759. if (maxRow < curRow)
  1760. {
  1761. maxRow = curRow;
  1762. }
  1763. return ws.Cells[curRow + lineEnd, curCol];
  1764. }
  1765. private List<Tuple<int, string>> GetDicWeeks()
  1766. {
  1767. List<Tuple<int, string>> dic = new List<Tuple<int, string>>();
  1768. dic.Add(new Tuple<int, string>(1, "星期一"));
  1769. dic.Add(new Tuple<int, string>(2, "星期二"));
  1770. dic.Add(new Tuple<int, string>(3, "星期三"));
  1771. dic.Add(new Tuple<int, string>(4, "星期四"));
  1772. dic.Add(new Tuple<int, string>(5, "星期五"));
  1773. dic.Add(new Tuple<int, string>(6, "星期六"));
  1774. dic.Add(new Tuple<int, string>(0, "星期日"));
  1775. return dic;
  1776. }
  1777. }
  1778. }