This commit is contained in:
272
source/bizobjects/AyaLib/GZTW.AyaNova.BLL/PartWarehouses.cs
Normal file
272
source/bizobjects/AyaLib/GZTW.AyaNova.BLL/PartWarehouses.cs
Normal file
@@ -0,0 +1,272 @@
|
||||
///////////////////////////////////////////////////////////
|
||||
// PartWarehouses.cs
|
||||
// Implementation of Class PartWarehouses
|
||||
// CSLA type: Editable root collection
|
||||
// Created on: 04-Nov-2004
|
||||
// Object design: Joyce
|
||||
// Coded: John 04-Nov-2004
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using CSLA.Data;
|
||||
using GZTW.Data;
|
||||
using CSLA;
|
||||
|
||||
|
||||
namespace GZTW.AyaNova.BLL
|
||||
{
|
||||
/// <summary>
|
||||
/// Editable Root collection of <see cref="PartWarehouse"/> objects
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class PartWarehouses : BusinessCollectionBase
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
//Private constructor prevents direction instantiation
|
||||
private PartWarehouses()
|
||||
{
|
||||
AllowSort=false;
|
||||
AllowFind=true;
|
||||
AllowEdit=true;
|
||||
AllowNew=true;
|
||||
AllowRemove=false;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Business properties and methods
|
||||
/// <summary>
|
||||
/// Locale key so that generic list editor
|
||||
/// UI code knows what title to give the list in a
|
||||
/// grid
|
||||
/// </summary>
|
||||
public string LocaleKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "PartWarehouse.Label.List";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve PartWarehouse by index
|
||||
/// </summary>
|
||||
/// <param name="Item">Index</param>
|
||||
public PartWarehouse this[int Item]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (PartWarehouse) List[Item];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remove PartWarehouse by passing it in
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public void Remove(PartWarehouse obj)
|
||||
{
|
||||
List.Remove(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove by Guid value of ID
|
||||
/// </summary>
|
||||
/// <param name="ID"></param>
|
||||
public void Remove(Guid ID)
|
||||
{
|
||||
PartWarehouse delete = null;
|
||||
foreach (PartWarehouse child in List)
|
||||
{
|
||||
if (child.ID == ID)
|
||||
{
|
||||
delete = child;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (delete != null)
|
||||
Remove(delete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new PartWarehouse to the collection
|
||||
/// </summary>
|
||||
|
||||
public PartWarehouse Add()
|
||||
{
|
||||
PartWarehouse child=PartWarehouse.NewItem();
|
||||
List.Add(child);
|
||||
return child;
|
||||
}
|
||||
/// <summary>
|
||||
/// Add PartWarehouse by passing it in
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public void Add(PartWarehouse obj)
|
||||
{
|
||||
List.Add(obj);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override object OnAddNew()
|
||||
{
|
||||
PartWarehouse child=PartWarehouse.NewItem();
|
||||
List.Add(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Contains
|
||||
|
||||
/// <summary>
|
||||
/// Check if item in collection
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public bool Contains(PartWarehouse obj)
|
||||
{
|
||||
foreach (PartWarehouse child in List)
|
||||
{
|
||||
if(child.Equals(obj)) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check if item in deleted collection
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public bool ContainsDeleted(PartWarehouse obj)
|
||||
{
|
||||
foreach (PartWarehouse child in deletedList)
|
||||
{
|
||||
if(child.Equals(obj)) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get item collection
|
||||
/// </summary>
|
||||
///
|
||||
/// <returns></returns>
|
||||
public static PartWarehouses GetItems(bool Regional)
|
||||
{
|
||||
//in future specify criteria if filtering (e.g. filter by region)
|
||||
PartWarehouses col = new PartWarehouses();
|
||||
return (PartWarehouses)DataPortal.Fetch(new Criteria(Regional));
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region DAL DATA ACCESS
|
||||
|
||||
/// <summary>
|
||||
/// Fetch children
|
||||
/// </summary>
|
||||
/// <param name="Criteria"></param>
|
||||
protected override void DataPortal_Fetch(object Criteria)
|
||||
{
|
||||
Criteria crit = (Criteria)Criteria;
|
||||
SafeDataReader dr = null;
|
||||
try
|
||||
{
|
||||
dr=DBUtil.GetReaderFromSQLString(DBUtil.AddRegionFilter("SELECT * FROM aPartWarehouse ORDER BY ANAME ","aPartWarehouse","",crit.Regional));
|
||||
while(dr.Read())
|
||||
{
|
||||
|
||||
List.Add(PartWarehouse.GetItem(dr));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(dr!=null) dr.Close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Editable Root Collection Update
|
||||
/// </summary>
|
||||
protected override void DataPortal_Update()
|
||||
{
|
||||
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
||||
{
|
||||
connection.Open();
|
||||
IDbTransaction tr = connection.BeginTransaction();
|
||||
try
|
||||
{
|
||||
|
||||
//update (thus deleting) any deleted child objects
|
||||
foreach (PartWarehouse child in deletedList)
|
||||
{
|
||||
child.Update(tr);
|
||||
}
|
||||
|
||||
//Now that they are deleted remove them from memory
|
||||
deletedList.Clear();
|
||||
|
||||
foreach (PartWarehouse child in List)
|
||||
{
|
||||
child.Update(tr);
|
||||
|
||||
}
|
||||
|
||||
tr.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
tr.Rollback();
|
||||
throw;//WAS: throw(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region criteria
|
||||
/// <summary>
|
||||
/// Criteria for identifying existing object
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
private class Criteria
|
||||
{
|
||||
public bool Regional;
|
||||
|
||||
public Criteria(bool _Regional)
|
||||
{
|
||||
Regional = _Regional;
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
}//end PartWarehouses
|
||||
|
||||
}//end namespace GZTW.AyaNova.BLL
|
||||
Reference in New Issue
Block a user