/////////////////////////////////////////////////////////// // PartInventoryAdjustmentItems.cs // Implementation of Class PartInventoryAdjustmentItems // CSLA type: Editable child collection // Created on: 07-Jun-2004 8:41:18 AM // Object design: Joyce // Coded: John 29-July-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Collection of objects used by the object /// [Serializable] public class PartInventoryAdjustmentItems : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private PartInventoryAdjustmentItems() { //Child MarkAsChild(); AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Retrieve PartInventoryAdjustmentItem by index /// /// Index public PartInventoryAdjustmentItem this[int Item] { get { return (PartInventoryAdjustmentItem) List[Item]; } } /// /// Retrieve PartInventoryAdjustmentItem by string containing Guid value /// public PartInventoryAdjustmentItem this[string PartInventoryAdjustmentItemID] { get { System.Guid sid = new System.Guid(PartInventoryAdjustmentItemID); foreach (PartInventoryAdjustmentItem child in List) { if(child.ID==sid) return child; } return null; } } /// /// Retrieve PartInventoryAdjustmentItem by Guid value /// public PartInventoryAdjustmentItem this[Guid PartInventoryAdjustmentItemGUID] { get { foreach (PartInventoryAdjustmentItem child in List) { if(child.ID==PartInventoryAdjustmentItemGUID) return child; } return null; } } /// /// Remove PartInventoryAdjustmentItem by passing it in /// /// public void Remove(PartInventoryAdjustmentItem obj) { List.Remove(obj); } /// /// Remove PartInventoryAdjustmentItem by string of id value /// /// public void Remove(string PartInventoryAdjustmentItemID) { System.Guid sid = new System.Guid(PartInventoryAdjustmentItemID); foreach (PartInventoryAdjustmentItem child in List) { if(child.ID==sid) List.Remove(child); } } /// /// Remove by Guid value of ID /// /// public void Remove(Guid PartInventoryAdjustmentItemID) {//case 1301 PartInventoryAdjustmentItem pDelete = null; foreach (PartInventoryAdjustmentItem child in List) { if (child.ID == PartInventoryAdjustmentItemID) { pDelete = child; break; } } if(pDelete!=null) List.Remove(pDelete); } /// /// /// /// Parent Adjustment object /// public PartInventoryAdjustmentItem Add(PartInventoryAdjustment Adjustment) { PartInventoryAdjustmentItem child=PartInventoryAdjustmentItem.NewItem( Adjustment.ID); List.Add(child); child.mDateAdjusted=Adjustment.sdDateAdjusted; return child; } /// /// Checks if grandchildren are dirty /// /// public bool GrandChildIsDirty() { foreach (PartInventoryAdjustmentItem child in List) { if(child.SerialNumbers.IsDirty==true) return true; } return false; } /// /// Checks if grandchildren are valid /// /// public bool GrandChildIsValid() { foreach (PartInventoryAdjustmentItem child in List) { if(child.SerialNumbers.IsValid==false) return false; } return true; } /// /// Remove empty items (qty zero) /// /// public void RemoveZeroQuantityItems() { foreach (PartInventoryAdjustmentItem child in List) { if(child.QuantityAdjustment==0) List.Remove(child); } } /// /// Sets broken rule for item /// if it's a duplicate in collection /// Only one instance of same part / warehouse allowed /// in collection to avoid several potential ways of damaging integrity /// of serial numbers and inventory /// public void CheckForDuplicateParts() { //clear all duplicate broken rules first //to start fresh foreach(PartInventoryAdjustmentItem ps in List) { ps.DuplicatePart=false; } //Loop through all foreach(PartInventoryAdjustmentItem pMain in List) { if(pMain.PartWarehouseID!=Guid.Empty && pMain.PartID!=Guid.Empty) { //compare to all other serials foreach(PartInventoryAdjustmentItem pOther in List) { if(pMain!=pOther && pOther.PartWarehouseID!=Guid.Empty && pOther.PartID!=Guid.Empty) { if(pMain.PartWarehouseID==pOther.PartWarehouseID && pMain.PartID==pOther.PartID ) { pMain.DuplicatePart=true; pOther.DuplicatePart=true; } } } } } } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(PartInventoryAdjustmentItem obj) { foreach (PartInventoryAdjustmentItem 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 PartInventoryAdjustmentItemID) { System.Guid sid = new System.Guid(PartInventoryAdjustmentItemID); foreach (PartInventoryAdjustmentItem child in List) { if(child.ID==sid) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(PartInventoryAdjustmentItem obj) { foreach (PartInventoryAdjustmentItem 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 PartInventoryAdjustmentItemID) { System.Guid sid = new System.Guid(PartInventoryAdjustmentItemID); foreach (PartInventoryAdjustmentItem child in deletedList) { if(child.ID==sid) return true; } return false; } #endregion #region Static methods /// /// NewItems /// /// internal static PartInventoryAdjustmentItems NewItems() { return new PartInventoryAdjustmentItems(); } /// /// GetItems /// /// /// internal static PartInventoryAdjustmentItems GetItems(SafeDataReader dr) { PartInventoryAdjustmentItems col = new PartInventoryAdjustmentItems(); 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(PartInventoryAdjustmentItem.GetItem(dr)); } } /// /// /// /// /// internal void Update(Guid ParentID,IDbTransaction tr) { //case 1301 System.Collections.Generic.List gBad=new System.Collections.Generic.List(); foreach (PartInventoryAdjustmentItem child in List) { if (child.PartID == Guid.Empty || child.QuantityAdjustment==0) gBad.Add(child.ID); } if (gBad.Count > 0) { foreach (Guid idBad in gBad) this.Remove(idBad); } //update (thus deleting) any deleted child objects foreach (PartInventoryAdjustmentItem child in deletedList) { child.Update( ParentID, tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (PartInventoryAdjustmentItem child in List) { child.Update( ParentID, tr); } } #endregion }//end PartInventoryAdjustmentItems }//end namespace GZTW.AyaNova.BLL