public override void SaveLookups(LookupItemCollection lookups) { var root = CurrentXmlLookup.DocumentElement; var targetCollection = root.SelectSingleNode(String.Format("lookupCollection[@name='{0}']", lookups.CollectionName)); if (targetCollection == null) { targetCollection = CurrentXmlLookup.CreateNode(XmlNodeType.Element, "lookup", null); var nameAttr = CurrentXmlLookup.CreateAttribute(nameAttributeName); nameAttr.Value = lookups.CollectionName; targetCollection.Attributes.Append(nameAttr); CurrentXmlLookup.AppendChild(targetCollection); } else { targetCollection.RemoveAll(); var nameAttr = CurrentXmlLookup.CreateAttribute(nameAttributeName); nameAttr.Value = lookups.CollectionName; targetCollection.Attributes.Append(nameAttr); } foreach (var lookup in lookups) { XmlNode newNode = CurrentXmlLookup.CreateNode(XmlNodeType.Element, "lookup", null); newNode.InnerText = lookup.LookupDesc; var idAttr = CurrentXmlLookup.CreateAttribute(idAttributeName); idAttr.Value = lookup.LookupID; var codeAttr = CurrentXmlLookup.CreateAttribute(codeAttributeName); codeAttr.Value = lookup.LookupCode; var viewOrderAttr = CurrentXmlLookup.CreateAttribute(viewOrderAttributeName); viewOrderAttr.Value = lookup.ViewOrder.ToString(); newNode.Attributes.Append(idAttr); newNode.Attributes.Append(codeAttr); newNode.Attributes.Append(viewOrderAttr); targetCollection.AppendChild(newNode); } CurrentXmlLookup.Save(XmlFileName); }
protected override LookupItemCollection InitializeLookups (string collectionName) { var root = CurrentXmlLookup.DocumentElement; var targetCollection = root.SelectSingleNode(String.Format("lookupCollection[@name='{0}']",collectionName)); if (targetCollection == null) { return null; } LookupItemCollection result = new LookupItemCollection(collectionName); foreach (XmlNode item in targetCollection.ChildNodes) { LookupItem currentLookup = InitializeLookupItem(item); currentLookup.CollectionName = collectionName; result.Add(currentLookup); } return result; }
protected override LookupItemCollection InitializeLookups(string collectionName) { var root = CurrentXmlLookup.DocumentElement; var targetCollection = root.SelectSingleNode(String.Format("lookupCollection[@name='{0}']", collectionName)); if (targetCollection == null) { return(null); } LookupItemCollection result = new LookupItemCollection(collectionName); foreach (XmlNode item in targetCollection.ChildNodes) { LookupItem currentLookup = InitializeLookupItem(item); currentLookup.CollectionName = collectionName; result.Add(currentLookup); } return(result); }
public void CanReadAddRemoveLookupItem() { LookupDataModelProvider lookupDataModel = ProviderFactory.GetInstance <LookupDataModelFactory> (ProviderRepositoryFactory.Instance.Provider).GetDefaultProvider <LookupDataModelProvider> (); Assert.AreNotEqual(lookupDataModel.GetLookups("dataType").Count, 0); Assert.AreEqual(lookupDataModel.GetLookups("dataType").Count, 2); Assert.AreEqual(lookupDataModel.GetLookups("dataType")["1"].LookupID, "1"); Assert.AreEqual(lookupDataModel.GetLookups("dataType")["1"].LookupDesc, "String"); LookupItemCollection dataTypes = lookupDataModel.GetLookups("dataType"); LookupItem newItem = new LookupItem(); newItem.LookupID = "3"; newItem.LookupDesc = "Percentage"; newItem.LookupCode = "3"; dataTypes.Add(newItem); lookupDataModel.SaveLookups(dataTypes); var xmlDoc = new XmlDocument(); xmlDoc.Load(lookupDataModel.XmlFileName); var dataTypeNode = xmlDoc.DocumentElement.SelectSingleNode(String.Format("lookupCollection[@name='{0}']", dataTypes.CollectionName)); Assert.AreEqual(dataTypeNode.ChildNodes.Count, 3); Assert.AreEqual(dataTypeNode.ChildNodes[2].Attributes["code"].Value, "3"); dataTypes = lookupDataModel.GetLookups("dataType"); dataTypes.Remove(dataTypes["3"]); lookupDataModel.SaveLookups(dataTypes); xmlDoc = new XmlDocument(); xmlDoc.Load(lookupDataModel.XmlFileName); dataTypeNode = xmlDoc.DocumentElement.SelectSingleNode(String.Format("lookupCollection[@name='{0}']", dataTypes.CollectionName)); Assert.AreEqual(dataTypeNode.ChildNodes.Count, 2); Assert.AreNotEqual(dataTypeNode.ChildNodes[1].Attributes["code"].Value, "3"); }
public override void SaveLookups (LookupItemCollection lookups) { var root = CurrentXmlLookup.DocumentElement; var targetCollection = root.SelectSingleNode (String.Format ("lookupCollection[@name='{0}']", lookups.CollectionName)); if (targetCollection == null) { targetCollection = CurrentXmlLookup.CreateNode (XmlNodeType.Element, "lookup", null); var nameAttr = CurrentXmlLookup.CreateAttribute (nameAttributeName); nameAttr.Value = lookups.CollectionName; targetCollection.Attributes.Append (nameAttr); CurrentXmlLookup.AppendChild (targetCollection); } else { targetCollection.RemoveAll (); var nameAttr = CurrentXmlLookup.CreateAttribute (nameAttributeName); nameAttr.Value = lookups.CollectionName; targetCollection.Attributes.Append (nameAttr); } foreach (var lookup in lookups) { XmlNode newNode = CurrentXmlLookup.CreateNode(XmlNodeType.Element,"lookup", null); newNode.InnerText = lookup.LookupDesc; var idAttr = CurrentXmlLookup.CreateAttribute(idAttributeName); idAttr.Value = lookup.LookupID; var codeAttr = CurrentXmlLookup.CreateAttribute(codeAttributeName); codeAttr.Value = lookup.LookupCode; var viewOrderAttr = CurrentXmlLookup.CreateAttribute(viewOrderAttributeName); viewOrderAttr.Value = lookup.ViewOrder.ToString(); newNode.Attributes.Append(idAttr); newNode.Attributes.Append(codeAttr); newNode.Attributes.Append(viewOrderAttr); targetCollection.AppendChild(newNode); } CurrentXmlLookup.Save(XmlFileName); }
public abstract void SaveLookups(LookupItemCollection lookups);