///////////////////////////////////////////////////////////
// UserListScheduleable.cs
// Implementation of Class UserListScheduleable
// CSLA type: Read only collection
// Created on: 20-Dec-2004
// Object design: John
// Coded: 20-Dec-2004
///////////////////////////////////////////////////////////
using System;
using System.Data;
using GZTW.Data;
using CSLA.Data;
using CSLA;
namespace GZTW.AyaNova.BLL
{
///
/// Lightweight read only list of objects representing *Scheduleable* users only.
/// Used in UI picklists and extensively throughout the API internally by other business objects.
///
[Serializable]
public class UserListScheduleable : ReadOnlyCollectionBase
{
#region Data structure
///
///
///
[Serializable]
public struct UserListScheduleableInfo
{
internal Guid mID;
internal string mLastName;
internal string mFirstName;
internal string mInitials;
internal string mEmployeeNumber;
internal bool mActive;
internal Guid mRegionID;
internal Guid mDispatchZoneID;
internal int mScheduleBackColor;
//Public properties
///
/// ID
///
public Guid ID {get{return mID;}}
///
///
///
public string LastName {get{return mLastName;}}
///
///
///
public string FirstName {get{return mFirstName;}}
///
/// Firstname plus a space and lastname
///
public string FullName {get{return mFirstName + " " + mLastName;}}
///
///
///
public string Initials {get{return mInitials;}}
///
///
///
public string EmployeeNumber {get{return mEmployeeNumber;}}
///
///
///
public bool Active {get{return mActive;}}
///
/// ID
///
public Guid RegionID {get{return mRegionID;}}
///
/// ID
///
public Guid DispatchZoneID {get{return mDispatchZoneID;}}
///
/// Color used to identify user in schedule calendar in AyaNova user interface
///
public int ScheduleBackColor {get{return mScheduleBackColor;}}
//case 1446
internal string mRegionName;
///
///
///
public string RegionName { get { return mRegionName; } }
///
/// Return name in selected format
///
///
///
public string Name(ScheduleableUserNameDisplayFormats Format)
{
return User.NameFormatter(mFirstName,mLastName,mInitials,mEmployeeNumber,mRegionName,Format);
}
///
///
///
///
public bool Equals(UserListScheduleableInfo obj)
{
return this.mID.Equals(obj.mID);
}
}//end UserListScheduleableInfo
#endregion
#region Constructor
///
///
///
protected UserListScheduleable()
{
// AllowSort=false;
// AllowFind=true;
// AllowEdit=false;
// AllowNew=false;
// AllowRemove=false;
}
#endregion
#region Business properties and methods
///
/// Get item by index
///
///
public UserListScheduleableInfo this[int Item]
{
get
{
return (UserListScheduleableInfo) List[Item];
}
}
///
/// Returns UserListScheduleableInfo item that matches passed in itemid value
///
///
public UserListScheduleableInfo this[Guid ItemID]
{
get
{
foreach (UserListScheduleableInfo child in List)
{
if(child.mID==ItemID) return child;
}
throw new ArgumentException("UserListScheduleable: ID not found or not a scheduleable user:\r\n"+ItemID.ToString());
}
}
#endregion
#region contains
///
/// Check if item in collection
///
///
public bool Contains(UserListScheduleableInfo obj)
{
foreach (UserListScheduleableInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
///
/// Check if item in collection by userID
/// and Active
///
///
///
public bool ContainsActiveUser(Guid UserID)
{
if(UserID==Guid.Empty) return false;
foreach (UserListScheduleableInfo child in List)
{
if(child.ID.Equals(UserID) && child.Active) return true;
}
return false;
}
#endregion
#region Static methods
///
/// Get all scheduleable users
///
/// list of objects
public static UserListScheduleable GetList()
{
return (UserListScheduleable) DataPortal.Fetch(new Criteria());
}
#endregion
#region DAL DATA ACCESS
///
///
protected override void DataPortal_Fetch(object Criteria)
{
SafeDataReader dr = null;
try
{
dr=DBUtil.GetReaderFromSQLString(
//************************************************************
"SELECT AUSER.aID AS AUSERID, AUSER.AACTIVE AS AUSERACTIVE, aFirstName, aLastName, aInitials, " +
" aEmployeeNumber, aRegionID, aDispatchZoneID, " +
" aScheduleBackColor, AREGION.ANAME AS AREGIONNAME " +
" FROM aUser " +
" LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " +
" WHERE (aUserType = 2) ORDER BY ALASTNAME, AFIRSTNAME " //case 814 //case 1446
//************************************************************
);
//case 1300
bool bCurrentUserIsInDefaultRegion = User.CurrentUserIsInDefaultRegion;
Guid myRegion = User.CurrentUserRegionID;
while(dr.Read())
{
//*******************************************
UserListScheduleableInfo info=new UserListScheduleableInfo();
info.mID = dr.GetGuid("AUSERID");
info.mActive = dr.GetBoolean("AUSERACTIVE");
info.mEmployeeNumber=dr.GetString("aEmployeeNumber");
info.mFirstName=dr.GetString("aFirstName");
info.mLastName=dr.GetString("aLastName");
info.mInitials=dr.GetString("aInitials");
info.mRegionID=dr.GetGuid("aRegionID");
info.mDispatchZoneID=dr.GetGuid("aDispatchZoneID");
info.mScheduleBackColor=dr.GetInt32("aScheduleBackColor");
info.mRegionName = dr.GetString("AREGIONNAME");
//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 (!AyaBizUtils.InYourRegion(info.mRegionID))
// info.mActive = false;
//case 1300 same effect as above but without triggering db calls to get user region
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 VendorID;
public Criteria( )
{
//VendorID=_VendorID;
}
}
#endregion
}//end UserListScheduleable
}//end namespace GZTW.AyaNova.BLL