/////////////////////////////////////////////////////////// // IntegrationMaps.cs // Implementation of Class IntegrationMaps // CSLA type: Editable child collection // Created on: 09-Feb-2006 // Object design: John // Coded: John 09-Feb-2006 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Editable child collection of objects /// [Serializable] public class IntegrationMaps : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private IntegrationMaps() { //Child MarkAsChild(); AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Retrieve IntegrationMap by index /// /// Index public IntegrationMap this[int Item] { get { return (IntegrationMap) List[Item]; } } /// /// Retrieve by string containing ForeignID value /// Note: if you have more than one with the same ForeignID /// this will return the first one found /// /// It is not a good idea to have more than one foreign ID with /// the same value if possible. /// /// public IntegrationMap this[string ForeignID, RootObjectTypes ObjectType] { get { foreach (IntegrationMap child in List) { if(child.ForeignID==ForeignID && child.RootObjectType==ObjectType) return child; } return null; } } /// /// Retrieve by AyaNova RootObject ID and type /// Note: Since AyaNova ID's are always unique this will /// return the correct item without need for the type /// /// public IntegrationMap this[Guid ObjectID] { get { foreach (IntegrationMap child in List) { if(child.RootObjectID==ObjectID) return child; } return null; } } /// /// Remove by passing it in /// /// public void Remove(IntegrationMap obj) { List.Remove(obj); } /// /// Remove by string of internal ID value /// /// public void Remove(string IntegrationMapID) { System.Guid sid = new System.Guid(IntegrationMapID); Remove(sid); } /// /// Remove by Guid value of ID /// /// public void Remove(Guid IntegrationMapID) { IntegrationMap delete = null; foreach (IntegrationMap child in List) { if (child.ID == IntegrationMapID) { delete = child; break; } } if (delete != null) Remove(delete); } /// /// Add a new to the collection /// /// public IntegrationMap Add(Integration obj) { IntegrationMap child=IntegrationMap.NewItem(obj); List.Add(child); return child; } /// /// Fetch just the ForeignID string /// based on the AyaNova RootObject ID /// /// ID of AyaNova object /// Foreign ID or empty string if not found public string GetForeignID(Guid objectID) { foreach (IntegrationMap child in List) { if(child.RootObjectID==objectID) return child.ForeignID; } return ""; } /// /// Get any broken rules in entire collection as a string /// /// public string GetBrokenRules() { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach(IntegrationMap child in List) { if(child.BrokenRulesText!="") sb.Append(child.Name + ": " + child.BrokenRulesText); } return sb.ToString(); } #endregion #region Contains /// /// Check if item in collection by Guid of /// AyaNova RootObject ID /// /// public bool Contains(Guid RootObjectID) { foreach (IntegrationMap child in List) { if(child.RootObjectID==RootObjectID) return true; } return false; } /// /// Check if item in collection by foreignID value /// and object type. /// /// (object type is necessary because in many cases there are duplicate foriegn id values /// for example a 3rd party program that uses serial integers to identify it's objects /// and re-uses the integer for different object types) /// /// String foreign ID value /// Root object type from RootObjects enum public bool Contains(string ForeignID, RootObjectTypes RootObjectType) { foreach (IntegrationMap child in List) { if(child.ForeignID==ForeignID && child.RootObjectType==RootObjectType) return true; } return false; } /// /// Check if item in collection by AyaNova type /// /// /// /// /// /// True if one or more objects of the specified type are found or false if not public bool ContainsType(RootObjectTypes RootObjectType) { foreach (IntegrationMap child in List) { if(child.RootObjectType==RootObjectType) return true; } return false; } #endregion #region Static methods /// /// NewItems /// /// internal static IntegrationMaps NewItems() { return new IntegrationMaps(); } /// /// GetItems /// /// /// internal static IntegrationMaps GetItems(SafeDataReader dr) { IntegrationMaps col = new IntegrationMaps(); col.Fetch(dr); return col; } #endregion #region DAL DATA ACCESS /// /// Fetch children /// /// Populated data reader private void Fetch(SafeDataReader dr) { while(dr.Read()) { List.Add(IntegrationMap.GetItem(dr)); } } /// /// Update children /// /// /// internal void Update(Integration obj,IDbTransaction tr) { //update (thus deleting) any deleted child objects foreach (IntegrationMap child in deletedList) { child.Update(obj,tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (IntegrationMap child in List) { child.Update(obj,tr); } } #endregion }//end IntegrationMaps }//end namespace GZTW.AyaNova.BLL