public ExportMakeUpReportSettingForm(string targetBatchID, string printMode) { InitializeComponent(); _targetBatchID = targetBatchID; _worker = new BackgroundWorker(); _worker.DoWork += new DoWorkEventHandler(Worker_DoWork); _worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Worker_RunWorkerCompleted); _worker.ProgressChanged += new ProgressChangedEventHandler(Worker_ProgressChanged); _worker.WorkerReportsProgress = true; _printMode = printMode; // 依照選擇的模式(依群組、依學生) 修改標題 this.Text = "產生補考公告" + "(" + _printMode + ")"; labelMemo.Text = "本功能將選擇梯次內所有補考資料," + _printMode + "分類列印報表。"; FISCA.UDT.AccessHelper _AccessHelper = new FISCA.UDT.AccessHelper(); // 一開始就先 select 假如沒有的話, 傳預設樣板上去 _configuresList = _AccessHelper.Select <UDT_ReportTemplate>(); if (_configuresList.Count == 0) { UDT_ReportTemplate configure1 = new UDT_ReportTemplate(); configure1.Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.補考公告樣板_依群組_)); configure1.PrintMode = "依群組"; configure1.Encode(); configure1.Save(); UDT_ReportTemplate configure2 = new UDT_ReportTemplate(); configure2.Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.補考公告樣板_依學生_)); configure2.PrintMode = "依學生"; configure2.Encode(); configure2.Save(); } string qry = "PrintMode = '" + _printMode + "'"; _configuresList = _AccessHelper.Select <UDT_ReportTemplate>(qry); if (_configuresList.Count > 0) { _configure = _configuresList[0]; _configure.Decode(); } GetMakeUpBatch(); }
// 依照所選的 評分樣板 、報表種類 、 學年度、學期 Load 進正確的 Configure private void LoadConitionalConfigure() { string qry = "ref_exam_template_id ='" + SourceID + "' and schoolyear='" + comboBoxEx1.Text + "' and semester ='" + comboBoxEx2.Text + "' and exam ='" + SourceType + "'"; _Configures = _AccessHelper.Select <UDT_ReportTemplate>(qry); Configure = _Configures.Count > 0 ? _Configures[0] : null; // 理論上只會有一筆 }
// 變更套印樣板 private void lbc01_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { LoadConitionalConfigure(); // 假如沒有抓到 Configure 代表是第一次設定,帶入預設的報表後,也幫她上傳儲存設定 if (Configure == null) { Configure = new UDT_ReportTemplate(); // 沒有的話 就帶一個新的給它 Configure.Ref_exam_Template_ID = SourceID; Configure.SchoolYear = comboBoxEx1.Text; Configure.Semester = comboBoxEx2.Text; Configure.Exam = SourceType; if (SourceType == "期中") { Configure.Template = new Document(new System.IO.MemoryStream(Properties.Resources.MidReport)); } if (SourceType == "期末") { Configure.Template = new Document(new System.IO.MemoryStream(Properties.Resources.FinalReport)); } if (SourceType == "學期") { Configure.Template = new Document(new System.IO.MemoryStream(Properties.Resources.SemesterReport)); } Configure.Encode(); // 將Word 轉成 stream Configure.Save(); } OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "上傳樣板"; dialog.Filter = "Word檔案 (*.docx)|*.docx|所有檔案 (*.*)|*.*"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { Configure.Template = new Aspose.Words.Document(dialog.FileName); Configure.Encode(); // 將word 轉成 stream Configure.Save(); // 儲存 MsgBox.Show("樣板更改成功!"); } catch { MsgBox.Show("樣板開啟失敗!"); } } }
// 檢視套印樣板 private void lbv01_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { LoadConitionalConfigure(); // 假如沒有抓到 Configure 代表是第一次設定,帶入預設的報表後,也幫她上傳儲存設定 if (Configure == null) { Configure = new UDT_ReportTemplate(); // 沒有的話 就帶一個新的給它 Configure.Ref_exam_Template_ID = SourceID; Configure.SchoolYear = comboBoxEx1.Text; Configure.Semester = comboBoxEx2.Text; Configure.Exam = SourceType; if (SourceType == "期中") { //Configure.Template = new Document(new System.IO.MemoryStream(Properties.Resources.MidReport)); // 2018/10/15 穎驊註記,不再帶出預設定的樣板,因為每間學校不一樣,跑出別的設定很奇怪, // 沒設定的話 就給她空的 Configure.Template = new Document(); } if (SourceType == "期末") { //Configure.Template = new Document(new System.IO.MemoryStream(Properties.Resources.FinalReport)); // 2018/10/15 穎驊註記,不再帶出預設定的樣板,因為每間學校不一樣,跑出別的設定很奇怪, // 沒設定的話 就給她空的 Configure.Template = new Document(); } if (SourceType == "學期") { //Configure.Template = new Document(new System.IO.MemoryStream(Properties.Resources.SemesterReport)); // 2018/10/15 穎驊註記,不再帶出預設定的樣板,因為每間學校不一樣,跑出別的設定很奇怪, // 沒設定的話 就給她空的 Configure.Template = new Document(); } Configure.Encode(); // 將Word 轉成 stream Configure.Save(); } Document doc = new Document(); Configure.Decode(); // 將 stream 轉成 Word doc = Configure.Template; SaveFileDialog sd = new SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = SourceType + "報表樣版.docx"; sd.Filter = "Word檔案 (*.docx)|*.docx|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { doc.Save(sd.FileName, Aspose.Words.SaveFormat.Docx); System.Diagnostics.Process.Start(sd.FileName); } catch { MessageBox.Show("檔案儲存失敗"); } } }