659 lines
16 KiB
C#
659 lines
16 KiB
C#
///////////////////////////////////////////////////////////
|
|
// xContactPhone.cs
|
|
// Implementation of Class xContactPhone
|
|
// CSLA type: Editable Child
|
|
// Created on: 07-Jun-2004 8:41:17 AM
|
|
// Object design: Joyce
|
|
// Coded: John 15-July-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.Text;
|
|
using GZTW.Data;
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
|
|
#pragma warning disable 1591
|
|
/// <summary>
|
|
/// DEPRECATED V4.0
|
|
/// </summary>
|
|
[Serializable]
|
|
public class xContactPhone : BusinessBase {
|
|
|
|
|
|
#region Attributes
|
|
|
|
private bool bReadOnly;
|
|
|
|
private Guid mID;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
|
|
|
|
/// <summary>
|
|
/// Guid ID of contact
|
|
/// </summary>
|
|
private Guid mContactID;
|
|
/// <summary>
|
|
/// The point is so that if can not list all phone numbers, this is the default
|
|
/// number that will be displayed default is the first one entered is true, all
|
|
/// others are false. But if another is made true, then this one becomes false
|
|
/// Additional phone entered are then set to false automatically User has ability
|
|
/// to change true and false
|
|
/// </summary>
|
|
private bool mPhoneDefault;
|
|
/// <summary>
|
|
/// Could be phone, fax, cell etc
|
|
/// </summary>
|
|
private ContactPhoneTypes mContactPhoneType;
|
|
private string mPhoneNumber="";
|
|
/// <summary>
|
|
/// Default can be set from regional settings (or global settings?)
|
|
/// </summary>
|
|
private string mPhoneAreaCode="";
|
|
private string mPhoneCountryCode="";
|
|
private string mPhoneExtension="";
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
private xContactPhone()
|
|
{
|
|
|
|
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//Child object
|
|
MarkAsChild();
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
}
|
|
#endregion
|
|
|
|
#region BusinessProperties
|
|
|
|
//---Common properties
|
|
/// <summary>
|
|
/// Initial created date of this object
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// User ID of who initially created this object
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Last modified date of this object
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// User ID of who last modified this object
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unique ID of this object
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
|
|
//---xContactPhone specific properties
|
|
|
|
/// <summary>
|
|
/// Could be phone, fax, cell etc
|
|
/// </summary>
|
|
public ContactPhoneTypes ContactPhoneType
|
|
{
|
|
get
|
|
{
|
|
return mContactPhoneType;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mContactPhoneType!=value)
|
|
{
|
|
mContactPhoneType = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Localized text of phone type
|
|
/// </summary>
|
|
public string ContactPhoneTypeString
|
|
{
|
|
get
|
|
{
|
|
|
|
return GetContactPhoneTypeString(this.ContactPhoneType);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Localized text of complete phone record
|
|
/// including descriptive name of phone type, country code etc etc
|
|
/// </summary>
|
|
public string FullPhoneRecord
|
|
{
|
|
get
|
|
{
|
|
StringBuilder b = new StringBuilder();
|
|
b.Append(AyaBizUtils.SS("",ContactPhoneTypeString,": "));
|
|
b.Append(AyaBizUtils.SS("+",PhoneCountryCode," "));
|
|
b.Append(AyaBizUtils.SS("(",PhoneAreaCode,") "));
|
|
b.Append(AyaBizUtils.SS("",PhoneNumber," "));
|
|
b.Append(AyaBizUtils.SS("[",PhoneExtension,"]"));
|
|
|
|
return b.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Full phone number without phone type descriptive string
|
|
///
|
|
/// </summary>
|
|
public string NumberOnlyFullPhoneRecord
|
|
{
|
|
get
|
|
{
|
|
StringBuilder b = new StringBuilder();
|
|
b.Append(AyaBizUtils.SS("+",PhoneCountryCode," "));
|
|
b.Append(AyaBizUtils.SS("(",PhoneAreaCode,") "));
|
|
b.Append(AyaBizUtils.SS("",PhoneNumber," "));
|
|
b.Append(AyaBizUtils.SS("[",PhoneExtension,"]"));
|
|
|
|
return b.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public string PhoneCountryCode
|
|
{
|
|
get
|
|
{
|
|
return mPhoneCountryCode;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPhoneCountryCode!=value)
|
|
{
|
|
mPhoneCountryCode = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string PhoneExtension
|
|
{
|
|
get
|
|
{
|
|
return mPhoneExtension;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPhoneExtension!=value)
|
|
{
|
|
mPhoneExtension = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Guid ID of contact
|
|
/// </summary>
|
|
public Guid ContactID
|
|
{
|
|
get
|
|
{
|
|
return mContactID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mContactID!=value)
|
|
{
|
|
mContactID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default can be set from regional settings (or global settings?)
|
|
/// </summary>
|
|
public string PhoneAreaCode
|
|
{
|
|
get
|
|
{
|
|
return mPhoneAreaCode;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPhoneAreaCode!=value)
|
|
{
|
|
mPhoneAreaCode = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string PhoneNumber
|
|
{
|
|
get
|
|
{
|
|
return mPhoneNumber;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPhoneNumber!=value)
|
|
{
|
|
mPhoneNumber = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This is so that if can not list all phone numbers, this is the default
|
|
/// number that will be displayed default is the first one entered is true, all
|
|
/// others are false. But if another is made true, then this one becomes false
|
|
/// Additional phone entered are then set to false automatically User has ability
|
|
/// to change true and false
|
|
/// </summary>
|
|
public bool PhoneDefault
|
|
{
|
|
get
|
|
{
|
|
return mPhoneDefault;
|
|
}
|
|
//case 260, put it back
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mPhoneDefault != value)
|
|
{
|
|
mPhoneDefault = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Case 124
|
|
internal bool internalPhoneDefault
|
|
{
|
|
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mPhoneDefault != value)
|
|
{
|
|
mPhoneDefault = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Throw an error when a read only user
|
|
/// tries to set a property
|
|
/// (this should normally never be called unless someone is using the developer api since the UI
|
|
/// should prevent it from happening initially)
|
|
/// </summary>
|
|
private void ThrowSetError()
|
|
{
|
|
throw new System.Security.SecurityException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.xContactPhone")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
|
|
public override string ToString()
|
|
{
|
|
return "ContactPhone" + mID.ToString();
|
|
}
|
|
|
|
///
|
|
/// <param name="obj"></param>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
xContactPhone c=(xContactPhone)obj;
|
|
return mID==c.mID;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return ("ContactPhone" + mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Searching
|
|
|
|
/// <summary>
|
|
/// DEPRECATED V4.X
|
|
/// </summary>
|
|
/// <param name="ID"></param>
|
|
/// <param name="searchTerms"></param>
|
|
/// <returns></returns>
|
|
public static SearchResult GetSearchResult(Guid ID, string[]searchTerms)
|
|
{
|
|
return new SearchResult();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
public static string GetContactPhoneTypeString(ContactPhoneTypes pType)
|
|
{
|
|
|
|
switch(pType)
|
|
{
|
|
case ContactPhoneTypes.Business:
|
|
return LocalizedTextTable.GetLocalizedTextDirect("ContactPhone.Label.ContactPhoneType.Business");
|
|
|
|
case ContactPhoneTypes.Fax:
|
|
return LocalizedTextTable.GetLocalizedTextDirect("ContactPhone.Label.ContactPhoneType.Fax");
|
|
|
|
case ContactPhoneTypes.Home:
|
|
return LocalizedTextTable.GetLocalizedTextDirect("ContactPhone.Label.ContactPhoneType.Home");
|
|
|
|
case ContactPhoneTypes.Mobile:
|
|
return LocalizedTextTable.GetLocalizedTextDirect("ContactPhone.Label.ContactPhoneType.Mobile");
|
|
|
|
case ContactPhoneTypes.Pager:
|
|
return LocalizedTextTable.GetLocalizedTextDirect("ContactPhone.Label.ContactPhoneType.Pager");
|
|
|
|
|
|
}
|
|
return "UNKNOWN CONTACT PHONE TYPE";
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Create item
|
|
/// </summary>
|
|
/// <param name="obj">Parent ID</param>
|
|
/// <returns>New Item</returns>
|
|
internal static xContactPhone NewItem(xContact obj)
|
|
{
|
|
|
|
if(AyaBizUtils.Right(obj.RootObjectType)>(int)SecurityLevelTypes.ReadOnly)
|
|
{
|
|
xContactPhone child=new xContactPhone();
|
|
child.mContactID=obj.ID;
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.xContactPhone")));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve item
|
|
/// </summary>
|
|
internal static xContactPhone GetItem(SafeDataReader dr,RootObjectTypes RootObject)
|
|
{
|
|
|
|
|
|
if(AyaBizUtils.Right(RootObject)>(int)SecurityLevelTypes.NoAccess)
|
|
{
|
|
xContactPhone child = new xContactPhone();
|
|
child.Fetch(dr,RootObject);
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.xContactPhone")));
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
/// <summary>
|
|
/// Fetch from db
|
|
/// </summary>
|
|
private void Fetch(SafeDataReader dr,RootObjectTypes RootObject)
|
|
{
|
|
//Standard items
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mModifier=dr.GetGuid("aModifier");
|
|
|
|
//xContactPhone specific parameters
|
|
mContactID = dr.GetGuid("aContactID");
|
|
mContactPhoneType=(ContactPhoneTypes)dr.GetInt16("aContactPhoneType");
|
|
mID=dr.GetGuid("aID");
|
|
mPhoneAreaCode=dr.GetString("aPhoneAreaCode");
|
|
mPhoneCountryCode=dr.GetString("aPhoneCountryCode");
|
|
mPhoneDefault=dr.GetBoolean("aPhoneDefault");
|
|
mPhoneExtension=dr.GetString("aPhoneExtension");
|
|
mPhoneNumber=dr.GetString("aPhoneNumber");
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right(RootObject)<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
MarkOld();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Persist object to database
|
|
/// </summary>
|
|
/// <param name="obj">Parent object</param>
|
|
/// <param name="tr">Parents transaction object</param>
|
|
internal void Update(xContact obj,IDbTransaction tr)
|
|
{
|
|
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
|
|
//Changed: 20-June-2006, added transaction parameter and changed to
|
|
//call CheckSafeToUpdateInsideTransaction instead of regular non transaction one
|
|
|
|
if(!IsNew)//call custom checksafetoupdate method for an address
|
|
DBUtil.CheckSafeToUpdateInsideTransaction(this.mModified.Date, this.mID, "aContactPhone", tr);
|
|
|
|
//No need to update if there is nothing changed
|
|
if(!this.IsDirty) return;
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aContactPhone WHERE aID=@ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, tr);
|
|
DBUtil.RemoveKeywords(tr,RootObjectTypes.ContactPhone,this.mID);
|
|
}
|
|
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 aContactPhone (aID, aContactID, aPhoneDefault, aContactPhoneType, aPhoneNumber, aPhoneAreaCode, " +
|
|
"aPhoneCountryCode, aPhoneExtension, aCreated,aModified,aCreator,aModifier) " +
|
|
"VALUES (@ID,@ContactID,@PhoneDefault,@ContactPhoneType,@PhoneNumber,@PhoneAreaCode, " +
|
|
"@PhoneCountryCode,@PhoneExtension,@Created,@Modified,@CurrentUserID,@CurrentUserID);"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aContactPhone SET aID=@ID, aContactID=@ContactID, " +
|
|
"aPhoneDefault=@PhoneDefault, aContactPhoneType=@ContactPhoneType, " +
|
|
"aPhoneNumber=@PhoneNumber, " +
|
|
"aPhoneAreaCode=@PhoneAreaCode, aPhoneCountryCode=@PhoneCountryCode, " +
|
|
"aPhoneExtension=@PhoneExtension, " +
|
|
"aModifier=@CurrentUserID, aModified=@Modified " +
|
|
"WHERE aID=@ID"
|
|
);
|
|
|
|
|
|
|
|
cm.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
|
|
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated.Date));
|
|
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
|
|
|
|
//xContactPhone specific parameters
|
|
cm.AddInParameter("@ContactID",DbType.Guid,mContactID);
|
|
cm.AddInParameter("@ContactPhoneType",DbType.Int16, (int)mContactPhoneType);
|
|
cm.AddInParameter("@PhoneAreaCode", DbType.String, mPhoneAreaCode);
|
|
cm.AddInParameter("@PhoneCountryCode", DbType.String, mPhoneCountryCode);
|
|
cm.AddInParameter("@PhoneDefault", DbType.Boolean, mPhoneDefault);
|
|
cm.AddInParameter("@PhoneExtension", DbType.String, mPhoneExtension);
|
|
cm.AddInParameter("@PhoneNumber", DbType.String, mPhoneNumber);
|
|
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, tr);
|
|
|
|
//Process keywords
|
|
DBUtil.ProcessKeywords(tr,this.mID,RootObjectTypes.ContactPhone,IsNew,AyaBizUtils.Break(false,
|
|
mPhoneCountryCode,mPhoneAreaCode,
|
|
mPhoneExtension,mPhoneNumber));
|
|
|
|
|
|
MarkOld();//db is now synched with object
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}//end xContactPhone
|
|
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |