179 lines
4.1 KiB
C#
179 lines
4.1 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Bool.cs
|
|
// Implementation of Class WorkorderInternalIDFetcher
|
|
// CSLA type: Read-only object
|
|
// Created on: 04-Feb-2006
|
|
// Object design: John
|
|
// Coded: John 04-Feb-2006
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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 get the internal ID number of a workorder
|
|
/// based on it's service number, quote number or
|
|
/// preventive maintenance number.
|
|
///
|
|
/// Also useful for checking for the existance of a workorder
|
|
/// </summary>
|
|
[Serializable]
|
|
public class WorkorderInternalIDFetcher : ReadOnlyBase
|
|
{
|
|
|
|
#region Attributes
|
|
private Guid mWorkorderID;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private WorkorderInternalIDFetcher()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get internal Guid ID value of workorder from string
|
|
/// representation of workorder or quote or pm number
|
|
/// </summary>
|
|
/// <param name="WorkorderNumber">Service number, Quote number or Preventive maintenance number</param>
|
|
/// <param name="Type">Type of workorder (service, quote, pm)</param>
|
|
/// <returns>Guid of workorder in database or Guid.Empty if not found or input string invalid</returns>
|
|
public static Guid GetItem(string WorkorderNumber,WorkorderTypes Type)
|
|
{
|
|
if(WorkorderNumber==null || WorkorderNumber=="") return Guid.Empty;
|
|
int nWO=0;
|
|
Guid gWO=Guid.Empty;
|
|
//TODO: .net 2.0 replace this with a try parse method
|
|
try
|
|
{
|
|
nWO=int.Parse(WorkorderNumber);
|
|
}
|
|
catch
|
|
{
|
|
nWO=0;
|
|
}
|
|
|
|
if(nWO!=0)
|
|
return ((WorkorderInternalIDFetcher)DataPortal.Fetch(new Criteria( nWO, Type))).mWorkorderID;
|
|
else
|
|
return Guid.Empty;
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param Bool="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
DBCommandWrapper cm = null;
|
|
try
|
|
{
|
|
|
|
|
|
switch(crit.Type)
|
|
{
|
|
case WorkorderTypes.PreventiveMaintenance:
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"SELECT " +
|
|
"AWORKORDERPREVENTIVEMAINTENANCE.AWORKORDERID " +
|
|
"FROM " +
|
|
"AWORKORDERPREVENTIVEMAINTENANCE " +
|
|
"WHERE " +
|
|
"(AWORKORDERPREVENTIVEMAINTENANCE.APREVENTIVEMAINTENANCENUMBER = @AVISIBLEID) " );
|
|
break;
|
|
|
|
case WorkorderTypes.Quote:
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"SELECT " +
|
|
"AWORKORDERQUOTE.AWORKORDERID " +
|
|
"FROM " +
|
|
"AWORKORDERQUOTE " +
|
|
"WHERE " +
|
|
"(AWORKORDERQUOTE.AQUOTENUMBER = @AVISIBLEID) " );
|
|
break;
|
|
|
|
case WorkorderTypes.Service:
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"SELECT " +
|
|
"AWORKORDERSERVICE.AWORKORDERID " +
|
|
"FROM " +
|
|
"AWORKORDERSERVICE " +
|
|
"WHERE " +
|
|
"(AWORKORDERSERVICE.ASERVICENUMBER = @AVISIBLEID) " );
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
cm.AddInParameter("@AVISIBLEID",DbType.Int32,crit.WorkorderNumber);
|
|
dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
|
|
|
if(dr.Read())
|
|
mWorkorderID=dr.GetGuid("AWORKORDERID");
|
|
else
|
|
mWorkorderID=Guid.Empty;
|
|
|
|
|
|
|
|
}
|
|
catch
|
|
{
|
|
this.mWorkorderID=Guid.Empty;
|
|
}
|
|
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 int WorkorderNumber;
|
|
public WorkorderTypes Type;
|
|
|
|
public Criteria(int _WorkorderNumber,WorkorderTypes _Type)
|
|
{
|
|
WorkorderNumber=_WorkorderNumber;
|
|
Type=_Type;
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end Bool
|
|
|
|
}//end Boolspace GZTW.AyaNova.BLL |