/////////////////////////////////////////////////////////// // 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 { /// /// This identifies the physical parts in stock /// [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 /// /// Private constructor to prevent direct instantiation /// 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 /// /// Get internal id number Read only property because it's set internally, not /// externally /// public Guid ID { get { return mID; } } /// /// Get created date /// /// /// public string Created { get { return mCreated.ToString(); } } /// /// Get modified date /// /// /// public string Modified { get { return mModified.ToString(); } } /// /// Get user record ID of person who created this record /// public Guid Creator { get { return mCreator; } } /// /// Get user ID of person who modified this record /// public Guid Modifier { get { return mModifier; } } /// /// The ID of the object that contains this inventory item /// public Guid PartWarehouseID { get { return mPartWarehouseID; } set { if(bReadOnly) ThrowSetError(); else { if(mPartWarehouseID!=value) { mPartWarehouseID = value; MarkDirty(); } } } } /// /// The ID of the object this inventory record is tracking /// public Guid PartID { get { return mPartID; } set { if(bReadOnly) ThrowSetError(); else { if(mPartID!=value) { mPartID = value; MarkDirty(); } } } } ///// ///// if true, does show in select list; if false then is not selectable, but can ///// still bring up history etc ///// default is true ///// //public bool Active //{ // get // { // return mActive; // } // set // { // if (bReadOnly) // ThrowSetError(); // else // { // if (mActive != value) // { // mActive = value; // MarkDirty(); // } // } // } //} /// /// Quantity in stock / on the shelf / in the boxes / in the truck / in the toolkit / in hand /// public decimal QuantityOnHand { get { return mQuantityOnHand; } set { if(bReadOnly) ThrowSetError(); else { if(mQuantityOnHand!=value) { mQuantityOnHand = value; MarkDirty(); } } } } /// /// The number of items ordered on purchase orders but not yet received /// public decimal QuantityOnOrder { get { return mQuantityOnOrder; } set { if(bReadOnly) ThrowSetError(); else { if(mQuantityOnOrder!=value) { mQuantityOnOrder = value; MarkDirty(); } } } } /// /// The number of items that are on purchase orders but are already spoken for in workorder item part requests /// public decimal QtyOnOrderCommitted { get { return mQtyOnOrderCommitted; } set { if(bReadOnly) ThrowSetError(); else { if(mQtyOnOrderCommitted!=value) { mQtyOnOrderCommitted = value; MarkDirty(); } } } } /// /// The desired minimum quantity to keep in stock. /// public decimal MinStockLevel { get { return mMinStockLevel; } set { if(bReadOnly) ThrowSetError(); else { if(mMinStockLevel!=value) { mMinStockLevel = value; MarkDirty(); } } } } /// /// 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) /// private void ThrowSetError() { throw new System.Security.SecurityException ( string.Format ( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"), LocalizedTextTable.GetLocalizedTextDirect("O.PartByWarehouseInventory") ) ); } #endregion #region System.Object overrides /// /// /// /// public override string ToString() { return "PartByWarehouseInventory" + mID.ToString(); } /// /// /// /// /// public override bool Equals(Object obj) { if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; PartByWarehouseInventory c=(PartByWarehouseInventory)obj; return mID==c.mID; } /// /// /// /// public override int GetHashCode() { return ("PartByWarehouseInventory" + mID).GetHashCode(); } #endregion #region Static methods /// /// Get new object /// /// 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"))); } /// /// /// /// /// 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 /// /// Populate this object from the values in the datareader passed to it /// /// 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 /// /// /// /// 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