/////////////////////////////////////////////////////////// // PartByWarehouseInventories.cs // Implementation of Class PartByWarehouseInventories // CSLA type: Editable root collection // Created on: 24-Nov-2005 // Object design: Joyce // Coded: 24-Nov-2005 /////////////////////////////////////////////////////////// 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 PartByWarehouseInventories : BusinessCollectionBase //v8port: This is only used to feed the PartByWarehouseInventoryForm which is only used to set teh restock level and view inventory levels, it's redundant { private Guid mPartID=Guid.Empty; #region Constructor //Private constructor prevents direction instantiation private PartByWarehouseInventories() { AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Retrieve PartByWarehouseInventory by index /// /// Index public PartByWarehouseInventory this[int Item] { get { return (PartByWarehouseInventory) List[Item]; } } /// /// Remove PartByWarehouseInventory by passing it in /// /// public void Remove(PartByWarehouseInventory obj) { List.Remove(obj); } /// /// Add a new PartByWarehouseInventory to the collection /// public PartByWarehouseInventory Add() { PartByWarehouseInventory child=PartByWarehouseInventory.NewItem(); child.PartID=mPartID; List.Add(child); return child; } /// /// Add PartByWarehouseInventory by passing it in /// /// public void Add(PartByWarehouseInventory obj) { List.Add(obj); } /// /// /// /// protected override object OnAddNew() { PartByWarehouseInventory child=PartByWarehouseInventory.NewItem(); List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(PartByWarehouseInventory obj) { foreach (PartByWarehouseInventory child in List) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(PartByWarehouseInventory obj) { foreach (PartByWarehouseInventory child in deletedList) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get item collection /// /// /// public static PartByWarehouseInventories GetItems(Guid PartID) { PartByWarehouseInventories col = new PartByWarehouseInventories(); col.mPartID=PartID; return (PartByWarehouseInventories)DataPortal.Fetch(new Criteria(PartID)); } #endregion #region DAL DATA ACCESS /// /// Fetch children /// /// PartID protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aPartByWarehouseInventory WHERE aPartID=@ID;",crit.PartID); while(dr.Read()) { List.Add(PartByWarehouseInventory.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 (PartByWarehouseInventory child in deletedList) { child.Update(tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (PartByWarehouseInventory 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 Guid PartID; public Criteria(Guid _PartID) { PartID=_PartID; } } #endregion }//end PartByWarehouseInventories }//end namespace GZTW.AyaNova.BLL