DigitalPlatform / dp2

Integrated Library System / 图书馆集成系统
http://digitalplatform.github.io/dp2
Apache License 2.0
106 stars 54 forks source link

定制索取号创建规则一例 #1163

Open DigitalPlatform opened 1 year ago

DigitalPlatform commented 1 year ago

某用户单位希望创建的索取号为以下形态

分类号/同类书区分号/出版年份

即,在一般的索取号后面增加第三行“出版年份”。

升级 dp2circulation 到最新版,定制“中文图书”的 dp2circulation_marc_autogen.cs 文件,增加下列函数即可:

    public override string MergeLines(string strHeadLine,
    string strClass,
    string strQufenhao)
    {
        string text = base.MergeLines(strHeadLine, strClass, strQufenhao);

        string strMARC = this.DetailForm.MarcEditor.Marc;
        var record = new MarcRecord(strMARC);
        var publish_time = record.select("field[@name='210']/subfield[@name='d']").FirstContent;

        return text + "/" + GetYear(publish_time);

        string GetYear(string text)
        {
            if (string.IsNullOrEmpty(text))
                return "";
            int index = text.IndexOf(".");
            if (index == -1)
                return text;
            return text.Substring(0, index).Trim();
        }
    }

定制的原理是,dp2circulation_marc_autogen.cs 代码内的 MyHost 类是从宿主程序的 DetailHost 类派生的一个类,MyHost 类中重载基类的 MergeLines() 函数,这个函数是用来在创建索取号最后一步合成多行的,只需要在基类的此函数合成的字符串基础上追加第三行内容即可。第三行内容是从书目记录 MARC 中取相应字段子字段得到的,用了 MarcQuery 函数来操作 MARC 记录。