/////////////////////////////////////////////////////////// // PartWarehouses.cs // Implementation of Class PartWarehouses // CSLA type: Editable root collection // Created on: 04-Nov-2004 // Object design: Joyce // 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 PartWarehouses : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private PartWarehouses() { AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=false; } #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 "PartWarehouse.Label.List"; } } /// /// Retrieve PartWarehouse by index /// /// Index public PartWarehouse this[int Item] { get { return (PartWarehouse) List[Item]; } } /// /// Remove PartWarehouse by passing it in /// /// public void Remove(PartWarehouse obj) { List.Remove(obj); } /// /// Remove by Guid value of ID /// /// public void Remove(Guid ID) { PartWarehouse delete = null; foreach (PartWarehouse child in List) { if (child.ID == ID) { delete = child; break; } } if (delete != null) Remove(delete); } /// /// Add a new PartWarehouse to the collection /// public PartWarehouse Add() { PartWarehouse child=PartWarehouse.NewItem(); List.Add(child); return child; } /// /// Add PartWarehouse by passing it in /// /// public void Add(PartWarehouse obj) { List.Add(obj); } /// /// /// /// protected override object OnAddNew() { PartWarehouse child=PartWarehouse.NewItem(); List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(PartWarehouse obj) { foreach (PartWarehouse child in List) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(PartWarehouse obj) { foreach (PartWarehouse child in deletedList) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get item collection /// /// /// public static PartWarehouses GetItems(bool Regional) { //in future specify criteria if filtering (e.g. filter by region) PartWarehouses col = new PartWarehouses(); return (PartWarehouses)DataPortal.Fetch(new Criteria(Regional)); } #endregion #region DAL DATA ACCESS /// /// Fetch children /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString(DBUtil.AddRegionFilter("SELECT * FROM aPartWarehouse ORDER BY ANAME ","aPartWarehouse","",crit.Regional)); while(dr.Read()) { List.Add(PartWarehouse.GetItem(dr)); } } finally { if(dr!=null) dr.Close(); } } /// /// 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 (PartWarehouse child in deletedList) { child.Update(tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (PartWarehouse child in List) { child.Update(tr); } tr.Commit(); } catch { tr.Rollback(); throw;//WAS: throw(ex); } } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public bool Regional; public Criteria(bool _Regional) { Regional = _Regional; } } #endregion }//end PartWarehouses }//end namespace GZTW.AyaNova.BLL