Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/WorkorderItemParts.cs
2018-06-29 19:47:36 +00:00

354 lines
8.4 KiB
C#

///////////////////////////////////////////////////////////
// WorkorderItemParts.cs
// Implementation of Class WorkorderItemParts
// CSLA type: Editable Grandchild collection
// Created on: 07-Jun-2004 8:41:49 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="WorkorderItemPart"/> objects residing in parent <see cref="WorkorderItem"/> object
/// </summary>
[Serializable]
public class WorkorderItemParts : BusinessCollectionBase {
//Type of workorder
//used to flag whether to track serial numbers
//etc
//internal WorkorderTypes mWorkorderType;
#region Constructor
//Private constructor prevents direction instantiation
private WorkorderItemParts()
{
//Child
MarkAsChild();
AllowSort=false;
AllowFind=true;
AllowEdit=true;
AllowNew=true;
AllowRemove=true;
}
#endregion
#region Business properties and methods
/// <summary>
/// Retrieve WorkorderItemPart by index
/// </summary>
/// <param name="Item">Index</param>
public WorkorderItemPart this[int Item]
{
get
{
return (WorkorderItemPart) List[Item];
}
}
/// <summary>
/// Retrieve WorkorderItemPart by string containing Guid value
/// </summary>
public WorkorderItemPart this[string WorkorderItemPartID]
{
get
{
System.Guid sid = new System.Guid(WorkorderItemPartID);
foreach (WorkorderItemPart child in List)
{
if(child.ID==sid)
return child;
}
return null;
}
}
/// <summary>
/// Retrieve WorkorderItemPart by Guid value
/// </summary>
public WorkorderItemPart this[Guid WorkorderItemPartID]
{
get
{
foreach (WorkorderItemPart child in List)
{
if(child.ID==WorkorderItemPartID)
return child;
}
return null;
}
}
/// <summary>
/// Remove WorkorderItemPart by passing it in
/// </summary>
/// <param name="obj"></param>
public void Remove(WorkorderItemPart obj)
{
List.Remove(obj);
}
/// <summary>
/// Remove WorkorderItemPart by string of id value
/// </summary>
/// <param name="WorkorderItemPartID"></param>
public void Remove(string WorkorderItemPartID)
{
System.Guid sid = new System.Guid(WorkorderItemPartID);
Remove(sid);
}
/// <summary>
/// Remove by Guid value of ID
/// </summary>
/// <param name="WorkorderItemPartID"></param>
public void Remove(Guid WorkorderItemPartID)
{
WorkorderItemPart delete = null;
foreach (WorkorderItemPart child in List)
{
if (child.ID == WorkorderItemPartID)
{
delete = child;
break;
}
}
if (delete != null)
Remove(delete);
}
/// <summary>
/// Add a new WorkorderItemPart to the collection
/// </summary>
/// <param name="obj"></param>
public WorkorderItemPart Add(WorkorderItem obj)
{
WorkorderItemPart child=WorkorderItemPart.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 (WorkorderItemPart child in List)
{
if(RO==false)
RO=AyaBizUtils.Right("Object.WorkorderItemPart")<(int)SecurityLevelTypes.ReadWrite;
child.SetReadOnly(RO);
}
}
#endregion
#region Contains
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(WorkorderItemPart obj)
{
foreach (WorkorderItemPart 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="WorkorderItemPartID"></param>
public bool Contains(string WorkorderItemPartID)
{
System.Guid sid = new System.Guid(WorkorderItemPartID);
foreach (WorkorderItemPart 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(WorkorderItemPart obj)
{
foreach (WorkorderItemPart 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="WorkorderItemPartID"></param>
public bool ContainsDeleted(string WorkorderItemPartID)
{
System.Guid sid = new System.Guid(WorkorderItemPartID);
foreach (WorkorderItemPart child in deletedList)
{
if(child.ID==sid) return true;
}
return false;
}
#endregion
#region Static methods
/// <summary>
/// NewItems
/// </summary>
/// <returns></returns>
internal static WorkorderItemParts NewItems()
{
return new WorkorderItemParts();
}
/// <summary>
/// Get items - Grandchild style
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
internal static WorkorderItemParts GetItems(WorkorderItem obj)
{
WorkorderItemParts col = new WorkorderItemParts();
//case 1317
if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemPart) > (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 aWorkorderItemPart " +
"WHERE aWorkorderItemID=@ID",obj.ID);
while(dr.Read())
{
List.Add(WorkorderItemPart.GetItem(dr, obj.mWorkorderType, 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 (WorkorderItemPart child in deletedList)
{
child.Update(obj,tr);
}
//Now that they are deleted remove them from memory
deletedList.Clear();
foreach (WorkorderItemPart child in List)
{
child.Update(obj,tr);
}
}
#region Shared delete method
internal struct pinfo
{
public Guid id;
public bool hasaffected;
}
/// <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)
{
//This one is more tricky, here we need to iterate through all the matching part records
//and call the workorderitempart static delete method to ensure inventory get's updated properly
SafeDataReader dr = null;
System.Collections.ArrayList al = new System.Collections.ArrayList();
try
{
dr=DBUtil.GetReaderFromSQLString("SELECT aID, aHasAffectedInventory " +
"FROM aWorkorderItemPart " +
"WHERE aWorkorderItemID=@ID",WorkorderItemID,transaction);
while(dr.Read())
{
pinfo pp=new pinfo();
pp.id=dr.GetGuid("aID");
pp.hasaffected=dr.GetBoolean("aHasAffectedInventory");
al.Add(pp);
}
dr.Close();
foreach(object o in al)
WorkorderItemPart.DeleteItem(((pinfo)o).id,((pinfo)o).hasaffected,transaction);
}
finally
{
if(dr!=null) dr.Close();
}
}
#endregion
#endregion
}//end WorkorderItemParts
}//end namespace GZTW.AyaNova.BLL