425 lines
10 KiB
C#
425 lines
10 KiB
C#
///////////////////////////////////////////////////////////
|
|
// ClientNotes.cs
|
|
// Implementation of Class ClientNotes
|
|
// 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;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Collection of <see cref="ClientNote"/> objects attached to a <see cref="Client"/>
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ClientNotes : BusinessCollectionBase
|
|
{
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private ClientNotes()
|
|
{
|
|
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 "ClientNote.Label.List";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reference <see cref="ClientNote"/> by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public ClientNote this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (ClientNote) List[Item];
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Reference <see cref="ClientNote"/> from collection by ID
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public ClientNote this[Guid id]
|
|
{
|
|
get
|
|
{
|
|
foreach (ClientNote child in List)
|
|
{
|
|
if (child.ID == id)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reference <see cref="ClientNote"/> in collection based on a string representation of it's Guid value
|
|
/// </summary>
|
|
/// <param name="sid"></param>
|
|
/// <returns></returns>
|
|
public ClientNote this[string sid]
|
|
{
|
|
get{
|
|
return this[new Guid(sid)];
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove <see cref="ClientNote"/> by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(ClientNote obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove <see cref="ClientNote"/> from collection by ID value
|
|
/// </summary>
|
|
/// <param name="ID"></param>
|
|
public void Remove(Guid ID)
|
|
{
|
|
ClientNote delete = null;
|
|
foreach (ClientNote child in List)
|
|
{
|
|
if (child.ID == ID)
|
|
{
|
|
delete = child;
|
|
break;
|
|
}
|
|
}
|
|
if (delete != null)
|
|
Remove(delete);
|
|
|
|
}
|
|
/// <summary>
|
|
/// Remove <see cref="ClientNote"/> from collection based on a string representation of it's ID
|
|
/// </summary>
|
|
/// <param name="sID"></param>
|
|
public void Remove(string sID)
|
|
{
|
|
Remove(new Guid(sID));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Add a new ClientNote to the collection
|
|
/// </summary>
|
|
|
|
public ClientNote Add()
|
|
{
|
|
ClientNote child=ClientNote.NewItem();
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
/// <summary>
|
|
/// Add ClientNote by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Add(ClientNote obj)
|
|
{
|
|
List.Add(obj);
|
|
}
|
|
|
|
// protected override object OnAddNew()
|
|
// {
|
|
// ClientNote child=ClientNote.NewItem();
|
|
// List.Add(child);
|
|
// return child;
|
|
// }
|
|
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(ClientNote obj)
|
|
{
|
|
foreach (ClientNote 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(ClientNote obj)
|
|
{
|
|
foreach (ClientNote child in deletedList)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Reporting and shared UI editor helpers
|
|
|
|
/// <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 "ClientNoteList";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the Detailed report key
|
|
/// which is used to determine which reports and objects
|
|
/// will be used for detailed reports
|
|
///
|
|
/// If empty string then indicates there is no detailed report object or reports
|
|
/// </summary>
|
|
public static string DetailedReportKey
|
|
{
|
|
get
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Base object that this list is reporting on
|
|
/// used by shared UI editor to instantiate new objects
|
|
/// when user selects new in UI elements that display this list
|
|
///
|
|
/// (I.E. when user clicks on new in a read only list grid, this is the object type created)
|
|
/// </summary>
|
|
public static RootObjectTypes BaseObjectType
|
|
{
|
|
get
|
|
{
|
|
return RootObjectTypes.ClientNote;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// The Type of the struct used to store list records
|
|
/// Used to fetch the custom display attributes of the fields
|
|
/// contained within the record to modify the grid display accordingly
|
|
/// <see cref="DisplayAttribute"/>
|
|
/// </summary>
|
|
public static Type ListRecordType
|
|
{
|
|
get
|
|
{
|
|
return typeof(ClientNote);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Field that contains the ID of the objects
|
|
/// that are the basis of this list.
|
|
///
|
|
/// Used for compiling an ID list for reporting from user
|
|
/// selections in a grid.
|
|
/// </summary>
|
|
public static string IDField
|
|
{
|
|
get
|
|
{
|
|
return "ID";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Same as IDField but for detailed reports
|
|
/// </summary>
|
|
public static string IDFieldDetailed
|
|
{
|
|
get
|
|
{
|
|
return IDField;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// Get item collection
|
|
/// </summary>
|
|
///
|
|
/// <returns></returns>
|
|
public static ClientNotes GetItems(Guid ClientID)
|
|
{
|
|
ClientNotes col = new ClientNotes();
|
|
return (ClientNotes)DataPortal.Fetch(new Criteria(ClientID, null));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get list by items indicated in IDList
|
|
/// </summary>
|
|
/// <param name="IDList">Generic list of Guid's</param>
|
|
/// <returns></returns>
|
|
public static ClientNotes GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 274
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new ClientNotes();
|
|
return (ClientNotes)DataPortal.Fetch(new Criteria(Guid.Empty, IDList));
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
|
|
/// <summary>
|
|
/// Fetch children
|
|
/// </summary>
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
if (crit.IDList != null)
|
|
{
|
|
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
|
|
sbIN.Append("SELECT * FROM ACLIENTNOTE WHERE aClientNote.aID in (");
|
|
foreach (Guid gItem in crit.IDList)
|
|
{
|
|
sbIN.Append("'");
|
|
sbIN.Append("{");
|
|
sbIN.Append(gItem.ToString().ToUpperInvariant());
|
|
sbIN.Append("}");
|
|
sbIN.Append("',");
|
|
}
|
|
sbIN.Length = sbIN.Length - 1;
|
|
sbIN.Append(") order by anotedate desc");
|
|
dr = DBUtil.GetReaderFromSQLString(sbIN.ToString());
|
|
}
|
|
else
|
|
{
|
|
dr = DBUtil.GetReaderFromSQLString("SELECT * FROM aClientNote WHERE aClientID=@ID order by anotedate desc", crit.ClientID);
|
|
}
|
|
|
|
while (dr.Read())
|
|
{
|
|
List.Add(ClientNote.GetItem(dr));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
}
|
|
|
|
#endregion fetch
|
|
|
|
#region Update
|
|
|
|
/// <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 (ClientNote child in deletedList)
|
|
{
|
|
child.Update(tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (ClientNote child in List)
|
|
{
|
|
child.Update(tr);
|
|
}
|
|
tr.Commit();
|
|
}
|
|
catch
|
|
{
|
|
tr.Rollback();
|
|
throw;//WAS: throw(ex);
|
|
}
|
|
}
|
|
}
|
|
#endregion update
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public Guid ClientID;
|
|
public List<Guid> IDList;
|
|
public Criteria(Guid _ClientID, List<Guid> _IDList)
|
|
{
|
|
ClientID=_ClientID;
|
|
IDList = _IDList;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end ClientNotes
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |