/////////////////////////////////////////////////////////// // ClientPickList.cs // Implementation of Class ClientPickList // CSLA type: Read only collection // Created on: 16-Feb-2006 // Object design: John // Coded: 16-Feb-2006 /////////////////////////////////////////////////////////// using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; using System.Collections.Generic; namespace GZTW.AyaNova.BLL { #pragma warning disable 1591 /// /// Lightweight list of objects used for quickly fetching a list of clients. /// Used for user selection and internal API useage by other business objects. /// /// NOTE: this is used mostly internally so the default GetList() method is not regionalized /// /// [Serializable] public class ClientPickList : ReadOnlyCollectionBase { #region Data structure /// /// /// [Serializable] public struct ClientPickListInfo { internal Guid mID; internal string mName; internal bool mActive; //internal string mNotes; internal Guid mRegionID;//case 981 //Public properties /// /// ID of /// public Guid ID {get{return mID;}} /// /// Name of /// public string Name {get{return mName;}} /// /// Active status of /// public bool Active {get{return mActive;}} //public string Notes {get{return mNotes;}} /// /// ID of /// public Guid RegionID { get { return mRegionID; } } /// /// /// /// public bool Equals(ClientPickListInfo obj) { return this.mID.Equals(obj.mID); } }//end ClientPickListInfo #endregion #region Constructor /// /// /// protected ClientPickList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public ClientPickListInfo this[int Item] { get { return (ClientPickListInfo) List[Item]; } } /// /// Returns ClientPickListInfo item that matches passed in itemid value /// /// public ClientPickListInfo this[Guid ItemID] { get { foreach (ClientPickListInfo child in List) { if(child.mID==ItemID) return child; } throw new ArgumentException("ClientPickList: 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 (ClientPickListInfo 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(ClientPickListInfo obj) { foreach (ClientPickListInfo child in List) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in collection /// ///Id of client object public bool Contains(Guid ClientID) { foreach (ClientPickListInfo child in List) { if(child.ID.Equals(ClientID)) return true; } return false; } #endregion #region Static methods /// /// Get all clients /// /// list of objects public static ClientPickList GetList() { return (ClientPickList) DataPortal.Fetch(new Criteria(Guid.Empty,null,false)); } /// /// Get all clients in users current region /// /// /// list of objects public static ClientPickList GetList(bool Regionalized) { return (ClientPickList)DataPortal.Fetch(new Criteria(Guid.Empty, null,Regionalized)); } //Added: 10-Nov-2006 list for head office only for wbi client service request support /// /// Get a list of all active clients that share the indicated head office /// /// /// list of objects public static ClientPickList GetListForHeadOffice(Guid headOfficeID) { return (ClientPickList)DataPortal.Fetch(new Criteria(headOfficeID,null,false)); } /// /// Get a list of all active clients regionalized /// that are in the id list provided /// /// Guid's in a generic list /// Check and enforce region rules /// list of objects public static ClientPickList GetList(List IDList, bool Regionalized) { return (ClientPickList)DataPortal.Fetch(new Criteria(Guid.Empty, IDList, Regionalized)); } /// /// 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.HeadOfficeID != Guid.Empty) { dr = DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT aID, AACTIVE, aName, aRegionID FROM aClient WHERE aHeadOfficeID=@ID " + "ORDER BY aName",crit.HeadOfficeID //************************************************************ ); } else { if (crit.IDList == null) {//case 1019 changes string q="SELECT aID, AACTIVE, aName, aRegionID FROM aClient ORDER BY ANAME "; if(crit.Regionalized) q=DBUtil.AddRegionFilter(q); dr = DBUtil.GetReaderFromSQLString(q); } else { if (crit.IDList.Count > 0) { System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); sbIN.Append(" (aClient.aID in ("); foreach (Guid gItem in crit.IDList) { sbIN.Append("'"); sbIN.Append("{"); sbIN.Append(gItem.ToString().ToUpperInvariant()); sbIN.Append("}"); sbIN.Append("',"); } sbIN.Length = sbIN.Length - 1; sbIN.Append(")) "); dr = DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT aID, AACTIVE, aName, aRegionID FROM aClient WHERE " + sbIN.ToString() + (string)(crit.Regionalized ? DBUtil.RegionAClientClause : "") + " ORDER BY ACLIENT.ANAME " //************************************************************ ); } else return; } } //case 1298 int AID = dr.GetOrdinal("AID"); int AACTIVE = dr.GetOrdinal("AACTIVE"); int ANAME = dr.GetOrdinal("ANAME"); int AREGIONID = dr.GetOrdinal("AREGIONID"); //int XXX = dr.GetOrdinal("XXX"); while(dr.Read()) { //******************************************* ClientPickListInfo info=new ClientPickListInfo(); info.mID=dr.GetGuid(AID); info.mActive=dr.GetBoolean(AACTIVE); info.mName=dr.GetString(ANAME); info.mRegionID = dr.GetGuid(AREGIONID); InnerList.Add(info); //******************************************* } } finally { if(dr!=null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Guid HeadOfficeID; public List IDList; public bool Regionalized; public Criteria(Guid _HeadOfficeID, List _IDList, bool _Regionalized) { HeadOfficeID = _HeadOfficeID; IDList=_IDList; Regionalized = _Regionalized; } } #endregion }//end ClientPickList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL