315 lines
7.6 KiB
C#
315 lines
7.6 KiB
C#
///////////////////////////////////////////////////////////
|
|
// PurchaseOrderItems.cs
|
|
// Implementation of Class PurchaseOrderItems
|
|
// CSLA type: Editable child collection
|
|
// Created on: 07-Jun-2004 8:41:31 AM
|
|
// Object design: Joyce
|
|
// Coded: John 27-July-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Editable child collection of <see cref="PurchaseOrderItem"/> objects
|
|
/// </summary>
|
|
[Serializable]
|
|
public class PurchaseOrderItems : BusinessCollectionBase {
|
|
private bool _Locked=false;
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private PurchaseOrderItems()
|
|
{
|
|
//Child
|
|
MarkAsChild();
|
|
AllowSort=false;
|
|
AllowFind=true;
|
|
AllowEdit=true;
|
|
AllowNew=true;
|
|
AllowRemove=true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
/// <summary>
|
|
/// Retrieve PurchaseOrderItem by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public PurchaseOrderItem this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (PurchaseOrderItem) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve PurchaseOrderItem by string containing Guid value
|
|
/// </summary>
|
|
public PurchaseOrderItem this[string PurchaseOrderItemID]
|
|
{
|
|
get
|
|
{
|
|
System.Guid sid = new System.Guid(PurchaseOrderItemID);
|
|
foreach (PurchaseOrderItem child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove PurchaseOrderItem by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(PurchaseOrderItem obj)
|
|
{
|
|
if(_Locked)
|
|
throw new System.ApplicationException
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("PurchaseOrder.Label.Error.Locked")
|
|
);
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove PurchaseOrderItem by string of id value
|
|
/// </summary>
|
|
/// <param name="PurchaseOrderItemID"></param>
|
|
public void Remove(string PurchaseOrderItemID)
|
|
{
|
|
if(_Locked)
|
|
throw new System.ApplicationException
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("PurchaseOrder.Label.Error.Locked")
|
|
);
|
|
System.Guid sid = new System.Guid(PurchaseOrderItemID);
|
|
//case 564 - found this was buggy, can't remove while iterating collection
|
|
//changed accordingly
|
|
PurchaseOrderItem poidelete = null;
|
|
foreach (PurchaseOrderItem child in List)
|
|
{
|
|
if (child.ID == sid)
|
|
{
|
|
poidelete = child;
|
|
break;
|
|
}
|
|
}
|
|
if (poidelete != null)
|
|
List.Remove(poidelete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove by Guid value of ID
|
|
/// </summary>
|
|
/// <param name="PurchaseOrderItemID"></param>
|
|
public void Remove(Guid PurchaseOrderItemID)
|
|
{
|
|
if(_Locked)
|
|
throw new System.ApplicationException
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("PurchaseOrder.Label.Error.Locked")
|
|
);
|
|
//case 564 - found this was buggy, can't remove while iterating collection
|
|
//changed accordingly
|
|
PurchaseOrderItem poidelete = null;
|
|
foreach (PurchaseOrderItem child in List)
|
|
{
|
|
if (child.ID == PurchaseOrderItemID)
|
|
{
|
|
poidelete = child;
|
|
break;
|
|
}
|
|
}
|
|
if (poidelete != null)
|
|
List.Remove(poidelete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new PurchaseOrderItem to the collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public PurchaseOrderItem Add(PurchaseOrder obj)
|
|
{
|
|
if(_Locked)
|
|
throw new System.ApplicationException
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("PurchaseOrder.Label.Error.Locked")
|
|
);
|
|
PurchaseOrderItem child=PurchaseOrderItem.NewItem(obj);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Set all items to read only
|
|
/// </summary>
|
|
public void SetAllItemsReadOnly()
|
|
{
|
|
_Locked=true;
|
|
foreach (PurchaseOrderItem child in List)
|
|
{
|
|
child.bReadOnly=true;
|
|
}
|
|
}
|
|
|
|
//case 564 helper
|
|
internal bool IsLocked
|
|
{
|
|
get
|
|
{
|
|
return _Locked;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Set all items to writeable
|
|
///
|
|
/// </summary>
|
|
///
|
|
internal void SetAllItemsWrite()//required to support case 564, called from po db update
|
|
{
|
|
_Locked = false;
|
|
foreach (PurchaseOrderItem child in List)
|
|
{
|
|
child.bReadOnly = false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(PurchaseOrderItem obj)
|
|
{
|
|
foreach (PurchaseOrderItem 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="PurchaseOrderItemID"></param>
|
|
public bool Contains(string PurchaseOrderItemID)
|
|
{
|
|
System.Guid sid = new System.Guid(PurchaseOrderItemID);
|
|
foreach (PurchaseOrderItem 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(PurchaseOrderItem obj)
|
|
{
|
|
foreach (PurchaseOrderItem 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="PurchaseOrderItemID"></param>
|
|
public bool ContainsDeleted(string PurchaseOrderItemID)
|
|
{
|
|
System.Guid sid = new System.Guid(PurchaseOrderItemID);
|
|
foreach (PurchaseOrderItem child in deletedList)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static PurchaseOrderItems NewItems()
|
|
{
|
|
return new PurchaseOrderItems();
|
|
}
|
|
|
|
/// <summary>
|
|
/// GetItems
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
/// <returns></returns>
|
|
internal static PurchaseOrderItems GetItems(SafeDataReader dr)
|
|
{
|
|
PurchaseOrderItems col = new PurchaseOrderItems();
|
|
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(PurchaseOrderItem.GetItem(dr));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update children
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="tr"></param>
|
|
internal void Update(PurchaseOrder obj,IDbTransaction tr)
|
|
{
|
|
//update (thus deleting) any deleted child objects
|
|
foreach (PurchaseOrderItem child in deletedList)
|
|
{
|
|
child.Update(obj,tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (PurchaseOrderItem child in List)
|
|
{
|
|
child.Update(obj,tr);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
}//end PurchaseOrderItems
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |