예제 #1
0
        // parameters:
        //      strIndicator    字段指示符。如果用null调用,则表示不对指示符进行筛选
        // return:
        //      0   没有找到匹配的配置事项
        //      >=1 找到。返回找到的配置事项个数
        public static int GetPinyinCfgLine(XmlDocument cfg_dom,
                                           string strFieldName,
                                           string strIndicator,
                                           out List <PinyinCfgItem> cfg_items)
        {
            cfg_items = new List <PinyinCfgItem>();

            XmlNodeList nodes = cfg_dom.DocumentElement.SelectNodes("item");

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes[i];

                PinyinCfgItem item = new PinyinCfgItem(node);

                if (item.FieldName != strFieldName)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(item.IndicatorMatchCase) == false &&
                    string.IsNullOrEmpty(strIndicator) == false)
                {
                    if (MarcUtil.MatchIndicator(item.IndicatorMatchCase, strIndicator) == false)
                    {
                        continue;
                    }
                }

                cfg_items.Add(item);
            }

            return(cfg_items.Count);
        }
예제 #2
0
        static int GetMarcLength(string strXml)
        {
            string strError = "";

            string strMarc          = "";
            string strOutMarcSyntax = "";
            // 将MARCXML格式的xml记录转换为marc机内格式字符串
            // parameters:
            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
            int nRet = MarcUtil.Xml2Marc(strXml,
                                         true, // 2013/1/12 修改为true
                                         "",   // strMarcSyntax
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);

            if (nRet == -1)
            {
                return(0);
            }

            MarcRecord record = new MarcRecord(strMarc);

            return(record.Text.Length);
        }
예제 #3
0
파일: MarcBrowse.cs 프로젝트: pxmarc/dp2
        public static Dictionary <string, MarcColumn> Build(XmlDocument dom,
                                                            List <string> column_list = null)
        {
            Dictionary <string, MarcColumn> results = new Dictionary <string, MarcColumn>();

            string strOutMarcSyntax = "";
            string strMarc          = "";
            string strError         = "";
            // 将MARCXML格式的xml记录转换为marc机内格式字符串
            // parameters:
            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
            int nRet = MarcUtil.Xml2Marc(dom,
                                         true,
                                         "",
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);

            if (nRet == -1)
            {
                results.Add("error", new MarcColumn("error", strError));
                return(results);
            }

            if (strOutMarcSyntax == "unimarc")
            {
                return(BuildUnimarc(strMarc, column_list));
            }

            return(results);
        }
예제 #4
0
파일: BiblioStatis.cs 프로젝트: zszqwe/dp2
        /// <summary>
        /// 将一条 MARC 记录保存到当前正在处理的书目记录的数据库原始位置
        /// 所谓当前位置由 this.CurrentRecPath 决定
        /// 提交保存所采用的时间戳是 this.Timestamp
        /// </summary>
        /// <param name="strMARC">MARC机内格式字符串</param>
        /// <param name="strError">出错信息</param>
        /// <returns>-1: 出错,错误信息在 strError 中; 0: 成功</returns>
        public int SaveMarcRecord(string strMARC,
                                  out string strError)
        {
            strError = "";

            string strXml = this.Xml;
            int    nRet   = MarcUtil.Marc2XmlEx(strMARC,
                                                this.CurrentDbSyntax,
                                                ref strXml, // 2015/10/12
                                                out strError);

            if (nRet == -1)
            {
                return(-1);
            }

            string strOutputPath = "";

            byte[] baNewTimestamp = null;
            nRet = this.BiblioStatisForm.SaveXmlBiblioRecordToDatabase(this.CurrentRecPath,
                                                                       strXml,
                                                                       this.Timestamp,
                                                                       out strOutputPath,
                                                                       out baNewTimestamp,
                                                                       out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            this.Timestamp = baNewTimestamp;
            return(0);
        }
예제 #5
0
        // 获得一条记录的 MARC 格式 OID
        static string GetMarcSyntaxOID(DigitalPlatform.LibraryClient.localhost.Record dp2library_record)
        {
            if (dp2library_record.RecordBody == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(dp2library_record.RecordBody.Xml))
            {
                return(null);
            }

            // return:
            //      -1  出错
            //      0   正常
            int nRet = MarcUtil.GetMarcSyntax(dp2library_record.RecordBody.Xml,
                                              out string strOutMarcSyntax,
                                              out string strError);

            if (nRet == -1)
            {
                throw new Exception("获得 MARCXML 记录的 MARC Syntax 时出错: " + strError);
            }

            if (strOutMarcSyntax == "unimarc")
            {
                return("1.2.840.10003.5.1");
            }
            if (strOutMarcSyntax == "usmarc")
            {
                return("1.2.840.10003.5.10");
            }

            return(null);
        }
예제 #6
0
        // 从 dp2library 服务器获得全部 isbn 和 title 字符串
        IsbnResult GetIsbnStrings()
        {
            LibraryChannel channel = _channelPool.GetChannel(this.textBox_dp2libraryUrl.Text, "public");

            try
            {
                // TODO: <全部UNIMARC>
                long lRet = channel.SearchBiblio("<全部>", "", -1, "isbn",
                                                 "left", "zh", "default", "", "", "",
                                                 out string strQueryXml, out string strError);
                if (lRet == -1)
                {
                    return new IsbnResult {
                               Value = -1, ErrorInfo = strError
                    }
                }
                ;
                ResultSetLoader loader = new ResultSetLoader(channel, "default",
                                                             "id,xml");
                IsbnResult result = new IsbnResult();
                result.IsbnList = new List <string>();
                foreach (Record record in loader)
                {
                    // XML 转换为 MARC
                    int nRet = MarcUtil.Xml2Marc(record.RecordBody.Xml,
                                                 false,
                                                 "",
                                                 out string strMarcSyntax,
                                                 out string strMARC,
                                                 out strError);

                    if (nRet != 0)
                    {
                        continue;
                    }

                    // 从 MARC 中取 010$a
                    var    marc_record = new MarcRecord(strMARC);
                    string xpath       = "field[@name='010']/subfield[@name='a']";
                    if (strMarcSyntax == "usmarc")
                    {
                        xpath = "field[@name='020']/subfield[@name='a']";
                    }
                    var nodes = marc_record.select(xpath);

                    foreach (MarcSubfield subfield in nodes)
                    {
                        result.IsbnList.Add(subfield.Content);
                    }
                }

                return(result);
            }
            finally
            {
                _channelPool.ReturnChannel(channel);
            }
        }
예제 #7
0
파일: Form1.cs 프로젝트: keji56/chord
        private async void MenuItem_iso2709LoaderTest_Click(object sender, EventArgs e)
        {
            this.MenuItem_iso2709LoaderTest.Enabled = false;
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();

                dlg.Title = "请指定要装载的 ISO2709 文件名";
                // dlg.FileName = this.textBox_filename.Text;
                dlg.Filter           = "ISO2709文件 (*.iso)|*.iso|All files (*.*)|*.*";
                dlg.RestoreDirectory = true;

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

                MarcLoader loader = new MarcLoader(dlg.FileName,
                                                   Encoding.GetEncoding(936),
                                                   "marc",
                                                   (length, current) =>
                {
                    this.Invoke(
                        (Action)(() =>
                    {
                        this.toolStripProgressBar1.Maximum = (int)length;
                        this.toolStripProgressBar1.Value = (int)current;
                    })
                        );
                }
                                                   );

                this.ClearHtml();
                await Task.Run(() =>
                {
                    int i = 0;
                    foreach (string strMARC in loader)
                    {
                        this.AppendHtml("<div class='debug green' >" + (i + 1) + ") ===</div>");

                        // 获得 MARC 记录的 HTML 格式字符串
                        string strHtml = MarcUtil.GetHtmlOfMarc(strMARC,
                                                                null,
                                                                null,
                                                                false);

                        this.AppendHtml(strHtml);
                        i++;
                    }
                });
            }
            finally
            {
                this.MenuItem_iso2709LoaderTest.Enabled = true;
            }
        }
예제 #8
0
파일: UtilityForm.cs 프로젝트: gvhung/dp2
        void DisplayFirstWorksheetRecord()
        {
            if (string.IsNullOrEmpty(this.textBox_worToIso_worFilename.Text) == true)
            {
                this.textBox_worToIso_preview.Text = "";
                return;
            }

            this.textBox_worToIso_preview.Text = MarcUtil.ReaderFirstWorksheetRecord(this.textBox_worToIso_worFilename.Text,
                                                                                     this.comboBox_worToIso_encoding.Text);
        }
예제 #9
0
파일: Form1.cs 프로젝트: keji56/chord
        void AppendMarcRecords(RecordCollection records,
                               Encoding encoding,
                               int start_index)
        {
            if (records == null)
            {
                return;
            }

            int i = start_index;

            foreach (Record record in records)
            {
                this.AppendHtml("<div class='debug green' >" + (i + 1) + ") ===</div>");

                if (string.IsNullOrEmpty(record.m_strDiagSetID) == false)
                {
                    // 这是诊断记录

                    this.AppendHtml("<div>" + HttpUtility.HtmlEncode(record.ToString()).Replace("\r\n", "<br/>") + "</div>");
                    i++;
                    continue;
                }

                // 把byte[]类型的MARC记录转换为机内格式
                // return:
                //		-2	MARC格式错
                //		-1	一般错误
                //		0	正常
                int nRet = MarcLoader.ConvertIso2709ToMarcString(record.m_baRecord,
                                                                 encoding == null ? Encoding.GetEncoding(936) : encoding,
                                                                 true,
                                                                 out string strMARC,
                                                                 out string strError);
                if (nRet == -1)
                {
                    this.AppendHtml("<div>" + strError + "</div>");
                    i++;
                    continue;
                }

                // 获得 MARC 记录的 HTML 格式字符串
                string strHtml = MarcUtil.GetHtmlOfMarc(strMARC,
                                                        null,
                                                        null,
                                                        false);

                this.AppendHtml(strHtml);
                i++;
            }
        }
예제 #10
0
파일: MyForm.cs 프로젝트: gvhung/dp2
        public int BuildBrowseText(string strXml,
                                   out string strBrowseText,
                                   out string strMarcSyntax,
                                   out string strColumnTitles,
                                   out string strError)
        {
            strError        = "";
            strBrowseText   = "";
            strMarcSyntax   = "";
            strColumnTitles = "";

            int nRet = 0;

            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;
                return(-1);
            }
            if (string.IsNullOrEmpty(strMARC))
            {
                strError = "MARC 记录为空";
                return(-1);
            }

            Debug.Assert(string.IsNullOrEmpty(strMarcSyntax) == false, "");

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

            return(0);
        }
예제 #11
0
파일: LinkMarcFile.cs 프로젝트: zszqwe/dp2
        // 重新获得当前记录
        // return:
        //      -1  error
        //      0   succeed
        //      1   reach head
        public int CurrentRecord(out string strMARC,
                                 out byte[] baRecord,
                                 out string strError)
        {
            strError = "";
            strMARC  = "";
            baRecord = null;
            int nRet = 0;

            if (this.CurrentIndex < 0)
            {
                strError = "越过头部";
                return(1);
            }

            int index = this.CurrentIndex;

            _file.Position = heads[index];

            // 从ISO2709文件中读入一条MARC记录
            // return:
            //	-2	MARC格式错
            //	-1	出错
            //	0	正确
            //	1	结束(当前返回的记录有效)
            //	2	结束(当前返回的记录无效)
            nRet = MarcUtil.ReadMarcRecord(_file,
                                           Encoding,
                                           true, // bRemoveEndCrLf,
                                           true, // bForce,
                                           out strMARC,
                                           out baRecord,
                                           out strError);
            if (nRet == -2 || nRet == -1)
            {
                strError = "读入MARC记录(" + index.ToString() + ")出错: " + strError;
                return(-1);
            }

            if (nRet != 0 && nRet != 1)
            {
                strError = "越过尾部";
                return(1);
            }

            // this.CurrentIndex = index;
            return(0);
        }
예제 #12
0
        void DisplayMarc(string strOldMARC,
                         string strNewMARC)
        {
            string strError = "";

            string strHtml2 = "";

            if (string.IsNullOrEmpty(strOldMARC) == false &&
                string.IsNullOrEmpty(strNewMARC) == true)
            {
                strHtml2 = MarcUtil.GetHtmlOfMarc(strOldMARC,
                                                  null,
                                                  null,
                                                  false);
            }
            else
            {
                // 创建展示两个 MARC 记录差异的 HTML 字符串
                // return:
                //      -1  出错
                //      0   成功
                int nRet = MarcDiff.DiffHtml(
                    strOldMARC,
                    null,
                    null,
                    strNewMARC,
                    null,
                    null,
                    out strHtml2,
                    out strError);
                if (nRet == -1)
                {
                }
            }

            string strHtml = "<html>" +
                             this.MarcHtmlHead +
                             "<body>" +
                             strHtml2 +
                             "</body></html>";

            this.webBrowser1.Stop();
            Global.SetHtmlString(this.webBrowser1,
                                 strHtml,
                                 this.TempDir,
                                 "temp_html");
        }
예제 #13
0
파일: MarcForm.cs 프로젝트: renyh/dp2mini
        // 从 ISO2709 文件中读出第一条记录。返回的是机内格式
        // return:
        //      -1  出错
        //      0   正常
        /*public*/
        static int LoadFirstRecord(string strMarcFileName,
                                   Encoding encoding,
                                   out string strMARC,
                                   out string strError)
        {
            strError = "";
            strMARC  = "";

            try
            {
                using (Stream stream = File.Open(strMarcFileName,
                                                 FileMode.Open,
                                                 FileAccess.Read,
                                                 FileShare.ReadWrite))
                {
                    // 从ISO2709文件中读入一条MARC记录
                    // return:
                    //	-2	MARC格式错
                    //	-1	出错
                    //	0	正确
                    //	1	结束(当前返回的记录有效)
                    //	2	结束(当前返回的记录无效)
                    int nRet = MarcUtil.ReadMarcRecord(stream,
                                                       encoding,
                                                       true, // bRemoveEndCrLf,
                                                       true, // bForce,
                                                       out strMARC,
                                                       out strError);
                    if (nRet == 0 || nRet == 1)
                    {
                        return(0);   // 正常
                    }
                    strError = "读入MARC记录时出错: " + strError;
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                strError = "异常: " + ex.Message;
                return(-1);
            }
        }
예제 #14
0
파일: Form1.cs 프로젝트: distinct2010/chord
        void AppendMarcRecords(RecordCollection records,
                               Encoding encoding,
                               int start_index)
        {
            if (records == null)
            {
                return;
            }

            int i = start_index;

            foreach (Record record in records)
            {
                this.AppendHtml("<div class='debug green' >" + (i + 1) + ") ===</div>");

                // 把byte[]类型的MARC记录转换为机内格式
                // return:
                //		-2	MARC格式错
                //		-1	一般错误
                //		0	正常
                int nRet = MarcUtil.ConvertByteArrayToMarcRecord(record.m_baRecord,
                                                                 encoding,
                                                                 true,
                                                                 out string strMARC,
                                                                 out string strError);
                if (nRet == -1)
                {
                    this.AppendHtml("<div>" + strError + "</div>");
                    i++;
                    continue;
                }

                // 获得 MARC 记录的 HTML 格式字符串
                string strHtml = MarcUtil.GetHtmlOfMarc(strMARC,
                                                        null,
                                                        null,
                                                        false);

                this.AppendHtml(strHtml);
                i++;
            }
        }
예제 #15
0
        public void CreateSummary(string strXml, string recpath)
        {
            int nRet = MarcUtil.Xml2Marc(strXml,
                                         false,
                                         null,
                                         out string strOutMarcSyntax,
                                         out string strMARC,
                                         out string strError);

            if (nRet == -1)
            {
                this.Summary = "error:" + strError;
                return;
            }

            this.Summary = CreateSummary(
                recpath,
                strMARC,
                strOutMarcSyntax);
        }
예제 #16
0
        static int Count6XX(string strXml)
        {
            string strError = "";

            string strMarc          = "";
            string strOutMarcSyntax = "";
            // 将MARCXML格式的xml记录转换为marc机内格式字符串
            // parameters:
            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
            int nRet = MarcUtil.Xml2Marc(strXml,
                                         true, // 2013/1/12 修改为true
                                         "",   // strMarcSyntax
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);

            if (nRet == -1)
            {
                return(0);
            }

            int nCount = 0;

            if (strOutMarcSyntax == "unimarc")
            {
                MarcRecord record = new MarcRecord(strMarc);
                nCount += record.select("field[@name='606']").count;
                nCount += record.select("field[@name='690']").count;
                return(nCount);
            }
            if (strOutMarcSyntax == "usmarc")
            {
                MarcRecord record = new MarcRecord(strMarc);
                nCount += record.select("field[@name='600' or @name='610' or @name='630' or @name='650' or @name='651']").count;
                nCount += record.select("field[@name='093']").count;
                return(nCount);
            }
            return(0);
        }
예제 #17
0
        public static void CreateTestRecords(LibraryContext context)
        {
            // context.Database.Migrate();

            string recpath = "test/1";
            // 删除可能存在的记录
            var record = context.Biblios
                         .Where(x => x.RecPath == recpath).FirstOrDefault();

            if (record != null)
            {
                context.Biblios.Remove(record);
                context.SaveChanges();
            }

            // 创建一条新的记录
            Biblio biblio = new Biblio {
                RecPath = recpath
            };

            MarcRecord marc = new MarcRecord();

            marc.add(new MarcField('$', "200  $atitle$fauthor"));
            marc.add(new MarcField('$', "690  $aclass_string1"));
            marc.add(new MarcField('$', "690  $aclass_string2"));

            if (MarcUtil.Marc2Xml(marc.Text,
                                  "unimarc",
                                  out string xml,
                                  out string error) == -1)
            {
                throw new Exception(error);
            }
            biblio.RecPath = recpath;
            biblio.Xml     = xml;
            biblio.Create(biblio.Xml, biblio.RecPath);
            context.Biblios.Add(biblio);
            context.SaveChanges();
        }
예제 #18
0
        int GetMarcRecord(XmlDocument domData,
                          ref MarcRecord record,
                          ref string strMarcSyntax,
                          out string strError)
        {
            strError = "";

            if (record != null)
            {
                return(0);
            }

            string strOutMarcSyntax = "";
            string strMarc          = "";
            // 将MARCXML格式的xml记录转换为marc机内格式字符串
            // parameters:
            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
            int nRet = MarcUtil.Xml2Marc(domData,
                                         true,
                                         "",
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);

            if (nRet == -1)
            {
                strError = "XML 转换到 MARC 时出错: " + strError;
                return(-1);
            }

            record        = new MarcRecord(strMarc);
            strMarcSyntax = strOutMarcSyntax;
            return(0);
        }
예제 #19
0
        int LoadBiblioRecord(
            string strBiblioRecPath,
            out string strError)
        {
            strError           = "";
            this.BiblioRecPath = strBiblioRecPath;

            string strMarcXml = "";

            byte[] baTimeStamp = null;

            int nRet = this.SearchPanel.GetRecord(
                this.ServerUrl,
                this.BiblioRecPath,
                out strMarcXml,
                out baTimeStamp,
                out strError);

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

            // 转换为MARC格式

            string strOutMarcSyntax = "";
            string strMarc          = "";

            // 将MARCXML格式的xml记录转换为marc机内格式字符串
            // parameters:
            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
            nRet = MarcUtil.Xml2Marc(strMarcXml,
                                     true,
                                     "", // this.CurMarcSyntax,
                                     out strOutMarcSyntax,
                                     out strMarc,
                                     out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            if (this.filter == null)
            {
                string strCfgFilePath = this.BiblioDbName + "/cfgs/html.fltx";
                string strContent     = "";
                // 获得配置文件
                // return:
                //		-1	error
                //		0	not found
                //		1	found
                nRet = this.SearchPanel.GetCfgFile(
                    this.ServerUrl,
                    strCfgFilePath,
                    out strContent,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
                if (nRet == 0)
                {
                    strError = "在服务器 " + this.ServerUrl + " 上没有找到配置文件 '" + strCfgFilePath + "' ,因此只能以MARC工作单格式显示书目信息...";
                    string strText = strMarc.Replace((char)31, '^');
                    strText         = strText.Replace(new string((char)30, 1), "<br/>");
                    this.HtmlString = strText;
                    goto ERROR1;
                }


                MyFilterDocument tempfilter = null;

                nRet = PrepareMarcFilter(
                    strContent,
                    //Environment.CurrentDirectory + "\\marc.fltx",
                    out tempfilter,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                this.filter = tempfilter;
            }

            this.ResultString = "";

            // 触发filter中的Record相关动作
            nRet = this.filter.DoRecord(
                null,
                strMarc,
                0,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            this.HtmlString = this.ResultString;

            // 装载册信息
            nRet = LoadItems(this.BiblioRecPath,
                             out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            return(0);

ERROR1:
            return(-1);
        }
예제 #20
0
        // TODO: 预先将AppInfo中值取出,加快速度
        // return:
        //      -1  出错
        //      0   未发生改变
        //      1   发生了改变
        int ModifyField998(ref string strMARC,
                           DateTime now,
                           out string strError)
        {
            strError = "";
            // int nRet = 0;
            bool bChanged = false;

            string strField998 = MarcUtil.GetField(strMARC,
                                                   "998");

            if (strField998 == null)
            {
                strError = "GetField() 998 error";
                return(-1);
            }

            if (String.IsNullOrEmpty(strField998) == true ||
                strField998.Length < 5)
            {
                strField998 = "998  ";
            }


            // state
            string strStateAction = Program.MainForm.AppInfo.GetString(
                "change_biblio_param",
                "state",
                "<不改变>");

            if (strStateAction != "<不改变>")
            {
                string strState = MarcUtil.GetSubfieldContent(strField998,
                                                              "s");

                if (strStateAction == "<增、减>")
                {
                    string strAdd = Program.MainForm.AppInfo.GetString(
                        "change_biblio_param",
                        "state_add",
                        "");
                    string strRemove = Program.MainForm.AppInfo.GetString(
                        "change_biblio_param",
                        "state_remove",
                        "");

                    string strOldState = strState;

                    if (String.IsNullOrEmpty(strAdd) == false)
                    {
                        StringUtil.SetInList(ref strState, strAdd, true);
                    }
                    if (String.IsNullOrEmpty(strRemove) == false)
                    {
                        StringUtil.SetInList(ref strState, strRemove, false);
                    }

                    if (strOldState != strState)
                    {
                        MarcUtil.ReplaceSubfieldContent(ref strField998,
                                                        "s", strState);
                        bChanged = true;
                    }
                }
                else
                {
                    if (strStateAction != strState)
                    {
                        MarcUtil.ReplaceSubfieldContent(ref strField998,
                                                        "s", strStateAction);
                        bChanged = true;
                    }
                }
            }


            // time
            string strTimeAction = Program.MainForm.AppInfo.GetString(
                "change_biblio_param",
                "opertime",
                "<不改变>");

            if (strTimeAction != "<不改变>")
            {
                string strTime = MarcUtil.GetSubfieldContent(strField998,
                                                             "u");
                DateTime time = new DateTime(0);
                if (strTimeAction == "<当前时间>")
                {
                    time = now;
                }
                else if (strTimeAction == "<清除>")
                {
                }
                else if (strTimeAction == "<指定时间>")
                {
                    string strValue = Program.MainForm.AppInfo.GetString(
                        "change_biblio_param",
                        "opertime_value",
                        "");
                    if (String.IsNullOrEmpty(strValue) == true)
                    {
                        strError = "当进行 <指定时间> 方式的修改时,所指定的时间值不能为空";
                        return(-1);
                    }
                    try
                    {
                        time = DateTime.Parse(strValue);
                    }
                    catch (Exception ex)
                    {
                        strError = "无法解析时间字符串 '" + strValue + "' :" + ex.Message;
                        return(-1);
                    }
                }
                else
                {
                    // 不支持
                    strError = "不支持的时间动作 '" + strTimeAction + "'";
                    return(-1);
                }

                string strOldTime = strTime;

                if (strTimeAction == "<清除>")
                {
                    strTime = "";
                }
                else
                {
                    strTime = time.ToString("u");
                }

                if (strOldTime != strTime)
                {
                    MarcUtil.ReplaceSubfieldContent(ref strField998,
                                                    "u", strTime);
                    bChanged = true;
                }
            }


            // batchno
            string strBatchNoAction = Program.MainForm.AppInfo.GetString(
                "change_biblio_param",
                "batchNo",
                "<不改变>");

            if (strBatchNoAction != "<不改变>")
            {
                string strBatchNo = MarcUtil.GetSubfieldContent(strField998,
                                                                "a");

                if (strBatchNo != strBatchNoAction)
                {
                    MarcUtil.ReplaceSubfieldContent(ref strField998,
                                                    "a", strBatchNoAction);
                    bChanged = true;
                }
            }

            if (bChanged == false)
            {
                return(0);
            }

            //
            MarcUtil.ReplaceField(ref strMARC,
                                  "998",
                                  0,
                                  strField998);

            return(1);
        }
예제 #21
0
        // return:
        //      -1  出错
        //      0   未发生改变
        //      1   发生了改变
        int ChangeOneRecord(string strBiblioRecPath,
                            DateTime now,
                            out string strError)
        {
            strError = "";
            int nRet = 0;

            stop.SetMessage("正在处理 " + strBiblioRecPath + " ...");

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

            string[] results   = null;
            byte[]   timestamp = null;
            long     lRet      = Channel.GetBiblioInfos(
                stop,
                strBiblioRecPath,
                "",
                formats,
                out results,
                out timestamp,
                out strError);

            if (lRet == 0)
            {
                return(0);   // not found
            }
            if (lRet == -1)
            {
                return(-1);
            }
            if (results.Length == 0)
            {
                strError = "results length error";
                return(-1);
            }
            string strXml = results[0];

            XmlDocument domOrigin = new XmlDocument();

            try
            {
                domOrigin.LoadXml(strXml);
            }
            catch (Exception ex)
            {
                strError = "装载XML到DOM时发生错误: " + ex.Message;
                return(-1);
            }


            string strMARC          = "";
            string strMarcSyntax    = "";
            string strOutMarcSyntax = "";

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

            // 修改
            // return:
            //      -1  出错
            //      0   未发生改变
            //      1   发生了改变
            nRet = ModifyField998(ref strMARC,
                                  now,
                                  out strError);
            if (nRet == -1)
            {
                return(-1);
            }
            if (nRet == 0)
            {
                return(0);
            }

            // 转换回xml格式
            XmlDocument domMarc = null;

            nRet = MarcUtil.Marc2Xml(strMARC,
                                     strOutMarcSyntax,
                                     out domMarc,
                                     out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            // 合并<dprms:file>元素
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

            nsmgr.AddNamespace("dprms", DpNs.dprms);

            XmlNodeList nodes = domOrigin.DocumentElement.SelectNodes("//dprms:file", nsmgr);

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlElement new_node = domMarc.CreateElement("dprms",
                                                            "file",
                                                            DpNs.dprms);
                domMarc.DocumentElement.AppendChild(new_node);
                DomUtil.SetElementOuterXml(new_node, nodes[i].OuterXml);
            }

            // 保存
            byte[] baNewTimestamp = null;
            string strOutputPath  = "";

            lRet = Channel.SetBiblioInfo(
                stop,
                "change",
                strBiblioRecPath,
                "xml",
                domMarc.DocumentElement.OuterXml,
                timestamp,
                "",
                out strOutputPath,
                out baNewTimestamp,
                out strError);
            if (lRet == -1)
            {
                strError = "保存书目记录 '" + strBiblioRecPath + "' 时出错: " + strError;
                return(-1);
            }

            return(1);
        }
예제 #22
0
        // 注意:上级函数RunScript()已经使用了BeginLoop()和EnableControls()
        // 对每个Iso2709Statis记录进行循环
        // return:
        //      0   普通返回
        //      1   要全部中断
        int DoLoop(out string strError)
        {
            strError = "";
            // int nRet = 0;
            // long lRet = 0;
            Encoding encoding = null;

            if (string.IsNullOrEmpty(this._openMarcFileDialog.EncodingName) == true)
            {
                strError = "尚未选定 ISO2709 文件的编码方式";
                return(-1);
            }

            if (StringUtil.IsNumber(this._openMarcFileDialog.EncodingName) == true)
            {
                encoding = Encoding.GetEncoding(Convert.ToInt32(this._openMarcFileDialog.EncodingName));
            }
            else
            {
                encoding = Encoding.GetEncoding(this._openMarcFileDialog.EncodingName);
            }

#if NO
            // 清除错误信息窗口中残余的内容
            if (this.ErrorInfoForm != null)
            {
                try
                {
                    this.ErrorInfoForm.HtmlString = "<pre>";
                }
                catch
                {
                }
            }
#endif
            ClearErrorInfoForm();

            string strInputFileName = "";

            try
            {
                strInputFileName = this._openMarcFileDialog.FileName;

                Stream file = null;

                try
                {
                    file = File.Open(strInputFileName,
                                     FileMode.Open,
                                     FileAccess.Read);
                }
                catch (Exception ex)
                {
                    strError = "打开文件 " + strInputFileName + " 失败: " + ex.Message;
                    return(-1);
                }

                this.progressBar_records.Minimum = 0;
                this.progressBar_records.Maximum = (int)file.Length;
                this.progressBar_records.Value   = 0;

                /*
                 * stop.OnStop += new StopEventHandler(this.DoStop);
                 * stop.Initial("正在获取ISO2709记录 ...");
                 * stop.BeginLoop();
                 *
                 * EnableControls(false);
                 * */

                try
                {
                    int nCount = 0;

                    for (int i = 0; ; i++)
                    {
                        Application.DoEvents(); // 出让界面控制权

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                DialogResult result = MessageBox.Show(this,
                                                                      "准备中断。\r\n\r\n确实要中断全部操作? (Yes 全部中断;No 中断循环,但是继续收尾处理;Cancel 放弃中断,继续操作)",
                                                                      "Iso2709StatisForm",
                                                                      MessageBoxButtons.YesNoCancel,
                                                                      MessageBoxIcon.Question,
                                                                      MessageBoxDefaultButton.Button3);

                                if (result == DialogResult.Yes)
                                {
                                    strError = "用户中断";
                                    return(-1);
                                }
                                if (result == DialogResult.No)
                                {
                                    return(0);   // 假装loop正常结束
                                }
                                stop.Continue(); // 继续循环
                            }
                        }

                        // 从ISO2709文件中读入一条MARC记录
                        // return:
                        //	-2	MARC格式错
                        //	-1	出错
                        //	0	正确
                        //	1	结束(当前返回的记录有效)
                        //	2	结束(当前返回的记录无效)
                        int nRet = MarcUtil.ReadMarcRecord(file,
                                                           encoding,
                                                           true, // bRemoveEndCrLf,
                                                           true, // bForce,
                                                           out string strMARC,
                                                           out strError);
                        if (nRet == -2 || nRet == -1)
                        {
                            DialogResult result = MessageBox.Show(this,
                                                                  "读入MARC记录(" + nCount.ToString() + ")出错: " + strError + "\r\n\r\n确实要中断当前批处理操作?",
                                                                  "Iso2709StatisForm",
                                                                  MessageBoxButtons.YesNo,
                                                                  MessageBoxIcon.Question,
                                                                  MessageBoxDefaultButton.Button2);
                            if (result == DialogResult.Yes)
                            {
                                break;
                            }
                            else
                            {
                                strError = "读入MARC记录(" + nCount.ToString() + ")出错: " + strError;
                                GetErrorInfoForm().WriteHtml(strError + "\r\n");
                                continue;
                            }
                        }

                        if (nRet != 0 && nRet != 1)
                        {
                            return(0);   // 结束
                        }
                        stop.SetMessage("正在获取第 " + (i + 1).ToString() + " 个 ISO2709 记录");
                        this.progressBar_records.Value = (int)file.Position;

                        // 跳过太短的记录
                        if (string.IsNullOrEmpty(strMARC) == true ||
                            strMARC.Length <= 24)
                        {
                            continue;
                        }

                        if (this._openMarcFileDialog.Mode880 == true &&
                            (this._openMarcFileDialog.MarcSyntax == "usmarc" || this._openMarcFileDialog.MarcSyntax == "<自动>"))
                        {
                            MarcRecord temp = new MarcRecord(strMARC);
                            MarcQuery.ToParallel(temp);
                            strMARC = temp.Text;
                        }

                        // 触发Script中OnRecord()代码
                        if (objStatis != null)
                        {
                            objStatis.MARC = strMARC;
                            objStatis.CurrentRecordIndex = i;

                            StatisEventArgs args = new StatisEventArgs();
                            objStatis.OnRecord(this, args);
                            if (args.Continue == ContinueType.SkipAll)
                            {
                                return(1);
                            }
                            if (args.Continue == ContinueType.Error)
                            {
                                strError = args.ParamString;
                                return(-1);
                            }
                        }

                        nCount++;
                    }

                    /*
                     * Global.WriteHtml(this.webBrowser_batchAddItemPrice,
                     *  "处理结束。共增补价格字符串 " + nCount.ToString() + " 个。\r\n");
                     * */

                    return(0);
                }
                finally
                {
                    /*
                     * EnableControls(true);
                     *
                     * stop.EndLoop();
                     * stop.OnStop -= new StopEventHandler(this.DoStop);
                     * stop.Initial("");
                     * */

                    if (file != null)
                    {
                        file.Close();
                    }
                }
            }
            finally
            {
            }

            // return 0;
        }
예제 #23
0
        public static void TestAddOrUpdateBiblio(ref LibraryContext context)
        {
            string recpath = "test/1";
            // 删除可能存在的记录
            var record = context.Biblios
                         .Where(x => x.RecPath == recpath).FirstOrDefault();

            if (record != null)
            {
                context.Biblios.Remove(record);
                context.SaveChanges();
            }

            // 创建一条新的记录
            {
                MarcRecord marc = new MarcRecord();
                marc.add(new MarcField('$', "200  $atitle1$fauthor1"));
                marc.add(new MarcField('$', "690  $aclass_string1"));
                Biblio biblio = new Biblio {
                    RecPath = recpath
                };
                if (MarcUtil.Marc2Xml(marc.Text,
                                      "unimarc",
                                      out string xml,
                                      out string error) == -1)
                {
                    throw new Exception(error);
                }
                biblio.RecPath = recpath;
                biblio.Xml     = xml;
                biblio.Create(biblio.Xml, biblio.RecPath);
                context.Add(biblio);
                context.SaveChanges();
            }

            context.Dispose();
            context = new LibraryContext();

            // 用于最后阶段比对检索点
            List <Key> save_keys = new List <Key>();

            // 更新上述书目记录
            {
                MarcRecord marc = new MarcRecord();
                marc.add(new MarcField('$', "200  $atitle2$fauthor2"));
                marc.add(new MarcField('$', "690  $aclass_string2"));
                if (MarcUtil.Marc2Xml(marc.Text,
                                      "unimarc",
                                      out string xml,
                                      out string error) == -1)
                {
                    throw new Exception(error);
                }

                var biblio = context.Biblios.SingleOrDefault(c => c.RecPath == recpath)
                             ?? new Biblio {
                    RecPath = recpath
                };

                Debug.Assert(biblio.RecPath == recpath);

                biblio.RecPath = recpath;
                biblio.Xml     = xml;
                biblio.Create(biblio.Xml, biblio.RecPath);

                save_keys.AddRange(biblio.Keys);

                context.AddOrUpdate(biblio);
                context.SaveChanges();
            }

            context.Dispose();
            context = new LibraryContext();

            // 检查检索点是否正确
            var keys = context.Keys
                       .Where(x => x.BiblioRecPath == recpath)
                       .ToList();

            if (keys.Count != save_keys.Count)
            {
                throw new Exception($"keys.Count ({keys.Count}) 和 save_keys.Count ({save_keys.Count})应该相等");
            }

            foreach (var current in save_keys)
            {
                if (Key.IndexOf(keys, current) == -1)
                {
                    throw new Exception($"key '{current.ToString()}' 在检索结果中没有找到");
                }
            }
        }
예제 #24
0
        /// <summary>
        /// 为 MARC 编辑器内的记录加拼音
        /// </summary>
        /// <param name="strCfgXml">拼音配置 XML</param>
        /// <param name="bUseCache">是否使用记录中以前缓存的结果?</param>
        /// <param name="style">风格</param>
        /// <param name="strPrefix">前缀字符串。缺省为空 [暂时没有使用本参数]</param>
        /// <param name="strDuoyinStyle">是否自动选择多音字。auto/first 之一或者组合</param>
        /// <returns>-1: 出错。包括中断的情况; 0: 正常</returns>
        public virtual int AddPinyin(string strCfgXml,
                                     bool bUseCache,    //  = true,
                                     PinyinStyle style, // = PinyinStyle.None,
                                     string strPrefix,
                                     string strDuoyinStyle)
        // bool bAutoSel = false)
        {
            string      strError = "";
            XmlDocument cfg_dom  = new XmlDocument();

            try
            {
                cfg_dom.LoadXml(strCfgXml);
            }
            catch (Exception ex)
            {
                strError = "strCfgXml装载到XMLDOM时出错: " + ex.Message;
                goto ERROR1;
            }


            this.DetailForm.MarcEditor.Enabled = false;

            Hashtable old_selected = (bUseCache == true) ? this.DetailForm.GetSelectedPinyin() : new Hashtable();
            Hashtable new_selected = new Hashtable();

            try
            {
                // PinyinStyle style = PinyinStyle.None;	// 在这里修改拼音大小写风格

                for (int i = 0; i < DetailForm.MarcEditor.Record.Fields.Count; i++)
                {
                    Field field = DetailForm.MarcEditor.Record.Fields[i];

                    List <PinyinCfgItem> cfg_items = null;
                    int nRet = GetPinyinCfgLine(
                        cfg_dom,
                        field.Name,
                        field.Indicator,
                        out cfg_items);
                    if (nRet <= 0)
                    {
                        continue;
                    }

                    string strHanzi            = "";
                    string strNextSubfieldName = "";

                    string strField = field.Text;

                    foreach (PinyinCfgItem item in cfg_items)
                    {
                        for (int k = 0; k < item.From.Length; k++)
                        {
                            if (item.From.Length != item.To.Length)
                            {
                                strError = "配置事项 fieldname='" + item.FieldName + "' from='" + item.From + "' to='" + item.To + "' 其中from和to参数值的字符数不等";
                                goto ERROR1;
                            }

                            string from = new string(item.From[k], 1);
                            string to   = new string(item.To[k], 1);
                            for (int j = 0; ; j++)
                            {
                                // return:
                                //		-1	error
                                //		0	not found
                                //		1	found

                                nRet = MarcUtil.GetSubfield(strField,
                                                            ItemType.Field,
                                                            from,
                                                            j,
                                                            out strHanzi,
                                                            out strNextSubfieldName);
                                if (nRet != 1)
                                {
                                    break;
                                }
                                if (strHanzi.Length <= 1)
                                {
                                    break;
                                }

                                strHanzi = strHanzi.Substring(1);

                                // 2013/6/13
                                if (MarcDetailHost.ContainHanzi(strHanzi) == false)
                                {
                                    continue;
                                }

                                string strPinyin = "";

                                strPinyin = (string)old_selected[strHanzi];
                                if (string.IsNullOrEmpty(strPinyin) == true)
                                {
                                    // 把字符串中的汉字和拼音分离
                                    // return:
                                    //      -1  出错
                                    //      0   用户希望中断
                                    //      1   正常
                                    if (string.IsNullOrEmpty(this.DetailForm.MainForm.PinyinServerUrl) == true ||
                                        this.DetailForm.MainForm.ForceUseLocalPinyinFunc == true)
                                    {
                                        nRet = this.DetailForm.MainForm.HanziTextToPinyin(
                                            this.DetailForm,
                                            true,       // 本地,快速
                                            strHanzi,
                                            style,
                                            strDuoyinStyle,
                                            out strPinyin,
                                            out strError);
                                    }
                                    else
                                    {
                                        // 汉字字符串转换为拼音
                                        // 如果函数中已经MessageBox报错,则strError第一字符会为空格
                                        // return:
                                        //      -1  出错
                                        //      0   用户希望中断
                                        //      1   正常
                                        //      2   结果字符串中有没有找到拼音的汉字
                                        nRet = this.DetailForm.MainForm.SmartHanziTextToPinyin(
                                            this.DetailForm,
                                            strHanzi,
                                            style,
                                            strDuoyinStyle,
                                            out strPinyin,
                                            out strError);
                                    }
                                    if (nRet == -1)
                                    {
                                        new_selected = null;
                                        goto ERROR1;
                                    }
                                    if (nRet == 0)
                                    {
                                        new_selected = null;
                                        strError     = "用户中断。拼音子字段内容可能不完整。";
                                        goto ERROR1;
                                    }
                                }

                                if (new_selected != null && nRet != 2)
                                {
                                    new_selected[strHanzi] = strPinyin;
                                }

                                nRet = MarcUtil.DeleteSubfield(
                                    ref strField,
                                    to,
                                    j);
                                nRet = MarcUtil.InsertSubfield(
                                    ref strField,
                                    from,
                                    j,
                                    new string(MarcUtil.SUBFLD, 1) + to + strPinyin,
                                    1);
                                field.Text = strField;
                            }
                        }
                    }
                }

                if (new_selected != null)
                {
                    this.DetailForm.SetSelectedPinyin(new_selected);
                }
            }
            finally
            {
                this.DetailForm.MarcEditor.Enabled = true;
                this.DetailForm.MarcEditor.Focus();
            }
            return(0);

ERROR1:
            if (string.IsNullOrEmpty(strError) == false)
            {
                if (strError[0] != ' ')
                {
                    MessageBox.Show(this.DetailForm, strError);
                }
            }
            return(-1);
        }
예제 #25
0
        // 将种记录数据从XML格式转换为HTML格式
        // parameters:
        //      strBiblioXml    XML记录,或者 MARC 记录
        //      strSyntax   MARC格式 usmarc/unimarc。如果strBiblioXml 第一字符为 '<' 则本参数可以为空
        public int ConvertBiblioXmlToHtml(
            string strFilterFileName,
            string strBiblioXml,
            string strSyntax,
            string strRecPath,
            out string strBiblio,
            out string strError)
        {
            strBiblio = "";
            strError  = "";
            int nRet = 0;

            LibraryApplication app = this;

            FilterHost host = new FilterHost();

            host.RecPath = strRecPath;
            host.App     = this;

            string strMarc = "";

            if (string.IsNullOrEmpty(strBiblioXml) == false &&
                strBiblioXml[0] == '<')
            {
                // 如果必要,转换为MARC格式,调用filter

                // string strOutMarcSyntax = "";
                // 将MARCXML格式的xml记录转换为marc机内格式字符串
                // parameters:
                //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                nRet = MarcUtil.Xml2Marc(strBiblioXml,
                                         true,
                                         "", // this.CurMarcSyntax,
                                         out strSyntax,
                                         out strMarc,
                                         out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
            else
            {
                strMarc = strBiblioXml;
            }

            LoanFilterDocument filter = null;

            nRet = app.PrepareMarcFilter(
                // host,
                strFilterFileName,
                out filter,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            filter.FilterHost = host;

            try
            {
                nRet = filter.DoRecord(null,
                                       strMarc,
                                       strSyntax,
                                       0,
                                       out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                strBiblio = host.ResultString;
            }
            catch (Exception ex)
            {
                strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                // 2012/3/28
                filter.FilterHost = null;   // 脱钩

                // 归还对象
                app.Filters.SetFilter(strFilterFileName, filter);
            }

            return(0);

ERROR1:
            return(-1);
        }
예제 #26
0
        void GetVolume(string strBiblioRecPath,
                       out string strVolume,
                       out string strPrice)
        {
            strVolume = "";
            strPrice  = "";

            string strXml = (string)this._biblioXmlTable[strBiblioRecPath];

            if (string.IsNullOrEmpty(strXml) == true)
            {
                return;
            }

            string strOutMarcSyntax = "";
            string strMARC          = "";
            string strError         = "";
            int    nRet             = MarcUtil.Xml2Marc(strXml,
                                                        false,
                                                        "",
                                                        out strOutMarcSyntax,
                                                        out strMARC,
                                                        out strError);

            if (nRet == -1)
            {
                return;
            }
            if (string.IsNullOrEmpty(strMARC) == true)
            {
                return;
            }
            MarcRecord record = new MarcRecord(strMARC);

            if (strOutMarcSyntax == "unimarc")
            {
                string h = record.select("field[@name='200']/subfield[@name='h']").FirstContent;
                string i = record.select("field[@name='200']/subfield[@name='i']").FirstContent;
                if (string.IsNullOrEmpty(h) == false && string.IsNullOrEmpty(i) == false)
                {
                    strVolume = h + " . " + i;
                }
                else
                {
                    if (h == null)
                    {
                        h = "";
                    }
                    strVolume = h + i;
                }

                strPrice = record.select("field[@name='010']/subfield[@name='d']").FirstContent;
            }
            else if (strOutMarcSyntax == "usmarc")
            {
                string n = record.select("field[@name='200']/subfield[@name='n']").FirstContent;
                string p = record.select("field[@name='200']/subfield[@name='p']").FirstContent;
                if (string.IsNullOrEmpty(n) == false && string.IsNullOrEmpty(p) == false)
                {
                    strVolume = n + " . " + p;
                }
                else
                {
                    if (n == null)
                    {
                        n = "";
                    }
                    strVolume = n + p;
                }

                strPrice = record.select("field[@name='020']/subfield[@name='c']").FirstContent;
            }
            else
            {
            }
        }
예제 #27
0
        // 这个函数放在外面适当位置实现
        // return:
        //		-2	MARC格式错
        //		-1	一般错误
        //		0	正常
        public static int ConvertByteArrayToMarcRecord(byte[] baRecord,
                                                       Encoding encoding,
                                                       bool bForce,
                                                       out string strMarc,
                                                       out string strError)
        {
            strError = "";
            strMarc  = "";
            int nRet = 0;

            List <byte[]> aField = new List <byte[]>();

            if (bForce == true)
            {
                nRet = MarcUtil.ForceCvt2709ToFieldArray(ref encoding,  //2007/7/16
                                                         baRecord,
                                                         out aField,
                                                         out strError);
            }
            else
            {
                //???
                nRet = MarcUtil.Cvt2709ToFieldArray(
                    encoding,   // 2007/7/16
                    baRecord,
                    out aField,
                    out strError);
            }

            if (nRet == -1)
            {
                return(-1);
            }

            if (nRet == -2)  //marc出错
            {
                return(-2);
            }

            string[] saField = null;
            GetMarcRecordString(aField,
                                encoding,
                                out saField);

            if (saField.Length > 0)
            {
                string strHeader = saField[0];

                if (strHeader.Length > 24)
                {
                    strHeader = strHeader.Substring(0, 24);
                }
                else
                {
                    strHeader = saField[0].PadRight(24, '*');
                }

                strMarc = strHeader;
                for (int i = 1; i < saField.Length; i++)
                {
                    strMarc += saField[i] + new string(MarcUtil.FLDEND, 1);
                }

                return(0);
            }

            return(0);
        }
예제 #28
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);
        }
예제 #29
0
        public virtual void RemovePinyin(string strCfgXml)
        {
            string      strError = "";
            XmlDocument cfg_dom  = new XmlDocument();

            try
            {
                cfg_dom.LoadXml(strCfgXml);
            }
            catch (Exception ex)
            {
                strError = "strCfgXml装载到XMLDOM时出错: " + ex.Message;
                goto ERROR1;
            }

            this.DetailForm.MarcEditor.Enabled = false;

            try
            {
                for (int i = 0; i < DetailForm.MarcEditor.Record.Fields.Count; i++)
                {
                    Field field = DetailForm.MarcEditor.Record.Fields[i];

                    List <PinyinCfgItem> cfg_items = null;
                    int nRet = GetPinyinCfgLine(
                        cfg_dom,
                        field.Name,
                        field.Indicator,    // TODO: 可以不考虑指示符的情况,扩大删除的搜寻范围
                        out cfg_items);
                    if (nRet <= 0)
                    {
                        continue;
                    }

                    string strField = field.Text;
                    bool   bChanged = false;
                    foreach (PinyinCfgItem item in cfg_items)
                    {
                        for (int k = 0; k < item.To.Length; k++)
                        {
                            string to = new string(item.To[k], 1);
                            for (; ;)
                            {
                                // 删除一个子字段
                                // 其实原来的ReplaceSubfield()也可以当作删除来使用
                                // return:
                                //      -1  出错
                                //      0   没有找到子字段
                                //      1   找到并删除
                                nRet = MarcUtil.DeleteSubfield(
                                    ref strField,
                                    to,
                                    0);
                                if (nRet != 1)
                                {
                                    break;
                                }
                                bChanged = true;
                            }
                        }
                    }
                    if (bChanged == true)
                    {
                        field.Text = strField;
                    }
                }
            }
            finally
            {
                this.DetailForm.MarcEditor.Enabled = true;
                this.DetailForm.MarcEditor.Focus();
            }
            return;

ERROR1:
            MessageBox.Show(this.DetailForm, strError);
        }
예제 #30
0
        public static void TestLeftJoin(LibraryContext context)
        {
            // *** 第一步,准备数据
            string recpath = "test/1";

            {
                // 删除可能存在的记录
                var record = context.Biblios
                             .Where(x => x.RecPath == recpath).FirstOrDefault();
                if (record != null)
                {
                    context.Biblios.Remove(record);
                    context.SaveChanges();
                }

                // 创建一条新的记录
                Biblio biblio = new Biblio {
                    RecPath = recpath
                };

                MarcRecord marc = new MarcRecord();
                marc.add(new MarcField('$', "200  $atitle$fauthor"));
                marc.add(new MarcField('$', "690  $aclass_string1"));
                marc.add(new MarcField('$', "690  $aclass_string2"));

                if (MarcUtil.Marc2Xml(marc.Text,
                                      "unimarc",
                                      out string xml,
                                      out string error) == -1)
                {
                    throw new Exception(error);
                }
                biblio.RecPath = recpath;
                biblio.Xml     = xml;
                biblio.Create(biblio.Xml, biblio.RecPath);
                context.Biblios.Add(biblio);
                context.SaveChanges();
            }

            // *** 第二步,验证 left join
            {
                var biblios = context.Biblios.Where(x => x.RecPath == recpath)
                              .LeftJoin(
                    context.Keys,
                    biblio => new { recpath = biblio.RecPath, type = "class_clc", index = 0 },
                    key => new { recpath = key.BiblioRecPath, type = key.Type, index = key.Index },
                    (biblio, key) => new
                {
                    biblio.RecPath,
                    Class = key.Text,
                }
                    ).ToList();

                if (biblios.Count != 1)
                {
                    throw new Exception("left join 得到的元素个数不正确");
                }

                if (biblios[0].Class != "class_string1")
                {
                    throw new Exception("得到的分类号字符串不正确");
                }

                /*
                 * StringBuilder text = new StringBuilder();
                 * foreach (var biblio in biblios)
                 * {
                 *  text.AppendLine($"bibliorecpath={biblio.RecPath}, class_clc={biblio.Class}");
                 * }
                 *
                 * return text.ToString();
                 */
            }
        }