212 lines
5.2 KiB
C#
212 lines
5.2 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Bool.cs
|
|
// Implementation of Class LocalizedTextFetcher
|
|
// CSLA type: Read-only object
|
|
// Created on: 29-Aug-2005
|
|
// Object design: John
|
|
// Coded: 29-Aug-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.Collections;
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Used internally by LocalizedTextTable for static get text direct method
|
|
/// this ensures dataportal friendliness
|
|
/// </summary>
|
|
[Serializable,EditorBrowsable(EditorBrowsableState.Never)]
|
|
public class LocalizedTextFetcher : ReadOnlyBase
|
|
{
|
|
// Create a logger for use in this class
|
|
//private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
#region Attributes
|
|
private string mText="";
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private LocalizedTextFetcher()
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string Text
|
|
{
|
|
get
|
|
{
|
|
return mText;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#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;
|
|
// LocalizedTextFetcher c=(LocalizedTextFetcher)obj;
|
|
// return mBoolValue==c.mBoolValue;
|
|
// }
|
|
//
|
|
// public override int GetHashCode()
|
|
// {
|
|
// return ("Bool" + mBoolValue.ToString()).GetHashCode();
|
|
// }
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// Load the localized text string for the Key provided
|
|
/// </summary>
|
|
/// <param name="Key">Localized text key i.e. "Address.Label.City"</param>
|
|
/// <returns></returns>
|
|
public static LocalizedTextFetcher GetItem(string Key)
|
|
{
|
|
////case 1039 //log.Debug("LocalizedTextFetcher.GetItem(" + Key + ")");
|
|
if (Key == "UI.Label.CurrentUserName")
|
|
{
|
|
LocalizedTextFetcher ltf = new LocalizedTextFetcher();
|
|
ltf.mText = System.Threading.Thread.CurrentPrincipal.Identity.Name;
|
|
return ltf;
|
|
}
|
|
return (LocalizedTextFetcher)DataPortal.Fetch(new Criteria( Key, ""));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load the localized text string for the Key provided
|
|
/// from the Locale provided
|
|
/// </summary>
|
|
/// <param name="Key">Localized text key i.e. "Address.Label.City"</param>
|
|
/// <param name="Locale">Locale key, i.e. "English"</param>
|
|
/// <returns></returns>
|
|
public static LocalizedTextFetcher GetItemForSpecificLocale(string Key, string Locale)
|
|
{
|
|
////case 1039 //log.Debug("LocalizedTextFetcher.GetItem(" + Key + ")");
|
|
if (Key == "UI.Label.CurrentUserName")
|
|
{
|
|
LocalizedTextFetcher ltf = new LocalizedTextFetcher();
|
|
ltf.mText=System.Threading.Thread.CurrentPrincipal.Identity.Name;
|
|
return ltf;
|
|
}
|
|
return (LocalizedTextFetcher)DataPortal.Fetch(new Criteria( Key, Locale));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param Bool="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
|
|
//default's to passed in key if there is nothing found
|
|
mText=crit.Key;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
|
|
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
"SELECT aDisplayText, aDisplayTextCustom FROM aLocalizedText " +
|
|
"WHERE (aKey = @Key) " +
|
|
"AND (aLocale = @Locale)"
|
|
);
|
|
if(crit.Locale=="")
|
|
dbCommandWrapper.AddInParameter("@Locale",DbType.String,User.CurrentUserLanguage);
|
|
else
|
|
dbCommandWrapper.AddInParameter("@Locale",DbType.String,crit.Locale);
|
|
|
|
dbCommandWrapper.AddInParameter("@Key",DbType.String,crit.Key);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
|
|
if(dr.Read())
|
|
{
|
|
//*******************************************
|
|
//If there is no custom text then add the stock text
|
|
if(dr.GetString("aDisplayTextCustom").Length<1)
|
|
mText = dr.GetString("aDisplayText");
|
|
else//It's custom, add the custom text instead
|
|
mText = dr.GetString("aDisplayTextCustom");
|
|
|
|
|
|
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
public string Key;
|
|
public string Locale;
|
|
|
|
|
|
public Criteria(string _Key, string _Locale)
|
|
{
|
|
Locale=_Locale;
|
|
Key=_Key;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end Class
|
|
|
|
}//end Namespace |