/////////////////////////////////////////////////////////// // VendorPickList.cs // Implementation of Class VendorPickList // CSLA type: Read only collection // Created on: 29-Dec-2004 // Object design: John // Coded: 29-Dec-2004 /////////////////////////////////////////////////////////// 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 in UI selection lists and by other business objects internally /// [Serializable] public class VendorPickList : ReadOnlyCollectionBase { #region Data structure /// /// /// [Serializable] public struct VendorPickListInfo { internal Guid mID; internal string mName; internal bool mActive; internal VendorTypes mVendorType; //Public properties /// /// ID /// public Guid ID { get { return mID; } } /// /// name /// public string Name { get { return mName; } } /// /// Active status /// public bool Active { get { return mActive; } } /// /// /// public VendorTypes VendorType { get { return mVendorType; } } /// /// /// /// public bool Equals(VendorPickListInfo obj) { return this.mID.Equals(obj.mID); } }//end VendorPickListInfo #endregion #region Constructor /// /// /// protected VendorPickList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public VendorPickListInfo this[int Item] { get { return (VendorPickListInfo)List[Item]; } } /// /// Returns VendorPickListInfo item that matches passed in itemid value /// /// public VendorPickListInfo this[Guid ItemID] { get { foreach (VendorPickListInfo child in List) { if (child.mID == ItemID) return child; } throw new ArgumentException("VendorPickList: ID not found:\r\n" + ItemID.ToString()); } } /// /// 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 (VendorPickListInfo 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(VendorPickListInfo obj) { foreach (VendorPickListInfo child in List) { if (child.Equals(obj)) return true; } return false; } /// /// Check if item in collection /// /// Vendor ID public bool Contains(Guid ID) { foreach (VendorPickListInfo child in List) { if (child.ID.Equals(ID)) return true; } return false; } #endregion #region Static methods /// /// Get all scheduleable users /// /// list of objects public static VendorPickList GetList() { return (VendorPickList)DataPortal.Fetch(new Criteria(VendorTypes.All)); } /// /// Get a list of vendors of one specific type only /// /// /// list of objects public static VendorPickList GetList(VendorTypes type) { return (VendorPickList)DataPortal.Fetch(new Criteria(type)); } /// /// 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) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { if (crit.Type != VendorTypes.All) { DBCommandWrapper dbCommandWrapper = null; dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper( //************************************************************ "SELECT aID, AACTIVE, aName, aVendorType FROM aVendor " + "WHERE aVendorType=@VendorType"); //************************************************************ dbCommandWrapper.AddInParameter("@VendorType", DbType.Int16, (int)crit.Type); dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper)); } else { dr = DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT aID, AACTIVE, aName, aVendorType FROM aVendor" //************************************************************ ); } while (dr.Read()) { //******************************************* VendorPickListInfo info = new VendorPickListInfo(); info.mID = dr.GetGuid("aID"); info.mActive = dr.GetBoolean("AACTIVE"); info.mName = dr.GetString("aName"); info.mVendorType = (VendorTypes)dr.GetInt16("aVendorType"); InnerList.Add(info); //******************************************* } } finally { if (dr != null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public VendorTypes Type; //public Guid VendorID; public Criteria(VendorTypes _Type) { Type = _Type; } } #endregion }//end VendorPickList }//end namespace GZTW.AyaNova.BLL