172 lines
5.6 KiB
C#
172 lines
5.6 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Bool.cs
|
|
// Implementation of Class PartByWarehouseInventoryManager
|
|
// 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 internally to manage the warehouses in the database
|
|
/// and keep the quantity of empty records to a minimum saving db space
|
|
///
|
|
/// Creates a fresh record if none exists
|
|
/// </summary>
|
|
[Serializable]
|
|
internal class PartByWarehouseInventoryManager : ReadOnlyBase
|
|
{
|
|
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private PartByWarehouseInventoryManager()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Static methods
|
|
|
|
/// <summary>
|
|
/// Creates a new record if none exists
|
|
/// </summary>
|
|
/// <param name="PartID">ID of part</param>
|
|
/// <param name="PartWarehouseID">ID of warehouse</param>
|
|
/// <returns>nothing</returns>
|
|
public static void EnsureItem(Guid PartID, Guid PartWarehouseID)
|
|
{
|
|
//case 3175 - do nothing if there are no valid parameters
|
|
if (PartID == Guid.Empty || PartWarehouseID == Guid.Empty)
|
|
return;
|
|
|
|
DataPortal.Fetch(new Criteria(PartID, PartWarehouseID, null));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new record if none exists 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 void EnsureItem(Guid PartID, Guid PartWarehouseID, IDbTransaction tr)
|
|
{
|
|
//case 3175 - do nothing if there are no valid parameters
|
|
if (PartID == Guid.Empty || PartWarehouseID == Guid.Empty)
|
|
return;
|
|
|
|
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;
|
|
DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
"SELECT AID 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())
|
|
{
|
|
//create one because it doesn't exist
|
|
dr.Close();
|
|
|
|
DBCommandWrapper cmInvent = DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO aPartByWarehouseInventory ( " +
|
|
"aID, aPartID, aPartWarehouseID, " +
|
|
"aQuantityOnHand, aQuantityOnOrder, " +
|
|
"aQtyOnOrderCommitted, aMinStockLevel, " +
|
|
"aCreated,aModified,aCreator,aModifier) VALUES " +
|
|
"(@ID,@PartID,@PartWarehouseID, " +
|
|
"0,0,0,0, " +
|
|
"@Created,@Modified,@CurrentUserID,@CurrentUserID)"
|
|
);
|
|
|
|
|
|
|
|
cmInvent.Command.Parameters.Clear();
|
|
cmInvent.AddInParameter("@ID", DbType.Guid, Guid.NewGuid());
|
|
cmInvent.AddInParameter("@PartID", DbType.Guid, crit.PartID);
|
|
cmInvent.AddInParameter("@PartWarehouseID", DbType.Guid, crit.PartWarehouseID);
|
|
|
|
|
|
//Standard fields
|
|
cmInvent.AddInParameter("@CurrentUserID", DbType.Guid, User.CurrentThreadUserID);
|
|
cmInvent.AddInParameter("@Created", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime));
|
|
cmInvent.AddInParameter("@Modified", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime));
|
|
|
|
if (crit.tr != null)
|
|
DBUtil.DB.ExecuteNonQuery(cmInvent, crit.tr);
|
|
else
|
|
DBUtil.DB.ExecuteNonQuery(cmInvent);
|
|
|
|
|
|
|
|
|
|
}
|
|
else
|
|
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 |