// 打印选项 private void button_print_option_Click(object sender, EventArgs e) { // 配置标题和风格 PrintOption option = new SettlementPrintOption(this.MainForm.DataDir); option.LoadData(this.MainForm.AppInfo, "settlement_printoption"); PrintOptionDlg dlg = new PrintOptionDlg(); MainForm.SetControlFont(dlg, this.Font, false); dlg.MainForm = this.MainForm; dlg.DataDir = this.MainForm.DataDir; dlg.PrintOption = option; dlg.ColumnItems = new string[] { "no -- 序号", "id -- 记录ID", "state -- 状态", "readerBarcode -- 读者证条码号", "summary -- 摘要", "price -- 金额", "comment -- 注释", "reason -- 原因", "borrowDate -- 借阅日期", "borrowPeriod -- 借阅时限", "returnDate -- 还书日期", "returnOperator -- 还书操作者", "barcode -- 册条码号", "amerceOperator -- 收费者", "amerceTime -- 收费日期", "settlementOperator -- 结算者", "settlementTime -- 结算日期", "recpath -- 记录路径" }; this.MainForm.AppInfo.LinkFormState(dlg, "settlement_printoption_formstate"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult != DialogResult.OK) return; option.SaveData(this.MainForm.AppInfo, "settlement_printoption"); }
// 构造html页面 int BuildHtml( List<ListViewItem> items, out List<string> filenames, out string strError) { strError = ""; Hashtable macro_table = new Hashtable(); // 获得打印参数 PrintOption option = new SettlementPrintOption(this.MainForm.DataDir); option.LoadData(this.MainForm.AppInfo, "settlement_printoption"); // 检查按收费者小计时,是否具有价格列 if (this.checkBox_sumByAmerceOperator.Checked == true) { // 检查是否具有价格列? if (HasPriceColumn(option) == false) { MessageBox.Show(this, "警告:虽打印要求‘按收费者小计金额’,但‘价格’列并未包含在打印列中。因此小计的金额无法打印出来。"); } } // 计算出页总数 int nTablePageCount = items.Count / option.LinesPerPage; if ((items.Count % option.LinesPerPage) != 0) nTablePageCount++; int nPageCount = nTablePageCount + 1; macro_table["%pagecount%"] = nPageCount.ToString(); macro_table["%linesperpage%"] = option.LinesPerPage.ToString(); macro_table["%date%"] = DateTime.Now.ToLongDateString(); filenames = new List<string>(); // 每页一个文件,这个数组存放了所有文件名 string strFileNamePrefix = this.MainForm.DataDir + "\\~settlement"; string strFileName = ""; // 输出信息页 // TODO: 要增加“统计页”模板功能。如何用模板来定义循环的行,有一定难度 { int nItemCount = GetItemCount(items); string strTotalPrice = GetTotalPrice(items).ToString(); macro_table["%itemcount%"] = nItemCount.ToString(); macro_table["%totalprice%"] = strTotalPrice; macro_table["%pageno%"] = "1"; strFileName = strFileNamePrefix + "0" + ".html"; filenames.Add(strFileName); BuildPageTop(option, macro_table, strFileName, false); // 内容行 StreamUtil.WriteText(strFileName, "<table class='totalsum'>"); // 列标题行 StreamUtil.WriteText(strFileName, "<tr class='totalsum_columtitle'>"); StreamUtil.WriteText(strFileName, "<td class='person'>收费者</td>"); StreamUtil.WriteText(strFileName, "<td class='itemcount'>事项数</td>"); StreamUtil.WriteText(strFileName, "<td class='price'>金额</td>"); StreamUtil.WriteText(strFileName, "</tr>"); // 总计行 StreamUtil.WriteText(strFileName, "<tr class='totalsum_line'>"); StreamUtil.WriteText(strFileName, "<td class='person'>总计</td>"); StreamUtil.WriteText(strFileName, "<td class='itemcount'>" + nItemCount.ToString() + "</td>"); StreamUtil.WriteText(strFileName, "<td class='price'>" + strTotalPrice + "</td>"); StreamUtil.WriteText(strFileName, "</tr>"); if (this.checkBox_sumByAmerceOperator.Checked == true) { // 收费人小计 // 小计提示行 StreamUtil.WriteText(strFileName, "<tr class='amerceoperatorsum_titleline'>"); StreamUtil.WriteText(strFileName, "<td class='amerceoperatorsum_titleline' colspan='3'>(以下为按收费者分类的小计金额)</td>"); StreamUtil.WriteText(strFileName, "</tr>"); for (int i = 0; i < items.Count; i++) { ListViewItem item = items[i]; if (item == null) { string strAmerceOperator = ""; int nSumItemCount = 0; decimal sum = ComputeSameAmerceOperatorSumPrice(items, i, out strAmerceOperator, out nSumItemCount); StreamUtil.WriteText(strFileName, "<tr class='amerceoperatorsum_line'>"); StreamUtil.WriteText(strFileName, "<td class='person'>" + strAmerceOperator + "</td>"); StreamUtil.WriteText(strFileName, "<td class='itemcount'>" + nSumItemCount.ToString() + "</td>"); StreamUtil.WriteText(strFileName, "<td class='price'>" + sum.ToString() + "</td>"); StreamUtil.WriteText(strFileName, "</tr>"); } } StreamUtil.WriteText(strFileName, "</table>"); } BuildPageBottom(option, macro_table, strFileName, false); } // 表格页循环 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; }