/////////////////////////////////////////////////////////// // TaxCodes.cs // Implementation of Class TaxCodes // CSLA type: Editable root collection // Created on: 11-Nov-2004 // Object design: John // Coded: John 11-Nov-2004 /////////////////////////////////////////////////////////// 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 TaxCodes : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private TaxCodes() { 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 "TaxCode.Label.List"; } } /// /// Retrieve TaxCode by index /// /// Index public TaxCode this[int Item] { get { return (TaxCode) List[Item]; } } /// /// Remove TaxCode by passing it in /// /// public void Remove(TaxCode obj) { List.Remove(obj); } /// /// Remove by Guid value of ID /// /// public void Remove(Guid ID) { TaxCode delete = null; foreach (TaxCode child in List) { if (child.ID == ID) { delete = child; break; } } if (delete != null) Remove(delete); } /// /// Add a new TaxCode to the collection /// public TaxCode Add() { TaxCode child=TaxCode.NewItem(); List.Add(child); return child; } /// /// Add TaxCode by passing it in /// /// public void Add(TaxCode obj) { List.Add(obj); } /// /// /// /// protected override object OnAddNew() { TaxCode child=TaxCode.NewItem(); List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(TaxCode obj) { foreach (TaxCode child in List) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(TaxCode obj) { foreach (TaxCode child in deletedList) { if(child.Equals(obj)) return true; } return false; } #endregion #region Reporting /// /// Returns the report key which is a property of /// reports used to link all reports that can be used /// with a particular data source. /// public static string ReportKey { get { return "TaxCodes"; } } #endregion #region Static methods /// /// Get item collection /// /// /// public static TaxCodes GetItems() { //in future specify criteria if filtering (e.g. filter by region) TaxCodes col = new TaxCodes(); return (TaxCodes)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 aTaxCode;"); while(dr.Read()) { List.Add(TaxCode.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 (TaxCode child in deletedList) { child.Update(tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (TaxCode 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 TaxCodes }//end namespace GZTW.AyaNova.BLL