/////////////////////////////////////////////////////////// // LoanItemPickList.cs // Implementation of Class LoanItemPickList // CSLA type: Read only collection // Created on: 13-Nov-2005 // Object design: John // Coded: 13-Nov-2005 /////////////////////////////////////////////////////////// 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 for selectin in UI /// /// [Serializable] public class LoanItemPickList : ReadOnlyCollectionBase { #region Data structure /// /// /// [Serializable] public struct LoanItemPickListInfo { internal Guid mID; internal string mSerial; internal string mName; internal bool mActive; internal Guid mWorkorderItemLoanID; //Case 420 internal decimal mRateHour; internal decimal mRateHalfDay; internal decimal mRateDay; internal decimal mRateWeek; internal decimal mRateMonth; internal decimal mRateYear; //Public properties /// /// ID of /// public Guid ID { get { return mID; } } /// /// Serial number of loan item /// public string Serial { get { return mSerial; } } /// /// Name of loan item /// public string Name { get { return mName; } } /// /// Selectable in new records /// public bool Active { get { return mActive; } } /// /// If loaned out this is the ID it's currently associated with /// public Guid WorkorderItemLoanID { get { return mWorkorderItemLoanID; } } //Case 420 /// /// Hourly loaner rental rate /// public decimal RateHour { get { return mRateHour; } } /// /// Half day loaner rental rate /// public decimal RateHalfDay { get { return mRateHalfDay; } } /// /// Day loaner rental rate /// public decimal RateDay { get { return mRateDay; } } /// /// Weekly loaner rental rate /// public decimal RateWeek { get { return mRateWeek; } } /// /// Monthly loaner rental rate /// public decimal RateMonth { get { return mRateMonth; } } /// /// Yearly loaner rental rate /// public decimal RateYear { get { return mRateYear; } } //case 58 internal Guid mRegionID; /// /// ID to which this loaner item is restricted /// public Guid RegionID { get { return mRegionID; } } /// /// /// /// public bool Equals(LoanItemPickListInfo obj) { return this.mID.Equals(obj.mID); } }//end LoanItemPickListInfo #endregion #region Constructor /// /// /// protected LoanItemPickList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public LoanItemPickListInfo this[int Item] { get { return (LoanItemPickListInfo) List[Item]; } } /// /// Returns LoanItemPickListInfo item that matches passed in itemid value /// /// public LoanItemPickListInfo this[Guid ItemID] { get { foreach (LoanItemPickListInfo child in List) { if(child.mID==ItemID) return child; } throw new ArgumentException("LoanItemPickList: ID not found:\r\n"+ItemID.ToString()); } } //Case 420 this method /// /// Returns decimal rate for item of ItemID and rate time period "rate" /// returns 0m in all failure cases or if rate=none /// /// /// /// public decimal RateValue(Guid ItemID, LoanItemRates rate) { //short circuit if called without an item id if (ItemID == Guid.Empty) return 0m; foreach (LoanItemPickListInfo child in List) { if (child.mID == ItemID) { switch (rate) { case LoanItemRates.None: return 0m; case LoanItemRates.Hours: return child.RateHour; case LoanItemRates.HalfDays: return child.RateHalfDay; case LoanItemRates.Days: return child.RateDay; case LoanItemRates.Weeks: return child.RateWeek; case LoanItemRates.Months: return child.RateMonth; case LoanItemRates.Years: return child.RateYear; } } } return 0m; } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(LoanItemPickListInfo obj) { foreach (LoanItemPickListInfo child in List) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get a list of all LoanItems /// /// list of objects public static LoanItemPickList GetList(bool Regional) { return (LoanItemPickList)DataPortal.Fetch(new Criteria(Guid.Empty, Regional,Guid.Empty, string.Empty)); } //Added: 3-Oct-2006 for WBI /// /// Get one loan item /// /// Guid of loan item /// list of containing one object public static LoanItemPickList GetOneLoanItem(Guid LoanItemID) { return (LoanItemPickList)DataPortal.Fetch(new Criteria(LoanItemID, false, Guid.Empty, string.Empty)); } //case 1975 RI /// /// Get all loan items selected on workorder /// /// /// list of objects public static LoanItemPickList GetListSelectedOnWorkOrder(Guid WorkorderID) { return (LoanItemPickList)DataPortal.Fetch(new Criteria(Guid.Empty, false, WorkorderID, string.Empty)); } //case 1975 RI /// /// Get all loan items matching search term /// /// public static LoanItemPickList GetList(string searchTerm) { return (LoanItemPickList)DataPortal.Fetch(new Criteria(Guid.Empty, false, Guid.Empty, searchTerm)); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { //on workorder version if (crit.WorkOrderID != Guid.Empty) { dr = DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT ALOANITEM.* " + " FROM " + " AWORKORDERITEMLOAN " + " INNER JOIN AWORKORDERITEM ON (AWORKORDERITEMLOAN.AWORKORDERITEMID = AWORKORDERITEM.AID) " + " INNER JOIN ALOANITEM ON (AWORKORDERITEMLOAN.ALOANITEMID = ALOANITEM.AID) " + " WHERE AWORKORDERITEM.AWORKORDERID = @ID ", crit.WorkOrderID //************************************************************ ); } else { //Single item only version if (crit.LoanItemID != Guid.Empty) { dr = DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT * " + "FROM aLoanItem " + "WHERE aLoanItem.aID=@ID", crit.LoanItemID //************************************************************ ); } else { //all items version //case 1975 string likeTerm = string.Empty; if (!string.IsNullOrEmpty(crit.SearchTerm))//case 1975 { likeTerm = " WHERE (LOWER(ALOANITEM.ANAME) LIKE '%" + crit.SearchTerm + "%')" + " OR (LOWER(ALOANITEM.ASERIAL) LIKE '%" + crit.SearchTerm + "%')"; } dr = DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT * " + "FROM aLoanItem " + likeTerm//case 1975 //************************************************************ ); } } //case 1300 bool bCurrentUserIsInDefaultRegion = User.CurrentUserIsInDefaultRegion; Guid myRegion = User.CurrentUserRegionID; while(dr.Read()) { //******************************************* LoanItemPickListInfo info=new LoanItemPickListInfo(); info.mID=dr.GetGuid("aID"); info.mActive=dr.GetBoolean("AACTIVE"); info.mWorkorderItemLoanID=dr.GetGuid("aCurrentWorkorderItemLoan"); info.mSerial=dr.GetString("aSerial"); info.mName=dr.GetString("aName"); //case 58 info.mRegionID = dr.GetGuid("aRegionID"); //Case 420 info.mRateHour = dr.GetDecimal("aRateHour"); info.mRateHalfDay = dr.GetDecimal("aRateHalfDay"); info.mRateDay = dr.GetDecimal("aRateDay"); info.mRateWeek = dr.GetDecimal("aRateWeek"); info.mRateMonth = dr.GetDecimal("aRateMonth"); info.mRateYear = dr.GetDecimal("aRateYear"); //Case 58 //theory is that users outside current region should just be inactive so they don't show in //workorders unless preselected but will then be grayed out. //if (crit.Regional && !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; InnerList.Add(info); //******************************************* } } finally { if(dr!=null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Guid LoanItemID; public bool Regional; public Guid WorkOrderID; public string SearchTerm;//case 1975 public Criteria(Guid _LoanItemID, bool _Regional, Guid _WorkOrderID, string _searchTerm) { LoanItemID = _LoanItemID; Regional = _Regional; WorkOrderID = _WorkOrderID; SearchTerm = _searchTerm; } } #endregion }//end LoanItemPickList }//end namespace GZTW.AyaNova.BLL