示例#1
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;
            }
        }
示例#2
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++;
            }
        }
示例#3
0
文件: MarcForm.cs 项目: renyh/dp2mini
        // 开始转bdf
        private void button_tobdf_Click(object sender, EventArgs e)
        {
            if (textBox_isofilename.Text.Trim() == "")
            {
                MessageBox.Show(this, "尚未选择iso数据文件");
                return;
            }

            if (comboBox_source.Text.Trim() == "")
            {
                MessageBox.Show(this, "尚未选择数据来源系统");
                return;
            }

            if (this.comboBox_source.Text.ToUpper() == "DT1000")
            {
                if (this.Location == "")
                {
                    MessageBox.Show(this, "请输入馆藏地");
                    return;
                }

                if (this.BookType == "")
                {
                    MessageBox.Show(this, "请输入图书类型");
                    return;
                }
            }



            // 选择保存的bdf文件
            SaveFileDialog dlg = new SaveFileDialog()
            {
                Title            = "书目转储文件名",
                Filter           = "书目转储文件(*.bdf)|*.bdf",
                RestoreDirectory = true
            };

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

            // bdf文件是一个xml结构
            string bdfFile = dlg.FileName;

            XmlTextWriter _writer = null;

            _writer = new XmlTextWriter(bdfFile, Encoding.UTF8)
            {
                Formatting  = Formatting.Indented,
                Indentation = 4
            };
            _writer.WriteStartDocument();
            _writer.WriteStartElement("dprms", "collection", DpNs.dprms);
            _writer.WriteAttributeString("xmlns", "dprms", null, DpNs.dprms);

            // 输出一个错误信息文件
            FileInfo fileInfo      = new FileInfo(bdfFile);
            string   strSourceDir  = fileInfo.DirectoryName;
            string   errorFilename = strSourceDir + "\\~error.txt";

            long         errorCount1 = 0;
            StreamWriter sw_error    = new StreamWriter(errorFilename,
                                                        false, // append
                                                        Encoding.UTF8);

            // 源iso文件
            string isoFileName = this.textBox_isofilename.Text.Trim();

            // 用当前日期作为批次号
            string strBatchNo = DateTime.Now.ToString("yyyyMMdd");
            int    nIndex     = 0;
            string strError   = "";

            MarcLoader loader = new MarcLoader(isoFileName, this.Encoding, "marc", null);

            foreach (string marc in loader)
            {
                MarcRecord record = new MarcRecord(marc);

                string strISBN = record.select("field[@name='010']/subfield[@name='a']").FirstContent;
                strISBN = string.IsNullOrEmpty(strISBN) ? "" : strISBN;

                string strTitle = record.select("field[@name='200']/subfield[@name='a']").FirstContent;
                strTitle = string.IsNullOrEmpty(strTitle) ? "" : strTitle;

                string strSummary = strISBN + "\t" + strTitle;


                // 转换回XML
                XmlDocument domMarc = null;
                int         nRet    = MarcUtil.Marc2Xml(marc,
                                                        this.MarcSyntax,//this.m_strBiblioSyntax,
                                                        out domMarc,
                                                        out strError);
                if (nRet == -1)
                {
                    errorCount1++;
                    sw_error.WriteLine("!!!异常Marc2Xml()" + strError);
                    return;
                }

                // 写<record>
                _writer.WriteStartElement("dprms", "record", DpNs.dprms);

                // 写<biblio>
                _writer.WriteStartElement("dprms", "biblio", DpNs.dprms);

                // 把marc xml写入<biblio>下级
                domMarc.WriteTo(_writer);
                // </<biblio>>
                _writer.WriteEndElement();

                #region 关于价格

                bool bPriceError = false;

                // *** 从010$d中取得价格
                string strErrorPrice = "";
                string strCataPrice  = record.select("field[@name='010']/subfield[@name='d']").FirstContent;
                string strOldPrice   = strCataPrice;

                // marc中不存在010$d价格
                if (string.IsNullOrEmpty(strCataPrice) == true)
                {
                    strCataPrice = "CNY0";
                    sw_error.WriteLine(nIndex + "\t" + strSummary + "\t不存在010$d价格子字段。");

                    bPriceError = true;
                }
                else
                {
                    // 如果不在合法的价格格式
                    if (!Regex.IsMatch(strCataPrice, @"^(CNY)?\d+\.?\d{0,2}$"))
                    {
                        //将价格中含有的汉字型数值替换为数字
                        strCataPrice = ParsePrice(strCataPrice);
                        if (strCataPrice != strOldPrice)
                        {
                            strErrorPrice = strOldPrice;
                            sw_error.WriteLine(nIndex + "\t" + strSummary + "\t价格字符串 '" + strOldPrice + "' 被自动修改为 '" + strCataPrice + "'");
                            bPriceError = true;
                        }

                        //已知格式价格内容转换
                        string temp1 = strCataPrice;
                        strCataPrice = CorrectPrice(strCataPrice);
                        if (strCataPrice != temp1)
                        {
                            strErrorPrice = strOldPrice;
                            sw_error.WriteLine(nIndex + "\t" + strSummary + "\t价格字符串 '" + strOldPrice + "' 被自动修改为 '" + strCataPrice + "'");
                            bPriceError = true;
                        }
                    }

                    List <string> temp = VerifyPrice(strCataPrice);
                    if (temp.Count > 0)
                    {
                        string temp1 = strCataPrice;
                        CorrectPrice(ref strCataPrice);
                        if (temp1 != strCataPrice)
                        {
                            if (IsPriceCorrect(strCataPrice) == true)
                            {
                                sw_error.WriteLine(nIndex + "\t" + strSummary + "\t价格字符串 '" + strOldPrice + "' 被自动修改为 '" + strCataPrice + "'");
                                bPriceError = true;
                            }
                            else
                            {
                                strCataPrice  = "CNY0";
                                strErrorPrice = strOldPrice;
                                sw_error.WriteLine(nIndex + "\t" + strSummary + "\t价格字符串 '" + strOldPrice + "' 无法被自动修改,默认为 CNY0");
                                bPriceError = true;
                            }
                        }
                        else
                        {
                            strCataPrice  = "CNY0";
                            strErrorPrice = strOldPrice;
                            sw_error.WriteLine(nIndex + "\t" + strSummary + "\t价格字符串 '" + strOldPrice + "' 无法被自动修改,默认为 CNY0");
                            bPriceError = true;
                        }
                    }

                    // 如果不是CNY开头的,加CNY
                    if (!strCataPrice.StartsWith("CNY"))
                    {
                        strCataPrice = "CNY" + strCataPrice;
                        sw_error.WriteLine(nIndex + ":" + strSummary + "*** 价格字符串 '" + strCataPrice + "' 不含有币种前缀,自动添加为'CNY'\r\n");
                        bPriceError = true;
                    }
                }

                // 如果价格经过修复,错误记录数增加1
                if (bPriceError == true)
                {
                    errorCount1++;
                }

                #endregion

                #region 从905$d$e取得索书号

                // 905$d 中图法大类
                string str905d = record.select("field[@name='905']/subfield[@name='d']").FirstContent;
                if (String.IsNullOrEmpty(str905d) == true)
                {
                    strError = nIndex + "\t" + strSummary + "\t905字段不存在$d子字段";
                    sw_error.WriteLine(strError);
                }

                // 905$e 种次号
                string str905e = record.select("field[@name='905']/subfield[@name='e']").FirstContent;
                if (String.IsNullOrEmpty(str905e) == true)
                {
                    strError = nIndex + "\t" + strSummary + "\t905字段不存在$e子字段";
                    sw_error.WriteLine(strError);
                }

                // 如果缺索取号记一笔
                if (bPriceError == false)
                {
                    if (string.IsNullOrEmpty(str905d) == true || string.IsNullOrEmpty(str905e) == true)
                    {
                        errorCount1++;
                    }
                }

                #endregion


                // 册条码是放在906$h字段的
                MarcNodeList subfield_690h = record.select("field[@name='906']/subfield[@name='h']");


                int index = 0;
                // <itemCollection>
                _writer.WriteStartElement("dprms", "itemCollection", DpNs.dprms);
                foreach (MarcNode node in subfield_690h)
                {
                    index++;
                    string strBarcode = node.Content;
                    // 册条码号为空,则不创建册信息元素
                    if (string.IsNullOrEmpty(strBarcode))
                    {
                        continue;
                    }

                    _writer.WriteStartElement("dprms", "item", DpNs.dprms);


                    strBarcode = strBarcode.Trim();
                    _writer.WriteElementString("barcode", strBarcode);


                    string strLocation = this.Location;  //DT1000使用界面输入的值
                    _writer.WriteElementString("location", strLocation);


                    if (!string.IsNullOrEmpty(strCataPrice))
                    {
                        _writer.WriteElementString("price", strCataPrice);
                    }

                    if (!string.IsNullOrEmpty(strErrorPrice))
                    {
                        _writer.WriteElementString("comment", "原价格:" + strErrorPrice);
                    }

                    string strBookType = this.BookType;//DT1000使用界面输入的值
                    _writer.WriteElementString("bookType", strBookType);

                    if (!string.IsNullOrEmpty(str905d) && !string.IsNullOrEmpty(str905e))
                    {
                        _writer.WriteElementString("accessNo", str905d + "/" + str905e);
                    }
                    else
                    {
                        //strError = nIndex + "\t" + strSummary + "\t册记录'" + strBarcode + "'不含有 索取号 内容";
                        //sw_error.WriteLine(strError);
                    }

                    _writer.WriteElementString("batchNo", strBatchNo);//

                    _writer.WriteEndElement();
                }
                //</itemCollection>
                _writer.WriteEndElement();

                //</record>
                _writer.WriteEndElement();



                nIndex++;
                this._mainForm.SetStatusMessage(nIndex.ToString() + " " + strSummary);

                Application.DoEvents();
            }



            //</collection>
            _writer.WriteEndElement();
            _writer.WriteEndDocument();
            _writer.Close();
            _writer = null;


            this._mainForm.SetStatusMessage("处理完成,共处理" + nIndex.ToString() + "条。");

            string strMsg = "数据转换处理结束。请到dp2内务使用【批处理】-【从书目转储文件导入】功能将转换的 书目转储文件 导入到目标书目库。";

            MessageBox.Show(this, strMsg);

            if (sw_error != null)
            {
                strMsg = "共处理'" + nIndex + "'条MARC记录,其中有 " + errorCount1.ToString() + " 条记录中有错误信息。";

                sw_error.WriteLine(strMsg);
                sw_error.Close();
                sw_error = null;
            }
        }