// 修改字段名后要变换说明信息 /// <summary> /// 修改字段名 /// </summary> /// <param name="field">字段对象</param> /// <param name="strNewName">要修改成的字段名</param> public void ChangeFieldName(Field field, string strNewName) { // 此处应使用Name,让界面跟着改变 string strOldName = field.Name; if (strOldName != strNewName) { // 旧字段名是控制字段,新字段名是非控制字段 的情况 if (Record.IsControlFieldName(strOldName) == true && Record.IsControlFieldName(strNewName) == false) { field.Name = strNewName; string strAllValue = field.ValueKernel; if (strAllValue.Length < 2) strAllValue = strAllValue + new string(' ',2-strAllValue.Length); field.Indicator = strAllValue.Substring(0,2); if (strAllValue.Length > 2) field.Value = strAllValue.Substring(2); else field.Value = ""; } else if (Record.IsControlFieldName(strOldName) == false && Record.IsControlFieldName(strNewName) == true) { // 旧字段名是非控制字段,新字段名是控制字段 的情况 field.Name = strNewName; string strValue = this.FocusedField.Indicator + this.FocusedField.ValueKernel; field.Indicator = ""; field.Value = strValue; } else { field.Name = strNewName; if (StringUtil.IsPureNumber(strNewName) == true) { if (Record.IsControlFieldName(strNewName) == true) { if(field.Indicator != "") field.Indicator = ""; } else { if (field.Indicator.Length != 2) { if (field.Indicator.Length > 2) field.Indicator = field.Indicator.Substring(0,2); else field.Indicator = field.Indicator.PadRight(2,' '); } } } } } }
// 包装版本 /// <summary> /// 设置活动字段 /// </summary> /// <param name="field">字段对象</param> /// <param name="nCol">插入符的列号。列号的含义:1: 字段名 2: 指示符 3:字段内容</param> public void SetActiveField(Field field, int nCol) { this.SetActiveField(field, nCol, true); }
// 把一个字段设为当前活动的字段(对象版本) internal void SetActiveField(Field field, int nCol, bool bFocus) { int nIndex = this.record.Fields.IndexOf(field); Debug.Assert(nIndex != -1,"field不可能不在record里"); this.SetActiveField(nIndex, nCol, bFocus); }
/// <summary> /// 根据一个 Field 对象的内容创建一个新的 SubfieldCollection 对象 /// </summary> /// <param name="container">Field 对象,也被当作要创建的 SubfieldCollection 对象的容器</param> /// <returns>新创建的 SubfieldCollection 对象</returns> public static SubfieldCollection BuildSubfields(Field container) { SubfieldCollection subfields = new SubfieldCollection(); string strField = container.Text; for (int i = 0; ; i++) { string strSubfield = ""; string strNextSubfieldName = ""; // 从字段或子字段组中得到一个子字段 // parameters: // strText 字段内容,或者子字段组内容。 // textType 表示strText中包含的是字段内容还是组内容。若为ItemType.Field,表示strText参数中为字段;若为ItemType.Group,表示strText参数中为子字段组。 // strSubfieldName 子字段名,内容为1位字符。如果==null,表示任意子字段 // 形式为'a'这样的。 // nIndex 想要获得同名子字段中的第几个。从0开始计算。 // strSubfield [out]输出子字段。子字段名(1字符)、子字段内容。 // strNextSubfieldName [out]下一个子字段的名字,内容一个字符 // return: // -1 出错 // 0 所指定的子字段没有找到 // 1 找到。找到的子字段返回在strSubfield参数中 int nRet = MarcUtil.GetSubfield(strField, ItemType.Field, null, i, out strSubfield, out strNextSubfieldName); if (nRet == -1 || nRet == 0) break; Subfield subfield = new Subfield(); subfield.Text = strSubfield; subfield.Container = subfields; subfields.Add(subfield); } subfields.Container = container; return subfields; }