/// <summary> /// 每一名學生的報表資料列印 /// </summary> /// <returns></returns> private Document SetDocument(string classID) { List <StudentRecord> StudentList = ClassByStudentDic[classID]; //取得範本樣式 Document PageOne = (Document)_template.Clone(true); #region MailMerge List <string> name = new List <string>(); List <string> value = new List <string>(); name.Add("班級"); value.Add(Class.SelectByID(classID).Name); name.Add("學年度"); value.Add(School.DefaultSchoolYear); name.Add("學期"); value.Add(School.DefaultSemester); PageOne.MailMerge.Execute(name.ToArray(), value.ToArray()); #endregion //??? _run = new Run(PageOne); //可建構的... DocumentBuilder builder = new DocumentBuilder(PageOne); builder.MoveToMergeField("資料"); Cell cell = (Cell)builder.CurrentParagraph.ParentNode; //取得目前Row Row 日3row = (Row)cell.ParentRow; //除了原來的Row-1,高於1就多建立幾行 for (int x = 1; x < StudentList.Count; x++) { cell.ParentRow.ParentTable.InsertAfter(日3row.Clone(true), cell.ParentNode); } foreach (StudentRecord each in StudentList) { StudentSCjoinObj scj = SCjoinObjDic[each.ID]; foreach (CLUBRecord club in scj.CLUBRecord) { //座號 Write(cell, scj.SeatNo); cell = GetMoveRightCell(cell, 1); Write(cell, scj.Name); cell = GetMoveRightCell(cell, 1); Write(cell, scj.StudentNumber); cell = GetMoveRightCell(cell, 1); Write(cell, scj.Gender); cell = GetMoveRightCell(cell, 1); Write(cell, club.ClubName); Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一行 if (Nextrow == null) { break; } cell = Nextrow.FirstCell; //第一格 } } return(PageOne); }
/// <summary> /// 取得學生的社團記錄 /// </summary> private void GetAndSortStudent() { SCjoinObjDic.Clear(); ClassByStudentDic.Clear(); //取得班級清單 List <string> ClassIDList = K12.Presentation.NLDPanels.Class.SelectedSource; foreach (ClassRecord each in Class.SelectByIDs(ClassIDList)) { if (!ClassDic.ContainsKey(each.ID)) { ClassDic.Add(each.ID, each); } } //取得學生清單 List <StudentRecord> studentList = K12.Data.Student.SelectByClassIDs(ClassIDList); foreach (StudentRecord stud in studentList) { if (stud.Status != StudentRecord.StudentStatus.一般 && stud.Status != StudentRecord.StudentStatus.延修) { continue; } if (string.IsNullOrEmpty(stud.RefClassID)) { continue; } //班級:學生ID清單:學生Record if (!ClassByStudentDic.ContainsKey(stud.RefClassID)) { ClassByStudentDic.Add(stud.RefClassID, new List <StudentRecord>()); } if (!ClassByStudentDic[stud.RefClassID].Contains(stud)) { ClassByStudentDic[stud.RefClassID].Add(stud); } //學生ID:特殊Obj StudentSCjoinObj sc = new StudentSCjoinObj(stud); if (!SCjoinObjDic.ContainsKey(stud.ID)) { SCjoinObjDic.Add(stud.ID, sc); } } List <string> StudentIDList = new List <string>(); foreach (StudentRecord sr in studentList) { if (!StudentIDList.Contains(sr.ID)) { StudentIDList.Add(sr.ID); } } //由學生ID去比對SCJoin List <SCJoin> SCJoinLIst = _AccessHelper.Select <SCJoin>("ref_student_id in ('" + string.Join("','", StudentIDList) + "')"); List <CLUBRecord> CLUBList = GetCLUB(SCJoinLIst); Dictionary <string, CLUBRecord> CLUBDic = new Dictionary <string, CLUBRecord>(); foreach (CLUBRecord each in CLUBList) { if (!CLUBDic.ContainsKey(each.UID)) { CLUBDic.Add(each.UID, each); } } //由SCJoin的ref_club_id取得社團資料 foreach (SCJoin each in SCJoinLIst) { if (SCjoinObjDic.ContainsKey(each.RefStudentID)) { if (CLUBDic.ContainsKey(each.RefClubID)) { SCjoinObjDic[each.RefStudentID].CLUBRecord.Add(CLUBDic[each.RefClubID]); } } } }
/// <summary> /// 每一名學生的報表資料列印 /// </summary> /// <returns></returns> private Document SetDocument(string classID) { List <StudentRecord> CheckList = ClassByStudentDic[classID]; List <StudentRecord> StudentList = new List <StudentRecord>(); if (np == NowPrint.empty) //未選 { foreach (StudentRecord each in CheckList) { StudentSCjoinObj scj = SCjoinObjDic[each.ID]; if (scj.CLUBRecord.Count == 0) { StudentList.Add(each); } } } else if (np == NowPrint.General) //已選 { foreach (StudentRecord each in CheckList) { StudentSCjoinObj scj = SCjoinObjDic[each.ID]; if (scj.CLUBRecord.Count == 1) { StudentList.Add(each); } } } else if (np == NowPrint.Repeat) //重覆 { foreach (StudentRecord each in CheckList) { StudentSCjoinObj scj = SCjoinObjDic[each.ID]; if (scj.CLUBRecord.Count > 1) { StudentList.Add(each); } } } else { StudentList.AddRange(CheckList); } //如果沒資料回傳null if (StudentList.Count == 0) { return(null); } //取得範本樣式 Document PageOne = (Document)_template.Clone(true); #region MailMerge List <string> name = new List <string>(); List <string> value = new List <string>(); name.Add("學校名稱"); value.Add(School.ChineseName); name.Add("名稱"); value.Add(RePortName); name.Add("班級"); value.Add(Class.SelectByID(classID).Name); name.Add("學年度"); value.Add("" + _SchoolYear); name.Add("學期"); value.Add("" + _Semester); PageOne.MailMerge.Execute(name.ToArray(), value.ToArray()); #endregion //??? _run = new Run(PageOne); //可建構的... DocumentBuilder builder = new DocumentBuilder(PageOne); builder.MoveToMergeField("資料"); Cell cell = (Cell)builder.CurrentParagraph.ParentNode; //取得目前Row Row 日3row = (Row)cell.ParentRow; int addcount = 0; foreach (StudentRecord each in StudentList) { StudentSCjoinObj scj = SCjoinObjDic[each.ID]; if (scj.CLUBRecord.Count > 0) { foreach (CLUBRecord club in scj.CLUBRecord) { addcount++; } } else { addcount++; } } //除了原來的Row-1,高於1就多建立幾行 for (int x = 1; x < addcount; x++) { cell.ParentRow.ParentTable.InsertAfter(日3row.Clone(true), cell.ParentNode); } foreach (StudentRecord each in StudentList) { StudentSCjoinObj scj = SCjoinObjDic[each.ID]; if (scj.CLUBRecord.Count > 0) { foreach (CLUBRecord club in scj.CLUBRecord) { //座號 Write(cell, scj.SeatNo); cell = GetMoveRightCell(cell, 1); Write(cell, scj.Name); cell = GetMoveRightCell(cell, 1); Write(cell, scj.StudentNumber); cell = GetMoveRightCell(cell, 1); Write(cell, scj.Gender); cell = GetMoveRightCell(cell, 1); Write(cell, club.ClubName); cell = GetMoveRightCell(cell, 1); //社團類型 Write(cell, club.ClubCategory); cell = GetMoveRightCell(cell, 1); //學生擔任幹部 List <string> list = new List <string>(); if (club.President == each.ID) { list.Add("社長"); //社長 } if (club.VicePresident == each.ID) { list.Add("副社長"); } List <CadresRecord> CadreList = tool._A.Select <CadresRecord>("ref_club_id='" + club.UID + "'"); foreach (CadresRecord cadre in CadreList) { if (cadre.RefStudentID == each.ID) { list.Add(cadre.CadreName); } } if (list.Count > 0) { Write(cell, string.Join(",", list)); } Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一行 if (Nextrow == null) { break; } cell = Nextrow.FirstCell; //第一格 } } else { //座號 Write(cell, scj.SeatNo); cell = GetMoveRightCell(cell, 1); Write(cell, scj.Name); cell = GetMoveRightCell(cell, 1); Write(cell, scj.StudentNumber); cell = GetMoveRightCell(cell, 1); Write(cell, scj.Gender); cell = GetMoveRightCell(cell, 1); Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一行 if (Nextrow == null) { break; } cell = Nextrow.FirstCell; //第一格 } } return(PageOne); }