298 lines
5.9 KiB
C#
298 lines
5.9 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UIUserFormSettings.cs
|
|
// Implementation of Class UIUserFormSettings
|
|
// CSLA type: Editable root collection
|
|
// Created on: 07-Oct-2004
|
|
// Object design: John
|
|
// Coded: John 07-Oct-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
[Serializable]
|
|
public class UIUserFormSettings : BusinessCollectionBase
|
|
{
|
|
|
|
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private UIUserFormSettings()
|
|
{
|
|
//AllowSort = true;
|
|
//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 "UIUserFormSetting.Label.List";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve UIUserFormSetting by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public UIUserFormSetting this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (UIUserFormSetting) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve UIUserFormSetting by string containing form's name value
|
|
/// </summary>
|
|
public UIUserFormSetting this[string FormName]
|
|
{
|
|
get
|
|
{
|
|
foreach (UIUserFormSetting child in List)
|
|
{
|
|
if(child.FormName==FormName)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove UIUserFormSetting by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(UIUserFormSetting obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove UIUserFormSetting by string of form name
|
|
/// </summary>
|
|
|
|
public void Remove(string FormName)
|
|
{
|
|
foreach (UIUserFormSetting child in List)
|
|
{
|
|
if(child.FormName==FormName)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Add a new UIUserFormSetting to the collection
|
|
/// </summary>
|
|
|
|
public UIUserFormSetting Add(string FormName)
|
|
{
|
|
UIUserFormSetting child=UIUserFormSetting.NewItem(FormName);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new UIUserFormSetting to the collection
|
|
/// by copying from someone elses
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public UIUserFormSetting Add(UIUserFormSetting obj)
|
|
{
|
|
UIUserFormSetting child=UIUserFormSetting.NewItem(obj.FormName);
|
|
|
|
child.UserID=User.CurrentThreadUserID;
|
|
child.Layout = obj.Layout;
|
|
List.Add(child);
|
|
return child;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(UIUserFormSetting obj)
|
|
{
|
|
foreach (UIUserFormSetting child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection by form name
|
|
/// </summary>
|
|
|
|
public bool Contains(string FormName)
|
|
{
|
|
foreach (UIUserFormSetting child in List)
|
|
{
|
|
if(child.FormName==FormName) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool ContainsDeleted(UIUserFormSetting obj)
|
|
{
|
|
foreach (UIUserFormSetting child in deletedList)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static UIUserFormSettings NewItems()
|
|
{
|
|
return new UIUserFormSettings();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get item collection (Root collection style)
|
|
/// </summary>
|
|
/// <param name="UserID"></param>
|
|
/// <returns></returns>
|
|
public static UIUserFormSettings GetItems(Guid UserID)
|
|
{
|
|
UIUserFormSettings col = new UIUserFormSettings();
|
|
return (UIUserFormSettings)DataPortal.Fetch(new Criteria(UserID));
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
/// <summary>
|
|
/// Fetch children root style
|
|
/// </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 aUIUserFormSetting WHERE aUserID=@ID",crit.UserID);
|
|
|
|
while(dr.Read())
|
|
{
|
|
List.Add(UIUserFormSetting.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 (UIUserFormSetting child in deletedList)
|
|
{
|
|
child.Update(tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (UIUserFormSetting 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
|
|
|
|
#pragma warning restore 1591
|
|
}//end UIUserFormSettings
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |