Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/IntegrationMaps.cs
2018-06-29 19:47:36 +00:00

306 lines
7.3 KiB
C#

///////////////////////////////////////////////////////////
// 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
{
/// <summary>
/// Editable child collection of <see cref="IntegrationMap"/> objects
/// </summary>
[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
/// <summary>
/// Retrieve IntegrationMap by index
/// </summary>
/// <param name="Item">Index</param>
public IntegrationMap this[int Item]
{
get
{
return (IntegrationMap) List[Item];
}
}
/// <summary>
/// Retrieve <see cref="IntegrationMap"/> by string containing ForeignID value
/// Note: if you have more than one <see cref="IntegrationMap"/> 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.
/// </summary>
/// <returns><see cref="IntegrationMap"/></returns>
public IntegrationMap this[string ForeignID, RootObjectTypes ObjectType]
{
get
{
foreach (IntegrationMap child in List)
{
if(child.ForeignID==ForeignID && child.RootObjectType==ObjectType)
return child;
}
return null;
}
}
/// <summary>
/// Retrieve <see cref="IntegrationMap"/> 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
///
/// </summary>
public IntegrationMap this[Guid ObjectID]
{
get
{
foreach (IntegrationMap child in List)
{
if(child.RootObjectID==ObjectID)
return child;
}
return null;
}
}
/// <summary>
/// Remove <see cref="IntegrationMap"/> by passing it in
/// </summary>
/// <param name="obj"></param>
public void Remove(IntegrationMap obj)
{
List.Remove(obj);
}
/// <summary>
/// Remove <see cref="IntegrationMap"/> by string of internal ID value
/// </summary>
/// <param name="IntegrationMapID"></param>
public void Remove(string IntegrationMapID)
{
System.Guid sid = new System.Guid(IntegrationMapID);
Remove(sid);
}
/// <summary>
/// Remove by Guid value of ID
/// </summary>
/// <param name="IntegrationMapID"></param>
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);
}
/// <summary>
/// Add a new <see cref="IntegrationMap"/> to the collection
/// </summary>
/// <param name="obj"></param>
public IntegrationMap Add(Integration obj)
{
IntegrationMap child=IntegrationMap.NewItem(obj);
List.Add(child);
return child;
}
/// <summary>
/// Fetch just the ForeignID string
/// based on the AyaNova RootObject ID
/// </summary>
/// <param name="objectID">ID of AyaNova object</param>
/// <returns>Foreign ID or empty string if not found</returns>
public string GetForeignID(Guid objectID)
{
foreach (IntegrationMap child in List)
{
if(child.RootObjectID==objectID)
return child.ForeignID;
}
return "";
}
/// <summary>
/// Get any broken rules in entire collection as a string
/// </summary>
/// <returns></returns>
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
/// <summary>
/// Check if item in collection by Guid of
/// AyaNova RootObject ID
/// </summary>
/// <param name="RootObjectID"></param>
public bool Contains(Guid RootObjectID)
{
foreach (IntegrationMap child in List)
{
if(child.RootObjectID==RootObjectID) return true;
}
return false;
}
/// <summary>
/// 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)
/// </summary>
/// <param name="ForeignID">String foreign ID value</param>
/// <param name="RootObjectType">Root object type from RootObjects enum</param>
public bool Contains(string ForeignID, RootObjectTypes RootObjectType)
{
foreach (IntegrationMap child in List)
{
if(child.ForeignID==ForeignID && child.RootObjectType==RootObjectType) return true;
}
return false;
}
/// <summary>
/// Check if item in collection by AyaNova type
///
///
///
/// </summary>
/// <param name="RootObjectType"></param>
/// <returns>True if one or more objects of the specified type are found or false if not</returns>
public bool ContainsType(RootObjectTypes RootObjectType)
{
foreach (IntegrationMap child in List)
{
if(child.RootObjectType==RootObjectType) return true;
}
return false;
}
#endregion
#region Static methods
/// <summary>
/// NewItems
/// </summary>
/// <returns></returns>
internal static IntegrationMaps NewItems()
{
return new IntegrationMaps();
}
/// <summary>
/// GetItems
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
internal static IntegrationMaps GetItems(SafeDataReader dr)
{
IntegrationMaps col = new IntegrationMaps();
col.Fetch(dr);
return col;
}
#endregion
#region DAL DATA ACCESS
/// <summary>
/// Fetch children
/// </summary>
/// <param name="dr">Populated data reader</param>
private void Fetch(SafeDataReader dr)
{
while(dr.Read())
{
List.Add(IntegrationMap.GetItem(dr));
}
}
/// <summary>
/// Update children
/// </summary>
/// <param name="obj"></param>
/// <param name="tr"></param>
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