/////////////////////////////////////////////////////////// // Tasks.cs // Implementation of Class Tasks // CSLA type: Editable root collection // Created on: 04-Nov-2004 // Object design: John // Coded: John 04-Nov-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using GZTW.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Collection of objects /// [Serializable] public class Tasks : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private Tasks() { AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Locale key so that generic list editor /// UI code knows what title to give the list in a /// grid /// public string LocaleKey { get { return "Task.Label.List"; } } /// /// Retrieve Task by index /// /// Index public Task this[int Item] { get { return (Task) List[Item]; } } /// /// Remove Task by passing it in /// /// public void Remove(Task obj) { List.Remove(obj); } /// /// Add a new Task to the collection /// public Task Add() { Task child=Task.NewItem(); List.Add(child); return child; } /// /// Add Task by passing it in /// /// public void Add(Task obj) { List.Add(obj); } /// /// /// /// protected override object OnAddNew() { Task child=Task.NewItem(); List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(Task obj) { foreach (Task child in List) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(Task obj) { foreach (Task child in deletedList) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get item collection /// /// /// public static Tasks GetItems() { //in future specify criteria if filtering (e.g. filter by region) Tasks col = new Tasks(); return (Tasks)DataPortal.Fetch(new Criteria()); } #endregion #region DAL DATA ACCESS /// /// Fetch children /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aTask ORDER BY ANAME;"); while(dr.Read()) { List.Add(Task.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 (Task child in deletedList) { child.Update(tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (Task 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 string ObjectName; public Criteria(/*string _ObjectName*/) { //ObjectName=_ObjectName; } } #endregion }//end Tasks }//end namespace GZTW.AyaNova.BLL