317 lines
7.3 KiB
C#
317 lines
7.3 KiB
C#
///////////////////////////////////////////////////////////
|
|
// PurchaseOrderReceiptItems.cs
|
|
// Implementation of Class PurchaseOrderReceiptItems
|
|
// CSLA type: Editable child collection
|
|
// Created on: 17-Nov-2004
|
|
// Object design: Joyce & John
|
|
// Coded: John 17-Nov-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
using System.Collections;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Editable child collection of <see cref="PurchaseOrderReceiptItem"/> objects
|
|
/// </summary>
|
|
[Serializable]
|
|
public class PurchaseOrderReceiptItems : BusinessCollectionBase
|
|
{
|
|
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private PurchaseOrderReceiptItems()
|
|
{
|
|
//Child
|
|
MarkAsChild();
|
|
AllowSort=false;
|
|
AllowFind=true;
|
|
AllowEdit=true;
|
|
AllowNew=true;
|
|
AllowRemove=true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
/// <summary>
|
|
/// Retrieve PurchaseOrderReceiptItem by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public PurchaseOrderReceiptItem this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (PurchaseOrderReceiptItem) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve PurchaseOrderReceiptItem by string containing Guid value
|
|
/// </summary>
|
|
public PurchaseOrderReceiptItem this[string PurchaseOrderReceiptItemID]
|
|
{
|
|
get
|
|
{
|
|
System.Guid sid = new System.Guid(PurchaseOrderReceiptItemID);
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove PurchaseOrderReceiptItem by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(PurchaseOrderReceiptItem obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove PurchaseOrderReceiptItem by string of id value
|
|
/// </summary>
|
|
/// <param name="PurchaseOrderReceiptItemID"></param>
|
|
public void Remove(string PurchaseOrderReceiptItemID)
|
|
{
|
|
System.Guid sid = new System.Guid(PurchaseOrderReceiptItemID);
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove by Guid value of ID
|
|
/// </summary>
|
|
/// <param name="PurchaseOrderReceiptItemID"></param>
|
|
public void Remove(Guid PurchaseOrderReceiptItemID)
|
|
{
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(child.ID==PurchaseOrderReceiptItemID)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new PurchaseOrderReceiptItem to the collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public PurchaseOrderReceiptItem Add(PurchaseOrderReceipt obj)
|
|
{
|
|
PurchaseOrderReceiptItem child=PurchaseOrderReceiptItem.NewItem(obj);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Checks if grandchildren are dirty
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool GrandChildIsDirty()
|
|
{
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(child.SerialNumbers.IsDirty==true)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if grandchildren are valid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool GrandChildIsValid()
|
|
{
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(child.SerialNumbers.IsValid==false)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove empty received items (qty zero)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public void RemoveZeroQuantityItems()
|
|
{
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(child.QuantityReceived<1)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
internal ArrayList UniquePurchaseOrderGuids
|
|
{
|
|
get
|
|
{
|
|
ArrayList al=new ArrayList();
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(!al.Contains(child.PurchaseOrderID))
|
|
al.Add(child.PurchaseOrderID);
|
|
}
|
|
return al;
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(PurchaseOrderReceiptItem obj)
|
|
{
|
|
foreach (PurchaseOrderReceiptItem 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="PurchaseOrderReceiptItemID"></param>
|
|
public bool Contains(string PurchaseOrderReceiptItemID)
|
|
{
|
|
System.Guid sid = new System.Guid(PurchaseOrderReceiptItemID);
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if Purchase order item in collection by ID value
|
|
/// </summary>
|
|
/// <param name="PurchaseOrderItemID"></param>
|
|
public bool ContainsPurchaseOrderItem(Guid PurchaseOrderItemID)
|
|
{
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
if(child.PurchaseOrderItemID==PurchaseOrderItemID) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool ContainsDeleted(PurchaseOrderReceiptItem obj)
|
|
{
|
|
foreach (PurchaseOrderReceiptItem 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="PurchaseOrderReceiptItemID"></param>
|
|
public bool ContainsDeleted(string PurchaseOrderReceiptItemID)
|
|
{
|
|
System.Guid sid = new System.Guid(PurchaseOrderReceiptItemID);
|
|
foreach (PurchaseOrderReceiptItem child in deletedList)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static PurchaseOrderReceiptItems NewItems()
|
|
{
|
|
return new PurchaseOrderReceiptItems();
|
|
}
|
|
|
|
/// <summary>
|
|
/// GetItems
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
/// <returns></returns>
|
|
internal static PurchaseOrderReceiptItems GetItems(SafeDataReader dr)
|
|
{
|
|
PurchaseOrderReceiptItems col = new PurchaseOrderReceiptItems();
|
|
col.Fetch(dr);
|
|
return col;
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
/// <summary>
|
|
/// Fetch children
|
|
/// </summary>
|
|
/// <param name="dr">Populated data reader</param>
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
while(dr.Read())
|
|
{
|
|
List.Add(PurchaseOrderReceiptItem.GetItem(dr));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update children
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="tr"></param>
|
|
internal void Update(PurchaseOrderReceipt obj,IDbTransaction tr)
|
|
{
|
|
//update (thus deleting) any deleted child objects
|
|
foreach (PurchaseOrderReceiptItem child in deletedList)
|
|
{
|
|
child.Update(obj,tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (PurchaseOrderReceiptItem child in List)
|
|
{
|
|
child.Update(obj,tr);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
}//end PurchaseOrderReceiptItems
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |