/////////////////////////////////////////////////////////// // ClientGroups.cs // Implementation of Class ClientGroups // CSLA type: Editable root collection // Created on: 04-Nov-2004 // Object design: John // Coded: John 04-Nov-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using GZTW.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Editable root collection of objects /// [Serializable] public class ClientGroups : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private ClientGroups() { AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Locale key so that generic list editor /// UI code knows what title to give the list in a /// grid /// public string LocaleKey { get { return "ClientGroup.Label.List"; } } /// /// Retrieve ClientGroup by index /// /// Index public ClientGroup this[int Item] { get { return (ClientGroup) List[Item]; } } //case 2072 /// /// Retrieve ClientGroup by Id /// /// ID of item public ClientGroup this[Guid Id] { get { foreach (ClientGroup child in List) { if (child.ID.Equals(Id)) return child; } return null; } } /// /// Remove ClientGroup by passing it in /// /// public void Remove(ClientGroup obj) { List.Remove(obj); } /// /// Remove by Guid value of ID /// /// public void Remove(Guid ID) { ClientGroup delete = null; foreach (ClientGroup child in List) { if (child.ID == ID) { delete = child; break; } } if (delete != null) Remove(delete); } /// /// Add a new ClientGroup to the collection /// public ClientGroup Add() { ClientGroup child=ClientGroup.NewItem(); List.Add(child); return child; } /// /// Add ClientGroup by passing it in /// /// public void Add(ClientGroup obj) { List.Add(obj); } /// /// /// /// protected override object OnAddNew() { ClientGroup child=ClientGroup.NewItem(); List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(ClientGroup obj) { foreach (ClientGroup child in List) { if(child.Equals(obj)) return true; } return false; } //case 2072 /// /// Check if item in collection by Id /// /// public bool Contains(Guid Id) { foreach (ClientGroup child in List) { if (child.ID.Equals(Id)) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(ClientGroup obj) { foreach (ClientGroup child in deletedList) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get item collection /// /// /// public static ClientGroups GetItems() { //in future specify criteria if filtering (e.g. filter by region) ClientGroups col = new ClientGroups(); return (ClientGroups)DataPortal.Fetch(new Criteria()); } #endregion #region DAL DATA ACCESS #region Fetch /// /// Fetch children /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aClientGroup ORDER BY ANAME;"); while(dr.Read()) { List.Add(ClientGroup.GetItem(dr)); } } finally { if(dr!=null) dr.Close(); } } #endregion #region Update /// /// Editable Root Collection Update /// protected override void DataPortal_Update() { using (IDbConnection connection = DBUtil.DB.GetConnection()) { connection.Open(); IDbTransaction tr = connection.BeginTransaction(); try { //update (thus deleting) any deleted child objects foreach (ClientGroup child in deletedList) { child.Update(tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (ClientGroup child in List) { child.Update(tr); } tr.Commit(); } catch { tr.Rollback(); throw;//WAS: throw(ex); } } } #endregion update #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { //public string ObjectName; public Criteria(/*string _ObjectName*/) { //ObjectName=_ObjectName; } } #endregion }//end ClientGroups }//end namespace GZTW.AyaNova.BLL