374 lines
10 KiB
C#
374 lines
10 KiB
C#
///////////////////////////////////////////////////////////
|
|
// WorkorderItemMiscExpenses.cs
|
|
// Implementation of Class WorkorderItemMiscExpenses
|
|
// CSLA type: Editable Grandchild collection
|
|
// Created on: 07-Jun-2004 8:41:48 AM
|
|
// Object design: Joyce
|
|
// Coded: John 28-July-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using GZTW.Data;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
///Editable Grandchild collection of <see cref="WorkorderItemMiscExpense"/> objects residing in parent <see cref="WorkorderItem"/> object
|
|
/// </summary>
|
|
[Serializable]
|
|
public class WorkorderItemMiscExpenses : BusinessCollectionBase {
|
|
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private WorkorderItemMiscExpenses()
|
|
{
|
|
//Child
|
|
MarkAsChild();
|
|
AllowSort=false;
|
|
AllowFind=true;
|
|
AllowEdit=true;
|
|
AllowNew=true;
|
|
AllowRemove=true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
/// <summary>
|
|
/// Retrieve WorkorderItemMiscExpense by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public WorkorderItemMiscExpense this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (WorkorderItemMiscExpense) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve WorkorderItemMiscExpense by string containing Guid value
|
|
/// </summary>
|
|
public WorkorderItemMiscExpense this[string WorkorderItemMiscExpenseID]
|
|
{
|
|
get
|
|
{
|
|
System.Guid sid = new System.Guid(WorkorderItemMiscExpenseID);
|
|
foreach (WorkorderItemMiscExpense child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
//case 1975
|
|
/// <summary>
|
|
/// Retrieve WorkorderItemMiscExpense by Guid value
|
|
/// </summary>
|
|
public WorkorderItemMiscExpense this[Guid WorkorderItemMiscExpenseID]
|
|
{
|
|
get
|
|
{
|
|
foreach (WorkorderItemMiscExpense child in List)
|
|
{
|
|
if (child.ID == WorkorderItemMiscExpenseID)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove WorkorderItemMiscExpense by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(WorkorderItemMiscExpense obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove WorkorderItemMiscExpense by string of id value
|
|
/// </summary>
|
|
/// <param name="WorkorderItemMiscExpenseID"></param>
|
|
public void Remove(string WorkorderItemMiscExpenseID)
|
|
{
|
|
System.Guid sid = new System.Guid(WorkorderItemMiscExpenseID);
|
|
foreach (WorkorderItemMiscExpense child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
///// <summary>
|
|
///// Remove by Guid value of ID
|
|
///// </summary>
|
|
///// <param name="WorkorderItemMiscExpenseID"></param>
|
|
//public void Remove(Guid WorkorderItemMiscExpenseID)
|
|
//{
|
|
// foreach (WorkorderItemMiscExpense child in List)
|
|
// {
|
|
// if(child.ID==WorkorderItemMiscExpenseID)
|
|
// List.Remove(child);
|
|
// }
|
|
//}
|
|
|
|
//case 1975
|
|
//weird problem, using the above was throwing an error about modifying collection while iterating it
|
|
//however it was able to work with windows UI so not sure what the f?
|
|
//but this is how it *should* have been written:
|
|
|
|
/// <summary>
|
|
/// Remove by Guid value of ID
|
|
/// </summary>
|
|
/// <param name="WorkorderItemMiscExpenseID"></param>
|
|
public void Remove(Guid WorkorderItemMiscExpenseID)
|
|
{
|
|
WorkorderItemMiscExpense delete = null;
|
|
foreach (WorkorderItemMiscExpense child in List)
|
|
{
|
|
if (child.ID == WorkorderItemMiscExpenseID)
|
|
{
|
|
delete = child;
|
|
break;
|
|
}
|
|
|
|
}
|
|
if (delete != null)
|
|
Remove(delete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new WorkorderItemMiscExpense to the collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public WorkorderItemMiscExpense Add(WorkorderItem obj)
|
|
{
|
|
WorkorderItemMiscExpense child=WorkorderItemMiscExpense.NewItem(obj);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets all items to read / write status
|
|
/// used by workorder object when it's closed or service completed is true
|
|
/// </summary>
|
|
/// <param name="RO">true=Set to read only explicitly, false=set to whatever rights allowed</param>
|
|
public void SetReadOnly(bool RO)
|
|
{
|
|
foreach (WorkorderItemMiscExpense child in List)
|
|
{
|
|
if(RO==false)
|
|
RO=AyaBizUtils.Right("Object.WorkorderItemMiscExpense")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
child.SetReadOnly(RO);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(WorkorderItemMiscExpense obj)
|
|
{
|
|
foreach (WorkorderItemMiscExpense child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection by string of ID value
|
|
/// </summary>
|
|
/// <param name="WorkorderItemMiscExpenseID"></param>
|
|
public bool Contains(string WorkorderItemMiscExpenseID)
|
|
{
|
|
System.Guid sid = new System.Guid(WorkorderItemMiscExpenseID);
|
|
foreach (WorkorderItemMiscExpense child in List)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool ContainsDeleted(WorkorderItemMiscExpense obj)
|
|
{
|
|
foreach (WorkorderItemMiscExpense child in deletedList)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection by string of ID value
|
|
/// </summary>
|
|
/// <param name="WorkorderItemMiscExpenseID"></param>
|
|
public bool ContainsDeleted(string WorkorderItemMiscExpenseID)
|
|
{
|
|
System.Guid sid = new System.Guid(WorkorderItemMiscExpenseID);
|
|
foreach (WorkorderItemMiscExpense child in deletedList)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static WorkorderItemMiscExpenses NewItems()
|
|
{
|
|
return new WorkorderItemMiscExpenses();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get items - Grandchild style
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
internal static WorkorderItemMiscExpenses GetItems(WorkorderItem obj)
|
|
{
|
|
WorkorderItemMiscExpenses col = new WorkorderItemMiscExpenses();
|
|
|
|
//case 1317
|
|
if(AyaBizUtils.Right(RootObjectTypes.WorkorderItemMiscExpense) > (int)SecurityLevelTypes.NoAccess)
|
|
col.Fetch(obj);
|
|
|
|
return col;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
/// <summary>
|
|
/// Fetch children - grandchild style
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
private void Fetch(WorkorderItem obj)
|
|
{
|
|
//Load data Grandchild style
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * " +
|
|
"FROM aWorkorderItemMiscExpense " +
|
|
"WHERE aWorkorderItemID=@ID",obj.ID);
|
|
while(dr.Read())
|
|
{
|
|
List.Add(WorkorderItemMiscExpense.GetItem(dr,obj));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update children
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="tr"></param>
|
|
internal void Update(WorkorderItem obj,IDbTransaction tr)
|
|
{
|
|
//update (thus deleting) any deleted child objects
|
|
foreach (WorkorderItemMiscExpense child in deletedList)
|
|
{
|
|
child.Update(obj,tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (WorkorderItemMiscExpense child in List)
|
|
{
|
|
child.Update(obj,tr);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#region Shared delete method
|
|
/// <summary>
|
|
/// Given a workorder item ID deletes all items for that ID
|
|
///
|
|
/// Called by workorderitems delete
|
|
/// </summary>
|
|
/// <param name="WorkorderItemID">ID of parent workorder item</param>
|
|
/// <param name="transaction">Database transaction from ascendant item</param>
|
|
internal static void DeleteItems(Guid WorkorderItemID,IDbTransaction transaction)
|
|
{
|
|
|
|
//Delete all items indexed keywords for this workorderitemID
|
|
SafeDataReader dr = null;
|
|
System.Collections.ArrayList al = new System.Collections.ArrayList();
|
|
try
|
|
{
|
|
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT aID " +
|
|
"FROM aWorkorderItemMiscExpense " +
|
|
"WHERE aWorkorderItemID=@ID",WorkorderItemID,transaction);
|
|
while(dr.Read())
|
|
{
|
|
al.Add(dr.GetGuid("aID"));
|
|
|
|
}
|
|
dr.Close();
|
|
foreach(object o in al)
|
|
DBUtil.RemoveKeywords(transaction,RootObjectTypes.WorkorderItemMiscExpense,(Guid)o);
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
// DBCommandWrapper cmDeleteKeywords = DBUtil.GetCommandFromSQL(
|
|
// "DELETE aSearchKey FROM aSearchKey INNER JOIN aWorkorderItemMiscExpense " +
|
|
// "ON aSearchKey.aSourceObjectID = aWorkorderItemMiscExpense.aID WHERE " +
|
|
// "(aWorkorderItemMiscExpense.aWorkorderItemID = @ID);");
|
|
// cmDeleteKeywords.AddInParameter("@ID",DbType.Guid,WorkorderItemID);
|
|
// DBUtil.DB.ExecuteNonQuery(cmDeleteKeywords,transaction);
|
|
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aWorkorderItemMiscExpense WHERE aWorkorderItemID=@ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,WorkorderItemID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
|
|
}
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
}//end WorkorderItemMiscExpenses
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |