Exemple #1
0
 /// <summary>
 /// 使用預設的 Dispatcher 傳送資料。
 /// </summary>
 public static void Dispatch(ElectronicPaper ePaper)
 {
     if (_default_dispatcher != null)
     {
         _default_dispatcher.Dispatch(ePaper);
     }
     else
     {
         throw new ArgumentException("未指定預設的 Dispatcher。");
     }
 }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //未輸入電子報表名稱的檢查
            if (textBox1.Text.Trim() != "")
            {
                //主要的Word文件
                Document doc = new Document();
                doc.Sections.Clear();

                if (radioButton2.Checked)
                {
                    #region 班級電子報表
                    //建立一個班級電子報表
                    //傳入參數 : 報表名稱,學年度,學期,類型(學生/班級/教師/課程)
                    paperForClass = new SmartSchool.ePaper.ElectronicPaper(textBox1.Text, School.DefaultSchoolYear, School.DefaultSemester, SmartSchool.ePaper.ViewerType.Class);

                    MemoryStream stream = new MemoryStream();

                    Document each_page = new Document(template, "", LoadFormat.Doc, "");
                    each_page.Save(stream, SaveFormat.Doc);

                    //取得所選擇的班級ID
                    List<string> ClassID = K12.Presentation.NLDPanels.Class.SelectedSource;
                    foreach (string each in ClassID)
                    {
                        //傳參數給PaperItem
                        //格式 / 內容 / 對象的系統編號
                        paperForClass.Append(new PaperItem(PaperFormat.Office2003Doc, stream, each));
                    }

                    //開始上傳
                    SmartSchool.ePaper.DispatcherProvider.Dispatch(paperForClass);
                    #endregion
                }
                else
                {
                    #region 班級學生的電子報表
                    //建立一個學生電子報表
                    //傳入參數 : 報表名稱,學年度,學期,類型(學生/班級/教師/課程)
                    paperForStudent = new SmartSchool.ePaper.ElectronicPaper(textBox1.Text, School.DefaultSchoolYear, School.DefaultSemester, SmartSchool.ePaper.ViewerType.Student);

                    //學生個人的文件
                    Document each_page = new Document(template, "", LoadFormat.Doc, "");
                    MemoryStream stream = new MemoryStream();
                    each_page.Save(stream, SaveFormat.Doc);
                    doc.Sections.Add(doc.ImportNode(each_page.Sections[0], true)); //合併至doc

                    List<string> ClassID = K12.Presentation.NLDPanels.Class.SelectedSource; //取得畫面上所選班級的ID清單
                    List<StudentRecord> srList = Student.SelectByClassIDs(ClassID); //依據班級ID,取得學生物件
                    foreach (StudentRecord sr in srList)
                    {
                        //傳參數給PaperItem
                        //格式 / 內容 / 對象的系統編號
                        paperForStudent.Append(new PaperItem(PaperFormat.Office2003Doc, stream, sr.ID));
                    }

                    //開始上傳
                    SmartSchool.ePaper.DispatcherProvider.Dispatch(paperForStudent);
                    #endregion
                }
            }
            else
            {
                MessageBox.Show("請輸入電子報表名稱!!");
            }
        }
Exemple #3
0
        void BGW_DoWork(object sender, DoWorkEventArgs e)
        {
            //電子報表
            string time = DateTime.Now.Hour.ToString().PadLeft(2) + DateTime.Now.Minute.ToString().PadLeft(2);

            paperForClass = new SmartSchool.ePaper.ElectronicPaper(string.Format("日常表現記錄表(新制_{0})", time), _Schoolyear.ToString(), _Semester.ToString(), SmartSchool.ePaper.ViewerType.Class);

            BGW.ReportProgress(1, "取得紙張設定");
            //取得列印紙張
            int sizeIndex = GetSizeIndex();

            BGW.ReportProgress(4, "取得假別設定");
            //取得列印假別內容
            Dictionary <string, List <string> > UserType = GetUserType();


            #region 取得資料

            //取得使用者選擇班級
            BGW.ReportProgress(8, "取得所選班級");
            List <ClassRecord> allClasses = Class.SelectByIDs(K12.Presentation.NLDPanels.Class.SelectedSource);
            //排序(因為上面沒有照班級排序)
            int displayOrder;
            allClasses = allClasses.OrderBy(i => i.GradeYear).ThenBy(i => displayOrder = Int32.TryParse(i.DisplayOrder, out displayOrder)? displayOrder :0).ThenBy(i => i.Name).ToList();



            #region 取得使用者所選擇的班級學生

            BGW.ReportProgress(12, "取得學生清單");
            string        classidlist = string.Join(",", K12.Presentation.NLDPanels.Class.SelectedSource);
            StringBuilder sb          = new StringBuilder();
            sb.Append("select student.id,student.ref_class_id from student ");
            sb.Append("join class on class.id=student.ref_class_id ");
            sb.Append("where student.status=1 ");
            sb.Append(string.Format("and class.id in ({0})", classidlist));

            List <string> StudentIDList = new List <string>();
            DataTable     dt            = _QueryHelper.Select(sb.ToString());
            foreach (DataRow row in dt.Rows)
            {
                StudentIDList.Add("" + row[0]);
            }

            BGW.ReportProgress(15, "取得學生清單");
            List <StudentRecord> allStudents = Student.SelectByIDs(StudentIDList);

            int maxStudents  = 0;
            int totalStudent = allStudents.Count;

            Dictionary <string, List <StudentRecord> > classStudents = new Dictionary <string, List <StudentRecord> >();
            foreach (StudentRecord each in allStudents)
            {
                if (!classStudents.ContainsKey(each.RefClassID))
                {
                    classStudents.Add(each.RefClassID, new List <StudentRecord>());
                }

                classStudents[each.RefClassID].Add(each);
            }

            foreach (string each in classStudents.Keys)
            {
                if (classStudents[each].Count > maxStudents)
                {
                    maxStudents = classStudents[each].Count;
                }

                classStudents[each].Sort(SortStudent);
            }
            #endregion


            Dictionary <string, RewardRecord> MeritDemeritAttDic   = new Dictionary <string, RewardRecord>();
            Dictionary <string, RewardRecord> TotalMeritDemeritDic = new Dictionary <string, RewardRecord>();

            BGW.ReportProgress(20, "取得獎勵資料");
            #region 獎勵

            foreach (SHMeritRecord each in SHMerit.SelectByStudentIDs(StudentIDList))
            {
                // 2018/1/8 羿均 新增 累計獎勵紀錄資料
                RewardRecord totalMerit = new RewardRecord();
                if (TotalMeritDemeritDic.ContainsKey(each.RefStudentID))
                {
                    totalMerit = TotalMeritDemeritDic[each.RefStudentID];
                }

                totalMerit.MeritACount += each.MeritA.HasValue ? each.MeritA.Value : 0;
                totalMerit.MeritBCount += each.MeritB.HasValue ? each.MeritB.Value : 0;
                totalMerit.MeritCCount += each.MeritC.HasValue ? each.MeritC.Value : 0;

                if (!TotalMeritDemeritDic.ContainsKey(each.RefStudentID))
                {
                    TotalMeritDemeritDic.Add(each.RefStudentID, totalMerit);
                }

                if (each.SchoolYear != _Schoolyear || each.Semester != _Semester)
                {
                    continue;
                }

                RewardRecord rr = new RewardRecord();

                if (MeritDemeritAttDic.ContainsKey(each.RefStudentID))
                {
                    rr = MeritDemeritAttDic[each.RefStudentID];
                }

                rr.MeritACount += each.MeritA.HasValue ? each.MeritA.Value : 0;
                rr.MeritBCount += each.MeritB.HasValue ? each.MeritB.Value : 0;
                rr.MeritCCount += each.MeritC.HasValue ? each.MeritC.Value : 0;

                if (!MeritDemeritAttDic.ContainsKey(each.RefStudentID))
                {
                    MeritDemeritAttDic.Add(each.RefStudentID, rr);
                }
            }
            #endregion

            BGW.ReportProgress(25, "取得懲戒資料");
            #region 懲戒
            foreach (SHDemeritRecord each in SHDemerit.SelectByStudentIDs(StudentIDList))
            {
                // 2018/1/8 羿均 新增 累計懲戒紀錄資料
                RewardRecord totalDemerit = new RewardRecord();

                if (each.Cleared == "是")
                {
                    continue;
                }

                if (TotalMeritDemeritDic.ContainsKey(each.RefStudentID))
                {
                    totalDemerit = TotalMeritDemeritDic[each.RefStudentID];
                }

                totalDemerit.DemeritACount += each.DemeritA.HasValue ? each.DemeritA.Value : 0;
                totalDemerit.DemeritBCount += each.DemeritB.HasValue ? each.DemeritB.Value : 0;
                totalDemerit.DemeritCCount += each.DemeritC.HasValue ? each.DemeritC.Value : 0;

                if (!TotalMeritDemeritDic.ContainsKey(each.RefStudentID))
                {
                    TotalMeritDemeritDic.Add(each.RefStudentID, totalDemerit);
                }

                if (each.SchoolYear != _Schoolyear || each.Semester != _Semester)
                {
                    continue;
                }

                RewardRecord rr = new RewardRecord();

                if (MeritDemeritAttDic.ContainsKey(each.RefStudentID))
                {
                    rr = MeritDemeritAttDic[each.RefStudentID];
                }

                rr.DemeritACount += each.DemeritA.HasValue ? each.DemeritA.Value : 0;
                rr.DemeritBCount += each.DemeritB.HasValue ? each.DemeritB.Value : 0;
                rr.DemeritCCount += each.DemeritC.HasValue ? each.DemeritC.Value : 0;

                if (!MeritDemeritAttDic.ContainsKey(each.RefStudentID))
                {
                    MeritDemeritAttDic.Add(each.RefStudentID, rr);
                }
            }
            #endregion

            BGW.ReportProgress(30, "取得節次對照");
            //取得節次對照表
            Dictionary <string, string> periodDic = new Dictionary <string, string>();
            foreach (PeriodMappingInfo var in PeriodMapping.SelectAll())
            {
                string name = var.Type;

                //取得對照表並且對照出節次->類別的清單(99/11/24 by dylan)
                if (!periodDic.ContainsKey(var.Name))
                {
                    periodDic.Add(var.Name, var.Type);
                }
            }

            BGW.ReportProgress(35, "取得缺曠資料");
            #region 缺曠
            foreach (SHAttendanceRecord each in SHAttendance.SelectByStudentIDs(StudentIDList))
            {
                if (each.SchoolYear != _Schoolyear || each.Semester != _Semester)
                {
                    continue;
                }

                RewardRecord rr = new RewardRecord();
                if (MeritDemeritAttDic.ContainsKey(each.RefStudentID))
                {
                    rr = MeritDemeritAttDic[each.RefStudentID];
                }

                foreach (AttendancePeriod _Period in each.PeriodDetail)
                {
                    if (periodDic.ContainsKey(_Period.Period))
                    {
                        string typename = periodDic[_Period.Period] + "_" + _Period.AbsenceType;
                        if (rr.Attendance.ContainsKey(typename))
                        {
                            rr.Attendance[typename]++;
                        }
                        else
                        {
                            rr.Attendance.Add(typename, 1);
                        }
                    }
                }

                if (!MeritDemeritAttDic.ContainsKey(each.RefStudentID))
                {
                    MeritDemeritAttDic.Add(each.RefStudentID, rr);
                }
            }
            #endregion

            //日常表現資料
            BGW.ReportProgress(40, "取得日常表現");
            Dictionary <string, SHMoralScoreRecord> SHMoralScoreDic = new Dictionary <string, SHMoralScoreRecord>();
            foreach (SHMoralScoreRecord each in SHMoralScore.Select(null, StudentIDList, _Schoolyear, _Semester))
            {
                if (!SHMoralScoreDic.ContainsKey(each.RefStudentID))
                {
                    SHMoralScoreDic.Add(each.RefStudentID, each);
                }
            }

            //文字評量對照表
            BGW.ReportProgress(45, "取得文字評量");
            List <string> TextScoreList = new List <string>();
            SmartSchool.Customization.Data.SystemInformation.getField("文字評量對照表");
            System.Xml.XmlElement ElmTextScoreList = (System.Xml.XmlElement)SmartSchool.Customization.Data.SystemInformation.Fields["文字評量對照表"];
            foreach (System.Xml.XmlNode Node in ElmTextScoreList.SelectNodes("Content/Morality"))
            {
                TextScoreList.Add(Node.Attributes["Face"].InnerText);
            }

            #endregion

            #region 產生表格

            BGW.ReportProgress(50, "產生報表樣式");

            Workbook template  = new Workbook();
            Workbook prototype = new Workbook();

            //列印尺寸
            if (sizeIndex == 0)
            {
                template.Open(new MemoryStream(Properties.Resources.德行表現總表新制A3), FileFormatType.Excel2003);
            }
            else if (sizeIndex == 1)
            {
                template.Open(new MemoryStream(Properties.Resources.德行表現總表新制A4), FileFormatType.Excel2003);
            }
            else if (sizeIndex == 2)
            {
                template.Open(new MemoryStream(Properties.Resources.德行表現總表新制B4), FileFormatType.Excel2003);
            }

            prototype.Copy(template);

            Worksheet templateSheet  = template.Worksheets[0];
            Worksheet prototypeSheet = prototype.Worksheets[0];

            Range tempAbsence        = templateSheet.Cells.CreateRange(9, 1, true);
            Range tempScoreText      = templateSheet.Cells.CreateRange(10, 1, true);
            Range tempAfterOtherDiff = templateSheet.Cells.CreateRange(11, 1, true);
            Range oder = templateSheet.Cells.CreateRange(12, 1, true);

            Dictionary <string, int> columnIndexTable = new Dictionary <string, int>();

            Dictionary <string, List <string> > periodAbsence = new Dictionary <string, List <string> >();

            //紀錄獎懲的 Column Index
            columnIndexTable.Add("大功", 3);
            columnIndexTable.Add("小功", 4);
            columnIndexTable.Add("嘉獎", 5);
            columnIndexTable.Add("大過", 6);
            columnIndexTable.Add("小過", 7);
            columnIndexTable.Add("警告", 8);

            //缺曠
            int ptColIndex = 9;
            foreach (string var in UserType.Keys)
            {
                foreach (string absence in UserType[var])
                {
                    if (!periodAbsence.ContainsKey(var))
                    {
                        periodAbsence.Add(var, new List <string>());
                    }
                    if (!periodAbsence[var].Contains(absence))
                    {
                        periodAbsence[var].Add(absence);
                    }

                    prototypeSheet.Cells.CreateRange(ptColIndex, 1, true).Copy(tempAbsence);
                    ptColIndex += 1;
                }
            }

            ptColIndex = 9;
            foreach (string period in periodAbsence.Keys)
            {
                prototypeSheet.Cells.CreateRange(2, ptColIndex, 1, periodAbsence[period].Count).Merge();
                prototypeSheet.Cells[2, ptColIndex].PutValue(period);

                foreach (string absence in periodAbsence[period])
                {
                    prototypeSheet.Cells[3, ptColIndex].PutValue(absence);
                    columnIndexTable.Add(period + "_" + absence, ptColIndex);
                    ptColIndex++;
                }
            }

            if (ptColIndex > 9)
            {
                prototypeSheet.Cells.CreateRange(1, 9, 1, ptColIndex - 9).Merge();
                prototypeSheet.Cells[1, 9].PutValue("缺曠");
            }

            //用來調整Column寬度的定位
            int ColumnMax = ptColIndex;

            //文字評量
            foreach (string textscore in TextScoreList)
            {
                columnIndexTable.Add(textscore, ptColIndex);
                prototypeSheet.Cells.CreateRange(ptColIndex, 1, true).Copy(tempScoreText);
                prototypeSheet.Cells[4, ptColIndex].PutValue(textscore);
                ptColIndex++;
            }

            prototypeSheet.Cells[1, ptColIndex - TextScoreList.Count].PutValue("學生綜合表現");

            if ((ptColIndex - TextScoreList.Count > 0) && (TextScoreList.Count > 0))
            {
                prototypeSheet.Cells.CreateRange(1, ptColIndex - TextScoreList.Count, 3, TextScoreList.Count).Merge();
            }

            prototypeSheet.Cells.CreateRange(ptColIndex, 1, true).Copy(tempAfterOtherDiff);
            columnIndexTable.Add("評語", ptColIndex++);
            prototypeSheet.Cells.CreateRange(ptColIndex, 1, true).Copy(oder);
            columnIndexTable.Add("是否留察", ptColIndex++);

            //填入製表日期
            prototypeSheet.Cells[0, 0].PutValue("製表日期:" + DateTime.Today.ToShortDateString());

            //填入標題
            prototypeSheet.Cells.CreateRange(0, 3, 1, ptColIndex - 3).Merge();
            prototypeSheet.Cells[0, 3].PutValue(K12.Data.School.ChineseName + " " + _Schoolyear + " 學年度 " + ((_Semester == 1) ? "上" : "下") + " 學期 日常表現記錄表(新制)");

            Range ptEachRow = prototypeSheet.Cells.CreateRange(5, 1, false);

            for (int i = 5; i < maxStudents + 5; i++)
            {
                prototypeSheet.Cells.CreateRange(i, 1, false).Copy(ptEachRow);
            }

            //加上底線
            prototypeSheet.Cells.CreateRange(maxStudents + 5, 0, 1, ptColIndex).SetOutlineBorder(BorderType.TopBorder, CellBorderType.Medium, System.Drawing.Color.Black);

            for (int i = 12; i >= ptColIndex; i--)
            {
                prototypeSheet.Cells.DeleteColumn(i);
            }

            Range pt = prototypeSheet.Cells.CreateRange(0, maxStudents + 5, false);

            #endregion

            #region 填入表格

            BGW.ReportProgress(53, "填入報表資料");


            Workbook wb = new Workbook();
            wb.Copy(prototype);
            Worksheet ws = wb.Worksheets[0];

            int index         = 0;
            int dataIndex     = 0;
            int classTotalRow = maxStudents + 5;

            BGW.ReportProgress(57, "填入老師姓名");
            #region 取得全校班級,與老師姓名/暱稱(2012/5/24)
            Dictionary <string, string> TeacherDic = new Dictionary <string, string>();
            string st = "SELECT class.id,teacher.teacher_name,teacher.nickname FROM class JOIN teacher ON class.ref_teacher_id = teacher.id";
            dt = _QueryHelper.Select(st);
            foreach (DataRow row in dt.Rows)
            {
                string classID         = "" + row[0];
                string teacherName     = "" + row[1];
                string teacherNickname = "" + row[2];

                if (!TeacherDic.ContainsKey(classID))
                {
                    if (string.IsNullOrEmpty(teacherNickname))
                    {
                        TeacherDic.Add(classID, teacherName);
                    }
                    else
                    {
                        TeacherDic.Add(classID, teacherName + "(" + teacherNickname + ")");
                    }
                }
            }

            #endregion

            BGW.ReportProgress(61, "學生留察資料");
            #region 取得全校本學年度留查之記錄(2012/5/24)
            List <string> MeritFlagIs2 = new List <string>();
            st = string.Format("SELECT ref_student_id from discipline where merit_flag=2 and school_year={0} and semester={1}", _Schoolyear, _Semester);
            dt = _QueryHelper.Select(st);
            foreach (DataRow row in dt.Rows)
            {
                if (!MeritFlagIs2.Contains("" + row[0]))
                {
                    MeritFlagIs2.Add("" + row[0]);
                }
            }

            #endregion

            BGW.ReportProgress(70, "開始列印資料");

            int PeogressNow1 = totalStudent / 30;
            int PeogressNow2 = 0;
            int PeogressNow3 = 70;

            foreach (ClassRecord aClass in allClasses)
            {
                //電子報表用
                #region 電子報表用

                Workbook Paper_wb = new Workbook();
                Paper_wb.Copy(prototype);
                Worksheet Paper_ws = Paper_wb.Worksheets[0];

                int Paper_index         = 0;
                int Paper_dataIndex     = 0;
                int Paper_classTotalRow = maxStudents + 5;

                int Paper_PeogressNow1 = totalStudent / 30;


                #endregion

                if (!classStudents.ContainsKey(aClass.ID))
                {
                    continue;
                }

                string TeacherName = "";
                if (TeacherDic.ContainsKey(aClass.ID))
                {
                    TeacherName = TeacherDic[aClass.ID];
                }

                //複製完成後的樣板
                ws.Cells.CreateRange(index, classTotalRow, false).Copy(pt);
                Paper_ws.Cells.CreateRange(Paper_index, Paper_classTotalRow, false).Copy(pt);

                //填入班級名稱
                ws.Cells[index + 1, 0].PutValue("班級:" + aClass.Name);
                Paper_ws.Cells[Paper_index + 1, 0].PutValue("班級:" + aClass.Name);

                //填入老師名稱
                ws.Cells[index + 3, 0].PutValue("教師:" + TeacherName);
                Paper_ws.Cells[Paper_index + 3, 0].PutValue("教師:" + TeacherName);

                dataIndex       = index + 5;
                Paper_dataIndex = Paper_index + 5;

                foreach (StudentRecord aStudent in classStudents[aClass.ID])
                {
                    PeogressNow2++;

                    if (PeogressNow2 > PeogressNow1 && PeogressNow3 < 101)
                    {
                        PeogressNow3++;
                        PeogressNow2 = 0;
                        BGW.ReportProgress(PeogressNow3, "開始列印資料");
                    }

                    ws.Cells[dataIndex, 0].PutValue(aStudent.SeatNo);
                    ws.Cells[dataIndex, 1].PutValue(aStudent.Name);
                    ws.Cells[dataIndex, 2].PutValue(aStudent.StudentNumber);

                    Paper_ws.Cells[Paper_dataIndex, 0].PutValue(aStudent.SeatNo);
                    Paper_ws.Cells[Paper_dataIndex, 1].PutValue(aStudent.Name);
                    Paper_ws.Cells[Paper_dataIndex, 2].PutValue(aStudent.StudentNumber);
                    // 2018/01/17 羿均
                    // MeritDemeritAttDic 為當學年度學期 缺曠獎懲資料
                    // TotalMeritDemeritDic 為獎懲累計資料
                    if (MeritDemeritAttDic.ContainsKey(aStudent.ID) || TotalMeritDemeritDic.ContainsKey(aStudent.ID))
                    {
                        RewardRecord rr = new RewardRecord();
                        if (MeritDemeritAttDic.ContainsKey(aStudent.ID))
                        {
                            rr = MeritDemeritAttDic[aStudent.ID];
                        }
                        if (TotalMeritDemeritDic.ContainsKey(aStudent.ID))
                        {
                            RewardRecord totalRecord = TotalMeritDemeritDic[aStudent.ID];

                            ws.Cells[dataIndex, columnIndexTable["大功"]].PutValue(rr.MeritACount + " / " + totalRecord.MeritACount);
                            ws.Cells[dataIndex, columnIndexTable["小功"]].PutValue(rr.MeritBCount + " / " + totalRecord.MeritBCount);
                            ws.Cells[dataIndex, columnIndexTable["嘉獎"]].PutValue(rr.MeritCCount + " / " + totalRecord.MeritCCount);
                            ws.Cells[dataIndex, columnIndexTable["大過"]].PutValue(rr.DemeritACount + " / " + totalRecord.DemeritACount);
                            ws.Cells[dataIndex, columnIndexTable["小過"]].PutValue(rr.DemeritBCount + " / " + totalRecord.DemeritBCount);
                            ws.Cells[dataIndex, columnIndexTable["警告"]].PutValue(rr.DemeritCCount + " / " + totalRecord.DemeritCCount);

                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["大功"]].PutValue(rr.MeritACount + " / " + totalRecord.MeritACount);
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["小功"]].PutValue(rr.MeritBCount + " / " + totalRecord.MeritBCount);
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["嘉獎"]].PutValue(rr.MeritCCount + " / " + totalRecord.MeritCCount);
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["大過"]].PutValue(rr.DemeritACount + " / " + totalRecord.DemeritACount);
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["小過"]].PutValue(rr.DemeritBCount + " / " + totalRecord.DemeritBCount);
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["警告"]].PutValue(rr.DemeritCCount + " / " + totalRecord.DemeritCCount);
                        }
                        else
                        {
                            //有缺曠沒獎懲,要印獎懲0/0
                            //https://3.basecamp.com/4399967/buckets/15765350/todos/4520462594
                            ws.Cells[dataIndex, columnIndexTable["大功"]].PutValue("0 / 0");
                            ws.Cells[dataIndex, columnIndexTable["小功"]].PutValue("0 / 0");
                            ws.Cells[dataIndex, columnIndexTable["嘉獎"]].PutValue("0 / 0");
                            ws.Cells[dataIndex, columnIndexTable["大過"]].PutValue("0 / 0");
                            ws.Cells[dataIndex, columnIndexTable["小過"]].PutValue("0 / 0");
                            ws.Cells[dataIndex, columnIndexTable["警告"]].PutValue("0 / 0");

                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["大功"]].PutValue("0 / 0");
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["小功"]].PutValue("0 / 0");
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["嘉獎"]].PutValue("0 / 0");
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["大過"]].PutValue("0 / 0");
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["小過"]].PutValue("0 / 0");
                            Paper_ws.Cells[Paper_dataIndex, columnIndexTable["警告"]].PutValue("0 / 0");
                        }
                        foreach (string each in rr.Attendance.Keys)
                        {
                            if (columnIndexTable.ContainsKey(each))
                            {
                                ws.Cells[dataIndex, columnIndexTable[each]].PutValue(rr.Attendance[each]);
                                Paper_ws.Cells[Paper_dataIndex, columnIndexTable[each]].PutValue(rr.Attendance[each]);
                            }
                        }
                    }
                    else
                    {
                        //沒缺曠沒獎懲,要印獎懲0/0
                        // https://3.basecamp.com/4399967/buckets/15765350/todos/4520462594
                        ws.Cells[dataIndex, columnIndexTable["大功"]].PutValue("0 / 0");
                        ws.Cells[dataIndex, columnIndexTable["小功"]].PutValue("0 / 0");
                        ws.Cells[dataIndex, columnIndexTable["嘉獎"]].PutValue("0 / 0");
                        ws.Cells[dataIndex, columnIndexTable["大過"]].PutValue("0 / 0");
                        ws.Cells[dataIndex, columnIndexTable["小過"]].PutValue("0 / 0");
                        ws.Cells[dataIndex, columnIndexTable["警告"]].PutValue("0 / 0");

                        Paper_ws.Cells[Paper_dataIndex, columnIndexTable["大功"]].PutValue("0 / 0");
                        Paper_ws.Cells[Paper_dataIndex, columnIndexTable["小功"]].PutValue("0 / 0");
                        Paper_ws.Cells[Paper_dataIndex, columnIndexTable["嘉獎"]].PutValue("0 / 0");
                        Paper_ws.Cells[Paper_dataIndex, columnIndexTable["大過"]].PutValue("0 / 0");
                        Paper_ws.Cells[Paper_dataIndex, columnIndexTable["小過"]].PutValue("0 / 0");
                        Paper_ws.Cells[Paper_dataIndex, columnIndexTable["警告"]].PutValue("0 / 0");
                    }

                    //文字評量部份
                    SHMoralScoreRecord demonScore;
                    if (SHMoralScoreDic.ContainsKey(aStudent.ID))
                    {
                        demonScore = SHMoralScoreDic[aStudent.ID];

                        //文字評量
                        XmlElement xml = demonScore.TextScore;
                        foreach (XmlElement each in xml.SelectNodes("Morality"))
                        {
                            string strFace = each.GetAttribute("Face");
                            if (columnIndexTable.ContainsKey(strFace))
                            {
                                int colIndex = columnIndexTable[strFace];
                                ws.Cells[dataIndex, colIndex].PutValue(each.InnerText);
                                Paper_ws.Cells[Paper_dataIndex, colIndex].PutValue(each.InnerText);
                            }
                        }

                        //導師評語
                        ws.Cells[dataIndex, columnIndexTable["評語"]].PutValue(demonScore.Comment);
                        Paper_ws.Cells[Paper_dataIndex, columnIndexTable["評語"]].PutValue(demonScore.Comment);
                    }

                    //留察
                    if (MeritFlagIs2.Contains(aStudent.ID))
                    {
                        ws.Cells[dataIndex, columnIndexTable["是否留察"]].PutValue("是");
                        Paper_ws.Cells[Paper_dataIndex, columnIndexTable["是否留察"]].PutValue("是");
                    }

                    foreach (int each in columnIndexTable.Values)
                    {
                        if (each >= ColumnMax)
                        {
                            Paper_ws.AutoFitColumn(each);
                        }
                    }

                    dataIndex++;
                    Paper_dataIndex++;
                }

                //電子報表
                MemoryStream stream = Paper_wb.SaveToStream();
                paperForClass.Append(new PaperItem(PaperFormat.Office2003Xls, stream, aClass.ID));

                index += classTotalRow + 2;
                ws.HPageBreaks.Add(index, ptColIndex);
            }

            foreach (int each in columnIndexTable.Values)
            {
                if (each >= ColumnMax)
                {
                    ws.AutoFitColumn(each);
                }
            }
            #endregion
            if (Carty_paper)
            {
                BGW.ReportProgress(90, "上傳電子報表");
                SmartSchool.ePaper.DispatcherProvider.Dispatch(paperForClass);
            }

            BGW.ReportProgress(100, "資料列印完成");
            e.Result = wb;
        }
        public void Dispatch(ElectronicPaper ePaper)
        {
            string epaperId = EditElectronicPaper.Insert(
                ePaper.Name,
                ePaper.SchoolYear,
                ePaper.Semester,
                ePaper.ViewerType.ToString(),
                ePaper.Metadata);

            List <DSXmlHelper> requests = new List <DSXmlHelper>();
            DSXmlHelper        papers   = null;
            int count = 0;

            IProgressReceiver receiver = ePaper.ProgressReceiver;

            if (receiver == null)
            {
                receiver = new ElectronicPaperProgress();
            }

            foreach (PaperItem eachPaper in ePaper)
            {
                if (eachPaper.Viewers.Count <= 0)
                {
                    throw new ArgumentException("每一張電子報表至少要有一個 Viewer。");
                }

                if (count % 10 == 0)
                {
                    papers = new DSXmlHelper("Request");
                    requests.Add(papers);
                }

                DSXmlHelper paper = new DSXmlHelper(papers.AddElement("Paper"));
                foreach (string eachViewer in eachPaper.Viewers)
                {
                    paper.AddElement(".", "RefElectronicPaperID", epaperId);
                    paper.AddElement(".", "Format", eachPaper.Format);
                    paper.AddElement(".", "Content", eachPaper.Content);
                    //paper.AddElement(".", "ViewerType", ePaper.ViewerType.ToString());
                    paper.AddElement(".", "ViewerID", eachViewer);

                    count++;
                }
            }

            if (count > 0)
            {
                if (receiver != null)
                {
                    receiver.ProcessStart();
                }

                int current = 1;
                foreach (DSXmlHelper each in requests)
                {
                    EditElectronicPaper.InsertPaperItem(each);

                    if (receiver != null)
                    {
                        receiver.ProcessProgress((int)(((float)current / (float)requests.Count) * 100f));
                    }

                    current++;
                }

                if (receiver != null)
                {
                    receiver.ProcessEnd();
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 背景模式
        /// </summary>
        void BGW_DoWork(object sender, DoWorkEventArgs e)
        {
            paperForStudent = new SmartSchool.ePaper.ElectronicPaper(School.DefaultSchoolYear + "學生日常表現總表", School.DefaultSchoolYear, School.DefaultSemester, SmartSchool.ePaper.ViewerType.Student);

            #region 設定檔

            cd = Campus.Configuration.Config.User[ConfigName];

            XmlElement config = cd.GetXml("XmlData", null);
            if (config == null)
            {
                e.Cancel = true;
                return;
            }

            absenceList = new List <string>();
            int absenceindex = 1;
            //集會,一般...
            foreach (XmlElement xml in config.SelectNodes("Type"))
            {
                //曠課,病假...
                foreach (XmlElement node in xml.SelectNodes("Absence"))
                {
                    string s1 = xml.GetAttribute("Text");
                    string s2 = node.GetAttribute("Text");
                    absenceList.Add(s2 + s1);

                    //記錄Index
                    DicSummaryIndex.Add(s2 + s1, absenceindex);
                    absenceindex++;
                }
            }

            #endregion

            #region 開頭處理

            BehaviorList  = GetBehaviorConfig();
            BehaviorList1 = new List <string>();
            BehaviorList2 = new List <string>();
            BehaviorList3 = new List <string>();

            //製作日常生活表現,標題的Index
            int BeIndex = 0;
            foreach (string each in BehaviorList)
            {
                BeIndex++;
                if (BeIndex > SuperBehaviorIndex1 && BeIndex <= SuperBehaviorIndex2)
                {
                    BehaviorList2.Add(each);
                    DicSummaryIndex.Add(each, BeIndex - SuperBehaviorIndex1);
                }
                else if (BeIndex > SuperBehaviorIndex2)
                {
                    BehaviorList3.Add(each);
                    DicSummaryIndex.Add(each, BeIndex - SuperBehaviorIndex2);
                }
                else if (BeIndex <= SuperBehaviorIndex1)
                {
                    BehaviorList1.Add(each);
                    DicSummaryIndex.Add(each, BeIndex);
                }
            }

            //依據日常生活表現欄位,讀取範本
            _template = new Document(new MemoryStream(Properties.Resources.日常生活記錄表_範本_1));

            if (BehaviorList.Count > SuperBehaviorIndex1)
            {
                _template = new Document(new MemoryStream(Properties.Resources.日常生活記錄表_範本_2));
            }

            if (BehaviorList.Count > SuperBehaviorIndex2)
            {
                _template = new Document(new MemoryStream(Properties.Resources.日常生活記錄表_範本_3));
            }

            //建立資料模型
            Data = new StudentInfo(BehaviorList);

            #endregion

            if (SingeFile) //如果是單檔儲存
            {
                #region 單一學生

                Dictionary <string, Document> DocDic = new Dictionary <string, Document>();

                foreach (string student in Data.DicStudent.Keys)
                {
                    Document PageOne = SetDocument(student);

                    //電子報表
                    MemoryStream stream = new MemoryStream();
                    PageOne.Save(stream, SaveFormat.Docx);
                    paperForStudent.Append(new PaperItem(PaperFormat.Office2003Doc, stream, student));

                    if (!DocDic.ContainsKey(student))
                    {
                        DocDic.Add(student, PageOne);
                    }
                }

                e.Result = DocDic;

                #endregion
            }
            else
            {
                #region 多名學生存單一檔案

                _doc = new Document();
                _doc.Sections.Clear(); //清空此Document

                foreach (string student in Data.DicStudent.Keys)
                {
                    Document PageOne = SetDocument(student);

                    //電子報表
                    MemoryStream stream = new MemoryStream();
                    PageOne.Save(stream, SaveFormat.Docx);
                    paperForStudent.Append(new PaperItem(PaperFormat.Office2003Doc, stream, student));

                    _doc.Sections.Add(_doc.ImportNode(PageOne.FirstSection, true));
                }

                e.Result = _doc;

                #endregion
            }

            //如果有打勾則上傳電子報表
            if (PrintUpdateStudentFile)
            {
                SmartSchool.ePaper.DispatcherProvider.Dispatch(paperForStudent);
            }
        }
Exemple #6
0
        private void _BGWAbsenceNotification_DoWork(object sender, DoWorkEventArgs e)
        {
            #region 取得學生

            if (entityName.ToLower() == "student") //學生模式
            {
                SelectedStudents = K12.Data.Student.SelectByIDs(K12.Presentation.NLDPanels.Student.SelectedSource);
            }
            else if (entityName.ToLower() == "class") //班級模式
            {
                SelectedStudents = new List <StudentRecord>();
                foreach (StudentRecord each in Student.SelectByClassIDs(K12.Presentation.NLDPanels.Class.SelectedSource))
                {
                    if (each.Status != StudentRecord.StudentStatus.一般)
                    {
                        continue;
                    }

                    SelectedStudents.Add(each);
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            SelectedStudents.Sort(new Comparison <StudentRecord>(CommonMethods.ClassSeatNoComparer));

            #endregion
            string reportName = "缺曠通知單";

            #region 快取資料

            //超級資訊物件
            Dictionary <string, StudentOBJ> StudentSuperOBJ = new Dictionary <string, StudentOBJ>();

            //合併列印的資料
            Dictionary <string, object> Allmapping   = new Dictionary <string, object>();
            Dictionary <string, string> ReversionDic = new Dictionary <string, string>();

            //所有學生ID
            List <string> allStudentID = new List <string>();

            //學生人數
            int currentStudentCount = 1;
            int totalStudentNumber  = 0;

            #region 取得 Period List
            List <string> periodList = new List <string>();
            Dictionary <string, string> TestPeriodList = new Dictionary <string, string>();
            int PeriodX = 1;
            Dictionary <string, object> mappingAccessory_copy = new Dictionary <string, object>();
            foreach (K12.Data.PeriodMappingInfo each in K12.Data.PeriodMapping.SelectAll())
            {
                if (!periodList.Contains(each.Name))
                {
                    periodList.Add(each.Name);
                }

                if (!TestPeriodList.ContainsKey(each.Name)) //節次<-->類別
                {
                    TestPeriodList.Add(each.Name, each.Type);
                }

                Allmapping.Add("節次" + PeriodX, each.Name);
                mappingAccessory_copy.Add("節次" + PeriodX, each.Name);
                ReversionDic.Add(each.Name, "節次" + PeriodX);
                PeriodX++;
            }
            #endregion

            #region 取得 Absence List
            Dictionary <string, string> TestAbsenceList = new Dictionary <string, string>(); //代碼替換(新)
            foreach (K12.Data.AbsenceMappingInfo each in K12.Data.AbsenceMapping.SelectAll())
            {
                if (!absenceList.ContainsKey(each.Name))
                {
                    absenceList.Add(each.Name, each.Abbreviation);
                }

                if (!TestAbsenceList.ContainsKey(each.Name)) //縮寫<-->假別
                {
                    TestAbsenceList.Add(each.Abbreviation, each.Name);
                }


                //Allmapping.Add("類型" + DefinedType + "缺曠" + DefinedAbsence,
            }
            #endregion

            //????使用者所選取的所有假別種類????
            List <string> userDefinedAbsenceList = new List <string>();

            int DefinedType = 1;
            foreach (string kind in configkeylist)
            {
                int DefinedAbsence = 1;
                Allmapping.Add("類型" + DefinedType, kind);

                foreach (string type in config[kind])
                {
                    Allmapping.Add("類型" + DefinedType + "缺曠" + DefinedAbsence, type);
                    Allmapping.Add("類型" + DefinedType + "縮寫" + DefinedAbsence, absenceList[type]);
                    DefinedAbsence++;

                    if (!userDefinedAbsenceList.Contains(type))
                    {
                        userDefinedAbsenceList.Add(type);
                    }
                }

                DefinedType++;
            }

            #region 取得所有學生ID
            foreach (StudentRecord aStudent in SelectedStudents)
            {
                //建立學生資訊,班級、座號、學號、姓名、導師
                string studentID = aStudent.ID;
                if (!StudentSuperOBJ.ContainsKey(studentID))
                {
                    StudentSuperOBJ.Add(studentID, new StudentOBJ());
                }

                //學生ID清單
                if (!allStudentID.Contains(studentID))
                {
                    allStudentID.Add(studentID);
                }

                StudentSuperOBJ[studentID].student       = aStudent;
                StudentSuperOBJ[studentID].TeacherName   = aStudent.Class != null ? (aStudent.Class.Teacher != null ? aStudent.Class.Teacher.Name : "") : "";
                StudentSuperOBJ[studentID].ClassName     = aStudent.Class != null ? aStudent.Class.Name : "";
                StudentSuperOBJ[studentID].SeatNo        = aStudent.SeatNo.HasValue ? aStudent.SeatNo.Value.ToString() : "";
                StudentSuperOBJ[studentID].StudentNumber = aStudent.StudentNumber;
                StudentSuperOBJ[studentID].ParentCode    = "";
            }
            #endregion

            #region 取得家長代碼
            // 因應 2019/11/14 弘文要求新epost  增加家長代碼抓取
            string ids = string.Join(",", allStudentID);

            string sql = "select student.id, student.parent_code, student.student_code, student.seat_no, student.name, class.grade_year, class.class_name from student";
            sql += " join class on class.id = student.ref_class_id where student.status in (1,2) and student.id in (" + ids + ") order by class.grade_year,class.display_order,class.class_name,student.seat_no";
            DataTable dt_parent_code = queryHelper.Select(sql);;

            foreach (DataRow row in dt_parent_code.Rows)
            {
                if (StudentSuperOBJ.ContainsKey("" + row["id"]))
                {
                    StudentSuperOBJ["" + row["id"]].ParentCode = "" + row["parent_code"];
                }
            }
            #endregion


            #region 取得所有學生缺曠紀錄,日期區間

            List <AttendanceRecord> attendanceList = K12.Data.Attendance.SelectByDate(SelectedStudents, obj.StartDate, obj.EndDate);

            if (attendanceList.Count == 0)
            {
                e.Cancel = true; //沒有缺曠資料
            }
            foreach (AttendanceRecord attendance in attendanceList)
            {
                if (!allStudentID.Contains(attendance.RefStudentID)) //如果是選取班級的學生
                {
                    continue;
                }

                string     studentID  = attendance.RefStudentID;
                DateTime   occurDate  = attendance.OccurDate;
                StudentOBJ studentOBJ = StudentSuperOBJ[studentID]; //取得這個物件

                foreach (AttendancePeriod attendancePeriod in attendance.PeriodDetail)
                {
                    string absenceType = attendancePeriod.AbsenceType; //假別
                    string periodName  = attendancePeriod.Period;      //節次

                    //是否為設定檔節次清單之中
                    if (!TestPeriodList.ContainsKey(periodName))
                    {
                        continue;
                    }

                    //是否為使用者選取之假別&類型
                    if (config.ContainsKey(TestPeriodList[periodName]))
                    {
                        if (config[TestPeriodList[periodName]].Contains(absenceType))
                        {
                            string PeriodAndAbsence = TestPeriodList[periodName] + "," + absenceType;
                            //區間統計
                            if (!studentOBJ.studentAbsence.ContainsKey(PeriodAndAbsence))
                            {
                                studentOBJ.studentAbsence.Add(PeriodAndAbsence, 0);
                            }

                            studentOBJ.studentAbsence[PeriodAndAbsence]++;

                            //明細記錄
                            if (!studentOBJ.studentAbsenceDetail.ContainsKey(occurDate.ToShortDateString()))
                            {
                                studentOBJ.studentAbsenceDetail.Add(occurDate.ToShortDateString(), new Dictionary <string, string>());
                            }

                            if (!studentOBJ.studentAbsenceDetail[occurDate.ToShortDateString()].ContainsKey(attendancePeriod.Period))
                            {
                                studentOBJ.studentAbsenceDetail[occurDate.ToShortDateString()].Add(attendancePeriod.Period, attendancePeriod.AbsenceType);
                            }
                        }
                    }
                }
            }

            #endregion

            List <string> DelStudent = new List <string>(); //列印的學生

            #region 條件1
            if (obj.ConditionName != "")                       //如果不等於空就是要判斷啦
            {
                foreach (string each1 in StudentSuperOBJ.Keys) //取出一個學生
                {
                    int  AbsenceCount = 0;
                    bool AbsenceBOOL  = false;
                    foreach (string each2 in StudentSuperOBJ[each1].studentAbsenceDetail.Keys)            //取出一天
                    {
                        foreach (string each3 in StudentSuperOBJ[each1].studentAbsenceDetail[each2].Keys) //取出一節內容
                        {
                            string each4 = StudentSuperOBJ[each1].studentAbsenceDetail[each2][each3];

                            if (TestPeriodList.ContainsKey(each3))
                            {
                                if (config.ContainsKey(TestPeriodList[each3]))
                                {
                                    if (obj.ConditionName == each4)
                                    {
                                        AbsenceCount++;
                                    }

                                    if (AbsenceCount >= int.Parse(obj.ConditionNumber))
                                    {
                                        AbsenceBOOL = true;
                                        if (!DelStudent.Contains(each1))
                                        {
                                            DelStudent.Add(each1); //把學生ID記下
                                        }
                                    }

                                    if (AbsenceBOOL)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        if (AbsenceBOOL)
                        {
                            break;
                        }
                    }
                }
            }
            #endregion

            #region 條件2
            if (obj.ConditionName2 != "")                      //如果等於空就是直接全部印啦!!
            {
                foreach (string each1 in StudentSuperOBJ.Keys) //取出一個學生
                {
                    int  AbsenceCount = 0;
                    bool AbsenceBOOL  = false;
                    foreach (string each2 in StudentSuperOBJ[each1].studentAbsenceDetail.Keys)            //取出一天
                    {
                        foreach (string each3 in StudentSuperOBJ[each1].studentAbsenceDetail[each2].Keys) //取出一節內容
                        {
                            string each4 = StudentSuperOBJ[each1].studentAbsenceDetail[each2][each3];

                            if (TestPeriodList.ContainsKey(each3))
                            {
                                if (config.ContainsKey(TestPeriodList[each3]))
                                {
                                    if (obj.ConditionName2 == each4)
                                    {
                                        AbsenceCount++;
                                    }

                                    if (AbsenceCount >= int.Parse(obj.ConditionNumber2))
                                    {
                                        AbsenceBOOL = true;

                                        DelStudent.Add(each1); //把學生ID記下
                                    }

                                    if (AbsenceBOOL)
                                    {
                                        break;
                                    }
                                }
                                if (AbsenceBOOL)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region 無條件則全部列印
            if (obj.ConditionName == "" && obj.ConditionName2 == "")
            {
                foreach (string each1 in StudentSuperOBJ.Keys) //取出一個學生
                {
                    if (!DelStudent.Contains(each1))
                    {
                        DelStudent.Add(each1);
                    }
                }
            }
            #endregion

            #region 取得所有學生缺曠紀錄,學期累計
            foreach (AttendanceRecord attendance in K12.Data.Attendance.SelectBySchoolYearAndSemester(Student.SelectByIDs(allStudentID), int.Parse(School.DefaultSchoolYear), int.Parse(School.DefaultSemester)))
            {
                //1(大於),0(等於)-1(小於)
                if (obj.EndDate.CompareTo(attendance.OccurDate) == -1)
                {
                    continue;
                }

                string     studentID  = attendance.RefStudentID;
                DateTime   occurDate  = attendance.OccurDate;
                StudentOBJ studentOBJ = StudentSuperOBJ[studentID]; //取得這個物件

                foreach (AttendancePeriod attendancePeriod in attendance.PeriodDetail)
                {
                    string absenceType = attendancePeriod.AbsenceType; //假別
                    string periodName  = attendancePeriod.Period;      //節次
                    if (!TestPeriodList.ContainsKey(periodName))
                    {
                        continue;
                    }

                    string PeriodAndAbsence = TestPeriodList[periodName] + "," + absenceType;
                    //區間統計
                    if (!studentOBJ.studentSemesterAbsence.ContainsKey(PeriodAndAbsence))
                    {
                        studentOBJ.studentSemesterAbsence.Add(PeriodAndAbsence, 0);
                    }

                    studentOBJ.studentSemesterAbsence[PeriodAndAbsence]++;
                }
            }

            #endregion

            #region 取得學生通訊地址資料
            foreach (AddressRecord record in Address.SelectByStudentIDs(allStudentID))
            {
                if (obj.ReceiveAddress == "戶籍地址")
                {
                    if (!string.IsNullOrEmpty(record.PermanentAddress))
                    {
                        StudentSuperOBJ[record.RefStudentID].address = record.Permanent.County + record.Permanent.Town + record.Permanent.District + record.Permanent.Area + record.Permanent.Detail;
                    }

                    if (!string.IsNullOrEmpty(record.PermanentZipCode))
                    {
                        StudentSuperOBJ[record.RefStudentID].ZipCode = record.PermanentZipCode;

                        if (record.PermanentZipCode.Length >= 1)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode1 = record.PermanentZipCode.Substring(0, 1);
                        }
                        if (record.PermanentZipCode.Length >= 2)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode2 = record.PermanentZipCode.Substring(1, 1);
                        }
                        if (record.PermanentZipCode.Length >= 3)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode3 = record.PermanentZipCode.Substring(2, 1);
                        }
                        if (record.PermanentZipCode.Length >= 4)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode4 = record.PermanentZipCode.Substring(3, 1);
                        }
                        if (record.PermanentZipCode.Length >= 5)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode5 = record.PermanentZipCode.Substring(4, 1);
                        }
                    }
                }
                else if (obj.ReceiveAddress == "聯絡地址")
                {
                    if (!string.IsNullOrEmpty(record.MailingAddress))
                    {
                        StudentSuperOBJ[record.RefStudentID].address = record.Mailing.County + record.Mailing.Town + record.Mailing.District + record.Mailing.Area + record.Mailing.Detail; //再處理
                    }
                    if (!string.IsNullOrEmpty(record.MailingZipCode))
                    {
                        StudentSuperOBJ[record.RefStudentID].ZipCode = record.MailingZipCode;

                        if (record.MailingZipCode.Length >= 1)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode1 = record.MailingZipCode.Substring(0, 1);
                        }
                        if (record.MailingZipCode.Length >= 2)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode2 = record.MailingZipCode.Substring(1, 1);
                        }
                        if (record.MailingZipCode.Length >= 3)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode3 = record.MailingZipCode.Substring(2, 1);
                        }
                        if (record.MailingZipCode.Length >= 4)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode4 = record.MailingZipCode.Substring(3, 1);
                        }
                        if (record.MailingZipCode.Length >= 5)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode5 = record.MailingZipCode.Substring(4, 1);
                        }
                    }
                }
                else if (obj.ReceiveAddress == "其他地址")
                {
                    if (!string.IsNullOrEmpty(record.Address1Address))
                    {
                        StudentSuperOBJ[record.RefStudentID].address = record.Address1.County + record.Address1.Town + record.Address1.District + record.Address1.Area + record.Address1.Detail; //再處理
                    }
                    if (!string.IsNullOrEmpty(record.Address1ZipCode))
                    {
                        StudentSuperOBJ[record.RefStudentID].ZipCode = record.Address1ZipCode;

                        if (record.Address1ZipCode.Length >= 1)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode1 = record.Address1ZipCode.Substring(0, 1);
                        }
                        if (record.Address1ZipCode.Length >= 2)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode2 = record.Address1ZipCode.Substring(1, 1);
                        }
                        if (record.Address1ZipCode.Length >= 3)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode3 = record.Address1ZipCode.Substring(2, 1);
                        }
                        if (record.Address1ZipCode.Length >= 4)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode4 = record.Address1ZipCode.Substring(3, 1);
                        }
                        if (record.Address1ZipCode.Length >= 5)
                        {
                            StudentSuperOBJ[record.RefStudentID].ZipCode5 = record.Address1ZipCode.Substring(4, 1);
                        }
                    }
                }
            }
            #endregion

            #region 取得學生監護人父母親資料
            foreach (ParentRecord record in Parent.SelectByStudentIDs(allStudentID))
            {
                StudentSuperOBJ[record.RefStudentID].CustodianName = record.CustodianName;
                StudentSuperOBJ[record.RefStudentID].FatherName    = record.FatherName;
                StudentSuperOBJ[record.RefStudentID].MotherName    = record.MotherName;
            }
            //dsrsp = JHSchool.Compatibility.Feature.QueryStudent.GetMultiParentInfo(allStudentID.ToArray());
            //foreach (XmlElement var in dsrsp.GetContent().GetElements("ParentInfo"))
            //{
            //    string studentID = var.GetAttribute("StudentID");

            //    studentInfo[studentID].Add("CustodianName", var.SelectSingleNode("CustodianName").InnerText);
            //    studentInfo[studentID].Add("FatherName", var.SelectSingleNode("FatherName").InnerText);
            //    studentInfo[studentID].Add("MotherName", var.SelectSingleNode("MotherName").InnerText);
            //}
            #endregion

            #endregion

            Document template = new Document(obj.Template);

            #region 缺曠類別部份
            int columnNumber = 0;

            foreach (List <string> var in config.Values)
            {
                columnNumber += var.Count;
            }
            #endregion

            #region 產生報表

            Document doc = new Document();
            doc.Sections.Clear();
            paperForStudent = new SmartSchool.ePaper.ElectronicPaper("缺曠通知單_" + DateTime.Now.Year + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0'), School.DefaultSchoolYear, School.DefaultSemester, SmartSchool.ePaper.ViewerType.Student);

            DataTable dt = new DataTable();

            // 2020/01/09 穎驊修正,因應郵局格式要求說明文件中,收件人的姓名、郵遞區號和地址,有規定的欄位名稱(CN,POSTALCODE,POSTALADDRESS),手動填入
            dt.Columns.Add("CN");
            dt.Columns.Add("POSTALCODE");
            dt.Columns.Add("POSTALADDRESS");

            foreach (string studentID in StudentSuperOBJ.Keys)
            {
                Dictionary <string, object> mappingAccessory = new Dictionary <string, object>();
                foreach (string each in mappingAccessory_copy.Keys)
                {
                    mappingAccessory.Add(each, mappingAccessory_copy[each]);
                }

                StudentOBJ eachStudentInfo = StudentSuperOBJ[studentID];

                //合併列印的資料
                Dictionary <string, object> mapping = new Dictionary <string, object>();

                if (!DelStudent.Contains(studentID)) //如果不包含在內,就離開
                {
                    continue;
                }

                if (obj.PrintHasRecordOnly)
                {
                    //明細等於0
                    if (eachStudentInfo.studentAbsenceDetail.Count == 0)
                    {
                        currentStudentCount++;
                        continue;
                    }
                }

                Document eachSection = new Document();
                eachSection.Sections.Clear();
                eachSection.Sections.Add(eachSection.ImportNode(template.Sections[0], true));

                MemoryStream          accessoryMemory;
                Aspose.Words.Document accessoryDoc;

                //學生資料
                mappingAccessory.Add("學生姓名", eachStudentInfo.student.Name);
                mappingAccessory.Add("班級", eachStudentInfo.ClassName);
                mappingAccessory.Add("座號", eachStudentInfo.SeatNo);
                mappingAccessory.Add("學號", eachStudentInfo.StudentNumber);
                mappingAccessory.Add("導師", eachStudentInfo.TeacherName);
                mappingAccessory.Add("學年度", School.DefaultSchoolYear);
                mappingAccessory.Add("學期", School.DefaultSemester);
                mappingAccessory.Add("資料期間", obj.StartDate.ToShortDateString() + " 至 " + obj.EndDate.ToShortDateString());
                //懲戒明細
                bool IsAccessory = false;

                //學校資訊
                mapping.Add("學校名稱", School.ChineseName);
                mapping.Add("學校地址", School.Address);
                mapping.Add("學校電話", School.Telephone);

                //學生資料
                mapping.Add("學生姓名", eachStudentInfo.student.Name);
                mapping.Add("班級", eachStudentInfo.ClassName);
                mapping.Add("座號", eachStudentInfo.SeatNo);
                mapping.Add("學號", eachStudentInfo.StudentNumber);
                mapping.Add("導師", eachStudentInfo.TeacherName);
                mapping.Add("資料期間", obj.StartDate.ToShortDateString() + " 至 " + obj.EndDate.ToShortDateString());

                // 2019/11/12 穎驊註解 本專案為弘文於本學期提出來的需求,增加家長代碼
                mapping.Add("家長代碼", eachStudentInfo.ParentCode);

                //收件人資料
                if (obj.ReceiveName == "監護人姓名")
                {
                    mapping.Add("收件人姓名", eachStudentInfo.CustodianName);
                }
                else if (obj.ReceiveName == "父親姓名")
                {
                    mapping.Add("收件人姓名", eachStudentInfo.FatherName);
                }
                else if (obj.ReceiveName == "母親姓名")
                {
                    mapping.Add("收件人姓名", eachStudentInfo.MotherName);
                }
                else
                {
                    mapping.Add("收件人姓名", eachStudentInfo.student.Name);
                }

                //收件人地址資料
                mapping.Add("收件人地址", eachStudentInfo.address);
                mapping.Add("郵遞區號", eachStudentInfo.ZipCode);
                mapping.Add("0", eachStudentInfo.ZipCode1);
                mapping.Add("1", eachStudentInfo.ZipCode2);
                mapping.Add("2", eachStudentInfo.ZipCode3);
                mapping.Add("4", eachStudentInfo.ZipCode4);
                mapping.Add("5", eachStudentInfo.ZipCode5);

                mapping.Add("學年度", School.DefaultSchoolYear);
                mapping.Add("學期", School.DefaultSemester);

                //缺曠學期統計部份
                int columnIndex      = 1;
                int DefinedTypeCount = 1;
                foreach (string attendanceType in configkeylist)
                {
                    int DefinedAbsenceCount = 1;

                    foreach (string absenceType in config[attendanceType])
                    {
                        string dataValue         = "0";
                        string semesterDataValue = "0";
                        string PeriodAndAbsence  = attendanceType + "," + absenceType;
                        //本期統計
                        if (eachStudentInfo.studentAbsence.ContainsKey(PeriodAndAbsence))
                        {
                            dataValue = eachStudentInfo.studentAbsence[PeriodAndAbsence].ToString();
                        }
                        //學期統計
                        if (eachStudentInfo.studentSemesterAbsence.ContainsKey(PeriodAndAbsence))
                        {
                            semesterDataValue = eachStudentInfo.studentSemesterAbsence[PeriodAndAbsence].ToString();
                        }

                        mapping.Add("類型" + DefinedTypeCount + "本期" + DefinedAbsenceCount, dataValue);
                        mapping.Add("類型" + DefinedTypeCount + "學期" + DefinedAbsenceCount, semesterDataValue);
                        DefinedAbsenceCount++;
                        columnIndex++;
                    }
                    DefinedTypeCount++;
                }

                // 2020/02/07 嘉詮與學校後 確立 格式固定要有 日期1~日期12 且每日節次1~12,故總變數為日期1節次1 ~ 日期12節次12
                for (int date = 1; date <= 12; date++)
                {
                    mapping.Add("日期" + date, "");

                    for (int peroid = 1; peroid <= 12; peroid++)
                    {
                        mapping.Add("日期" + date + "節次" + peroid, "");
                    }
                }


                //缺曠明細
                int DateCount = 1;
                foreach (string each in eachStudentInfo.studentAbsenceDetail.Keys)
                {
                    int Period = 1;
                    //資料數大於10,透過附件列印
                    if (DateCount <= 12)
                    {
                        if (mapping.ContainsKey("日期" + DateCount))
                        {
                            mapping["日期" + DateCount] = Switching(each);
                        }
                        else
                        {
                            mapping.Add("日期" + DateCount, Switching(each));
                        }
                    }

                    else
                    {
                        mappingAccessory.Add("日期" + DateCount, Switching(each));
                    }


                    //取得節次清單,一一檢查是否有資料要填
                    foreach (string Date in eachStudentInfo.studentAbsenceDetail[each].Keys)
                    {
                        string detail = eachStudentInfo.studentAbsenceDetail[each][Date];

                        if (absenceList.ContainsKey(detail))
                        {
                            if (ReversionDic.ContainsKey(Date))
                            {
                                if (DateCount <= 12) //資料數大於10,透過附件列印
                                {
                                    if (mapping.ContainsKey("日期" + DateCount + ReversionDic[Date]))
                                    {
                                        mapping["日期" + DateCount + ReversionDic[Date]] = absenceList[detail];
                                    }
                                    else
                                    {
                                        mapping.Add("日期" + DateCount + ReversionDic[Date], absenceList[detail]);
                                    }

                                    Period++;
                                }
                                else
                                {
                                    mappingAccessory.Add("日期" + DateCount + ReversionDic[Date], absenceList[detail]);
                                    IsAccessory = true;
                                    Period++;
                                }
                            }
                        }
                    }

                    DateCount++;
                }



                //學生個人資料
                string[] keys   = new string[mapping.Count];
                object[] values = new object[mapping.Count];
                int      i      = 0;
                foreach (string key in mapping.Keys)
                {
                    keys[i]     = key;
                    values[i++] = mapping[key];
                }
                eachSection.MailMerge.Execute(keys, values);


                //整體資料
                string[] Allkeys   = new string[Allmapping.Count];
                object[] Allvalues = new object[Allmapping.Count];
                int      t         = 0;
                foreach (string key in Allmapping.Keys)
                {
                    Allkeys[t]     = key;
                    Allvalues[t++] = Allmapping[key];
                }

                eachSection.MailMerge.Execute(Allkeys, Allvalues);
                eachSection.MailMerge.DeleteFields();

                #region epost 使用



                // 將對應功能變數 套入dt
                foreach (string key in mapping.Keys)
                {
                    if (!dt.Columns.Contains(key))
                    {
                        dt.Columns.Add(key);
                    }
                }

                foreach (string key in Allmapping.Keys)
                {
                    if (!dt.Columns.Contains(key))
                    {
                        dt.Columns.Add(key);
                    }
                }

                DataRow row = dt.NewRow();

                row["CN"]            = mapping["收件人姓名"];
                row["POSTALCODE"]    = mapping["郵遞區號"];
                row["POSTALADDRESS"] = mapping["收件人地址"];

                foreach (string key in mapping.Keys)
                {
                    row[key] = mapping[key];
                }

                foreach (string key in Allmapping.Keys)
                {
                    row[key] = Allmapping[key];
                }



                dt.Rows.Add(row);
                #endregion


                if (IsAccessory)
                {
                    accessoryMemory = new MemoryStream(Properties.Resources.缺曠通知單_附件一);
                    accessoryDoc    = new Aspose.Words.Document(accessoryMemory);

                    string[] keysAccessory   = new string[mappingAccessory.Count];
                    object[] valuesAccessory = new object[mappingAccessory.Count];
                    int      xx = 0;
                    foreach (string key in mappingAccessory.Keys)
                    {
                        keysAccessory[xx]     = key;
                        valuesAccessory[xx++] = mappingAccessory[key];
                    }

                    accessoryDoc.MailMerge.CleanupOptions = Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveEmptyParagraphs;
                    accessoryDoc.MailMerge.Execute(keysAccessory, valuesAccessory);
                    accessoryDoc.MailMerge.DeleteFields(); //刪除未合併之內容

                    Aspose.Words.Node eachSectionaccessory = accessoryDoc.Sections[0].Clone();
                    eachSection.Sections.Add(eachSection.ImportNode(eachSectionaccessory, true));

                    MemoryStream stream = new MemoryStream();
                    eachSection.Save(stream, SaveFormat.Doc);
                    paperForStudent.Append(new PaperItem(PaperFormat.Office2003Doc, stream, eachStudentInfo.student.ID));
                }
                else
                {
                    MemoryStream stream = new MemoryStream();
                    eachSection.Save(stream, SaveFormat.Doc);
                    paperForStudent.Append(new PaperItem(PaperFormat.Office2003Doc, stream, eachStudentInfo.student.ID));
                }

                foreach (Aspose.Words.Section each in eachSection.Sections)
                {
                    Aspose.Words.Node eachSectionNode = each.Clone();
                    doc.Sections.Add(doc.ImportNode(eachSectionNode, true));
                }

                //回報進度
                _BGWAbsenceNotification.ReportProgress((int)(((double)currentStudentCount++ *100.0) / (double)totalStudentNumber));
            }

            #endregion

            #region 產生學生清單

            Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
            if (obj.PrintStudentList)
            {
                int CountRow = 0;
                wb.Worksheets[0].Cells[CountRow, 0].PutValue("班級");
                wb.Worksheets[0].Cells[CountRow, 1].PutValue("座號");
                wb.Worksheets[0].Cells[CountRow, 2].PutValue("學號");
                wb.Worksheets[0].Cells[CountRow, 3].PutValue("學生姓名");
                wb.Worksheets[0].Cells[CountRow, 4].PutValue("收件人姓名");
                wb.Worksheets[0].Cells[CountRow, 5].PutValue("地址");
                wb.Worksheets[0].Cells[CountRow, 6].PutValue("家長代碼");
                CountRow++;
                foreach (string each in StudentSuperOBJ.Keys)
                {
                    if (!DelStudent.Contains(each)) //如果不包含在內,就離開
                    {
                        continue;
                    }

                    if (obj.PrintHasRecordOnly)
                    {
                        //明細等於0
                        if (StudentSuperOBJ[each].studentAbsenceDetail.Count == 0)
                        {
                            currentStudentCount++;
                            continue;
                        }
                    }

                    wb.Worksheets[0].Cells[CountRow, 0].PutValue(StudentSuperOBJ[each].ClassName);
                    wb.Worksheets[0].Cells[CountRow, 1].PutValue(StudentSuperOBJ[each].SeatNo);
                    wb.Worksheets[0].Cells[CountRow, 2].PutValue(StudentSuperOBJ[each].StudentNumber);
                    wb.Worksheets[0].Cells[CountRow, 3].PutValue(StudentSuperOBJ[each].student.Name);
                    //收件人資料
                    if (obj.ReceiveName == "監護人姓名")
                    {
                        wb.Worksheets[0].Cells[CountRow, 4].PutValue(StudentSuperOBJ[each].CustodianName);
                    }
                    else if (obj.ReceiveName == "父親姓名")
                    {
                        wb.Worksheets[0].Cells[CountRow, 4].PutValue(StudentSuperOBJ[each].FatherName);
                    }
                    else if (obj.ReceiveName == "母親姓名")
                    {
                        wb.Worksheets[0].Cells[CountRow, 4].PutValue(StudentSuperOBJ[each].MotherName);
                    }
                    else
                    {
                        wb.Worksheets[0].Cells[CountRow, 4].PutValue(StudentSuperOBJ[each].student.Name);
                    }

                    wb.Worksheets[0].Cells[CountRow, 5].PutValue(StudentSuperOBJ[each].ZipCode + " " + StudentSuperOBJ[each].address);
                    wb.Worksheets[0].Cells[CountRow, 6].PutValue(StudentSuperOBJ[each].ParentCode);
                    CountRow++;
                }
                wb.Worksheets[0].AutoFitColumns();
            }
            #endregion

            //是否上傳電子報表
            if (obj.PaperUpdate)
            {
                SmartSchool.ePaper.DispatcherProvider.Dispatch(paperForStudent);
            }

            string path  = Path.Combine(Application.StartupPath, "Reports");
            string path2 = Path.Combine(Application.StartupPath, "Reports");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path     = Path.Combine(path, reportName + ".docx");
            path2    = Path.Combine(path2, reportName + "(學生清單).xlsx");
            e.Result = new object[] { reportName, path, doc, path2, obj.PrintStudentList, wb, dt };
        }