575 lines
17 KiB
C#
575 lines
17 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UserList.cs
|
|
// Implementation of Class UserList
|
|
// CSLA type: Read only collection
|
|
// Created on: 23-Nov-2004
|
|
// Object design: John
|
|
// Coded: 23-Nov-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
using System.Collections.Generic;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Read only list of <see cref="UserList.UserListInfo"/> objects representing <see cref="User"/> objects.
|
|
/// Used in UI for grids and reporting.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UserList : ReadOnlyCollectionBase
|
|
{
|
|
#pragma warning disable 1591
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct UserListInfo
|
|
{
|
|
internal bool mActive;
|
|
internal GridNameValueCellItem mFirstName;
|
|
internal GridNameValueCellItem mLastName;
|
|
internal GridNameValueCellItem mInitials;
|
|
internal GridNameValueCellItem mEmployeeNumber;
|
|
internal GridNameValueCellItem mVendorID;
|
|
internal GridNameValueCellItem mMemberOfGroup;
|
|
internal GridNameValueCellItem mDispatchZoneID;
|
|
internal GridNameValueCellItem mRegionID;
|
|
//Case 155
|
|
internal GridNameValueCellItem mClientID;
|
|
|
|
internal UserTypes mUserType;
|
|
internal string mEmailAddress;
|
|
internal string mPhone1;
|
|
internal string mPhone2;
|
|
internal string mPageAddress;
|
|
internal bool mSubContractor;
|
|
|
|
[Display(DisplayType.TrueFalse)]
|
|
public bool LT_User_Label_Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
}
|
|
|
|
|
|
[Display(DisplayType.TrueFalse, ShowInLite = false)]
|
|
public bool LT_User_Label_SubContractor
|
|
{
|
|
get
|
|
{
|
|
return mSubContractor;
|
|
}
|
|
}
|
|
|
|
|
|
[SqlColumnNameAttribute("aUser.aFirstName", "aUser.aID"),
|
|
Display(DisplayType.Button,RootObjectType=RootObjectTypes.User)]
|
|
public GridNameValueCellItem LT_User_Label_FirstName
|
|
{
|
|
get
|
|
{
|
|
return mFirstName;
|
|
}
|
|
}
|
|
|
|
|
|
[SqlColumnNameAttribute("aUser.aLastName", "aUser.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.User)]
|
|
public GridNameValueCellItem LT_User_Label_LastName
|
|
{
|
|
get
|
|
{
|
|
return mLastName;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aUser.aInitials", "aUser.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.User)]
|
|
public GridNameValueCellItem LT_User_Label_Initials
|
|
{
|
|
get
|
|
{
|
|
return mInitials;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aUser.aEmployeeNumber", "aUser.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.User)]
|
|
public GridNameValueCellItem LT_User_Label_EmployeeNumber
|
|
{
|
|
get
|
|
{
|
|
return mEmployeeNumber;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.ListUserTypes, ShowInLite = false)]
|
|
public UserTypes LT_User_Label_UserType
|
|
{
|
|
get
|
|
{
|
|
return mUserType;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aDispatchZone.aName", "aUser.aDispatchZoneID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.DispatchZone, ShowInLite = false)]
|
|
public GridNameValueCellItem LT_O_DispatchZone
|
|
{
|
|
get
|
|
{
|
|
return mDispatchZoneID;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aVendor.aName", "aUser.aVendorID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor, ShowInLite = false)]
|
|
public GridNameValueCellItem LT_O_Vendor
|
|
{
|
|
get
|
|
{
|
|
return mVendorID;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aRegion.aName", "aUser.aRegionID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Region, ShowInLite = false)]
|
|
public GridNameValueCellItem LT_O_Region
|
|
{
|
|
get
|
|
{
|
|
return mRegionID;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aSecurityGroup.aName", "aUser.aMemberOfGroup"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.SecurityGroup, ShowInLite = false)]
|
|
public GridNameValueCellItem LT_User_Label_MemberOfGroup
|
|
{
|
|
get
|
|
{
|
|
return mMemberOfGroup;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.URL_Email)]
|
|
public string LT_User_Label_EmailAddress
|
|
{
|
|
get
|
|
{
|
|
return mEmailAddress;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_User_Label_Phone1
|
|
{
|
|
get
|
|
{
|
|
return mPhone1;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_User_Label_Phone2
|
|
{
|
|
get
|
|
{
|
|
return mPhone2;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_User_Label_PageAddress
|
|
{
|
|
get
|
|
{
|
|
return mPageAddress;
|
|
}
|
|
}
|
|
|
|
|
|
//Case 155
|
|
[SqlColumnNameAttribute("aClient.aName", "aUser.aClientID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Client, ShowInLite = false)]
|
|
public GridNameValueCellItem LT_O_Client
|
|
{
|
|
get
|
|
{
|
|
return mClientID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(UserListInfo obj)
|
|
{
|
|
return this.mInitials.Value.Equals(obj.mInitials.Value);
|
|
}
|
|
|
|
}//end UserListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected UserList()
|
|
{
|
|
// 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 UserListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (UserListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (UserListInfo child in List)
|
|
{
|
|
if(child.mInitials.Value==ItemID) return child.ToString();
|
|
}
|
|
return "Missing: "+ItemID.ToString();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(UserListInfo obj)
|
|
{
|
|
foreach (UserListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Reporting and shared UI editor helpers
|
|
|
|
/// <summary>
|
|
/// Returns the report key which is a property of
|
|
/// reports used to link all reports that can be used
|
|
/// with a particular data source.
|
|
/// </summary>
|
|
public static string ReportKey
|
|
{
|
|
get
|
|
{
|
|
return "UserList";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the Detailed report key
|
|
/// which is used to determine which reports and objects
|
|
/// will be used for detailed reports
|
|
///
|
|
/// If empty string then indicates there is no detailed report object or reports
|
|
/// </summary>
|
|
public static string DetailedReportKey
|
|
{
|
|
get
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Base object that this list is reporting on
|
|
/// used by shared UI editor to instantiate new objects
|
|
/// when user selects new in UI elements that display this list
|
|
///
|
|
/// (I.E. when user clicks on new in a read only list grid, this is the object type created)
|
|
/// </summary>
|
|
public static RootObjectTypes BaseObjectType
|
|
{
|
|
get
|
|
{
|
|
return RootObjectTypes.User;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Locale key so that generic list editor
|
|
/// UI code knows what title to give the list in a
|
|
/// grid
|
|
/// </summary>
|
|
public string LocaleKey
|
|
{
|
|
get
|
|
{
|
|
return "User.Label.List";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The Type of the struct used to store list records
|
|
/// Used to fetch the custom display attributes of the fields
|
|
/// contained within the record to modify the grid display accordingly
|
|
/// <see cref="DisplayAttribute"/>
|
|
/// </summary>
|
|
public static Type ListRecordType
|
|
{
|
|
get
|
|
{
|
|
return typeof(UserListInfo);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Field that contains the ID of the objects
|
|
/// that are the basis of this list.
|
|
///
|
|
/// Used for compiling an ID list for reporting from user
|
|
/// selections in a grid.
|
|
/// </summary>
|
|
public static string IDField
|
|
{
|
|
get
|
|
{
|
|
return "LT_User_Label_Initials";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Same as IDField but for detailed reports
|
|
/// </summary>
|
|
public static string IDFieldDetailed
|
|
{
|
|
get
|
|
{
|
|
return IDField;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
/// <summary>
|
|
/// Internal method used by list factory
|
|
/// </summary>
|
|
internal static UserList Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (UserList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all User (filtered by crit)
|
|
/// </summary>
|
|
/// <param name="xmlCriteria">Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code</param>
|
|
/// <returns>list of <see cref="UserList.UserListInfo"/> objects </returns>
|
|
public static UserList GetList(string xmlCriteria)
|
|
{
|
|
return (UserList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Takes a single ID and returns a "list" of one object
|
|
/// </summary>
|
|
/// <param name="UserID">ID of User object</param>
|
|
/// <returns>list of <see cref="UserList.UserListInfo"/> objects </returns>
|
|
public static UserList GetListForSingleItem(Guid UserID)
|
|
{
|
|
//Case 556
|
|
List<Guid> l = new List<Guid>();
|
|
l.Add(UserID);
|
|
return GetListFromIDList(l);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get list by items indicated in IDList
|
|
/// </summary>
|
|
/// <param name="IDList">Generic list of Guid's</param>
|
|
/// <returns>list of <see cref="UserList.UserListInfo"/> objects </returns>
|
|
public static UserList GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new UserList();
|
|
return (UserList)DataPortal.Fetch(new Criteria("", IDList, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for clearing a grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static UserList GetEmptyList()
|
|
{
|
|
return new UserList();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
|
|
//************************************************************
|
|
string q = "SELECT ~MAXRECS~ aUser.aID, aUser.aDispatchZoneID AS aZONEID, " +
|
|
"aDispatchZone.aName AS aZONENAME, aUser.aVendorID " +
|
|
"AS aVENDORID, aVendor.aName AS aVENDORNAME, " +
|
|
"aUser.aRegionID AS aREGIONID, aRegion.aName AS aREGIONNAME, " +
|
|
//CASE 155
|
|
"AUSER.ACLIENTID AS AUSERCLIENTID, ACLIENT.ANAME AS ACLIENTNAME, " +
|
|
|
|
"aUser.aMemberOfGroup AS aSECURITYGROUPID, " +
|
|
"aSecurityGroup.aName AS aSECURITYGROUPNAME, " +
|
|
"aUser.aFirstName, aUser.aLastName, aUser.aInitials, " +
|
|
"aUser.aEmployeeNumber, aUser.aUserType, " +
|
|
"aUser.aEmailAddress, aUser.aPhone1, " +
|
|
"aUser.aPhone2, aUser.aPageAddress, aUser.aSubContractor, " +
|
|
"aUser.AACTIVE FROM aUser " +
|
|
"LEFT OUTER JOIN aRegion ON aUser.aRegionID " +
|
|
"= aRegion.aID LEFT OUTER JOIN aVendor ON aUser.aVendorID " +
|
|
"= aVendor.aID LEFT OUTER JOIN aDispatchZone " +
|
|
"ON aUser.aDispatchZoneID = aDispatchZone.aID " +
|
|
"LEFT OUTER JOIN aSecurityGroup " +
|
|
"ON aUser.aMemberOfGroup = aSecurityGroup.aID " +
|
|
//Case 155
|
|
"LEFT OUTER JOIN ACLIENT ON AUSER.ACLIENTID = ACLIENT.AID ";
|
|
|
|
if (crit.IDList != null)
|
|
{
|
|
//Case 556
|
|
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
|
|
sbIN.Append(" WHERE (aUser.aID in (");
|
|
foreach (Guid gItem in crit.IDList)
|
|
{
|
|
sbIN.Append("'");
|
|
sbIN.Append("{");
|
|
sbIN.Append(gItem.ToString().ToUpperInvariant());
|
|
sbIN.Append("}");
|
|
sbIN.Append("',");
|
|
}
|
|
sbIN.Length = sbIN.Length - 1;
|
|
sbIN.Append(")) ");
|
|
sbIN.Append(AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML));
|
|
q = q.Replace("~MAXRECS~", "") + sbIN.ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
q = q + AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, true) + " " +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
|
|
//************************************************************
|
|
if (crit.MaxRecords > 0)
|
|
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
}
|
|
|
|
dr=DBUtil.GetReaderFromSQLString(q);
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
if((UserTypes)dr.GetInt16("aUserType")==UserTypes.Utility) continue;
|
|
UserListInfo info=new UserListInfo();
|
|
|
|
info.mActive=dr.GetBoolean("AACTIVE");
|
|
Guid tempID=dr.GetGuid("aID");
|
|
info.mFirstName=new GridNameValueCellItem(tempID,dr.GetString("aFirstName"),RootObjectTypes.User);
|
|
info.mLastName=new GridNameValueCellItem(tempID,dr.GetString("aLastName"),RootObjectTypes.User);
|
|
info.mInitials=new GridNameValueCellItem(tempID,dr.GetString("aInitials"),RootObjectTypes.User);
|
|
info.mEmployeeNumber=new GridNameValueCellItem(tempID,dr.GetString("aEmployeeNumber"),RootObjectTypes.User);
|
|
info.mVendorID=new GridNameValueCellItem(dr.GetGuid("aVENDORID"),dr.GetString("aVENDORNAME"),RootObjectTypes.Vendor);
|
|
info.mMemberOfGroup=new GridNameValueCellItem(dr.GetGuid("aSECURITYGROUPID"),dr.GetString("aSECURITYGROUPNAME"),RootObjectTypes.SecurityGroup);
|
|
info.mDispatchZoneID=new GridNameValueCellItem(dr.GetGuid("aZONEID"),dr.GetString("aZONENAME"),RootObjectTypes.DispatchZone);
|
|
info.mRegionID=new GridNameValueCellItem(dr.GetGuid("aREGIONID"),dr.GetString("aREGIONNAME"),RootObjectTypes.Region);
|
|
info.mUserType=(UserTypes)dr.GetInt16("aUserType");
|
|
info.mEmailAddress=dr.GetString("aEmailAddress");
|
|
info.mPhone1=dr.GetString("aPhone1");
|
|
info.mPhone2=dr.GetString("aPhone2");
|
|
info.mPageAddress=dr.GetString("aPageAddress");
|
|
info.mSubContractor=dr.GetBoolean("aSubContractor");
|
|
|
|
//Case 155
|
|
info.mClientID = new GridNameValueCellItem(dr.GetGuid("AUSERCLIENTID"), dr.GetString("ACLIENTNAME"), RootObjectTypes.Client);
|
|
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public List<Guid> IDList;
|
|
public string CriteriaXML;
|
|
public int MaxRecords;
|
|
public Criteria(string _CriteriaXML, List<Guid> _IDList, int _MaxRecords)
|
|
{
|
|
CriteriaXML = _CriteriaXML;
|
|
IDList = _IDList;
|
|
MaxRecords = _MaxRecords;
|
|
}
|
|
}
|
|
#endregion
|
|
#pragma warning restore 1591
|
|
}//end UserList
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |