public LookupRowValidator(XmlElement XmlNode) { mevKeyValue = new EnumerationValidator(XmlNode.SelectSingleNode("Enumeration") as XmlElement); mKeyFieldName = XmlNode.SelectSingleNode("KeyField").InnerText; mValueFieldName = XmlNode.SelectSingleNode("ValueField").InnerText; }
public EnumerationEnhancementValidator(XmlElement XmlNode) { //存放動態取得之列舉值清單 List<string> dynamicValues = new List<string>(); //靜態之列舉值清單 (直接寫在驗證規則裡) List<string> staticValues = new List<string>(); foreach (XmlElement Elm in XmlNode.SelectNodes("Source")) { string Type = Elm.GetAttribute("Type"); if (Type.Equals("Excel")) { #region Excel try { string Path = @Elm.GetAttribute("Path"); string SheetName = Elm.GetAttribute("SheetName"); string ColumnName = Elm.GetAttribute("ColumnName"); dynamicValues.AddRange(GetItemsFromExcel(Path, SheetName, ColumnName)); } catch { } #endregion } else if (Type.Equals("UserPreferences")) { #region UserPreferences try { string Name = Elm.GetAttribute("Name"); XmlDocument xmlDoc = new XmlDocument(); //是否有資料夾 if (!Directory.Exists(Path.Combine(Application.StartupPath, "ValidationReports"))) { Directory.CreateDirectory(Path.Combine(Application.StartupPath, "ValidationReports")); } xmlDoc.Load(Path.Combine(Application.StartupPath + "\\ValidationReports", "ValidationPreferences.xml")); XmlElement Mapping = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("Mapping[@Name='" + Name + "']"); if (Mapping != null) { dynamicValues.AddRange(GetItemsFromExcel( Mapping.GetAttribute("Path"), Mapping.GetAttribute("SheetName"), Mapping.GetAttribute("ColumnName") )); } } catch { } #endregion } } XmlDocument doc = new XmlDocument(); XmlElement ContentXmlNode = doc.CreateElement("FieldValidator"); //加入靜態的 Item Nodes foreach (XmlElement item in XmlNode.SelectNodes("Item")) { ContentXmlNode.AppendChild(ContentXmlNode.OwnerDocument.ImportNode(item, true)); staticValues.Add(item.GetAttribute("Value")); } //加入動態的 Item Nodes foreach (string value in dynamicValues.Except(staticValues).ToList()) { XmlElement ItemElm = ContentXmlNode.OwnerDocument.CreateElement("Item"); ItemElm.SetAttribute("Value", value); ContentXmlNode.AppendChild(ItemElm); } Validator = new EnumerationValidator(ContentXmlNode); }