946 lines
24 KiB
C#
946 lines
24 KiB
C#
///////////////////////////////////////////////////////////
|
|
// LocalizedText.cs
|
|
// Implementation of Class LocalizedText
|
|
// CSLA type: Switchable
|
|
// Created on: 07-Jun-2004 8:41:26 AM
|
|
// Object design: Joyce
|
|
// Coded: John
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
using GZTW.Data;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.Collections;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Most user interface element text displayed to the user will be held here.
|
|
/// This is the editable root object used to modify a particular localized text entry
|
|
/// This is for editing not read only display in a user interface, for that see <see cref="LocalizedTextTable"/> instead.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class LocalizedText : BusinessBase
|
|
{
|
|
|
|
|
|
#region Attributes
|
|
bool bReadOnly;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
|
|
/// <summary>
|
|
/// i.e English, French, Spanish, German
|
|
/// </summary>
|
|
private string mLocale=null;
|
|
/// <summary>
|
|
/// i.e "wo.category"
|
|
/// </summary>
|
|
private string mKey=null;
|
|
/// <summary>
|
|
/// i.e "Category"
|
|
/// </summary>
|
|
private string mDisplayText=null;
|
|
/// <summary>
|
|
/// i.e "Workorder Category"
|
|
/// </summary>
|
|
private string mDisplayTextCustom;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
//Editable Root style constructor
|
|
private LocalizedText()
|
|
{
|
|
//pre-break the rules
|
|
DisplayText = "";
|
|
Key = "";
|
|
Locale = "";
|
|
|
|
mDisplayTextCustom = "";
|
|
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified = new SmartDate();
|
|
mCreator = Guid.Empty;
|
|
mModifier = Guid.Empty;
|
|
}
|
|
|
|
|
|
|
|
//Editable child style constructor:
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private LocalizedText(bool IsChild)
|
|
{
|
|
|
|
|
|
//pre-break the rules
|
|
DisplayText="";
|
|
Key="";
|
|
Locale="";
|
|
|
|
mDisplayTextCustom="";
|
|
if(IsChild)
|
|
MarkAsChild();
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
/// <summary>
|
|
/// i.e "Category"
|
|
/// </summary>
|
|
public string DisplayText
|
|
{
|
|
get
|
|
{
|
|
return mDisplayText;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mDisplayText!=value)
|
|
{
|
|
mDisplayText = value;
|
|
//case 829
|
|
if (string.IsNullOrEmpty(mDisplayText))
|
|
mDisplayText = "?";
|
|
|
|
if (mDisplayText.Length > 255)
|
|
mDisplayText = mDisplayText.Substring(0, 255);
|
|
|
|
//BrokenRules.Assert("DisplayTextRequired","Error.Object.RequiredFieldEmpty,LocalizedText.Label.DisplayText","DisplayText",value.Length==0);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// i.e "Workorder Category"
|
|
/// </summary>
|
|
public string DisplayTextCustom
|
|
{
|
|
get
|
|
{
|
|
return mDisplayTextCustom;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mDisplayTextCustom!=value)
|
|
{
|
|
mDisplayTextCustom = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// i.e "wo.category"
|
|
/// </summary>
|
|
public string Key
|
|
{
|
|
get
|
|
{
|
|
return mKey;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mKey!=value)
|
|
{
|
|
mKey = value;
|
|
BrokenRules.Assert("KeyRequired","Error.Object.RequiredFieldEmpty,LocalizedText.Label.Key","Key",value.Length==0);
|
|
MarkDirty();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// i.e English, French, Spanish, German
|
|
/// </summary>
|
|
public string Locale
|
|
{
|
|
get
|
|
{
|
|
return mLocale;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mLocale!=value)
|
|
{
|
|
mLocale = value;
|
|
BrokenRules.Assert("LocaleRequired","Error.Object.RequiredFieldEmpty,LocalizedText.Label.Locale","Key",value.Length==0);
|
|
|
|
MarkDirty();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get created date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get modified date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user record ID of person who created this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user ID of person who modified this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Throw an error when a read only user
|
|
/// tries to set a property
|
|
/// </summary>
|
|
private void ThrowSetError()
|
|
{
|
|
throw new System.Security.SecurityException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.User")
|
|
)
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "LocalizedText:" + mLocale+mKey;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
LocalizedText c=(LocalizedText)obj;
|
|
return (mLocale+mKey)==(c.Locale+c.Key);
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
string sTemp=mLocale+mKey;
|
|
return sTemp.GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Root version of new item
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static LocalizedText NewItem()
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.LocalizedText")>(int)SecurityLevelTypes.ReadOnly)
|
|
return new LocalizedText(false);
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.LocalizedText")));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Child version of new item
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static LocalizedText NewItemChild()
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.LocalizedText")>(int)SecurityLevelTypes.ReadOnly)
|
|
return new LocalizedText(true);
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.LocalizedText")));
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Item - Editable root version
|
|
/// </summary>
|
|
/// <param name="Key"></param>
|
|
/// <param name="Locale"></param>
|
|
/// <returns></returns>
|
|
public static LocalizedText GetItem(string Key, string Locale)
|
|
{
|
|
|
|
//if(AyaBizUtils.Right("Object.LocalizedText")>(int)SecurityLevelTypes.NoAccess)
|
|
|
|
//Can always retrieve no matter what rights, it's up to the UI
|
|
//to hide the editor form if necessary
|
|
return (LocalizedText)DataPortal.Fetch(new Criteria(Locale,Key,false));
|
|
//
|
|
//else
|
|
// throw new System.Security.SecurityException(
|
|
// string.Format(
|
|
// LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
// LocalizedTextTable.GetLocalizedTextDirect("O.LocalizedText")));
|
|
//
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get item - Child version
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
/// <returns></returns>
|
|
internal static LocalizedText GetItemChild(SafeDataReader dr)
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.LocalizedText")>(int)SecurityLevelTypes.NoAccess)
|
|
{
|
|
LocalizedText child = new LocalizedText(true);
|
|
child.Fetch(dr);
|
|
return child;
|
|
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.LocalizedText")));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete LocalizedText Item
|
|
/// </summary>
|
|
/// <param name="Key"></param>
|
|
/// <param name="Locale"></param>
|
|
public static void DeleteItem(string Key, string Locale)
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.LocalizedText")>(int)SecurityLevelTypes.ReadWrite)
|
|
DataPortal.Delete(new Criteria(Locale,Key,false));
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.LocalizedText")));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
//THIS IS A SWITCHABLE OBJECT
|
|
|
|
#region custom concurrency check
|
|
|
|
private static void CheckSafeToUpdate(System.DateTime LastUpdated, string Locale, string Key,IDbTransaction tr)
|
|
{
|
|
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
"SELECT aModified, aModifier FROM aLocalizedText " +
|
|
"WHERE aLocale=@Locale AND aKey=@Key"
|
|
);
|
|
dbCommandWrapper.AddInParameter("@Locale",DbType.String,Locale);
|
|
dbCommandWrapper.AddInParameter("@Key",DbType.String,Key);
|
|
SafeDataReader r =null;
|
|
if(tr!=null)
|
|
r = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper,tr));
|
|
else
|
|
r = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
if(r.Read())
|
|
{
|
|
if(!DBUtil.DatesAreEqualish(DBUtil.ToUTC(LastUpdated),r.GetSmartDate("aModified").Date))
|
|
{
|
|
Guid gModifier=r.GetGuid("aModifier");
|
|
r.Close();
|
|
dbCommandWrapper.Command.Parameters.Clear();
|
|
dbCommandWrapper.AddInParameter("@ID",DbType.Guid,gModifier);
|
|
dbCommandWrapper.Command.CommandText="SELECT aFirstName, aLastName FROM aUser WHERE aID = @ID";
|
|
r=new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
if(r.Read())
|
|
{
|
|
string sUser=r.GetString("aFirstName") + " " + r.GetString("aLastName");
|
|
r.Close();
|
|
|
|
throw new System.Exception(string.Format(LocalizedTextTable.GetLocalizedTextDirect("Error.DB.RecordModifiedExternally"),"Address",sUser));
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
//de nada
|
|
r.Close();
|
|
return;
|
|
}
|
|
}
|
|
|
|
//Added: 20-June-2006
|
|
r.Close();
|
|
}
|
|
#endregion
|
|
|
|
#region Fetch Child style
|
|
/// <summary>
|
|
/// Populate this object from the values in the datareader passed to it
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModifier=dr.GetGuid("aModifier");
|
|
|
|
//Important: use property not internal field
|
|
//so that initial broken rule is unbroken on fetch
|
|
Locale=dr.GetString("aLocale");
|
|
Key=dr.GetString("aKey");
|
|
DisplayText=dr.GetString("aDisplayText");
|
|
|
|
mDisplayTextCustom=dr.GetString("aDisplayTextCustom");
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.LocalizedText")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
MarkOld();
|
|
}
|
|
#endregion Fetch child style
|
|
|
|
#region Fetch - Editable root style
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
|
|
try
|
|
{
|
|
|
|
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
"SELECT * FROM aLocalizedText WHERE aLocale=@Locale " +
|
|
"AND aKey=@Key"
|
|
);
|
|
dbCommandWrapper.AddInParameter("@Locale",DbType.String,crit.Locale);
|
|
dbCommandWrapper.AddInParameter("@Key",DbType.String,crit.Key);
|
|
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
if(!dr.Read())
|
|
DBUtil.ThrowFetchError("LocalizedText: " + crit.Locale + "." + crit.Key);
|
|
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModifier=dr.GetGuid("aModifier");
|
|
|
|
//Important: use property not internal field
|
|
//so that initial broken rule is unbroken on fetch
|
|
Locale=dr.GetString("aLocale");
|
|
Key=dr.GetString("aKey");
|
|
DisplayText=dr.GetString("aDisplayText");
|
|
|
|
DisplayTextCustom=dr.GetString("aDisplayTextCustom");
|
|
|
|
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
MarkOld();
|
|
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.LocalizedText")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
}
|
|
#endregion fetch editable root style
|
|
|
|
#region Update - Editable Root Version
|
|
/// <summary>
|
|
/// Called by DataPortal to delete/add/update data into the database
|
|
/// Editable root version
|
|
/// </summary>
|
|
protected override void DataPortal_Update()
|
|
{
|
|
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
if(!IsNew)
|
|
CheckSafeToUpdate(this.mModified.Date,this.mLocale,this.mKey,null);
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
//Delete object
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aLocalizedText WHERE aLocale=@Locale AND aKey=@Key");
|
|
cmDelete.AddInParameter("@Locale",DbType.String,this.mLocale);
|
|
cmDelete.AddInParameter("@Key",DbType.String,this.mKey);
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
try
|
|
{
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
}
|
|
|
|
//-----------------------------
|
|
}
|
|
MarkNew();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Add / Update
|
|
|
|
//get modification time temporarily, if update succeeds then
|
|
//set to this time
|
|
System.DateTime dtModified = DBUtil.CurrentWorkingDateTime;
|
|
|
|
DBCommandWrapper cm = null;
|
|
if(IsNew)//Add or update?
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO aLocalizedText (aLocale, aKey, aDisplayText, " +
|
|
"aDisplayTextCustom, aCreated,aModified,aCreator,aModifier) VALUES " +
|
|
"(@Locale,@Key,@DisplayText,@DisplayTextCustom, " +
|
|
"@Created,@Modified,@CurrentUserID,@CurrentUserID)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aLocalizedText SET aLocale=@Locale, aKey=@Key, " +
|
|
"aDisplayText=@DisplayText, aDisplayTextCustom=@DisplayTextCustom, " +
|
|
"aModifier=@CurrentUserID, aModified=@Modified " +
|
|
"WHERE aLocale=@Locale AND aKey=@Key"
|
|
);
|
|
|
|
|
|
//Localized text fields
|
|
cm.AddInParameter("@Locale",DbType.String,this.mLocale);
|
|
cm.AddInParameter("@Key",DbType.String,this.mKey);
|
|
cm.AddInParameter("@DisplayText",DbType.String,mDisplayText);
|
|
cm.AddInParameter("@DisplayTextCustom",DbType.String,mDisplayTextCustom);
|
|
|
|
|
|
//Standard fields
|
|
//Changed: 21-March-2006
|
|
//This object is invoked by the schema update before a user has logged in so
|
|
//if currentuserid is empty it will sub the admin id instead
|
|
if(CurrentUserID!=Guid.Empty)
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
|
|
else
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, User.AdministratorID);
|
|
|
|
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue);
|
|
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
|
|
|
|
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, transaction);
|
|
|
|
|
|
MarkOld();//db is now synched with object
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
//case 829 - reset stoplist
|
|
AyaBizUtils.StopList = null;
|
|
AyaBizUtils.LocaleText = null;
|
|
}
|
|
|
|
#endregion Update editable root version
|
|
|
|
#region Update - child version
|
|
|
|
|
|
/// <summary>
|
|
/// Update - Child version
|
|
/// </summary>
|
|
/// <param name="tr"></param>
|
|
internal void Update(IDbTransaction tr)
|
|
{
|
|
//No need to update if there is nothing changed
|
|
if(!this.IsDirty) return;
|
|
|
|
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
if(!IsNew)
|
|
CheckSafeToUpdate(this.mModified.Date,this.mLocale,this.mKey,tr);//<-see checksafetoupdate for why this transaction is necessary here
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aLocalizedText WHERE aLocale=@Locale AND aKey=@Key");
|
|
cmDelete.AddInParameter("@Locale",DbType.String,this.mLocale);
|
|
cmDelete.AddInParameter("@Key",DbType.String,this.mKey);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, tr);
|
|
//-----------------------------
|
|
}
|
|
MarkNew();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Add / Update
|
|
|
|
//get modification time temporarily, if update succeeds then
|
|
//set to this time
|
|
System.DateTime dtModified = DBUtil.CurrentWorkingDateTime;
|
|
|
|
DBCommandWrapper cm = null;
|
|
if(IsNew)//Add or update?
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO aLocalizedText (aLocale, aKey, aDisplayText, " +
|
|
"aDisplayTextCustom, aCreated,aModified,aCreator,aModifier) VALUES " +
|
|
"(@Locale,@Key,@DisplayText,@DisplayTextCustom, " +
|
|
"@Created,@Modified,@CurrentUserID,@CurrentUserID)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aLocalizedText SET aLocale=@Locale, aKey=@Key, " +
|
|
"aDisplayText=@DisplayText, aDisplayTextCustom=@DisplayTextCustom, " +
|
|
"aModifier=@CurrentUserID, aModified=@Modified " +
|
|
"WHERE aLocale=@Locale AND aKey=@Key"
|
|
);
|
|
|
|
|
|
//Localized text fields
|
|
cm.AddInParameter("@Locale",DbType.String,this.mLocale);
|
|
cm.AddInParameter("@Key",DbType.String,this.mKey);
|
|
cm.AddInParameter("@DisplayText",DbType.String,mDisplayText);
|
|
cm.AddInParameter("@DisplayTextCustom",DbType.String,mDisplayTextCustom);
|
|
|
|
|
|
//Standard fields
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
|
|
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue);
|
|
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, tr);
|
|
|
|
MarkOld();//db is now synched with object
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
#endregion
|
|
|
|
//case 829 - reset stoplist
|
|
AyaBizUtils.StopList = null;
|
|
AyaBizUtils.LocaleText = null;
|
|
}
|
|
|
|
#endregion Update child version
|
|
|
|
#region Delete - editable root version
|
|
|
|
/// <summary>
|
|
/// Remove a Localized Text record from the database
|
|
/// </summary>
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Delete(object Criteria)
|
|
{
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
//Delete object
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aLocalizedText WHERE aLocale=@Locale AND aKey=@Key");
|
|
cmDelete.AddInParameter("@Locale",DbType.String,crit.Locale);
|
|
cmDelete.AddInParameter("@Key",DbType.String,crit.Key);
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
try
|
|
{
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
#endregion Delete editable root style
|
|
|
|
#endregion
|
|
|
|
#region Override IsValid / IsDirty
|
|
//Override base class version if there are child objects
|
|
/*
|
|
public override bool IsValid
|
|
{
|
|
get
|
|
{
|
|
return base.IsValid && ChildItem.IsValid;
|
|
}
|
|
}
|
|
public override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
return base.IsDirty || ChildItem.IsDirty;
|
|
}
|
|
}
|
|
*/
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public string Locale;
|
|
public string Key;
|
|
public bool IsChild;
|
|
public Criteria(string _Locale,string _Key, bool _IsChild)
|
|
{
|
|
Locale=_Locale;
|
|
Key=_Key;
|
|
IsChild=_IsChild;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end LocalizedText
|
|
|
|
#region Locale Type Converter
|
|
#pragma warning disable 1591
|
|
|
|
public class LocaleConverter:StringConverter
|
|
{
|
|
|
|
private LocaleList mList;
|
|
|
|
public LocaleConverter()
|
|
{
|
|
mList=LocaleList.GetList();
|
|
|
|
}
|
|
|
|
|
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|
{
|
|
ArrayList ar = new ArrayList(mList.Count);
|
|
//ar.Add("");
|
|
foreach(LocaleList.LocaleListInfo ll in mList)
|
|
{
|
|
ar.Add(ll.Locale);
|
|
}
|
|
|
|
return new StandardValuesCollection(ar);
|
|
|
|
}
|
|
|
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
|
{
|
|
if (destinationType == typeof(string) && value is string)
|
|
{
|
|
return value;
|
|
}
|
|
|
|
|
|
// if (destinationType==typeof(Guid))
|
|
// {
|
|
// Guid g= new Guid(mList[(string)value);
|
|
// return g;// (Guid)mList[value];
|
|
//
|
|
// }
|
|
//
|
|
//
|
|
return base.ConvertTo (context, culture, value, destinationType);
|
|
}
|
|
|
|
//convert from whatever kind of object to this converters type
|
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
|
{
|
|
|
|
if(value==null) return "";
|
|
if(value is String)
|
|
{//the list name and value are the same so just return whatever came in
|
|
return value;
|
|
}
|
|
|
|
return base.ConvertFrom (context, culture, value);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
#pragma warning restore 1591
|
|
#endregion
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |