private void TaskProcessBtn_Click(object sender, EventArgs e) { if (todoTask.Items.Count == 0) { MessageBox.Show("当前没有待处理任务", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (fileGrid.Rows.Count == 0) { MessageBox.Show("请添加文件", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } startChangeBtn(); FormValOption formValOption = this.mainController.formValOption(this.mainFormOption); formValOption.ProcessTitle = TaskProcessBtn.Text; if (bgWorker.IsBusy) { MessageBox.Show("系统正忙,请稍后再试", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { this.bgWorker.RunWorkerAsync(formValOption); } }
private int TaskProcessAsync(BackgroundWorker bw, FormValOption formValOption) { if (formValOption.TodoTask.Count == 0) { MessageBox.Show("当前没有待处理任务", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(ConstData.STOP_PROCESS); } return(Process(bw, formValOption, ToDoTaskProcess)); }
private void ToDoTaskProcess(FormValOption formValOption, string filepath, string targetFile, ref string result) { targetFile += ConstData.DOCXPREF; formValOption.OutPutFolder = targetFile; using (var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.None)) { using (var document = DocX.Load(fs)) { List <string> tasks = formValOption.TodoTask; foreach (string title in tasks) { if (title == ConstData.pageSettingTabText) { ProcessWorker.PageSet(document, pageSettingService, formValOption); } else if (title == ConstData.headerFooterTabText) { ProcessWorker.HeaderFooterSet(document, headerFooterService, formValOption); } else if (title == ConstData.docInfoTabText) { ProcessWorker.DocInfoSet(document, docInfoService, formValOption); } else if (title == ConstData.textReplaceTabText) { ProcessWorker.TextReplaceSet(document, textReplaceService, formValOption); } else if (title == ConstData.paragraphTabText) { //ProcessWorker.ParagraphSet(document,); } else if (title == ConstData.extractTabText) { ProcessWorker.ExtractSet(document, imageService, hyperLinkService, tableService, formValOption); } } if (!(tasks.Contains(ConstData.extractTabText) && tasks.Count == 1)) { document.SaveAs(targetFile); } if (tasks.Contains(ConstData.docInfoTabText)) { ProcessWorker.UpdateFileTime(docInfoService, targetFile, formValOption); } result = ConstData.SUCCESS; } } }
private void PDFConverterProcess(FormValOption formValOption, string filepath, string targetFile, ref string result) { targetFile += ConstData.PDFPREF; Boolean flag = this.pdfService.WordToPDF(filepath, targetFile); if (flag) { result = ConstData.SUCCESS; } else { result = ConstData.FAIL; } }
public static void ExtractSet(DocX document, ImageService imageService, HyperLinkService hyperLinkService, TableService tableService, FormValOption formValOption) { string output = formValOption.OutPutFolder; if (formValOption.ExtractImageCheckBox) { imageService.extractImages(document, output); } if (formValOption.ExtractHyperLinkCheckBox) { hyperLinkService.extractHyperLink(document, output); } if (formValOption.ExtractTable) { tableService.extractTable(document, output); } }
private void DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bw = sender as BackgroundWorker; FormValOption formValOption = (FormValOption)e.Argument; string title = formValOption.ProcessTitle; if (title == ConstData.START_PRC) { e.Result = TaskProcessAsync(bw, formValOption); } else if (title == ConstData.PDF_EXPORT) { e.Result = PdfExportAsync(bw, formValOption); } if (bw.CancellationPending) { e.Cancel = true; } }
public static void DocInfoSet(DocX document, DocInfoService docInfoService, FormValOption formValOption) { string title = formValOption.DocTitle; string subject = formValOption.DocSubject; string category = formValOption.DocCategory; string description = formValOption.DocDescription; string creator = formValOption.DocCreator; string version = formValOption.DocVersion; Boolean editProtect = formValOption.DocEditPrctCheckBox; Boolean removeEditPrct = formValOption.DocEditPrctRemove; string editPassword = formValOption.DocEditPassword; DocInfoOption option = new DocInfoOption(subject, title, creator, "", description, "", "", category, version, "", ""); docInfoService.addCoreProperties(document, option); if (removeEditPrct) { docInfoService.DocRemoveProtect(document, removeEditPrct); } else if (editProtect) { docInfoService.DocProtect(document, editProtect, editPassword); } }
public int Process(BackgroundWorker bw, FormValOption formValOption, TaskProcess taskProcess) { string outputDirectory = formValOption.OutPutFolder; if (string.IsNullOrWhiteSpace(outputDirectory)) { MessageBox.Show("请选择输出目录", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(ConstData.STOP_PROCESS); } DialogResult dialogResult = MessageBox.Show("开始处理前将关闭所有word文件", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD")) { p.Kill(); } } else { return(ConstData.STOP_PROCESS); } Dictionary <string, string> rows = formValOption.FileGrid; int count = rows.Count; int i = 0; foreach (KeyValuePair <string, string> kv in rows) { if (!bw.CancellationPending) { i++; string filename = kv.Key; string filepath = kv.Value; string result = ""; try { if (!String.IsNullOrWhiteSpace(filepath) && File.Exists(filepath)) { string targetFile = outputDirectory + @"\" + filename; taskProcess(formValOption, filepath, targetFile, ref result); result = ConstData.SUCCESS; } else { result = ConstData.WITHOUT_FILE; } } catch (Exception ex) { logger.Error("***" + filename + ": " + ex.Message); result = ConstData.FAIL; } finally { string data = (i - 1) + "," + result; bw.ReportProgress(i * 100 / count, data); Thread.Sleep(1000); } } } return(ConstData.FINISH_PROCESS); }
private int PdfExportAsync(BackgroundWorker bw, FormValOption formValOption) { return(Process(bw, formValOption, PDFConverterProcess)); }
public FormValOption formValOption(MainFormOption mainFormOption) { List <string> tasks = mainFormOption.TodoTask.Items.Cast <string>().ToList(); FormValOption formValOption = new FormValOption( mainFormOption.OutPutFolder.Text.ToString(), mainFormOption.ExtractImageCheckBox.Checked, mainFormOption.ExtractHyperLinkCheckBox.Checked, mainFormOption.ExtractTable.Checked, mainFormOption.NotSetMargin.Checked, mainFormOption.NotSetPageSize.Checked, mainFormOption.TopMargin.Value.ToString(), mainFormOption.BottomMargin.Value.ToString(), mainFormOption.LeftMargin.Value.ToString(), mainFormOption.RightMargin.Value.ToString(), mainFormOption.PageWidth.Value.ToString(), mainFormOption.PageHeight.Value.ToString(), mainFormOption.PageSetOrientation.Text.ToString(), mainFormOption.ClearHeader.Checked, mainFormOption.ClearFooter.Checked, mainFormOption.FirstHeaderFooter.Checked, mainFormOption.OddEvenHeaderFooter.Checked, mainFormOption.NotSetHeader.Checked, mainFormOption.NotSetFooter.Checked, mainFormOption.HeaderFontDialog.Font, mainFormOption.HeaderAlignComBox.Text.ToString(), mainFormOption.HeaderColorDialog.Color, mainFormOption.PageHeader.Text.ToString(), mainFormOption.FirstHeader.Text.ToString(), mainFormOption.OddHeader.Text.ToString(), mainFormOption.EvenHeader.Text.ToString(), mainFormOption.HeaderImagePath.Text.ToString(), mainFormOption.HeaderLine.Checked, mainFormOption.FooterFontDialog.Font, mainFormOption.FooterAlignComBox.Text.ToString(), mainFormOption.FooterColorDialog.Color, mainFormOption.PageFooter.Text.ToString(), mainFormOption.FirstFooter.Text.ToString(), mainFormOption.OddFooter.Text.ToString(), mainFormOption.EvenFooter.Text.ToString(), mainFormOption.FooterImagePath.Text.ToString(), mainFormOption.FooterLine.Checked, mainFormOption.PageNumberComBox.Text.ToString(), mainFormOption.DocTitle.Text.ToString(), mainFormOption.DocSubject.Text.ToString(), mainFormOption.DocCategory.Text.ToString(), mainFormOption.DocDescription.Text.ToString(), mainFormOption.DocCreator.Text.ToString(), mainFormOption.DocVersion.Text.ToString(), mainFormOption.DocEditPrctCheckBox.Checked, mainFormOption.DocEditPrctRemove.Checked, mainFormOption.DocEditPassword.Text.ToString(), getTextList(mainFormOption.FileGrid), tasks, getTextList(mainFormOption.ReplaceTextGridView), getTextList(mainFormOption.ReplaceLinkGridView), mainFormOption.CreateTimeCheckBox.Checked, mainFormOption.DocCreateTime.Value, mainFormOption.UpdateTimeCheckBox.Checked, mainFormOption.DocUpdateTime.Value ); return(formValOption); }
public static void HeaderFooterSet(DocX document, HeaderFooterService headerFooterService, FormValOption formValOption) { if (formValOption.ClearHeader) { headerFooterService.clearHeader(document); } if (formValOption.ClearFooter) { headerFooterService.clearFooter(document); } Boolean firstOption = formValOption.FirstHeaderFooter; Boolean oddEvenOption = formValOption.OddEvenHeaderFooter; if (!formValOption.NotSetHeader && !formValOption.ClearHeader) { Font headerFont = formValOption.HeaderFontDialog; string headerAlign = formValOption.HeaderAlignComBox; Color headerColor = formValOption.HeaderColorDialog; string pageHeaderText = formValOption.PageHeader; string firstHeaderText = formValOption.FirstHeader; string oddHeaderText = formValOption.OddHeader; string evenHeaderText = formValOption.EvenHeader; string headerImage = formValOption.HeaderImagePath; Boolean headerLineBool = formValOption.HeaderLine; HeaderFooterOption headerOption = new HeaderFooterOption(headerFont, headerColor, headerAlign, pageHeaderText, firstHeaderText, oddHeaderText, evenHeaderText, headerImage, "", headerLineBool); headerFooterService.addHeaders(document, headerOption, firstOption, oddEvenOption); } if (!formValOption.NotSetFooter && !formValOption.ClearFooter) { Font footerFont = formValOption.FooterFontDialog; string footerAlign = formValOption.FooterAlignComBox; Color footerColor = formValOption.FooterColorDialog; string pageFooterText = formValOption.PageFooter; string firstFooterText = formValOption.FirstFooter; string oddFooterText = formValOption.OddFooter; string evenFooterText = formValOption.EvenFooter; string footerImage = formValOption.FooterImagePath; string pageNumber = formValOption.PageNumberComBox; Boolean footerLineBool = formValOption.FooterLine; HeaderFooterOption footerOption = new HeaderFooterOption(footerFont, footerColor, footerAlign, pageFooterText, firstFooterText, oddFooterText, evenFooterText, footerImage, pageNumber, footerLineBool); headerFooterService.addFooters(document, footerOption, firstOption, oddEvenOption); } }
public static void PageSet(DocX document, PageSettingService pageSettingService, FormValOption formValOption) { pageSettingService.marginSetting(document, formValOption.NotSetMargin, formValOption.TopMargin, formValOption.BottomMargin, formValOption.LeftMargin, formValOption.RightMargin); pageSettingService.pageSizeSetting(document, formValOption.NotSetPageSize, formValOption.PageWidth, formValOption.PageHeight); pageSettingService.pageOrientation(document, formValOption.PageSetOrientation); }
/*private void ParagraphSet(DocX document) * { * this.paragraphService.Set(document, SpaceBefore, SpaceAfter, SpaceLineVal, IndentationSpecialVal, IndentationBefore, IndentationAfter, TextSpace * , ParagraphAlign, SpaceLineType, IndentationSpecial); * }*/ public static void TextReplaceSet(DocX document, TextReplaceService textReplaceService, FormValOption formValOption) { Dictionary <string, string> replaceTextLists = formValOption.ReplaceTextGridView; textReplaceService.TextReplaceSet(document, replaceTextLists); //Dictionary<string, string> replaceLinkGridView = formValOption.ReplaceLinkGridView; //thisReplaceService.HyperLinkReplaceSet(document, hyperLinkLists); }
public static void UpdateFileTime(DocInfoService docInfoService, string targetFile, FormValOption formValOption) { docInfoService.UpdateFileTime(targetFile, formValOption.CreateTimeCheckBox, formValOption.DocCreateTime, formValOption.UpdateTimeCheckBox, formValOption.DocUpdateTime); }