// 补全册记录字段 public int CompleteEntities(out string strError) { strError = ""; int i = 0; foreach (Control control in this.flowLayoutPanel1.Controls) { if (!(control is EntityEditControl)) continue; EntityEditControl edit = control as EntityEditControl; if (edit.Changed == false) { i++; continue; } string strName = "册记录 " + (i + 1); string strPrice = edit.Price.Trim(); if (strPrice == "@price") { // 兑现宏 string strResult = DoGetMacroValue(strPrice); if (strResult != strPrice) edit.Price = strResult; } string strAccessNo = edit.AccessNo.Trim(); if (string.IsNullOrEmpty(strAccessNo) == true || strAccessNo == "@accessNo") { // 获得索取号 if (this.GenerateData != null) { GetCallNumberParameter parameter = new GetCallNumberParameter(); parameter.ExistingAccessNo = ""; parameter.Location = edit.LocationString; parameter.RecPath = ""; // TODO: 可以通过书目库名,获得对应的实体库名,从而模拟出记录路径 GenerateDataEventArgs e1 = new GenerateDataEventArgs(); e1.ScriptEntry = "CreateCallNumber"; e1.FocusedControl = null; e1.Parameter = parameter; this.GenerateData(this, e1); if (string.IsNullOrEmpty(e1.ErrorInfo) == false) { // TODO: edit 控件索取号右边要有个提示区就好了。或者 tips } else { parameter = e1.Parameter as GetCallNumberParameter; edit.AccessNo = parameter.ResultAccessNo; } } } i++; } return 0; }
// 兑现实体记录中的宏 // return: // -1 出错 // 0 没有发生修改 // 1 发生过修改 public int ReplaceEntityMacro(XmlDocument dom, out string strError) { strError = ""; bool bChanged = false; // 遍历所有一级元素的内容 XmlNodeList nodes = dom.DocumentElement.SelectNodes("*"); for (int i = 0; i < nodes.Count; i++) { string strText = nodes[i].InnerText; if (strText.Length > 0 && (strText[0] == '@' || strText.IndexOf("%") != -1)) { // 兑现宏 string strResult = DoGetMacroValue(strText); if (strResult != strText) { nodes[i].InnerText = strResult; bChanged = true; } } } // 第一遍宏兑现后,第二遍专门兑现 @accessNo 宏 string strAccessNo = DomUtil.GetElementText(dom.DocumentElement, "accessNo"); if (string.IsNullOrEmpty(strAccessNo) == false) strAccessNo = strAccessNo.Trim(); if (strAccessNo == "@accessNo") { // 获得索取号 if (this.GenerateData != null) { GetCallNumberParameter parameter = new GetCallNumberParameter(); parameter.ExistingAccessNo = ""; parameter.Location = DomUtil.GetElementText(dom.DocumentElement, "location"); parameter.RecPath = ""; // TODO: 可以通过书目库名,获得对应的实体库名,从而模拟出记录路径 GenerateDataEventArgs e1 = new GenerateDataEventArgs(); e1.ScriptEntry = "CreateCallNumber"; e1.FocusedControl = null; e1.Parameter = parameter; this.GenerateData(this, e1); if (string.IsNullOrEmpty(e1.ErrorInfo) == false) { // TODO: edit 控件索取号右边要有个提示区就好了。或者 tips strError = e1.ErrorInfo; return -1; } else { parameter = e1.Parameter as GetCallNumberParameter; DomUtil.SetElementText(dom.DocumentElement, "accessNo", parameter.ResultAccessNo); bChanged = true; } } } if (bChanged == true) return 1; return 0; }