完整的功能需要加入4块代码到不同的位置:
一、
using System.Xml.XPath;
二、
actions.NewItem("加入四角号", "根据701/711$a内容, 创建905$e", "AddFourAngle", false);
三、
void AddFourAngle()
{
string[] cfgsjh = new string[] { "1234", "1313", "1311", "1111" }; //在此配置取号规则
string author = "";
string sijiaohao = "";
string first = "";
string second = "";
string third = "";
string forth = "";
string author1 = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("701", "a");
string author2 = this.DetailForm.MarcEditor.Record.Fields.GetFirstSubfield("711", "a");
getSiJiaoHao getsjh = new getSiJiaoHao();
if (author1 != "")
{
author = author1;
if (author.Length == 1)
{
first = cfgsjh[0].Substring(0,1);
second = cfgsjh[0].Substring(1, 1);
third = cfgsjh[0].Substring(2, 1);
forth = cfgsjh[0].Substring(3, 1);
getsjh.authorchar = author[0];
getsjh.QuHao();
sijiaohao += getsjh.hao[Convert.ToInt32(first)-1];
sijiaohao += getsjh.hao[Convert.ToInt32(second)-1];
sijiaohao += getsjh.hao[Convert.ToInt32(third)-1];
sijiaohao += getsjh.hao[Convert.ToInt32(forth)-1];
}
if (author.Length == 2)
{
first = cfgsjh[1].Substring(0, 1);
second = cfgsjh[1].Substring(1, 1);
third = cfgsjh[1].Substring(2, 1);
forth = cfgsjh[1].Substring(3, 1);
for (int i = 0; i <= 1; i++)
{
getsjh.authorchar=author[i];
getsjh.QuHao();
if (i == 0)
{
sijiaohao += getsjh.hao[Convert.ToInt32(first) - 1];
sijiaohao += getsjh.hao[Convert.ToInt32(second) - 1];
}
if (i == 1)
{
sijiaohao += getsjh.hao[Convert.ToInt32(third)-1];
sijiaohao+=getsjh.hao[Convert.ToInt32(forth)-1];
}
}
}
if (author.Length >= 3)
{
first = cfgsjh[2].Substring(0, 1);
second = cfgsjh[2].Substring(1, 1);
third = cfgsjh[2].Substring(2, 1);
forth = cfgsjh[2].Substring(3, 1);
author = author.Substring(0, 3);
for (int i = 0; i <= 2; i++)
{
getsjh.authorchar = author[i];
getsjh.QuHao();
if (i == 0)
{
sijiaohao += getsjh.hao[Convert.ToInt32(first) - 1];
sijiaohao += getsjh.hao[Convert.ToInt32(second) - 1];
}
if (i == 1)
sijiaohao += getsjh.hao[Convert.ToInt32(third) - 1];
if (i == 2)
sijiaohao += getsjh.hao[Convert.ToInt32(forth) - 1];
}
}
}
else if (author2 != "")
{
author = author2;
if (author.Length == 1)
{
first = cfgsjh[0].Substring(0, 1);
second = cfgsjh[0].Substring(1, 1);
third = cfgsjh[0].Substring(2, 1);
forth = cfgsjh[0].Substring(3, 1);
getsjh.authorchar = author[0];
getsjh.QuHao();
sijiaohao += getsjh.hao[Convert.ToInt32(first) - 1];
sijiaohao += getsjh.hao[Convert.ToInt32(second) - 1];
sijiaohao += getsjh.hao[Convert.ToInt32(third) - 1];
sijiaohao += getsjh.hao[Convert.ToInt32(forth) - 1];
}
if (author.Length == 2)
{
first = cfgsjh[1].Substring(0, 1);
second = cfgsjh[1].Substring(1, 1);
third = cfgsjh[1].Substring(2, 1);
forth = cfgsjh[1].Substring(3, 1);
for (int i = 0; i <= 1; i++)
{
getsjh.authorchar = author[i];
getsjh.QuHao();
if (i == 0)
{
sijiaohao += getsjh.hao[Convert.ToInt32(first) - 1];
sijiaohao += getsjh.hao[Convert.ToInt32(second) - 1];
}
if (i == 1)
{
sijiaohao += getsjh.hao[Convert.ToInt32(third) - 1];
sijiaohao += getsjh.hao[Convert.ToInt32(forth) - 1];
}
}
}
if (author.Length == 3)
{
first = cfgsjh[2].Substring(0, 1);
second = cfgsjh[2].Substring(1, 1);
third = cfgsjh[2].Substring(2, 1);
forth = cfgsjh[2].Substring(3, 1);
for (int i = 0; i <= 2; i++)
{
getsjh.authorchar = author[i];
getsjh.QuHao();
if (i == 0)
{
sijiaohao += getsjh.hao[Convert.ToInt32(first) - 1];
sijiaohao += getsjh.hao[Convert.ToInt32(second) - 1];
}
if (i == 1)
sijiaohao += getsjh.hao[Convert.ToInt32(third) - 1];
if (i == 2)
sijiaohao += getsjh.hao[Convert.ToInt32(forth) - 1];
}
}
else if (author.Length>=4)
{
first = cfgsjh[3].Substring(0, 1);
second = cfgsjh[3].Substring(1, 1);
third = cfgsjh[3].Substring(2, 1);
forth = cfgsjh[3].Substring(3, 1);
author = author.Substring(0, 4);
for (int i = 0; i <= 3; i++)
{
getsjh.authorchar = author[i];
getsjh.QuHao();
if (i == 0)
sijiaohao += getsjh.hao[Convert.ToInt32(first) - 1];
if (i == 1)
sijiaohao += getsjh.hao[Convert.ToInt32(second) - 1];
if (i == 2)
sijiaohao += getsjh.hao[Convert.ToInt32(third) - 1];
if (i == 3)
sijiaohao += getsjh.hao[Convert.ToInt32(forth) - 1];
}
}
}
else
{
MessageBox.Show(this.DetailForm, "701/711中均未发现$a,无法处理");
return;
}
this.DetailForm.MarcEditor.Record.Fields.SetFirstSubfield("905", "e", sijiaohao);
}
四、
class getSiJiaoHao
{
public string hao;
public char authorchar;
public void QuHao()
{
XPathDocument doc = new XPathDocument("http://localhost/Dp2LibraryWs/sijiaohao.xml");
XPathNavigator nav = ((IXPathNavigable)doc).CreateNavigator();
XPathNodeIterator iter = nav.Select("/Collection/Character[@char='" + authorchar + "']");
while (iter.MoveNext())
{
hao = iter.Current.Value;
}
}
}
说明:
1、配置字符串数组中分别对应责任者为:1字(如1234)、2字(如1313)、3字(如1311)、团体(如前四字1111);
2、个人责任者多于4字、只取前3字 ;
3、团体责任者少于4字,按个人责任者的规则取号。
4、两字每个字取两位号。
5、三个字首字取两位号,2、3字各取一位号。
5、四个字各字取一位号。
这是普遍应用的规则,在这大规则下,具体取号位可以自行配置,比如我碰到过的有:{1234,1313,1311,1111}或{1234,1414,1411,1111}等,都是在这个原则下。
当然,也不排除有特殊嗜好的图书馆,非要把首字只取一位,尾字取三位,那以上代码就没办法了,只能请数字平台的老师们来量身定做代码了。