562 lines
13 KiB
C#
562 lines
13 KiB
C#
///////////////////////////////////////////////////////////
|
|
// PartByWarehouseInventory.cs
|
|
// Implementation of Class PartByWarehouseInventory
|
|
// CSLA type: Editable Child
|
|
// Created on: 07-Jun-2004 8:41:27 AM
|
|
// Object design: Joyce
|
|
// Coded: John July 12 2004
|
|
// changed to editable child 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>
|
|
/// This identifies the physical parts in stock
|
|
/// </summary>
|
|
[Serializable]
|
|
public class PartByWarehouseInventory : BusinessBase//v8port: This is redundant do not port
|
|
{
|
|
|
|
|
|
#region Attributes
|
|
|
|
//private bool mActive=true;
|
|
private Guid mPartID;
|
|
private Guid mPartWarehouseID;
|
|
private decimal mQuantityOnHand=0;
|
|
private decimal mQuantityOnOrder=0;
|
|
|
|
private decimal mQtyOnOrderCommitted=0;
|
|
private decimal mMinStockLevel=0;
|
|
|
|
private bool bReadOnly;
|
|
private Guid mID;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private PartByWarehouseInventory()
|
|
{
|
|
MarkAsChild();
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
|
|
//Default warehouse
|
|
mPartWarehouseID=PartWarehouse.DefaultWarehouseID;
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties
|
|
/// <summary>
|
|
/// Get internal id number Read only property because it's set internally, not
|
|
/// externally
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get created date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get modified date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user record ID of person who created this record
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user ID of person who modified this record
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// The ID of the <see cref="PartWarehouse"/> object that contains this inventory item
|
|
/// </summary>
|
|
public Guid PartWarehouseID
|
|
{
|
|
get
|
|
{
|
|
return mPartWarehouseID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPartWarehouseID!=value)
|
|
{
|
|
mPartWarehouseID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The ID of the <see cref="Part"/> object this inventory record is tracking
|
|
/// </summary>
|
|
public Guid PartID
|
|
{
|
|
get
|
|
{
|
|
return mPartID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPartID!=value)
|
|
{
|
|
mPartID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
///// <summary>
|
|
///// if true, does show in select list; if false then is not selectable, but can
|
|
///// still bring up history etc
|
|
///// default is true
|
|
///// </summary>
|
|
//public bool Active
|
|
//{
|
|
// get
|
|
// {
|
|
// return mActive;
|
|
// }
|
|
// set
|
|
// {
|
|
// if (bReadOnly)
|
|
// ThrowSetError();
|
|
// else
|
|
// {
|
|
// if (mActive != value)
|
|
// {
|
|
// mActive = value;
|
|
// MarkDirty();
|
|
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
/// <summary>
|
|
/// Quantity in stock / on the shelf / in the boxes / in the truck / in the toolkit / in hand
|
|
/// </summary>
|
|
public decimal QuantityOnHand
|
|
{
|
|
get
|
|
{
|
|
return mQuantityOnHand;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mQuantityOnHand!=value)
|
|
{
|
|
mQuantityOnHand = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// The number of items ordered on purchase orders but not yet received
|
|
/// </summary>
|
|
public decimal QuantityOnOrder
|
|
{
|
|
get
|
|
{
|
|
return mQuantityOnOrder;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mQuantityOnOrder!=value)
|
|
{
|
|
mQuantityOnOrder = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The number of items that are on purchase orders but are already spoken for in workorder item part requests
|
|
/// </summary>
|
|
public decimal QtyOnOrderCommitted
|
|
{
|
|
get
|
|
{
|
|
return mQtyOnOrderCommitted;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mQtyOnOrderCommitted!=value)
|
|
{
|
|
mQtyOnOrderCommitted = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The desired minimum quantity to keep in stock.
|
|
/// </summary>
|
|
public decimal MinStockLevel
|
|
{
|
|
get
|
|
{
|
|
return mMinStockLevel;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mMinStockLevel!=value)
|
|
{
|
|
mMinStockLevel = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Throw an error when a read only user
|
|
/// tries to set a property
|
|
/// (this should normally never be called unless someone is using the developer api since the UI
|
|
/// should prevent it from happening initially)
|
|
/// </summary>
|
|
private void ThrowSetError()
|
|
{
|
|
throw new System.Security.SecurityException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.PartByWarehouseInventory")
|
|
)
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
#region System.Object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "PartByWarehouseInventory" + mID.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
PartByWarehouseInventory c=(PartByWarehouseInventory)obj;
|
|
return mID==c.mID;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("PartByWarehouseInventory" + mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get new object
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static PartByWarehouseInventory NewItem()
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.PartByWarehouseInventory")>(int)SecurityLevelTypes.ReadOnly)
|
|
return new PartByWarehouseInventory();
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.PartByWarehouseInventory")));
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
/// <returns></returns>
|
|
internal static PartByWarehouseInventory GetItem(SafeDataReader dr)
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.PartByWarehouseInventory")>(int)SecurityLevelTypes.NoAccess)
|
|
{
|
|
PartByWarehouseInventory child = new PartByWarehouseInventory();
|
|
child.Fetch(dr);
|
|
return child;
|
|
}
|
|
//return (PartByWarehouseInventory)DataPortal.Fetch(new Criteria(_ID,Guid.Empty,Guid.Empty));
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.PartByWarehouseInventory")));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
/// <summary>
|
|
/// Populate this object from the values in the datareader passed to it
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
|
|
|
|
|
|
//Standard fields
|
|
mID=dr.GetGuid("aID");
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModifier=dr.GetGuid("aModifier");
|
|
|
|
//PartByWarehouseInventory fields
|
|
//mActive=dr.GetBoolean("AACTIVE");
|
|
mPartID=dr.GetGuid("aPartID");
|
|
mQuantityOnHand=dr.GetDecimal("aQuantityOnHand");
|
|
mQuantityOnOrder=dr.GetDecimal("aQuantityOnOrder");
|
|
mPartWarehouseID=dr.GetGuid("aPartWarehouseID");
|
|
mQtyOnOrderCommitted=dr.GetDecimal("aQtyOnOrderCommitted");
|
|
mMinStockLevel=dr.GetDecimal("aMinStockLevel");
|
|
|
|
|
|
MarkOld();
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.PartByWarehouseInventory")<(int)SecurityLevelTypes.ReadWrite;
|
|
}
|
|
#endregion fetch
|
|
|
|
#region Update
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="tr"></param>
|
|
internal void Update(IDbTransaction tr)
|
|
{
|
|
|
|
//No need to update if there is nothing changed
|
|
if(!this.IsDirty) return;
|
|
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
if(!IsNew)
|
|
DBUtil.CheckSafeToUpdate(this.mModified.Date,this.mID,"aPartByWarehouseInventory");
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
//Delete object
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aPartByWarehouseInventory WHERE aID = @ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, tr);
|
|
|
|
}
|
|
|
|
|
|
//-----------------------------
|
|
|
|
MarkNew();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Add / Update
|
|
|
|
//get modification time temporarily, if update succeeds then
|
|
//set to this time
|
|
System.DateTime dtModified = DBUtil.CurrentWorkingDateTime;
|
|
|
|
DBCommandWrapper cm = null;
|
|
if(IsNew)//Add or update?
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO aPartByWarehouseInventory ( " +
|
|
"aID, aPartID, aPartWarehouseID, aQuantityOnHand, aQuantityOnOrder, " +
|
|
"aQtyOnOrderCommitted, aMinStockLevel, " +
|
|
"aCreated,aModified,aCreator,aModifier) VALUES " +
|
|
"(@ID,@PartID,@PartWarehouseID,@QuantityOnHand,@QuantityOnOrder, " +
|
|
"@QtyOnOrderCommitted, @MinStockLevel, " +
|
|
"@Created,@Modified,@CurrentUserID,@CurrentUserID)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aPartByWarehouseInventory SET aID=@ID, " +
|
|
"aPartID=@PartID, aPartWarehouseID=@PartWarehouseID, " +
|
|
"aQuantityOnHand=@QuantityOnHand, " +
|
|
"aQuantityOnOrder=@QuantityOnOrder, " +
|
|
"aQtyOnOrderCommitted=@QtyOnOrderCommitted, " +
|
|
"aMinStockLevel=@MinStockLevel, " +
|
|
"aModifier=@CurrentUserID, aModified=@Modified " +
|
|
"WHERE aID=@ID"
|
|
);
|
|
|
|
|
|
cm.AddInParameter("@ID",DbType.Guid,mID);
|
|
//cm.AddInParameter("@Active",DbType.Boolean, mActive);
|
|
cm.AddInParameter("@PartID",DbType.Guid,mPartID);
|
|
cm.AddInParameter("@QuantityOnHand",DbType.Decimal, mQuantityOnHand);
|
|
cm.AddInParameter("@QuantityOnOrder",DbType.Decimal,mQuantityOnOrder);
|
|
cm.AddInParameter("@PartWarehouseID",DbType.Guid,mPartWarehouseID);
|
|
cm.AddInParameter("@QtyOnOrderCommitted",DbType.Decimal,this.mQtyOnOrderCommitted);
|
|
cm.AddInParameter("@MinStockLevel",DbType.Decimal,mMinStockLevel);
|
|
|
|
//Standard fields
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
|
|
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue);
|
|
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, tr);
|
|
MarkOld();//db is now synched with object
|
|
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
#endregion update
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}//end PartByWarehouseInventory
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |