/////////////////////////////////////////////////////////// // WorkorderStatusPickList.cs // Implementation of Class WorkorderStatusPickList // For Case 11 && Case 40 // CSLA type: Read only collection // Created on: 02-Jan-2007 // Object design: John // Coded: 02-Jan-2007 /////////////////////////////////////////////////////////// using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Lightweight read only list of objects representing objects. /// Used for selection in UI and internally by business objects. /// [Serializable] public class WorkorderStatusPickList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct WorkorderStatusPickListInfo { internal Guid mID; internal string mName; internal int mARGB; internal bool mActive; /// /// /// public Guid ID { get { return mID; } } /// /// Set/get Name of item /// /// public string Name { get { return mName; } } /// /// Color to associate with this status in UI in ARGB format /// public int Color { get { return mARGB; } } /// /// Status is selectable in new records /// public bool Active { get { return mActive; } } /// /// /// /// public bool Equals(WorkorderStatusPickListInfo obj) { return this.mID.Equals(obj.mID); } }//end WorkorderStatusPickListInfo #endregion #region Constructor /// /// /// protected WorkorderStatusPickList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public WorkorderStatusPickListInfo this[int Item] { get { return (WorkorderStatusPickListInfo)List[Item]; } } /// /// Returns item that matches passed in itemid value /// /// public WorkorderStatusPickListInfo this[Guid ItemID] { get { foreach (WorkorderStatusPickListInfo child in List) { if (child.mID == ItemID) return child; } throw new ArgumentException("WorkorderStatusPickList: WorkorderStatusID not found:\r\n" + ItemID.ToString()); } } /// /// Returns item that matches passed in string value /// public WorkorderStatusPickListInfo this[string sName] { get { foreach (WorkorderStatusPickListInfo child in List) { if (child.Name == sName) return child; } throw new ArgumentException("WorkorderStatusPickList: WorkorderStatus name not found:\r\n" + sName); } } /// /// Get a list of all duplicate names in this list /// public System.Collections.Generic.List DuplicateNames { get { System.Collections.Generic.List dupes = new System.Collections.Generic.List(); System.Collections.Generic.List all = new System.Collections.Generic.List(); foreach (WorkorderStatusPickListInfo i in List) { if (all.Contains(i.Name)) { dupes.Add(i.Name); } else { all.Add(i.Name); } } return dupes; } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(WorkorderStatusPickListInfo obj) { foreach (WorkorderStatusPickListInfo child in List) { if (child.Equals(obj)) return true; } return false; } /// /// /// /// /// public bool Contains(Guid id) { foreach (WorkorderStatusPickListInfo child in List) { if (child.ID.Equals(id)) return true; } return false; } #endregion #region Static methods /// /// Get all WorkorderStatus (unfiltered as it's not bound) /// /// list of objects public static WorkorderStatusPickList GetList() { return (WorkorderStatusPickList)DataPortal.Fetch(new Criteria()); } /// /// Check all items for duplicate names /// /// List of duplicate names public static System.Collections.Generic.List DuplicateNameCheck() { return GetList().DuplicateNames; } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { SafeDataReader dr = null; try { dr = DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT aID, aName, AARGB, AACTIVE FROM aWorkorderStatus ORDER BY ANAME" //case 1266 //************************************************************ ); while (dr.Read()) { //******************************************* WorkorderStatusPickListInfo info = new WorkorderStatusPickListInfo(); info.mID = dr.GetGuid("aID"); info.mName = dr.GetString("aName"); info.mARGB = dr.GetInt32("AARGB"); info.mActive = dr.GetBoolean("AACTIVE"); InnerList.Add(info); //******************************************* } } finally { if (dr != null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { //public string CriteriaXML; public Criteria( /*string _CriteriaXML*/) { //CriteriaXML=_CriteriaXML; } } #endregion }//end WorkorderStatusPickList }//end namespace GZTW.AyaNova.BLL