Ejemplo n.º 1
0
        private void button_print_Click(object sender, EventArgs e)
        {
            if (this.objStatis == null)
            {
                MessageBox.Show(this, "尚未执行统计,无法打印");
                return;
            }

            HtmlPrintForm printform = new HtmlPrintForm();

            printform.Text = "打印统计结果";
            // printform.MainForm = Program.MainForm;

            Debug.Assert(this.objStatis != null, "");
            printform.Filenames = this.objStatis.OutputFileNames;
            Program.MainForm.AppInfo.LinkFormState(printform, "printform_state");
            printform.ShowDialog(this);
            Program.MainForm.AppInfo.UnlinkFormState(printform);
        }
Ejemplo n.º 2
0
        // 打印解释内容
        void menu_printHtml_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选定要打印的行";
                goto ERROR1;
            }

            List<string> filenames = new List<string>();
            string strFileNamePrefix = this.MainForm.DataDir + "\\~operlog_print_";
            string strFilename = strFileNamePrefix + (1).ToString() + ".html";
            filenames.Add(strFilename);

            File.Delete(strFilename);

            StreamUtil.WriteText(strFilename,
    "<html>" +
    GetHeadString(false) +
    "<body>");

            Stop stop = new DigitalPlatform.Stop();
            stop.Register(MainForm.stopManager, true);	// 和容器关联

            stop.OnStop += new StopEventHandler(this.DoStopPrint);
            stop.Initial("正在创建打印页面 ...");
            stop.BeginLoop();

            m_webExternalHost = new WebExternalHost();
            m_webExternalHost.Initial(this.MainForm, null);
            m_webExternalHost.IsInLoop = true;

            this.GetSummary += new GetSummaryEventHandler(OperLogForm_GetSummary);
            try
            {
                stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);
                int i = 0;
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    Application.DoEvents();

                    if (stop != null && stop.State != 0)
                    {
                        strError = "用户中断";
                        goto ERROR1;
                    }

                    OperLogItemInfo info = (OperLogItemInfo)item.Tag;

                    string strLogFileName = ListViewUtil.GetItemText(item, COLUMN_FILENAME);
                    string strIndex = ListViewUtil.GetItemText(item, COLUMN_INDEX);

                    string strXml = "";
                    // 从服务器获得
                    // return:
                    //      -1  出错
                    //      0   正常
                    //      1   用户中断
                    int nRet = GetXml(item,
            out strXml,
            out strError);
                    if (nRet == 1)
                        return;
                    if (nRet == -1)

                        goto ERROR1;

                    Global.SetXmlString(this.webBrowser_xml,
    strXml,
    this.MainForm.DataDir,
    "operlogexml");

                    string strHtml = "";
                    // 创建解释日志记录内容的 HTML 字符串
                    // return:
                    //      -1  出错
                    //      0   成功
                    //      1   未知的操作类型
                    nRet = GetHtmlString(strXml,
                        false,
                        out strHtml,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 1)
                        strHtml = strError;

                    StreamUtil.WriteText(strFilename,
        "<p class='record_title'>" + strLogFileName + " : " + strIndex + "</p>" + strHtml);

                    stop.SetProgressValue(i + 1);
                    i++;
                }
            }
            finally
            {
                this.GetSummary -= new GetSummaryEventHandler(OperLogForm_GetSummary);
                if (m_webExternalHost != null)
                {
                    m_webExternalHost.IsInLoop = false;
                    m_webExternalHost.Destroy();
                    m_webExternalHost = null;
                }

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStopPrint);
                stop.Initial("打印页面创建完成");
                stop.HideProgress();

                if (stop != null) // 脱离关联
                {
                    stop.Unregister();	// 和容器关联
                    stop = null;
                }
            }

            StreamUtil.WriteText(strFilename,
"</body></html>");

            // TODO: 浏览器控件连接javascript host
            HtmlPrintForm printform = new HtmlPrintForm();

            printform.Text = "打印解释内容";
            printform.MainForm = this.MainForm;
            printform.Filenames = filenames;

            this.MainForm.AppInfo.LinkFormState(printform, "operlogform_printform_state");
            printform.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(printform);

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Ejemplo n.º 3
0
        void PrintList(
            string strTitle,
            List<ListViewItem> items,
            List<ListViewItem> outof_items)
        {
            string strError = "";

            // 创建一个html文件,并显示在HtmlPrintForm中。
            EnableControls(false);
            List<string> filenames = null;
            try
            {
                // Debug.Assert(false, "");

                // 构造html页面
                int nRet = BuildHtml(
                    items,
                    outof_items,
                    out filenames,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                HtmlPrintForm printform = new HtmlPrintForm();

                printform.Text = "打印" + strTitle;
                printform.MainForm = this.MainForm;
                printform.Filenames = filenames;

                this.MainForm.AppInfo.LinkFormState(printform, "printform_state");
                printform.ShowDialog(this);
                this.MainForm.AppInfo.UnlinkFormState(printform);
            }
            finally
            {
                if (filenames != null)
                    Global.DeleteFiles(filenames);
                EnableControls(true);
            }

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Ejemplo n.º 4
0
        private void button_print_Click(object sender, EventArgs e)
        {
            if (this.objStatis == null)
            {
                MessageBox.Show(this, "尚未执行统计,无法打印");
                return;
            }

            HtmlPrintForm printform = new HtmlPrintForm();

            printform.Text = "打印统计结果";
            printform.MainForm = this.MainForm;

            Debug.Assert(this.objStatis != null, "");
            printform.Filenames = this.objStatis.OutputFileNames;
            this.MainForm.AppInfo.LinkFormState(printform, "printform_state");
            printform.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(printform);
        }
Ejemplo n.º 5
0
        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);
        }