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

328 lines
6.3 KiB
C#

///////////////////////////////////////////////////////////
// Rates.cs
// Implementation of Class Rates
// CSLA type: Editable root collection
// Created on: 11-Nov-2004
// Object design: John
// Coded: John 11-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="Rate"/> objects
/// </summary>
[Serializable]
public class Rates : BusinessCollectionBase
{
#region Constructor
//Private constructor prevents direction instantiation
private Rates()
{
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 "Rate.Label.List";
}
}
/// <summary>
/// Retrieve Rate by index
/// </summary>
/// <param name="Item">Index</param>
public Rate this[int Item]
{
get
{
return (Rate) List[Item];
}
}
/// <summary>
/// Retrieve Rate by name
/// returns null if not found
/// </summary>
/// <param name="rateName">rateName</param>
public Rate this[string rateName]
{
get
{
foreach (Rate child in List)
{
if (child.Name.Equals(rateName))
return child;
}
return null;
}
}
/// <summary>
/// Remove Rate by passing it in
/// </summary>
/// <param name="obj"></param>
public void Remove(Rate obj)
{
List.Remove(obj);
}
/// <summary>
/// Remove by Guid value of ID
/// </summary>
/// <param name="ID"></param>
public void Remove(Guid ID)
{
Rate delete = null;
foreach (Rate child in List)
{
if (child.ID == ID)
{
delete = child;
break;
}
}
if (delete != null)
Remove(delete);
}
/// <summary>
/// Add a new Rate to the collection
/// </summary>
public Rate Add()
{
Rate child=Rate.NewItem();
List.Add(child);
return child;
}
/// <summary>
/// Add Rate by passing it in
/// </summary>
/// <param name="obj"></param>
public void Add(Rate obj)
{
List.Add(obj);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected override object OnAddNew()
{
Rate child=Rate.NewItem();
List.Add(child);
return child;
}
#endregion
#region Contains
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(Rate obj)
{
foreach (Rate child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
//case 2072
/// <summary>
/// Check if item in collection by name
/// </summary>
/// <param name="rateName">Name of rate</param>
public bool Contains(String rateName)
{
foreach (Rate child in List)
{
if (child.Name.Equals(rateName)) return true;
}
return false;
}
/// <summary>
/// Check if item in deleted collection
/// </summary>
/// <param name="obj"></param>
public bool ContainsDeleted(Rate obj)
{
foreach (Rate child in deletedList)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
#region Reporting
/// <summary>
/// Returns the report key which is a property of
/// reports used to link all reports that can be used
/// with a particular data source.
/// </summary>
public static string ReportKey
{
get
{
return "Rates";
}
}
#endregion
#region Static methods
/// <summary>
/// Get item collection
/// </summary>
///
/// <returns></returns>
public static Rates GetItems(bool Regional)
{
//in future specify criteria if filtering (e.g. filter by region)
Rates col = new Rates();
return (Rates)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 aRate ORDER BY aRate.aName","aRate","",crit.Regional));//case 58
while(dr.Read())
{
List.Add(Rate.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 (Rate child in deletedList)
{
child.Update(tr);
}
//Now that they are deleted remove them from memory
deletedList.Clear();
foreach (Rate 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 Rates
}//end namespace GZTW.AyaNova.BLL