347 lines
9.3 KiB
C#
347 lines
9.3 KiB
C#
///////////////////////////////////////////////////////////
|
|
// WorkorderItemPartRequests.cs
|
|
// Implementation of Class WorkorderItemPartRequests
|
|
// CSLA type: Editable Grandchild collection
|
|
// Created on: 21-Feb-2005
|
|
// Object design: John
|
|
// Coded: John 21-Feb-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Editable Grandchild collection of <see cref="WorkorderItemPartRequest"/> objects residing in parent <see cref="WorkorderItem"/> object
|
|
/// </summary>
|
|
[Serializable]
|
|
public class WorkorderItemPartRequests : BusinessCollectionBase
|
|
{
|
|
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private WorkorderItemPartRequests()
|
|
{
|
|
//Child
|
|
MarkAsChild();
|
|
AllowSort=false;
|
|
AllowFind=true;
|
|
AllowEdit=true;
|
|
AllowNew=true;
|
|
AllowRemove=true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
/// <summary>
|
|
/// Retrieve WorkorderItemPartRequest by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public WorkorderItemPartRequest this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (WorkorderItemPartRequest) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve WorkorderItemPartRequest by string containing Guid value
|
|
/// </summary>
|
|
public WorkorderItemPartRequest this[string WorkorderItemPartRequestID]
|
|
{
|
|
get
|
|
{
|
|
System.Guid sid = new System.Guid(WorkorderItemPartRequestID);
|
|
foreach (WorkorderItemPartRequest child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve WorkorderItemPartRequest by id value
|
|
/// </summary>
|
|
public WorkorderItemPartRequest this[Guid WorkorderItemPartRequestID]
|
|
{
|
|
get
|
|
{
|
|
|
|
foreach (WorkorderItemPartRequest child in List)
|
|
{
|
|
if (child.ID == WorkorderItemPartRequestID)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove WorkorderItemPartRequest by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(WorkorderItemPartRequest obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove WorkorderItemPartRequest by string of id value
|
|
/// </summary>
|
|
/// <param name="WorkorderItemPartRequestID"></param>
|
|
public void Remove(string WorkorderItemPartRequestID)
|
|
{
|
|
System.Guid sid = new System.Guid(WorkorderItemPartRequestID);
|
|
Remove(sid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove by Guid value of ID
|
|
/// </summary>
|
|
/// <param name="WorkorderItemPartRequestID"></param>
|
|
public void Remove(Guid WorkorderItemPartRequestID)
|
|
{
|
|
WorkorderItemPartRequest delete = null;
|
|
foreach (WorkorderItemPartRequest child in List)
|
|
{
|
|
if (child.ID == WorkorderItemPartRequestID)
|
|
delete = child;
|
|
}
|
|
if (delete != null) Remove(delete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new WorkorderItemPartRequest to the collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public WorkorderItemPartRequest Add(WorkorderItem obj)
|
|
{
|
|
WorkorderItemPartRequest child=WorkorderItemPartRequest.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 (WorkorderItemPartRequest 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(WorkorderItemPartRequest obj)
|
|
{
|
|
foreach (WorkorderItemPartRequest 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="WorkorderItemPartRequestID"></param>
|
|
public bool Contains(string WorkorderItemPartRequestID)
|
|
{
|
|
System.Guid sid = new System.Guid(WorkorderItemPartRequestID);
|
|
foreach (WorkorderItemPartRequest 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(WorkorderItemPartRequest obj)
|
|
{
|
|
foreach (WorkorderItemPartRequest 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="WorkorderItemPartRequestID"></param>
|
|
public bool ContainsDeleted(string WorkorderItemPartRequestID)
|
|
{
|
|
System.Guid sid = new System.Guid(WorkorderItemPartRequestID);
|
|
foreach (WorkorderItemPartRequest child in deletedList)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static WorkorderItemPartRequests NewItems()
|
|
{
|
|
return new WorkorderItemPartRequests();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get items - Grandchild style
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
internal static WorkorderItemPartRequests GetItems(WorkorderItem obj)
|
|
{
|
|
WorkorderItemPartRequests col = new WorkorderItemPartRequests();
|
|
//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 aPurchaseOrder.aPONumber, aPurchaseOrder.aOrderedDate, " +
|
|
"aPurchaseOrder.aExpectedReceiveDate, aPurchaseOrder.AID AS APURCHASEORDERID, " + //CASE 227
|
|
" aWorkorderItemPartRequest.* " +
|
|
"FROM " +
|
|
" AWORKORDERITEMPARTREQUEST " +
|
|
" LEFT OUTER JOIN APURCHASEORDERITEM ON (AWORKORDERITEMPARTREQUEST.APURCHASEORDERITEMID=APURCHASEORDERITEM.AID) " +
|
|
" LEFT OUTER JOIN APURCHASEORDER ON (APURCHASEORDERITEM.APURCHASEORDERID=APURCHASEORDER.AID) " +
|
|
"WHERE (aWorkorderItemPartRequest.aWorkorderItemID = @ID)",obj.ID);
|
|
|
|
while(dr.Read())
|
|
{
|
|
List.Add(WorkorderItemPartRequest.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 (WorkorderItemPartRequest child in deletedList)
|
|
{
|
|
child.Update(obj,tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (WorkorderItemPartRequest 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)
|
|
{
|
|
//make sure that all items are deleteable before allowing this to happen
|
|
//A workorderitempartrequest with parts on order is *not* deleteable
|
|
//until those parts are received
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT aQuantity, aReceived, " +
|
|
"aPurchaseOrderItemID " +
|
|
"FROM aWorkorderItemPartRequest " +
|
|
"WHERE aWorkorderItemID=@ID",WorkorderItemID,transaction);
|
|
while(dr.Read())
|
|
{
|
|
|
|
if(dr.GetGuid("aPurchaseOrderItemID")!=Guid.Empty &&
|
|
dr.GetDecimal("aReceived") < dr.GetDecimal("aQuantity"))
|
|
throw new System.ApplicationException
|
|
(LocalizedTextTable.GetLocalizedTextDirect("WorkorderItemPartRequest.Error.NotDeleteableOnOrder"));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aWorkorderItemPartRequest WHERE aWorkorderItemID=@ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,WorkorderItemID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}//end WorkorderItemPartRequests
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |