Files
2018-06-29 19:47:36 +00:00

306 lines
6.4 KiB
C#

///////////////////////////////////////////////////////////
// PartAssemblies.cs
// Implementation of Class PartAssemblies
// CSLA type: Editable root collection
// Created on: 04-Nov-2004
// Object design: John
// 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="PartAssembly"/> objects
/// </summary>
[Serializable]
public class PartAssemblies : BusinessCollectionBase
{
#region Constructor
//Private constructor prevents direction instantiation
private PartAssemblies()
{
AllowSort=false;
AllowFind=true;
AllowEdit=true;
AllowNew=true;
AllowRemove=true;
}
#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 "PartAssembly.Label.List";
}
}
/// <summary>
/// Retrieve PartAssembly by index
/// </summary>
/// <param name="Item">Index</param>
public PartAssembly this[int Item]
{
get
{
return (PartAssembly) List[Item];
}
}
/// <summary>
/// Remove PartAssembly by passing it in
/// </summary>
/// <param name="obj"></param>
public void Remove(PartAssembly obj)
{
List.Remove(obj);
}
/// <summary>
/// Remove by Guid value of ID
/// </summary>
/// <param name="ID"></param>
public void Remove(Guid ID)
{
PartAssembly delete = null;
foreach (PartAssembly child in List)
{
if (child.ID == ID)
{
delete = child;
break;
}
}
if (delete != null)
Remove(delete);
}
/// <summary>
/// Add a new PartAssembly to the collection
/// </summary>
public PartAssembly Add()
{
PartAssembly child=PartAssembly.NewItem();
List.Add(child);
return child;
}
/// <summary>
/// Add PartAssembly by passing it in
/// </summary>
/// <param name="obj"></param>
public void Add(PartAssembly obj)
{
List.Add(obj);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected override object OnAddNew()
{
PartAssembly child=PartAssembly.NewItem();
List.Add(child);
return child;
}
/// <summary>
/// Get a list of all duplicate names in this list
/// </summary>
public System.Collections.Generic.List<string> DuplicateNames
{
get
{
System.Collections.Generic.List<string> dupes = new System.Collections.Generic.List<string>();
System.Collections.Generic.List<string> all = new System.Collections.Generic.List<string>();
foreach (PartAssembly i in List)
{
if (all.Contains(i.Name))
{
dupes.Add(i.Name);
}
else
{
all.Add(i.Name);
}
}
return dupes;
}
}
#endregion
#region Contains
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(PartAssembly obj)
{
foreach (PartAssembly 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(PartAssembly obj)
{
foreach (PartAssembly child in deletedList)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
#region Static methods
/// <summary>
/// Get item collection
/// </summary>
///
/// <returns></returns>
public static PartAssemblies GetItems()
{
//in future specify criteria if filtering (e.g. filter by region)
PartAssemblies col = new PartAssemblies();
return (PartAssemblies)DataPortal.Fetch(new Criteria());
}
/// <summary>
/// Check all items for duplicate names
/// </summary>
/// <returns>List of duplicate names</returns>
public static System.Collections.Generic.List<string> DuplicateNameCheck()
{
return GetItems().DuplicateNames;
}
#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("SELECT * FROM aPartAssembly ORDER BY ANAME;");
while(dr.Read())
{
List.Add(PartAssembly.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 (PartAssembly child in deletedList)
{
child.Update(tr);
}
//Now that they are deleted remove them from memory
deletedList.Clear();
foreach (PartAssembly 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 string ObjectName;
public Criteria(/*string _ObjectName*/)
{
//ObjectName=_ObjectName;
}
}
#endregion
}//end PartAssemblies
}//end namespace GZTW.AyaNova.BLL