コード例 #1
0
        /// <summary>
        /// 背景完成
        /// </summary>
        void BGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                MsgBox.Show("請設定節次資料!!");
                return;
            }

            if (e.Error != null)
            {
                MsgBox.Show("列印資料發生錯誤\n" + e.Error.Message);
                SmartSchool.ErrorReporting.ReportingService.ReportException(e.Error);
                return;
            }

            if (SingeFile)
            {
                #region 學生清單多檔列印
                //未完成 6/21
                //以學生資料列印報表名稱

                Dictionary <string, Document> DocDic = (Dictionary <string, Document>)e.Result;
                btnSave.Enabled = true;
                try
                {
                    FolderBrowserDialog fbd = new FolderBrowserDialog();
                    fbd.Description         = "請選擇學生日常表現總表檔案儲存位置\n規格為(學號_身分證號_班級_座號_姓名)";
                    fbd.ShowNewFolderButton = true;

                    if (fbd.ShowDialog() == DialogResult.Cancel)
                    {
                        MsgBox.Show("已取消存檔!!");
                        return;
                    }

                    //學號 報表名稱 學生姓名
                    //DocDic - 系統編號
                    //學號
                    //姓名等資料
                    //儲存路逕
                    Dictionary <string, Document> dic = new Dictionary <string, Document>();

                    foreach (string each in DocDic.Keys)
                    {
                        if (Data.DicStudent.ContainsKey(each))
                        {
                            StudentDataObj obj      = Data.DicStudent[each];
                            Document       inResult = DocDic[each];

                            StringBuilder sb = new StringBuilder();
                            sb.Append(fbd.SelectedPath + "\\");
                            sb.Append(obj.StudentRecord.StudentNumber + "_");
                            sb.Append(obj.StudentRecord.IDNumber + "_");
                            sb.Append((obj.StudentRecord.Class != null ? obj.StudentRecord.Class.Name : "") + "_");
                            sb.Append((obj.StudentRecord.SeatNo.HasValue ? "" + obj.StudentRecord.SeatNo.Value : "") + "_");
                            sb.Append(obj.StudentRecord.Name + ".docx");
                            if (!dic.ContainsKey(sb.ToString()))
                            {
                                dic.Add(sb.ToString(), inResult);
                            }
                            else
                            {
                                MsgBox.Show("發生檔案同名錯誤!!\n" + sb.ToString());
                            }
                        }
                    }

                    foreach (string each in dic.Keys)
                    {
                        dic[each].Save(each);
                    }
                    System.Diagnostics.Process.Start("explorer", fbd.SelectedPath);
                    MotherForm.SetStatusBarMessage("學生日常表現總表,儲存完成!!");
                }
                catch
                {
                    FISCA.Presentation.Controls.MsgBox.Show("檔案儲存錯誤");
                    MotherForm.SetStatusBarMessage("檔案儲存錯誤");
                }
                #endregion
            }
            else
            {
                #region 學生清單單檔列印
                Document inResult = (Document)e.Result;
                btnSave.Enabled = true;

                try
                {
                    SaveFileDialog SaveFileDialog1 = new SaveFileDialog();

                    SaveFileDialog1.Filter   = "Word (*.docx)|*.docx|所有檔案 (*.*)|*.*";
                    SaveFileDialog1.FileName = "學生日常表現總表";

                    if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        inResult.Save(SaveFileDialog1.FileName);
                        Process.Start(SaveFileDialog1.FileName);
                        MotherForm.SetStatusBarMessage("學生日常表現總表,列印完成!!");
                    }
                    else
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("已取消存檔");
                        return;
                    }
                }
                catch
                {
                    FISCA.Presentation.Controls.MsgBox.Show("檔案儲存錯誤,請檢查檔案是否開啟中!!");
                    MotherForm.SetStatusBarMessage("檔案儲存錯誤,請檢查檔案是否開啟中!!");
                }
                #endregion
            }
        }
コード例 #2
0
        /// <summary>
        /// 每一名學生的報表資料列印
        /// </summary>
        /// <returns></returns>
        private Document SetDocument(string student)
        {
            #region 每一名學生的報表資料列印

            StudentDataObj obj = Data.DicStudent[student];
            //取得範本樣式
            Document PageOne = (Document)_template.Clone(true);
            //???
            _run = new Run(PageOne);
            //可建構的...
            DocumentBuilder builder  = new DocumentBuilder(PageOne);
            DocumentBuilder builderX = new DocumentBuilder(_template);

            builder.MoveToMergeField("缺曠");
            Cell absenceCell = (Cell)builder.CurrentParagraph.ParentNode;
            foreach (string each in absenceList)
            {
                Write(absenceCell, each);

                if (absenceCell.NextSibling != null)
                {
                    absenceCell = absenceCell.NextSibling as Cell; //取得下一格
                }
            }

            #region 資料MailMerge第一步

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

            name.Add("學校名稱");
            value.Add(School.ChineseName);

            name.Add("學號");
            value.Add(obj.StudentRecord.StudentNumber);

            name.Add("姓名");
            value.Add(obj.StudentRecord.Name);

            name.Add("性別");
            value.Add(obj.StudentRecord.Gender);

            name.Add("身分證");
            value.Add(obj.StudentRecord.IDNumber);

            name.Add("生日");
            value.Add(obj.StudentRecord.Birthday.HasValue ? obj.StudentRecord.Birthday.Value.ToShortDateString() : "");

            name.Add("出生");
            value.Add(obj.StudentRecord.BirthPlace);

            name.Add("監護");
            value.Add(obj.CustodianName);

            name.Add("戶籍");
            value.Add(obj.AddressPermanent);

            name.Add("電話1");
            value.Add(obj.PhonePermanent);

            name.Add("稱謂");
            value.Add(obj.CustodianTitle);

            name.Add("通訊");
            value.Add(obj.AddressMailing);

            name.Add("電話2");
            value.Add(obj.PhoneContact);

            name.Add("一上");
            value.Add(obj.GradeYear11);

            name.Add("一下");
            value.Add(obj.GradeYear12);

            name.Add("二上");
            value.Add(obj.GradeYear21);

            name.Add("二下");
            value.Add(obj.GradeYear22);

            name.Add("三上");
            value.Add(obj.GradeYear31);

            name.Add("三下");
            value.Add(obj.GradeYear32);

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

            #region 依據日常生活表現數量,建立欄位數量

            //記錄日常生活表現 - 學期的第一格
            DicBack = new Dictionary <string, Cell>();

            builder.MoveToMergeField("異2");
            SetRowCount("異動資料欄1", (Cell)builder.CurrentParagraph.ParentNode, obj.ListUpdateRecord.Count);

            builder.MoveToMergeField("日2");
            SetRowCount("日常生活表現欄1", (Cell)builder.CurrentParagraph.ParentNode, obj.TextScoreDic.Count);


            if (BehaviorList2.Count > 0)
            {
                builder.MoveToMergeField("常2");
                SetRowCount("日常生活表現欄2", (Cell)builder.CurrentParagraph.ParentNode, obj.TextScoreDic.Count);
            }

            if (BehaviorList3.Count > 0)
            {
                builder.MoveToMergeField("生2");
                SetRowCount("日常生活表現欄3", (Cell)builder.CurrentParagraph.ParentNode, obj.TextScoreDic.Count);
            }

            builder.MoveToMergeField("統2");
            SetRowCount("缺曠資料欄1", (Cell)builder.CurrentParagraph.ParentNode, obj.DicAsbs.Count);

            builder.MoveToMergeField("獎2");
            SetRowCount("獎懲資料欄1", (Cell)builder.CurrentParagraph.ParentNode, obj.DicMeritDemerit.Count);

            builder.MoveToMergeField("細2");

            int CountDem = 0;
            foreach (DemeritRecord dRecord in obj.ListDeMerit)
            {
                if (dRecord.Cleared == "是")
                {
                    continue;
                }
                CountDem++;
            }

            SetRowCount("獎懲明細欄1", (Cell)builder.CurrentParagraph.ParentNode, obj.ListMerit.Count + CountDem);

            #endregion

            #region 異動處理

            Cell UpdateRecordCell = DicBack["異動資料欄1"];

            foreach (UpdateRecordRecord updateRecord in obj.ListUpdateRecord)
            {
                List <string> list = new List <string>();
                list.Add(updateRecord.SchoolYear.HasValue ? updateRecord.SchoolYear.Value.ToString() : "");
                list.Add(updateRecord.Semester.HasValue ? updateRecord.Semester.Value.ToString() : "");
                list.Add(updateRecord.UpdateDate);
                list.Add(updateRecord.ADDate);
                list.Add(updateRecord.UpdateDescription);
                //list.Add(GetUpdateRecordCode(updateRecord.UpdateCode));
                list.Add(updateRecord.ADNumber);
                list.Add(updateRecord.Comment);

                foreach (string UpdateName in list)
                {
                    //寫入
                    Write(UpdateRecordCell, UpdateName);
                    if (UpdateRecordCell.NextSibling != null)                    //是否最後一格
                    {
                        UpdateRecordCell = UpdateRecordCell.NextSibling as Cell; //下一格
                    }
                }
                Row Nextrow = UpdateRecordCell.ParentRow.NextSibling as Row; //取得下一個Row
                UpdateRecordCell = Nextrow.FirstCell;                        //第一格Cell

                if (UpdateRecordCell == null)
                {
                    break;
                }
            }

            #endregion

            #region 日1

            //填入日常生活表現1標題內容
            builder.MoveToMergeField("日1");
            Cell setupCell = (Cell)builder.CurrentParagraph.ParentNode;

            foreach (string each in BehaviorList1)
            {
                Write(setupCell, each); //填入導師評語

                if (setupCell.NextSibling != null)
                {
                    setupCell = setupCell.NextSibling as Cell; //取得下一格
                }
            }

            Cell MoralScore1 = DicBack["日常生活表現欄1"];
            //KEY 學年期資訊
            foreach (string moralScore in obj.TextScoreDic.Keys)
            {
                //填入學年期
                Write(MoralScore1, moralScore);
                //欄位名稱
                foreach (string BehaviorConfigName1 in obj.TextScoreDic[moralScore].Keys)
                {
                    //第一欄內容
                    if (BehaviorList1.Contains(BehaviorConfigName1))
                    {
                        Cell Score = GetMoveRightCell(MoralScore1, GetSummaryIndex(BehaviorConfigName1));
                        Write(Score, obj.TextScoreDic[moralScore][BehaviorConfigName1]);
                    }
                }

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

            #endregion

            #region 日2

            if (BehaviorList2.Count > 0)
            {
                //填入日常生活表現2標題內容
                builder.MoveToMergeField("常1");
                setupCell = (Cell)builder.CurrentParagraph.ParentNode;

                foreach (string each in BehaviorList2)
                {
                    Write(setupCell, each); //填入導師評語

                    if (setupCell.NextSibling != null)
                    {
                        setupCell = setupCell.NextSibling as Cell; //取得下一格
                    }
                }

                Cell MoralScore2 = DicBack["日常生活表現欄2"];

                //KEY 學年期資訊
                foreach (string moralScore in obj.TextScoreDic.Keys)
                {
                    Write(MoralScore2, moralScore);

                    //欄位名稱
                    foreach (string BehaviorConfigName1 in obj.TextScoreDic[moralScore].Keys)
                    {
                        //第二欄內容
                        if (BehaviorList2.Contains(BehaviorConfigName1))
                        {
                            Cell Score = GetMoveRightCell(MoralScore2, GetSummaryIndex(BehaviorConfigName1));
                            Write(Score, obj.TextScoreDic[moralScore][BehaviorConfigName1]);
                        }
                    }

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

            #endregion

            #region 日3

            if (BehaviorList3.Count > 0)
            {
                //填入日常生活表現3標題內容
                builder.MoveToMergeField("生1");
                setupCell = (Cell)builder.CurrentParagraph.ParentNode;

                foreach (string each in BehaviorList3)
                {
                    Write(setupCell, each); //填入導師評語

                    if (setupCell.NextSibling != null)
                    {
                        setupCell = setupCell.NextSibling as Cell; //取得下一格
                    }
                }

                Cell MoralScore3 = DicBack["日常生活表現欄3"];

                //KEY 學年期資訊
                foreach (string moralScore in obj.TextScoreDic.Keys)
                {
                    Write(MoralScore3, moralScore);

                    //欄位名稱
                    foreach (string BehaviorConfigName1 in obj.TextScoreDic[moralScore].Keys)
                    {
                        //第三欄內容
                        if (BehaviorList3.Contains(BehaviorConfigName1))
                        {
                            Cell Score = GetMoveRightCell(MoralScore3, GetSummaryIndex(BehaviorConfigName1));
                            Write(Score, obj.TextScoreDic[moralScore][BehaviorConfigName1]);
                        }
                    }

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

            #endregion

            #region 缺曠

            //填內容

            //builder.MoveToMergeField("統");
            Cell absenceCell2 = DicBack["缺曠資料欄1"];
            //RowNull2 = 0;
            //Cell MoralScore3 = (Cell)builder.CurrentParagraph.ParentNode;
            foreach (string absence3 in obj.DicAsbs.Keys)
            {
                //填入學期
                Write(absenceCell2, absence3);

                foreach (string SummaryName in obj.DicAsbs[absence3].Keys)
                {
                    if (!absenceList.Contains(SummaryName))
                    {
                        continue;
                    }

                    int index = GetSummaryIndex(SummaryName);

                    //如果是0,就是沒有值
                    if (index == 0)
                    {
                        continue;
                    }
                    //取得MoralScore3為基準的 index 格 cell
                    Cell MoralScore4 = GetMoveRightCell(absenceCell2, index);
                    //填入值
                    if (obj.DicAsbs[absence3][SummaryName] != "0")
                    {
                        Write(MoralScore4, obj.DicAsbs[absence3][SummaryName]);
                    }
                }


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

            #region 獎懲

            Cell MeritDemeritCell2 = DicBack["獎懲資料欄1"];
            foreach (string MeritFile in obj.DicMeritDemerit.Keys)
            {
                //填入學期
                Write(MeritDemeritCell2, MeritFile);

                foreach (string SummaryName in obj.DicMeritDemerit[MeritFile].Keys)
                {
                    int index = GetSummaryIndex(SummaryName);

                    //如果是0,就是沒有值
                    if (index == 0)
                    {
                        continue;
                    }

                    //取得MoralScore3為基準的 index 格 cell
                    Cell MoralScore4 = GetMoveRightCell(MeritDemeritCell2, index);

                    //填入值
                    if (obj.DicMeritDemerit[MeritFile][SummaryName] != "0")
                    {
                        Write(MoralScore4, obj.DicMeritDemerit[MeritFile][SummaryName]);
                    }
                }

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


            #endregion

            #region 獎懲(明細部份)

            Cell meritRCell = DicBack["獎懲明細欄1"];

            foreach (MeritRecord record in obj.ListMerit)
            {
                //填入學年期
                Write(meritRCell, record.SchoolYear.ToString() + "/" + record.Semester.ToString());
                meritRCell = GetMoveRightCell(meritRCell, 1);

                //填入日期
                Write(meritRCell, record.OccurDate.ToShortDateString());
                meritRCell = GetMoveRightCell(meritRCell, 1);

                //填入獎懲支數
                Write(meritRCell, GetMeTxt(record));
                meritRCell = GetMoveRightCell(meritRCell, 1);

                //填入獎懲支數
                Write(meritRCell, record.Reason);
                meritRCell = GetMoveRightCell(meritRCell, 1);

                //填入獎懲備註
                Write(meritRCell, record.Remark);

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

            foreach (DemeritRecord record in obj.ListDeMerit)
            {
                if (record.MeritFlag == "2") //留查不顯示
                {
                    continue;
                }

                if (record.Cleared == "是") //留查不顯示
                {
                    continue;
                }

                //填入學年期
                Write(meritRCell, record.SchoolYear.ToString() + "/" + record.Semester.ToString());
                meritRCell = GetMoveRightCell(meritRCell, 1);

                //填入日期
                Write(meritRCell, record.OccurDate.ToShortDateString());
                meritRCell = GetMoveRightCell(meritRCell, 1);

                //填入獎懲支數
                Write(meritRCell, GetDemTxt(record));
                meritRCell = GetMoveRightCell(meritRCell, 1);

                //填入獎懲支數
                Write(meritRCell, record.Reason);
                meritRCell = GetMoveRightCell(meritRCell, 1);

                //填入獎懲支數
                Write(meritRCell, record.Remark);

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

            #endregion


            return(PageOne);

            #endregion
        }