320 lines
7.2 KiB
C#
320 lines
7.2 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UnitModelPickList.cs
|
|
// Implementation of Class UnitModelPickList
|
|
// CSLA type: Read only collection
|
|
// Created on: 18-Jan-2005
|
|
// Object design: John
|
|
// Coded: 18-Jan-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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="UnitModelPickList.UnitModelPickListInfo"/> objects representing <see cref="UnitModel"/> objects.
|
|
/// Used for selection in UI and internally by other business objects.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UnitModelPickList : ReadOnlyCollectionBase
|
|
{
|
|
|
|
#pragma warning disable 1591
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct UnitModelPickListInfo
|
|
{
|
|
internal bool mActive;
|
|
internal string mName;
|
|
internal Guid mID;
|
|
|
|
|
|
public bool Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(UnitModelPickListInfo obj)
|
|
{
|
|
return this.ID.Equals(obj.ID);
|
|
}
|
|
|
|
}//end UnitModelPickListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected UnitModelPickList()
|
|
{
|
|
// 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 UnitModelPickListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (UnitModelPickListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
if(ItemID==Guid.Empty) return "";
|
|
|
|
foreach (UnitModelPickListInfo child in List)
|
|
{
|
|
if(child.mID==ItemID) return child.Name;
|
|
}
|
|
return "UnitModelPickList[ItemID], couldn't find: "+ItemID.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="strItemID">Guid as string</param>
|
|
public UnitModelPickListInfo this[string strItemID]
|
|
{
|
|
|
|
|
|
get
|
|
{
|
|
|
|
if(strItemID=="") return new UnitModelPickListInfo();
|
|
Guid id=new Guid(strItemID);
|
|
if(id==Guid.Empty) return new UnitModelPickListInfo();
|
|
foreach (UnitModelPickListInfo child in List)
|
|
{
|
|
if(child.mID==id) return child;
|
|
}
|
|
UnitModelPickListInfo u=new UnitModelPickListInfo();
|
|
u.mName="UnitModel NOT FOUND";
|
|
return u;
|
|
}
|
|
}
|
|
|
|
|
|
/// <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 (UnitModelPickListInfo 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(UnitModelPickListInfo obj)
|
|
{
|
|
foreach (UnitModelPickListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// Get all UnitModels
|
|
/// </summary>
|
|
/// <returns>list of <see cref="UnitModelPickList.UnitModelPickListInfo"/> objects</returns>
|
|
public static UnitModelPickList GetList()
|
|
{
|
|
return (UnitModelPickList) DataPortal.Fetch(new Criteria(Guid.Empty));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get one specific UnitModel only but with all the pick list info
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static UnitModelPickList GetListOfOneSpecificUnitModel(Guid UnitModelID)
|
|
{
|
|
return (UnitModelPickList) DataPortal.Fetch(new Criteria(UnitModelID));
|
|
}
|
|
|
|
|
|
|
|
/// <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.UnitModelID==Guid.Empty)
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aUnitModel.aID, aUnitModel.AACTIVE, aUnitModel.aName, " +
|
|
"aUnitModel.aModelNumber " +
|
|
"FROM aUnitModel"
|
|
//************************************************************
|
|
);
|
|
}
|
|
else
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aUnitModel.aID, aUnitModel.AACTIVE, aUnitModel.aName, " +
|
|
"aUnitModel.aModelNumber " +
|
|
"FROM aUnitModel " +
|
|
"WHERE aUnitModel.aID=@ID"
|
|
,crit.UnitModelID
|
|
//************************************************************
|
|
);
|
|
|
|
}
|
|
|
|
while(dr.Read())
|
|
{
|
|
|
|
//*******************************************
|
|
|
|
UnitModelPickListInfo info=new UnitModelPickListInfo();
|
|
info.mActive=dr.GetBoolean("AACTIVE");
|
|
info.mID=dr.GetGuid("aID");
|
|
//Model name is optional, number is required
|
|
//format with optional name first and number second
|
|
info.mName = (AyaBizUtils.SS("", dr.GetString("aName"), " ") + dr.GetString("aModelNumber")).Trim();//case 1934 added trim
|
|
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 UnitModelID;
|
|
|
|
public Criteria( Guid _UnitModelID)
|
|
{
|
|
UnitModelID=_UnitModelID;
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
#pragma warning restore 1591
|
|
}//end UnitModelPickList
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |