359 lines
11 KiB
C#
359 lines
11 KiB
C#
///////////////////////////////////////////////////////////
|
|
// ClientPickList.cs
|
|
// Implementation of Class ClientPickList
|
|
// CSLA type: Read only collection
|
|
// Created on: 16-Feb-2006
|
|
// Object design: John
|
|
// Coded: 16-Feb-2006
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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
|
|
/// <summary>
|
|
/// Lightweight list of <see cref="ClientPickList.ClientPickListInfo"/> objects used for quickly fetching a list of clients.
|
|
/// Used for user selection and internal API useage by other business objects.
|
|
///
|
|
/// NOTE: this is used mostly internally so the default GetList() method is not regionalized
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ClientPickList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct ClientPickListInfo
|
|
{
|
|
|
|
internal Guid mID;
|
|
internal string mName;
|
|
internal bool mActive;
|
|
//internal string mNotes;
|
|
internal Guid mRegionID;//case 981
|
|
|
|
//Public properties
|
|
/// <summary>
|
|
/// ID of <see cref="Client"/>
|
|
/// </summary>
|
|
public Guid ID {get{return mID;}}
|
|
/// <summary>
|
|
/// Name of <see cref="Client"/>
|
|
/// </summary>
|
|
public string Name {get{return mName;}}
|
|
/// <summary>
|
|
/// Active status of <see cref="Client"/>
|
|
/// </summary>
|
|
public bool Active {get{return mActive;}}
|
|
//public string Notes {get{return mNotes;}}
|
|
/// <summary>
|
|
/// <see cref="Region"/> ID of <see cref="Client"/>
|
|
/// </summary>
|
|
public Guid RegionID { get { return mRegionID; } }
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(ClientPickListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end ClientPickListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected ClientPickList()
|
|
{
|
|
// 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 ClientPickListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (ClientPickListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns ClientPickListInfo item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public ClientPickListInfo this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (ClientPickListInfo child in List)
|
|
{
|
|
if(child.mID==ItemID) return child;
|
|
}
|
|
throw new ArgumentException("ClientPickList: ID not found:\r\n"+ItemID.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get a list of all duplicate names in this list
|
|
/// </summary>
|
|
public System.Collections.Generic.List<string> DuplicateNames
|
|
{
|
|
|
|
get
|
|
{
|
|
System.Collections.Generic.List<string> dupes = new System.Collections.Generic.List<string>();
|
|
System.Collections.Generic.List<string> all = new System.Collections.Generic.List<string>();
|
|
foreach (ClientPickListInfo i in List)
|
|
{
|
|
if (all.Contains(i.Name))
|
|
{
|
|
dupes.Add(i.Name);
|
|
}
|
|
else
|
|
{
|
|
all.Add(i.Name);
|
|
}
|
|
}
|
|
return dupes;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(ClientPickListInfo obj)
|
|
{
|
|
foreach (ClientPickListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
///<param name="ClientID">Id of client object</param>
|
|
public bool Contains(Guid ClientID)
|
|
{
|
|
foreach (ClientPickListInfo child in List)
|
|
{
|
|
if(child.ID.Equals(ClientID)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get all clients
|
|
/// </summary>
|
|
/// <returns>list of <see cref="ClientPickList.ClientPickListInfo"/> objects</returns>
|
|
|
|
public static ClientPickList GetList()
|
|
{
|
|
return (ClientPickList) DataPortal.Fetch(new Criteria(Guid.Empty,null,false));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all clients in users current region
|
|
/// </summary>
|
|
/// <param name="Regionalized"></param>
|
|
/// <returns>list of <see cref="ClientPickList.ClientPickListInfo"/> objects</returns>
|
|
public static ClientPickList GetList(bool Regionalized)
|
|
{
|
|
return (ClientPickList)DataPortal.Fetch(new Criteria(Guid.Empty, null,Regionalized));
|
|
}
|
|
|
|
//Added: 10-Nov-2006 list for head office only for wbi client service request support
|
|
|
|
/// <summary>
|
|
/// Get a list of all active clients that share the indicated head office
|
|
/// </summary>
|
|
/// <param name="headOfficeID"></param>
|
|
/// <returns>list of <see cref="ClientPickList.ClientPickListInfo"/> objects</returns>
|
|
public static ClientPickList GetListForHeadOffice(Guid headOfficeID)
|
|
{
|
|
return (ClientPickList)DataPortal.Fetch(new Criteria(headOfficeID,null,false));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a list of all active clients regionalized
|
|
/// that are in the id list provided
|
|
/// </summary>
|
|
/// <param name="IDList">Guid's in a generic list</param>
|
|
/// <param name="Regionalized">Check and enforce region rules</param>
|
|
/// <returns>list of <see cref="ClientPickList.ClientPickListInfo"/> objects</returns>
|
|
public static ClientPickList GetList(List<Guid> IDList, bool Regionalized)
|
|
{
|
|
return (ClientPickList)DataPortal.Fetch(new Criteria(Guid.Empty, IDList, Regionalized));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Check all items for duplicate names
|
|
/// </summary>
|
|
/// <returns>List of duplicate names</returns>
|
|
public static System.Collections.Generic.List<string> DuplicateNameCheck()
|
|
{
|
|
return GetList().DuplicateNames;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
|
|
|
|
if (crit.HeadOfficeID != Guid.Empty)
|
|
{
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aID, AACTIVE, aName, aRegionID FROM aClient WHERE aHeadOfficeID=@ID " +
|
|
"ORDER BY aName",crit.HeadOfficeID
|
|
//************************************************************
|
|
);
|
|
}
|
|
else
|
|
{
|
|
if (crit.IDList == null)
|
|
{//case 1019 changes
|
|
string q="SELECT aID, AACTIVE, aName, aRegionID FROM aClient ORDER BY ANAME ";
|
|
if(crit.Regionalized)
|
|
q=DBUtil.AddRegionFilter(q);
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(q);
|
|
}
|
|
else
|
|
{
|
|
if (crit.IDList.Count > 0)
|
|
{
|
|
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
|
|
sbIN.Append(" (aClient.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(")) ");
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aID, AACTIVE, aName, aRegionID FROM aClient WHERE " +
|
|
sbIN.ToString() + (string)(crit.Regionalized ? DBUtil.RegionAClientClause : "") + " ORDER BY ACLIENT.ANAME "
|
|
//************************************************************
|
|
);
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
//case 1298
|
|
int AID = dr.GetOrdinal("AID");
|
|
int AACTIVE = dr.GetOrdinal("AACTIVE");
|
|
int ANAME = dr.GetOrdinal("ANAME");
|
|
int AREGIONID = dr.GetOrdinal("AREGIONID");
|
|
//int XXX = dr.GetOrdinal("XXX");
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
ClientPickListInfo info=new ClientPickListInfo();
|
|
info.mID=dr.GetGuid(AID);
|
|
info.mActive=dr.GetBoolean(AACTIVE);
|
|
info.mName=dr.GetString(ANAME);
|
|
info.mRegionID = dr.GetGuid(AREGIONID);
|
|
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 HeadOfficeID;
|
|
public List<Guid> IDList;
|
|
public bool Regionalized;
|
|
public Criteria(Guid _HeadOfficeID, List<Guid> _IDList, bool _Regionalized)
|
|
{
|
|
HeadOfficeID = _HeadOfficeID;
|
|
IDList=_IDList;
|
|
Regionalized = _Regionalized;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end ClientPickList
|
|
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |