/////////////////////////////////////////////////////////// // 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 { /// /// Used internally by LocalizedTextTable for static get text direct method /// this ensures dataportal friendliness /// [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 /// /// Private constructor to prevent direct instantiation /// private LocalizedTextFetcher() { } #endregion #region Business properties /// /// /// public string Text { get { return mText; } } #endregion #region System.Object overrides // public override string ToString() // { // return mBoolValue.ToString(); // } // // /// // /// // 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 /// /// Load the localized text string for the Key provided /// /// Localized text key i.e. "Address.Label.City" /// 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, "")); } /// /// Load the localized text string for the Key provided /// from the Locale provided /// /// Localized text key i.e. "Address.Label.City" /// Locale key, i.e. "English" /// 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 /// /// 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 /// /// Criteria for identifying existing object /// [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