318 lines
8.5 KiB
C#
318 lines
8.5 KiB
C#
///////////////////////////////////////////////////////////
|
|
// WorkorderStatusPickList.cs
|
|
// Implementation of Class WorkorderStatusPickList
|
|
// For Case 11 && Case 40
|
|
// CSLA type: Read only collection
|
|
// Created on: 02-Jan-2007
|
|
// Object design: John
|
|
// Coded: 02-Jan-2007
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
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="WorkorderStatusPickList.WorkorderStatusPickListInfo"/> objects representing <see cref="WorkorderStatus"/> objects.
|
|
/// Used for selection in UI and internally by business objects.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class WorkorderStatusPickList : ReadOnlyCollectionBase
|
|
{
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct WorkorderStatusPickListInfo
|
|
{
|
|
|
|
|
|
|
|
internal Guid mID;
|
|
internal string mName;
|
|
internal int mARGB;
|
|
internal bool mActive;
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set/get Name of item
|
|
///
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// Color to associate with this status in UI in ARGB format
|
|
/// </summary>
|
|
public int Color
|
|
{
|
|
get
|
|
{
|
|
return mARGB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Status is selectable in new records
|
|
/// </summary>
|
|
public bool Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(WorkorderStatusPickListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end WorkorderStatusPickListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected WorkorderStatusPickList()
|
|
{
|
|
// 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 WorkorderStatusPickListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (WorkorderStatusPickListInfo)List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public WorkorderStatusPickListInfo this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (WorkorderStatusPickListInfo child in List)
|
|
{
|
|
if (child.mID == ItemID)
|
|
return child;
|
|
}
|
|
throw new ArgumentException("WorkorderStatusPickList: WorkorderStatusID not found:\r\n" + ItemID.ToString());
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns item that matches passed in string value
|
|
/// </summary>
|
|
public WorkorderStatusPickListInfo this[string sName]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (WorkorderStatusPickListInfo child in List)
|
|
{
|
|
if (child.Name == sName)
|
|
return child;
|
|
}
|
|
throw new ArgumentException("WorkorderStatusPickList: WorkorderStatus name not found:\r\n" + sName);
|
|
|
|
}
|
|
}
|
|
|
|
/// <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 (WorkorderStatusPickListInfo 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(WorkorderStatusPickListInfo obj)
|
|
{
|
|
foreach (WorkorderStatusPickListInfo child in List)
|
|
{
|
|
if (child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public bool Contains(Guid id)
|
|
{
|
|
foreach (WorkorderStatusPickListInfo child in List)
|
|
{
|
|
if (child.ID.Equals(id)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get all WorkorderStatus (unfiltered as it's not bound)
|
|
/// </summary>
|
|
/// <returns>list of <see cref="WorkorderStatusPickList.WorkorderStatusPickListInfo"/> objects</returns>
|
|
public static WorkorderStatusPickList GetList()
|
|
{
|
|
return (WorkorderStatusPickList)DataPortal.Fetch(new Criteria());
|
|
}
|
|
|
|
/// <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)
|
|
{
|
|
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr = DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aID, aName, AARGB, AACTIVE FROM aWorkorderStatus ORDER BY ANAME" //case 1266
|
|
//************************************************************
|
|
);
|
|
|
|
while (dr.Read())
|
|
{
|
|
//*******************************************
|
|
WorkorderStatusPickListInfo info = new WorkorderStatusPickListInfo();
|
|
info.mID = dr.GetGuid("aID");
|
|
info.mName = dr.GetString("aName");
|
|
info.mARGB = dr.GetInt32("AARGB");
|
|
info.mActive = dr.GetBoolean("AACTIVE");
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
|
|
//public string CriteriaXML;
|
|
|
|
public Criteria( /*string _CriteriaXML*/)
|
|
{
|
|
//CriteriaXML=_CriteriaXML;
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end WorkorderStatusPickList
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |