This commit is contained in:
166
source/bizobjects/AyaLib/GuidFetcher.cs
Normal file
166
source/bizobjects/AyaLib/GuidFetcher.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
///////////////////////////////////////////////////////////
|
||||
// Bool.cs
|
||||
// Implementation of Class GuidFetcher
|
||||
// CSLA type: Read-only object
|
||||
// Created on: 20-May-2010
|
||||
// Object design: John
|
||||
// Coded: John 20-May-2010
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
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 Guid record from the db
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class GuidFetcher : ReadOnlyBase
|
||||
{
|
||||
#pragma warning disable 1591
|
||||
#region Attributes
|
||||
private Guid mGuidValue;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Private constructor to prevent direct instantiation
|
||||
/// </summary>
|
||||
private GuidFetcher()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Business properties
|
||||
|
||||
|
||||
|
||||
public Guid GuidValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return mGuidValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region System.Object overrides
|
||||
public override string ToString()
|
||||
{
|
||||
return mGuidValue.ToString();
|
||||
}
|
||||
|
||||
///
|
||||
/// <param Bool="obj"></param>
|
||||
public override bool Equals(Object obj)
|
||||
{
|
||||
if (obj == null || GetType() != obj.GetType()) return false;
|
||||
GuidFetcher c = (GuidFetcher)obj;
|
||||
return mGuidValue == c.mGuidValue;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ("Guid" + mGuidValue.ToString()).GetHashCode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
|
||||
/// <summary>
|
||||
/// Fetch Guid based on unique text value
|
||||
/// e.g. a Client's Name or a Unit's unique Serial number
|
||||
/// (Table's ID column is assumed to be AID when calling this method)
|
||||
/// </summary>
|
||||
/// <param name="Table"></param>
|
||||
/// <param name="UniqueTextFieldName"></param>
|
||||
/// <param name="sUniqueTextValue"></param>
|
||||
/// <returns></returns>
|
||||
public static Guid GetItem(string Table, string UniqueTextFieldName, string sUniqueTextValue)
|
||||
{
|
||||
|
||||
return ((GuidFetcher)DataPortal.Fetch(new Criteria(Table, UniqueTextFieldName, sUniqueTextValue))).GuidValue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region DAL DATA ACCESS
|
||||
|
||||
protected override void DataPortal_Fetch(object Criteria)
|
||||
{
|
||||
Criteria crit = (Criteria)Criteria;
|
||||
try
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(crit.UniqueTextValue))
|
||||
{
|
||||
mGuidValue = Guid.Empty;
|
||||
return;
|
||||
}
|
||||
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
||||
"SELECT aID FROM " + AyaBizUtils.ToDBName(crit.Table) + " WHERE " +
|
||||
"(" + AyaBizUtils.ToDBName(crit.FieldName) + " = @ANAME)"
|
||||
);
|
||||
dbCommandWrapper.AddInParameter("@ANAME", DbType.String, crit.UniqueTextValue);
|
||||
mGuidValue = DBUtil.ToGuid(DBUtil.DB.ExecuteScalar(dbCommandWrapper));
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw new System.ArgumentException(
|
||||
string.Format(LocalizedTextTable.GetLocalizedTextDirect("Error.Object.NameFetcherNotFound")/*Name/bool Fetcher: Field {0} in table {1} with record ID {2} not found!*/,
|
||||
crit.FieldName, crit.Table, crit.UniqueTextValue) +
|
||||
"\r\n(" + ex.Message + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region criteria
|
||||
/// <summary>
|
||||
/// Criteria for identifying existing object
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
private class Criteria
|
||||
{
|
||||
|
||||
public string Table;
|
||||
public string FieldName;
|
||||
public string UniqueTextValue;
|
||||
|
||||
public Criteria(string _Table, string _FieldName, string _UniqueTextValue)
|
||||
{
|
||||
if (_Table == "User")
|
||||
_Table = "aUser";
|
||||
Table = _Table;
|
||||
FieldName = _FieldName;
|
||||
UniqueTextValue = _UniqueTextValue;
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
#pragma warning restore 1591
|
||||
}//end Bool
|
||||
|
||||
}//end Boolspace GZTW.AyaNova.BLL
|
||||
Reference in New Issue
Block a user