270 lines
5.5 KiB
C#
270 lines
5.5 KiB
C#
///////////////////////////////////////////////////////////
|
|
// NotifyDeliverySettings.cs
|
|
// Implementation of Class NotifyDeliverySettings
|
|
// CSLA type: Editable root collection
|
|
// Created on: 06-Oct-2005
|
|
// Object design: John
|
|
// Coded: John 06-Oct-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Editable root collection of <see cref="NotifyDeliverySetting"/> objects
|
|
/// </summary>
|
|
[Serializable]
|
|
public class NotifyDeliverySettings : BusinessCollectionBase
|
|
{
|
|
internal Guid mUserID;
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private NotifyDeliverySettings()
|
|
{
|
|
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 "NotifyDeliverySetting.Label.List";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve NotifyDeliverySetting by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public NotifyDeliverySetting this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (NotifyDeliverySetting) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve NotifyDeliverySetting by Guid value
|
|
/// </summary>
|
|
public NotifyDeliverySetting this[Guid ID]
|
|
{
|
|
get
|
|
{
|
|
|
|
foreach (NotifyDeliverySetting child in List)
|
|
{
|
|
if(child.ID==ID)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove NotifyDeliverySetting by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(NotifyDeliverySetting obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new NotifyDeliverySetting to the collection
|
|
/// </summary>
|
|
|
|
public NotifyDeliverySetting Add()
|
|
{
|
|
NotifyDeliverySetting child=NotifyDeliverySetting.NewItem(this.mUserID);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
/// <summary>
|
|
/// Add NotifyDeliverySetting by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Add(NotifyDeliverySetting obj)
|
|
{
|
|
List.Add(obj);
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected override object OnAddNew()
|
|
{
|
|
NotifyDeliverySetting child=NotifyDeliverySetting.NewItem(this.mUserID);
|
|
|
|
List.Add(child);
|
|
|
|
return child;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(NotifyDeliverySetting obj)
|
|
{
|
|
foreach (NotifyDeliverySetting 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(NotifyDeliverySetting obj)
|
|
{
|
|
foreach (NotifyDeliverySetting child in deletedList)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// Get item collection
|
|
/// </summary>
|
|
///
|
|
/// <returns></returns>
|
|
public static NotifyDeliverySettings GetItems(Guid UserID)
|
|
{
|
|
//in future specify criteria if filtering (e.g. filter by region)
|
|
NotifyDeliverySettings col = new NotifyDeliverySettings();
|
|
|
|
return (NotifyDeliverySettings)DataPortal.Fetch(new Criteria(UserID));
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
/// <summary>
|
|
/// Fetch children
|
|
/// </summary>
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
this.mUserID=crit.UserID;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
if(crit.UserID==Guid.Empty)
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aNotifyDeliverySetting");
|
|
else
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aNotifyDeliverySetting WHERE aUserID=@ID",crit.UserID);
|
|
while(dr.Read())
|
|
{
|
|
List.Add(NotifyDeliverySetting.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 (NotifyDeliverySetting child in deletedList)
|
|
{
|
|
child.Update(tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (NotifyDeliverySetting 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 Guid UserID;
|
|
|
|
public Criteria(Guid _UserID)
|
|
{
|
|
UserID=_UserID;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end NotifyDeliverySettings
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |