コード例 #1
0
        // 加入一个浏览行
        public void AddBiblioBrowseLine(
            int nType,
            string strBiblioRecPath,
            string strBrowseText,
            RegisterBiblioInfo info,
            bool bAutoSetFocus)
        {
            if (this.dpTable_browseLines.InvokeRequired)
            {
                // 事件是在多线程上下文中触发的,需要 Invoke 显示信息
                this.BeginInvoke(new Action<int, string, string, RegisterBiblioInfo, bool>(AddBiblioBrowseLine),
                    nType,
                    strBiblioRecPath,
                    strBrowseText,
                    info,
                    bAutoSetFocus);
                return;
            }

            List<string> columns = StringUtil.SplitList(strBrowseText, '\t');
            DpRow row = new DpRow();

            // 序号
            DpCell cell = new DpCell();
            cell.Alignment = DpTextAlignment.Far;
            cell.Font = new Font(this.Font.FontFamily, this.Font.Size * 2);
            cell.Text = (this.dpTable_browseLines.Rows.Count + 1).ToString();
            {
                cell.ImageIndex = nType;
                if (nType == TYPE_ERROR)
                    cell.BackColor = Color.Red;
                else if (nType == TYPE_INFO)
                    cell.BackColor = Color.Yellow;
            }
            row.Add(cell);

            // 记录路径
            cell = new DpCell();
            cell.Text = strBiblioRecPath;
            row.Add(cell);

            // 封面
            cell = new DpCell();
            cell.Text = "";
            row.Add(cell);

            foreach (string s in columns)
            {
                cell = new DpCell();
                cell.Text = s;
                row.Add(cell);
            }

            row.Tag = info;
            this.dpTable_browseLines.Rows.Add(row);

            // 当插入第一行的时候,顺便选中它
            if (this.dpTable_browseLines.Rows.Count == 1)
            {
                if (bAutoSetFocus)
                    this.dpTable_browseLines.Focus();
                row.Selected = true;
                this.dpTable_browseLines.FocusedItem = row;
            }

            PrepareCoverImage(row);
        }
コード例 #2
0
        void MessageHub_SearchResponseEvent(object sender, SearchResponseEventArgs e)
        {
            if (e.SsearchID != _searchParam._searchID)
                return;
            if (e.ResultCount == -1 && e.Start == -1)
            {
                // 检索过程结束
                _searchParam._searchComplete = true;
                return;
            }
            string strError = "";

            if (e.ResultCount == -1)
            {
                strError = e.ErrorInfo;
                goto ERROR1;
            }

            // TODO: 注意来自共享网络的图书馆名不能和 servers.xml 中的名字冲突。另外需要检查,不同的 UID,图书馆名字不能相同,如果发生冲突,则需要给分配 ..1 ..2 这样的编号以示区别
            // 需要一直保存一个 UID 到图书馆命的对照表在内存备用
            // TODO: 来自共享网络的记录,图标或 @ 后面的名字应该有明显的形态区别
            foreach(BiblioRecord record in e.Records)
            {
                string strXml = record.Data;

                string strMarcSyntax = "";
                string strBrowseText = "";
                string strColumnTitles = "";
                int nRet = BuildBrowseText(strXml,
out strBrowseText,
out strMarcSyntax,
out strColumnTitles,
out strError);
                if (nRet == -1)
                    goto ERROR1;

                int image_index = -1;
                image_index = TYPE_CLOUD;

                RegisterBiblioInfo info = new RegisterBiblioInfo();
                info.OldXml = strXml;   // strMARC;
                info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                info.RecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false? record.LibraryName : record.LibraryUID);
                info.MarcSyntax = strMarcSyntax;
                AddBiblioBrowseLine(
                    image_index,    // -1,
                    info.RecPath,
                    strBrowseText,
                    info,
                    _searchParam._autoSetFocus);
                _searchParam._searchCount++;
            }

            return;
        ERROR1:
            // 加入一个文本行
            AddBiblioBrowseLine(
                TYPE_ERROR,
                "", // item.RecPath,
                strError,
                null,
                false);
        }
コード例 #3
0
        // 针对 dp2library 服务器进行检索
        // parameters:
        //  
        // return:
        //      -1  出错
        //      >=0 命中的记录数
        int SearchLineDp2library(
            string strQueryWord,
            string strFrom,
            AccountInfo account,
            bool bAutoSetFocus,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            string strFromStyle = "";

            if (string.IsNullOrEmpty(strFrom) == true)
                strFrom = "ISBN";

            if (strFrom == "书名" || strFrom == "题名")
                strFromStyle = "title";
            else if (strFrom == "作者" || strFrom == "著者" || strFrom == "责任者")
                strFromStyle = "contributor";
            else if (strFrom == "出版社" || strFrom == "出版者")
                strFromStyle = "publisher";
            else if (strFrom == "出版日期")
                strFromStyle = "publishtime";
            else if (strFrom == "主题词")
                strFromStyle = "subject";

            if (string.IsNullOrEmpty(strFromStyle) == true)
            {
                try
                {
                    strFromStyle = this.MainForm.GetBiblioFromStyle(strFrom);
                }
                catch (Exception ex)
                {
                    strError = ex.Message;
                    goto ERROR1;
                }

                if (String.IsNullOrEmpty(strFromStyle) == true)
                {
                    strError = "GetFromStyle()没有找到 '" + strFrom + "' 对应的 style 字符串";
                    goto ERROR1;
                }
            }

            _channel = _base.GetChannel(account.ServerUrl, account.UserName);
            _channel.Timeout = new TimeSpan(0, 0, 5);   // 超时值为 5 秒
            _channel.Idle += _channel_Idle;
            try
            {
                string strMatchStyle = "left";  // BiblioSearchForm.GetCurrentMatchStyle(this.comboBox_matchStyle.Text);
                if (string.IsNullOrEmpty(strQueryWord) == true)
                {
                    if (strMatchStyle == "null")
                    {
                        strQueryWord = "";

                        // 专门检索空值
                        strMatchStyle = "exact";
                    }
                    else
                    {
                        // 为了在检索词为空的时候,检索出全部的记录
                        strMatchStyle = "left";
                    }
                }
                else
                {
                    if (strMatchStyle == "null")
                    {
                        strError = "检索空值的时候,请保持检索词为空";
                        goto ERROR1;
                    }
                }

                ServerInfo server_info = null;

                //if (line != null)
                //    line.BiblioSummary = "正在获取服务器 " + account.ServerName + " 的配置信息 ...";
                this.ShowMessage("正在获取服务器 " + account.ServerName + " 的配置信息 ...", 
                    "progress", false);

                // 准备服务器信息
                nRet = _base.GetServerInfo(
                    _channel,
                    account,
                    out server_info,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;    // 可以不报错 ?

                this.ShowMessage("正在针对 " + account.ServerName + " \r\n检索 " + strQueryWord + " ...",
                    "progress", false);

                string strQueryXml = "";
                long lRet = _channel.SearchBiblio(Progress,
                    server_info == null ? "<全部>" : server_info.GetBiblioDbNames(),    // "<全部>",
                    strQueryWord,   // this.textBox_queryWord.Text,
                    1000,
                    strFromStyle,
                    strMatchStyle,
                    this.Lang,
                    null,   // strResultSetName
                    "",    // strSearchStyle
                    "", // strOutputStyle
                    out strQueryXml,
                    out strError);
                if (lRet == -1)
                {
                    strError = "针对服务器 '" + account.ServerName + "' 检索出错: " + strError;
                    goto ERROR1;
                }
                if (lRet == 0)
                {
                    strError = "没有命中";
                    return 0;
                }

                // 装入浏览格式
                long lHitCount = lRet;

                long lStart = 0;
                long lCount = lHitCount;
                DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                string strStyle = "id";

                List<string> biblio_recpaths = new List<string>();
                // 装入浏览格式
                for (; ; )
                {
                    if (this.Progress != null && this.Progress.State != 0)
                    {
                        break;
                    }

                    lRet = _channel.GetSearchResult(
                        this.Progress,
                        null,   // strResultSetName
                        lStart,
                        lCount,
                        strStyle, // bOutputKeyCount == true ? "keycount" : "id,cols",
                        this.Lang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条," + strError;
                        goto ERROR1;
                    }

                    if (lRet == 0)
                        break;

                    // 处理浏览结果

                    foreach (DigitalPlatform.CirculationClient.localhost.Record searchresult in searchresults)
                    {
                        biblio_recpaths.Add(searchresult.Path);
                    }

                    {
                        // 获得书目记录
                        BiblioLoader loader = new BiblioLoader();
                        loader.Channel = _channel;
                        loader.Stop = this.Progress;
                        loader.Format = "xml";
                        loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp;
                        loader.RecPaths = biblio_recpaths;

                        try
                        {
                            int i = 0;
                            foreach (BiblioItem item in loader)
                            {
                                if (string.IsNullOrEmpty(item.ErrorInfo) == false)
                                {
                                    AddBiblioBrowseLine(
                                        TYPE_ERROR,
                                        item.RecPath,
                                        item.ErrorInfo,
                                        null,
                                        false);
                                    i++;
                                    continue;
                                }

                                string strXml = item.Content;

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

                                nRet = BuildMarcBrowseText(
                                    strMarcSyntax,
                                    strMARC,
                                    out strBrowseText,
                                    out strError);
                                if (nRet == -1)
                                {
                                    strError = "MARC记录转换到浏览格式时出错: " + strError;
                                    goto ERROR1;
                                }
#endif
                                nRet = BuildBrowseText(strXml,
            out strBrowseText,
            out strMarcSyntax,
            out strColumnTitles,
            out strError);
                                if (nRet == -1)
                                    goto ERROR1;

                                int image_index = -1;
                                if (account.IsLocalServer == false)
                                    image_index = TYPE_CLOUD;

                                RegisterBiblioInfo info = new RegisterBiblioInfo();
                                info.OldXml = strXml;   // strMARC;
                                info.Timestamp = item.Timestamp;
                                info.RecPath = item.RecPath + "@" + account.ServerName;
                                info.MarcSyntax = strMarcSyntax;
                                AddBiblioBrowseLine(
                                    image_index,    // -1,
                                    info.RecPath,
                                    strBrowseText,
                                    info,
                                    bAutoSetFocus);
                                i++;
                            }
                        }
                        catch (Exception ex)
                        {
                            strError = ex.Message;
                            goto ERROR1;
                        }

                        // lIndex += biblio_recpaths.Count;
                        biblio_recpaths.Clear();
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }

                return (int)lHitCount;
            }
            finally
            {
                _channel.Idle -= _channel_Idle;
                _base.ReturnChannel(_channel);
                _channel = null;
                this.ClearMessage();
            }

        ERROR1:
            AddBiblioBrowseLine(strError, TYPE_ERROR, bAutoSetFocus);
            return -1;
        }
コード例 #4
0
        // 加入一个浏览行
        public void AddBiblioBrowseLine(
            int nType,
            string strBiblioRecPath,
            string strBrowseText,
            RegisterBiblioInfo info)
        {
            if (this.dpTable_browseLines.InvokeRequired)
            {
                // 事件是在多线程上下文中触发的,需要 Invoke 显示信息
                this.BeginInvoke(new Action<int, string, string, RegisterBiblioInfo>(AddBiblioBrowseLine),
                    nType,
                    strBiblioRecPath,
                    strBrowseText,
                    info);
                return;
            }

            List<string> columns = StringUtil.SplitList(strBrowseText, '\t');
            DpRow row = new DpRow();

            DpCell cell = new DpCell();
            cell.Text = (this.dpTable_browseLines.Rows.Count + 1).ToString();
            {
                cell.ImageIndex = nType;
                if (nType == TYPE_ERROR)
                    cell.BackColor = Color.Red;
                else if (nType == TYPE_INFO)
                    cell.BackColor = Color.Yellow;
            }
            row.Add(cell);

            cell = new DpCell();
            cell.Text = strBiblioRecPath;
            row.Add(cell);

            foreach (string s in columns)
            {
                cell = new DpCell();
                cell.Text = s;
                row.Add(cell);
            }

            row.Tag = info;
            this.dpTable_browseLines.Rows.Add(row);

            PrepareCoverImage(row);
        }
コード例 #5
0
        // 针对亚马逊服务器检索,装入一个浏览行的回调函数
        int appendBrowseLine(string strRecPath,
            string strRecord,
            object param,
            bool bAutoSetFocus,
            out string strError)
        {
            strError = "";

            // RegisterLine line = param as RegisterLine;

            XmlDocument dom = new XmlDocument();
            dom.LoadXml(strRecord);

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
            nsmgr.AddNamespace("amazon", AmazonSearch.NAMESPACE);

            List<string> cols = null;
            string strASIN = "";
            string strCoverImageUrl = "";
            int nRet = AmazonSearch.ParseItemXml(dom.DocumentElement,
                nsmgr,
                out strASIN,
                out strCoverImageUrl,
                out cols,
                out strError);
            if (nRet == -1)
                return -1;

            string strMARC = "";
            // 将亚马逊 XML 格式转换为 UNIMARC 格式
            nRet = AmazonSearch.AmazonXmlToUNIMARC(dom.DocumentElement,
                out strMARC,
                out strError);
            if (nRet == -1)
                return -1;

            string strXml = "";
            nRet = MarcUtil.Marc2Xml(strMARC,
    "unimarc",
    out strXml,
    out strError);
            if (nRet == -1)
                return -1;

            RegisterBiblioInfo info = new RegisterBiblioInfo();
            info.OldXml = strXml;   //  strMARC;
            info.Timestamp = null;
            info.RecPath = strASIN + "@" + _base.CurrentAccount.ServerName;
            info.MarcSyntax = "unimarc";
            AddBiblioBrowseLine(
                TYPE_AMAZON,  // -1,
                info.RecPath,
                StringUtil.MakePathList(cols, "\t"),
                info,
                bAutoSetFocus);

            return 0;
        }
コード例 #6
0
        int SetBiblio(RegisterBiblioInfo info, 
            bool bAutoSetFocus,
            out string strError)
        {
            strError = "";

            string strStartText = info.RecPath;

            string strStartServerName = "";
            string strStartRecPath = "";
            StringUtil.ParseTwoPart(info.RecPath, "@", out strStartRecPath, out strStartServerName);

            // 给书目记录一个本地路径,用于后面可能发生的保存操作
            string strServerName = "";
            string strBiblioRecPath = "";
            bool bAllowCopy = true;

            AccountInfo _currentAccount = _base.GetAccountInfo(strStartServerName, false);
            if (_currentAccount == null)
            {
                //strError = "服务器名 '" + strStartServerName + "' 没有配置";
                //return -1;
            }
            else
            {
                if (_currentAccount.IsLocalServer == false)
                    bAllowCopy = true;
                else
                    bAllowCopy = false;
            }

            // 根据书目记录的路径,匹配适当的目标
            // return:
            //      -1  出错
            //      0   没有找到
            //      1   找到
            int nRet = GetTargetInfo(
                bAllowCopy,
                strStartServerName,
                strStartRecPath,
                out strServerName,
                out strBiblioRecPath);
            if (nRet == -1)
                return -1;
            if (nRet == 0)
            {
                // strError = "来自服务器 '" + this._biblio.ServerName + "' 的书目记录 '" + this._biblio.BiblioRecPath + "' 没有找到匹配的保存目标";
                strServerName = strStartServerName;
                strBiblioRecPath = strStartRecPath;
            }

            info.RecPath = strBiblioRecPath + "@" + strServerName;

            this.toolStripLabel_biblioSource.Text = strStartText + " --> " + info.RecPath;

            OnHiddenFieldsChanged(info.MarcSyntax);

            nRet = this._biblio.SetBiblio(info, bAutoSetFocus, out strError);
            if (nRet == -1)
                return -1;
            {
                if (this._genData != null
    && this.MainForm.PanelFixedVisible == true
    && this._biblio != null)
                    this._genData.AutoGenerate(this.easyMarcControl1,
                        new GenerateDataEventArgs(),
                        this._biblio.BiblioRecPath,
                        true);
            }

            return 0;
        }
コード例 #7
0
        // 构造一条空白书目记录
        RegisterBiblioInfo BuildBlankBiblioInfo(
            string strRecord,
            string strFrom,
            string strValue)
        {
#if NO
            // 获得一个可以保存新书目记录的服务器地址和书目库名
            string strServerName = "";
            string strBiblioDbName = "";
            // 寻找一个可以创建新书目记录的数据库信息
            // return:
            //      false 没有找到
            //      ture 找到
            GetTargetDatabaseInfo(out strServerName,
                out strBiblioDbName);
#endif

            // 装入一条空白书目记录
            RegisterBiblioInfo info = new RegisterBiblioInfo();

#if NO
            if (string.IsNullOrEmpty(strBiblioDbName) == false)
                info.RecPath = strBiblioDbName + "/?@" + strServerName; 
#endif

            string strISBN = "";
            string strTitle = "";
            string strAuthor = "";
            string strPublisher = "";

            strFrom = strFrom.ToLower();

            if (strFrom == "isbn")
                strISBN = strValue;
            if (strFrom == "书名" || strFrom == "题名")
                strTitle = strValue;
            if (strFrom == "作者" || strFrom == "著者" || strFrom == "责任者")
                strAuthor = strValue;
            if (strFrom == "出版者" || strFrom == "出版社")
                strPublisher = strValue;

            info.MarcSyntax = "unimarc";
            MarcRecord record = new MarcRecord(strRecord);
            if (string.IsNullOrEmpty(strRecord) == true)
            {
                record.add(new MarcField('$', "010  $a" + strISBN + "$dCNY??"));
                record.add(new MarcField('$', "2001 $a"+strTitle+"$f"+strAuthor));
                record.add(new MarcField('$', "210  $a$c"+strPublisher+"$d"));
                record.add(new MarcField('$', "215  $a$d??cm"));
                record.add(new MarcField('$', "690  $a"));
                record.add(new MarcField('$', "701  $a" + strAuthor));

                // record.Header.ForceUNIMARCHeader();
                record.Header[0, 24] = "?????nam0 22?????3i 45  ";
            }
            else
            {
                record.setFirstSubfield("010", "a", strISBN);
                record.setFirstSubfield("200", "a", strTitle);
                record.setFirstSubfield("200", "f", strAuthor);
                record.setFirstSubfield("210", "c", strPublisher);
                record.setFirstSubfield("701", "a", strAuthor);
#if NO
                if (record.select("field[@name='010']").count == 0)
                    record.ChildNodes.insertSequence(new MarcField('$', "010  $a" + strISBN + "$dCNY??"));
                else if (record.select("field[@name='010']/subfield[@name='a']").count == 0)
                    (record.select("field[@name='010']")[0] as MarcField).ChildNodes.insertSequence(new MarcSubfield("a", strISBN));
                else
                    record.select("field[@name='010']/subfield[@name='a']")[0].Content = strISBN;
#endif
            }

            // info.OldXml = record.Text;

            string strError = "";
            string strXml = "";
            int nRet = MarcUtil.Marc2Xml(record.Text,
                info.MarcSyntax,
                out strXml,
                out strError);
            if (nRet == -1)
                throw new Exception(strError);

            info.OldXml = strXml;
            return info;
        }
コード例 #8
0
ファイル: BiblioSearchForm.cs プロジェクト: paopaofeng/dp2
        void MessageHub_SearchResponseEvent(object sender, SearchResponseEventArgs e)
        {
            if (e.SsearchID != _searchParam._searchID)
                return;
            if (e.ResultCount == -1 && e.Start == -1)
            {
                // 检索过程结束
                _searchParam._searchComplete = true;
                return;
            }
            string strError = "";

            if (e.ResultCount == -1)
            {
                strError = e.ErrorInfo;
                goto ERROR1;
            }

            // TODO: 注意来自共享网络的图书馆名不能和 servers.xml 中的名字冲突。另外需要检查,不同的 UID,图书馆名字不能相同,如果发生冲突,则需要给分配 ..1 ..2 这样的编号以示区别
            // 需要一直保存一个 UID 到图书馆命的对照表在内存备用
            // TODO: 来自共享网络的记录,图标或 @ 后面的名字应该有明显的形态区别
            foreach (BiblioRecord record in e.Records)
            {
                string strXml = record.Data;

                string strMarcSyntax = "";
                string strBrowseText = "";
                string strColumnTitles = "";
                int nRet = BuildBrowseText(strXml,
out strBrowseText,
out strMarcSyntax,
out strColumnTitles,
out strError);
                if (nRet == -1)
                    goto ERROR1;

                string strRecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false ? record.LibraryName : record.LibraryUID);

#if NO
                string strDbName = ListViewProperty.GetDbName(strRecPath);
                _browseTitleTable[strDbName] = strColumnTitles;
#endif
                _browseTitleTable[strMarcSyntax] = strColumnTitles;

                // 将书目记录放入 m_biblioTable
                {
                    BiblioInfo info = new BiblioInfo();
                    info.OldXml = strXml;
                    info.RecPath = strRecPath;
                    info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                    info.Format = strMarcSyntax;
                    this.m_biblioTable[strRecPath] = info;
                }

                List<string> column_list = StringUtil.SplitList(strBrowseText, '\t');
                string[] cols = new string[column_list.Count];
                column_list.CopyTo(cols);

                ListViewItem item = null;
                this.Invoke((Action)(() =>
                {
                    item = Global.AppendNewLine(
    this.listView_records,
    strRecPath,
    cols);
                }
                ));

                if (item != null)
                    item.BackColor = Color.LightGreen;

#if NO
                RegisterBiblioInfo info = new RegisterBiblioInfo();
                info.OldXml = strXml;   // strMARC;
                info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                info.RecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false ? record.LibraryName : record.LibraryUID);
                info.MarcSyntax = strMarcSyntax;
#endif
                _searchParam._searchCount++;
            }

            return;
        ERROR1:
            // 加入一个文本行
            {
                string[] cols = new string[1];
                cols[0] = strError;
                this.Invoke((Action)(() =>
                {

                    ListViewItem item = Global.AppendNewLine(
        this.listView_records,
        "error",
        cols);
                }
    ));
            }
        }
コード例 #9
0
ファイル: BiblioSearchForm.cs プロジェクト: renyh1013/dp2
        void FillList(long lStart,
            string strLibraryName,
            IList<DigitalPlatform.MessageClient.Record> Records)
        {
            string strError = "";

            // lock (_searchParam)
            {
                // TODO: 注意来自共享网络的图书馆名不能和 servers.xml 中的名字冲突。另外需要检查,不同的 UID,图书馆名字不能相同,如果发生冲突,则需要给分配 ..1 ..2 这样的编号以示区别
                // 需要一直保存一个 UID 到图书馆命的对照表在内存备用
                // TODO: 来自共享网络的记录,图标或 @ 后面的名字应该有明显的形态区别
                foreach (DigitalPlatform.MessageClient.Record record in Records)
                {
                    MessageHub.DecodeRecord(record, _searchParam._serverPushEncoding);

                    string strRecPath = record.RecPath + "@" + strLibraryName;

                    // 校验一下 MD5
                    if (string.IsNullOrEmpty(record.MD5) == false)
                    {
                        string strMD5 = StringUtil.GetMd5(record.Data);
                        if (record.MD5 != strMD5)
                        {
                            strError = "dp2Circulation : 记录 '" + strRecPath + "' Data 的 MD5 校验出现异常";
                            AddErrorLine(strError);
                            continue;
                        }
                    }

                    string strXml = record.Data;

                    string strMarcSyntax = "";
                    string strBrowseText = "";
                    string strColumnTitles = "";
                    int nRet = BuildBrowseText(strXml,
    out strBrowseText,
    out strMarcSyntax,
    out strColumnTitles,
    out strError);
                    if (nRet == -1)
                    {
                        AddErrorLine("记录 " + strRecPath + " 创建浏览格式时出: " + strError);
                        continue;
                    }

#if NO
                    // string strRecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false ? record.LibraryName : record.LibraryUID);
                    string strRecPath = // "lStart="+lStart.ToString() + " " + i + "/"+ Records.Count + " " +
                        _searchParam.BuildNamePath(record.RecPath);
#endif

#if NO
                string strDbName = ListViewProperty.GetDbName(strRecPath);
                _browseTitleTable[strDbName] = strColumnTitles;
#endif
                    _browseTitleTable[strMarcSyntax] = strColumnTitles;

                    // 将书目记录放入 m_biblioTable
                    {
                        BiblioInfo info = new BiblioInfo();
                        info.OldXml = strXml;
                        info.RecPath = strRecPath;
                        info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                        info.Format = strMarcSyntax;
                        lock (this.m_biblioTable)
                        {
                            this.m_biblioTable[strRecPath] = info;
                        }
                    }

                    List<string> column_list = StringUtil.SplitList(strBrowseText, '\t');
                    string[] cols = new string[column_list.Count];
                    column_list.CopyTo(cols);

                    ListViewItem item = null;
                    this.Invoke((Action)(() =>
                    {
                        item = Global.AppendNewLine(
        this.listView_records,
        strRecPath,
        cols);
                    }
                    ));

                    if (item != null)
                        item.BackColor = Color.LightGreen;

#if NO
                RegisterBiblioInfo info = new RegisterBiblioInfo();
                info.OldXml = strXml;   // strMARC;
                info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                info.RecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false ? record.LibraryName : record.LibraryUID);
                info.MarcSyntax = strMarcSyntax;
#endif
                }

                // Debug.Assert(e.Start == _searchParam._searchCount, "");
                return;
            }

            return;
#if NO
        ERROR1:
            AddErrorLine(strError);
#endif
        }
コード例 #10
0
ファイル: EntityRegisterWizard.cs プロジェクト: renyh1013/dp2
        void FillList(long lStart,
    string strLibraryName,
    IList<DigitalPlatform.MessageClient.Record> Records)
        {
            string strError = "";

            {
                foreach (DigitalPlatform.MessageClient.Record record in Records)
                {
                    MessageHub.DecodeRecord(record, _searchParam._serverPushEncoding);

                    string strRecPath = record.RecPath + "@" + strLibraryName;
                    string strXml = record.Data;

                    string strMarcSyntax = "";
                    string strBrowseText = "";
                    string strColumnTitles = "";
                    int nRet = BuildBrowseText(strXml,
    out strBrowseText,
    out strMarcSyntax,
    out strColumnTitles,
    out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    int image_index = -1;
                    image_index = TYPE_CLOUD;

                    RegisterBiblioInfo info = new RegisterBiblioInfo();
                    info.OldXml = strXml;   // strMARC;
                    info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                    // info.RecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false ? record.LibraryName : record.LibraryUID);
                    info.RecPath = strRecPath;
                    info.MarcSyntax = strMarcSyntax;

                    this.Invoke((Action)(() =>
                    {
                        AddBiblioBrowseLine(
                            image_index,    // -1,
                            info.RecPath,
                            strBrowseText,
                            info,
                            _searchParam._autoSetFocus);
                    }
));

                }
            }
            return;
        ERROR1:
            this.Invoke((Action)(() =>
            {
                AddBiblioBrowseLine(
TYPE_ERROR,
"", // item.RecPath,
strError,
null,
false);
            }
));
        }
コード例 #11
0
ファイル: EntityRegisterWizard.cs プロジェクト: renyh1013/dp2
        // 给一条书目记录添加默认字段
        // parameters:
        //      strDefaultRecord   包含默认字段的一条 MARC 记录
        void AddFields(
            RegisterBiblioInfo info,
            string strDefaultRecord)
        {
            string strError = "";
            string strMARC = "";
            string strMarcSyntax = "";
            // 将XML格式转换为MARC格式
            // 自动从数据记录中获得MARC语法
            int nRet = MarcUtil.Xml2Marc(info.OldXml,
                true,
                null,
                out strMarcSyntax,
                out strMARC,
                out strError);
            if (nRet == -1)
            {
                Debug.Assert(false, "");
                return;
            }

            MarcRecord default_record = new MarcRecord(strDefaultRecord);
            MarcRecord record = new MarcRecord(strMARC);
            bool bChanged = true;
            foreach (MarcField field in default_record.ChildNodes)
            {
                if (record.select("field[@name='" + field.Name + "']").count > 0)
                    continue;   // 已经存在的字段不会加入
                record.ChildNodes.insertSequence(field, InsertSequenceStyle.PreferTail);
                bChanged = true;
            }

            if (bChanged == true)
            {
                string strXml = "";
                nRet = MarcUtil.Marc2Xml(record.Text,
                    info.MarcSyntax,
                    out strXml,
                    out strError);
                if (nRet == -1)
                    throw new Exception(strError);

                info.OldXml = strXml;
            }
        }
コード例 #12
0
ファイル: EntityRegisterWizard.cs プロジェクト: renyh1013/dp2
        void MessageHub_SearchResponseEvent(object sender, SearchResponseEventArgs e)
        {
            if (e.TaskID != _searchParam._searchID)
                return;

            if (e.ResultCount == -1 && e.Start == -1)
            {
                // 检索过程结束
                _searchParam._searchComplete = true;
                _searchParam._searchCount = (int)_searchParam._manager.GetTotalCount();
                return;
            }

            string strError = "";

            if (e.ResultCount == -1)
            {
                strError = e.ErrorInfo;
                goto ERROR1;
            }

            List<string> array = StringUtil.ParseTwoPart(e.LibraryUID, "|");
            string strLibraryName = array[0];

            // 标记结束一个检索目标
            // return:
            //      0   尚未结束
            //      1   结束
            //      2   全部结束
            int nRet = _searchParam._manager.CompleteTarget(e.LibraryUID,
                e.ResultCount,
                e.Records == null ? 0 : e.Records.Count);

            _searchParam._searchCount = (int)_searchParam._manager.GetTotalCount();

            if (nRet == 2)
                _searchParam._searchComplete = true;

            // 单独给一个线程来执行
            Task.Factory.StartNew(() => FillList(e.Start, strLibraryName, e.Records));


#if NO
            // TODO: 注意来自共享网络的图书馆名不能和 servers.xml 中的名字冲突。另外需要检查,不同的 UID,图书馆名字不能相同,如果发生冲突,则需要给分配 ..1 ..2 这样的编号以示区别
            // 需要一直保存一个 UID 到图书馆命的对照表在内存备用
            // TODO: 来自共享网络的记录,图标或 @ 后面的名字应该有明显的形态区别
            foreach (DigitalPlatform.MessageClient.Record record in e.Records)
            {
                MessageHub.DecodeRecord(record, _searchParam._serverPushEncoding);

                string strXml = record.Data;

                string strMarcSyntax = "";
                string strBrowseText = "";
                string strColumnTitles = "";
                int nRet = BuildBrowseText(strXml,
out strBrowseText,
out strMarcSyntax,
out strColumnTitles,
out strError);
                if (nRet == -1)
                    goto ERROR1;

                int image_index = -1;
                image_index = TYPE_CLOUD;

                RegisterBiblioInfo info = new RegisterBiblioInfo();
                info.OldXml = strXml;   // strMARC;
                info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                // info.RecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false ? record.LibraryName : record.LibraryUID);
                info.RecPath = record.RecPath;
                info.MarcSyntax = strMarcSyntax;
                AddBiblioBrowseLine(
                    image_index,    // -1,
                    info.RecPath,
                    strBrowseText,
                    info,
                    _searchParam._autoSetFocus);
                _searchParam._searchCount++;
            }
#endif
            return;
        ERROR1:
            // 加入一个文本行
            AddBiblioBrowseLine(
                TYPE_ERROR,
                "", // item.RecPath,
                strError,
                null,
                false);
        }
コード例 #13
0
ファイル: BiblioAndEntities.cs プロジェクト: renyh1013/dp2
 // 拷贝构造
 public RegisterBiblioInfo(RegisterBiblioInfo ref_obj)
 {
     this.RecPath = ref_obj.RecPath;
     this.OldXml = ref_obj.OldXml;
     this.NewXml = ref_obj.NewXml;
     this.Timestamp = ref_obj.Timestamp;
     this.MarcSyntax = ref_obj.MarcSyntax;
 }
コード例 #14
0
ファイル: BiblioAndEntities.cs プロジェクト: renyh1013/dp2
        // 从列表中选择一条书目记录装入编辑模板
        // return:
        //      -1  出错
        //      0   放弃装入
        //      1   成功装入
        public int SetBiblio(
            RegisterBiblioInfo info,
            bool bAutoSetFocus,
            out string strError)
        {
            strError = "";

            if (this.BiblioChanged == true
                || this.EntitiesChanged == true)
            {
                string strParts = "";
                if (this.BiblioChanged)
                    strParts += "书目记录";
                if (this.EntitiesChanged)
                {
                    if (string.IsNullOrEmpty(strParts) == false)
                        strParts += "和";
                    strParts += "册记录";
                }
                DialogResult result = MessageBox.Show(this.Owner,
"当前" + strParts + "修改后尚未保存。如果此时装入新记录内容,先前的修改将会丢失。\r\n\r\n是否装入新记录?",
"册登记",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
                if (result == DialogResult.No)
                    return 0;
            }

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

            // 装载书目以外的其它XML片断
            nRet = LoadXmlFragment(info.OldXml,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            this.ClearEntityEditControls();
            this.EntitiesChanged = false;

            this.OldMARC = strMARC;
            this.Timestamp = info.Timestamp;

            string strPath = "";
            string strServerName = "";
            StringUtil.ParseTwoPart(info.RecPath, "@", out strPath, out strServerName);
            this.ServerName = strServerName;
            this.BiblioRecPath = strPath;

            this.MarcSyntax = strMarcSyntax;    // info.MarcSyntax;

            this.SetMarc(strMARC); // info.OldXml
            Debug.Assert(this.BiblioChanged == false, "");

            // 设置封面图像
#if NO
            string strMARC = info.OldXml;
            if (string.IsNullOrEmpty(strMARC) == false)
            {
                this.ImageUrl = ScriptUtil.GetCoverImageUrl(strMARC);
                this.CoverImageRequested = false;
            }
#endif

            if (this.LoadEntities != null)
                this.LoadEntities(this, new EventArgs());

            return 1;
        ERROR1:
            // MessageBox.Show(this, strError);
            return -1;
        }
コード例 #15
0
        // 替换浏览列内容
        public void ChangeBiblioBrowseLine(
            DpRow row,
            string strBrowseText,
            RegisterBiblioInfo info)
        {
            if (this.dpTable_browseLines.InvokeRequired)
            {
                // 事件是在多线程上下文中触发的,需要 Invoke 显示信息
                this.BeginInvoke(new Action<DpRow, string, RegisterBiblioInfo>(ChangeBiblioBrowseLine),
                    row,
                    strBrowseText,
                    info);
                return;
            }

            List<string> columns = StringUtil.SplitList(strBrowseText, '\t');


            // 0: index
            // 1: recpath

            int index = COLUMN_IMAGE + 1;
            foreach (string s in columns)
            {
                if (index >= row.Count)
                    break;
                row[index].Text = s;
                index++;
            }

            row.Tag = info;
            // PrepareCoverImage(row);
        }
コード例 #16
0
        RegisterBiblioInfo BuildBlankBiblioInfo(string strISBN)
        {
            // 获得一个可以保存新书目记录的服务器地址和书目库名
            string strServerName = "";
            string strBiblioDbName = "";
            // 寻找一个可以创建新书目记录的数据库信息
            // return:
            //      false 没有找到
            //      ture 找到
            GetTargetDatabaseInfo(out strServerName,
                out strBiblioDbName);


            // 装入一条空白书目记录
            RegisterBiblioInfo info = new RegisterBiblioInfo();

#if NO
            if (string.IsNullOrEmpty(strBiblioDbName) == false)
                info.RecPath = strBiblioDbName + "/?@" + strServerName; 
#endif

            info.MarcSyntax = "unimarc";
            MarcRecord record = new MarcRecord();
            record.add(new MarcField('$', "010  $a" + strISBN + "$dCNY??"));
            record.add(new MarcField('$', "2001 $a$f"));
            record.add(new MarcField('$', "210  $a$c$d"));
            record.add(new MarcField('$', "215  $a$d??cm"));
            record.add(new MarcField('$', "690  $a"));
            record.add(new MarcField('$', "701  $a"));
            info.OldXml = record.Text;

            return info;
        }
コード例 #17
0
        // 更新浏览行中缓冲的书目信息
        // parameters:
        //      new_info    要更新的 RegisterBiblioInfo 对象。如果为 null,表示要删除此浏览行
        void RefreshBrowseLineBiblio(string strRecPath,
            RegisterBiblioInfo new_info)
        {
#if DEBUG
            if (new_info != null)
            {
                Debug.Assert(strRecPath == new_info.RecPath, "");
            }
#endif

            foreach (DpRow row in this.dpTable_browseLines.Rows)
            {
                RegisterBiblioInfo info = row.Tag as RegisterBiblioInfo;
                if (info == null)
                    continue;
                if (info.RecPath == strRecPath)
                {
                    if (new_info == null)
                    {
                        this.dpTable_browseLines.Rows.Remove(row);
                        // TODO: 需要修改后面的浏览行的序号
                        return;
                    }
#if NO
                    info.OldXml = "";
                    info.NewXml = "";
                    info.Timestamp = null;
                    // 仅保留 RecPath 供重新装载用
#endif
                    RegisterBiblioInfo dup = new RegisterBiblioInfo(new_info);
                    //dup.CoverImageFileName = info.CoverImageFileName;
                    //dup.CoverImageRquested = info.CoverImageRquested;
                    // row.Tag = dup;

                    // XML 转换为 MARC,为了构造浏览格式的需要
                    string strError = "";
                    string strBrowseText = "";
                    string strMarcSyntax = "";
                    string strColumnTitles = "";

                    int nRet = BuildBrowseText(dup.OldXml,
out strBrowseText,
out strMarcSyntax,
out strColumnTitles,
out strError);
                    if (nRet == -1)
                        strBrowseText = strError;

                    dup.MarcSyntax = strMarcSyntax;


#if NO
                    // 刷新浏览列
                    string strBrowseText = "";
                    int nRet = BuildMarcBrowseText(
                        dup.MarcSyntax,
                        dup.OldXml,
                        out strBrowseText,
                        out strError);
                    if (nRet == -1)
                    {
                        strBrowseText = "MARC记录转换到浏览格式时出错: " + strError;
                    }
#endif
                    // 替换浏览列内容
                    ChangeBiblioBrowseLine(
                        row,
                        strBrowseText,
                        dup);
                }
            }

        }
コード例 #18
0
        // 针对 dp2library 服务器进行检索
        // parameters:
        //  
        // return:
        //      -1  出错
        //      >=0 命中的记录数
        int SearchLineDp2library(RegisterLine line,
            AccountInfo account,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            // ??? _currentAccount = account;

            _channel = _base.GetChannel(account.ServerUrl, account.UserName);
            _channel.Timeout = new TimeSpan(0, 0, 5);   // 超时值为 5 秒
            try
            {
                string strQueryWord = line.BiblioBarcode;

                string strFromStyle = "";

                try
                {
                    strFromStyle = this.MainForm.GetBiblioFromStyle("ISBN");
                }
                catch (Exception ex)
                {
                    strError = ex.Message;
                    goto ERROR1;
                }

                if (String.IsNullOrEmpty(strFromStyle) == true)
                {
                    strError = "GetFromStyle()没有找到 '" + "ISBN" + "' 对应的style字符串";
                    goto ERROR1;
                }

                string strMatchStyle = "left";  // BiblioSearchForm.GetCurrentMatchStyle(this.comboBox_matchStyle.Text);
                if (string.IsNullOrEmpty(strQueryWord) == true)
                {
                    if (strMatchStyle == "null")
                    {
                        strQueryWord = "";

                        // 专门检索空值
                        strMatchStyle = "exact";
                    }
                    else
                    {
                        // 为了在检索词为空的时候,检索出全部的记录
                        strMatchStyle = "left";
                    }
                }
                else
                {
                    if (strMatchStyle == "null")
                    {
                        strError = "检索空值的时候,请保持检索词为空";
                        goto ERROR1;
                    }
                }

                ServerInfo server_info = null;

                if (line != null)
                    line.BiblioSummary = "正在获取服务器 " + account.ServerName + " 的配置信息 ...";

                // 准备服务器信息
                nRet = _base.GetServerInfo(
                    // line,
                    _channel,
                    account,
                    out server_info,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;    // 可以不报错 ?

                line.BiblioSummary = "正在针对 "+account.ServerName+ " \r\n检索 " + line.BiblioBarcode + " ...";

                string strQueryXml = "";
                long lRet = _channel.SearchBiblio(Progress,
                    server_info == null ? "<全部>" : server_info.GetBiblioDbNames(),    // "<全部>",
                    strQueryWord,   // this.textBox_queryWord.Text,
                    1000,
                    strFromStyle,
                    strMatchStyle,
                    _base.Lang,
                    null,   // strResultSetName
                    "",    // strSearchStyle
                    "", // strOutputStyle
                    out strQueryXml,
                    out strError);
                if (lRet == -1)
                {
                    strError = "针对服务器 '"+account.ServerName+"' 检索出错: " + strError;
                    goto ERROR1;
                }

                // 装入浏览格式
                long lHitCount = lRet;

                long lStart = 0;
                long lCount = lHitCount;
                DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                string strStyle = "id";

                List<string> biblio_recpaths = new List<string>();
                // 装入浏览格式
                for (; ; )
                {
                    if (this.Progress != null && this.Progress.State != 0)
                    {
                        break;
                    }
                    // DoTasks();

                    lRet = _channel.GetSearchResult(
                        this.Progress,
                        null,   // strResultSetName
                        lStart,
                        lCount,
                        strStyle, // bOutputKeyCount == true ? "keycount" : "id,cols",
                        _base.Lang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条," + strError;
                        goto ERROR1;
                    }

                    if (lRet == 0)
                        break;

                    // 处理浏览结果

                    foreach (DigitalPlatform.CirculationClient.localhost.Record searchresult in searchresults)
                    {
                        biblio_recpaths.Add(searchresult.Path);
                    }

                    {
                        // 获得书目摘要
                        BiblioLoader loader = new BiblioLoader();
                        loader.Channel = _channel;
                        loader.Stop = this.Progress;
                        loader.Format = "xml";
                        loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp;
                        loader.RecPaths = biblio_recpaths;

                        try
                        {
                            int i = 0;
                            foreach (BiblioItem item in loader)
                            {
                                string strXml = item.Content;

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

                                string strBrowseText = "";
                                nRet = BuildMarcBrowseText(
                                    strMarcSyntax,
                                    strMARC,
                                    out strBrowseText,
                                    out strError);
                                if (nRet == -1)
                                {
                                    strError = "MARC记录转换到浏览格式时出错: " + strError;
                                    goto ERROR1;
                                }

                                RegisterBiblioInfo info = new RegisterBiblioInfo();
                                info.OldXml = strMARC;
                                info.Timestamp = item.Timestamp;
                                info.RecPath = item.RecPath + "@" + account.ServerName;
                                info.MarcSyntax = strMarcSyntax;
                                line.AddBiblioBrowseLine(
                                    -1,
                                    info.RecPath,
                                    strBrowseText,
                                    info);
                                i++;
                            }
                        }
                        catch (Exception ex)
                        {
                            strError = ex.Message;
                            goto ERROR1;
                        }


                        // lIndex += biblio_recpaths.Count;
                        biblio_recpaths.Clear();
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }


                return (int)lHitCount;

            }
            finally
            {
                _base.ReturnChannel(_channel);
                _channel = null;
            }

        ERROR1:
#if NO
            line.SetDisplayMode("summary");
            line.SetBiblioSearchState("error");
            line.BiblioSummary = strError;
#endif
            line.AddBiblioBrowseLine(strError, BiblioRegisterControl.TYPE_ERROR);

            return -1;
        }
コード例 #19
0
        // 保存书目记录和下属的册记录
        // return:
        //      -1      保存过程出错
        //      0       没有必要保存(例如没有发生过修改)
        //      1       保存成功
        int SaveBiblioAndItems()
        {
            string strError = "";
            int nRet = 0;

            if (_biblio.BiblioChanged)
            {
                List<BiblioError> errors = null;
                // return:
                //      -1  检查过程出错。错误信息在 strError 中。和返回 1 的区别是,这里是某些因素导致无法检查了,而不是因为册记录格式有错
                //      0   正确
                //      1   有错。错误信息在 errors 中
                nRet = _biblio.VerifyBiblio(
                    "",
                    out errors,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
                if (nRet == 1)
                {
                    // 观察报错的字段是否有隐藏状态的。如果有,则需要把它们显示出来,以便操作者观察修改
                    {
#if NO
                        List<string> important_fieldnames = null; //  StringUtil.SplitList(this.textBox_settings_importantFields.Text.Replace("\r\n", ","));
                        if (_biblio.MarcSyntax == "unimarc")
                            important_fieldnames = StringUtil.SplitList(this.UnimarcBiblioImportantFields);
                        else
                            important_fieldnames = StringUtil.SplitList(this.Marc21BiblioImportantFields);

                        List<string> hidden_fieldnames = BiblioError.GetOutOfRangeFieldNames(errors, important_fieldnames);
                        if (hidden_fieldnames.Count > 0)
                            this.easyMarcControl1.HideFields(hidden_fieldnames, false); // null, false 可显示全部隐藏字段
#endif
                        List<string> names = BiblioError.GetFieldNames(errors);
                        if (names.Count > 0)
                            this.easyMarcControl1.HideFields(names, true); // null, false 可显示全部隐藏字段
                    }

                    bool bTemp = false;
                    // TODO: 如果保持窗口修改后的尺寸位置?
                    MessageDialog.Show(this,
                        "书目记录格式不正确",
                        BiblioError.GetListString(errors, "\r\n"),
                        null,
                        ref bTemp);

                    strError = "书目记录没有被保存。请修改相关字段后重新提交保存";
                    goto ERROR1;
                }

            }

            {
                // 补全册记录信息
                nRet = _biblio.CompleteEntities(
    out strError);
                if (nRet == -1)
                    goto ERROR1;

                List<string> verify_styles = new List<string>();

                if (this.checkBox_settings_needBookType.Checked == true)
                    verify_styles.Add("need_booktype");
                if (this.checkBox_settings_needLocation.Checked == true)
                    verify_styles.Add("need_location");
                if (this.checkBox_settings_needAccessNo.Checked == true)
                    verify_styles.Add("need_accessno");
                if (this.checkBox_settings_needPrice.Checked == true)
                    verify_styles.Add("need_price");
                if (this.checkBox_settings_needItemBarcode.Checked == true)
                    verify_styles.Add("need_barcode");
                if (this.checkBox_settings_needBatchNo.Checked == true)
                    verify_styles.Add("need_batchno");

                List<string> errors = null;

                // 检查册记录的格式是否正确
                // parameters:
                //      errors  返回册记录出错信息。每个元素返回一个错误信息,顺次对应于每个有错的册记录。文字中有说明,是那个册记录出错
                // return:
                //      -1  检查过程出错。错误信息在 strError 中。和返回 1 的区别是,这里是某些因素导致无法检查了,而不是因为册记录格式有错
                //      0   正确
                //      1   有错。错误信息在 errors 中
                nRet = _biblio.VerifyEntities(
                    StringUtil.MakePathList(verify_styles),
                    out errors,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
                if (nRet == 1)
                {
                    bool bTemp = false;
                    MessageDialog.Show(this,
                        "册记录格式不正确",
                        StringUtil.MakePathList(errors, "\r\n"),
                        null,
                        ref bTemp);
                    strError = "记录没有被保存。请修改相关记录后重新提交保存";
                    goto ERROR1;
                }
            }

            bool bBiblioSaved = false;
            bool bEntitySaved = false;

            this.ShowMessage("正在保存书目和册记录", "progress", false);

            this.Progress.OnStop += new StopEventHandler(this.DoStop);
            this.Progress.BeginLoop();
            try
            {
                string strCancelSaveBiblio = "";
                string strWarning = "";

                AccountInfo _currentAccount = _base.GetAccountInfo(this._biblio.ServerName);
                if (_currentAccount == null)
                {
                    strError = "服务器名 '" + this._biblio.ServerName + "' 没有配置";
                    goto ERROR1;
                }

                // line.SetBiblioSearchState("searching");
                if (this._biblio.BiblioChanged == true
                    || Global.IsAppendRecPath(this._biblio.BiblioRecPath) == true
                    || _currentAccount.IsLocalServer == false)
                {
                    // TODO: 确定目标 dp2library 服务器 目标书目库
                    string strServerName = "";
                    string strBiblioRecPath = "";
                    // 根据书目记录的路径,匹配适当的目标
                    // return:
                    //      -1  出错
                    //      0   没有找到
                    //      1   找到
                    nRet = GetTargetInfo(
                        _currentAccount.IsLocalServer == false ? true : false,
                        this._biblio.ServerName,
                        this._biblio.BiblioRecPath,
                        out strServerName,
                        out strBiblioRecPath);
#if NO
                    if (nRet != 1)
                    {
                        strError = "line (servername='" + line._biblioRegister.ServerName + "' bibliorecpath='" + line._biblioRegister.BiblioRecPath + "') 没有找到匹配的保存目标";
                        goto ERROR1;
                    }
#endif
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 0)
                    {
                        strError = "来自服务器 '" + this._biblio.ServerName + "' 的书目记录 '" + this._biblio.BiblioRecPath + "' 没有找到匹配的保存目标";
                        bool bAppend = Global.IsAppendRecPath(this._biblio.BiblioRecPath);
                        if (bAppend == true || _currentAccount.IsLocalServer == false)
                            goto ERROR1;

                        // 虽然书目记录无法保存,但继续寻求保存册记录
                        strCancelSaveBiblio = strError;
                        goto SAVE_ENTITIES;
                    }

                    // if nRet == 0 并且 书目记录路径不是追加型的
                    // 虽然无法兑现修改后保存,但是否可以依然保存实体记录?

                    string strXml = "";
                    nRet = this._biblio.GetBiblioXml(
                        out strXml,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    string strOutputPath = "";
                    byte[] baNewTimestamp = null;
                    // return:
                    //      -1  出错
                    //      0   有警告,在 strWarning 中。一般是因为部分保存成功
                    //      1   成功
                    nRet = SaveXmlBiblioRecordToDatabase(
                        strServerName,
                        strBiblioRecPath,
                        strXml,
                        this._biblio.Timestamp,
                        out strOutputPath,
                        out baNewTimestamp,
                        out strWarning,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 0)
                    {
                        // strWarning 中为警告信息
                        // TODO: 出现对照窗口,允许进一步修改
                    }
                    this._biblio.ServerName = strServerName;
                    this._biblio.BiblioRecPath = strOutputPath;
                    this._biblio.Timestamp = baNewTimestamp;

                    if (string.IsNullOrEmpty(strWarning) == true)
                        this._biblio.BiblioChanged = false;

                    this.toolStripLabel_biblioSource.Text = this._biblio.BiblioRecPath + "@" + this._biblio.ServerName;

                    bBiblioSaved = true;

                    // 刷新浏览列表中的书目信息
                    {
                        strXml = "";
                        if (string.IsNullOrEmpty(strWarning) == true)
                        {
                            nRet = this._biblio.GetBiblioXml(out strXml, out strError);
                            if (nRet == -1)
                                goto ERROR1;
                        }

                        RegisterBiblioInfo info = new RegisterBiblioInfo(
                            _biblio.BiblioRecPath + "@" + _biblio.ServerName,
                            strXml,
                            "",
                            _biblio.Timestamp,
                            _biblio.MarcSyntax);
                        this.RefreshBrowseLineBiblio(info.RecPath,
                            info);
                    }

                    this.ShowMessage("书目记录 " + strOutputPath + " 保存成功", "green", true);
                }

                // line.SetDisplayMode("summary");

                SAVE_ENTITIES:
                // 保存下属的册记录
                {
                    EntityInfo[] entities = null;
                    // 构造用于保存的实体信息数组
                    nRet = this._biblio.BuildSaveEntities(
                        "change",
                        null,
                        out entities,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    if (entities.Length > 0)
                    {
                        this.ShowMessage("正在保存 " + entities.Length + " 个册记录", "progress", false);
                        // 分批进行保存
                        // return:
                        //      -2  部分成功,部分失败
                        //      -1  出错
                        //      0   保存成功,没有错误和警告
                        nRet = SaveEntities(
                            entities,
                            out strError);
                        if (nRet == -1 || nRet == -2)
                            goto ERROR1;
                        this._biblio.EntitiesChanged = false;
                        bEntitySaved = true;
                    }
                    else
                    {
                        this._biblio.EntitiesChanged = false;
                        // line._biblioRegister.BarColor = "G";   // 绿色

                    }
                }


                if (string.IsNullOrEmpty(strCancelSaveBiblio) == false)
                {
                    if (bEntitySaved == false)
                        strError = "书目记录无法保存\r\n(" + strCancelSaveBiblio + ")";
                    else
                        strError = "书目记录无法保存,但册记录保存成功\r\n(" + strCancelSaveBiblio + ")";
                    goto ERROR1;
                }
                else if (string.IsNullOrEmpty(strWarning) == false)
                {
                    if (bEntitySaved == false)
                        this.ShowMessage(strWarning, "yellow", true);
                    else
                        this.ShowMessage(strWarning + ",但册记录保存成功", "yellow", true);
                }
                else if (bBiblioSaved == false && bEntitySaved == false)
                {
                    this.ShowMessage("没有可保存的信息", "yellow", true);
                    return 0;
                }
                else
                {
                    this.ShowMessage("保存成功", "green", true);
                }
                return 1;
            }
            finally
            {
                this.Progress.EndLoop();
                this.Progress.OnStop -= new StopEventHandler(this.DoStop);
                // this.Progress.Initial("");
            }
        ERROR1:
            this.ShowMessage(strError, "red", true);
            return -1;
        }
コード例 #20
0
 public void AddBiblioBrowseLine(
     int nType,
     string strBiblioRecPath,
     string strBrowseText,
     RegisterBiblioInfo info)
 {
     this._biblioRegister.AddBiblioBrowseLine(
         nType,
         strBiblioRecPath,
         strBrowseText,
         info);
 }
コード例 #21
0
ファイル: EntityForm.cs プロジェクト: renyh1013/dp2
        void MessageHub_SearchResponseEvent(object sender, SearchResponseEventArgs e)
        {
            if (e.TaskID != _searchParam._searchID)
                return;

            if (e.ResultCount == -1 && e.Start == -1)
            {
                // 检索过程结束
                _searchParam._searchComplete = true;
                _searchParam._searchCount = (int)_searchParam._manager.GetTotalCount();
                return;
            }

            string strError = "";

            if (e.ResultCount == -1)
            {
                strError = e.ErrorInfo;
                goto ERROR1;
            }

            List<string> array = StringUtil.ParseTwoPart(e.LibraryUID, "|");
            string strLibraryName = array[0];

            // 标记结束一个检索目标
            // return:
            //      0   尚未结束
            //      1   结束
            //      2   全部结束
            int nRet = _searchParam._manager.CompleteTarget(e.LibraryUID,
                e.ResultCount,
                e.Records == null ? 0 : e.Records.Count);

            _searchParam._searchCount = (int)_searchParam._manager.GetTotalCount();

            if (nRet == 2)
                _searchParam._searchComplete = true;

            // 单独给一个线程来执行
            Task.Factory.StartNew(() => FillList(e.Start, strLibraryName, e.Records));
            return;

#if NO
            // TODO: 注意来自共享网络的图书馆名不能和 servers.xml 中的名字冲突。另外需要检查,不同的 UID,图书馆名字不能相同,如果发生冲突,则需要给分配 ..1 ..2 这样的编号以示区别
            // 需要一直保存一个 UID 到图书馆命的对照表在内存备用
            // TODO: 来自共享网络的记录,图标或 @ 后面的名字应该有明显的形态区别
            foreach (DigitalPlatform.MessageClient.Record record in e.Records)
            {
                MessageHub.DecodeRecord(record, _searchParam._serverPushEncoding);

                string strXml = record.Data;

                string strMarcSyntax = "";
                string strBrowseText = "";
                string strColumnTitles = "";
                int nRet = BuildBrowseText(strXml,
out strBrowseText,
out strMarcSyntax,
out strColumnTitles,
out strError);
                if (nRet == -1)
                    goto ERROR1;

                // string strRecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false ? record.LibraryName : record.LibraryUID);
                string strRecPath = record.RecPath;

#if NO
                string strDbName = ListViewProperty.GetDbName(strRecPath);
                _browseTitleTable[strDbName] = strColumnTitles;
#endif
                _browseTitleTable[strMarcSyntax] = strColumnTitles;

                // 将书目记录放入 m_biblioTable
                {
                    BiblioInfo info = new BiblioInfo();
                    info.OldXml = strXml;
                    info.RecPath = strRecPath;
                    info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                    info.Format = strMarcSyntax;
                    this.browseWindow.BiblioTable[strRecPath] = info;
                }

                List<string> column_list = StringUtil.SplitList(strBrowseText, '\t');
                string[] cols = new string[column_list.Count];
                column_list.CopyTo(cols);

                ListViewItem item = null;
                this.Invoke((Action)(() =>
                {
                    item = Global.AppendNewLine(
    this.browseWindow.RecordsList,
    strRecPath,
    cols);
                }
                ));

                if (item != null)
                    item.BackColor = Color.LightGreen;

#if NO
                RegisterBiblioInfo info = new RegisterBiblioInfo();
                info.OldXml = strXml;   // strMARC;
                info.Timestamp = ByteArray.GetTimeStampByteArray(record.Timestamp);
                info.RecPath = record.RecPath + "@" + (string.IsNullOrEmpty(record.LibraryName) == false ? record.LibraryName : record.LibraryUID);
                info.MarcSyntax = strMarcSyntax;
#endif
                _searchParam._searchCount++;
            }
            return;
#endif
        ERROR1:
            // 加入一个文本行
            AddErrorLine(strError);
        }
コード例 #22
0
        // 从列表中选择一条书目记录装入编辑模板
        public int SelectBiblio(int index, 
            out string strError)
        {
            strError = "";

            if (this.InvokeRequired)
            {
                Delegate_SelectBiblio d = new Delegate_SelectBiblio(SelectBiblio);
                object[] args = new object[2];
                args[0] = index;
                args[1] = strError;
                int result = (int)this.Invoke(d, args);

                // 取出out参数值
                strError = (string)args[1];
                return result;
            }

            if (index >= this.dpTable_browseLines.Rows.Count)
            {
                strError = "index 超过范围";
                goto ERROR1;
            }

            if (this.BiblioChanged == true)
            {
                DialogResult result = MessageBox.Show(this,
"当前书目记录修改后尚未保存。如果此时装入新记录内容,先前的修改将会丢失。\r\n\r\n是否装入新记录?",
"BiblioRegisterControl",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
                if (result == DialogResult.No)
                    return 0;
            }

            // 警告那些从原书目记录下属装入的册记录修改。但新增的册不会被清除
            if (HasEntitiesChanged("normal") == true)
            {
                DialogResult result = MessageBox.Show(this,
"当前有册记录修改后尚未保存。如果此时装入新记录内容,先前的修改将会丢失。\r\n\r\n是否装入新记录?",
"BiblioRegisterControl",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
                if (result == DialogResult.No)
                    return 0;
            }

            // this.ClearEntityEditControls("normal");

            DpRow row = this.dpTable_browseLines.Rows[index];
            RegisterBiblioInfo info = row.Tag as RegisterBiblioInfo;

            if (info == null)
            {
                strError = "这是提示信息行";
                return -1;
#if NO
                if (row[0].ImageIndex == TYPE_ERROR)
                {
                    strError = "这是提示信息行";
                    return -1;
                }
                // 装入一条空白书目记录
                info = new RegisterBiblioInfo();
                info.MarcSyntax = "unimarc";
                MarcRecord record = new MarcRecord();
                record.add(new MarcField('$', "010  $a" + this.BiblioBarcode));
                record.add(new MarcField('$', "2001 $a$f"));
                record.add(new MarcField('$', "210  $a$c$d"));
                record.add(new MarcField('$', "215  $a$d"));
                record.add(new MarcField('$', "690  $a"));
                record.add(new MarcField('$', "701  $a"));
                info.OldXml = record.Text;
#endif
            }

            this.OldMARC = info.OldXml;
            this.Timestamp = info.Timestamp;

            string strPath = "";
            string strServerName = "";
            StringUtil.ParseTwoPart(info.RecPath, "@", out strPath, out strServerName);
            this.ServerName = strServerName;
            this.BiblioRecPath = strPath;

            this.MarcSyntax = info.MarcSyntax;

            this.easyMarcControl1.SetMarc(info.OldXml);
            Debug.Assert(this.BiblioChanged == false, "");

            // 设置封面图像
            // SetCoverImage(row);
            string strMARC = info.OldXml;
            if (string.IsNullOrEmpty(strMARC) == false)
            {
                this.ImageUrl = ScriptUtil.GetCoverImageUrl(strMARC);
                this.CoverImageRequested = false;
            }

            this.SetDisplayMode("detail");

            if (this.LoadEntities != null)
                this.LoadEntities(this, new EventArgs());

            return 1;
        ERROR1:
            // MessageBox.Show(this, strError);
            return -1;
        }