Ejemplo n.º 1
0
        // 排序:年級/班級序號/班級名稱
        private int SortClass(ClassTotalObj obj1, ClassTotalObj obj2)
        {
            //年級
            string seatno1 = obj1.class_grade_year.PadLeft(1, '0');

            seatno1 += obj1.class_index.PadLeft(3, '0');
            seatno1 += obj1.class_name.PadLeft(10, '0');

            string seatno2 = obj2.class_grade_year.PadLeft(1, '0');

            seatno2 += obj2.class_index.PadLeft(3, '0');
            seatno2 += obj2.class_name.PadLeft(10, '0');

            return(seatno1.CompareTo(seatno2));
        }
Ejemplo n.º 2
0
        // 取得班級資料 By SQL
        private List <ClassTotalObj> GetClassOBJ(List <string> _ClassIDList)
        {
            List <ClassTotalObj> list = new List <ClassTotalObj>();
            string classid            = string.Join("','", _ClassIDList);
            string qu = "select class.id,class.class_name,teacher.id as teacher_id,teacher.teacher_name,teacher.nickname,class.grade_year,class.display_order ";

            qu += "from class LEFT join teacher on class.ref_teacher_id=teacher.id ";
            qu += "where class.id in('" + classid + "')";
            DataTable dt = _queryHelper.Select(qu);

            foreach (DataRow row in dt.Rows)
            {
                ClassTotalObj obj = new ClassTotalObj(row);
                list.Add(obj);
            }
            return(list);
        }
Ejemplo n.º 3
0
        // WORD處理
        private Document SetDocument(ClassTotalObj aClass)
        {
            StringBuilder WarningStudents = new StringBuilder();

            // 取得班級中所有學生清單
            List <StudentTotalObj> studentObjList = new List <StudentTotalObj>(aClass.StudentDic.Values);

            //排序
            studentObjList.Sort(SortStudent);

            Document PageOne = (Document)_template.Clone(true);

            _run = new Run(PageOne);
            DocumentBuilder builder = new DocumentBuilder(PageOne);

            int columnCount = aClass.SLRSchoolYearSemesterDic.Count;
            int columnIndex = 1;

            // 文件移到學年度跟學期的標題
            builder.MoveToMergeField("學年度"); // 移到有學年度的標籤上
            Cell cellSchoolYear = (Cell)builder.CurrentParagraph.ParentNode;

            // 準備學年度跟學期的標題
            List <string> SchoolYearSemesterList = new List <string>(aClass.SLRSchoolYearSemesterDic.Keys);

            // 排序
            SchoolYearSemesterList.Sort(SortSchoolYearSemester);

            // 取得學年度跟學期的欄位數量
            _MAX_COLUMN_COUNT = GetRemainColumn(cellSchoolYear);

            // 確保資料的數量跟欄位一致
            if (SchoolYearSemesterList.Count > _MAX_COLUMN_COUNT)
            {
                int delCount = SchoolYearSemesterList.Count - _MAX_COLUMN_COUNT;
                for (int intI = 0; intI < delCount; intI++)
                {
                    SchoolYearSemesterList.RemoveAt(0);
                }
            }

            // 輸出學年度跟學期的標題
            foreach (string each in SchoolYearSemesterList)
            {
                // 學年度
                Write(cellSchoolYear, each);

                // 不是最後一筆資料的話, 就移到下一個cell
                if (columnIndex < columnCount)
                {
                    cellSchoolYear = GetMoveRightCell(cellSchoolYear, 1);
                }
                columnIndex++;
            }


            builder.MoveToMergeField("資料"); // 移到有資料的標籤上
            Cell cell = (Cell)builder.CurrentParagraph.ParentNode;

            //需要Insert Row
            //取得目前Row
            Row 日3row = (Row)cell.ParentRow;

            for (int x = 1; x < studentObjList.Count; x++)
            {
                cell.ParentRow.ParentTable.InsertAfter(日3row.Clone(true), cell.ParentNode);
            }

            //學生ID
            foreach (StudentTotalObj student in studentObjList)
            {
                // 用來計算輸出了幾次學年度跟學期的服務時數
                int SLROutputCount = 0;

                // 座號
                Write(cell, student.seat_no);
                cell = GetMoveRightCell(cell, 1);

                // 姓名
                Write(cell, student.student_name);
                cell = GetMoveRightCell(cell, 1);

                // 學號
                Write(cell, student.student_number);
                cell = GetMoveRightCell(cell, 1);

                // 性別
                Write(cell, student.student_gender);
                cell = GetMoveRightCell(cell, 1);

                // 學習時數
                columnCount = SchoolYearSemesterList.Count;
                columnIndex = 1;
                foreach (string each in SchoolYearSemesterList)
                {
                    if (student.SLRDic.ContainsKey(each))
                    {
                        Write(cell, student.SLRDic[each].ToString());
                        SLROutputCount++;
                    }
                    else
                    {
                        Write(cell, "0");
                    }

                    // 不是最後一筆資料的話, 就移到後面一個cell
                    if (columnIndex < columnCount)
                    {
                        cell = GetMoveRightCell(cell, 1);
                    }
                    columnIndex++;
                }

                // 假如學生服務學習的總學年度跟學期的數量不等於列印的的數量, 加入警告清單
                if (student.SLRDic.Count != SLROutputCount)
                {
                    string msg = String.Format(_WarningMsg, student.seat_no, student.student_name);

                    WarningStudents.AppendLine(msg);
                }

                Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一行
                if (Nextrow == null)
                {
                    break;
                }
                cell = Nextrow.FirstCell; //第一格
            }

            #region MailMerge

            List <string> name  = new List <string>();
            List <string> value = new List <string>();

            name.Add("班級");
            value.Add(aClass.class_name);

            name.Add("導師");
            value.Add(aClass.GetTeacherName());

            name.Add("提示");
            value.Add(WarningStudents.ToString());

            PageOne.MailMerge.Execute(name.ToArray(), value.ToArray());

            #endregion

            return(PageOne);
        }
        // 取得班級資料 By SQL
        private List<ClassTotalObj> GetClassOBJ(List<string> _ClassIDList)
        {
            List<ClassTotalObj> list = new List<ClassTotalObj>();
            string classid = string.Join("','", _ClassIDList);
            string qu = "select class.id,class.class_name,teacher.id as teacher_id,teacher.teacher_name,teacher.nickname,class.grade_year,class.display_order ";
            qu += "from class LEFT join teacher on class.ref_teacher_id=teacher.id ";
            qu += "where class.id in('" + classid + "')";
            DataTable dt = _queryHelper.Select(qu);

            foreach (DataRow row in dt.Rows)
            {
                ClassTotalObj obj = new ClassTotalObj(row);
                list.Add(obj);
            }
            return list;

        }
        // 排序:年級/班級序號/班級名稱
        private int SortClass(ClassTotalObj obj1, ClassTotalObj obj2)
        {
            //年級
            string seatno1 = obj1.class_grade_year.PadLeft(1, '0');
            seatno1 += obj1.class_index.PadLeft(3, '0');
            seatno1 += obj1.class_name.PadLeft(10, '0');

            string seatno2 = obj2.class_grade_year.PadLeft(1, '0');
            seatno2 += obj2.class_index.PadLeft(3, '0');
            seatno2 += obj2.class_name.PadLeft(10, '0');

            return seatno1.CompareTo(seatno2);
        }
        // WORD處理
        private Document SetDocument(ClassTotalObj aClass)
        {
            StringBuilder WarningStudents = new StringBuilder();

            // 取得班級中所有學生清單
            List<StudentTotalObj> studentObjList = new List<StudentTotalObj>(aClass.StudentDic.Values);
            
            //排序
            studentObjList.Sort(SortStudent);

            Document PageOne = (Document)_template.Clone(true);
            _run = new Run(PageOne);
            DocumentBuilder builder = new DocumentBuilder(PageOne);

            int columnCount = aClass.SLRSchoolYearSemesterDic.Count;
            int columnIndex = 1;

            // 文件移到學年度跟學期的標題
            builder.MoveToMergeField("學年度"); // 移到有學年度的標籤上
            Cell cellSchoolYear = (Cell)builder.CurrentParagraph.ParentNode;

            // 準備學年度跟學期的標題
            List<string> SchoolYearSemesterList = new List<string>(aClass.SLRSchoolYearSemesterDic.Keys);

            // 排序
            SchoolYearSemesterList.Sort(SortSchoolYearSemester);

            // 取得學年度跟學期的欄位數量
            _MAX_COLUMN_COUNT = GetRemainColumn(cellSchoolYear);

            // 確保資料的數量跟欄位一致
            if (SchoolYearSemesterList.Count > _MAX_COLUMN_COUNT)
            {
                int delCount = SchoolYearSemesterList.Count - _MAX_COLUMN_COUNT;
                for(int intI=0; intI<delCount; intI++)
                {
                    SchoolYearSemesterList.RemoveAt(0);
                }
            }

            // 輸出學年度跟學期的標題
            foreach (string each in SchoolYearSemesterList)
            {
                // 學年度
                Write(cellSchoolYear, each);

                // 不是最後一筆資料的話, 就移到下一個cell
                if(columnIndex < columnCount)
                {
                    cellSchoolYear = GetMoveRightCell(cellSchoolYear, 1);
                }
                columnIndex++;
            }
            

            builder.MoveToMergeField("資料"); // 移到有資料的標籤上
            Cell cell = (Cell)builder.CurrentParagraph.ParentNode;

            //需要Insert Row
            //取得目前Row
            Row 日3row = (Row)cell.ParentRow;

            for (int x = 1; x < studentObjList.Count; x++)
            {
                cell.ParentRow.ParentTable.InsertAfter(日3row.Clone(true), cell.ParentNode);
            }

            //學生ID
            foreach (StudentTotalObj student in studentObjList)
            {
                // 用來計算輸出了幾次學年度跟學期的服務時數
                int SLROutputCount = 0;

                // 座號
                Write(cell, student.seat_no);
                cell = GetMoveRightCell(cell, 1);
                
                // 姓名
                Write(cell, student.student_name);
                cell = GetMoveRightCell(cell, 1);
                
                // 學號
                Write(cell, student.student_number);
                cell = GetMoveRightCell(cell, 1);
                
                // 性別
                Write(cell, student.student_gender);
                cell = GetMoveRightCell(cell, 1);
                
                // 學習時數
                columnCount = SchoolYearSemesterList.Count;
                columnIndex = 1;
                foreach(string each in SchoolYearSemesterList)
                {
                    if (student.SLRDic.ContainsKey(each))
                    {
                        Write(cell, student.SLRDic[each].ToString());
                        SLROutputCount++;
                    }
                    else
                    {
                        Write(cell, "0");
                    }

                    // 不是最後一筆資料的話, 就移到後面一個cell
                    if (columnIndex < columnCount)
                    {
                        cell = GetMoveRightCell(cell, 1);
                    }
                    columnIndex++;
                }

                // 假如學生服務學習的總學年度跟學期的數量不等於列印的的數量, 加入警告清單
                if (student.SLRDic.Count != SLROutputCount )
                {
                    string msg = String.Format(_WarningMsg, student.seat_no, student.student_name);

                    WarningStudents.AppendLine(msg);
                }

                Row Nextrow = cell.ParentRow.NextSibling as Row; //取得下一行
                if (Nextrow == null)
                {
                    break;
                }
                cell = Nextrow.FirstCell; //第一格
            }

            #region MailMerge

            List<string> name = new List<string>();
            List<string> value = new List<string>();

            name.Add("班級");
            value.Add(aClass.class_name);

            name.Add("導師");
            value.Add(aClass.GetTeacherName());

            name.Add("提示");
            value.Add(WarningStudents.ToString());

            PageOne.MailMerge.Execute(name.ToArray(), value.ToArray());

            #endregion

            return PageOne;
        }