/////////////////////////////////////////////////////////// // 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 { /// /// 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 /// [Serializable] public class WorkorderInternalIDFetcher : ReadOnlyBase { #region Attributes private Guid mWorkorderID; #endregion #region Constructor /// /// Private constructor to prevent direct instantiation /// private WorkorderInternalIDFetcher() { } #endregion #region Static methods /// /// Get internal Guid ID value of workorder from string /// representation of workorder or quote or pm number /// /// Service number, Quote number or Preventive maintenance number /// Type of workorder (service, quote, pm) /// Guid of workorder in database or Guid.Empty if not found or input string invalid 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 /// /// 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 /// /// Criteria for identifying existing object /// [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