欢迎您来到 数字平台。 您尚未登录。[登录] [注册新用户]
当前位置: 论坛首页 / 栏目 产品与服务 / 文章 465

点击:10262[回复顶层] [树状] [简明]


文章数: 6
积分: 60
注册时间: 2009/2/5
[回复留言] [回复(需要先登录)] [引用(需要先登录)]普通文章第 1 楼
文章id: 465
dp2circulation_marc_autogen.cs



// dp2circulation MARC 编目自动创建数据C#脚本程序
// 最后修改时间: 2009/3/5
// 修改情况:
// 1) 2008/10/17 增加维护102对照表、210对照表的功能
// 2) 2008/12/18 "7*1$a <-- 200$f"增加了可以插入到711字段的能力

using System;
using System.Windows.Forms;
using System.IO;
using System.Text;

using DigitalPlatform;
using DigitalPlatform.Xml;
using DigitalPlatform.Marc;
using DigitalPlatform.IO;
using DigitalPlatform.GcatClient;
using DigitalPlatform.Text;

using DigitalPlatform.Script;

using dp2Circulation;

public class MyHost : DetailHost
{
    DigitalPlatform.GcatClient.Channel GcatChannel = null;

    string[] cfgFields = new string[] {
  "200(a-9)",
  "701(a-9)",
  "711(a-9)",
  "702(a-9)",
  "712(a-9)"
 };

    public override void Main(object sender, GenerateDataEventArgs e)
    {

        Field curfield = this.DetailForm.MarcEditor.FocusedField;

        ScriptActionCollection actions = new ScriptActionCollection();

        bool bActive = false;

        if (!(sender is EntityEditForm || sender is EntityControl))
        {

            // 加拼音
            actions.NewItem("加拼音", "给.....加拼音", "AddPinyin", false);

            // 规整ISBN为13
            if (curfield != null && curfield.Name == "010")
                bActive = true;
            else
                bActive = false;
            actions.NewItem("规整ISBN-13", "对010$a中ISBN进行规整", "HyphenISBN_13", bActive);

            // 规整ISBN为10
            if (curfield != null && curfield.Name == "010")
                bActive = true;
            else
                bActive = false;
            actions.NewItem("规整ISBN-10", "对010$a中ISBN进行规整", "HyphenISBN_10", bActive);


            // 102国家代码 地区代码
            if (curfield != null && curfield.Name == "102")
                bActive = true;
            else
                bActive = false;
            actions.NewItem("102$a$b <-- 010$a", "根据010$a中ISBN出版社代码, 自动创建102字段$a国家代码$b地区代码", "Add102", bActive);

            // 410 <-- 225
            if (curfield != null &&
                (curfield.Name == "225"
                || curfield.Name == "410"))
                bActive = true;
            else
                bActive = false;
            actions.NewItem("410 <-- 225", "将225$a内容加入410  $1200  $a", "Copy225To410", bActive);

            // 7*1$a <-- 200$f
            if (curfield != null &&
                (curfield.Name == "701"
                || curfield.Name == "711"))
                bActive = true;
            else
                bActive = false;

            actions.NewItem("7*1$a <-- 200$f", "将200$f内容加入701/711字段$a", "Copy200fTo7x1a", bActive);

            // 7*2$a <-- 200$g
            if (curfield != null &&
                (curfield.Name == "702"
                || curfield.Name == "712"))
                bActive = true;
            else
                bActive = false;
            actions.NewItem("7*2$a <-- 200$g", "将200$g内容加入702/712字段$a", "Copy200gTo7x2a", bActive);


            // 905$d <-- 690$a
            if (curfield != null &&
                (curfield.Name == "905" || curfield.Name == "690"))
                bActive = true;
            else
                bActive = false;
            actions.NewItem("905$d <-- 690$a", "将690$a内容加入905字段$d", "Copy690aTo905d", bActive);

            /*
            // 加入著者号
            if (curfield != null && curfield.Name == "905")
                bActive = true;
            else
                bActive = false;

            actions.NewItem("加入著者号", "根据701/711/702/712$a内容, 创建905$e", "AddAuthorNumber", bActive);

            // 加入种次号
            if (curfield != null && curfield.Name == "905" && this.DetailForm.MarcEditor.FocusedSubfieldName == 'd')
                bActive = true;
            else
                bActive = false;
            actions.NewItem("加入种次号", "根据905$d内容, 创建905$e", "AddZhongcihao", bActive);

            //  维护种次号
            actions.NewItem("维护种次号", "根据905$d内容中的类号, 出现维护种次号的界面", "ManageZhongcihao", false);
             * */

            // 出版地
            if (curfield != null && curfield.Name == "210")
                bActive = true;
            else
                bActive = false;
            actions.NewItem("210$a$c <-- 010$a", "根据010$a中ISBN出版社代码, 自动创建出版社子字段210$a$c", "AddPublisher", bActive);


            // 维护 102 国家代码 地区代码
            bActive = false;
            actions.NewItem("维护102对照表", "ISBN出版社代码 和 102字段$a国家代码$b地区代码 的对照表", "Manage102", bActive);

            // 维护 210 出版地 出版社
            bActive = false;
            actions.NewItem("维护210对照表", "ISBN出版社代码 和 210字段$a出版地$c出版社名 的对照表", "Manage210", bActive);

        }
        else
        {
            // 创建索取号
            bActive = false;
            if (sender is EntityEditForm)
                bActive = true;
            actions.NewItem("创建索取号", "为册记录创建索取号", "CreateCallNumber", bActive);

            // 管理索取号
            bActive = false;
            actions.NewItem("管理索取号", "为册记录管理索取号", "ManageCallNumber", bActive);
        }

        ScriptActionMenuDlg dlg = new ScriptActionMenuDlg();

        dlg.Actions = actions;
        if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
            dlg.AutoRun = false;
        else
            dlg.AutoRun = this.DetailForm.MainForm.AppInfo.GetBoolean("detailform", "gen_auto_run", false);
        // dlg.StartPosition = FormStartPosition.CenterScreen;

        this.DetailForm.MainForm.AppInfo.LinkFormState(dlg, "gen_data_dlg_state");
        dlg.ShowDialog();
        this.DetailForm.MainForm.AppInfo.UnlinkFormState(dlg);


        this.DetailForm.MainForm.AppInfo.SetBoolean("detailform", "gen_auto_run", dlg.AutoRun);

        if (dlg.DialogResult == DialogResult.OK)
        {
            this.Invoke(dlg.SelectedAction.ScriptEntry, sender, e);
        }
    }


    void AddPinyin()
    {
        this.DetailForm.MarcEditor.Enabled = false;

        try
        {

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

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

                string strFrom = "";
                string strTo = "";
                int nRet = GetPinyinCfgLine(field.Name,
                    out strFrom,
                    out strTo);
                if (nRet != 1)
                    continue;

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

                string strField = field.Text;

                for (int j = 0; ; j++)
                {

                    // return:
                    //  -1 error
                    //  0 not found
                    //  1 found

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

                    strHanzi = strHanzi.Substring(1);

                    string strPinyin;
                    string strError = "";

                    // 把字符串中的汉字和拼音分离
                    // return:
                    //      -1  出错
                    //      0   用户希望中断
                    //      1   正常

                    nRet = this.DetailForm.HanziTextToPinyin(
                        true, // 本地,快速
                        strHanzi,
                        style,
                        out strPinyin,
                        out strError);
                    if (nRet == -1)
                    {
                        MessageBox.Show(this.DetailForm, strError);
                        break;
                    }
                    if (nRet == 0)
                    {
                        MessageBox.Show(this.DetailForm, "用户中断。拼音子字段内容可能不完整。");
                        return;
                    }

                    nRet = MarcUtil.ReplaceSubfield(
                        ref strField,
                        strTo,
                        j,
                        strTo + strPinyin);

                    field.Text = strField;

                }

            }

        }
        finally
        {
            this.DetailForm.MarcEditor.Enabled = true;
            this.DetailForm.MarcEditor.Focus();

        }


    }

    int GetPinyinCfgLine(string strFieldName,
        out string strFrom,
        out string strTo)
    {
        strFrom = "";
        strTo = "";
        for (int i = 0; i < cfgFields.Length; i++)
        {
            string strLine = cfgFields[i];
            string strName = strLine.Substring(0, 3);
            if (strName == strFieldName)
            {
                string strRight = strLine.Substring(3).Trim();

                if (strRight.Length == 0)
                    return -1;
                if (strRight[0] == '(')
                    strRight = strRight.Substring(1).Trim();
                if (strRight.Length == 0)
                    return -1;
                if (strRight[strRight.Length - 1] == ')')
                    strRight = strRight.Substring(0, strRight.Length - 1).Trim();
                if (strRight.Length == 0)
                    return -1;

                int nRet = strRight.IndexOf("-");
                if (nRet == -1)
                    return -1;
                strFrom = strRight.Substring(0, nRet).Trim(); strTo = strRight.Substring(nRet + 1).Trim();
                return 1;

            }

        }


        return 0;
    }

    void Copy200fTo7x1a()
    {
        Copy200gfTo7xxa("f", "701,711");
    }

    void Copy200gTo7x2a()
    {
        Copy200gfTo7xxa("g", "702,712");
    }

    // 取列表值的第一个
    static string FirstOf(string strParts)
    {
        string[] parts = strParts.Split(new char[] { ',' });
        if (parts.Length > 0)
            return parts[0];

        return strParts;
    }

    void Copy200gfTo7xxa(string strFromSubfield, string strToFields)
    {
        Field field_200 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("200", 0);
        SubfieldCollection subfields_200 = field_200.Subfields;

        Subfield subfield_f = subfields_200[strFromSubfield];

        if (subfield_f == null)
        {
            MessageBox.Show(this.DetailForm, "200$" + strFromSubfield + "不存在");
            return;
        }

        string strToField = FirstOf(strToFields);

        string strContent = subfield_f.Value;

        // 看看当前活动字段是不是701
        Field field_701 = null;

        field_701 = this.DetailForm.MarcEditor.FocusedField;
        if (field_701 != null)
        {
            if (StringUtil.IsInList(field_701.Name, strToFields) == true)
            {
                strToField = field_701.Name;
            }
            else
                field_701 = null;
        }


        if (field_701 == null)
        {
            field_701 = this.DetailForm.MarcEditor.Record.Fields.GetOneField(strToField, 0);

            if (field_701 == null)
            {
                field_701 = this.DetailForm.MarcEditor.Record.Fields.Add(strToField, "  ", "", true);
            }

        }


        if (field_701 == null)
            throw (new Exception("error ..."));


        Subfield subfield_701a = field_701.Subfields["a"];
        if (subfield_701a == null)
        {
            subfield_701a = new Subfield();
            subfield_701a.Name = "a";
        }

        subfield_701a.Value = strContent;
        field_701.Subfields["a"] = subfield_701a;

    }

    void AddAuthorNumber()
    {
        string strAuthor = "";

        strAuthor = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("701", "a");

        if (strAuthor != "")
            goto BEGIN;

        strAuthor = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("711", "a");

        if (strAuthor != "")
            goto BEGIN;

        strAuthor = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("702", "a");

        if (strAuthor != "")
            goto BEGIN;

        strAuthor = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("712", "a");

        if (strAuthor == "")
        {
            MessageBox.Show(this.DetailForm, "701/711/702/712中均未发现&a,无法处理");
            return;
        }

    BEGIN:


        string strGcatWebServiceUrl = this.DetailForm.MainForm.GcatServerUrl;   // "http://dp2003.com/dp2libraryws/gcat.asmx";


        string strNumber = "";
        string strError = "";

        // 获得著者号
        // return:
        //      -1  error
        //      0   canceled
        //      1   succeed
        int nRet = GetGcatAuthorNumber(strGcatWebServiceUrl,
            strAuthor,
            out strNumber,
            out strError);
        if (nRet == -1)
            goto ERROR1;

        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("905", "e", strNumber);
        return;
    ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }


    void AddZhongcihao()
    {
        string strError = "";
        ZhongcihaoForm dlg = new ZhongcihaoForm();

        try
        {
            string strClass = "";
            string strNumber = "";
            int nRet = 0;

            strClass = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("905", "d");

            if (strClass == "")
            {
                MessageBox.Show(this.DetailForm, "记录中不存在905$d子字段,因此无法加种次号");
                return;
            }

            string strExistNumber = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("905", "e");

            // dlg.MdiParent = this.DetailForm.MainForm;
            dlg.MainForm = this.DetailForm.MainForm;
            dlg.TopMost = true;
            dlg.MyselfBiblioRecPath = this.DetailForm.BiblioRecPath;

            // dlg.ClassNumber = strClass;
            // dlg.BiblioDbName = this.DetailForm.BiblioDbName;


            dlg.Show();


            // return:
            //      -1  error
            //      0   canceled
            //      1   succeed
            nRet = dlg.GetNumber(
                ZhongcihaoStyle.Seed,
                        strClass,
                        this.DetailForm.BiblioDbName,
                        out strNumber,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("905", "e", strNumber);
            return;

        }
        catch (Exception ex)
        {
            strError = ex.Message;
            goto ERROR1;
        }
        finally
        {
            dlg.Close();
        }

    ERROR1:
        MessageBox.Show(this.DetailForm, strError);

 

    }

    // 维护种次号
    void ManageZhongcihao()
    {
        string strError = "";
        ZhongcihaoForm dlg = new ZhongcihaoForm();

        string strClass = "";
        int nRet = 0;

        strClass = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("905", "d");

        dlg.MdiParent = this.DetailForm.MainForm;
        dlg.MainForm = this.DetailForm.MainForm;
        dlg.TopMost = true;
        dlg.AutoBeginSearch = true;

        dlg.ClassNumber = strClass;
        dlg.BiblioDbName = this.DetailForm.BiblioDbName;

        dlg.Show();

    }

    // 加入出版地、出版者
    void AddPublisher()
    {
        string strError = "";
        string strISBN = "";

        int nRet = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a");

        if (strISBN.Trim() == "")
        {
            strError = "记录中不存在010$a子字段,因此无法加出版社子字段";
            goto ERROR1;
        }

 

        // 切割出 出版社 代码部分
        string strPublisherNumber = "";
        nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
            out strPublisherNumber,
            out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        string strValue = "";

        nRet = this.DetailForm.GetPublisherInfo(strPublisherNumber,
            out strValue,
            out strError);
        if (nRet == -1)
            goto ERROR1;

        if (nRet == 0 || strValue == "")
        {
            // 创建新条目
            strValue = InputDlg.GetInput(
                this.DetailForm,
                null,
                "请输入ISBN出版社号 '" + strPublisherNumber + "' 对应的出版社名称(格式 出版地:出版社名):",
                "出版地:出版社名");
            if (strValue == null)
                return; // 放弃整个操作

            nRet = this.DetailForm.SetPublisherInfo(strPublisherNumber,
                strValue,
                out strError);
            if (nRet == -1)
                goto ERROR1;

        }

        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strName = "";
        string strCity = "";
        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strName = strValue;
        }
        else
        {
            strCity = strValue.Substring(0, nRet);
            strName = strValue.Substring(nRet + 1);
        }

        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("210", "a", strCity);
        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("210", "c", strName);


        return;

    ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }

    // 维护210对照关系
    // 2008/10/17 new add
    void Manage210()
    {
        string strError = "";
        string strISBN = "";
        int nRet = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a").Trim();

        string strPublisherNumber = "";

        if (String.IsNullOrEmpty(strISBN) == false)
        {
            // 切割出 出版社 代码部分
            nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
                out strPublisherNumber,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
        }

        if (String.IsNullOrEmpty(strPublisherNumber) == true)
            strPublisherNumber = "978-7-?";

        strPublisherNumber = InputDlg.GetInput(
                this.DetailForm,
                "维护210对照表 -- 第1步",
                "请输入ISBN中出版社号码部分:",
                strPublisherNumber);
        if (strPublisherNumber == null)
            return; // 放弃整个操作

        string strValue = "";

        nRet = this.DetailForm.GetPublisherInfo(strPublisherNumber,
            out strValue,
            out strError);
        if (nRet == -1)
            goto ERROR1;

        if (nRet == 0 || strValue == "")
        {
            strValue = "出版地:出版社名";
        }

        // 创建新条目
        strValue = InputDlg.GetInput(
            this.DetailForm,
            "维护210对照表 -- 第2步",
            "请输入ISBN出版社号码 '" + strPublisherNumber + "' 对应的UNIMARC 210$a$c参数(格式 出版地:出版社名):",
            strValue);
        if (strValue == null)
            return; // 放弃整个操作

        if (strValue == "")
            goto DOSAVE;


        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strName = "";
        string strCity = "";
        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strError = "输入的内容中缺少冒号";
            goto ERROR1;
            // strName = strValue;
        }
        else
        {
            strCity = strValue.Substring(0, nRet);
            strName = strValue.Substring(nRet + 1);
        }

        strValue = strCity + ":" + strName;

    DOSAVE:
        nRet = this.DetailForm.SetPublisherInfo(strPublisherNumber,
            strValue,
            out strError);
        if (nRet == -1)
            goto ERROR1;

        return;
    ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }

 

    void HyphenISBN_13()
    {
        HyphenISBN(true);
    }


    void HyphenISBN_10()
    {
        HyphenISBN(false);
    }


    void HyphenISBN(bool bForce13)
    {
        string strError = "";
        string strISBN = "";
        int nRet = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a");

        if (strISBN.Trim() == "")
        {
            MessageBox.Show(this.DetailForm, "记录中不存在010$a子字段,因此无法进行规整");
            return;
        }

        nRet = this.DetailForm.MainForm.LoadIsbnSplitter(true, out strError);
        if (nRet == -1)
            goto ERROR1;

        string strResult = "";

        nRet = this.DetailForm.MainForm.IsbnSplitter.IsbnInsertHyphen(strISBN,
            bForce13 == true ? "force13,strict" : "force10,strict",
                    out strResult,
                    out strError);
        if (nRet == -1)
            goto ERROR1;

        if (nRet == 1)
        {
            DialogResult result = MessageBox.Show(this.DetailForm,
                "原ISBN '" + strISBN + "'加工成 '" + strResult + "' 后发现校验位有变化。\r\n\r\n是否接受修改?",
                "规整ISBN",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);
            if (result != DialogResult.Yes)
                return;

        }

        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("010", "a", strResult);

        return;

    ERROR1:
        MessageBox.Show(this.DetailForm, strError);

    }

    void Add102()
    {
        string strError = "";
        string strISBN = "";
        int nRet = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a");

        if (strISBN.Trim() == "")
        {
            strError = "记录中不存在010$a子字段,因此无法加102$a$b";
            goto ERROR1;
        }

        // 切割出 出版社 代码部分
        string strPublisherNumber = "";
        nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
            out strPublisherNumber,
            out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        string strValue = "";

        nRet = this.DetailForm.Get102Info(strPublisherNumber,
            out strValue,
            out strError);
        if (nRet == -1)
            goto ERROR1;

        if (nRet == 0 || strValue == "")
        {
            // 创建新条目
            strValue = InputDlg.GetInput(
                this.DetailForm,
                null,
                "请输入ISBN出版社号码 '" + strISBN + "' 对应的UNIMARC 102$a$b参数(格式 国家代码[2位]:城市代码[6位]):",
                "国家代码[2位]:城市代码[6位]");
            if (strValue == null)
                return; // 放弃整个操作

            nRet = this.DetailForm.Set102Info(strPublisherNumber,
                strValue,
                out strError);
            if (nRet == -1)
                goto ERROR1;

        }

        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strCountryCode = "";
        string strCityCode = "";
        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strCountryCode = strValue;

            if (strCountryCode.Length != 2)
            {
                strError = "国家代码 '" + strCountryCode + "' 应当为2字符";
                goto ERROR1;
            }
        }
        else
        {
            strCountryCode = strValue.Substring(0, nRet);
            strCityCode = strValue.Substring(nRet + 1);
            if (strCountryCode.Length != 2)
            {
                strError = "冒号前面的国家代码部分 '" + strCountryCode + "' 应当为2字符";
                goto ERROR1;
            }
            if (strCityCode.Length != 6)
            {
                strError = "冒号后面的城市代码部分 '" + strCityCode + "' 应当为6字符";
                goto ERROR1;
            }
        }

        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("102", "a", strCountryCode);
        this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("102", "b", strCityCode);


        return;

    ERROR1:
        MessageBox.Show(this.DetailForm, strError);


    }

    // 维护102对照关系
    void Manage102()
    {
        string strError = "";
        string strISBN = "";
        int nRet = 0;

        strISBN = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("010", "a").Trim();

        string strPublisherNumber = "";

        if (String.IsNullOrEmpty(strISBN) == false)
        {
            // 切割出 出版社 代码部分
            nRet = this.DetailForm.MainForm.GetPublisherNumber(strISBN,
                out strPublisherNumber,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
        }

        if (String.IsNullOrEmpty(strPublisherNumber) == true)
            strPublisherNumber = "978-7-?";

        strPublisherNumber = InputDlg.GetInput(
                this.DetailForm,
                "维护102对照表 -- 第1步",
                "请输入ISBN中出版社号码部分:",
                strPublisherNumber);
        if (strPublisherNumber == null)
            return; // 放弃整个操作

        string strValue = "";

        nRet = this.DetailForm.Get102Info(strPublisherNumber,
            out strValue,
            out strError);
        if (nRet == -1)
            goto ERROR1;

        if (nRet == 0 || strValue == "")
        {
            strValue = "国家代码[2位]:城市代码[6位]";
        }

        // 创建新条目
        strValue = InputDlg.GetInput(
            this.DetailForm,
            "维护102对照表 -- 第2步",
            "请输入ISBN出版社号码 '" + strPublisherNumber + "' 对应的UNIMARC 102$a$b参数(格式国家代码[2位]:城市代码[6位]):",
            strValue);
        if (strValue == null)
            return; // 放弃整个操作

        if (strValue == "")
            goto DOSAVE;


        // MessageBox.Show(this.DetailForm, strValue);

        // 把全角冒号替换为半角的形态
        strValue = strValue.Replace(":", ":");

        string strCountryCode = "";
        string strCityCode = "";
        nRet = strValue.IndexOf(":");
        if (nRet == -1)
        {
            strCountryCode = strValue;

            if (strCountryCode.Length != 2)
            {
                strError = "国家代码 '" + strCountryCode + "' 应当为2字符";
                goto ERROR1;
            }
        }
        else
        {
            strCountryCode = strValue.Substring(0, nRet);
            strCityCode = strValue.Substring(nRet + 1);
            if (strCountryCode.Length != 2)
            {
                strError = "冒号前面的国家代码部分 '" + strCountryCode + "' 应当为2字符";
                goto ERROR1;
            }
            if (strCityCode.Length != 6)
            {
                strError = "冒号后面的城市代码部分 '" + strCityCode + "' 应当为6字符";
                goto ERROR1;
            }
        }

        strValue = strCountryCode + ":" + strCityCode;

    DOSAVE:
        nRet = this.DetailForm.Set102Info(strPublisherNumber,
            strValue,
            out strError);
        if (nRet == -1)
            goto ERROR1;

        return;
    ERROR1:
        MessageBox.Show(this.DetailForm, strError);
    }

    void Copy225To410()
    {
        Field field_225 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("225", 0);

        if (field_225 == null)
        {
            MessageBox.Show(this.DetailForm, "225字段不存在");
            return;
        }

        SubfieldCollection subfields_225 = field_225.Subfields;

 

        Subfield subfield_a = subfields_225["a"];

        if (subfield_a == null)
        {
            MessageBox.Show(this.DetailForm, "225$" + "a" + "不存在");
            return;
        }

        string strContent = subfield_a.Value;

        // 看看当前活动字段是不是410
        Field field_410 = null;

        field_410 = this.DetailForm.MarcEditor.FocusedField;
        if (field_410 != null)
        {
            if (field_410.Name != "410")
                field_410 = null;
        }

        bool bInitial410Value = false; // 410字段的值是否初始化过

        if (field_410 == null)
        {
            field_410 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("410", 0);

            if (field_410 == null)
            {
                field_410 = this.DetailForm.MarcEditor.Record.Fields.Add("410", "  ", new string((char)31, 1) + "1200  " + new string((char)31, 1) + "a", true);
                bInitial410Value = true;
            }


        }


        if (bInitial410Value == false)
        {
            field_410.Value = new string((char)31, 1) + "1200  " + new string((char)31, 1) + "a" + field_410.Value;
        }

        if (field_410 == null)
            throw (new Exception("error ..."));


        Subfield subfield_410a = field_410.Subfields["a"];
        if (subfield_410a == null)
        {
            subfield_410a = new Subfield();
            subfield_410a.Name = "a";
        }

        subfield_410a.Value = strContent;
        field_410.Subfields["a"] = subfield_410a;
    }


    void Copy690aTo905d()
    {
        Copy690aTo905d("a", "905");

    }

    void Copy690aTo905d(string strFromSubfield, string strToField)
    {
        Field field_690 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("690", 0);
        SubfieldCollection subfields_690 = field_690.Subfields;

        Subfield subfield_a = subfields_690[strFromSubfield];

        if (subfield_a == null)
        {
            MessageBox.Show(this.DetailForm, "690$" + strFromSubfield + "不存在");
            return;
        }

        string strContent = subfield_a.Value;

        // 看看当前活动字段是不是905
        Field field_905 = null;

        field_905 = this.DetailForm.MarcEditor.FocusedField;
        if (field_905 != null)
        {
            if (field_905.Name != strToField)
                field_905 = null;
        }


        if (field_905 == null)
        {
            field_905 = this.DetailForm.MarcEditor.Record.Fields.GetOneField(strToField, 0);

            if (field_905 == null)
            {
                field_905 = this.DetailForm.MarcEditor.Record.Fields.Add(strToField, "  ", "", true);
            }

        }


        if (field_905 == null)
            throw (new Exception("error ..."));


        Subfield subfield_905d = field_905.Subfields["d"];
        if (subfield_905d == null)
        {
            subfield_905d = new Subfield();
            subfield_905d.Name = "d";
        }

        subfield_905d.Value = strContent;
        field_905.Subfields["d"] = subfield_905d;

    }

    public override void CreateCallNumber(object sender,
        GenerateDataEventArgs e)
    {
        base.CreateCallNumber(sender, e);
    }
}



发表时间: 2009-03-24 15:01:33



页 1 / 1
 

在线用户
访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客   访客访客
当前栏目在线用户数 36, 总在线用户数 43