コード例 #1
0
ファイル: PrintBindingForm.cs プロジェクト: paopaofeng/dp2
        // 打印一个合订册的装订单
        int PrintOneBinding(
            PrintBindingPrintOption option,
            Hashtable macro_table,
            ListViewItem item,
            int nIndex,
            out string strFilename,
            out string strWarning,
            out string strError)
        {
            strWarning = "";
            strError = "";
            strFilename = "";

            int nRet = 0;

            macro_table["%bindingissn%"] = ListViewUtil.GetItemText(item, COLUMN_ISBNISSN);
            macro_table["%bindingsummary%"] = ListViewUtil.GetItemText(item, COLUMN_SUMMARY);
            macro_table["%bindingaccessno%"] = ListViewUtil.GetItemText(item, COLUMN_ACCESSNO);

            // 2012/5/29
            string strBidningBarcode = ListViewUtil.GetItemText(item, COLUMN_BARCODE);
            string strBindingBarcodeStyle = "";
            if (this.checkBox_print_barcodeFix.Checked == true)
            {
                if (string.IsNullOrEmpty(strBidningBarcode) == false)
                    strBidningBarcode = "*" + strBidningBarcode + "*";

                // strStyle = " style=\"font-family: C39HrP24DhTt; \"";
            }
            macro_table["%bindingbarcode%"] = strBidningBarcode;

            macro_table["%bindingintact%"] = ListViewUtil.GetItemText(item, COLUMN_INTACT);
            macro_table["%bindingprice%"] = ListViewUtil.GetItemText(item, COLUMN_PRICE);
            macro_table["%bindingvolume%"] = ListViewUtil.GetItemText(item, COLUMN_VOLUME);
            macro_table["%bindingpublishtime%"] = ListViewUtil.GetItemText(item, COLUMN_PUBLISHTIME);
            macro_table["%bindinglocation%"] = ListViewUtil.GetItemText(item, COLUMN_LOCATION);
            macro_table["%bindingrefid%"] = ListViewUtil.GetItemText(item, COLUMN_REFID);

            // string strBiblioRecPath = ListViewUtil.GetItemText(item, COLUMN_BIBLIORECPATH);
            // TODO: 获得书目记录,创建某种格式,并获得某些宏内容?

            if (this.MarcFilter != null)
            {
                string strMARC = "";
                string strOutMarcSyntax = "";

                // TODO: 有错误要明显报出来,否则容易在打印出来后才发现,就晚了

                // 获得MARC格式书目记录
                nRet = GetMarc(item,
                    out strMARC,
                    out strOutMarcSyntax,
                    out strError);
                if (nRet == -1)
                    return -1;

                /*
                // 清除上次曾经加入到macro_table中的内容
                foreach (string key in this.ColumnTable.Keys)
                {
                    macro_table.Remove("%" + key + "%");
                }
                 * */

                this.ColumnTable.Clear();   // 清除上一记录处理时残余的内容

                // 让脚本能够感知到准备的宏
                foreach (string key in macro_table.Keys)
                {
                    this.ColumnTable.Add(key.Replace("%", ""), macro_table[key]);
                }

                // 触发filter中的Record相关动作
                nRet = this.MarcFilter.DoRecord(
                    null,
                    strMARC,
                    strOutMarcSyntax,
                    nIndex,
                    out strError);
                if (nRet == -1)
                    return -1;

                // 追加到macro_table中
                foreach(string key in this.ColumnTable.Keys)
                {
                    macro_table.Remove("%" + key + "%");

                    macro_table.Add("%" + key + "%", this.ColumnTable[key]);
                }
            }

            // 需要将属于合订册的文件名前缀区别开来
            string strRecPath = ListViewUtil.GetItemText(item, COLUMN_RECPATH);
            string strFileNamePrefix = this.MainForm.DataDir + "\\~printbinding_" + strRecPath.Replace("/", "_") + "_";

            strFilename = strFileNamePrefix + "0" + ".html";

            // 提前创建成员表格的内容,因为里面也要顺便创建若干和统计数据有关的宏值
            // 内容暂时不输出
            string strMemberTableResult = "";
            // 构造下属成员的详情表格
            // return:
            //      实际到达的成员册数
            nRet = BuildMembersTable(
                option,
                macro_table,
                item,
                out strMemberTableResult,
                out strError);
            if (nRet == -1)
                return -1;

            if (nRet == 0)
            {
                strWarning = "合订册 (记录路径="+strRecPath+"; 参考ID="
                    +ListViewUtil.GetItemText(item, COLUMN_REFID)+") 中没有包含任何(实到的)成员册";
            }

            BuildPageTop(option,
                macro_table,
                strFilename);

            // 输出信函内容
            {

                /*
                // 期刊种数
                macro_table["%seriescount%"] = seller.Count.ToString();
                // 相关的期数
                macro_table["%issuecount%"] = GetIssueCount(seller).ToString();
                // 缺的册数
                macro_table["%missingitemcount%"] = GetMissingItemCount(seller).ToString();
                */


                string strTemplateFilePath = option.GetTemplatePageFilePath("合订册正文");
                if (String.IsNullOrEmpty(strTemplateFilePath) == false)
                {
                    /*
                     * 期刊名 ISSN 
                     * 索取号
                     * 合订册的册条码号
                     * 合订册的完好率
                     * 合订册的价格
                     * 包含的期范围
                     * 缺期范围
                     * */


                    /*
<div class='binding_table_title'>合订册</div>
<table class='binding'>
<tr class='biblio'>
	<td class='name'>期刊</td>
	<td class='value'>%bindingsummary%</td>
</tr>
<tr class='issn'>
	<td class='name'>ISSN</td>
	<td class='value'>%bindingissn%</td>
</tr>
<tr class='accessno'>
	<td class='name'>索取号</td>
	<td class='value'>%bindingaccessno%</td>
</tr>
<tr class='location'>
	<td class='name'>馆藏地点</td>
	<td class='value'>%bindinglocation%</td>
</tr>
<tr class='barcode'>
	<td class='name'>册条码号</td>
	<td class='value'>%bindingbarcode%</td>
</tr>
<tr class='refid'>
	<td class='name'>参考ID</td>
	<td class='value'>%bindingrefid%</td>
</tr>
<tr class='intact'>
	<td class='name'>完好率</td>
	<td class='value'>%bindingintact%</td>
</tr>
<tr class='bindingprice'>
	<td class='name'>合订价格</td>
	<td class='value'>%bindingprice%</td>
</tr>
<tr class='publishtime'>
	<td class='name'>出版时间</td>
	<td class='value'>%bindingpublishtime%</td>
</tr>
<tr class='bindingissuecount'>
	<td class='name'>期数</td>
	<td class='value'>实含数: %arrivecount%; 缺期数: %missingcount%; 理论数: %issuecount%; 缺期号: %missingvolume%</td>
</tr>
<tr class='volume'>
	<td class='name'>包含期号</td>
	<td class='value'>%bindingvolume%</td>
</tr>
</table>
                     * */

                    // 根据模板打印
                    string strContent = "";
                    // 能自动识别文件内容的编码方式的读入文本文件内容模块
                    // 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);
                }
                else
                {
                    // 缺省的固定内容打印

                    string strTableTitle = option.TableTitle;

                    if (String.IsNullOrEmpty(strTableTitle) == false)
                    {
                        strTableTitle = StringUtil.MacroString(macro_table,
                            strTableTitle);
                    }

                    // 表格开始
                    StreamUtil.WriteText(strFilename,
                        "<div class='binding_table_title'>" + HttpUtility.HtmlEncode(strTableTitle) + "</div>");


                    // 表格开始
                    StreamUtil.WriteText(strFilename,
                        "<table class='binding'>");

                    // 期刊信息
                    StreamUtil.WriteText(strFilename,
                        "<tr class='biblio'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>期刊</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>"+HttpUtility.HtmlEncode(
                      (string)macro_table["%bindingsummary%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // ISSN
                    StreamUtil.WriteText(strFilename,
                        "<tr class='issn'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>ISSN</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(
                      (string)macro_table["%bindingissn%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");


                    // 索取号
                    StreamUtil.WriteText(strFilename,
                        "<tr class='accessno'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>索取号</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(
                      (string)macro_table["%bindingaccessno%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // 馆藏地点
                    StreamUtil.WriteText(strFilename,
                        "<tr class='location'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>馆藏地点</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(
                      (string)macro_table["%bindinglocation%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // 条码号
                    StreamUtil.WriteText(strFilename,
                        "<tr class='barcode'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>册条码号</td>");

                    StreamUtil.WriteText(strFilename,
                      "<td class='value' " + strBindingBarcodeStyle + " >" + HttpUtility.HtmlEncode((string)macro_table["%bindingbarcode%"])
                        + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // 参考ID
                    StreamUtil.WriteText(strFilename,
                        "<tr class='refid'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>参考ID</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(
                      (string)macro_table["%bindingrefid%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // 完好率
                    StreamUtil.WriteText(strFilename,
                        "<tr class='intact'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>完好率</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(
                      (string)macro_table["%bindingintact%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // 价格
                    StreamUtil.WriteText(strFilename,
                        "<tr class='bindingprice'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>合订价格</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(
                      (string)macro_table["%bindingprice%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // 出版时间
                    StreamUtil.WriteText(strFilename,
                        "<tr class='publishtime'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>出版时间</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(
                      (string)macro_table["%bindingpublishtime%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // 期数
                    string strValue = "实含数: " + (string)macro_table["%arrivecount%"] + "; "
                    + "缺期数: " + (string)macro_table["%missingcount%"] + "; "
                    + "理论数: " + (string)macro_table["%issuecount%"];
                    string strMissingVolume = (string)macro_table["%missingvolume%"];
                    if (String.IsNullOrEmpty(strMissingVolume) == false)
                        strValue += "; 缺期号: " + strMissingVolume;
                    StreamUtil.WriteText(strFilename,
                        "<tr class='bindingissuecount'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>期数</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(strValue) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");


                    // 包含的期
                    StreamUtil.WriteText(strFilename,
                        "<tr class='volume'>");
                    StreamUtil.WriteText(strFilename,
                       "<td class='name'>包含期号</td>");
                    StreamUtil.WriteText(strFilename,
                      "<td class='value'>" + HttpUtility.HtmlEncode(
                      (string)macro_table["%bindingvolume%"]) + "</td>");
                    StreamUtil.WriteText(strFilename,
                        "</tr>");

                    // 表格结束
                    StreamUtil.WriteText(strFilename,
                        "</table>");
                }

            }

            // 这时候才输出成员表格内容
            StreamUtil.WriteText(strFilename,
                strMemberTableResult);


            BuildPageBottom(option,
                macro_table,
                strFilename);

            return 0;
        }
コード例 #2
0
ファイル: PrintBindingForm.cs プロジェクト: paopaofeng/dp2
        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);
        }