Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/PartInventoryAdjustmentItems.cs
2018-06-29 19:47:36 +00:00

377 lines
9.1 KiB
C#

///////////////////////////////////////////////////////////
// PartInventoryAdjustmentItems.cs
// Implementation of Class PartInventoryAdjustmentItems
// CSLA type: Editable child collection
// Created on: 07-Jun-2004 8:41:18 AM
// Object design: Joyce
// Coded: John 29-July-2004
///////////////////////////////////////////////////////////
using System;
using System.Data;
using CSLA.Data;
using CSLA;
namespace GZTW.AyaNova.BLL
{
/// <summary>
/// Collection of <see cref="PartInventoryAdjustmentItem"/> objects used by the <see cref="PartInventoryAdjustment"/> object
/// </summary>
[Serializable]
public class PartInventoryAdjustmentItems : BusinessCollectionBase
{
#region Constructor
//Private constructor prevents direction instantiation
private PartInventoryAdjustmentItems()
{
//Child
MarkAsChild();
AllowSort=false;
AllowFind=true;
AllowEdit=true;
AllowNew=true;
AllowRemove=true;
}
#endregion
#region Business properties and methods
/// <summary>
/// Retrieve PartInventoryAdjustmentItem by index
/// </summary>
/// <param name="Item">Index</param>
public PartInventoryAdjustmentItem this[int Item]
{
get
{
return (PartInventoryAdjustmentItem) List[Item];
}
}
/// <summary>
/// Retrieve PartInventoryAdjustmentItem by string containing Guid value
/// </summary>
public PartInventoryAdjustmentItem this[string PartInventoryAdjustmentItemID]
{
get
{
System.Guid sid = new System.Guid(PartInventoryAdjustmentItemID);
foreach (PartInventoryAdjustmentItem child in List)
{
if(child.ID==sid)
return child;
}
return null;
}
}
/// <summary>
/// Retrieve PartInventoryAdjustmentItem by Guid value
/// </summary>
public PartInventoryAdjustmentItem this[Guid PartInventoryAdjustmentItemGUID]
{
get
{
foreach (PartInventoryAdjustmentItem child in List)
{
if(child.ID==PartInventoryAdjustmentItemGUID)
return child;
}
return null;
}
}
/// <summary>
/// Remove PartInventoryAdjustmentItem by passing it in
/// </summary>
/// <param name="obj"></param>
public void Remove(PartInventoryAdjustmentItem obj)
{
List.Remove(obj);
}
/// <summary>
/// Remove PartInventoryAdjustmentItem by string of id value
/// </summary>
/// <param name="PartInventoryAdjustmentItemID"></param>
public void Remove(string PartInventoryAdjustmentItemID)
{
System.Guid sid = new System.Guid(PartInventoryAdjustmentItemID);
foreach (PartInventoryAdjustmentItem child in List)
{
if(child.ID==sid)
List.Remove(child);
}
}
/// <summary>
/// Remove by Guid value of ID
/// </summary>
/// <param name="PartInventoryAdjustmentItemID"></param>
public void Remove(Guid PartInventoryAdjustmentItemID)
{//case 1301
PartInventoryAdjustmentItem pDelete = null;
foreach (PartInventoryAdjustmentItem child in List)
{
if (child.ID == PartInventoryAdjustmentItemID)
{
pDelete = child;
break;
}
}
if(pDelete!=null)
List.Remove(pDelete);
}
/// <summary>
///
/// </summary>
/// <param name="Adjustment">Parent Adjustment object</param>
/// <returns></returns>
public PartInventoryAdjustmentItem Add(PartInventoryAdjustment Adjustment)
{
PartInventoryAdjustmentItem child=PartInventoryAdjustmentItem.NewItem( Adjustment.ID);
List.Add(child);
child.mDateAdjusted=Adjustment.sdDateAdjusted;
return child;
}
/// <summary>
/// Checks if grandchildren are dirty
/// </summary>
/// <returns></returns>
public bool GrandChildIsDirty()
{
foreach (PartInventoryAdjustmentItem 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 (PartInventoryAdjustmentItem child in List)
{
if(child.SerialNumbers.IsValid==false)
return false;
}
return true;
}
/// <summary>
/// Remove empty items (qty zero)
/// </summary>
/// <returns></returns>
public void RemoveZeroQuantityItems()
{
foreach (PartInventoryAdjustmentItem child in List)
{
if(child.QuantityAdjustment==0)
List.Remove(child);
}
}
/// <summary>
/// Sets broken rule for item
/// if it's a duplicate in collection
/// Only one instance of same part / warehouse allowed
/// in collection to avoid several potential ways of damaging integrity
/// of serial numbers and inventory
/// </summary>
public void CheckForDuplicateParts()
{
//clear all duplicate broken rules first
//to start fresh
foreach(PartInventoryAdjustmentItem ps in List)
{
ps.DuplicatePart=false;
}
//Loop through all
foreach(PartInventoryAdjustmentItem pMain in List)
{
if(pMain.PartWarehouseID!=Guid.Empty && pMain.PartID!=Guid.Empty)
{
//compare to all other serials
foreach(PartInventoryAdjustmentItem pOther in List)
{
if(pMain!=pOther && pOther.PartWarehouseID!=Guid.Empty && pOther.PartID!=Guid.Empty)
{
if(pMain.PartWarehouseID==pOther.PartWarehouseID && pMain.PartID==pOther.PartID )
{
pMain.DuplicatePart=true;
pOther.DuplicatePart=true;
}
}
}
}
}
}
#endregion
#region Contains
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(PartInventoryAdjustmentItem obj)
{
foreach (PartInventoryAdjustmentItem 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="PartInventoryAdjustmentItemID"></param>
public bool Contains(string PartInventoryAdjustmentItemID)
{
System.Guid sid = new System.Guid(PartInventoryAdjustmentItemID);
foreach (PartInventoryAdjustmentItem 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(PartInventoryAdjustmentItem obj)
{
foreach (PartInventoryAdjustmentItem 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="PartInventoryAdjustmentItemID"></param>
public bool ContainsDeleted(string PartInventoryAdjustmentItemID)
{
System.Guid sid = new System.Guid(PartInventoryAdjustmentItemID);
foreach (PartInventoryAdjustmentItem child in deletedList)
{
if(child.ID==sid) return true;
}
return false;
}
#endregion
#region Static methods
/// <summary>
/// NewItems
/// </summary>
/// <returns></returns>
internal static PartInventoryAdjustmentItems NewItems()
{
return new PartInventoryAdjustmentItems();
}
/// <summary>
/// GetItems
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
internal static PartInventoryAdjustmentItems GetItems(SafeDataReader dr)
{
PartInventoryAdjustmentItems col = new PartInventoryAdjustmentItems();
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(PartInventoryAdjustmentItem.GetItem(dr));
}
}
/// <summary>
///
/// </summary>
/// <param name="ParentID"></param>
/// <param name="tr"></param>
internal void Update(Guid ParentID,IDbTransaction tr)
{
//case 1301
System.Collections.Generic.List<Guid> gBad=new System.Collections.Generic.List<Guid>();
foreach (PartInventoryAdjustmentItem child in List)
{
if (child.PartID == Guid.Empty || child.QuantityAdjustment==0)
gBad.Add(child.ID);
}
if (gBad.Count > 0)
{
foreach (Guid idBad in gBad)
this.Remove(idBad);
}
//update (thus deleting) any deleted child objects
foreach (PartInventoryAdjustmentItem child in deletedList)
{
child.Update( ParentID, tr);
}
//Now that they are deleted remove them from memory
deletedList.Clear();
foreach (PartInventoryAdjustmentItem child in List)
{
child.Update( ParentID, tr);
}
}
#endregion
}//end PartInventoryAdjustmentItems
}//end namespace GZTW.AyaNova.BLL