1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347 |
- using Aspose.Cells;
- using EMIS.CommonLogic.UniversityManage.SpecialtyClassManage;
- using EMIS.DataLogic.Repositories;
- using EMIS.DataLogic.UniversityManage.SpecialtyClassManage;
- using EMIS.Utility;
- using EMIS.ViewModel.Report;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.IO;
- using System.Linq;
- using System.Text;
- namespace EMIS.CommonLogic.Report
- {
- public class NewReportServices: BaseServices, INewReportServices
- {
- public ClassmajorDAL ClassmajorDAL { get; set; }
- public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
- public MemoryStream TeacherselfSchedulingPDF(Guid SchoolyearID, Guid? UserID)
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/TeacherselfSchedulingView.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (UserID.HasValue)
- {
- sParams.Add(new SqlParameter("@UserID", UserID));
- }
- else
- {
- sParams.Add(new SqlParameter("@UserID", DBNull.Value));
- }
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var wk = rh.GetReportTemple("EducationScheduling/TeacherselfSchedulingView.xlsx");
- var ws = wk.Worksheets[0];
- string title = "{0}{1}学期课程表-{2}", code = "", staffName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- code = ds.Tables[1].Rows[0]["Code"].ToString();
- staffName = ds.Tables[1].Rows[0]["StaffName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, staffName);
- //聚合唯一
- //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
- dtShow.DefaultView.Sort = "StartTimes asc";
- dtShow = dtShow.DefaultView.ToTable();
- int lineEnd = 2;
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- string col1Format = "{0}\n{1}";
- ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
- string condition = "StartTimes='{0}'";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "MinWeekNum asc");
- int lineMax = 0;
- for (int j = 0; j < weekRows.Count(); j++)
- {
- int weekDay = (int)weekRows[j]["Weekday"];
- //weekDay += 1;
- var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(weekRows[j]["Name"].ToString());
- if (weekRows[j]["StudentCount"] != DBNull.Value)
- {
- sbCell.Append("(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
- }
- sbCell.AppendLine(weekRows[j]["ClassroomName"].ToString());
- if (weekRows[j]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (weekRows[j]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
- }
- curCell.Value += sbCell.ToString();
- if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
- {
- string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
- }
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
- mergeRange.Merge();
- var style1 = rh.BuildBorderStyle(wk);
- StyleFlag stFlag1 = new StyleFlag();
- stFlag1.Borders = true;
- mergeRange.ApplyStyle(style1, stFlag1);
- var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
- StyleFlag stFlag2 = new StyleFlag();
- stFlag2.LeftBorder = true;
- stFlag2.RightBorder = true;
- weekRange.ApplyStyle(style1, stFlag2);
- StyleFlag stFlag3 = new StyleFlag();
- stFlag3.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
- lineEnd = lineEnd + lineMax + 1;
- }
- ws.AutoFitRows();
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- public MemoryStream StudentForTeacherSchedulingPDF(Guid SchoolyearID, Guid StudentNo)
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/StudentForTeacherSchedulingView.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- sParams.Add(new SqlParameter("@StudentNo", StudentNo));
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var wk = rh.GetReportTemple("EducationScheduling/StudentForTeacherSchedulingView.xlsx");
- var ws = wk.Worksheets[0];
- string title = "{0}{1}学期课程表-{2}", code = "", classMajorName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- code = ds.Tables[1].Rows[0]["Code"].ToString();
- classMajorName = ds.Tables[1].Rows[0]["ClassmajorName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classMajorName);
- //聚合唯一
- //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
- dtShow.DefaultView.Sort = "StartTimes asc";
- dtShow = dtShow.DefaultView.ToTable();
- int lineEnd = 2;
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- string col1Format = "{0}\n{1}";
- ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
- string condition = "StartTimes='{0}'";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "MinWeekNum asc");
- int lineMax = 0;
- for (int j = 0; j < weekRows.Count(); j++)
- {
- int weekDay = (int)weekRows[j]["Weekday"];
- //weekDay += 1;
- var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(weekRows[j]["Name"].ToString());
- if (weekRows[j]["ClassroomName"] != DBNull.Value)
- {
- sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
- }
- if (weekRows[j]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (weekRows[j]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
- }
- curCell.Value += sbCell.ToString();
- if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
- {
- string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
- }
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
- mergeRange.Merge();
- var style1 = rh.BuildBorderStyle(wk);
- StyleFlag stFlag1 = new StyleFlag();
- stFlag1.Borders = true;
- mergeRange.ApplyStyle(style1, stFlag1);
- var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
- StyleFlag stFlag2 = new StyleFlag();
- stFlag2.LeftBorder = true;
- stFlag2.RightBorder = true;
- weekRange.ApplyStyle(style1, stFlag2);
- StyleFlag stFlag3 = new StyleFlag();
- stFlag3.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
- lineEnd = lineEnd + lineMax + 1;
- }
- ws.AutoFitRows();
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- public MemoryStream TeacherSchedulingPDF(Guid SchoolyearID, Guid? CollegeID, Guid? UserID)
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/TeacherSchedulingView.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (CollegeID.HasValue)
- {
- sParams.Add(new SqlParameter("@CollegeID", CollegeID));
- }
- else
- {
- sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
- }
- if (UserID.HasValue)
- {
- sParams.Add(new SqlParameter("@UserID", UserID));
- }
- else
- {
- sParams.Add(new SqlParameter("@UserID", DBNull.Value));
- }
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var wk = rh.GetReportTemple("EducationScheduling/TeacherSchedulingView.xlsx");
- var ws = wk.Worksheets[0];
- string title = "{0}{1}学期课程表-{2}", code = "", staffName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- code = ds.Tables[1].Rows[0]["Code"].ToString();
- staffName = ds.Tables[1].Rows[0]["StaffName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, staffName);
- //聚合唯一
- //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
- dtShow.DefaultView.Sort = "StartTimes asc";
- dtShow = dtShow.DefaultView.ToTable();
- int lineEnd = 2;
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- string col1Format = "{0}\n{1}";
- ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
- string condition = "StartTimes='{0}'";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "StartTimes asc");
- int lineMax = 0;
- for (int j = 0; j < weekRows.Count(); j++)
- {
- int weekDay = (int)weekRows[j]["Weekday"];
- //weekDay += 1;
- var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(weekRows[j]["Name"].ToString());
- sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
- if (weekRows[j]["ClassroomName"] != DBNull.Value)
- {
- sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
- }
- if (weekRows[j]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (weekRows[j]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
- }
- curCell.Value += sbCell.ToString();
- if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
- {
- string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
- }
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
- mergeRange.Merge();
- var style1 = rh.BuildBorderStyle(wk);
- StyleFlag stFlag1 = new StyleFlag();
- stFlag1.Borders = true;
- mergeRange.ApplyStyle(style1, stFlag1);
- var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
- StyleFlag stFlag2 = new StyleFlag();
- stFlag2.LeftBorder = true;
- stFlag2.RightBorder = true;
- weekRange.ApplyStyle(style1, stFlag2);
- StyleFlag stFlag3 = new StyleFlag();
- stFlag3.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
- lineEnd = lineEnd + lineMax + 1;
- }
- ws.AutoFitRows();
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- public MemoryStream TeacherPrintingSchedulingPDF(Guid SchoolyearID, Guid? CollegeID)
- {
- try
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/TeacherSchedulingView.sql");
- var wk = rh.GetReportTemple("EducationScheduling/TeacherSchedulingView.xlsx");
- var templateSheetCount = wk.Worksheets.Count;
- List<SqlParameter> teacherParams = new List<SqlParameter>();
- teacherParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (CollegeID.HasValue)
- {
- teacherParams.Add(new SqlParameter("@CollegeID", CollegeID));
- }
- else
- {
- teacherParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
- }
- teacherParams.Add(new SqlParameter("@UserID", DBNull.Value));
- var teacherds = this.UnitOfWork.QuerySQL(sql2, teacherParams);
- var tsReportViewList = DateTableHelper.DataTableToList<TeacherSchedulingView>(teacherds.Tables[0]);
- List<Guid?> teacherIDList = tsReportViewList.Select(x => x.UserID).Distinct().ToList();
- for (int i = templateSheetCount; i < teacherIDList.Count; i += templateSheetCount)
- {
- for (int index = 0; index < templateSheetCount; index++)
- {
- wk.Worksheets.AddCopy(index); //.CopyTo(wk, "Sheet" + (i + 1).ToString(), true, true);
- }
- }
- for (int m = 0; m < teacherIDList.Count(); m++)
- {
- var userID = teacherIDList[m];
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (CollegeID.HasValue)
- {
- sParams.Add(new SqlParameter("@CollegeID", CollegeID));
- }
- else
- {
- sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
- }
- sParams.Add(new SqlParameter("@UserID", userID));
- //if (UserID.HasValue)
- //{
- // sParams.Add(new SqlParameter("@UserID", UserID));
- //}
- //else
- //{
- // sParams.Add(new SqlParameter("@UserID", DBNull.Value));
- //}
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var ws = wk.Worksheets[m];
- string title = "{0}{1}学期课程表-{2}", code = "", staffName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- code = ds.Tables[1].Rows[0]["Code"].ToString();
- staffName = ds.Tables[1].Rows[0]["StaffName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, staffName);
- //聚合唯一
- //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
- dtShow.DefaultView.Sort = "StartTimes asc";
- dtShow = dtShow.DefaultView.ToTable();
- int lineEnd = 2;
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- string col1Format = "{0}\n{1}";
- ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
- string condition = "StartTimes='{0}'";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "StartTimes asc");
- int lineMax = 0;
- for (int j = 0; j < weekRows.Count(); j++)
- {
- int weekDay = (int)weekRows[j]["Weekday"];
- //weekDay += 1;
- var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(weekRows[j]["Name"].ToString());
- sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
- if (weekRows[j]["ClassroomName"] != DBNull.Value)
- {
- sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
- }
- if (weekRows[j]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (weekRows[j]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
- }
- curCell.Value += sbCell.ToString();
- if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
- {
- string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
- }
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
- mergeRange.Merge();
- var style1 = rh.BuildBorderStyle(wk);
- StyleFlag stFlag1 = new StyleFlag();
- stFlag1.Borders = true;
- mergeRange.ApplyStyle(style1, stFlag1);
- var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
- StyleFlag stFlag2 = new StyleFlag();
- stFlag2.LeftBorder = true;
- stFlag2.RightBorder = true;
- weekRange.ApplyStyle(style1, stFlag2);
- StyleFlag stFlag3 = new StyleFlag();
- stFlag3.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
- lineEnd = lineEnd + lineMax + 1;
- }
- ws.AutoFitRows();
- }
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public MemoryStream ClassmajorSchedulingPDF(Guid SchoolyearID, Guid? CollegeID, Guid? ClassmajorID, int? Years)
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/ClassmajorWithSchedule.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (CollegeID.HasValue)
- {
- sParams.Add(new SqlParameter("@CollegeID", CollegeID));
- }
- else
- {
- sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
- }
- if (ClassmajorID.HasValue)
- {
- sParams.Add(new SqlParameter("@ClassmajorID", ClassmajorID));
- }
- else
- {
- sParams.Add(new SqlParameter("@ClassmajorID", DBNull.Value));
- }
- if (Years.HasValue)
- {
- sParams.Add(new SqlParameter("@Years", Years));
- }
- else
- {
- sParams.Add(new SqlParameter("@Years", DBNull.Value));
- }
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var wk = rh.GetReportTemple("EducationScheduling/ClassmajorSchedulingView.xlsx");
- var ws = wk.Worksheets[0];
- string title = "{0}{1}学期课程表-{2}", code = "", classMajorName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- code = ds.Tables[1].Rows[0]["Code"].ToString();
- classMajorName = ds.Tables[1].Rows[0]["ClassMajorName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classMajorName);
- //聚合唯一
- //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
- dtShow.DefaultView.Sort = "StartTimes asc";
- dtShow = dtShow.DefaultView.ToTable();
- int lineEnd = 2;
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- string col1Format = "{0}\n{1}";
- ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
- string condition = "StartTimes='{0}'";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "MinWeekNum asc");
- int lineMax = 0;
- for (int j = 0; j < weekRows.Count(); j++)
- {
- int weekDay = (int)weekRows[j]["Weekday"];
- //weekDay += 1;
- var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(weekRows[j]["Name"].ToString());
- sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
- if (weekRows[j]["ClassroomName"] != DBNull.Value)
- {
- sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
- }
- if (weekRows[j]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (weekRows[j]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
- }
- curCell.Value += sbCell.ToString();
- if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
- {
- string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
- }
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
- mergeRange.Merge();
- var style1 = rh.BuildBorderStyle(wk);
- StyleFlag stFlag1 = new StyleFlag();
- stFlag1.Borders = true;
- mergeRange.ApplyStyle(style1, stFlag1);
- var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
- StyleFlag stFlag2 = new StyleFlag();
- stFlag2.LeftBorder = true;
- stFlag2.RightBorder = true;
- weekRange.ApplyStyle(style1, stFlag2);
- StyleFlag stFlag3 = new StyleFlag();
- stFlag3.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
- lineEnd = lineEnd + lineMax + 1;
- }
- ws.AutoFitRows();
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- public MemoryStream ClassmajorPrintingSchedulingPDF(Guid SchoolyearID, Guid? CollegeID)
- {
- try
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- var wk = rh.GetReportTemple("EducationScheduling/ClassmajorSchedulingView.xlsx");
- var templateSheetCount = wk.Worksheets.Count;
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/ClassmajorWithSchedule.sql");
- List<SqlParameter> classParams = new List<SqlParameter>();
- classParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (CollegeID.HasValue)
- {
- //sParams.Add(new SqlParameter("@CollegeID", CollegeID));
- classParams.Add(new SqlParameter("@CollegeID", CollegeID));
- }
- else
- {
- //sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
- classParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
- }
- classParams.Add(new SqlParameter("@ClassmajorID", DBNull.Value));
- classParams.Add(new SqlParameter("@Years", DBNull.Value));
- var classds = this.UnitOfWork.QuerySQL(sql2, classParams);
- //var classTable = classds.Tables[0];
- var cpsReportViewList = DateTableHelper.DataTableToList<ClassmajorPrintingSchedulingReportView>(classds.Tables[0]);
- List<Guid?> classmajorIDList = cpsReportViewList.Select(x => x.ClassmajorID).Distinct().ToList();
- for (int i = templateSheetCount; i < classmajorIDList.Count; i += templateSheetCount)
- {
- for (int index = 0; index < templateSheetCount; index++)
- {
- wk.Worksheets.AddCopy(index); //.CopyTo(wk, "Sheet" + (i + 1).ToString(), true, true);
- }
- }
- for (int claI = 0; claI < classmajorIDList.Count(); claI++)
- {
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (CollegeID.HasValue)
- {
- sParams.Add(new SqlParameter("@CollegeID", CollegeID));
- }
- else
- {
- sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
- }
- var ClassmajorID = classmajorIDList[claI];
- var cpsReportListByClassmajorID = cpsReportViewList.Where(x => x.ClassmajorID == ClassmajorID).ToList();
- sParams.Add(new SqlParameter("@ClassmajorID", ClassmajorID));
- sParams.Add(new SqlParameter("@Years", DBNull.Value));
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var ws = wk.Worksheets[claI];
- string title = "{0}{1}学期课程表-{2}", code = "", classMajorName = "";
- if(ds.Tables.Count == 0)
- {
- continue;
- }
- if (cpsReportListByClassmajorID.Count > 0)
- {
- code = cpsReportListByClassmajorID.FirstOrDefault().Code.ToString();
- classMajorName = cpsReportListByClassmajorID.FirstOrDefault().ClassMajorName.ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classMajorName);
- //聚合唯一
- //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
- dtShow.DefaultView.Sort = "StartTimes asc";
- dtShow = dtShow.DefaultView.ToTable();
- int lineEnd = 2;
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- string col1Format = "{0}\n{1}";
- ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
- string condition = "StartTimes='{0}'";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "MinWeekNum asc");
- int lineMax = 0;
- for (int j = 0; j < weekRows.Count(); j++)
- {
- int weekDay = (int)weekRows[j]["Weekday"];
- //weekDay += 1;
- var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(weekRows[j]["Name"].ToString());
- sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
- if (weekRows[j]["ClassroomName"] != DBNull.Value)
- {
- sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
- }
- if (weekRows[j]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (weekRows[j]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
- }
- curCell.Value += sbCell.ToString();
- if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
- {
- string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
- }
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
- mergeRange.Merge();
- var style1 = rh.BuildBorderStyle(wk);
- StyleFlag stFlag1 = new StyleFlag();
- stFlag1.Borders = true;
- mergeRange.ApplyStyle(style1, stFlag1);
- var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
- StyleFlag stFlag2 = new StyleFlag();
- stFlag2.LeftBorder = true;
- stFlag2.RightBorder = true;
- weekRange.ApplyStyle(style1, stFlag2);
- StyleFlag stFlag3 = new StyleFlag();
- stFlag3.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
- lineEnd = lineEnd + lineMax + 1;
- }
- ws.AutoFitRows();
- }
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public MemoryStream ClassroomReportPDF(Guid SchoolyearID, Guid? BuildingsInfoID, Guid? ClassroomID)
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/ClassroomSchedulingView.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (BuildingsInfoID.HasValue)
- {
- sParams.Add(new SqlParameter("@BuildingsInfoID", BuildingsInfoID));
- }
- else
- {
- sParams.Add(new SqlParameter("@BuildingsInfoID", DBNull.Value));
- }
- if (ClassroomID.HasValue)
- {
- sParams.Add(new SqlParameter("@ClassroomID", ClassroomID));
- }
- else
- {
- sParams.Add(new SqlParameter("@ClassroomID", DBNull.Value));
- }
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var wk = rh.GetReportTemple("EducationScheduling/ClassroomSchedulingView.xlsx");
- var ws = wk.Worksheets[0];
- string title = "{0}{1}学期课程表-{2}", code = "", classroomName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- code = ds.Tables[1].Rows[0]["Code"].ToString();
- classroomName = ds.Tables[1].Rows[0]["ClassroomName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classroomName);
- //聚合唯一
- //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
- dtShow.DefaultView.Sort = "StartTimes asc";
- dtShow = dtShow.DefaultView.ToTable();
- int lineEnd = 2;
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- string col1Format = "{0}\n{1}";
- ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
- string condition = "StartTimes='{0}'";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "StartTimes asc");
- int lineMax = 0;
- for (int j = 0; j < weekRows.Count(); j++)
- {
- //Name
- int weekDay = (int)weekRows[j]["Weekday"];
- //weekDay += 1;
- var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(weekRows[j]["Name"].ToString());
- sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
- if (weekRows[j]["Name"] != DBNull.Value)
- {
- sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
- }
- if (weekRows[j]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (weekRows[j]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
- }
- curCell.Value = sbCell.ToString();
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
- mergeRange.Merge();
- var style1 = rh.BuildBorderStyle(wk);
- StyleFlag stFlag1 = new StyleFlag();
- stFlag1.Borders = true;
- mergeRange.ApplyStyle(style1, stFlag1);
- var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
- StyleFlag stFlag2 = new StyleFlag();
- stFlag2.LeftBorder = true;
- stFlag2.RightBorder = true;
- weekRange.ApplyStyle(style1, stFlag2);
- StyleFlag stFlag3 = new StyleFlag();
- stFlag3.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
- lineEnd = lineEnd + lineMax + 1;
- }
- ws.AutoFitRows();
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- public MemoryStream ClassroomPrintingReportPDF(Guid SchoolyearID, Guid? BuildingsInfoID)
- {
- try
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/ClassroomSchedulingView.sql");
- var wk = rh.GetReportTemple("EducationScheduling/ClassroomSchedulingView.xlsx");
- var templateSheetCount = wk.Worksheets.Count;
- List<SqlParameter> roomParams = new List<SqlParameter>();
- roomParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (BuildingsInfoID.HasValue)
- {
- roomParams.Add(new SqlParameter("@BuildingsInfoID", BuildingsInfoID));
- }
- else
- {
- roomParams.Add(new SqlParameter("@BuildingsInfoID", DBNull.Value));
- }
- roomParams.Add(new SqlParameter("@ClassroomID", DBNull.Value));
- var roomds = this.UnitOfWork.QuerySQL(sql2, roomParams);
- var csReportViewList = DateTableHelper.DataTableToList<ClassroomSchedulingReportView>(roomds.Tables[0]);
- List<Guid?> roomIDList = csReportViewList.Select(x => x.ClassroomID).Distinct().ToList();
- for (int i = templateSheetCount; i < roomIDList.Count; i += templateSheetCount)
- {
- for (int index = 0; index < templateSheetCount; index++)
- {
- wk.Worksheets.AddCopy(index); //.CopyTo(wk, "Sheet" + (i + 1).ToString(), true, true);
- }
- }
- for (int m = 0; m < roomIDList.Count(); m++)
- {
- var roomID = roomIDList[m];
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (BuildingsInfoID.HasValue)
- {
- sParams.Add(new SqlParameter("@BuildingsInfoID", BuildingsInfoID));
- }
- else
- {
- sParams.Add(new SqlParameter("@BuildingsInfoID", DBNull.Value));
- }
- sParams.Add(new SqlParameter("@ClassroomID", roomID));
- //if (ClassroomID.HasValue)
- //{
- // sParams.Add(new SqlParameter("@ClassroomID", ClassroomID));
- //}
- //else
- //{
- // sParams.Add(new SqlParameter("@ClassroomID", DBNull.Value));
- //}
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var ws = wk.Worksheets[m];
- string title = "{0}{1}学期课程表-{2}", code = "", classroomName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- code = ds.Tables[1].Rows[0]["Code"].ToString();
- classroomName = ds.Tables[1].Rows[0]["ClassroomName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classroomName);
- //聚合唯一
- //ds.Tables[1].DefaultView.Sort = "StartTimes asc";
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times");
- dtShow.DefaultView.Sort = "StartTimes asc";
- dtShow = dtShow.DefaultView.ToTable();
- int lineEnd = 2;
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- string col1Format = "{0}\n{1}";
- ws.Cells[lineEnd, 0].PutValue(string.Format(col1Format, dtShow.Rows[i]["TimeDesc"], dtShow.Rows[i]["Times"] == DBNull.Value ? "" : "<" + dtShow.Rows[i]["Times"].ToString() + ">"));
- string condition = "StartTimes='{0}'";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i]["StartTimes"]), "StartTimes asc");
- int lineMax = 0;
- for (int j = 0; j < weekRows.Count(); j++)
- {
- //Name
- int weekDay = (int)weekRows[j]["Weekday"];
- //weekDay += 1;
- var curCell = GetLastCell(ws, weekDay, 0, lineEnd, ref lineMax);
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(weekRows[j]["Name"].ToString());
- sbCell.Append(weekRows[j]["StudentCount"] == DBNull.Value ? "" : "(" + weekRows[j]["StudentCount"].ToString() + "人)\n");
- if (weekRows[j]["Name"] != DBNull.Value)
- {
- sbCell.Append(weekRows[j]["ClassroomName"].ToString() + "\n");
- }
- if (weekRows[j]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (weekRows[j]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", weekRows[j]["TeacherName"]);
- }
- curCell.Value = sbCell.ToString();
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- var mergeRange = ws.Cells.CreateRange(lineEnd, 0, lineMax + 1, 1);
- mergeRange.Merge();
- var style1 = rh.BuildBorderStyle(wk);
- StyleFlag stFlag1 = new StyleFlag();
- stFlag1.Borders = true;
- mergeRange.ApplyStyle(style1, stFlag1);
- var weekRange = ws.Cells.CreateRange(lineEnd, 1, lineMax + 1, 7);
- StyleFlag stFlag2 = new StyleFlag();
- stFlag2.LeftBorder = true;
- stFlag2.RightBorder = true;
- weekRange.ApplyStyle(style1, stFlag2);
- StyleFlag stFlag3 = new StyleFlag();
- stFlag3.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + lineMax, 1, 1, 7).ApplyStyle(style1, stFlag3);
- lineEnd = lineEnd + lineMax + 1;
- }
- ws.AutoFitRows();
- }
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public MemoryStream DepartmentSchedulingPDF(Guid SchoolyearID, Guid CollegeID, Guid DepartmentID, Guid? HandleModeID)
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/DepartmentWithSchedule.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- sParams.Add(new SqlParameter("@CollegeID ", CollegeID));
- sParams.Add(new SqlParameter("@DepartmentID", DepartmentID));
- if (HandleModeID.HasValue)
- {
- sParams.Add(new SqlParameter("@HandleModeID", HandleModeID));
- }
- else
- {
- sParams.Add(new SqlParameter("@HandleModeID", DBNull.Value));
- }
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var wk = rh.GetReportTemple("EducationScheduling/DepartmentWithSchedule.xlsx");
- var ws = wk.Worksheets[0];
- string title = "{0}{1}学期-{2}课程表", schoolyearCode = "", DepartmentName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- schoolyearCode = ds.Tables[1].Rows[0]["SchoolyearCode"].ToString();
- DepartmentName = ds.Tables[1].Rows[0]["DepartmentName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], schoolyearCode, DepartmentName);
- //聚合唯一
- var dtShow = ds.Tables[1].DefaultView.ToTable(true, "CourseName", "EducationMissionClassName", "TotalHours", "StudentCount", "TeacherName", "TitleDesc");
- for (int i = 0; i < dtShow.Rows.Count; i++)
- {
- ws.Cells[i + 2, 0].PutValue(dtShow.Rows[i]["CourseName"]);
- ws.Cells[i + 2, 1].PutValue(dtShow.Rows[i]["EducationMissionClassName"]);
- ws.Cells[i + 2, 2].PutValue(dtShow.Rows[i]["TotalHours"]);
- ws.Cells[i + 2, 3].PutValue(dtShow.Rows[i]["StudentCount"]);
- ws.Cells[i + 2, 4].PutValue(dtShow.Rows[i]["TeacherName"]);
- ws.Cells[i + 2, 5].PutValue(dtShow.Rows[i]["TitleDesc"]);
- //周几方法
- try
- {
- string condition = "CourseName='{0}' and EducationMissionClassName='{1}' and TotalHours='{2}' and StudentCount='{3}' and TeacherName='{4}' and TitleDesc='{5}' ";
- var weekRows = ds.Tables[1].Select(string.Format(condition, dtShow.Rows[i].ItemArray), "StartTimes asc");
- for (int j = 0; j < weekRows.Count(); j++)
- {
- int weekDay = (int)weekRows[j]["Weekday"] == 0 ? 7 : (int)weekRows[j]["Weekday"];
- weekDay += 5;
- var curCell = ws.Cells[i + 2, weekDay];
- if (weekRows[j]["ClassroomID"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(weekRows[j]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- string timeNum = rh.SetNumberMerge(weekRows[j]["Times"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- if (curCell.Value != null && curCell.Value.ToString() != "")
- {
- curCell.Value += " \n";
- }
- else
- {
- curCell.Value = "";
- }
- curCell.Value += string.Format("第{0}周\n第{1}节\n({2})", weekNum, timeNum, weekRows[j]["ClassroomName"]);
- }
- if (weekRows[j]["StopWeekNumStr"] != DBNull.Value)
- {
- string stopStr = rh.SetNumberMerge(weekRows[j]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
- }
- }
- }
- catch (Exception ex)
- {
- var a = ex;
- }
- }
- var style = rh.BuildBorderStyle(wk);
- //style.IsTextWrapped = true;
- if (dtShow.Rows.Count > 0)
- {
- var wstrange = ws.Cells.CreateRange(2, 0, dtShow.Rows.Count, 13);
- StyleFlag stFlag = new StyleFlag();
- stFlag.Borders = true;
- wstrange.ApplyStyle(style, stFlag);
- }
- ws.AutoFitColumns(0, 5);
- ws.AutoFitRows();
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- public MemoryStream CollegeSchedulingPDF(Guid SchoolyearID, Guid? CollegeID, int? Years)
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("EducationScheduling/ClassmajorWithSchedule.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- sParams.Add(new SqlParameter("@SchoolyearID", SchoolyearID));
- if (CollegeID.HasValue)
- {
- sParams.Add(new SqlParameter("@CollegeID", CollegeID));
- }
- else
- {
- sParams.Add(new SqlParameter("@CollegeID", DBNull.Value));
- }
- sParams.Add(new SqlParameter("@ClassmajorID", DBNull.Value));
- if (Years.HasValue)
- {
- sParams.Add(new SqlParameter("@Years", Years));
- }
- else
- {
- sParams.Add(new SqlParameter("@Years", DBNull.Value));
- }
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var wk = rh.GetReportTemple("EducationScheduling/CollegeSchedulingView.xlsx");
- var ws = wk.Worksheets[0];
- string title = "{0}{1}学期课程表-{2}", code = "", classMajorName = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- code = ds.Tables[1].Rows[0]["Code"].ToString();
- classMajorName = ds.Tables[1].Rows[0]["CollegeName"].ToString();
- }
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], code, classMajorName);
- var dicWeeks = GetDicWeeks();
- var dtTimes = ds.Tables[1].DefaultView.ToTable(true, "StartTimes", "TimeDesc", "Times").AsEnumerable().OrderBy(o => o.Field<int>("StartTimes")).ToList();
- //表头
- for (int i = 0; i < dicWeeks.Count; i++)
- {
- var rowFirst = i * dtTimes.Count + 2;
- ws.Cells[1, rowFirst].PutValue(dicWeeks[i].Item2);
- for (int j = 0; j < dtTimes.Count; j++)
- {
- string subTitle = "";
- if (dtTimes[j]["Times"] != DBNull.Value)
- {
- subTitle += "<" + dtTimes[j].Field<string>("Times") + ">\n";
- }
- if (dtTimes[j]["TimeDesc"] != DBNull.Value)
- {
- subTitle += dtTimes[j].Field<string>("TimeDesc");
- }
- ws.Cells[2, rowFirst + j].PutValue(subTitle);
- }
- var subTitleRange = ws.Cells.CreateRange(1, rowFirst, 1, dtTimes.Count);
- subTitleRange.Merge();
- }
- ws.Cells.CreateRange(0, 0, 1, dtTimes.Count * dicWeeks.Count + 2).Merge();
- ws.Cells.CreateRange(1, 0, 2, 2).Merge();
- var titleRange = ws.Cells.CreateRange(0, 0, 3, dtTimes.Count * dicWeeks.Count + 2);
- var style = rh.BuildBorderStyle(wk);
- StyleFlag stFlag = new StyleFlag();
- stFlag.Borders = true;
- titleRange.ApplyStyle(style, stFlag);
- //学年和班级聚合
- var dtSecond = ds.Tables[1].DefaultView.ToTable(true, "GrademajorID", "GrademajorName", "ClassMajorID", "ClassMajorName");
- dtSecond.DefaultView.Sort = "GrademajorName asc";
- var dtFirst = dtSecond.DefaultView.ToTable(true, "GrademajorID", "GrademajorName");
- int lineEnd = 3;
- for (int i = 0; i < dtFirst.Rows.Count; i++)
- {
- string condition = "GrademajorID='{0}'";
- var classRows = dtSecond.Select(string.Format(condition, dtFirst.Rows[i]["GrademajorID"]), "ClassMajorName asc");
- int jLineMax = 0;
- for (int j = 0; j < classRows.Count(); j++)
- {
- string conditionItem = "GrademajorID='{0}' and ClassMajorID='{1}'";
- var cellItems = ds.Tables[1].Select(string.Format(conditionItem, classRows[j]["GrademajorID"], classRows[j]["ClassMajorID"]));
- int klineMax = 0;
- for (int k = 0; k < cellItems.Count(); k++)
- {
- int addCol = 2;
- addCol += dtTimes.FindIndex(w => w.Field<int>("StartTimes") == cellItems[k].Field<int>("StartTimes"));
- var curCell = GetCrossTimeCell(ws, cellItems[k].Field<int>("Weekday"), dtTimes.Count, addCol, lineEnd + jLineMax, ref klineMax);
- //var curCell=GetLastCell(ws,(int)cellItems[k]["Weekday"],
- try
- {
- StringBuilder sbCell = new StringBuilder();
- sbCell.AppendLine(cellItems[k]["Name"].ToString());
- sbCell.Append(cellItems[k]["StudentCount"] == DBNull.Value ? "" : "(" + cellItems[k]["StudentCount"].ToString() + "人)\n");
- if (cellItems[k]["Name"] != DBNull.Value)
- {
- sbCell.Append(cellItems[k].Field<string>("ClassroomName") + "\n");
- }
- if (cellItems[k]["WeekNums"] != DBNull.Value)
- {
- string weekNum = rh.SetNumberMerge(cellItems[k]["WeekNums"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- sbCell.AppendFormat("第{0}周\n", weekNum);
- }
- if (cellItems[k]["TeacherName"] != DBNull.Value)
- {
- sbCell.AppendFormat("<{0}>\n", cellItems[k]["TeacherName"]);
- }
- curCell.Value = sbCell.ToString();
- if (cellItems[k]["StopWeekNumStr"] != DBNull.Value)
- {
- string stopStr = rh.SetNumberMerge(cellItems[k]["StopWeekNumStr"].ToString().Split(',').Select(s => int.Parse(s)).ToList());
- curCell.HtmlString += string.Format("<Br><Font Style=\"COLOR: #FF0000;\">({0}停课)</Font>", stopStr);
- }
- //curCell.PutValue(sbCell.ToString());
- }
- catch
- {
- }
- }
- //第二格合并
- ws.Cells[lineEnd + jLineMax, 1].Value = classRows[j].Field<string>("ClassMajorName").Replace(classRows[j].Field<string>("GrademajorName"), "");
- ws.Cells.CreateRange(lineEnd + jLineMax, 1, klineMax + 1, 1).Merge();
- StyleFlag jLineFlag = new StyleFlag();
- jLineFlag.LeftBorder = true;
- jLineFlag.RightBorder = true;
- ws.Cells.CreateRange(lineEnd + jLineMax, 0, klineMax + 1, dtTimes.Count * dicWeeks.Count + 2).ApplyStyle(style, jLineFlag);
- StyleFlag jLinebuttFlag = new StyleFlag();
- jLinebuttFlag.BottomBorder = true;
- ws.Cells.CreateRange(lineEnd + jLineMax + klineMax, 1, 1, dtTimes.Count * dicWeeks.Count + 2).ApplyStyle(style, jLinebuttFlag);
- //style
- //lineEnd
- jLineMax += klineMax + 1;
- }
- //第一格合并
- ws.Cells[lineEnd, 0].Value = dtFirst.Rows[i].Field<string>("GrademajorName");
- var gRange = ws.Cells.CreateRange(lineEnd, 0, jLineMax, 1);
- gRange.Merge();
- StyleFlag gFlag = new StyleFlag();
- gFlag.Borders = true;
- gRange.ApplyStyle(style, gFlag);
- lineEnd += jLineMax;
- }
- ws.AutoFitRows();
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- public MemoryStream StudentCountPDF(int? InSchoolStatusID)
- {
- try
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- StyleFlag commentFlag = new StyleFlag();
- commentFlag.Borders = true;
- commentFlag.Font = true;
- commentFlag.VerticalAlignment = true;
- commentFlag.HorizontalAlignment = true;
- string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("StudentManage/StudentCountView.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- if (InSchoolStatusID.HasValue)
- {
- sParams.Add(new SqlParameter("@InSchoolStatusID", InSchoolStatusID));
- }
- else
- {
- sParams.Add(new SqlParameter("@InSchoolStatusID", DBNull.Value));
- }
- var ds = this.UnitOfWork.QuerySQL(sql1 + "\r\n" + sql2, sParams);
- var wk = rh.GetReportTemple("StudentManage/StudentCountView.xlsx");
- var ws = wk.Worksheets[0];
- var style = rh.BuildBorderStyle(wk);
- int allRow = 4;
- string title = "{0}{1}学生学籍信息统计表", schoolyearCode = "";
- if (ds.Tables[1].Rows.Count > 0)
- {
- schoolyearCode = ds.Tables[1].Rows[0]["SchoolyearCode"].ToString();
- }
- var table1 = DateTableHelper.DataTableToList<StudentCountReportView>(ds.Tables[1]);
- var gradeYearCount = table1.Select(x => x.GradeYear).Distinct().ToList().Count();
- var educationNameList = table1.Select(x => new { x.EducationID, x.EducationName }).Distinct().OrderBy(x => x.EducationID).ToList();
- var studentTypeList = table1.Select(x => new { x.EducationID, x.EducationName, x.StudentType, x.StudentTypeName }).Distinct().OrderBy(x => x.StudentType).ToList();
- var gGradeYearList = table1.GroupBy(x => new { x.GradeYear, x.EducationID, x.EducationName, x.StudentType, x.StudentTypeName }).Select(x => new
- {
- GradeYear = x.Key.GradeYear,
- StudentMaleCount = x.Sum(y => y.StudentMaleCount),
- StudentFemaleCount = x.Sum(y => y.StudentFemaleCount),
- ClassmajorCount = x.Sum(y => y.ClassmajorCount),
- EducationID = x.Key.EducationID,
- EducationName = x.Key.EducationName,
- StudentType = x.Key.StudentType,
- StudentTypeName = x.Key.StudentTypeName,
- }).OrderBy(x => x.GradeYear).ToList();
- var campusNameList = table1.Select(x => new { x.CampusID, x.CampusNo, x.CampusName }).OrderBy(x => x.CampusID).Distinct().OrderBy(x => x.CampusID).ToList();
- var collegeNameList = table1.Select(x => new { x.CampusID, x.CampusNo, x.CampusName, x.CollegeID, x.CollegeNo, x.CollegeName }).Distinct().OrderBy(x => x.CollegeID).ToList();
- 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();
- var gGradeYearList2 = table1.GroupBy(x => new
- {
- x.GradeYear,
- x.EducationID,
- x.EducationName,
- x.StudentType,
- x.StudentTypeName,
- x.CampusID,
- x.CampusNo,
- x.CampusName,
- x.CollegeID,
- x.CollegeNo,
- x.CollegeName,
- x.StandardID,
- x.StandardName
- }).Select(x => new
- {
- GradeYear = x.Key.GradeYear,
- StudentMaleCount = x.Sum(y => y.StudentMaleCount),
- StudentFemaleCount = x.Sum(y => y.StudentFemaleCount),
- ClassmajorCount = x.Sum(y => y.ClassmajorCount),
- EducationID = x.Key.EducationID,
- EducationName = x.Key.EducationName,
- StudentType = x.Key.StudentType,
- StudentTypeName = x.Key.StudentTypeName,
- CampusID = x.Key.CampusID,
- CampusNo = x.Key.CampusNo,
- CampusName = x.Key.CampusName,
- CollegeID = x.Key.CollegeID,
- CollegeNo = x.Key.CollegeNo,
- CollegeName = x.Key.CollegeName,
- StandardID = x.Key.StandardID,
- StandardName = x.Key.StandardName,
- }).OrderBy(x => x.CampusID).ThenBy(x => x.CollegeID).ThenBy(x => x.StandardID).ThenBy(x => x.GradeYear).ToList();
- var collegeTotalList = table1.GroupBy(x => new
- {
- x.CollegeID,
- x.CollegeNo,
- x.CollegeName,
- x.GradeYear,
- x.StudentType,
- x.StudentTypeName,
- x.EducationID,
- x.EducationName,
- }).Select(x => new
- {
- GradeYear = x.Key.GradeYear,
- StudentMaleCount = x.Sum(y => y.StudentMaleCount),
- StudentFemaleCount = x.Sum(y => y.StudentFemaleCount),
- ClassmajorCount = x.Sum(y => y.ClassmajorCount),
- CollegeID = x.Key.CollegeID,
- CollegeNo = x.Key.CollegeNo,
- CollegeName = x.Key.CollegeName,
- StudentType = x.Key.StudentType,
- StudentTypeName = x.Key.StudentTypeName,
- EducationID = x.Key.EducationID,
- EducationName = x.Key.EducationName,
- }).OrderBy(x => x.CollegeID).ThenBy(x => x.GradeYear).ToList();
- ws.Cells[0, 0].Value = string.Format(title, ds.Tables[0].Rows[0]["Name"], schoolyearCode);
- var titleRange = ws.Cells.CreateRange(0, 0, 1, 5 * studentTypeList.Count + 5);
- var titlestyle = rh.BuildBorderStyleAndSize(wk);
- titleRange.Merge();
- StyleFlag titleFlag = new StyleFlag();
- titleFlag.Borders = true;
- titleFlag.Font = true;
- titleFlag.VerticalAlignment = true;
- titleFlag.HorizontalAlignment = true;
- titleRange.ApplyStyle(titlestyle, titleFlag);
- var colCount = 4;
- var rowCount = 1;
- for (int i = 0; i < educationNameList.Count; i++)
- {
- var education = educationNameList[i];
- //第一行标题合并
- ws.Cells[rowCount, colCount].Value = education.EducationName;
- var gRange = ws.Cells.CreateRange(rowCount, colCount, 1, 5);
- gRange.Merge();
- gRange.ApplyStyle(style, commentFlag);
- var stCount = colCount;
- var studentTypeListByEducation = studentTypeList.Where(x => x.EducationID == education.EducationID).ToList();
- for (int j = 0; j < studentTypeListByEducation.Count; j++)
- {
- var studentType = studentTypeListByEducation[j];
- //第三行标题
- ws.Cells[rowCount + 2, stCount].Value = "男";
- ws.Cells[rowCount + 2, stCount].SetStyle(style);
- ws.Cells[rowCount + 2, stCount + 1].Value = "女";
- ws.Cells[rowCount + 2, stCount + 1].SetStyle(style);
- ws.Cells[rowCount + 2, stCount + 2].Value = "总人数";
- ws.Cells[rowCount + 2, stCount + 2].SetStyle(style);
- ws.Cells[rowCount + 2, stCount + 3].Value = "班级数";
- ws.Cells[rowCount + 2, stCount + 3].SetStyle(style);
- //第二行标题合并
- ws.Cells[rowCount + 1, stCount].Value = studentType.StudentTypeName;
- var stRange = ws.Cells.CreateRange(rowCount + 1, stCount, 1, 4);
- stRange.Merge();
- stRange.ApplyStyle(style, commentFlag);
- stCount += 4;
- ws.Cells[rowCount + 1, stCount].Value = "小计";
- var xiaojiRange = ws.Cells.CreateRange(rowCount + 1, stCount, 2, 1);
- xiaojiRange.Merge();
- xiaojiRange.ApplyStyle(style, commentFlag);
- stCount += 1;
- var gradeYearListByStudentType = gGradeYearList.Where(x => x.EducationID == education.EducationID && x.StudentType == studentType.StudentType).ToList();
- int? allSchoolMaleCount = 0;
- int? allSchoolFemaleCount = 0;
- int? allSchoolClassCount = 0;
- for (int k = 0; k < gradeYearListByStudentType.Count; k++)
- {
- var gradeYear = gradeYearListByStudentType[k];
- if (j == 0)
- {
- //年级
- ws.Cells[allRow + k, 3].Value = gradeYear.GradeYear.ToString();
- ws.Cells[allRow + k, 3].SetStyle(style);
- }
- //男
- ws.Cells[allRow + k, 4 + j * 4].Value = gradeYear.StudentMaleCount.ToString();
- ws.Cells[allRow + k, 4 + j * 4].SetStyle(style);
- allSchoolMaleCount += gGradeYearList[i].StudentMaleCount;
- //女
- ws.Cells[allRow + k, 5 + j * 4].Value = gradeYear.StudentFemaleCount.ToString();
- ws.Cells[allRow + k, 5 + j * 4].SetStyle(style);
- allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
- //总
- ws.Cells[allRow + k, 6 + j * 4].Value = (gradeYear.StudentMaleCount + gradeYear.StudentFemaleCount).ToString();
- ws.Cells[allRow + k, 6 + j * 4].SetStyle(style);
- //班级数
- ws.Cells[allRow + k, 7 + j * 4].Value = gradeYear.ClassmajorCount.ToString();
- ws.Cells[allRow + k, 7 + j * 4].SetStyle(style);
- allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
- if (j == studentTypeListByEducation.Count - 1)
- {
- //小计
- var xiaojiCount = gGradeYearList.Where(x => x.EducationID == education.EducationID && x.GradeYear == gradeYear.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + k, 8 + j * 4].Value = xiaojiCount.ToString();
- ws.Cells[allRow + k, 8 + j * 4].SetStyle(style);
- }
- if (i == educationNameList.Count - 1)
- {
- //总计
- var zongjiCount = gGradeYearList2.Where(x => x.GradeYear == gradeYear.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + k, 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
- ws.Cells[allRow + k, 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
- }
- }
- //总计
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 4 + j * 4].Value = allSchoolMaleCount;
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 4 + j * 4].SetStyle(style);
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 5 + j * 4].Value = allSchoolFemaleCount;
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 5 + j * 4].SetStyle(style);
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 6 + j * 4].Value = allSchoolMaleCount + allSchoolFemaleCount;
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 6 + j * 4].SetStyle(style);
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 7 + j * 4].Value = allSchoolClassCount;
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 7 + j * 4].SetStyle(style);
- if (j == studentTypeListByEducation.Count - 1)
- {
- //总计小计
- var xiaojiCount = gGradeYearList.Where(x => x.EducationID == education.EducationID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 8 + j * 4].Value = xiaojiCount.ToString();
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 8 + j * 4].SetStyle(style);
- }
- if (i == educationNameList.Count - 1)
- {
- //总计小计
- var xiaojiCount = gGradeYearList.Where(x => x.EducationID == education.EducationID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].Value = xiaojiCount.ToString();
- ws.Cells[allRow + gradeYearListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
- }
- allRow += gradeYearListByStudentType.Count + 1;
- }
- colCount += 5;
- }
- for (int i = 0; i < campusNameList.Count(); i++)
- {
- var campus = campusNameList[i];
- int? campusRowCout = 0;
- var collegeListByCampus = collegeNameList.Where(x => x.CampusID == campus.CampusID).OrderBy(x => x.CollegeID).ToList();
- var campusStartRow = allRow;
- for (int j = 0; j < collegeListByCampus.Count(); j++)
- {
- var college = collegeListByCampus[j];
- int? collegeRowCount = 0;
- //var collegeGradeYearCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID).Count();
- //ws.Cells[allRow, 2].Value = college.CollegeName;
- //var collegeRange = ws.Cells.CreateRange(allRow, 2, 1, collegeRowCount.Value);
- //collegeRange.Merge();
- //collegeRange.ApplyStyle(style, commentFlag);
- //campusRowCout += collegeGradeYearCount + 1;
- var startRow = allRow;
- var standardListByCollege = standardNameList.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID).OrderBy(x => x.StandardID).ToList();
- for (int k = 0; k < standardListByCollege.Count(); k++)
- {
- var standard = standardListByCollege[k];
- var standardGradeYearCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
- && x.StandardID == standard.StandardID).Count();
- collegeRowCount += standardGradeYearCount + 1;
- ws.Cells[allRow, 2].Value = standard.StandardName;
- var gRange = ws.Cells.CreateRange(allRow, 2, standardGradeYearCount + 1, 1);
- gRange.Merge();
- gRange.ApplyStyle(style, commentFlag);
- for (int m = 0; m < educationNameList.Count(); m++)
- {
- var education = educationNameList[m];
- var studentTypeListByEducation = studentTypeList.Where(x => x.EducationID == education.EducationID).OrderBy(x => x.StudentType).ToList();
- for (int n = 0; n < studentTypeListByEducation.Count(); n++)
- {
- var studentType = studentTypeListByEducation[n];
- var dbListByStudentType = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
- && x.StandardID == standard.StandardID && x.EducationID == education.EducationID && x.StudentType == studentType.StudentType).OrderBy(x => x.GradeYear).ToList();
- //int? allSchoolMaleCount = 0;
- //int? allSchoolFemaleCount = 0;
- //int? allSchoolClassCount = 0;
- for (int p = 0; p < dbListByStudentType.Count(); p++)
- {
- var db = dbListByStudentType[p];
- if (n == 0)
- {
- ws.Cells[allRow + p, 3].Value = db.GradeYear;
- ws.Cells[allRow + p, 3].SetStyle(style);
- }
- //男
- ws.Cells[allRow + p, 4 + n * 4].Value = db.StudentMaleCount.ToString();
- ws.Cells[allRow + p, 4 + n * 4].SetStyle(style);
- //allSchoolMaleCount += db.StudentMaleCount;
- //女
- ws.Cells[allRow + p, 5 + n * 4].Value = db.StudentFemaleCount.ToString();
- ws.Cells[allRow + p, 5 + n * 4].SetStyle(style);
- //allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
- //总
- ws.Cells[allRow + p, 6 + n * 4].Value = (db.StudentMaleCount + db.StudentFemaleCount).ToString();
- ws.Cells[allRow + p, 6 + n * 4].SetStyle(style);
- //班级数
- ws.Cells[allRow + p, 7 + n * 4].Value = db.ClassmajorCount.ToString();
- ws.Cells[allRow + p, 7 + n * 4].SetStyle(style);
- //allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
- if (n == studentTypeListByEducation.Count - 1)
- {
- //小计
- var xiaojiCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
- && x.StandardID == standard.StandardID && x.EducationID == education.EducationID
- && x.GradeYear == db.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + p, 8 + n * 4].Value = xiaojiCount.ToString();
- ws.Cells[allRow + p, 8 + n * 4].SetStyle(style);
- }
- if (m == educationNameList.Count - 1)
- {
- //总计
- var zongjiCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
- && x.StandardID == standard.StandardID && x.GradeYear == db.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + p, 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
- ws.Cells[allRow + p, 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
- }
- }
- if (n == 0)
- {
- ws.Cells[allRow + dbListByStudentType.Count(), 3].Value = "小计";
- ws.Cells[allRow + dbListByStudentType.Count(), 3].SetStyle(style);
- }
- //男
- ws.Cells[allRow + dbListByStudentType.Count(), 4 + n * 4].Value = dbListByStudentType.Sum(x => x.StudentMaleCount).ToString();
- ws.Cells[allRow + dbListByStudentType.Count(), 4 + n * 4].SetStyle(style);
- //allSchoolMaleCount += db.StudentMaleCount;
- //女
- ws.Cells[allRow + dbListByStudentType.Count(), 5 + n * 4].Value = dbListByStudentType.Sum(x => x.StudentFemaleCount).ToString();
- ws.Cells[allRow + dbListByStudentType.Count(), 5 + n * 4].SetStyle(style);
- //allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
- //总
- ws.Cells[allRow + dbListByStudentType.Count(), 6 + n * 4].Value = dbListByStudentType.Sum(x => x.StudentFemaleCount + x.StudentFemaleCount).ToString();
- ws.Cells[allRow + dbListByStudentType.Count(), 6 + n * 4].SetStyle(style);
- //班级数
- ws.Cells[allRow + dbListByStudentType.Count(), 7 + n * 4].Value = dbListByStudentType.Sum(x => x.ClassmajorCount).ToString();
- ws.Cells[allRow + dbListByStudentType.Count(), 7 + n * 4].SetStyle(style);
- //allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
- if (n == studentTypeListByEducation.Count - 1)
- {
- //小计
- var xiaojiCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
- && x.StandardID == standard.StandardID && x.EducationID == education.EducationID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + dbListByStudentType.Count(), 8 + n * 4].Value = xiaojiCount.ToString();
- ws.Cells[allRow + dbListByStudentType.Count(), 8 + n * 4].SetStyle(style);
- }
- if (m == educationNameList.Count - 1)
- {
- //总计
- var zongjiCount = gGradeYearList2.Where(x => x.CampusID == campus.CampusID && x.CollegeID == college.CollegeID
- && x.StandardID == standard.StandardID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + dbListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
- ws.Cells[allRow + dbListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
- }
- }
- }
- allRow += standardGradeYearCount + 1;
- }
- var collegeList = collegeTotalList.Where(x => x.CollegeID == college.CollegeID).ToList();
- var gradeYearByCollegeList = collegeList.Select(x => x.GradeYear).Distinct().ToList();
- for (int s = 0; s < educationNameList.Count(); s++)
- {
- var education = educationNameList[s];
- //var collegeTotalListByEducation = collegeList.Where(x => x.EducationID == education.EducationID).ToList();
- var studentTypeListByEducation = studentTypeList.Where(x => x.EducationID == education.EducationID).ToList();
- for (int t = 0; t < studentTypeListByEducation.Count(); t++)
- {
- var studentType = studentTypeListByEducation[t];
- var collegeTotalListByStudentType = collegeList.Where(x => x.EducationID == education.EducationID && x.StudentType == studentType.StudentType).ToList();
- for (int u = 0; u < collegeTotalListByStudentType.Count(); u++)
- {
- var db = collegeTotalListByStudentType[u];
- if (t == 0)
- {
- ws.Cells[allRow + u, 3].Value = db.GradeYear;
- var collegeYearRange = ws.Cells.CreateRange(allRow + u, 2, 1, 2);
- collegeYearRange.Merge();
- collegeYearRange.ApplyStyle(style, commentFlag);
- }
- //男
- ws.Cells[allRow + u, 4 + t * 4].Value = db.StudentMaleCount.ToString();
- ws.Cells[allRow + u, 4 + t * 4].SetStyle(style);
- //allSchoolMaleCount += db.StudentMaleCount;
- //女
- ws.Cells[allRow + u, 5 + t * 4].Value = db.StudentFemaleCount.ToString();
- ws.Cells[allRow + u, 5 + t * 4].SetStyle(style);
- //allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
- //总
- ws.Cells[allRow + u, 6 + t * 4].Value = (db.StudentMaleCount + db.StudentFemaleCount).ToString();
- ws.Cells[allRow + u, 6 + t * 4].SetStyle(style);
- //班级数
- ws.Cells[allRow + u, 7 + t * 4].Value = db.ClassmajorCount.ToString();
- ws.Cells[allRow + u, 7 + t * 4].SetStyle(style);
- //allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
- if (t == studentTypeListByEducation.Count - 1)
- {
- //小计
- var xiaojiCount = collegeList.Where(x => x.EducationID == education.EducationID && x.GradeYear == db.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + u, 8 + t * 4].Value = xiaojiCount.ToString();
- ws.Cells[allRow + u, 8 + t * 4].SetStyle(style);
- }
- if (s == educationNameList.Count - 1)
- {
- //总计
- var zongjiCount = collegeList.Where(x => x.GradeYear == db.GradeYear).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + u, 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
- ws.Cells[allRow + u, 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
- }
- }
- if (t == 0)
- {
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 3].Value = "合计";
- var collegehejiRange = ws.Cells.CreateRange(allRow + collegeTotalListByStudentType.Count(), 2, 1, 2);
- collegehejiRange.Merge();
- collegehejiRange.ApplyStyle(style, commentFlag);
- }
- //男
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 4 + t * 4].Value = collegeTotalListByStudentType.Sum(x => x.StudentMaleCount).ToString();
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 4 + t * 4].SetStyle(style);
- //allSchoolMaleCount += db.StudentMaleCount;
- //女
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 5 + t * 4].Value = collegeTotalListByStudentType.Sum(x => x.StudentFemaleCount).ToString();
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 5 + t * 4].SetStyle(style);
- //allSchoolFemaleCount += gGradeYearList[i].StudentFemaleCount;
- //总
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 6 + t * 4].Value = collegeTotalListByStudentType.Sum(x => x.StudentFemaleCount + x.StudentFemaleCount).ToString();
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 6 + t * 4].SetStyle(style);
- //班级数
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 7 + t * 4].Value = collegeTotalListByStudentType.Sum(x => x.ClassmajorCount).ToString();
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 7 + t * 4].SetStyle(style);
- //allSchoolClassCount += gGradeYearList[i].ClassmajorCount;
- if (t == studentTypeListByEducation.Count - 1)
- {
- //小计
- var xiaojiCount = collegeList.Where(x => x.EducationID == education.EducationID).Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 8 + t * 4].Value = xiaojiCount.ToString();
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 8 + t * 4].SetStyle(style);
- }
- if (s == educationNameList.Count - 1)
- {
- //总计
- var zongjiCount = collegeList.Sum(x => x.StudentMaleCount + x.StudentFemaleCount);
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].Value = zongjiCount.ToString();
- ws.Cells[allRow + collegeTotalListByStudentType.Count(), 4 + studentTypeListByEducation.Count * 5].SetStyle(style);
- }
- }
- }
- allRow += gradeYearByCollegeList.Count() + 1;
- ws.Cells[startRow, 1].Value = college.CollegeName;
- var collegeRange = ws.Cells.CreateRange(startRow, 1, collegeRowCount.Value, 1);
- collegeRange.Merge();
- collegeRange.ApplyStyle(style, commentFlag);
- ws.Cells[startRow + collegeRowCount.Value + 1, 1].Value = college.CollegeName + "合计";
- var collegeTotalRange = ws.Cells.CreateRange(startRow + collegeRowCount.Value, 1, gradeYearByCollegeList.Count() + 1, 1);
- collegeTotalRange.Merge();
- collegeTotalRange.ApplyStyle(style, commentFlag);
- campusRowCout += collegeRowCount + gradeYearByCollegeList.Count() + 1;
- }
- ws.Cells[campusStartRow, 0].Value = campus.CampusName;
- var campusRange = ws.Cells.CreateRange(campusStartRow, 0, campusRowCout.Value, 1);
- campusRange.Merge();
- campusRange.ApplyStyle(style, commentFlag);
- }
- ws.Cells[rowCount, colCount].Value = "合计";
- var hejiRange = ws.Cells.CreateRange(1, colCount, 3, 1);
- hejiRange.Merge();
- hejiRange.ApplyStyle(style, commentFlag);
- //var gGradeYear = dtGradeYear.GroupBy(x => x.Field<int>("GradeYear")).ToList();
- //校区
- ws.Cells[4, 0].Value = "校区";
- var xiaoquRange = ws.Cells.CreateRange(4, 0, gradeYearCount + 1, 1);
- xiaoquRange.Merge();
- xiaoquRange.ApplyStyle(style, commentFlag);
- //全校
- ws.Cells[4, 1].Value = "全校";
- var quanxiaoRange = ws.Cells.CreateRange(4, 1, gradeYearCount + 1, 2);
- quanxiaoRange.Merge();
- quanxiaoRange.ApplyStyle(style, commentFlag);
- //全校总计
- ws.Cells[4 + gradeYearCount, 3].Value = "总计";
- var quanxiaoHejiRange = ws.Cells.CreateRange(4 + gradeYearCount, 3, 1, 1);
- quanxiaoHejiRange.Merge();
- quanxiaoHejiRange.ApplyStyle(style, commentFlag);
- ws.AutoFitColumns();
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public MemoryStream StudentStatisticsPDF(int? InSchoolStatusID)
- {
- try
- {
- ReportHelper rh = new ReportHelper();
- MemoryStream ms = new MemoryStream();
- StyleFlag commentFlag = new StyleFlag();
- commentFlag.Borders = true;
- commentFlag.Font = true;
- commentFlag.VerticalAlignment = true;
- commentFlag.HorizontalAlignment = true;
- //string sql1 = rh.GetReportSql("EducationScheduling/University.sql");
- string sql2 = rh.GetReportSql("StudentManage/StudentStatisticsData.sql");
- List<SqlParameter> sParams = new List<SqlParameter>();
- if (InSchoolStatusID.HasValue)
- {
- sParams.Add(new SqlParameter("@INSchoolStatus", InSchoolStatusID));
- }
- else
- {
- sParams.Add(new SqlParameter("@INSchoolStatus", DBNull.Value));
- }
- var ds = this.UnitOfWork.QuerySQL(sql2, sParams);
- var wk = rh.GetReportTemple("StudentManage/StudentStatisticsData.xlsx");
- var ws = wk.Worksheets[0];
- var style = rh.BuildBorderStyle(wk);
- var table = DateTableHelper.DataTableToList<StudentStatisticsDataView>(ds.Tables[0]);
- var title = table.FirstOrDefault().unicersityName + table.FirstOrDefault().schoolCode + "年级专业学籍统计表";
- var classNoList = table.Select(x => x.classNo).Distinct().ToList();
- var collegeList = table.Select(x => x.collegeName).Distinct().ToList();
- var listByClassNo = table.GroupBy(x => new { x.collegeName, x.StandardsName, x.year, x.classNo }).ToList();
- ws.Cells[0, 0].Value = title;
- var titleRange = ws.Cells.CreateRange(0, 0, 1, classNoList.Count + 4);
- var titlestyle = rh.BuildBorderStyleAndSize(wk);
- titleRange.Merge();
- StyleFlag titleFlag = new StyleFlag();
- titleFlag.Borders = true;
- titleFlag.Font = true;
- titleFlag.VerticalAlignment = true;
- titleFlag.HorizontalAlignment = true;
- titleRange.ApplyStyle(titlestyle, titleFlag);
- ws.Cells[1, 1].Value = "系所函授站";
- ws.Cells[1, 1].SetStyle(style);
- ws.Cells[1, 2].Value = "院系所专业";
- ws.Cells[1, 2].SetStyle(style);
- ws.Cells[1, 3].Value = "年级";
- ws.Cells[1, 3].SetStyle(style);
- ws.Cells[1, 3 + classNoList.Count()].Value = "总计";
- ws.Cells[1, 3 + classNoList.Count()].SetStyle(style);
- for (int i = 0; i < classNoList.Count(); i++)
- {
- ws.Cells[1, 3 + i + 1].Value = classNoList[i] + "班";
- ws.Cells[1, 3 + i + 1].SetStyle(style);
- }
- for (int i = 0; i < collegeList.Count(); i++)
- {
- var college = collegeList[i];
- var standardList = table.Where(x => x.collegeName == college).Select(x => x.StandardsName).Distinct().ToList();
- for (int j = 0; j < standardList.Count(); j++)
- {
- var standard = standardList[j];
- var yearList = table.Where(x => x.collegeName == college && x.StandardsName == standard).Select(x => x.year).Distinct().ToList();
- //ws.Cells[2 + j, 2].Value = standard;
- //var standardRange = ws.Cells.CreateRange(2, 2, 1, 2);
- //standardRange.Merge();
- //standardRange.ApplyStyle(style, commentFlag);
- for (int k = 0; k < yearList.Count(); k++)
- {
- var year = yearList[k];
- var listByYearAndClassNo = listByClassNo.Where(x => x.Key.year == year).Select(x => new { x.Key.classNo, StudentCount = x.Sum(y => y.StudentCount) }).ToList();
- ws.Cells[2 + k, 3].Value = year;
- ws.Cells[2 + k, 3].SetStyle(style);
- for (int m = 0; m < classNoList.Count(); m++)
- {
- var classNo = classNoList[m];
- var listByClass = listByYearAndClassNo.Where(x => x.classNo == classNo).ToList();
- ws.Cells[2 + k, 3 + m + 1].Value = listByClass.Sum(y => y.StudentCount);
- ws.Cells[2 + k, 3 + m + 1].SetStyle(style);
- }
- }
- }
- }
- wk.Save(ms, Aspose.Cells.SaveFormat.Pdf);
- return ms;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 获取空格和当行最大行数
- /// </summary>
- /// <param name="ws"></param>
- /// <param name="weekDay"></param>
- /// <param name="firstCol"></param>
- /// <param name="lineEnd"></param>
- /// <param name="maxRow">最大行数</param>
- /// <returns>空格</returns>
- private Cell GetLastCell(Worksheet ws, int weekDay, int firstCol, int lineEnd, ref int maxRow)
- {
- int curRow = 0;
- int curCol = weekDay == 0 ? 7 : weekDay;
- curCol += firstCol;
- while (ws.Cells[curRow + lineEnd, curCol].Value != null)
- {
- curRow++;
- }
- if (maxRow < curRow)
- {
- maxRow = curRow;
- }
- return ws.Cells[curRow + lineEnd, curCol];
- }
- /// <summary>
- /// 时间段横向计算定位
- /// </summary>
- /// <param name="ws"></param>
- /// <param name="weekDay"></param>
- /// <param name="dayNum"></param>
- /// <param name="addCol">原始偏量+时间段偏量</param>
- /// <param name="lineEnd"></param>
- /// <param name="maxRow"></param>
- /// <returns></returns>
- private Cell GetCrossTimeCell(Worksheet ws, int weekDay, int dayNum, int addCol, int lineEnd, ref int maxRow)
- {
- int curRow = 0;
- var dicWeeks = GetDicWeeks();
- int curCol = dicWeeks.FindIndex(w => w.Item1 == weekDay) * dayNum;
- curCol += addCol;
- while (ws.Cells[curRow + lineEnd, curCol].Value != null)
- {
- curRow++;
- }
- if (maxRow < curRow)
- {
- maxRow = curRow;
- }
- return ws.Cells[curRow + lineEnd, curCol];
- }
- private List<Tuple<int, string>> GetDicWeeks()
- {
- List<Tuple<int, string>> dic = new List<Tuple<int, string>>();
- dic.Add(new Tuple<int, string>(1, "星期一"));
- dic.Add(new Tuple<int, string>(2, "星期二"));
- dic.Add(new Tuple<int, string>(3, "星期三"));
- dic.Add(new Tuple<int, string>(4, "星期四"));
- dic.Add(new Tuple<int, string>(5, "星期五"));
- dic.Add(new Tuple<int, string>(6, "星期六"));
- dic.Add(new Tuple<int, string>(0, "星期日"));
- return dic;
- }
- }
- }
|