Ejemplo n.º 1
0
        // 获得一条MARC/XML记录
        // return:
        //      -1  error 包括not found
        //      0   found
        //      1   为诊断记录
        public int GetOneRecord(
            string strStyle,
            int nTest,
            string strPathParam,
            string strParameters,   // bool bHilightBrowseLine,
            out string strSavePath,
            out string strRecord,
            out string strXmlFragment,
            out string strOutStyle,
            out byte[] baTimestamp,
            out long lVersion,
            out DigitalPlatform.Z3950.Record record,
            out Encoding currrentEncoding,
            out LoginInfo logininfo,
            out string strError)
        {
            strXmlFragment   = "";
            strRecord        = "";
            record           = null;
            strError         = "";
            currrentEncoding = this.CurrentEncoding;
            baTimestamp      = null;
            strSavePath      = "";
            strOutStyle      = "marc";
            logininfo        = new LoginInfo();
            lVersion         = 0;

            // 防止重入
            if (m_bInSearch == true)
            {
                strError = "当前窗口正在被一个未结束的长操作使用,无法获得记录。请稍后再试。";
                return(-1);
            }

            if (strStyle != "marc" && strStyle != "xml")
            {
                strError = "DupForm只支持获取MARC格式记录和xml格式记录,不支持 '" + strStyle + "' 格式的记录";
                return(-1);
            }
            int nRet = 0;

            int    index        = -1;
            string strPath      = "";
            string strDirection = "";

            nRet = Global.ParsePathParam(strPathParam,
                                         out index,
                                         out strPath,
                                         out strDirection,
                                         out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            if (index == -1)
            {
                strError = "暂时不支持没有 index 的用法";
                return(-1);
            }

            bool bHilightBrowseLine = StringUtil.IsInList("hilight_browse_line", strParameters);

            if (index >= this.listView_browse.Items.Count)
            {
                strError = "越过结果集尾部";
                return(-1);
            }
            ListViewItem curItem = this.listView_browse.Items[index];

            if (bHilightBrowseLine == true)
            {
                // 修改listview中事项的选定状态
                for (int i = 0; i < this.listView_browse.SelectedItems.Count; i++)
                {
                    this.listView_browse.SelectedItems[i].Selected = false;
                }

                curItem.Selected = true;
                curItem.EnsureVisible();
            }

            string strPurePath   = curItem.Text;
            string strServerName = this.LibraryServerName;

            strPath = strPurePath + "@" + this.LibraryServerName;

            strSavePath = this.CurrentProtocol + ":" + strPath;

            // 拉上一个dp2检索窗,好办事
            dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

            if (dp2_searchform == null)
            {
                strError = "没有打开的dp2检索窗,无法GetOneRecordSyntax()";
                return(-1);
            }

            // 获得server url
            string strServerUrl = dp2_searchform.GetServerUrl(strServerName);

            if (strServerUrl == null)
            {
                strError = "没有找到服务器名 '" + strServerName + "' 对应的URL";
                return(-1);
            }

            this.Channel = this.Channels.GetChannel(strServerUrl);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在初始化浏览器组件 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {
                stop.SetMessage("正在装入书目记录 " + strPath + " ...");

                string[] formats = null;
                formats    = new string[1];
                formats[0] = "xml";

                string[] results = null;

                long lRet = Channel.GetBiblioInfos(
                    stop,
                    strPurePath,
                    "",
                    formats,
                    out results,
                    out baTimestamp,
                    out strError);
                if (lRet == 0)
                {
                    strError = "路径为 '" + strPath + "' 的书目记录没有找到 ...";
                    goto ERROR1;   // not found
                }

                if (lRet == -1)
                {
                    goto ERROR1;
                }

                // this.BiblioTimestamp = baTimestamp;

                if (results == null)
                {
                    strError = "results == null";
                    goto ERROR1;
                }
                if (results.Length != formats.Length)
                {
                    strError = "result.Length != formats.Length";
                    goto ERROR1;
                }

                string strXml = results[0];

                if (strStyle == "marc")
                {
                    string strMarcSyntax    = "";
                    string strOutMarcSyntax = "";
                    // 从数据记录中获得MARC格式
                    nRet = MarcUtil.Xml2Marc(strXml,
                                             true,
                                             strMarcSyntax,
                                             out strOutMarcSyntax,
                                             out strRecord,
                                             out strError);
                    if (nRet == -1)
                    {
                        strError = "XML转换到MARC记录时出错: " + strError;
                        goto ERROR1;
                    }


                    // 获得书目以外的其它XML片断
                    nRet = dp2SearchForm.GetXmlFragment(strXml,
                                                        out strXmlFragment,
                                                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                else
                {
                    strRecord   = strXml;
                    strOutStyle = strStyle;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
            return(0);

ERROR1:
            return(-1);
        }