// 设置菜单加亮状态 -- 规整ISBN为13 void HyphenISBN_13_setMenu(object sender, SetMenuEventArgs e) { Field curfield = this.DetailForm.MarcEditor.FocusedField; if (curfield == null || curfield.Name != "010") { e.Action.Active = false; return; } Subfield a = curfield.Subfields["a"]; if (a == null) { e.Action.Active = false; return; } string strISBN = a.Value; if (string.IsNullOrEmpty(strISBN) == true) { e.Action.Active = false; return; } if (IsbnSplitter.IsIsbn13(strISBN) == true) { e.Action.Active = false; return; } e.Action.Active = true; }
void Copy200gfTo7xxa(string strFromSubfield, string strToField) { Field field_200 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("200", 0); if (field_200 == null) { MessageBox.Show(this.DetailForm, "200字段不存在"); return; } SubfieldCollection subfields_200 = field_200.Subfields; Subfield subfield_f = subfields_200[strFromSubfield]; if (subfield_f == null) { MessageBox.Show(this.DetailForm, "200$" + strFromSubfield + "不存在"); return; } string strContent = subfield_f.Value; // 看看当前活动字段是不是701 Field field_701 = null; field_701 = this.DetailForm.MarcEditor.FocusedField; if (field_701 != null) { if (field_701.Name != strToField) { 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 Copy100aTo245c(string strFromSubfield, string strToField) { Field field_100 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("100", 0); if (field_100 == null) { MessageBox.Show(this.DetailForm, "100字段不存在"); return; } SubfieldCollection subfields_100 = field_100.Subfields; Subfield subfield_f = subfields_100[strFromSubfield]; if (subfield_f == null) { MessageBox.Show(this.DetailForm, "100$" + strFromSubfield + "不存在"); return; } string strContent = subfield_f.Value; // 看看当前活动字段是不是245 Field field_245 = null; field_245 = this.DetailForm.MarcEditor.FocusedField; if (field_245 != null) { if (field_245.Name != strToField) { field_245 = null; } } if (field_245 == null) { field_245 = this.DetailForm.MarcEditor.Record.Fields.GetOneField(strToField, 0); if (field_245 == null) { field_245 = this.DetailForm.MarcEditor.Record.Fields.Add(strToField, " ", "", true); } } if (field_245 == null) { throw (new Exception("error ...")); } Subfield subfield_245a = field_245.Subfields["c"]; if (subfield_245a == null) { subfield_245a = new Subfield(); subfield_245a.Name = "c"; } subfield_245a.Value = strContent; field_245.Subfields["c"] = subfield_245a; }
public void ToRawTest() { char code = 'a'; string data = "Test Data"; Subfield target = new Subfield(code, data); string expected = FileMARC.SUBFIELD_INDICATOR.ToString() + "aTest Data"; string actual = target.ToRaw(); Assert.AreEqual(expected, actual); }
public void ToStringTest() { char code = 'a'; string data = "Test Data"; Subfield target = new Subfield(code, data); string expected = "[a]: Test Data"; string actual = target.ToString(); Assert.AreEqual(expected, actual); }
public void ToXMLTest() { char code = 'a'; string data = "Test Data"; Subfield target = new Subfield(code, data); XElement expected = new XElement(FileMARCXML.Namespace + "subfield", new XAttribute("code", "a"), "Test Data"); XElement actual = target.ToXML(); Assert.IsTrue(XNode.DeepEquals(expected, actual)); }
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; }
static void NewSubfield( Field field, string strName, string strContent) { Subfield subfield = new Subfield(); subfield.Name = strName; subfield.Value = strContent; field.Subfields[strName] = subfield; }
public void CodeTest() { char code = 'a'; string data = "Test Data"; Subfield target = new Subfield(code, data); char expected = 'b'; target.Code = expected; char actual = target.Code; Assert.AreEqual(expected, actual); }
public void DataTest() { char code = 'a'; string data = "Test Data"; Subfield target = new Subfield(code, data); string expected = "Test Data Again"; target.Data = expected; string actual = target.Data; Assert.AreEqual(expected, actual); }
public void ToStringTest() { string tag = "100"; List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('a', "It's a book!"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); DataField target = new DataField(tag, subfields); string expected = "100 [a]: It's a book!" + Environment.NewLine + " [b]: Anne Author"; string actual = target.ToString(); Assert.AreEqual(expected, actual); }
public void ToRawTest() { string tag = "100"; List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('a', "It's a book!"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); DataField target = new DataField(tag, subfields); string expected = " " + FileMARC.SUBFIELD_INDICATOR.ToString() + "aIt's a book!" + FileMARC.SUBFIELD_INDICATOR.ToString() + "bAnne Author" + FileMARC.END_OF_FIELD.ToString(); string actual = target.ToRaw(); Assert.AreEqual(expected, actual); }
public void DataFieldConstructorTest2() { string tag = "100"; List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('a', "It's a book!"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); char ind1 = '1'; char ind2 = '0'; DataField target = new DataField(tag, subfields, ind1, ind2); { char expected = '1'; char actual = target.Indicator1; Assert.AreEqual(expected, actual); expected = '0'; actual = target.Indicator2; Assert.AreEqual(expected, actual); expected = 'a'; actual = target['a'].Code; Assert.AreEqual(expected, actual); expected = 'b'; actual = target['b'].Code; Assert.AreEqual(expected, actual); } { string expected = "100"; string actual = target.Tag; Assert.AreEqual(expected, actual); expected = "It's a book!"; actual = target['a'].Data; Assert.AreEqual(expected, actual); expected = "Anne Author"; actual = target['b'].Data; Assert.AreEqual(expected, actual); } { int expected = 2; int actual = target.Subfields.Count; Assert.AreEqual(expected, actual); } }
public void IsEmptyTest() { char code = 'a'; string data = "Test Data"; Subfield target = new Subfield(code, data); bool expected = false; bool actual = target.IsEmpty(); Assert.AreEqual(expected, actual); target.Data = null; expected = true; actual = target.IsEmpty(); Assert.AreEqual(expected, actual); target.Data = string.Empty; actual = target.IsEmpty(); Assert.AreEqual(expected, actual); }
public void ItemTest() { string tag = "100"; List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('a', "It's a book!"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); DataField target = new DataField(tag, subfields); char code = 'a'; Subfield expected = new Subfield('a', "It's a book!"); Subfield actual = target[code]; Assert.AreEqual(expected.Code, actual.Code); Assert.AreEqual(expected.Data, actual.Data); }
public void InsertSubfieldTest() { string tag = "600"; List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); subfield = new Subfield('d', "Some text"); subfields.Add(subfield); subfield = new Subfield('2', "Some more text"); subfields.Add(subfield); subfield = new Subfield('3', "Some fancy text"); subfields.Add(subfield); subfield = new Subfield('5', "Some more fancy text"); subfields.Add(subfield); DataField target = new DataField(tag, subfields); Subfield newSubfield = new Subfield('a', "Testing an insert at the beginning!"); target.InsertSubfield(newSubfield); newSubfield = new Subfield('c', "Testing an insert between letters!"); target.InsertSubfield(newSubfield); newSubfield = new Subfield('e', "Testing an insert at the end of letters before numbers"); target.InsertSubfield(newSubfield); newSubfield = new Subfield('1', "Testing a numbered insert before numbers!"); target.InsertSubfield(newSubfield); newSubfield = new Subfield('4', "Testing a numbered insert between numbers!"); target.InsertSubfield(newSubfield); newSubfield = new Subfield('6', "Testing a numbered insert after numbers!"); target.InsertSubfield(newSubfield); Assert.AreEqual('a', target.Subfields[0].Code); Assert.AreEqual('b', target.Subfields[1].Code); Assert.AreEqual('c', target.Subfields[2].Code); Assert.AreEqual('d', target.Subfields[3].Code); Assert.AreEqual('e', target.Subfields[4].Code); Assert.AreEqual('1', target.Subfields[5].Code); Assert.AreEqual('2', target.Subfields[6].Code); Assert.AreEqual('3', target.Subfields[7].Code); Assert.AreEqual('4', target.Subfields[8].Code); Assert.AreEqual('5', target.Subfields[9].Code); Assert.AreEqual('6', target.Subfields[10].Code); }
public void SubfieldConstructorTest() { char code = 'a'; string data = "Test Data"; Subfield target = new Subfield(code, data); Assert.IsInstanceOfType(target, typeof(Subfield)); { char expected = 'a'; char actual = target.Code; Assert.AreEqual(expected, actual); } { string expected = "Test Data"; string actual = target.Data; Assert.AreEqual(expected, actual); } }
public void ToXMLTest() { string tag = "100"; List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('a', "It's a book!"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); char ind1 = '1'; char ind2 = '0'; DataField target = new DataField(tag, subfields, ind1, ind2); XElement expected = new XElement(FileMARCXML.Namespace + "datafield", new XAttribute("tag", "100"), new XAttribute("ind1", "1"), new XAttribute("ind2", "0"), new XElement(FileMARCXML.Namespace + "subfield", new XAttribute("code", "a"), "It's a book!"), new XElement(FileMARCXML.Namespace + "subfield", new XAttribute("code", "b"), "Anne Author")); XElement actual = target.ToXML(); Assert.IsTrue(XNode.DeepEquals(expected, actual)); }
public void IsEmptyTest() { string tag = "100"; DataField target = new DataField(tag); bool expected = true; bool actual = target.IsEmpty(); Assert.AreEqual(expected, actual); List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('a', "It's a book!"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Otter Author"); subfields.Add(subfield); target = new DataField(tag, subfields); expected = false; actual = target.IsEmpty(); Assert.AreEqual(expected, actual); }
public void CloneTest() { string tag = "100"; List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('a', "It's a book!"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); Field target = new DataField(tag, subfields); Field actual = target.Clone(); Assert.AreNotEqual(target, actual); target.Tag = "200"; string expectedString = tag; string actualString = actual.Tag; Assert.AreEqual(expectedString, actualString); ((DataField)target).Indicator1 = '1'; ((DataField)target).Indicator2 = '2'; expectedString = " "; actualString = ((DataField)actual).Indicator1.ToString() + ((DataField)actual).Indicator2.ToString(); Assert.AreEqual(expectedString, actualString); ((DataField)target)['a'].Code = 'c'; ((DataField)target)['c'].Data = "It's a NEW book!"; expectedString = "aIt's a book!"; actualString = ((DataField)actual)['a'].Code.ToString() + ((DataField)actual)['a'].Data; Assert.AreEqual(expectedString, actualString); //This next line will fail as there's no subfield c! ((DataField)actual)['c'].Code = 'a'; }
public void CloneTest() { char code = 'a'; string data = "Test Data"; Subfield target = new Subfield(code, data); Subfield expected = target; Subfield actual = target.Clone(); Assert.AreNotEqual(expected, actual); target.Code = 'b'; string expectedString = "a"; string actualString = actual.Code.ToString(); Assert.AreEqual(expectedString, actualString); target.Data = "New Test Data"; expectedString = data; actualString = actual.Data; Assert.AreEqual(expectedString, actualString); }
public void FormatFieldTest1() { string tag = "600"; List <Subfield> subfields = new List <Subfield>(); Subfield subfield = new Subfield('a', "It's a book!"); subfields.Add(subfield); subfield = new Subfield('b', "Anne Author"); subfields.Add(subfield); subfield = new Subfield('c', "Some text"); subfields.Add(subfield); subfield = new Subfield('d', "Some more text"); subfields.Add(subfield); subfield = new Subfield('v', "Some fancy text"); subfields.Add(subfield); subfield = new Subfield('z', "Some more fancy text"); subfields.Add(subfield); DataField target = new DataField(tag, subfields); string expected = "It's a book! Anne Author Some text Some more text -- Some fancy text -- Some more fancy text"; string actual = target.FormatField(); Assert.AreEqual(expected, actual); }
void Copy245cTo7xxa(string strFromSubfield, string strToFields) { Field field_245 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("245", 0); if (field_245 == null) { MessageBox.Show(this.DetailForm, "245字段不存在"); return; } SubfieldCollection subfields_245 = field_245.Subfields; Subfield subfield_f = subfields_245[strFromSubfield]; if (subfield_f == null) { MessageBox.Show(this.DetailForm, "245$" + strFromSubfield + "不存在"); return; } string strContent = subfield_f.Value; // 看看当前活动字段是不是700 Field field_700 = null; field_700 = this.DetailForm.MarcEditor.FocusedField; string strToField = FirstOf(strToFields); if (field_700 != null) { if (StringUtil.IsInList(field_700.Name, strToFields) == true) { strToField = field_700.Name; } else { field_700 = null; } } if (field_700 == null) { field_700 = this.DetailForm.MarcEditor.Record.Fields.GetOneField(strToField, 0); if (field_700 == null) { field_700 = this.DetailForm.MarcEditor.Record.Fields.Add(strToField, " ", "", true); } } if (field_700 == null) { throw (new Exception("error ...")); } Subfield subfield_700a = field_700.Subfields["a"]; if (subfield_700a == null) { subfield_700a = new Subfield(); subfield_700a.Name = "a"; } subfield_700a.Value = strContent; field_700.Subfields["a"] = subfield_700a; }
// 维护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, this.DetailForm.MainForm.DefaultFont); if (strPublisherNumber == null) { return; // 放弃整个操作 } string strValue = ""; nRet = this.DetailForm.GetPublisherInfo(strPublisherNumber, out strValue, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0 || strValue == "") { // 获得现有的210字段 $a$c Field field_210 = this.DetailForm.MarcEditor.Record.Fields.GetOneField("210", 0); if (field_210 != null) { Subfield subfield_a = field_210.Subfields["a"]; Subfield subfield_c = field_210.Subfields["c"]; if (subfield_a != null && subfield_c != null && string.IsNullOrEmpty(subfield_a.Value) == false && string.IsNullOrEmpty(subfield_c.Value) == false) { strValue = subfield_a.Value + ":" + subfield_c.Value; } } if (string.IsNullOrEmpty(strValue) == true) { strValue = "出版地:出版社名"; } } // 创建新条目 strValue = InputDlg.GetInput( this.DetailForm, "维护210对照表 -- 第2步", "请输入ISBN出版社号码 '" + strPublisherNumber + "' 对应的UNIMARC 210$a$c参数(格式 出版地:出版社名):", strValue, this.DetailForm.MainForm.DefaultFont); 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); }
static void Main(string[] args) { //Read raw MARC record from a file. //The example .mrc files are in the project's root. string rawMarc = File.ReadAllText("..\\..\\..\\record.mrc"); //The FileMARC class does the actual decoding of a record and splits a string of multiple records into a list object. //Decoding is not done until you actually access a single record from the FileMARC object. //You can import records straight from a string in memory. The string can have one or many MARC records. FileMARC marcRecords = new FileMARC(rawMarc); //Or you can import it straight from a file marcRecords.ImportMARC("..\\..\\..\\record2.mrc"); //You can get how many records were found by using the Count property Console.WriteLine("Found " + marcRecords.Count + " records."); //You can access each individual record in it's native MARC format using the RawSource object Console.WriteLine("Here is the first record:"); Console.WriteLine(marcRecords.RawSource[0]); //You can access each record manually using array notation. Record firstRecord = marcRecords[0]; //Or you can loop through them as an Enumerable object //Note: I recommend only retrieving each record from the FileMARC object once as each time you do it will be decoded. int i = 0; foreach (Record record in marcRecords) { //The Warnings property contains a list of issues that the decoder found with the record. //The decoder attempts to return a valid MARC record to the best of it's ability. Console.WriteLine("Book #" + ++i + " has been decoded with " + record.Warnings.Count + " errors!"); //Once decoded you can easily access specific data within the record, as well as make changes. //Array notation we will get the first requested tag in the record, or null if one does not exist. //First we'll get the Author. Since there should only be one author tag array notation is the easiest to use. Field authorField = record["100"]; //Each tag in the record is a field object. To get the data we have to know if it is a DataField or a ControlField and act accordingly. if (authorField.IsDataField()) { DataField authorDataField = (DataField)authorField; //The author's name is in subfield a. Once again since there should only be one we can use array notation. Subfield authorName = authorDataField['a']; Console.WriteLine("The author of this book is " + authorName.Data); } else if (authorField.IsControlField()) { //Unreachable code! Console.WriteLine("Something went horribly wrong. The author field should never be a Control Field."); } //Now we will get the subjects for this record. Since a book can have multiple subjects we will use GetFields() which returns a List<Field> object. //Note: Not passing in a tag number to GetFields will return all the tags in the record. List <Field> subjects = record.GetFields("650"); Console.WriteLine("Here are the subjects for Book #" + i); //Here we will assume each Field is actually a DataField since ISBNs should always be a DataField. foreach (DataField subject in subjects) { string subjectText = string.Empty; //We also want to loop through each subfield. //Just like with GetFields() you can either pass in a subfield value, or nothing to get all the subfields foreach (Subfield subfield in subject.GetSubfields()) { subjectText += subfield.Data + " "; } Console.WriteLine(subjectText); } } Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
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; }