private void button_print_option_Click(object sender, EventArgs e) { // 配置标题和风格 string strNamePath = "printbinding_printoption"; string strPubType = "连续出版物"; PrintBindingPrintOption option = new PrintBindingPrintOption(this.MainForm.DataDir, strPubType); option.LoadData(this.MainForm.AppInfo, strNamePath); PrintOptionDlg dlg = new PrintOptionDlg(); MainForm.SetControlFont(dlg, this.Font, false); dlg.MainForm = this.MainForm; dlg.DataDir = this.MainForm.DataDir; dlg.Text = strPubType + " 装订单 打印参数"; dlg.PrintOption = option; dlg.ColumnItems = new string[] { "missing -- 缺期状态", "publishTime -- 出版日期", "volume -- 卷期号", "barcode -- 册条码号", "intact -- 完好率", "refID -- 参考ID", }; this.MainForm.AppInfo.LinkFormState(dlg, "printbinding_printoption_formstate"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult != DialogResult.OK) return; option.SaveData(this.MainForm.AppInfo, strNamePath); }
private void button_print_print_Click(object sender, EventArgs e) { string strError = ""; string strWarning = ""; int nRet = 0; if (this.listView_parent.Items.Count == 0) { strError = "目前没有可打印的内容"; goto ERROR1; } // TODO: 是否要警告有TYPE_ERROR的事项,不参与打印? int nSkipCount = 0; this.ItemXmlTable.Clear(); // 防止缓冲的册信息在两次批处理之间保留 Hashtable macro_table = new Hashtable(); // 批次号或文件名 多个宏不方便判断后选用,只好合并为一个宏 macro_table["%sourcedescription%"] = this.SourceDescription; macro_table["%libraryname%"] = this.MainForm.LibraryName; macro_table["%date%"] = DateTime.Now.ToLongDateString(); macro_table["%datadir%"] = this.MainForm.DataDir; // 便于引用datadir下templates目录内的某些文件 ////macro_table["%libraryserverdir%"] = this.MainForm.LibraryServerDir; // 便于引用服务器端的CSS文件 // 获得打印参数 string strPubType = "连续出版物"; PrintBindingPrintOption option = new PrintBindingPrintOption(this.MainForm.DataDir, strPubType); option.LoadData(this.MainForm.AppInfo, "printbinding_printoption"); /* macro_table["%pagecount%"] = nPageCount.ToString(); macro_table["%linesperpage%"] = option.LinesPerPage.ToString(); * */ string strMarcFilterFilePath = option.GetTemplatePageFilePath("MARC过滤器"); if (String.IsNullOrEmpty(strMarcFilterFilePath) == false) { ColumnFilterDocument filter = null; this.ColumnTable = new Hashtable(); nRet = PrepareMarcFilter(strMarcFilterFilePath, out filter, out strError); if (nRet == -1) goto ERROR1; // if (filter != null) this.AssemblyFilter = filter.Assembly; else this.AssemblyFilter = null; this.MarcFilter = filter; } List<string> filenames = new List<string>(); try { EnableControls(false); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在构造HTML页面 ..."); stop.BeginLoop(); try { stop.SetProgressRange(0, this.listView_parent.Items.Count); stop.SetProgressValue(0); for (int i = 0; i < this.listView_parent.Items.Count; i++) { ListViewItem item = this.listView_parent.Items[i]; if (item.ImageIndex == TYPE_ERROR) { nSkipCount++; continue; } string strFilename = ""; string strOneWarning = ""; nRet = PrintOneBinding( option, macro_table, item, i, out strFilename, out strOneWarning, out strError); if (nRet == -1) goto ERROR1; if (String.IsNullOrEmpty(strOneWarning) == false) { if (String.IsNullOrEmpty(strWarning) == false) strWarning += "\r\n"; strWarning += strOneWarning; } filenames.Add(strFilename); stop.SetProgressValue(i + 1); } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); EnableControls(true); } if (nSkipCount > 0) { if (String.IsNullOrEmpty(strWarning) == false) strWarning += "\r\n"; strWarning += "打印过程中,有 "+nSkipCount.ToString()+" 个错误状态的事项被跳过"; } if (String.IsNullOrEmpty(strWarning) == false) { // TODO: 如果警告文字的行数太多,需要截断,以便正常显示在MessageBox()中。但是进入文件的内容没有必要截断 MessageBox.Show(this, "警告:\r\n" + strWarning); string strErrorFilename = this.MainForm.DataDir + "\\~printbinding_" + "warning.txt"; StreamUtil.WriteText(strErrorFilename, "警告:\r\n" + strWarning); filenames.Insert(0, strErrorFilename); } HtmlPrintForm printform = new HtmlPrintForm(); printform.Text = "打印装订单"; printform.MainForm = this.MainForm; printform.Filenames = filenames; this.MainForm.AppInfo.LinkFormState(printform, "printbinding_htmlprint_formstate"); printform.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(printform); } finally { if (filenames != null) { Global.DeleteFiles(filenames); filenames.Clear(); } } return; ERROR1: MessageBox.Show(this, strError); }