Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/UserListScheduleable.cs
2018-06-29 19:47:36 +00:00

310 lines
8.4 KiB
C#

///////////////////////////////////////////////////////////
// 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
{
/// <summary>
/// Lightweight read only list of <see cref="UserListScheduleable.UserListScheduleableInfo"/> objects representing *Scheduleable* users only.
/// Used in UI picklists and extensively throughout the API internally by other business objects.
/// </summary>
[Serializable]
public class UserListScheduleable : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
///
/// </summary>
[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
/// <summary>
/// <see cref="User"/> ID
/// </summary>
public Guid ID {get{return mID;}}
/// <summary>
///
/// </summary>
public string LastName {get{return mLastName;}}
/// <summary>
///
/// </summary>
public string FirstName {get{return mFirstName;}}
/// <summary>
/// Firstname plus a space and lastname
/// </summary>
public string FullName {get{return mFirstName + " " + mLastName;}}
/// <summary>
///
/// </summary>
public string Initials {get{return mInitials;}}
/// <summary>
///
/// </summary>
public string EmployeeNumber {get{return mEmployeeNumber;}}
/// <summary>
///
/// </summary>
public bool Active {get{return mActive;}}
/// <summary>
/// <see cref="User"/> <see cref="Region"/> ID
/// </summary>
public Guid RegionID {get{return mRegionID;}}
/// <summary>
/// <see cref="User"/> <see cref="DispatchZone"/> ID
/// </summary>
public Guid DispatchZoneID {get{return mDispatchZoneID;}}
/// <summary>
/// Color used to identify user in schedule calendar in AyaNova user interface
/// </summary>
public int ScheduleBackColor {get{return mScheduleBackColor;}}
//case 1446
internal string mRegionName;
/// <summary>
///
/// </summary>
public string RegionName { get { return mRegionName; } }
/// <summary>
/// Return name in selected format
/// </summary>
/// <param name="Format"></param>
/// <returns></returns>
public string Name(ScheduleableUserNameDisplayFormats Format)
{
return User.NameFormatter(mFirstName,mLastName,mInitials,mEmployeeNumber,mRegionName,Format);
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public bool Equals(UserListScheduleableInfo obj)
{
return this.mID.Equals(obj.mID);
}
}//end UserListScheduleableInfo
#endregion
#region Constructor
/// <summary>
///
/// </summary>
protected UserListScheduleable()
{
// AllowSort=false;
// AllowFind=true;
// AllowEdit=false;
// AllowNew=false;
// AllowRemove=false;
}
#endregion
#region Business properties and methods
/// <summary>
/// Get item by index
/// </summary>
/// <param name="Item"></param>
public UserListScheduleableInfo this[int Item]
{
get
{
return (UserListScheduleableInfo) List[Item];
}
}
/// <summary>
/// Returns UserListScheduleableInfo item that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
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
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(UserListScheduleableInfo obj)
{
foreach (UserListScheduleableInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
/// <summary>
/// Check if item in collection by userID
/// and Active
/// </summary>
/// <param name="UserID"></param>
/// <returns></returns>
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
/// <summary>
/// Get all scheduleable users
/// </summary>
/// <returns>list of <see cref="UserListScheduleable.UserListScheduleableInfo"/> objects</returns>
public static UserListScheduleable GetList()
{
return (UserListScheduleable) DataPortal.Fetch(new Criteria());
}
#endregion
#region DAL DATA ACCESS
///
/// <param name="Criteria"></param>
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
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[Serializable]
private class Criteria
{
//public Guid VendorID;
public Criteria( )
{
//VendorID=_VendorID;
}
}
#endregion
}//end UserListScheduleable
}//end namespace GZTW.AyaNova.BLL