int BuildHtml( List<ListViewItem> in_items, List<ListViewItem> outof_items, out List<string> filenames, out string strError) { strError = ""; int nRet = 0; Hashtable macro_table = new Hashtable(); string strNamePath = "inventory_printoption"; // 获得打印参数 PrintOption option = new ItemHandoverPrintOption(this.MainForm.DataDir, this.comboBox_load_type.Text); option.LoadData(this.MainForm.AppInfo, strNamePath); macro_table["%date%"] = DateTime.Now.ToLongDateString(); macro_table["%barcodefilepath%"] = ""; macro_table["%barcodefilename%"] = ""; macro_table["%recpathfilepath%"] = ""; macro_table["%recpathfilename%"] = ""; if (this.SourceStyle == "barcodefile") { macro_table["%barcodefilepath%"] = this.BarcodeFilePath; macro_table["%barcodefilename%"] = Path.GetFileName(this.BarcodeFilePath); } else if (this.SourceStyle == "recpathfile") { macro_table["%recpathfilepath%"] = this.RecPathFilePath; macro_table["%recpathfilename%"] = Path.GetFileName(this.RecPathFilePath); } filenames = new List<string>(); // 这个数组存放了所有文件名 string strFileNamePrefix = this.MainForm.DataDir + "\\~inventory"; string strFileName = ""; Collections in_cols = new Collections(); Collections out_cols = new Collections(); // 统计集合 nRet = Count(in_items, ref in_cols, out strError); if (nRet == -1) return -1; // 统计集合 nRet = Count(outof_items, ref out_cols, out strError); if (nRet == -1) return -1; // 输出统计信息页 { macro_table["%scancount%"] = (in_cols.Scaned.Count + out_cols.DataBorrowed.Count + out_cols.DataOnShelf.Count).ToString(); macro_table["%incount%"] = in_items.Count.ToString(); macro_table["%borrowedcount%"] = in_cols.Borrowed.Count.ToString(); macro_table["%onshelfcount%"] = in_cols.OnShelf.Count.ToString(); macro_table["%notreturncount%"] = in_cols.OnShelfBorrowed.Count.ToString(); macro_table["%lostcount%"] = in_cols.Lost.Count.ToString(); macro_table["%outcount%"] = outof_items.Count.ToString(); macro_table["%datadir%"] = this.MainForm.DataDir; // 便于引用datadir下templates目录内的某些文件 macro_table["%cssfilepath%"] = this.GetAutoCssUrl(option, "itemhandover.css"); // 便于引用服务器端或“css”模板的CSS文件 strFileName = strFileNamePrefix + "0" + ".html"; filenames.Add(strFileName); string strTemplateFilePath = option.GetTemplatePageFilePath("统计页"); string strContent = ""; if (String.IsNullOrEmpty(strTemplateFilePath) == true) strContent = @"<html> <head> <LINK href='%cssfilepath%' type='text/css' rel='stylesheet'> </head> <body> <div class='pageheader'>%date% 盘点概况</div> <div class='tabletitle'>%date% 盘点概况 -- %barcodefilepath%</div> <div class='scancount'>数据采集册数: %scancount%</div> <div class='sepline'><hr/></div> <div class='incount'>集合内册数: %incount%</div> <div class='borrowedcount'>借出册数: %borrowedcount%</div> <div class='onshelfcount'>在架册数: %onshelfcount%</div> <div class='notreturncount'>在架错为外借册数: %notreturncount%</div> <div class='lostcount'>丢失册数: %lostcount%</div> <div class='sepline'><hr/></div> <div class='outcount'>集合外册数: %outcount%</div> <div class='sepline'><hr/></div> <div class='pagefooter'></div> </body> </html>"; else { // 根据模板打印 // 能自动识别文件内容的编码方式的读入文本文件内容模块 // return: // -1 出错 // 0 文件不存在 // 1 文件存在 nRet = Global.ReadTextFileContent(strTemplateFilePath, out strContent, out strError); if (nRet == -1) return -1; } string strResult = StringUtil.MacroString(macro_table, strContent); StreamUtil.WriteText(strFileName, strResult); } #if NO // 表格页循环 for (int i = 0; i < nTablePageCount; i++) { macro_table["%pageno%"] = (i + 1 + 1).ToString(); strFileName = strFileNamePrefix + (i + 1).ToString() + ".html"; filenames.Add(strFileName); BuildPageTop(option, macro_table, strFileName, true); // 行循环 for (int j = 0; j < option.LinesPerPage; j++) { BuildTableLine(option, in_items, strFileName, i, j); } BuildPageBottom(option, macro_table, strFileName, true); } /* for (int i = 0; i < this.listView_in.Items.Count; i++) { } * */ #endif return 0; }
private void button_print_option_Click(object sender, EventArgs e) { string strNamePath = "inventory_printoption"; // 配置标题和风格 PrintOption option = new ItemHandoverPrintOption(this.MainForm.DataDir, this.comboBox_load_type.Text); option.LoadData(this.MainForm.AppInfo, strNamePath); PrintOptionDlg dlg = new PrintOptionDlg(); MainForm.SetControlFont(dlg, this.Font, false); dlg.MainForm = this.MainForm; dlg.Text = this.comboBox_load_type.Text + " 打印配置"; dlg.DataDir = this.MainForm.DataDir; // 允许新增模板页 dlg.PrintOption = option; dlg.ColumnItems = new string[] { "no -- 序号", "barcode -- 册条码号", "summary -- 摘要", "isbnIssn -- ISBN/ISSN", "accessNo -- 索取号", "state -- 状态", "location -- 馆藏地点", "price -- 册价格", "bookType -- 册类型", "registerNo -- 登录号", "comment -- 注释", "mergeComment -- 合并注释", "batchNo -- 批次号", "borrower -- 借阅者", "borrowDate -- 借阅日期", "borrowPeriod -- 借阅期限", "recpath -- 册记录路径", "biblioRecpath -- 种记录路径", "biblioPrice -- 种价格" }; this.MainForm.AppInfo.LinkFormState(dlg, "inventory_printoption_formstate"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult != DialogResult.OK) return; option.SaveData(this.MainForm.AppInfo, strNamePath); }
// 构造html页面 // 无论是“打印已验证清单”还是“打印全部事项清单”都调用本函数 int BuildHtml( List<ListViewItem> items, out List<string> filenames, out string strError) { strError = ""; Hashtable macro_table = new Hashtable(); string strNamePath = "handover_printoption"; // 获得打印参数 PrintOption option = new ItemHandoverPrintOption(this.MainForm.DataDir, this.comboBox_load_type.Text); option.LoadData(this.MainForm.AppInfo, strNamePath); // 检查当前排序状态和包含种价格列之间是否存在矛盾 if (bHasBiblioPriceColumn(option) == true) { if (this.SortColumns_in.Count != 0 && this.SortColumns_in[0].No == COLUMN_BIBLIORECPATH) { } else { MessageBox.Show(this, "由于当前打印用到了 “种价格”列,为保证打印结果的准确,程序自动按 ‘种记录路径’ 列对全部列表事项进行一次自动排序。\r\n\r\n为避免这里的自动排序,可在打印前用鼠标左键点栏标题进行符合自己意愿的排序,只要最后一次点的是‘种记录路径’栏标题即可。"); ForceSortColumnsIn(COLUMN_BIBLIORECPATH); } } // 计算出页总数 int nTablePageCount = items.Count / option.LinesPerPage; if ((items.Count % option.LinesPerPage) != 0) nTablePageCount++; int nPageCount = nTablePageCount + 1; // 2009/7/24 changed if (this.SourceStyle == "batchno") { // 2008/11/22 macro_table["%batchno%"] = HttpUtility.HtmlEncode(this.BatchNo); // 批次号 macro_table["%location%"] = HttpUtility.HtmlEncode(this.LocationString); // 馆藏地点 用HtmlEncode()的原因是要防止里面出现的“<不指定>”字样 } else { macro_table["%batchno%"] = ""; macro_table["%location%"] = ""; } macro_table["%pagecount%"] = nPageCount.ToString(); macro_table["%linesperpage%"] = option.LinesPerPage.ToString(); macro_table["%date%"] = DateTime.Now.ToLongDateString(); // 2009/7/24 changed macro_table["%barcodefilepath%"] = ""; macro_table["%barcodefilename%"] = ""; macro_table["%recpathfilepath%"] = ""; macro_table["%recpathfilename%"] = ""; if (this.SourceStyle == "barcodefile") { macro_table["%barcodefilepath%"] = this.BarcodeFilePath; macro_table["%barcodefilename%"] = Path.GetFileName(this.BarcodeFilePath); } else if (this.SourceStyle == "recpathfile") { macro_table["%recpathfilepath%"] = this.RecPathFilePath; macro_table["%recpathfilename%"] = Path.GetFileName(this.RecPathFilePath); } filenames = new List<string>(); // 每页一个文件,这个数组存放了所有文件名 string strFileNamePrefix = this.MainForm.DataDir + "\\~itemhandover"; string strFileName = ""; // 输出统计信息页 { int nItemCount = items.Count; int nBiblioCount = GetBiblioCount(items); string strTotalPrice = GetTotalPrice(items).ToString(); macro_table["%itemcount%"] = nItemCount.ToString(); macro_table["%bibliocount%"] = nBiblioCount.ToString(); macro_table["%totalprice%"] = strTotalPrice; macro_table["%pageno%"] = "1"; // 2008/11/23 macro_table["%datadir%"] = this.MainForm.DataDir; // 便于引用datadir下templates目录内的某些文件 ////macro_table["%libraryserverdir%"] = this.MainForm.LibraryServerDir; // 便于引用服务器端的CSS文件 // 2009/10/10 macro_table["%cssfilepath%"] = this.GetAutoCssUrl(option, "itemhandover.css"); // 便于引用服务器端或“css”模板的CSS文件 strFileName = strFileNamePrefix + "0" + ".html"; filenames.Add(strFileName); string strTemplateFilePath = option.GetTemplatePageFilePath("统计页"); if (String.IsNullOrEmpty(strTemplateFilePath) == false) { /* <html> <head> 老用法<LINK href='%libraryserverdir%/itemhandover.css' type='text/css' rel='stylesheet'> 新用法<LINK href='%cssfilepath%' type='text/css' rel='stylesheet'> </head> <body> <div class='pageheader'>%date% 册移交清单 -- 批: %batchno% -- 地: %location% -- (共 %pagecount% 页)</div> <div class='tabletitle'>%date% 册移交清单 -- %barcodefilepath%</div> <div class='itemcount'>册数: %itemcount%</div> <div class='bibliocount'>种数: %bibliocount%</div> <div class='totalprice'>总价: %totalprice%</div> <div class='sepline'><hr/></div> <div class='batchno'>批次号: %batchno%</div> <div class='location'>馆藏地点: %location%</div> <div class='sepline'><hr/></div> <div class='sender'>移交者: </div> <div class='recipient'>接受者: </div> <div class='pagefooter'>%pageno%/%pagecount%</div> </body> </html> * * */ // 根据模板打印 string strContent = ""; // 能自动识别文件内容的编码方式的读入文本文件内容模块 // return: // -1 出错 // 0 文件不存在 // 1 文件存在 int nRet = Global.ReadTextFileContent(strTemplateFilePath, out strContent, out strError); if (nRet == -1) return -1; string strResult = StringUtil.MacroString(macro_table, strContent); StreamUtil.WriteText(strFileName, strResult); } else { // 缺省的固定内容打印 BuildPageTop(option, macro_table, strFileName, false); // 内容行 StreamUtil.WriteText(strFileName, "<div class='itemcount'>册数: " + nItemCount.ToString() + "</div>"); StreamUtil.WriteText(strFileName, "<div class='bibliocount'>种数: " + nBiblioCount.ToString() + "</div>"); StreamUtil.WriteText(strFileName, "<div class='totalprice'>总价: " + strTotalPrice + "</div>"); StreamUtil.WriteText(strFileName, "<div class='sepline'><hr/></div>"); if (this.SourceStyle == "batchno") { // 2008/11/22 if (String.IsNullOrEmpty(this.BatchNo) == false) { StreamUtil.WriteText(strFileName, "<div class='batchno'>批次号: " + this.BatchNo + "</div>"); } if (String.IsNullOrEmpty(this.LocationString) == false) { StreamUtil.WriteText(strFileName, "<div class='location'>馆藏地点: " + this.LocationString + "</div>"); } } if (this.SourceStyle == "barcodefile") { if (String.IsNullOrEmpty(this.BarcodeFilePath) == false) { StreamUtil.WriteText(strFileName, "<div class='barcodefilepath'>条码号文件: " + this.BarcodeFilePath + "</div>"); } } StreamUtil.WriteText(strFileName, "<div class='sepline'><hr/></div>"); StreamUtil.WriteText(strFileName, "<div class='sender'>移交者: </div>"); StreamUtil.WriteText(strFileName, "<div class='recipient'>接受者: </div>"); BuildPageBottom(option, macro_table, strFileName, false); } } string strMarcFilterFilePath = option.GetTemplatePageFilePath("MARC过滤器"); if (String.IsNullOrEmpty(strMarcFilterFilePath) == false) { int nRet = PrepareMarcFilter(strMarcFilterFilePath, out strError); if (nRet == -1) return -1; } // 表格页循环 for (int i = 0; i < nTablePageCount; i++) { macro_table["%pageno%"] = (i + 1 + 1).ToString(); strFileName = strFileNamePrefix + (i + 1).ToString() + ".html"; filenames.Add(strFileName); BuildPageTop(option, macro_table, strFileName, true); // 行循环 for (int j = 0; j < option.LinesPerPage; j++) { BuildTableLine(option, items, strFileName, i, j); } BuildPageBottom(option, macro_table, strFileName, true); } return 0; }