268 lines
8.0 KiB
C#
268 lines
8.0 KiB
C#
///////////////////////////////////////////////////////////
|
|
// PartSerialPickList.cs
|
|
// Implementation of Class PartSerialPickList
|
|
// CSLA type: Read only collection
|
|
// Created on: 28-Dec-2004
|
|
// Object design: John
|
|
// Coded: 28-Dec-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Lightweight read only list of <see cref="PartSerialPickList.PartSerialPickListInfo"/> objects
|
|
/// </summary>
|
|
[Serializable]
|
|
public class PartSerialPickList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct PartSerialPickListInfo
|
|
{
|
|
|
|
internal Guid mID;
|
|
internal string mSerialNumber;
|
|
|
|
|
|
|
|
|
|
//Public properties
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Guid ID {get{return mID;}}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string SerialNumber {get{return mSerialNumber;}}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(PartSerialPickListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end PartSerialPickListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected PartSerialPickList()
|
|
{
|
|
// AllowSort=false;
|
|
// AllowFind=true;
|
|
// AllowEdit=false;
|
|
// AllowNew=false;
|
|
// AllowRemove=false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
/// <summary>
|
|
/// Get item by index
|
|
/// </summary>
|
|
/// <param name="Item"></param>
|
|
public PartSerialPickListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (PartSerialPickListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns PartSerialPickListInfo item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public PartSerialPickListInfo this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (PartSerialPickListInfo child in List)
|
|
{
|
|
if(child.mID==ItemID) return child;
|
|
}
|
|
throw new ArgumentException("PartSerialPickList: ID not found:\r\n"+ItemID.ToString());
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(PartSerialPickListInfo obj)
|
|
{
|
|
foreach (PartSerialPickListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// Get all serial numbers for part and optionally for parts in warehouse selected
|
|
/// </summary>
|
|
/// <param name="PartID">Part ID</param>
|
|
/// <param name="PartWarehouseID">Warehouse ID or Guid empty for any warehouse</param>
|
|
/// <returns>list of <see cref="PartSerialPickList.PartSerialPickListInfo"/> objects</returns>
|
|
public static PartSerialPickList GetList(Guid PartID, Guid PartWarehouseID)
|
|
{
|
|
return (PartSerialPickList) DataPortal.Fetch(new Criteria(PartID, PartWarehouseID,Guid.Empty));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all serial numbers selected on workorder
|
|
/// </summary>
|
|
/// <param name="WorkorderID"></param>
|
|
/// <returns>list of <see cref="PartSerialPickList.PartSerialPickListInfo"/> objects</returns>
|
|
public static PartSerialPickList GetListForWorkOrder(Guid WorkorderID)
|
|
{
|
|
return (PartSerialPickList)DataPortal.Fetch(new Criteria(Guid.Empty,Guid.Empty,WorkorderID));
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
if (crit.WorkOrderID != Guid.Empty)
|
|
{
|
|
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
//************************************************************
|
|
"SELECT " +
|
|
" APARTSERIAL.ASERIALNUMBER, " +
|
|
" APARTSERIAL.AID " +
|
|
"FROM " +
|
|
" AWORKORDERITEMPART " +
|
|
" INNER JOIN AWORKORDERITEM ON (AWORKORDERITEMPART.AWORKORDERITEMID = AWORKORDERITEM.AID) " +
|
|
" INNER JOIN APARTSERIAL ON (AWORKORDERITEMPART.APARTSERIALID = APARTSERIAL.AID) " +
|
|
" WHERE AWORKORDERITEM.AWORKORDERID = @WorkOrderID "
|
|
//************************************************************
|
|
);
|
|
dbCommandWrapper.AddInParameter("@WorkOrderID", DbType.Guid, crit.WorkOrderID);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
}
|
|
else
|
|
{
|
|
if (crit.PartWarehouseID != Guid.Empty)
|
|
{
|
|
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
//************************************************************
|
|
"SELECT aID, aSerialNumber FROM aPartSerial " +
|
|
"WHERE (aPartID = @PartID) AND " +
|
|
"(aPartWarehouseID = @PartWarehouseID) " +
|
|
"AND (AAVAILABLE=@aTrue) " +
|
|
"ORDER BY ASERIALNUMBER " //case 1975
|
|
//************************************************************
|
|
);
|
|
dbCommandWrapper.AddInParameter("@aTrue", DbType.Boolean, true);
|
|
dbCommandWrapper.AddInParameter("@PartID", DbType.Guid, crit.PartID);
|
|
dbCommandWrapper.AddInParameter("@PartWarehouseID", DbType.Guid, crit.PartWarehouseID);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
//************************************************************
|
|
"SELECT aID, aSerialNumber FROM aPartSerial " +
|
|
"WHERE (aPartID = @PartID) " +
|
|
"AND (AAVAILABLE=@aTrue)"
|
|
//************************************************************
|
|
);
|
|
dbCommandWrapper.AddInParameter("@aTrue", DbType.Boolean, true);
|
|
dbCommandWrapper.AddInParameter("@PartID", DbType.Guid, crit.PartID);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
PartSerialPickListInfo info=new PartSerialPickListInfo();
|
|
info.mID=dr.GetGuid("aID");
|
|
info.mSerialNumber=dr.GetString("aSerialNumber");
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public Guid PartID;
|
|
public Guid PartWarehouseID;
|
|
public Guid WorkOrderID;
|
|
public Criteria(Guid _PartID, Guid _PartWarehouseID, Guid _WorkOrderID)
|
|
{
|
|
PartID=_PartID;
|
|
PartWarehouseID=_PartWarehouseID;
|
|
WorkOrderID = _WorkOrderID;
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end PartSerialPickList
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |