Beispiel #1
0
        // 准备脚本环境
        static int PrepareMarcFilter(
            IWin32Window owner,
            string strDataDir,
            string strFilterFileName,
            ColumnFilterDocument filter,
            out string strError)
        {
            strError = "";

            if (FileUtil.FileExist(strFilterFileName) == false)
            {
                strError = "文件 '" + strFilterFileName + "' 不存在";
                goto ERROR1;
            }

            string strWarning = "";

            string strLibPaths = "\"" + strDataDir + "\"";

            filter.strOtherDef = "dp2Circulation.ColumnFilterHost Host = null;";
            filter.strPreInitial = " ColumnFilterDocument doc = (ColumnFilterDocument)this.Document;\r\n";
            filter.strPreInitial += " Host = doc.Host;\r\n";
            /*
           filter.strOtherDef = entryClassType.FullName + " Host = null;";

           filter.strPreInitial = " ColumnFilterDocument doc = (ColumnFilterDocument)this.Document;\r\n";
           filter.strPreInitial += " Host = ("
               + entryClassType.FullName + ")doc.Host;\r\n";
            * */

            try
            {
                filter.Load(strFilterFileName);
            }
            catch (Exception ex)
            {
                strError = "文件 " + strFilterFileName + " 装载到MarcFilter时发生错误: " + ex.Message;
                goto ERROR1;
            }

            string strCode = "";    // c#代码
            int nRet = filter.BuildScriptFile(out strCode,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            // 一些必要的链接库
            string[] saAddRef1 = {
										 Environment.CurrentDirectory + "\\digitalplatform.marcdom.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.marckernel.dll",
									Environment.CurrentDirectory + "\\digitalplatform.marcquery.dll",
										 //Environment.CurrentDirectory + "\\digitalplatform.rms.client.dll",
										 //Environment.CurrentDirectory + "\\digitalplatform.library.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.Text.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.IO.dll",
										 Environment.CurrentDirectory + "\\digitalplatform.Xml.dll",
										 // Environment.CurrentDirectory + "\\Interop.SHDocVw.dll",
										 Environment.CurrentDirectory + "\\dp2circulation.exe"
                };

            // fltx文件里显式增补的链接库
            string[] saAdditionalRef = filter.GetRefs();

            // 合并的链接库
            string[] saTotalFilterRef = new string[saAddRef1.Length + saAdditionalRef.Length];
            Array.Copy(saAddRef1, saTotalFilterRef, saAddRef1.Length);
            Array.Copy(saAdditionalRef, 0,
                saTotalFilterRef, saAddRef1.Length,
                saAdditionalRef.Length);

            Assembly assemblyFilter = null;

            // 创建Script的Assembly
            // 本函数内对saRef不再进行宏替换
            nRet = ScriptManager.CreateAssembly_1(strCode,
                saTotalFilterRef,
                strLibPaths,
                out assemblyFilter,
                out strError,
                out strWarning);
            if (nRet == -2)
                goto ERROR1;
            if (nRet == -1)
            {
                if (strWarning == "")
                {
                    goto ERROR1;
                }
                MessageBox.Show(owner, strWarning);
            }

            filter.Assembly = assemblyFilter;
            return 0;
        ERROR1:
            return -1;
        }
Beispiel #2
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);
        }
Beispiel #3
0
        void menu_quickFilterRecords_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选择要快速执行脚本的事项";
                goto ERROR1;
            }

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = "请指定 MARC 过滤器脚本文件";
            dlg.FileName = this.m_strUsedMarcFilterFilename;
            dlg.Filter = "MARC过滤器脚本文件 (*.fltx)|*.fltx|All files (*.*)|*.*";
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog() != DialogResult.OK)
                return;

            this.m_strUsedMarcFilterFilename = dlg.FileName;

            ColumnFilterDocument filter = new ColumnFilterDocument();

            nRet = PrepareMarcFilter(
                this,
                this.MainForm.DataDir,
                this.m_strUsedMarcFilterFilename,
                filter,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            LibraryChannel channel = this.GetChannel();

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在针对书目记录执行 .fltx 脚本 ...");
            stop.BeginLoop();

            this.EnableControls(false);

            this.listView_records.Enabled = false;
            try
            {
                if (stop != null)
                    stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);

                List<ListViewItem> items = new List<ListViewItem>();
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    if (string.IsNullOrEmpty(item.Text) == true)
                        continue;

                    items.Add(item);
                }

                ListViewBiblioLoader loader = new ListViewBiblioLoader(channel, // this.Channel,
                    stop,
                    items,
                    this.m_biblioTable);
                loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
                loader.Prompt += new MessagePromptEventHandler(loader_Prompt);

                int i = 0;
                foreach (LoaderItem item in loader)
                {
                    Application.DoEvents();	// 出让界面控制权

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

#if NO
                    string strRecPath = item.Text;

                    if (string.IsNullOrEmpty(strRecPath) == true)
                        continue;

                    if (stop != null)
                    {
                        stop.SetMessage("正在获取书目记录 " + strRecPath);
                        stop.SetProgressValue(i);
                    }

                    string[] results = null;
                    byte[] baTimestamp = null;
                    // 获得书目记录
                    long lRet = Channel.GetBiblioInfos(
                        stop,
                        strRecPath,
                    "",
                        new string[] { "xml" },   // formats
                        out results,
                        out baTimestamp,
                        out strError);
                    if (lRet == 0)
                        goto ERROR1;
                    if (lRet == -1)
                        goto ERROR1;

                    if (results == null || results.Length == 0)
                    {
                        strError = "results error";
                        goto ERROR1;
                    }

                    string strXml = results[0];
#endif
                    BiblioInfo info = item.BiblioInfo;

                    string strXml = "";
                    {
                        if (string.IsNullOrEmpty(info.NewXml) == false)
                            strXml = info.NewXml;
                        else
                            strXml = info.OldXml;
                    }

                    string strMARC = "";
                    string strMarcSyntax = "";
                    // 将XML格式转换为MARC格式
                    // 自动从数据记录中获得MARC语法
                    nRet = MarcUtil.Xml2Marc(strXml,
                        true,
                        null,
                        out strMarcSyntax,
                        out strMARC,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "XML转换到MARC记录时出错: " + strError;
                        goto ERROR1;
                    }

                    filter.Host = new ColumnFilterHost();
                    filter.Host.ColumnTable = new System.Collections.Hashtable();
                    nRet = filter.DoRecord(
    null,
    strMARC,
    strMarcSyntax,
    i,
    out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    this.MainForm.OperHistory.AppendHtml("<p>" + HttpUtility.HtmlEncode(item.BiblioInfo.RecPath) + "</p>");    // strRecPath
                    foreach (string key in filter.Host.ColumnTable.Keys)
                    {
                        string strHtml = "<p>" + HttpUtility.HtmlEncode(key + "=" + (string)filter.Host.ColumnTable[key]) + "</p>";
                        this.MainForm.OperHistory.AppendHtml(strHtml);
                    }

#if NO
                    if (nRet == -1)
                    {
                        DialogResult result = MessageBox.Show(this,
        "刷新浏览内容时出错: " + strError + "。\r\n\r\n是否继续刷新? (OK 刷新;Cancel 放弃刷新)",
        "BiblioSearchForm",
        MessageBoxButtons.OKCancel,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button1);
                        if (result == System.Windows.Forms.DialogResult.Cancel)
                            break;
                    }
#endif
                    i++;
                }
            }
            finally
            {
                this.listView_records.Enabled = true;

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;

                this.ReturnChannel(channel);

                this.EnableControls(true);
            }

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Beispiel #4
0
        // parameters:
        //      strMarcFilterFilePath   脚本文件名,或者脚本内容。如果是脚本内容,第一个字符应该确保为 '<'
        /// <summary>
        /// 准备 MARC 过滤器
        /// </summary>
        /// <param name="strMarcFilterFilePath">MARC过滤器 .fltx 文件名全路径</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错; 0: 成功</returns>
        public int PrepareMarcFilter(string strMarcFilterFilePath,
            out string strError)
        {
            strError = "";
            ColumnFilterDocument filter = null;

            this.ColumnTable = new Hashtable();
            // parameters:
            //      strFilterFileName   脚本文件名,或者脚本内容。如果是脚本内容,第一个字符应该确保为 '<'
            int nRet = PrepareMarcFilter(strMarcFilterFilePath,
                out filter,
                out strError);
            if (nRet == -1)
                return -1;

            //
            if (filter != null)
                this.AssemblyFilter = filter.Assembly;
            else
                this.AssemblyFilter = null;

            this.MarcFilter = filter;

            return 0;
        }