/////////////////////////////////////////////////////////// // PurchaseOrderItems.cs // Implementation of Class PurchaseOrderItems // CSLA type: Editable child collection // Created on: 07-Jun-2004 8:41:31 AM // Object design: Joyce // Coded: John 27-July-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Editable child collection of objects /// [Serializable] public class PurchaseOrderItems : BusinessCollectionBase { private bool _Locked=false; #region Constructor //Private constructor prevents direction instantiation private PurchaseOrderItems() { //Child MarkAsChild(); AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Retrieve PurchaseOrderItem by index /// /// Index public PurchaseOrderItem this[int Item] { get { return (PurchaseOrderItem) List[Item]; } } /// /// Retrieve PurchaseOrderItem by string containing Guid value /// public PurchaseOrderItem this[string PurchaseOrderItemID] { get { System.Guid sid = new System.Guid(PurchaseOrderItemID); foreach (PurchaseOrderItem child in List) { if(child.ID==sid) return child; } return null; } } /// /// Remove PurchaseOrderItem by passing it in /// /// public void Remove(PurchaseOrderItem obj) { if(_Locked) throw new System.ApplicationException ( LocalizedTextTable.GetLocalizedTextDirect("PurchaseOrder.Label.Error.Locked") ); List.Remove(obj); } /// /// Remove PurchaseOrderItem by string of id value /// /// public void Remove(string PurchaseOrderItemID) { if(_Locked) throw new System.ApplicationException ( LocalizedTextTable.GetLocalizedTextDirect("PurchaseOrder.Label.Error.Locked") ); System.Guid sid = new System.Guid(PurchaseOrderItemID); //case 564 - found this was buggy, can't remove while iterating collection //changed accordingly PurchaseOrderItem poidelete = null; foreach (PurchaseOrderItem child in List) { if (child.ID == sid) { poidelete = child; break; } } if (poidelete != null) List.Remove(poidelete); } /// /// Remove by Guid value of ID /// /// public void Remove(Guid PurchaseOrderItemID) { if(_Locked) throw new System.ApplicationException ( LocalizedTextTable.GetLocalizedTextDirect("PurchaseOrder.Label.Error.Locked") ); //case 564 - found this was buggy, can't remove while iterating collection //changed accordingly PurchaseOrderItem poidelete = null; foreach (PurchaseOrderItem child in List) { if (child.ID == PurchaseOrderItemID) { poidelete = child; break; } } if (poidelete != null) List.Remove(poidelete); } /// /// Add a new PurchaseOrderItem to the collection /// /// public PurchaseOrderItem Add(PurchaseOrder obj) { if(_Locked) throw new System.ApplicationException ( LocalizedTextTable.GetLocalizedTextDirect("PurchaseOrder.Label.Error.Locked") ); PurchaseOrderItem child=PurchaseOrderItem.NewItem(obj); List.Add(child); return child; } /// /// Set all items to read only /// public void SetAllItemsReadOnly() { _Locked=true; foreach (PurchaseOrderItem child in List) { child.bReadOnly=true; } } //case 564 helper internal bool IsLocked { get { return _Locked; } } /// /// Set all items to writeable /// /// /// internal void SetAllItemsWrite()//required to support case 564, called from po db update { _Locked = false; foreach (PurchaseOrderItem child in List) { child.bReadOnly = false; } } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(PurchaseOrderItem obj) { foreach (PurchaseOrderItem child in List) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in collection by string of ID value /// /// public bool Contains(string PurchaseOrderItemID) { System.Guid sid = new System.Guid(PurchaseOrderItemID); foreach (PurchaseOrderItem child in List) { if(child.ID==sid) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(PurchaseOrderItem obj) { foreach (PurchaseOrderItem child in deletedList) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in deleted collection by string of ID value /// /// public bool ContainsDeleted(string PurchaseOrderItemID) { System.Guid sid = new System.Guid(PurchaseOrderItemID); foreach (PurchaseOrderItem child in deletedList) { if(child.ID==sid) return true; } return false; } #endregion #region Static methods /// /// NewItems /// /// internal static PurchaseOrderItems NewItems() { return new PurchaseOrderItems(); } /// /// GetItems /// /// /// internal static PurchaseOrderItems GetItems(SafeDataReader dr) { PurchaseOrderItems col = new PurchaseOrderItems(); 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(PurchaseOrderItem.GetItem(dr)); } } /// /// Update children /// /// /// internal void Update(PurchaseOrder obj,IDbTransaction tr) { //update (thus deleting) any deleted child objects foreach (PurchaseOrderItem child in deletedList) { child.Update(obj,tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (PurchaseOrderItem child in List) { child.Update(obj,tr); } } #endregion }//end PurchaseOrderItems }//end namespace GZTW.AyaNova.BLL