291 lines
8.6 KiB
C#
291 lines
8.6 KiB
C#
///////////////////////////////////////////////////////////
|
|
// VendorPickList.cs
|
|
// Implementation of Class VendorPickList
|
|
// CSLA type: Read only collection
|
|
// Created on: 29-Dec-2004
|
|
// Object design: John
|
|
// Coded: 29-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="VendorPickList.VendorPickListInfo"/> objects representing <see cref="Vendor"/> objects.
|
|
/// Used in UI selection lists and by other business objects internally
|
|
/// </summary>
|
|
[Serializable]
|
|
public class VendorPickList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct VendorPickListInfo
|
|
{
|
|
|
|
internal Guid mID;
|
|
internal string mName;
|
|
internal bool mActive;
|
|
internal VendorTypes mVendorType;
|
|
|
|
|
|
|
|
//Public properties
|
|
/// <summary>
|
|
/// <see cref="Vendor"/> ID
|
|
/// </summary>
|
|
public Guid ID { get { return mID; } }
|
|
/// <summary>
|
|
/// <see cref="Vendor"/> name
|
|
/// </summary>
|
|
public string Name { get { return mName; } }
|
|
/// <summary>
|
|
/// <see cref="Vendor"/> Active status
|
|
/// </summary>
|
|
public bool Active { get { return mActive; } }
|
|
/// <summary>
|
|
/// <see cref="Vendor"/> <see cref="VendorTypes"/>
|
|
/// </summary>
|
|
public VendorTypes VendorType { get { return mVendorType; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(VendorPickListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end VendorPickListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected VendorPickList()
|
|
{
|
|
// 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 VendorPickListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (VendorPickListInfo)List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns VendorPickListInfo item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public VendorPickListInfo this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (VendorPickListInfo child in List)
|
|
{
|
|
if (child.mID == ItemID) return child;
|
|
}
|
|
throw new ArgumentException("VendorPickList: 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 (VendorPickListInfo 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(VendorPickListInfo obj)
|
|
{
|
|
foreach (VendorPickListInfo child in List)
|
|
{
|
|
if (child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="ID">Vendor ID</param>
|
|
public bool Contains(Guid ID)
|
|
{
|
|
foreach (VendorPickListInfo child in List)
|
|
{
|
|
if (child.ID.Equals(ID)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get all scheduleable users
|
|
/// </summary>
|
|
/// <returns>list of <see cref="VendorPickList.VendorPickListInfo"/> objects</returns>
|
|
public static VendorPickList GetList()
|
|
{
|
|
return (VendorPickList)DataPortal.Fetch(new Criteria(VendorTypes.All));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get a list of vendors of one specific type only
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <returns>list of <see cref="VendorPickList.VendorPickListInfo"/> objects</returns>
|
|
public static VendorPickList GetList(VendorTypes type)
|
|
{
|
|
return (VendorPickList)DataPortal.Fetch(new Criteria(type));
|
|
}
|
|
|
|
|
|
/// <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.Type != VendorTypes.All)
|
|
{
|
|
DBCommandWrapper dbCommandWrapper = null;
|
|
dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
//************************************************************
|
|
"SELECT aID, AACTIVE, aName, aVendorType FROM aVendor " +
|
|
"WHERE aVendorType=@VendorType");
|
|
//************************************************************
|
|
dbCommandWrapper.AddInParameter("@VendorType", DbType.Int16, (int)crit.Type);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
dr = DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aID, AACTIVE, aName, aVendorType FROM aVendor"
|
|
//************************************************************
|
|
);
|
|
}
|
|
|
|
while (dr.Read())
|
|
{
|
|
//*******************************************
|
|
VendorPickListInfo info = new VendorPickListInfo();
|
|
info.mID = dr.GetGuid("aID");
|
|
info.mActive = dr.GetBoolean("AACTIVE");
|
|
info.mName = dr.GetString("aName");
|
|
info.mVendorType = (VendorTypes)dr.GetInt16("aVendorType");
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public VendorTypes Type;
|
|
|
|
//public Guid VendorID;
|
|
|
|
public Criteria(VendorTypes _Type)
|
|
{
|
|
Type = _Type;
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end VendorPickList
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |