308 lines
8.3 KiB
C#
308 lines
8.3 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UIUserGridLastViews.cs
|
|
// Implementation of Class UIUserGridLastViews
|
|
// CSLA type: Editable root collection
|
|
// Created on: 22-May-2006
|
|
// Object design: John
|
|
// Coded: John 22-May-2006
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UIUserGridLastViews : BusinessCollectionBase
|
|
{
|
|
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private UIUserGridLastViews()
|
|
{
|
|
//AllowSort = true;
|
|
//AllowFind = true;
|
|
//AllowEdit = true;
|
|
//AllowNew = true;
|
|
//AllowRemove = true;
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Retrieve UIUserGridLastView by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public UIUserGridLastView this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (UIUserGridLastView)List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve UIUserGridLastView by string containing GridKey's name value
|
|
/// If the GridKey in question is not found, a new one is created and if the
|
|
/// manager account has one for that GridKey then it's settings are copied to it
|
|
/// before returning.
|
|
///
|
|
/// This ensures that new users get the managers grid settings if they haven't
|
|
/// made their own yet.
|
|
/// </summary>
|
|
public UIUserGridLastView this[string GridKey]
|
|
{
|
|
get
|
|
{
|
|
foreach (UIUserGridLastView child in List)
|
|
{
|
|
if (child.GridKey == GridKey)
|
|
return child;
|
|
}
|
|
|
|
UIUserGridLastViews mlvs = UIUserGridLastViews.GetItems(User.AdministratorID);
|
|
if (mlvs.Contains(GridKey))
|
|
{
|
|
return this.Add(mlvs[GridKey]);
|
|
|
|
|
|
}
|
|
|
|
//Nope, no manager or local user one to return so make a new one and return it instead
|
|
return this.Add(GridKey);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove UIUserGridLastView by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(UIUserGridLastView obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove UIUserGridLastView by string of GridKey name
|
|
/// </summary>
|
|
/// <param name="GridKey"></param>
|
|
public void Remove(string GridKey)
|
|
{
|
|
foreach (UIUserGridLastView child in List)
|
|
{
|
|
if (child.GridKey == GridKey)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Add a new UIUserGridLastView to the collection
|
|
/// </summary>
|
|
/// <param name="GridKey"></param>
|
|
public UIUserGridLastView Add(string GridKey)
|
|
{
|
|
UIUserGridLastView child = UIUserGridLastView.NewItem(GridKey);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new UIUserGridLastView to the collection
|
|
/// by copying from someone elses
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public UIUserGridLastView Add(UIUserGridLastView obj)
|
|
{
|
|
UIUserGridLastView child = UIUserGridLastView.NewItem(obj.GridKey);
|
|
child.FilterID = obj.FilterID;
|
|
child.ViewXML = obj.ViewXML;
|
|
child.UserID = User.CurrentThreadUserID;
|
|
|
|
List.Add(child);
|
|
return child;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(UIUserGridLastView obj)
|
|
{
|
|
foreach (UIUserGridLastView child in List)
|
|
{
|
|
if (child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection by GridKey name
|
|
/// </summary>
|
|
/// <param name="GridKey"></param>
|
|
public bool Contains(string GridKey)
|
|
{
|
|
foreach (UIUserGridLastView child in List)
|
|
{
|
|
if (child.GridKey == GridKey) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool ContainsDeleted(UIUserGridLastView obj)
|
|
{
|
|
foreach (UIUserGridLastView child in deletedList)
|
|
{
|
|
if (child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static UIUserGridLastViews NewItems()
|
|
{
|
|
return new UIUserGridLastViews();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get item collection (Root collection style)
|
|
/// </summary>
|
|
/// <param name="UserID"></param>
|
|
/// <returns></returns>
|
|
public static UIUserGridLastViews GetItems(Guid UserID)
|
|
{
|
|
UIUserGridLastViews col = new UIUserGridLastViews();
|
|
return (UIUserGridLastViews)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 aUIUserGridLastView WHERE aUserID=@ID", crit.UserID);
|
|
|
|
while (dr.Read())
|
|
{
|
|
List.Add(UIUserGridLastView.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 (UIUserGridLastView child in deletedList)
|
|
{
|
|
child.Update(tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (UIUserGridLastView 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 UIUserGridLastViews
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL
|
|
|