/////////////////////////////////////////////////////////// // 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 /// /// DEPRECATED V4.0 /// [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; /// /// Guid ID of contact /// private Guid mContactID; /// /// 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 /// private bool mPhoneDefault; /// /// Could be phone, fax, cell etc /// private ContactPhoneTypes mContactPhoneType; private string mPhoneNumber=""; /// /// Default can be set from regional settings (or global settings?) /// 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 /// /// Initial created date of this object /// public string Created { get { return mCreated.ToString(); } } /// /// User ID of who initially created this object /// public Guid Creator { get { return mCreator; } } /// /// Last modified date of this object /// public string Modified { get { return mModified.ToString(); } } /// /// User ID of who last modified this object /// public Guid Modifier { get { return mModifier; } } /// /// Unique ID of this object /// public Guid ID { get { return mID; } } //---xContactPhone specific properties /// /// Could be phone, fax, cell etc /// public ContactPhoneTypes ContactPhoneType { get { return mContactPhoneType; } set { if(bReadOnly) ThrowSetError(); else { if(mContactPhoneType!=value) { mContactPhoneType = value; MarkDirty(); } } } } /// /// Localized text of phone type /// public string ContactPhoneTypeString { get { return GetContactPhoneTypeString(this.ContactPhoneType); } } /// /// Localized text of complete phone record /// including descriptive name of phone type, country code etc etc /// 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(); } } /// /// Full phone number without phone type descriptive string /// /// 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(); } } } } /// /// Guid ID of contact /// public Guid ContactID { get { return mContactID; } set { if(bReadOnly) ThrowSetError(); else { if(mContactID!=value) { mContactID = value; MarkDirty(); } } } } /// /// Default can be set from regional settings (or global settings?) /// 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(); } } } } /// /// 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 /// 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(); } } } } /// /// 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) /// 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(); } /// /// 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 /// /// DEPRECATED V4.X /// /// /// /// 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"; } /// /// Create item /// /// Parent ID /// New Item 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"))); } /// /// Retrieve item /// 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 /// /// Fetch from db /// 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(); } /// /// Persist object to database /// /// Parent object /// Parents transaction object 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