/////////////////////////////////////////////////////////// // WorkorderItemScheduledUsers.cs // Implementation of Class WorkorderItemScheduledUsers // CSLA type: Editable Grandchild collection // Created on: 07-Jun-2004 8:41:50 AM // Object design: Joyce // Coded: John 28-July-2004 /////////////////////////////////////////////////////////// using System; using GZTW.Data; using System.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Editable Grandchild collection of objects residing in parent object /// [Serializable] public class WorkorderItemScheduledUsers : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private WorkorderItemScheduledUsers() { //Child MarkAsChild(); AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Retrieve WorkorderItemScheduledUser by index /// /// Index public WorkorderItemScheduledUser this[int Item] { get { return (WorkorderItemScheduledUser) List[Item]; } } /// /// Retrieve WorkorderItemScheduledUser by string containing Guid value /// public WorkorderItemScheduledUser this[string WorkorderItemScheduledUserID] { get { System.Guid sid = new System.Guid(WorkorderItemScheduledUserID); foreach (WorkorderItemScheduledUser child in List) { if(child.ID==sid) return child; } return null; } } /// /// Retrieve WorkorderItemScheduledUser by Guid value /// public WorkorderItemScheduledUser this[Guid WorkorderItemScheduledUserID] {//case 1975 get { return this[WorkorderItemScheduledUserID.ToString()]; } } /// /// Remove WorkorderItemScheduledUser by passing it in /// /// public void Remove(WorkorderItemScheduledUser obj) { List.Remove(obj); } /// /// Remove WorkorderItemScheduledUser by string of id value /// /// public void Remove(string WorkorderItemScheduledUserID) { Remove( new System.Guid(WorkorderItemScheduledUserID)); } /// /// Remove by Guid value of ID /// /// public void Remove(Guid WorkorderItemScheduledUserID) { WorkorderItemScheduledUser delete = null; foreach (WorkorderItemScheduledUser child in List) { if (child.ID == WorkorderItemScheduledUserID) { delete = child; break; } } if (delete != null) List.Remove(delete); } /// /// Add a new WorkorderItemScheduledUser to the collection /// /// public WorkorderItemScheduledUser Add(WorkorderItem obj) { WorkorderItemScheduledUser child=WorkorderItemScheduledUser.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 (WorkorderItemScheduledUser child in List) { if(RO==false) RO=AyaBizUtils.Right("Object.WorkorderItemScheduledUser")<(int)SecurityLevelTypes.ReadWrite; child.SetReadOnly(RO); } } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(WorkorderItemScheduledUser obj) { foreach (WorkorderItemScheduledUser 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 WorkorderItemScheduledUserID) { System.Guid sid = new System.Guid(WorkorderItemScheduledUserID); foreach (WorkorderItemScheduledUser child in List) { if(child.ID==sid) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(WorkorderItemScheduledUser obj) { foreach (WorkorderItemScheduledUser 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 WorkorderItemScheduledUserID) { System.Guid sid = new System.Guid(WorkorderItemScheduledUserID); foreach (WorkorderItemScheduledUser child in deletedList) { if(child.ID==sid) return true; } return false; } #endregion #region Static methods /// /// NewItems /// /// internal static WorkorderItemScheduledUsers NewItems() { return new WorkorderItemScheduledUsers(); } /// /// Get items - Grandchild style /// /// /// internal static WorkorderItemScheduledUsers GetItems(WorkorderItem obj) { WorkorderItemScheduledUsers col = new WorkorderItemScheduledUsers(); //case 1317 if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemScheduledUser) > (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 //Load data Grandchild style SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString("SELECT * " + "FROM aWorkorderItemScheduledUser " + "WHERE aWorkorderItemID=@ID",obj.ID); while(dr.Read()) { List.Add(WorkorderItemScheduledUser.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 (WorkorderItemScheduledUser child in deletedList) { child.Update(obj,tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (WorkorderItemScheduledUser 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) { DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aWorkorderItemScheduledUser WHERE aWorkorderItemID=@ID;"); cmDelete.AddInParameter("@ID",DbType.Guid,WorkorderItemID); DBUtil.DB.ExecuteNonQuery(cmDelete, transaction); } #endregion #endregion }//end WorkorderItemScheduledUsers }//end namespace GZTW.AyaNova.BLL