This commit is contained in:
289
source/bizobjects/AyaLib/GZTW.AyaNova.BLL/ObjectCustomFields.cs
Normal file
289
source/bizobjects/AyaLib/GZTW.AyaNova.BLL/ObjectCustomFields.cs
Normal file
@@ -0,0 +1,289 @@
|
||||
///////////////////////////////////////////////////////////
|
||||
// ObjectCustomFields.cs
|
||||
// Implementation of Class ObjectCustomFields
|
||||
// CSLA type: Editable root collection
|
||||
// Created on: 12-Oct-2004
|
||||
// Object design: John
|
||||
// Coded: John 12-Oct-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="ObjectCustomField"/> objects
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ObjectCustomFields : BusinessCollectionBase
|
||||
{
|
||||
|
||||
#region Constructor
|
||||
|
||||
//Private constructor prevents direction instantiation
|
||||
private ObjectCustomFields()
|
||||
{
|
||||
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 "ObjectCustomField.Label.List";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve ObjectCustomField by index
|
||||
/// </summary>
|
||||
/// <param name="Item">Index</param>
|
||||
public ObjectCustomField this[int Item]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (ObjectCustomField) List[Item];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve ObjectCustomField by string containing form's name value
|
||||
/// </summary>
|
||||
public ObjectCustomField this[string sObjectName, string sFieldName]
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (ObjectCustomField child in List)
|
||||
{
|
||||
if(child.ObjectName==sObjectName && child.FieldName==sFieldName)
|
||||
return child;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove ObjectCustomField by passing it in
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public void Remove(ObjectCustomField obj)
|
||||
{
|
||||
List.Remove(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sObjectName"></param>
|
||||
/// <param name="sFieldName"></param>
|
||||
public void Remove(string sObjectName, string sFieldName)
|
||||
{
|
||||
foreach (ObjectCustomField child in List)
|
||||
{
|
||||
if(child.ObjectName==sObjectName && child.FieldName==sFieldName)
|
||||
List.Remove(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ObjectName"></param>
|
||||
/// <param name="FieldName"></param>
|
||||
/// <returns></returns>
|
||||
public ObjectCustomField Add(string ObjectName, string FieldName)
|
||||
{
|
||||
ObjectCustomField child=ObjectCustomField.NewItem(ObjectName, FieldName);
|
||||
List.Add(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Contains
|
||||
|
||||
/// <summary>
|
||||
/// Check if item in collection
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public bool Contains(ObjectCustomField obj)
|
||||
{
|
||||
foreach (ObjectCustomField child in List)
|
||||
{
|
||||
if(child.Equals(obj)) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sObjectName"></param>
|
||||
/// <param name="sFieldName"></param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(string sObjectName, string sFieldName)
|
||||
{
|
||||
foreach (ObjectCustomField child in List)
|
||||
{
|
||||
if(child.ObjectName==sObjectName && child.FieldName==sFieldName) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if item in deleted collection
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public bool ContainsDeleted(ObjectCustomField obj)
|
||||
{
|
||||
foreach (ObjectCustomField child in deletedList)
|
||||
{
|
||||
if(child.Equals(obj)) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
/// <summary>
|
||||
/// NewItems
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ObjectCustomFields NewItems()
|
||||
{
|
||||
return new ObjectCustomFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ObjectName"></param>
|
||||
/// <returns></returns>
|
||||
public static ObjectCustomFields GetItems(string ObjectName)
|
||||
{
|
||||
ObjectCustomFields col = new ObjectCustomFields();
|
||||
return (ObjectCustomFields)DataPortal.Fetch(new Criteria(ObjectName));
|
||||
|
||||
}
|
||||
#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
|
||||
{
|
||||
DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(
|
||||
"SELECT * FROM aObjectCustomField " +
|
||||
"WHERE aObjectName=@ObjectName"
|
||||
);
|
||||
|
||||
cm.AddInParameter("@ObjectName",DbType.String,crit.ObjectName);
|
||||
dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
||||
|
||||
while(dr.Read())
|
||||
{
|
||||
List.Add(ObjectCustomField.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 (ObjectCustomField child in deletedList)
|
||||
{
|
||||
child.Update(tr);
|
||||
}
|
||||
|
||||
//Now that they are deleted remove them from memory
|
||||
deletedList.Clear();
|
||||
|
||||
foreach (ObjectCustomField 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 string ObjectName;
|
||||
|
||||
public Criteria(string _ObjectName)
|
||||
{
|
||||
ObjectName=_ObjectName;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
}//end ObjectCustomFields
|
||||
|
||||
}//end namespace GZTW.AyaNova.BLL
|
||||
Reference in New Issue
Block a user