/////////////////////////////////////////////////////////// // CustomerDashBoardOpenServiceWOCountRI.cs // Implementation of Class CustomerDashBoardOpenServiceWOCountRI // CSLA type: Read only collection // Created on: 9-Feb-2016 // Coded: John 8-Feb-2016 /////////////////////////////////////////////////////////// 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 [Serializable] public class CustomerDashBoardOpenServiceWOCountRI : ReadOnlyBase { public long _Count = 0; #region Constructor protected CustomerDashBoardOpenServiceWOCountRI() { } #endregion #region Static methods public static long Get() { return ((CustomerDashBoardOpenServiceWOCountRI)DataPortal.Fetch(new Criteria()))._Count; } #endregion #region DAL DATA ACCESS protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; UserTypes currentUserType = User.CurrentUserType; if (currentUserType != UserTypes.HeadOffice && currentUserType != UserTypes.Client) throw new System.NotSupportedException("CustomerDashBoardList::Get-> Can only be called by a head office or client user type"); bool isHeadOffice = User.CurrentUserType == UserTypes.HeadOffice; Guid custID=Guid.Empty; if(isHeadOffice) custID=User.GetItem(User.CurrentThreadUserID).HeadOfficeID; else custID = User.GetItem(User.CurrentThreadUserID).ClientID; if (custID == Guid.Empty) throw new System.ArgumentException("CustomerDashBoardOpenServiceWOCountRI->custID is empty, current user does not have a valid client or headoffice ID.\r\nThis method can only be called by a head office or client user type"); SafeDataReader dr = null; try { DBCommandWrapper cm = null; string q = string.Empty; if (isHeadOffice) { q = "SELECT COUNT(*) FROM AWORKORDER " + "INNER JOIN ACLIENT ON (ACLIENT.AID=AWORKORDER.ACLIENTID) " + "WHERE AWORKORDER.AWORKORDERTYPE = 1 AND AWORKORDER.ACLOSED = 0 " + "AND ACLIENT.AHEADOFFICEID = @ID"; } else { q = "SELECT COUNT(*) FROM AWORKORDER " + "WHERE AWORKORDER.AWORKORDERTYPE = 1 AND AWORKORDER.ACLOSED = 0 " + "AND AWORKORDER.ACLIENTID = @ID"; } cm = DBUtil.DB.GetSqlStringCommandWrapper(q); cm.AddInParameter("@ID", DbType.Guid, custID); dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm)); while (dr.Read()) { object o = dr.GetValue(0); _Count = long.Parse(o.ToString()); } } finally { if (dr != null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Criteria() { } } #endregion }//end CustomerDashBoardOpenServiceWOCountRI #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL