/////////////////////////////////////////////////////////// // WorkorderItemLabors.cs // Implementation of Class WorkorderItemLabors // CSLA type: Editable Grandchild collection // Created on: 07-Jun-2004 8:41:48 AM // Object design: Joyce // Coded: John 28-July-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using CSLA; using GZTW.Data; namespace GZTW.AyaNova.BLL { /// ///Editable Grandchild collection of objects residing in parent object /// [Serializable] public class WorkorderItemLabors : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private WorkorderItemLabors() { //Child MarkAsChild(); AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Retrieve WorkorderItemLabor by index /// /// Index public WorkorderItemLabor this[int Item] { get { return (WorkorderItemLabor) List[Item]; } } /// /// Retrieve WorkorderItemLabor by string containing Guid value /// public WorkorderItemLabor this[string sID] { get { System.Guid sid = new System.Guid(sID); foreach (WorkorderItemLabor child in List) { if(child.ID==sid) return child; } return null; } } /// /// Retrieve WorkorderItemLabor by Guid value /// public WorkorderItemLabor this[Guid ID] {//case 1975 - should have been in from the start (why a string?) get { return this[ID.ToString()]; } } /// /// Remove WorkorderItemLabor by passing it in /// /// public void Remove(WorkorderItemLabor obj) { List.Remove(obj); } /// /// Remove WorkorderItemLabor by string of id value /// /// public void Remove(string WorkorderItemLaborID) { System.Guid sid = new System.Guid(WorkorderItemLaborID); Remove(sid); } /// /// Remove by Guid value of ID /// /// public void Remove(Guid WorkorderItemLaborID) { WorkorderItemLabor delete = null; foreach (WorkorderItemLabor child in List) { if (child.ID == WorkorderItemLaborID) { delete = child; break; } } if (delete != null) Remove(delete); } /// /// Add a new WorkorderItemLabor to the collection /// /// public WorkorderItemLabor Add(WorkorderItem obj) { WorkorderItemLabor child=WorkorderItemLabor.NewItem(obj); List.Add(child); return child; } /// /// Sets all items to read / write status /// used by workorder object when it's closed or service completed is true /// /// true=Set to read only explicitly, false=set to whatever rights allowed public void SetReadOnly(bool RO) { foreach (WorkorderItemLabor child in List) { if(RO==false) RO=AyaBizUtils.Right("Object.WorkorderItemLabor")<(int)SecurityLevelTypes.ReadWrite; child.SetReadOnly(RO); } } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(WorkorderItemLabor obj) { foreach (WorkorderItemLabor 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 WorkorderItemLaborID) { System.Guid sid = new System.Guid(WorkorderItemLaborID); foreach (WorkorderItemLabor child in List) { if(child.ID==sid) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(WorkorderItemLabor obj) { foreach (WorkorderItemLabor 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 WorkorderItemLaborID) { System.Guid sid = new System.Guid(WorkorderItemLaborID); foreach (WorkorderItemLabor child in deletedList) { if(child.ID==sid) return true; } return false; } #endregion #region Static methods /// /// NewItems /// /// internal static WorkorderItemLabors NewItems() { return new WorkorderItemLabors(); } /// /// Get items - Grandchild style /// /// /// internal static WorkorderItemLabors GetItems(WorkorderItem obj) { WorkorderItemLabors col = new WorkorderItemLabors(); //case 1317 if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemLabor) > (int)SecurityLevelTypes.NoAccess) col.Fetch(obj); return col; } #endregion #region DAL DATA ACCESS /// /// Fetch children - grandchild style /// /// private void Fetch(WorkorderItem obj) { //Load data Grandchild style SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString("SELECT * " + "FROM aWorkorderItemLabor " + "WHERE aWorkorderItemID=@ID",obj.ID); while(dr.Read()) { List.Add(WorkorderItemLabor.GetItem(dr, obj)); } } finally { if(dr!=null) dr.Close(); } } /// /// Update children /// /// /// internal void Update(WorkorderItem obj,IDbTransaction tr) { //update (thus deleting) any deleted child objects foreach (WorkorderItemLabor child in deletedList) { child.Update(obj,tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (WorkorderItemLabor child in List) { child.Update(obj,tr); } } #region Shared delete method /// /// Given a workorder item ID deletes all items for that ID /// /// Called by workorderitems delete /// /// ID of parent workorder item /// Database transaction from ascendant item internal static void DeleteItems(Guid WorkorderItemID,IDbTransaction transaction) { System.Collections.ArrayList alSBID=new System.Collections.ArrayList(); System.Collections.ArrayList alID=new System.Collections.ArrayList(); SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString("SELECT aID, aServiceBankID " + "FROM aWorkorderItemLabor " + "WHERE aWorkorderItemID=@ID",WorkorderItemID,transaction); while(dr.Read()) { //Make a reversing entry in the service bank //if necessary if(dr.GetGuid("aServiceBankID")!=Guid.Empty) alSBID.Add(dr.GetGuid("aServiceBankID")); //Keywords alID.Add(dr.GetGuid("aID")); } dr.Close(); //Make a reversing entry in the service bank //if necessary foreach(object o in alSBID) ServiceBank.ReverseItem((Guid)o,transaction); //Keywords foreach(object o in alID) DBUtil.RemoveKeywords(transaction, RootObjectTypes.WorkorderItemLabor,(Guid)o); } finally { if(dr!=null) dr.Close(); } //Delete objects themselves DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aWorkorderItemLabor WHERE aWorkorderItemID=@ID;"); cmDelete.AddInParameter("@ID",DbType.Guid,WorkorderItemID); DBUtil.DB.ExecuteNonQuery(cmDelete, transaction); } #endregion #endregion }//end WorkorderItemLabors }//end namespace GZTW.AyaNova.BLL