335 lines
7.3 KiB
C#
335 lines
7.3 KiB
C#
///////////////////////////////////////////////////////////
|
|
// PartSerials.cs
|
|
// Implementation of Class PartSerials
|
|
// CSLA type: Editable Grandchild collection
|
|
// Created on: 29-Nov-2004
|
|
// Object design: John
|
|
// Coded: John 29-Nov-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using GZTW.Data;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Part serial number collection of <see cref="PartSerial"/> objects used by <see cref="PartInventoryAdjustmentItem"/> and <see cref="PurchaseOrderReceiptItem"/>
|
|
/// </summary>
|
|
[Serializable]
|
|
public class PartSerials : BusinessCollectionBase
|
|
{
|
|
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private PartSerials()
|
|
{
|
|
//Child
|
|
MarkAsChild();
|
|
AllowSort=false;
|
|
AllowFind=true;
|
|
AllowEdit=true;
|
|
AllowNew=true;
|
|
AllowRemove=true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
/// <summary>
|
|
/// Retrieve PartSerial by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public PartSerial this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (PartSerial) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve PartSerial by string containing Guid value
|
|
/// </summary>
|
|
public PartSerial this[string PartSerialID]
|
|
{
|
|
get
|
|
{
|
|
System.Guid sid = new System.Guid(PartSerialID);
|
|
foreach (PartSerial child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve PartSerial by Guid value
|
|
/// </summary>
|
|
public PartSerial this[Guid PartSerialGUID]
|
|
{
|
|
get
|
|
{
|
|
|
|
foreach (PartSerial child in List)
|
|
{
|
|
if(child.ID==PartSerialGUID)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove PartSerial by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(PartSerial obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove PartSerial by string of id value
|
|
/// </summary>
|
|
/// <param name="PartSerialID"></param>
|
|
public void Remove(string PartSerialID)
|
|
{
|
|
System.Guid sid = new System.Guid(PartSerialID);
|
|
foreach (PartSerial child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove by Guid value of ID
|
|
/// </summary>
|
|
/// <param name="PartSerialID"></param>
|
|
public void Remove(Guid PartSerialID)
|
|
{
|
|
foreach (PartSerial child in List)
|
|
{
|
|
if(child.ID==PartSerialID)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new PartSerial to the collection
|
|
/// </summary>
|
|
public PartSerial Add(RootObjectTypes ObjectType)
|
|
{
|
|
PartSerial child=PartSerial.NewItem(ObjectType);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Sets broken rule for serial number item
|
|
/// if it's a duplicate in collection
|
|
/// </summary>
|
|
public void CheckForDuplicateSerialNumbers()
|
|
{
|
|
//clear all duplicate broken rules first
|
|
//to start fresh
|
|
foreach(PartSerial ps in List)
|
|
{
|
|
ps.DuplicateSerialNumber=false;
|
|
}
|
|
|
|
//Loop through all serials
|
|
foreach(PartSerial pMain in List)
|
|
{
|
|
|
|
if(pMain.SerialNumber!="")
|
|
{
|
|
//compare to all other serials
|
|
foreach(PartSerial pOther in List)
|
|
{
|
|
|
|
if(pMain!=pOther)
|
|
{
|
|
if(pMain.SerialNumber==pOther.SerialNumber && pMain.PartID==pOther.PartID )
|
|
{
|
|
pMain.DuplicateSerialNumber=true;
|
|
pOther.DuplicateSerialNumber=true;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(PartSerial obj)
|
|
{
|
|
foreach (PartSerial child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection by string of ID value
|
|
/// </summary>
|
|
/// <param name="PartSerialID"></param>
|
|
public bool Contains(string PartSerialID)
|
|
{
|
|
System.Guid sid = new System.Guid(PartSerialID);
|
|
foreach (PartSerial child in List)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool ContainsDeleted(PartSerial obj)
|
|
{
|
|
foreach (PartSerial child in deletedList)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection by string of ID value
|
|
/// </summary>
|
|
/// <param name="PartSerialID"></param>
|
|
public bool ContainsDeleted(string PartSerialID)
|
|
{
|
|
System.Guid sid = new System.Guid(PartSerialID);
|
|
foreach (PartSerial child in deletedList)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static PartSerials NewItems()
|
|
{
|
|
return new PartSerials();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get items - Grandchild style
|
|
/// (root object can be WorkorderItem, PurchaseOrderItem, Warehouse etc)
|
|
/// </summary>
|
|
/// <param name="RootObject"></param>
|
|
/// <param name="RootObjectID"></param>
|
|
/// <returns></returns>
|
|
internal static PartSerials GetItems(RootObjectTypes RootObject, Guid RootObjectID)
|
|
{
|
|
PartSerials col = new PartSerials();
|
|
col.Fetch(RootObject, RootObjectID);
|
|
return col;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
/// <summary>
|
|
/// Fetch children - grandchild style
|
|
/// </summary>
|
|
/// <param name="RootObject"></param>
|
|
/// <param name="RootObjectID"></param>
|
|
private void Fetch(RootObjectTypes RootObject, Guid RootObjectID)
|
|
{
|
|
//Load data Grandchild style
|
|
|
|
SafeDataReader dr = null;
|
|
|
|
try
|
|
{
|
|
switch(RootObject)
|
|
{
|
|
case RootObjectTypes.PurchaseOrder:
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aPartSerial WHERE aPurchaseOrderReceiptItemID=@ID",RootObjectID);
|
|
break;
|
|
case RootObjectTypes.PartInventoryAdjustment:
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aPartSerial WHERE AADJUSTMENTID=@ID",RootObjectID);
|
|
break;
|
|
default:
|
|
throw new ApplicationException("Invalid RootObjectType in:PartSerials.GetItems() only valid types are:PurchaseOrderReceiptItem or PartInventoryAdjustmentItem");
|
|
|
|
//dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aPartSerial");
|
|
|
|
}
|
|
|
|
while(dr.Read())
|
|
{
|
|
List.Add(PartSerial.GetItem(dr,RootObject));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update children
|
|
/// </summary>
|
|
/// <param name="tr"></param>
|
|
internal void Update(IDbTransaction tr)
|
|
{
|
|
//update (thus deleting) any deleted child objects
|
|
foreach (PartSerial child in deletedList)
|
|
{
|
|
child.Update(tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (PartSerial child in List)
|
|
{
|
|
child.Update(tr);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
}//end PartSerials
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |