/////////////////////////////////////////////////////////// // PartWarehousePickList.cs // Implementation of Class PartWarehousePickList // CSLA type: Read only collection // Created on: 22-Nov-2005 // Object design: John // Coded: 22-Nov-2005 /////////////////////////////////////////////////////////// using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; using System.Collections.Generic; namespace GZTW.AyaNova.BLL { /// /// Lightweight read only list of objects representing objects for selection in UI and API internal usage by other business objects /// [Serializable] public class PartWarehousePickList : ReadOnlyCollectionBase { #region Data structure #pragma warning disable 1591 /// /// /// [Serializable] public struct PartWarehousePickListInfo { internal Guid mID; internal string mName; internal bool mActive; //internal string mNotes; //Public properties public Guid ID {get{return mID;}} public string Name {get{return mName;}} public bool Active {get{return mActive;}} //public string Notes {get{return mNotes;}} internal Guid mRegionID;//case 58 public Guid RegionID { get { return mRegionID; } } /// /// /// /// public bool Equals(PartWarehousePickListInfo obj) { return this.mID.Equals(obj.mID); } }//end PartWarehousePickListInfo #pragma warning restore 1591 #endregion #region Constructor /// /// /// protected PartWarehousePickList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public PartWarehousePickListInfo this[int Item] { get { return (PartWarehousePickListInfo) List[Item]; } } /// /// Returns PartWarehousePickListInfo item that matches passed in itemid value /// /// public PartWarehousePickListInfo this[Guid ItemID] { get { //case 2082 if (ItemID == Guid.Empty) return new PartWarehousePickListInfo(); foreach (PartWarehousePickListInfo child in List) { if(child.mID==ItemID) return child; } throw new ArgumentException("PartWarehousePickList: ID not found:\r\n"+ItemID.ToString()); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(PartWarehousePickListInfo obj) { foreach (PartWarehousePickListInfo child in List) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get all items /// /// list of objects public static PartWarehousePickList GetList(bool Regional) { return (PartWarehousePickList) DataPortal.Fetch(new Criteria(null,Regional)); } /// /// Get list of active items only /// except if in the passed in id list then include /// /// Generic list of exception Guid's /// list of objects public static PartWarehousePickList GetActiveOnlyListWithExceptions(List IDList) { //Added Case 640 return (PartWarehousePickList)DataPortal.Fetch(new Criteria(IDList,true)); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT aID, AACTIVE, aName, aRegionID FROM aPartWarehouse" //************************************************************ ); //case 1300 bool bCurrentUserIsInDefaultRegion = User.CurrentUserIsInDefaultRegion; Guid myRegion = User.CurrentUserRegionID; while(dr.Read()) { //******************************************* PartWarehousePickListInfo info=new PartWarehousePickListInfo(); info.mID=dr.GetGuid("aID"); info.mActive=dr.GetBoolean("AACTIVE"); info.mName=dr.GetString("aName"); info.mRegionID = dr.GetGuid("aRegionID");//case 58 ////case 58 //if (crit.Regional) //{ // //theory is that warehouses outside current region should just be inactive so they don't show in // //workorders unless preselected but will then be grayed out. // if (!AyaBizUtils.InYourRegion(info.mRegionID)) // info.mActive = false; //} //case 1300 same effect as above but without triggering db calls to get user region if (crit.Regional) if (!bCurrentUserIsInDefaultRegion) if (info.mRegionID != Region.DefaultRegionID && info.mRegionID != myRegion) info.mActive = false; //Changed for case 640 if (crit.IDList == null) InnerList.Add(info); else { if (info.mActive == true) InnerList.Add(info); else { if (crit.IDList.Contains(info.mID)) InnerList.Add(info); } } //******************************************* } } finally { if(dr!=null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public List IDList; public bool Regional; public Criteria( List _IDList,bool _Regional) { IDList = _IDList; Regional = _Regional; } } #endregion }//end PartWarehousePickList }//end namespace GZTW.AyaNova.BLL