private void MarcEditor_GetTemplateDef(object sender, GetTemplateDefEventArgs e) { if (this._genData.DetailHostObj == null) { int nRet = 0; string strError = ""; // 初始化 dp2circulation_marc_autogen.cs 的 Assembly,并new DetailHost对象 // return: // -1 error // 0 没有重新初始化Assembly,而是直接用以前Cache的Assembly // 1 重新(或者首次)初始化了Assembly nRet = this._genData.InitialAutogenAssembly(this.BiblioRecPath, // null, out strError); if (nRet == -1) { e.ErrorInfo = strError; return; } if (nRet == 0) { if (this._genData.DetailHostObj == null) { e.Canceled = true; return; // 库名不具备,无法初始化 } } Debug.Assert(this._genData.DetailHostObj != null, ""); } Debug.Assert(this._genData.DetailHostObj != null, ""); // 如果脚本里面没有相应的回调函数 if (this._genData.DetailHostObj.GetType().GetMethod("GetTemplateDef", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod ) == null) { e.Canceled = true; return; } /* dynamic o = this.m_detailHostObj; try { o.GetTemplateDef(sender, e); } catch (Exception ex) { e.ErrorInfo = ex.Message; return; } * */ // 有两个参数的成员函数 Type classType = _genData.DetailHostObj.GetType(); try { classType.InvokeMember("GetTemplateDef", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod , null, this._genData.DetailHostObj, new object[] { sender, e }); } catch (Exception ex) { e.ErrorInfo = GetExceptionMessage(ex) + "\r\n\r\n" + ExceptionUtil.GetDebugText(ex); // GetExceptionMessage(ex); return; } }
void textBox_value_TextChanged(object sender, EventArgs e) { if (this.m_nDisableTextChanged > 0) return; m_nDisableTextChanged++; try { string strError = ""; TextBox textbox = (TextBox)sender; if (string.IsNullOrEmpty(textbox.Text) == true) return; TemplateLine changed_line = null; foreach (TemplateLine line in this.templateRoot.Lines) { if (line.TextBox_value == textbox) { changed_line = line; goto FOUND; } } return; FOUND: Debug.Assert(changed_line != null, ""); if (changed_line.IsSensitive == true && this.GetTemplateDef != null) { // 需要重新装载模板定义 GetTemplateDefEventArgs e1 = new GetTemplateDefEventArgs(); if (this.nodeTemplateDef != null) { if (this.nodeTemplateDef.Name == "Field") { e1.FieldName = DomUtil.GetAttr(this.nodeTemplateDef, "name"); } else if (this.nodeTemplateDef.Name == "Subfield") { e1.FieldName = DomUtil.GetAttr(this.nodeTemplateDef.ParentNode, "name"); e1.SubfieldName = DomUtil.GetAttr(this.nodeTemplateDef, "name"); } else { strError = "模板定义节点为意外的 <" + this.nodeTemplateDef.Name + "> 元素,无法进行敏感处理"; goto ERROR1; } } else { strError = "当前没有模板定义节点信息,无法进行敏感处理"; goto ERROR1; } string strValue = this.Value + this.AdditionalValue; e1.Value = strValue; this.GetTemplateDef(this, e1); if (string.IsNullOrEmpty(e1.ErrorInfo) == false) { strError = "获得模板定义时出错: " + e1.ErrorInfo; goto ERROR1; } if (e1.Canceled == true) return; if (e1.DefNode == this.nodeTemplateDef) return; // 模板定义没有发生变化 int nResultWidth = 0; int nResultHeight = 0; // paramters: // fieldNode Field节点 // strLang 语言版本 // return: // -1 出错 // 0 不是定长字段 // 1 成功 int nRet = this.Initial(e1.DefNode, this.Lang, out nResultWidth, out nResultHeight, out strError); if (nRet != 1) goto ERROR1; this.Value = strValue; // 通知Form尺寸发生了变化 if (this.ResetSize != null) { this.ResetSize(this, new EventArgs()); } // 通知标题变化 if (this.ResetTitle != null) { ResetTitleEventArgs e2 = new ResetTitleEventArgs(); e2.Title = e1.Title; this.ResetTitle(this, e2); } } return; ERROR1: MessageBox.Show(this, strError); } finally { m_nDisableTextChanged--; } }
void dlg_GetTemplateDef(object sender, GetTemplateDefEventArgs e) { if (this.GetTemplateDef != null) this.GetTemplateDef(sender, e); }
// 获得模板定义 void GetTemplateDef(object sender, GetTemplateDefEventArgs e) { if (e.FieldName == "008") { if (this.DetailForm.MarcEditor.MarcDefDom == null) { e.ErrorInfo = "MarcEditor中的MarcDefDom尚未准备好..."; return; } if (this.DetailForm.MarcEditor.Record.Fields.Count == 0) { e.ErrorInfo = "MarcEditor中没有头标区"; return; } // 观察头标区 Field header = this.DetailForm.MarcEditor.Record.Fields[0]; if (header.Value.Length < 24) { e.ErrorInfo = "MarcEditor中头标区不是24字符"; return; } string strType = ""; // http://www.loc.gov/marc/bibliographic/bd008b.html // Books definition of field 008/18-34 is used when Leader/06 (Type of record) contains code a (Language material) or t (Manuscript language material) and Leader/07 (Bibliographic level) contains code a (Monographic component part), c (Collection), d (Subunit), or m (Monograph). if ("at".IndexOf(header.Value[6]) != -1 && "acdm".IndexOf(header.Value[7]) != -1) strType = "books"; // http://www.loc.gov/marc/bibliographic/bd008c.html // Computer files definition of field 008/18-34 is used when Leader/06 (Type of record) contains code m. else if ("m".IndexOf(header.Value[6]) != -1) strType = "computer_files"; // http://www.loc.gov/marc/bibliographic/bd008p.html // Maps definition of field 008/18-34 is used when Leader/06 (Type of record) contains code e (Cartographic material) or f (Manuscript cartographic material). else if ("ef".IndexOf(header.Value[6]) != -1) strType = "maps"; // http://www.loc.gov/marc/bibliographic/bd008m.html // Music definition of field 008/18-34 is used when Leader/06 (Type of record) contains code c (Notated music), d (Manuscript notated music), i (Nonmusical sound recording), or j (Musical sound recording). else if ("cdij".IndexOf(header.Value[6]) != -1) strType = "music"; // http://www.loc.gov/marc/bibliographic/bd008s.html // Continuing resources field 008/18-34 contains coded data for all continuing resources, including serials and integrating resources. It is used when Leader/06 (Type of record) contains code a (Language material) and Leader/07 contains code b (Serial component part), i (Integrating resource), or code s (Serial). else if ("a".IndexOf(header.Value[6]) != -1 && "bis".IndexOf(header.Value[7]) != -1) strType = "contining_resources"; // http://www.loc.gov/marc/bibliographic/bd008v.html // Visual materials definition of field 008/18-34 is used when Leader/06 (Type of record) contains code g (Projected medium), code k (Two-dimensional nonprojectable graphic, code o (Kit), or code r (Three-dimensional artifact or naturally occurring object). else if ("gkor".IndexOf(header.Value[6]) != -1) strType = "visual_materials"; // http://www.loc.gov/marc/bibliographic/bd008x.html // Mixed materials definition of field 008/18-34 is used when Leader/06 (Type of record) contains code p (Mixed material). else if ("p".IndexOf(header.Value[6]) != -1) strType = "mixed_materials"; else { e.ErrorInfo = "无法根据当前头标区 '" + header.Value.Replace(" ", "_") + "' 内容辨别文献类型,所以无法获得模板定义"; return; } e.DefNode = this.DetailForm.MarcEditor.MarcDefDom.DocumentElement.SelectSingleNode("Field[@name='" + e.FieldName + "' and @type='" + strType + "']"); if (e.DefNode == null) { e.ErrorInfo = "字段名为 '" + e.FieldName + "' 类型为='" + strType + "' 的模板定义无法在MARC定义文件中找到"; return; } e.Title = "008 " + strType; return; } if (e.FieldName == "007") { if (this.DetailForm.MarcEditor.MarcDefDom == null) { e.ErrorInfo = "MarcEditor中的MarcDefDom尚未准备好..."; return; } string strType = ""; if (e.Value.Length < 1) { // 权且当作 'a' 处理 strType = "map"; } else { // http://www.loc.gov/marc/bibliographic/bd007.html // Map (007/00=a) if (e.Value[0] == 'a') strType = "map"; // Electronic resource (007/00=c) else if (e.Value[0] == 'c') strType = "electronic_resource"; // Globe (007/00=d) else if (e.Value[0] == 'd') strType = "globe"; // Tactile material (007/00=f) else if (e.Value[0] == 'f') strType = "tactile_material"; // Projected graphic (007/00=g) else if (e.Value[0] == 'g') strType = "projected_graphic"; // Microform (007/00=h) else if (e.Value[0] == 'h') strType = "microform"; // Nonprojected graphic (007/00=k) else if (e.Value[0] == 'k') strType = "nonprojected_graphic"; // Motion picture (007/00=m) else if (e.Value[0] == 'm') strType = "motion_picture"; // Kit (007/00=o) else if (e.Value[0] == 'o') strType = "kit"; // Notated music (007/00=q) else if (e.Value[0] == 'q') strType = "notated_music"; // Remote-sensing image (007/00=r) else if (e.Value[0] == 'r') strType = "remote-sensing_image"; // Sound recording (007/00=s) else if (e.Value[0] == 's') strType = "sound_recording"; // Text (007/00=t) else if (e.Value[0] == 't') strType = "text"; // Videorecording (007/00=v) else if (e.Value[0] == 'v') strType = "videorecording"; // Unspecified (007/00=z) else if (e.Value[0] == 'z') strType = "unspecified"; else { e.ErrorInfo = "无法根据当前007字段第一字符内容 '" + e.Value[0].ToString() + "' 从MARC定义文件中获得模板定义"; return; } } e.DefNode = this.DetailForm.MarcEditor.MarcDefDom.DocumentElement.SelectSingleNode("Field[@name='" + e.FieldName + "' and @type='" + strType + "']"); if (e.DefNode == null) { e.ErrorInfo = "字段名为 '" + e.FieldName + "' 类型为='" + strType + "' 的模板定义无法在MARC定义文件中找到"; return; } e.Title = "007 " + strType; return; } e.Canceled = true; }
public event GetTemplateDefEventHandler GetTemplateDef = null; // 外部接口,获取一个特定模板的XML定义 // 通过模板取固定字段的值 // parameter: // strFieldName 字段名称 // strSubFieldName 子字段名称 如果为空表示获得字段的定长模板 // return: // -1 出错 // 0 没找到 可能是模板文件不存在,或者对应的配置事项不存在 // 1 找到 private int GetValueFromTemplate(string strFieldName, string strSubFieldName, string strValue, out string strOutputValue, out string strError) { Debug.Assert(strFieldName != null, "GetValueFromTemplate(),strFieldName 参数不能为 null"); Debug.Assert(strSubFieldName != null, "GetValueFromTemplate(),strSubFieldName 参数不能为 null"); Debug.Assert(strValue != null, "GetValueFromTemplate(),strValue 参数不能为 null"); strError = ""; strOutputValue = strValue; // 检查MarcDefDom是否存在 if (this.MarcDefDom == null) { strError = this.m_strMarcDomError; return 0; // 2008/3/19恢复。 原来为什么要注释掉? } XmlNode nodeDef = null; string strTitle = ""; // 首先尝试从外部接口获得模板定义 if (this.GetTemplateDef != null) { GetTemplateDefEventArgs e = new GetTemplateDefEventArgs(); e.FieldName = strFieldName; e.SubfieldName = strSubFieldName; e.Value = strValue; this.GetTemplateDef(this, e); if (string.IsNullOrEmpty(e.ErrorInfo) == false) { strError = "在通过外部接口获取字段名为 '" + strFieldName + "' 子字段名为 '" + strSubFieldName + "' 的模板定义XML时出错: \r\n" + e.ErrorInfo; return -1; } if (e.Canceled == false) { nodeDef = e.DefNode; strTitle = e.Title; goto FOUND; } // e.Canceled == true 表示希望MarcEditor来自己获得定义 } // *** MarcEditor来自己获得定义 // 根据字段名找到配置文件中的该字段的定义 XmlNodeList nodes = null; if (strSubFieldName == "") nodes = this.MarcDefDom.DocumentElement.SelectNodes("Field[@name='" + strFieldName + "']"); else nodes = this.MarcDefDom.DocumentElement.SelectNodes("Field[@name='" + strFieldName + "']/Subfield[@name='" + strSubFieldName + "']"); if (nodes.Count == 0) { strError = "MARC定义文件中没有找到字段名为 '" + strFieldName + "' 子字段名为 '" + strSubFieldName + "' 的字段/子字段 定义"; return 0; } if (nodes.Count > 1) { List<string> lines = new List<string>(); int i = 0; foreach (XmlNode node in nodes) { string strType = DomUtil.GetAttr(node, "type"); lines.Add((i + 1).ToString() + ") " + strType); i++; } SelectListStringDialog select_def_dlg = new SelectListStringDialog(); GuiUtil.AutoSetDefaultFont(select_def_dlg); select_def_dlg.Text = "请选择模板定义"; select_def_dlg.Values = lines; select_def_dlg.Comment = "MARC定义文件中发现 字段名为 '" + strFieldName + "' 子字段名为 '" + strSubFieldName + "' 的模板定义有 " + nodes.Count.ToString() + " 处。\r\n\r\n请选择其中一个"; select_def_dlg.StartPosition = FormStartPosition.CenterScreen; select_def_dlg.ShowDialog(this); if (select_def_dlg.DialogResult == DialogResult.Cancel) { strError = "放弃选择模板定义"; return 0; } Debug.Assert(select_def_dlg.SelectedIndex != -1, ""); nodeDef = nodes[select_def_dlg.SelectedIndex]; #if NO strTitle = "定长模板 : " + strFieldName + (string.IsNullOrEmpty(strSubFieldName) == false ? new String(Record.KERNEL_SUBFLD, 1) + strSubFieldName : "") + " -- " + select_def_dlg.SelectedValue; #endif strTitle = strFieldName + (string.IsNullOrEmpty(strSubFieldName) == false ? "$" + strSubFieldName : "") + " " + GetCaption(strFieldName, strSubFieldName, false) + " -- " + select_def_dlg.SelectedValue; } else { nodeDef = nodes[0]; } FOUND: FixedTemplateDlg dlg = new FixedTemplateDlg(); // GuiUtil.AutoSetDefaultFont(dlg); if (string.IsNullOrEmpty(strTitle) == false) dlg.Text = "定长模板 : " + strTitle; else { #if NO dlg.Text = "定长模板 : " + strFieldName + (string.IsNullOrEmpty(strSubFieldName) == false ? new String(Record.KERNEL_SUBFLD, 1) + strSubFieldName : ""); #endif dlg.Text = "定长模板 : " + strFieldName + (string.IsNullOrEmpty(strSubFieldName) == false ? "$" + strSubFieldName : "") + " " + GetCaption(strFieldName, strSubFieldName, false); } dlg.TemplateControl.GetConfigDom += this.GetConfigDom; dlg.GetTemplateDef += new GetTemplateDefEventHandler(dlg_GetTemplateDef); dlg.TemplateControl.ParseMacro += new ParseMacroEventHandler(TemplateControl_ParseMacro); dlg.TemplateControl.MarcDefDom = this.MarcDefDom; dlg.TemplateControl.Lang = this.Lang; dlg.StartPosition = FormStartPosition.CenterScreen; int nRet = dlg.Initial(nodeDef, this.Lang, strValue, out strError); if (nRet == 0) return 0; if (nRet == -1) return -1; dlg.ShowDialog(this); #if NO dlg.TemplateControl.ParseMacro -= new ParseMacroEventHandler(TemplateControl_ParseMacro); dlg.TemplateControl.GetConfigDom -= this.GetConfigDom; #endif if (dlg.DialogResult == DialogResult.OK) { strOutputValue = dlg.TemplateControl.Value; } return 1; }