232 lines
7.3 KiB
C#
232 lines
7.3 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Bool.cs
|
|
// Implementation of Class UnitNameFetcher
|
|
// CSLA type: Read-only object
|
|
// Created on: 20-Oct-2005
|
|
// Object design: John
|
|
// Coded: John 20-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 single saved Unit's name
|
|
/// from the database in the currently selected UnitNameFormat style
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UnitNameFetcher : ReadOnlyBase
|
|
{
|
|
|
|
#region Attributes
|
|
private string mFormattedUnitName;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private UnitNameFetcher()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties
|
|
|
|
|
|
/// <summary>
|
|
/// Unit name formatted according to global setting for unit name format
|
|
/// </summary>
|
|
public string FormattedUnitName
|
|
{
|
|
get
|
|
{
|
|
return mFormattedUnitName;
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.Object overrides
|
|
/// <summary>
|
|
/// Returns formatted unit name
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return mFormattedUnitName;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// Fetches and formats a unit name
|
|
/// </summary>
|
|
/// <param name="UnitID">Guid value of existing unit in database</param>
|
|
/// <returns>Unit name formatted to current global UnitNameFormat setting</returns>
|
|
public static string GetUnitNameFromUnitID(Guid UnitID)
|
|
{
|
|
return ((UnitNameFetcher)DataPortal.Fetch(new Criteria( UnitID, Guid.Empty, Guid.Empty))).FormattedUnitName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetches and formats a workorder item's unit name
|
|
/// </summary>
|
|
/// <param name="WorkorderItemID">Guid value of existing WorkorderItem record in database</param>
|
|
/// <returns>Unit name formatted to current global UnitNameFormat setting, empty if no unit on workorderitem</returns>
|
|
public static string GetUnitNameFromWorkorderItemID(Guid WorkorderItemID)
|
|
{
|
|
return ((UnitNameFetcher)DataPortal.Fetch(new Criteria( Guid.Empty,WorkorderItemID,Guid.Empty))).FormattedUnitName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetches and formats a workorder item outside service's unit name
|
|
/// </summary>
|
|
/// <param name="WorkorderItemOutsideServiceID">Guid value of existing WorkorderItemOutsideService record in database</param>
|
|
/// <returns>Unit name formatted to current global UnitNameFormat setting, empty if no unit on workorderitem</returns>
|
|
public static string GetUnitNameFromWorkorderItemOutsideServiceID(Guid WorkorderItemOutsideServiceID)
|
|
{
|
|
return ((UnitNameFetcher)DataPortal.Fetch(new Criteria( Guid.Empty,Guid.Empty,WorkorderItemOutsideServiceID))).FormattedUnitName;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param Bool="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
|
|
|
|
if(crit.UnitID!=Guid.Empty)
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aUnit.aSerial, AUNIT.ADESCRIPTION , aUnitModel.aName " +
|
|
"AS aModelName, aUnitModel.aModelNumber, aVendor.aName AS aVendorName " +
|
|
"FROM " +
|
|
" AUNIT " +
|
|
" LEFT OUTER JOIN AUNITMODEL ON (AUNIT.AUNITMODELID=AUNITMODEL.AID) " +
|
|
" LEFT OUTER JOIN AVENDOR ON (AUNITMODEL.AVENDORID=AVENDOR.AID) " +
|
|
"WHERE aUnit.aID=@ID", crit.UnitID
|
|
//************************************************************
|
|
);
|
|
}
|
|
else if(crit.WorkorderItemID!=Guid.Empty)
|
|
{//fetch by workorder item
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aUnit.aSerial, AUNIT.ADESCRIPTION , aUnitModel.aName AS aModelName, aUnitModel.aModelNumber, " +
|
|
" aVendor.aName AS aVendorName " +
|
|
"FROM " +
|
|
" AUNIT " +
|
|
" LEFT OUTER JOIN AUNITMODEL ON (AUNIT.AUNITMODELID=AUNITMODEL.AID) " +
|
|
" LEFT OUTER JOIN AVENDOR ON (AUNITMODEL.AVENDORID=AVENDOR.AID) " +
|
|
" INNER JOIN AWORKORDERITEM ON (AUNIT.AID=AWORKORDERITEM.AUNITID) " +
|
|
"WHERE (aWorkorderItem.aID " +
|
|
"= @ID)", crit.WorkorderItemID
|
|
//************************************************************
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//fetch by workorder item outside service ID number
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aUnit.aSerial, AUNIT.ADESCRIPTION , aUnitModel.aName AS aModelName, aUnitModel.aModelNumber, " +
|
|
" aVendor.aName AS aVendorName " +
|
|
//"FROM aWorkorderItemOutsideService " +
|
|
|
|
"FROM " +
|
|
" AUNIT " +
|
|
" LEFT OUTER JOIN AUNITMODEL ON (AUNIT.AUNITMODELID=AUNITMODEL.AID) " +
|
|
" LEFT OUTER JOIN AVENDOR ON (AUNITMODEL.AVENDORID=AVENDOR.AID) " +
|
|
" INNER JOIN AWORKORDERITEM ON (AUNIT.AID=AWORKORDERITEM.AUNITID) " +
|
|
" INNER JOIN AWORKORDERITEMOUTSIDESERVICE ON (AWORKORDERITEM.AID=AWORKORDERITEMOUTSIDESERVICE.AWORKORDERITEMID) " +
|
|
|
|
"WHERE (aWorkorderItemOutsideService.aID " +
|
|
"= @ID)", crit.WorkorderItemOutsideServiceID
|
|
//************************************************************
|
|
);
|
|
}
|
|
|
|
if (dr.Read())
|
|
{
|
|
this.mFormattedUnitName = Unit.UnitNameFormatter(dr.GetString("aModelNumber"), dr.GetString("aModelName"), dr.GetString("aVendorName"),
|
|
dr.GetString("aSerial"), dr.GetString("ADESCRIPTION"));
|
|
|
|
}
|
|
else
|
|
//changed: 09-June-2006 shouldn't throw an exception here because it's
|
|
//legal in some cases to have no unit when this is called
|
|
//so indicate so
|
|
this.mFormattedUnitName = " ";
|
|
//throw new ApplicationException("Unit not found");
|
|
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
throw new System.ArgumentException(
|
|
string.Format(LocalizedTextTable.GetLocalizedTextDirect("Error.DB.FetchError"),
|
|
crit.UnitID.ToString()) +
|
|
"\r\n(" + ex.Message + ")");
|
|
}
|
|
finally
|
|
{
|
|
//Changed: 09-June-2006 this was missing!
|
|
if (dr != null) dr.Close();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
public Guid UnitID;
|
|
public Guid WorkorderItemID;
|
|
public Guid WorkorderItemOutsideServiceID;
|
|
|
|
public Criteria(Guid _UnitID, Guid _WorkorderItemID, Guid _WorkorderItemOutsideServiceID)
|
|
{
|
|
UnitID=_UnitID;
|
|
WorkorderItemID=_WorkorderItemID;
|
|
WorkorderItemOutsideServiceID=_WorkorderItemOutsideServiceID;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end Bool
|
|
|
|
}//end Boolspace GZTW.AyaNova.BLL |