/////////////////////////////////////////////////////////// // UIUserGridLastViews.cs // Implementation of Class UIUserGridLastViews // CSLA type: Editable root collection // Created on: 22-May-2006 // Object design: John // Coded: John 22-May-2006 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using GZTW.Data; using CSLA; namespace GZTW.AyaNova.BLL { #pragma warning disable 1591 /// /// /// [Serializable] public class UIUserGridLastViews : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private UIUserGridLastViews() { //AllowSort = true; //AllowFind = true; //AllowEdit = true; //AllowNew = true; //AllowRemove = true; } #endregion #region Business properties and methods /// /// Retrieve UIUserGridLastView by index /// /// Index public UIUserGridLastView this[int Item] { get { return (UIUserGridLastView)List[Item]; } } /// /// Retrieve UIUserGridLastView by string containing GridKey's name value /// If the GridKey in question is not found, a new one is created and if the /// manager account has one for that GridKey then it's settings are copied to it /// before returning. /// /// This ensures that new users get the managers grid settings if they haven't /// made their own yet. /// public UIUserGridLastView this[string GridKey] { get { foreach (UIUserGridLastView child in List) { if (child.GridKey == GridKey) return child; } UIUserGridLastViews mlvs = UIUserGridLastViews.GetItems(User.AdministratorID); if (mlvs.Contains(GridKey)) { return this.Add(mlvs[GridKey]); } //Nope, no manager or local user one to return so make a new one and return it instead return this.Add(GridKey); } } /// /// Remove UIUserGridLastView by passing it in /// /// public void Remove(UIUserGridLastView obj) { List.Remove(obj); } /// /// Remove UIUserGridLastView by string of GridKey name /// /// public void Remove(string GridKey) { foreach (UIUserGridLastView child in List) { if (child.GridKey == GridKey) List.Remove(child); } } /// /// Add a new UIUserGridLastView to the collection /// /// public UIUserGridLastView Add(string GridKey) { UIUserGridLastView child = UIUserGridLastView.NewItem(GridKey); List.Add(child); return child; } /// /// Add a new UIUserGridLastView to the collection /// by copying from someone elses /// /// public UIUserGridLastView Add(UIUserGridLastView obj) { UIUserGridLastView child = UIUserGridLastView.NewItem(obj.GridKey); child.FilterID = obj.FilterID; child.ViewXML = obj.ViewXML; child.UserID = User.CurrentThreadUserID; List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(UIUserGridLastView obj) { foreach (UIUserGridLastView child in List) { if (child.Equals(obj)) return true; } return false; } /// /// Check if item in collection by GridKey name /// /// public bool Contains(string GridKey) { foreach (UIUserGridLastView child in List) { if (child.GridKey == GridKey) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(UIUserGridLastView obj) { foreach (UIUserGridLastView child in deletedList) { if (child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// NewItems /// /// public static UIUserGridLastViews NewItems() { return new UIUserGridLastViews(); } /// /// Get item collection (Root collection style) /// /// /// public static UIUserGridLastViews GetItems(Guid UserID) { UIUserGridLastViews col = new UIUserGridLastViews(); return (UIUserGridLastViews)DataPortal.Fetch(new Criteria(UserID)); } #endregion #region DAL DATA ACCESS /// /// Fetch children root style /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { dr = DBUtil.GetReaderFromSQLString("SELECT * FROM aUIUserGridLastView WHERE aUserID=@ID", crit.UserID); while (dr.Read()) { List.Add(UIUserGridLastView.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 (UIUserGridLastView child in deletedList) { child.Update(tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (UIUserGridLastView 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 UserID; public Criteria(Guid _UserID) { UserID = _UserID; } } #endregion }//end UIUserGridLastViews #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL