161 lines
3.5 KiB
C#
161 lines
3.5 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Bool.cs
|
|
// Implementation of Class BoolFetcher
|
|
// CSLA type: Read-only object
|
|
// Created on: 06-Dec-2004
|
|
// Object design: John
|
|
// Coded: John Aug 4 2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
/// <summary>
|
|
/// Used to quickly fetch a single Bool record from the db
|
|
/// </summary>
|
|
[Serializable]
|
|
public class BoolFetcher : ReadOnlyBase
|
|
{
|
|
|
|
#region Attributes
|
|
private bool mBoolValue;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private BoolFetcher()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties
|
|
|
|
|
|
|
|
public bool BoolValue
|
|
{
|
|
get
|
|
{
|
|
return mBoolValue;
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.Object overrides
|
|
public override string ToString()
|
|
{
|
|
return mBoolValue.ToString();
|
|
}
|
|
|
|
///
|
|
/// <param Bool="obj"></param>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
BoolFetcher c=(BoolFetcher)obj;
|
|
return mBoolValue==c.mBoolValue;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return ("Bool" + mBoolValue.ToString()).GetHashCode();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param Bool="Table"></param>
|
|
/// <param Bool="FieldBool"></param>
|
|
/// <param Bool="RecordID"></param>
|
|
/// <returns></returns>
|
|
public static BoolFetcher GetItem(string Table, string FieldName, Guid RecordID)
|
|
{
|
|
|
|
return (BoolFetcher)DataPortal.Fetch(new Criteria( Table, FieldName, RecordID));
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param Bool="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
try
|
|
{
|
|
//FireBird will return an int16 0 or 1 value
|
|
//mssql will return a bool value
|
|
//because this isn't using the datareader which converts automatically
|
|
//but it's still faster to check here and use executescalar than
|
|
//to convert this to use a data reader
|
|
object o=DBUtil.GetScalarFromSQLString("SELECT " + AyaBizUtils.ToDBName(crit.FieldName) + " FROM "+ AyaBizUtils.ToDBName(crit.Table) +" WHERE aID=@ID",crit.RecordID);
|
|
mBoolValue=System.Convert.ToBoolean(o);
|
|
|
|
|
|
}
|
|
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.RecordID.ToString()) +
|
|
"\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 Guid RecordID;
|
|
|
|
public Criteria(string _Table, string _FieldName, Guid _RecordID)
|
|
{
|
|
if(_Table=="User")
|
|
_Table="aUser";
|
|
Table=_Table;
|
|
FieldName=_FieldName;
|
|
RecordID=_RecordID;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end Bool
|
|
#pragma warning restore 1591
|
|
}//end Boolspace GZTW.AyaNova.BLL |