186 lines
5.8 KiB
C#
186 lines
5.8 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Bool.cs
|
|
// Implementation of Class PartByWarehouseInventoryValuesFetcher
|
|
// CSLA type: Read-only object
|
|
// Created on: 25-Oct-2005
|
|
// Object design: John
|
|
// Coded: John 25-Oct-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Used to quickly fetch a various inventory related values
|
|
/// for a particular part / warehouse combination.
|
|
///
|
|
/// WARNING to developer API users:
|
|
/// There are potential concurrency issues using this value
|
|
/// in a multi-user scenario.
|
|
///
|
|
/// This value is intended for read only purposes when displaying in a user
|
|
/// interface. The actual value stored in the database is
|
|
/// subject to change by other users updating
|
|
/// inventory *after* this value is retrieved so it should not be used
|
|
/// in any calculations to affect inventory in the database,
|
|
/// those should be done through
|
|
/// the inventory updating methods provided in other classes which are
|
|
/// done within a database transaction with an IsolationLevel of Serializeable.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class PartByWarehouseInventoryValuesFetcher : ReadOnlyBase //v8port: there is also a PartInventoryValuesFetcher which is used by qbi only, this and that might be combined?
|
|
{
|
|
|
|
private decimal mQuantityOnHand=0;
|
|
private decimal mQuantityOnOrder=0;
|
|
private decimal mQtyOnOrderCommitted=0;
|
|
private decimal mMinStockLevel=0;
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private PartByWarehouseInventoryValuesFetcher()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Business properties
|
|
/// <summary>
|
|
/// Quantity in stock
|
|
/// </summary>
|
|
public decimal QuantityOnHand {get{return mQuantityOnHand;}}
|
|
/// <summary>
|
|
/// Quantity appearing on all un received outstanding purchase orders
|
|
/// </summary>
|
|
public decimal QuantityOnOrder {get{return mQuantityOnOrder;}}
|
|
/// <summary>
|
|
/// Quanity on order that is spoken for on open workorder item part requests
|
|
/// </summary>
|
|
public decimal QtyOnOrderCommitted {get{return mQtyOnOrderCommitted;}}
|
|
/// <summary>
|
|
/// Desired minimum inventory level to keep on hand
|
|
/// </summary>
|
|
public decimal MinStockLevel {get{return mMinStockLevel;}}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
/// <summary>
|
|
/// Retrieve a snapshot of current
|
|
/// inventory values
|
|
/// </summary>
|
|
/// <param name="PartID">ID of part</param>
|
|
/// <param name="PartWarehouseID">ID of warehouse</param>
|
|
/// <returns>PartByWarehouseInventoryValuesFetcher object</returns>
|
|
public static PartByWarehouseInventoryValuesFetcher GetItem(Guid PartID, Guid PartWarehouseID)
|
|
{
|
|
|
|
return (PartByWarehouseInventoryValuesFetcher)DataPortal.Fetch(new Criteria(PartID, PartWarehouseID, null ));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve a snapshot of current
|
|
/// inventory values frozen within a transaction
|
|
/// </summary>
|
|
/// <param name="PartID">ID of part</param>
|
|
/// <param name="PartWarehouseID">ID of warehouse</param>
|
|
/// <param name="tr">Database transaction</param>
|
|
/// <returns></returns>
|
|
internal static PartByWarehouseInventoryValuesFetcher GetItem(Guid PartID, Guid PartWarehouseID, IDbTransaction tr)
|
|
{
|
|
|
|
return (PartByWarehouseInventoryValuesFetcher)DataPortal.Fetch(new Criteria(PartID, PartWarehouseID, tr ));
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param Bool="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
//case 3175
|
|
//properly handle missing info
|
|
if (crit.PartID == Guid.Empty || crit.PartWarehouseID == Guid.Empty)
|
|
{
|
|
mQuantityOnHand = 0m;
|
|
mQuantityOnOrder = 0m;
|
|
mQtyOnOrderCommitted = 0m;
|
|
mMinStockLevel = 0m;
|
|
return;
|
|
}
|
|
|
|
//Case 476
|
|
PartByWarehouseInventoryManager.EnsureItem(crit.PartID,crit.PartWarehouseID,crit.tr);
|
|
|
|
DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
"SELECT aQuantityOnHand, aQuantityOnOrder,aMinStockLevel, " +
|
|
"aQtyOnOrderCommitted FROM aPartByWarehouseInventory " +
|
|
"WHERE (aPartID = @PartID) AND (aPartWarehouseID = @PartWarehouseID)"
|
|
);
|
|
cm.AddInParameter("@PartID",DbType.Guid,crit.PartID);
|
|
cm.AddInParameter("@PartWarehouseID",DbType.Guid,crit.PartWarehouseID);
|
|
|
|
SafeDataReader dr = null;
|
|
if(crit.tr==null)
|
|
dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
|
else
|
|
dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm,crit.tr));
|
|
if(!dr.Read())
|
|
throw new ApplicationException("PartByWarehouseInventoryValuesFetcher: unable to retrieve record indicated");
|
|
|
|
mQuantityOnHand=dr.GetDecimal("aQuantityOnHand");
|
|
mQuantityOnOrder=dr.GetDecimal("aQuantityOnOrder");
|
|
mQtyOnOrderCommitted=dr.GetDecimal("aQtyOnOrderCommitted");
|
|
mMinStockLevel=dr.GetDecimal("aMinStockLevel");
|
|
dr.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
public Guid PartID;
|
|
public Guid PartWarehouseID;
|
|
public IDbTransaction tr;
|
|
|
|
public Criteria(Guid _PartID, Guid _PartWarehouseID, IDbTransaction _tr)
|
|
{
|
|
PartID=_PartID;
|
|
PartWarehouseID=_PartWarehouseID;
|
|
tr=_tr;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end Bool
|
|
|
|
}//end Boolspace GZTW.AyaNova.BLL |