122 lines
4.2 KiB
C#
122 lines
4.2 KiB
C#
///////////////////////////////////////////////////////////
|
|
// CustomerDashBoardClientServiceRequestCountRI.cs
|
|
// Implementation of Class CustomerDashBoardClientServiceRequestCountRI
|
|
// 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 CustomerDashBoardClientServiceRequestCountRI : ReadOnlyBase
|
|
{
|
|
public long _Count = 0;
|
|
|
|
#region Constructor
|
|
|
|
protected CustomerDashBoardClientServiceRequestCountRI()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
public static long Get()
|
|
{
|
|
return ((CustomerDashBoardClientServiceRequestCountRI)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("CustomerDashBoardClientServiceRequestCountRI->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 " +
|
|
" ACLIENTSERVICEREQUEST " +
|
|
" INNER JOIN ACLIENT ON (ACLIENTSERVICEREQUEST.ACLIENTID = ACLIENT.AID) " +
|
|
" WHERE ACLIENTSERVICEREQUEST.ASTATUS=0 AND ACLIENT.AHEADOFFICEID=@ID";
|
|
|
|
}
|
|
else
|
|
{
|
|
q =
|
|
"SELECT COUNT(*) FROM " +
|
|
" ACLIENTSERVICEREQUEST " +
|
|
" INNER JOIN ACLIENT ON (ACLIENTSERVICEREQUEST.ACLIENTID = ACLIENT.AID) " +
|
|
" WHERE ACLIENTSERVICEREQUEST.ASTATUS=0 AND ACLIENTSERVICEREQUEST.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
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public Criteria()
|
|
{
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}//end CustomerDashBoardClientServiceRequestCountRI
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL
|