/// <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> 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]; //座號 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, scj.GetClubName); cell = GetMoveRightCell(cell, 1); Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一行 if (Nextrow == null) { break; } cell = Nextrow.FirstCell; //第一格 } return(PageOne); }