diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 27a5139..d1c4ed7 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -188,7 +188,7 @@ namespace AyaNova.PlugIn.V8 { if (!Map.ContainsKey(id)) { - throw new Exception("Error: GetMap (source id: "+ id.ToString() +") [" + details + "] - v7 Id not previously exported, missing or corrupted source data, export can not complete until fixed"); + throw new Exception("Error: GetMap (source id: " + id.ToString() + ") [" + details + "] - v7 Id not previously exported, missing or corrupted source data, export can not complete until fixed"); } return Map[id]; } @@ -303,7 +303,7 @@ namespace AyaNova.PlugIn.V8 progress.Op("Exporting Business objects"); //BIZ objects await ExportLocales(progress); - await ExportStaffUsers(progress); + await ExportStaffUsers(progress); await ExportContracts(progress); await ExportHeadOffices(progress); await ExportClients(progress); @@ -318,7 +318,7 @@ namespace AyaNova.PlugIn.V8 await ExportVendors(progress); await ExportExternalUsers(progress);//needs vendors, clients and headoffices already exported so needs to be here late await ExportMemos(progress); - + await ExportServiceWorkorders(progress); //todo: these are now invalid and awaiting RAVEN end implementation //after which can copy mostly from service workorder block @@ -852,8 +852,8 @@ namespace AyaNova.PlugIn.V8 d.webAddress = c.WebAddress; d.popUpNotes = c.PopUpNotes; d.billHeadOffice = c.BillHeadOffice; - - + + if (c.HeadOfficeID != Guid.Empty) { d.headOfficeId = GetMap(c.HeadOfficeID, "HeadOffice for Client " + d.name); @@ -861,7 +861,7 @@ namespace AyaNova.PlugIn.V8 d.techNotes = c.TechNotes; d.accountNumber = c.AccountNumber; d.usesBanking = c.UsesBanking; - + if (c.ContractID != Guid.Empty) { d.contractId = GetMap(c.ContractID, "Contract for Client " + d.name); @@ -1065,7 +1065,7 @@ namespace AyaNova.PlugIn.V8 { d.contractId = GetMap(c.ContractID, "Contract for Head Office " + d.name); } - + d.contractExpires = c.ContractExpires;//?? dates d.phone1 = c.Phone1; d.phone2 = c.Phone2; @@ -1755,19 +1755,19 @@ namespace AyaNova.PlugIn.V8 tags.Add(ImportTag); Vendor c = Vendor.GetItem(i.ID); - var ObjectTID = new TypeAndID(RootObjectTypes.Vendor, c.ID); + var ObjectTID = new TypeAndID(RootObjectTypes.Vendor, c.ID); dynamic d = new JObject(); d.name = GetUniqueName(c.Name); if (IsDuplicateMapItem(c.ID, c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; - + d.notes = c.Notes; d.contact = c.Contact; - d.contactNotes = c.ContactNotes; + d.contactNotes = c.ContactNotes; d.webAddress = c.WebAddress; d.accountNumber = c.AccountNumber; d.phone1 = c.Phone1; @@ -1859,47 +1859,53 @@ namespace AyaNova.PlugIn.V8 progress.Op("Start Memos export"); progress.SubOp(""); var ObjectTypeName = "Memo"; - - //Step 2: export the objects - MemoList pl = MemoList.GetListForSingleItem(PluginID); - - progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + "s"); + List tags = new List(); + tags.Add(ImportTag); - foreach (MemoList.MemoListInfo i in pl) + //Get all user id's then get all memo id's for each user id then fetch each memo and finally export + UserPickList upl = UserPickList.GetList(false); + foreach (UserPickList.UserPickListInfo upli in upl) { if (!progress.KeepGoing) return; - List tags = new List(); - tags.Add(ImportTag); + UserMemoIdList umidl = UserMemoIdList.GetList(upli.ID); + foreach (UserMemoIdList.UserMemoIdListInfo mid in umidl) + { + if (!progress.KeepGoing) return; + Memo mem = Memo.GetItem(mid.mID, PluginID); + dynamic d = new JObject(); + dynamic dmemo = new JObject(); + dynamic duserid = new JArray(); + dmemo.name = mem.Subject; + dmemo.notes = mem.Message; + dmemo.viewed = mem.Viewed; + dmemo.replied = mem.Replied; + var RavenFromId=SafeGetUserMap(mem.FromID); + dmemo.fromId = RavenFromId; + dmemo.sent = mem.Created; - + duserid.Add(SafeGetUserMap(mem.ToID)); + d.users = duserid; + d.memo = dmemo; + SetTags(d, tags); + progress.Op(ObjectTypeName + " " + mem.ID.ToString()); - dynamic d = new JObject(); - d.name = i.LT_Memo_Label_Subject.Display; - d.notes = i.LT_Memo_Label_Message; - //d.customFields = "{}"; - //d.tags = "[]"; - d.viewed = i.LT_Memo_Label_Viewed; - d.replied = i.LT_Memo_Label_Replied; - d.fromId = SafeGetUserMap(i.LT_Memo_Label_FromID.Value); - d.sent = i.LT_Memo_Label_Sent; - - progress.Op(ObjectTypeName + " " + i.ID.ToString()); - - + var rMainObject = await util.PostAsync("memo", d.ToString()); + long RavenId = util.IdFromResponse(rMainObject); - var rMainObject = await util.PostAsync("memo", d.ToString()); - long RavenId = util.IdFromResponse(rMainObject); - - //----- - - d = rMainObject.ObjectResponse["data"]; - - //----- + d = rMainObject.ObjectResponse["data"]; - //Event log fixup - await util.EventLog(util.AyaType.Project, RavenId, SafeGetUserMap(i.LT_Memo_Label_FromID.Value), SafeGetUserMap(i.LT_Memo_Label_FromID.Value), i.LT_Memo_Label_Sent.ToString(), i.LT_Memo_Label_Sent.ToString()); + //----- + //Event log fixup + await util.EventLog(util.AyaType.Project, RavenId, RavenFromId, RavenFromId, mem.Created, mem.Modified); + + } } + + + //------ + + } #endregion Memos @@ -2851,9 +2857,9 @@ namespace AyaNova.PlugIn.V8 else RavenTypeAsString = ((int)util.RootObjectToAyaType(tid.RootObjectType)).ToString(); formDataContent.Add(new StringContent(RavenTypeAsString), name: "AttachToObjectType"); - + //formDataContent.Add(new StringContent(Map[tid.ID].ToString()), name: "AttachToObjectId"); - formDataContent.Add(new StringContent(GetMap(tid.ID, "Object ID for attachment export (tid:"+tid.ToString()+") ").ToString()), name: "AttachToObjectId"); + formDataContent.Add(new StringContent(GetMap(tid.ID, "Object ID for attachment export (tid:" + tid.ToString() + ") ").ToString()), name: "AttachToObjectId"); formDataContent.Add(new StringContent(ImportTag), name: "Notes"); formDataContent.Add(new StringContent(dFileData.ToString()), name: "FileData"); @@ -2949,10 +2955,10 @@ namespace AyaNova.PlugIn.V8 else RavenTypeAsString = ((int)util.RootObjectToAyaType(tid.RootObjectType)).ToString(); formDataContent.Add(new StringContent(RavenTypeAsString), name: "AttachToObjectType"); - // formDataContent.Add(new StringContent(Map[tid.ID].ToString()), name: "AttachToObjectId"); + // formDataContent.Add(new StringContent(Map[tid.ID].ToString()), name: "AttachToObjectId"); formDataContent.Add(new StringContent(GetMap(tid.ID, "Object ID for attached docs export (tid:" + tid.ToString() + ") ").ToString()), name: "AttachToObjectId"); - + formDataContent.Add(new StringContent(doc.Description + " (" + ImportTag + ")"), name: "Notes"); formDataContent.Add(new StringContent(dFileData.ToString()), name: "FileData"); @@ -2996,7 +3002,7 @@ namespace AyaNova.PlugIn.V8 MatchCollection mc = AyaBizUtils.rxAyaImageTags.Matches(content); foreach (Match m in mc) { - var RavenId = GetMap(new Guid(m.Groups["guid"].Value), "Object id for Wiki export (tid:" + tid.ToString()+")"); //Map[new Guid(m.Groups["guid"].Value)]; + var RavenId = GetMap(new Guid(m.Groups["guid"].Value), "Object id for Wiki export (tid:" + tid.ToString() + ")"); //Map[new Guid(m.Groups["guid"].Value)]; content = content.Replace(m.Value, ""); } diff --git a/source/bizobjects/AyaLib/GZTW.AyaNova.BLL.csproj b/source/bizobjects/AyaLib/GZTW.AyaNova.BLL.csproj index c3785e0..962c14e 100644 --- a/source/bizobjects/AyaLib/GZTW.AyaNova.BLL.csproj +++ b/source/bizobjects/AyaLib/GZTW.AyaNova.BLL.csproj @@ -201,6 +201,9 @@ + + Code + @@ -269,7 +272,6 @@ - @@ -318,6 +320,7 @@ + diff --git a/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/Memo.cs b/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/Memo.cs index f794fb9..66d4842 100644 --- a/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/Memo.cs +++ b/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/Memo.cs @@ -17,859 +17,875 @@ using CSLA.Security; using System.ComponentModel; using System.Text; -namespace GZTW.AyaNova.BLL +namespace GZTW.AyaNova.BLL { - /// - /// AyaNova Memo between AyaNova users. - /// Used to create *new* Memo message only - /// - [Serializable] - public class Memo : BusinessBase - { - - - #region Attributes - - private bool bReadOnly; - private Guid mID; - private SmartDate mCreated; - private SmartDate mModified; - private Guid mCreator; - private Guid mModifier; - - - private string mSubject=null; - private string mMessage=""; - private Guid mFromID; - private Guid mToID; - private bool mViewed; - - - #endregion - - #region Constructor - - /// - /// Private constructor to prevent direct instantiation - /// - private Memo() - { - - - - //Set to read / write initially so that properties - //can be set - bReadOnly=false; - - //New ID - mID = Guid.NewGuid(); - Subject=""; - Message=""; - mViewed=false; - this.mFromID=CurrentUserID; - - - //Set record history to defaults - mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime); - mModified=new SmartDate(); - mCreator=Guid.Empty; - mModifier=Guid.Empty; - - } - #endregion - - #region Business properties - /// - /// Get internal id number Read only property because it's set internally, not - /// externally - /// - public Guid ID - { - get - { - return mID; - } - } - - /// - /// Get created date - /// - /// - /// - public string Created - { - get - { - return mCreated.ToString(); - } - - } - - /// - /// Set created date - /// only used for importing - /// old MAIL from AyaNova CE - /// - /// - public SmartDate zInternal - { - - set - { - if(bReadOnly) - ThrowSetError(); - else - { - if(mCreated!=value) - { - mCreated = value; - MarkDirty(); - - } - } - } - } - - /// - /// Get modified date - /// - /// - /// - public string Modified - { - get - { - return mModified.ToString(); - } - } - - /// - /// Get user record ID of person who created this record - /// - /// - /// - public Guid Creator - { - get - { - return mCreator; - } - } - - /// - /// Get user ID of person who modified this record - /// - /// - /// - public Guid Modifier - { - get - { - return mModifier; - } - } - - /// - /// Set/get Subject of item - /// Required, can't be empty - /// - public string Subject - { - get - { - return mSubject; - } - set - { - if(bReadOnly) - ThrowSetError(); - else - { - if(mSubject!=value) - { - mSubject = value; - BrokenRules.Assert("SubjectRequired", - "Error.Object.RequiredFieldEmpty,Memo.Label.Subject", - "Subject",value.Length==0); - - MarkDirty(); - - } - } - } - } - - /// - /// Set/get Subject of item - /// - /// - public string Message - { - get - { - return mMessage; - } - set - { - if(bReadOnly) - ThrowSetError(); - else - { - if(mMessage!=value) - { - mMessage = value; - - - MarkDirty(); - - } - } - } - } - - /// - /// From whom - /// - public Guid FromID - { - get - { - return mFromID; - } - set - { - if(bReadOnly) - ThrowSetError(); - else - { - if(mFromID!=value) - { - mFromID = value; - MarkDirty(); - - } - } - } - } - - /// - /// To whom - /// - public Guid ToID - { - get - { - return mToID; - } - set - { - if(bReadOnly) - ThrowSetError(); - else - { - if(mToID!=value) - { - mToID = value; - MarkDirty(); - - } - } - } - } - - /// - /// Viewed - user has read the message - /// - public bool Viewed - { - get - { - return mViewed; - } - set - { - if(bReadOnly) - ThrowSetError(); - else - { - if(mViewed!=value) - { - mViewed = 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.Memo") - ) - ); - } + /// + /// AyaNova Memo between AyaNova users. + /// Used to create *new* Memo message only + /// + [Serializable] + public class Memo : BusinessBase + { - - #endregion + #region Attributes - #region System.Object overrides + private bool bReadOnly; + private Guid mID; + private SmartDate mCreated; + private SmartDate mModified; + private Guid mCreator; + private Guid mModifier; + + + private string mSubject = null; + private string mMessage = ""; + private Guid mFromID; + private Guid mToID; + private bool mViewed; + + //case 3832 + private bool mReplied; + + + #endregion + + #region Constructor + + /// + /// Private constructor to prevent direct instantiation + /// + private Memo() + { + + + + //Set to read / write initially so that properties + //can be set + bReadOnly = false; + + //New ID + mID = Guid.NewGuid(); + Subject = ""; + Message = ""; + mViewed = false; + this.mFromID = CurrentUserID; + + + //Set record history to defaults + mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime); + mModified = new SmartDate(); + mCreator = Guid.Empty; + mModifier = Guid.Empty; + + } + #endregion + + #region Business properties + /// + /// Get internal id number Read only property because it's set internally, not + /// externally + /// + public Guid ID + { + get + { + return mID; + } + } + + /// + /// Get created date + /// + /// + /// + public string Created + { + get + { + return mCreated.ToString(); + } + + } + + /// + /// Set created date + /// only used for importing + /// old MAIL from AyaNova CE + /// + /// + public SmartDate zInternal + { + + set + { + if (bReadOnly) + ThrowSetError(); + else + { + if (mCreated != value) + { + mCreated = value; + MarkDirty(); + + } + } + } + } + + /// + /// Get modified date + /// + /// + /// + public string Modified + { + get + { + return mModified.ToString(); + } + } + + /// + /// Get user record ID of person who created this record + /// + /// + /// + public Guid Creator + { + get + { + return mCreator; + } + } + + /// + /// Get user ID of person who modified this record + /// + /// + /// + public Guid Modifier + { + get + { + return mModifier; + } + } + + /// + /// Set/get Subject of item + /// Required, can't be empty + /// + public string Subject + { + get + { + return mSubject; + } + set + { + if (bReadOnly) + ThrowSetError(); + else + { + if (mSubject != value) + { + mSubject = value; + BrokenRules.Assert("SubjectRequired", + "Error.Object.RequiredFieldEmpty,Memo.Label.Subject", + "Subject", value.Length == 0); + + MarkDirty(); + + } + } + } + } + + /// + /// Set/get Subject of item + /// + /// + public string Message + { + get + { + return mMessage; + } + set + { + if (bReadOnly) + ThrowSetError(); + else + { + if (mMessage != value) + { + mMessage = value; + + + MarkDirty(); + + } + } + } + } + + /// + /// From whom + /// + public Guid FromID + { + get + { + return mFromID; + } + set + { + if (bReadOnly) + ThrowSetError(); + else + { + if (mFromID != value) + { + mFromID = value; + MarkDirty(); + + } + } + } + } + + /// + /// To whom + /// + public Guid ToID + { + get + { + return mToID; + } + set + { + if (bReadOnly) + ThrowSetError(); + else + { + if (mToID != value) + { + mToID = value; + MarkDirty(); + + } + } + } + } + + /// + /// Viewed - user has read the message + /// + public bool Viewed + { + get + { + return mViewed; + } + set + { + if (bReadOnly) + ThrowSetError(); + else + { + if (mViewed != value) + { + mViewed = value; + MarkDirty(); + + } + } + } + } + + //case 3832 + + public bool Replied + { + get + { + return mViewed; + } + } + + /// + /// 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.Memo") + ) + ); + } + + + + #endregion + + #region System.Object overrides /// /// /// /// - public override string ToString() - { - return "Memo" + mID.ToString(); - } + public override string ToString() + { + return "Memo" + mID.ToString(); + } - /// - /// - /// - /// - /// - public override bool Equals(Object obj) - { - if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; - Memo c=(Memo)obj; - return mID==c.mID; - } + /// + /// + /// + /// + /// + public override bool Equals(Object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + Memo c = (Memo)obj; + return mID == c.mID; + } /// /// /// /// - public override int GetHashCode() - { - return ("Memo" + mID).GetHashCode(); - } - #endregion + public override int GetHashCode() + { + return ("Memo" + mID).GetHashCode(); + } + #endregion - #region Searching + #region Searching - /// - /// Returns a search result object based on search terms - /// for the ID specified - /// - /// - /// - /// - public static SearchResult GetSearchResult(Guid ID, string[]searchTerms) - { + /// + /// Returns a search result object based on search terms + /// for the ID specified + /// + /// + /// + /// + public static SearchResult GetSearchResult(Guid ID, string[] searchTerms) + { - - if(AyaBizUtils.Right("Object.Memo")<(int)SecurityLevelTypes.ReadOnly) - return new SearchResult(); - Guid To=Guid.Empty; - Guid From=Guid.Empty; - SearchResult sr=new SearchResult(); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - SafeDataReader dr = null; - try - { - dr=DBUtil.GetReaderFromSQLString( + if (AyaBizUtils.Right("Object.Memo") < (int)SecurityLevelTypes.ReadOnly) + return new SearchResult(); + Guid To = Guid.Empty; + Guid From = Guid.Empty; - "SELECT aID, aCreated, aModified, aCreator, aModifier, aSubject, " + - " aMessage, aFromID, aToID FROM aMemo WHERE (aID " + - "= @ID)" - ,ID); + SearchResult sr = new SearchResult(); + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + SafeDataReader dr = null; + try + { + dr = DBUtil.GetReaderFromSQLString( - if(!dr.Read()) - return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for MemoID: " + ID.ToString()); - - - sr.Description=dr.GetString("aSubject"); - sb.Append(sr.Description); - - sb.Append(" "); - sb.Append(dr.GetString("aMessage")); - - From=dr.GetGuid("aFromID"); - To=dr.GetGuid("aToID"); - + "SELECT aID, aCreated, aModified, aCreator, aModifier, aSubject, " + + " aMessage, aFromID, aToID FROM aMemo WHERE (aID " + + "= @ID)" + , ID); - sr.Created=DBUtil.ToLocal(dr.GetSmartDate("aCreated")); - sr.Modified=DBUtil.ToLocal(dr.GetSmartDate("aModified")); - sr.Creator=dr.GetGuid("aCreator"); - sr.Modifier=dr.GetGuid("aModifier"); - - - + if (!dr.Read()) + return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for MemoID: " + ID.ToString()); - } - finally - { - if(dr!=null) dr.Close(); - } - - + sr.Description = dr.GetString("aSubject"); + sb.Append(sr.Description); - //Security..for now only allow Memo to or from current user ID to be searched - //unless it's the built in admin account... + sb.Append(" "); + sb.Append(dr.GetString("aMessage")); - if(!User.IsAdmin) - { - //If it's not for or from current user then bail - if(User.CurrentThreadUserID != To && User.CurrentThreadUserID!=From) - return new SearchResult(); - } - //Formulate results - ExtractAndRank er = new ExtractAndRank(); - er.Process(sb.ToString().Trim(),searchTerms); - sr.Extract=er.Extract; - sr.Rank=er.Ranking; - sr.AncestorRootObjectID=ID; - sr.AncestorRootObjectType=RootObjectTypes.Memo; - - return sr; + From = dr.GetGuid("aFromID"); + To = dr.GetGuid("aToID"); - } - #endregion + sr.Created = DBUtil.ToLocal(dr.GetSmartDate("aCreated")); + sr.Modified = DBUtil.ToLocal(dr.GetSmartDate("aModified")); + sr.Creator = dr.GetGuid("aCreator"); + sr.Modifier = dr.GetGuid("aModifier"); - #region Static methods - /// - /// Get new object - /// - /// - public static Memo NewItem() - { - - if(AyaBizUtils.IsGenerator || AyaBizUtils.Right("Object.Memo")>(int)SecurityLevelTypes.ReadOnly) - return new Memo(); - else - throw new System.Security.SecurityException( - string.Format( - LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"), - LocalizedTextTable.GetLocalizedTextDirect("O.Memo"))); - } - /// - /// Memo Guid - public static Memo GetItem(Guid _ID) - { - //Memo is write only, once it's sent you can't retrieve it again - throw new System.Security.SecurityException( - string.Format( - LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"), - LocalizedTextTable.GetLocalizedTextDirect("O.Memo"))); - } - /// - /// Delete Memo - /// - /// Memo GUID - public static void DeleteItem(Guid _ID) - { - - - if(AyaBizUtils.Right("Object.Memo")>(int)SecurityLevelTypes.ReadWrite) - DataPortal.Delete(new Criteria(_ID)); - else - throw new System.Security.SecurityException( - string.Format( - LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"), - LocalizedTextTable.GetLocalizedTextDirect("O.Memo"))); - } + } + finally + { + if (dr != null) dr.Close(); + } + + + + + //Security..for now only allow Memo to or from current user ID to be searched + //unless it's the built in admin account... + + if (!User.IsAdmin) + { + //If it's not for or from current user then bail + if (User.CurrentThreadUserID != To && User.CurrentThreadUserID != From) + return new SearchResult(); + } + //Formulate results + ExtractAndRank er = new ExtractAndRank(); + er.Process(sb.ToString().Trim(), searchTerms); + sr.Extract = er.Extract; + sr.Rank = er.Ranking; + sr.AncestorRootObjectID = ID; + sr.AncestorRootObjectType = RootObjectTypes.Memo; + + return sr; + + } + + #endregion + + #region Static methods + /// + /// Get new object + /// + /// + public static Memo NewItem() + { + + if (AyaBizUtils.IsGenerator || AyaBizUtils.Right("Object.Memo") > (int)SecurityLevelTypes.ReadOnly) + return new Memo(); + else + throw new System.Security.SecurityException( + string.Format( + LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"), + LocalizedTextTable.GetLocalizedTextDirect("O.Memo"))); + } + + /// + /// Memo Guid + public static Memo GetItem(Guid _ID, Guid __ID)//case 3832 for v8 migrate + { + if (__ID == new Guid("{BD608E8A-820C-46D1-9D81-4CCB6E71B213}")) + return (Memo)DataPortal.Fetch(new Criteria(_ID)); + else + //Memo is write only, once it's sent you can't retrieve it again + throw new System.Security.SecurityException( + string.Format( + LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"), + LocalizedTextTable.GetLocalizedTextDirect("O.Memo"))); + } + + /// + /// Delete Memo + /// + /// Memo GUID + public static void DeleteItem(Guid _ID) + { + + + + if (AyaBizUtils.Right("Object.Memo") > (int)SecurityLevelTypes.ReadWrite) + DataPortal.Delete(new Criteria(_ID)); + else + throw new System.Security.SecurityException( + string.Format( + LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"), + LocalizedTextTable.GetLocalizedTextDirect("O.Memo"))); + } /// /// Used by UI to flag a memo has having been read when it's displayed to the end user /// /// - public static void FlagMessageRead(Guid _MemoID) - { - MemoFlagger.SetMemoFlags(_MemoID,true,false); - } + public static void FlagMessageRead(Guid _MemoID) + { + MemoFlagger.SetMemoFlags(_MemoID, true, false); + } /// /// Used by the UI to flag a memo has having been replied to when end user creates a new memo and sends it /// based off an existing received memo /// /// - public static void FlagMessageReplied(Guid _MemoID) - { - MemoFlagger.SetMemoFlags(_MemoID,false,true); - } + public static void FlagMessageReplied(Guid _MemoID) + { + MemoFlagger.SetMemoFlags(_MemoID, false, true); + } - - - #endregion - - #region Shared Notification Message Processor + + + #endregion + + #region Shared Notification Message Processor internal static NotifyMessage GetNotificationMessage(NotifyMessageRequestData d) - { - //string Language=User.GetUserLanguage(MessageForUserID); + { + //string Language=User.GetUserLanguage(MessageForUserID); MemoFetcher mf = MemoFetcher.GetItem(d.RootObjectID, d.Language); string sMessage = LocalizedTextTable.GetLocalizedTextDirect("O.Memo", d.Language); - NotifyMessage nm=null; + NotifyMessage nm = null; if (d.Format == NotifyDeliveryMessageFormats.Brief) - { - sMessage+="-" + mf.From + "-" + mf.Subject; + { + sMessage += "-" + mf.From + "-" + mf.Subject; if (d.MaxCharacters > 0 && sMessage.Length > d.MaxCharacters) nm = new NotifyMessage("", sMessage.Substring(0, d.MaxCharacters)); - else - nm=new NotifyMessage("", sMessage); + else + nm = new NotifyMessage("", sMessage); - } - else - { - sMessage+="\r\n" + mf.Header + "\r\n\r\n" + mf.Message; - nm=new NotifyMessage(mf.Subject,sMessage); - - } - return nm; - } - #endregion + } + else + { + sMessage += "\r\n" + mf.Header + "\r\n\r\n" + mf.Message; + nm = new NotifyMessage(mf.Subject, sMessage); - #region DAL DATA ACCESS + } + return nm; + } + #endregion - #region Fetch -// /// -// /// -// protected override void DataPortal_Fetch(object Criteria) -// { -// //set to false to load items initially -// bReadOnly=false; -// -// Criteria crit = (Criteria)Criteria; -// SafeDataReader dr = null; -// try -// { -// dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aMemo WHERE aID=@ID;",crit.ID); -// if(!dr.Read()) -// DBUtil.ThrowFetchError("Memo ID: " + crit.ID.ToString()); -// -// //Standard fields -// mID=dr.GetGuid("aID"); -// mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated")); -// mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified")); -// mCreator=dr.GetGuid("aCreator"); -// mModifier=dr.GetGuid("aModifier"); -// -// -// //Memo fields -// //Important: use property not internal field -// //so that initial broken rule is unbroken on fetch -// Subject=dr.GetString("aSubject"); -// mMessage=dr.GetString("aMessage"); -// mFromID=dr.GetGuid("aFromID"); -// mToID=dr.GetGuid("aToID"); -// mViewed=dr.GetBoolean("aViewed"); -// -// -// } -// finally -// { -// if(dr!=null) dr.Close(); -// } -// MarkOld(); -// -// -// //Get access rights level -// bReadOnly=AyaBizUtils.Right("Object.Memo")<(int)SecurityLevelTypes.ReadWrite; -// } -// - #endregion fetch + #region DAL DATA ACCESS - #region Update - /// - /// Called by DataPortal to delete/add/update data into the database - /// - protected override void DataPortal_Update() - { - //If not a new record, check if record was modified - //by another user since original retrieval: - if(!IsNew) - DBUtil.CheckSafeToUpdate(this.mModified.Date,this.mID,"aMemo"); + #region Fetch + //case 3832 + protected override void DataPortal_Fetch(object Criteria) + { + //set to false to load items initially + bReadOnly = false; - #region Delete - if(IsDeleted) - { - throw new System.Security.SecurityException( - string.Format( - LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"), - LocalizedTextTable.GetLocalizedTextDirect("O.Memo"))); -// if(!IsNew) -// { -// -// -// //Delete object and child objects -// DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aMemo WHERE aID = @ID;"); -// cmDelete.AddInParameter("@ID",DbType.Guid,this.mID); -// -// -// -// using (IDbConnection connection = DBUtil.DB.GetConnection()) -// { -// connection.Open(); -// IDbTransaction transaction = connection.BeginTransaction(); -// -// try -// { -// -// DBUtil.DB.ExecuteNonQuery(cmDelete, transaction); -// DBUtil.RemoveKeywords(transaction,RootObjectTypes.Memo,this.mID); -// -// // Commit the transaction -// transaction.Commit(); -// -// } -// catch -// { -// // Rollback transaction -// transaction.Rollback(); -// throw; -// } -// finally -// { -// connection.Close(); -// } -// } -// -// -// //----------------------------- -// } -// MarkNew(); -// return; - } + Criteria crit = (Criteria)Criteria; + SafeDataReader dr = null; + try + { + dr = DBUtil.GetReaderFromSQLString("SELECT * FROM aMemo WHERE aID=@ID;", crit.ID); + if (!dr.Read()) + DBUtil.ThrowFetchError("Memo ID: " + crit.ID.ToString()); - #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 aMemo (aID, aSubject, aMessage, aFromID, aToID, aViewed, aReplied, aCreator,aModifier,aCreated, aModified) " + - "VALUES (@ID,@Subject,@Message,@FromID,@ToID,@Viewed,@Replied,@CurrentUserID,@CurrentUserID,@Created,@Modified);" - ); - else - cm=DBUtil.GetCommandFromSQL( - "UPDATE aMemo SET aID=@ID, aSubject=@Subject, aMessage=@Message, " + - "aFromID=@FromID, aToID=@ToID, aViewed=@Viewed, " + - "aModifier=@CurrentUserID, aModified=@Modified " + - "WHERE aID=@ID;" - ); + //Standard fields + mID = dr.GetGuid("aID"); + mCreated = DBUtil.ToLocal(dr.GetSmartDate("aCreated")); + mModified = DBUtil.ToLocal(dr.GetSmartDate("aModified")); + mCreator = dr.GetGuid("aCreator"); + mModifier = dr.GetGuid("aModifier"); - cm.AddInParameter("@ID",DbType.Guid,mID); - cm.AddInParameter("@Subject", DbType.String, mSubject); - cm.AddLargeStringInParameter("@Message", mMessage); - cm.AddInParameter("@FromID", DbType.Guid, mFromID); - cm.AddInParameter("@ToID",DbType.Guid, mToID); - cm.AddInParameter("@Viewed", DbType.Boolean, mViewed); - cm.AddInParameter("@Replied", DbType.Boolean, false); - - //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)); - - - - using (IDbConnection connection = DBUtil.DB.GetConnection()) - { - connection.Open(); - IDbTransaction transaction = connection.BeginTransaction(); - - try - { - - DBUtil.DB.ExecuteNonQuery(cm, transaction); - - //Process keywords - DBUtil.ProcessKeywords(transaction,this.mID,RootObjectTypes.Memo,IsNew,AyaBizUtils.Break(false, - mSubject,mMessage)); - - 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; - //Process events as necessary - if(AyaBizUtils.GlobalSettings.UseNotification)//Case 509 - { - NotifyEvent.AddOrUpdateEvent(RootObjectTypes.Memo,this.mID,(int)MemoEvent.Created,this.mToID,new SmartDate(),Guid.Empty); - - } - - } - - #endregion + //Memo fields + //Important: use property not internal field + //so that initial broken rule is unbroken on fetch + Subject = dr.GetString("aSubject"); + mMessage = dr.GetString("aMessage"); + mFromID = dr.GetGuid("aFromID"); + mToID = dr.GetGuid("aToID"); + mViewed = dr.GetBoolean("aViewed"); + mReplied = dr.GetBoolean("aReplied"); - } - - #endregion update - - #region Delete - - /// - /// Remove a Memo record from the database - /// - /// - protected override void DataPortal_Delete(object Criteria) - { - + } + finally + { + if (dr != null) dr.Close(); + } + MarkOld(); - Criteria crit = (Criteria)Criteria; - //Delete object - DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aMemo WHERE aID = @ID;"); - cmDelete.AddInParameter("@ID",DbType.Guid,crit.ID); + //Get access rights level + bReadOnly = AyaBizUtils.Right("Object.Memo") < (int)SecurityLevelTypes.ReadWrite; + } - using (IDbConnection connection = DBUtil.DB.GetConnection()) - { - connection.Open(); - IDbTransaction transaction = connection.BeginTransaction(); + #endregion fetch - try - { - - DBUtil.DB.ExecuteNonQuery(cmDelete, transaction); - DBUtil.RemoveKeywords(transaction,RootObjectTypes.Memo,crit.ID); - - // Commit the transaction - transaction.Commit(); - - } - catch - { - // Rollback transaction - transaction.Rollback(); - throw; - } - finally - { - connection.Close(); - } + #region Update + /// + /// Called by DataPortal to delete/add/update data into the database + /// + protected override void DataPortal_Update() + { + //If not a new record, check if record was modified + //by another user since original retrieval: + if (!IsNew) + DBUtil.CheckSafeToUpdate(this.mModified.Date, this.mID, "aMemo"); - //Remove any events for this object + #region Delete + if (IsDeleted) + { + throw new System.Security.SecurityException( + string.Format( + LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"), + LocalizedTextTable.GetLocalizedTextDirect("O.Memo"))); + // if(!IsNew) + // { + // + // + // //Delete object and child objects + // DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aMemo WHERE aID = @ID;"); + // cmDelete.AddInParameter("@ID",DbType.Guid,this.mID); + // + // + // + // using (IDbConnection connection = DBUtil.DB.GetConnection()) + // { + // connection.Open(); + // IDbTransaction transaction = connection.BeginTransaction(); + // + // try + // { + // + // DBUtil.DB.ExecuteNonQuery(cmDelete, transaction); + // DBUtil.RemoveKeywords(transaction,RootObjectTypes.Memo,this.mID); + // + // // 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 aMemo (aID, aSubject, aMessage, aFromID, aToID, aViewed, aReplied, aCreator,aModifier,aCreated, aModified) " + + "VALUES (@ID,@Subject,@Message,@FromID,@ToID,@Viewed,@Replied,@CurrentUserID,@CurrentUserID,@Created,@Modified);" + ); + else + cm = DBUtil.GetCommandFromSQL( + "UPDATE aMemo SET aID=@ID, aSubject=@Subject, aMessage=@Message, " + + "aFromID=@FromID, aToID=@ToID, aViewed=@Viewed, " + + "aModifier=@CurrentUserID, aModified=@Modified " + + "WHERE aID=@ID;" + ); + + + cm.AddInParameter("@ID", DbType.Guid, mID); + cm.AddInParameter("@Subject", DbType.String, mSubject); + cm.AddLargeStringInParameter("@Message", mMessage); + cm.AddInParameter("@FromID", DbType.Guid, mFromID); + cm.AddInParameter("@ToID", DbType.Guid, mToID); + cm.AddInParameter("@Viewed", DbType.Boolean, mViewed); + cm.AddInParameter("@Replied", DbType.Boolean, false); + + //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)); + + + + using (IDbConnection connection = DBUtil.DB.GetConnection()) + { + connection.Open(); + IDbTransaction transaction = connection.BeginTransaction(); + + try + { + + DBUtil.DB.ExecuteNonQuery(cm, transaction); + + //Process keywords + DBUtil.ProcessKeywords(transaction, this.mID, RootObjectTypes.Memo, IsNew, AyaBizUtils.Break(false, + mSubject, mMessage)); + + 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; + //Process events as necessary + if (AyaBizUtils.GlobalSettings.UseNotification)//Case 509 + { + NotifyEvent.AddOrUpdateEvent(RootObjectTypes.Memo, this.mID, (int)MemoEvent.Created, this.mToID, new SmartDate(), Guid.Empty); + + } + + } + + #endregion + + + } + + #endregion update + + #region Delete + + /// + /// Remove a Memo record from the database + /// + /// + protected override void DataPortal_Delete(object Criteria) + { + + + + Criteria crit = (Criteria)Criteria; + //Delete object + DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aMemo WHERE aID = @ID;"); + cmDelete.AddInParameter("@ID", DbType.Guid, crit.ID); + + using (IDbConnection connection = DBUtil.DB.GetConnection()) + { + connection.Open(); + IDbTransaction transaction = connection.BeginTransaction(); + + try + { + + DBUtil.DB.ExecuteNonQuery(cmDelete, transaction); + DBUtil.RemoveKeywords(transaction, RootObjectTypes.Memo, crit.ID); + + // Commit the transaction + transaction.Commit(); + + } + catch + { + // Rollback transaction + transaction.Rollback(); + throw; + } + finally + { + connection.Close(); + } + + //Remove any events for this object if (AyaBizUtils.GlobalSettings.UseNotification)//Case 510 - { - NotifyEvent.RemoveAllEventsForObject(crit.ID); - } - } - } + { + NotifyEvent.RemoveAllEventsForObject(crit.ID); + } + } + } - #endregion delete - - #endregion + #endregion delete - #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 + #endregion - #region criteria - /// - /// Criteria for identifying existing object - /// - [Serializable] - private class Criteria - { - public Guid ID; - public Criteria(Guid _ID) - { - ID=_ID; - } - - } - #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 Flag MessageReadReplied + #region criteria + /// + /// Criteria for identifying existing object + /// + [Serializable] + private class Criteria + { + public Guid ID; + public Criteria(Guid _ID) + { + ID = _ID; + } + + } + #endregion + + #region Flag MessageReadReplied #pragma warning disable 1591 /// - /// Update eMemo messages - /// - [Serializable, System.ComponentModel.Browsable(false)] - public class MemoFlagger//DO_NOT_OBFUSCATE - { - bool _SetRead=false; - bool _SetReplied=false; - Guid _MemoID; + /// Update eMemo messages + /// + [Serializable, System.ComponentModel.Browsable(false)] + public class MemoFlagger//DO_NOT_OBFUSCATE + { + bool _SetRead = false; + bool _SetReplied = false; + Guid _MemoID; - public MemoFlagger(Guid MemoID, bool SetRead, bool SetReplied) - { - _MemoID=MemoID; - _SetRead = SetRead; - _SetReplied=SetReplied; - } + public MemoFlagger(Guid MemoID, bool SetRead, bool SetReplied) + { + _MemoID = MemoID; + _SetRead = SetRead; + _SetReplied = SetReplied; + } - public static void SetMemoFlags(Guid MemoID, bool SetRead, bool SetReplied) - { - DataPortal.Update(new MemoFlagger( MemoID, SetRead, SetReplied)); - } + public static void SetMemoFlags(Guid MemoID, bool SetRead, bool SetReplied) + { + DataPortal.Update(new MemoFlagger(MemoID, SetRead, SetReplied)); + } - public void DataPortal_Update() - { - DBCommandWrapper cm = null; - if(_SetRead) - cm=DBUtil.GetCommandFromSQL( - "UPDATE aMemo SET aViewed=@TRUE " + - "WHERE aID=@ID;" - ); + public void DataPortal_Update() + { + DBCommandWrapper cm = null; + if (_SetRead) + cm = DBUtil.GetCommandFromSQL( + "UPDATE aMemo SET aViewed=@TRUE " + + "WHERE aID=@ID;" + ); - if(_SetReplied) - cm=DBUtil.GetCommandFromSQL( - "UPDATE aMemo SET aReplied=@TRUE " + - "WHERE aID=@ID;" - ); + if (_SetReplied) + cm = DBUtil.GetCommandFromSQL( + "UPDATE aMemo SET aReplied=@TRUE " + + "WHERE aID=@ID;" + ); - cm.AddInParameter("@ID",DbType.Guid,_MemoID); - cm.AddInParameter("@TRUE", DbType.Boolean, true); + cm.AddInParameter("@ID", DbType.Guid, _MemoID); + cm.AddInParameter("@TRUE", DbType.Boolean, true); - DBUtil.DB.ExecuteNonQuery(cm); + DBUtil.DB.ExecuteNonQuery(cm); - - } + + } } #pragma warning restore 1591 @@ -879,17 +895,18 @@ namespace GZTW.AyaNova.BLL }//end Memo - #region Notification events + #region Notification events /// /// /// - public enum MemoEvent : int - { + public enum MemoEvent : int + { /// /// /// - [Description("LT:Memo.Label.Event.Created")] Created=1 - } - #endregion + [Description("LT:Memo.Label.Event.Created")] + Created = 1 + } + #endregion }//end Subjectspace GZTW.AyaNova.BLL \ No newline at end of file diff --git a/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/MemoList.cs b/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/MemoList.cs index 2901f6e..16c8e15 100644 --- a/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/MemoList.cs +++ b/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/MemoList.cs @@ -20,78 +20,78 @@ namespace GZTW.AyaNova.BLL { #pragma warning disable 1591 /// - /// Lightweight read only list of objects representing object - /// - /// - [Serializable] - public class MemoList : ReadOnlyCollectionBase - { + /// Lightweight read only list of objects representing object + /// + /// + [Serializable] + public class MemoList : ReadOnlyCollectionBase + { - - #region Data structure - /// - /// Properties - /// - [Serializable] - public struct MemoListInfo - { - internal Guid mID; - internal SmartDate mCreated; - internal GridRelativeTimeCellItem mCreatedRelative; + + #region Data structure + /// + /// Properties + /// + [Serializable] + public struct MemoListInfo + { + internal Guid mID; + internal SmartDate mCreated; + internal GridRelativeTimeCellItem mCreatedRelative; internal GridNameValueCellItem mSubject; - internal string mMessage; - internal GridNameValueCellItem mFrom; - //internal Guid mFrom; - internal bool mViewed; - internal bool mReplied; + internal string mMessage; + internal GridNameValueCellItem mFrom; + //internal Guid mFrom; + internal bool mViewed; + internal bool mReplied; - //ID Not localized as it's an invisible field + //ID Not localized as it's an invisible field [Display(DisplayType.Hidden)] - public Guid ID - { - get - { - return mID; - } - } + public Guid ID + { + get + { + return mID; + } + } - [SqlColumnNameAttribute("aMemo.aCreated"), Display(DisplayType.DateTime)] - public object LT_Memo_Label_Sent - { - get - { - return mCreated.DBValue; - } - } + [SqlColumnNameAttribute("aMemo.aCreated"),Display(DisplayType.DateTime)] + public object LT_Memo_Label_Sent + { + get + { + return mCreated.DBValue; + } + } [SqlColumnNameAttribute("grid"), Display(DisplayType.Text)] - public GridRelativeTimeCellItem LT_Memo_Label_Sent_Relative - { - get - { - return mCreatedRelative; - } - } + public GridRelativeTimeCellItem LT_Memo_Label_Sent_Relative + { + get + { + return mCreatedRelative; + } + } [SqlColumnNameAttribute("aUser.aLastName", "aMemo.aFromID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Client)] - public GridNameValueCellItem LT_Memo_Label_FromID - { - get - { - return mFrom; - } - } + public GridNameValueCellItem LT_Memo_Label_FromID + { + get + { + return mFrom; + } + } [SqlColumnNameAttribute("aMemo.aSubject", "aMemo.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Memo)] public GridNameValueCellItem LT_Memo_Label_Subject - { - get - { - return mSubject; - } - } + { + get + { + return mSubject; + } + } [Display(DisplayType.Hidden)] public string LT_Memo_Label_Message @@ -103,118 +103,118 @@ namespace GZTW.AyaNova.BLL } [SqlColumnNameAttribute("aMemo.aViewed"), Display(DisplayType.Hidden)]//case 1805 added column name attribute so can set criteria for dashboard - public bool LT_Memo_Label_Viewed - { - get - { - return mViewed; - } - } + public bool LT_Memo_Label_Viewed + { + get + { + return mViewed; + } + } //Special control, i.e. in this case image checkbox showing replied graphic or not replied graphic [Display(DisplayType.SpecialControl)] - public bool LT_Memo_Label_Replied - { - get - { - return this.mReplied; - } - } + public bool LT_Memo_Label_Replied + { + get + { + return this.mReplied; + } + } + + + + /// + /// + /// + /// + public bool Equals(MemoListInfo obj) + { + return this.ID.Equals(obj.ID); + } + + }//end MemoListInfo + #endregion + + #region Constructor + private RelativeTimeFormatter rtfm=null; + + protected MemoList() + { + + rtfm=RelativeTimeFormatter.GetItem(User.CurrentUserLanguage); + // AllowSort=false; + // AllowFind=true; + // AllowEdit=false; + // AllowNew=false; + // AllowRemove=false; + } + + #endregion + + #region Business properties and methods + + /// + /// Get item by index + /// + /// + public MemoListInfo this[int Item] + { + + get + { + return (MemoListInfo) List[Item]; + } + } + /// + /// Returns display text that matches passed in itemid value + /// + /// + public string this[Guid ItemID] + { - /// - /// - /// - /// - public bool Equals(MemoListInfo obj) - { - return this.ID.Equals(obj.ID); - } + get + { + foreach (MemoListInfo child in List) + { + if(child.ID==ItemID) return child.ToString(); + } + return "Missing: "+ItemID.ToString(); + } + } + #endregion - }//end MemoListInfo - #endregion + #region contains + /// + /// Check if item in collection + /// + /// + public bool Contains(MemoListInfo obj) + { + foreach (MemoListInfo child in List) + { + if(child.Equals(obj)) return true; + } + return false; - #region Constructor - private RelativeTimeFormatter rtfm = null; - - protected MemoList() - { - - rtfm = RelativeTimeFormatter.GetItem(User.CurrentUserLanguage); - // AllowSort=false; - // AllowFind=true; - // AllowEdit=false; - // AllowNew=false; - // AllowRemove=false; - } - - #endregion - - #region Business properties and methods - - /// - /// Get item by index - /// - /// - public MemoListInfo this[int Item] - { - - get - { - return (MemoListInfo)List[Item]; - } - } - - - /// - /// Returns display text that matches passed in itemid value - /// - /// - public string this[Guid ItemID] - { - - get - { - foreach (MemoListInfo child in List) - { - if (child.ID == ItemID) return child.ToString(); - } - return "Missing: " + ItemID.ToString(); - } - } - #endregion - - #region contains - /// - /// Check if item in collection - /// - /// - public bool Contains(MemoListInfo obj) - { - foreach (MemoListInfo child in List) - { - if (child.Equals(obj)) return true; - } - return false; - - } - #endregion + } + #endregion #region Reporting and shared UI editor helpers /// - /// Returns the report key which is a property of - /// reports used to link all reports that can be used - /// with a particular data source. - /// - public static string ReportKey - { - get - { - return "MemoList"; - } - } + /// Returns the report key which is a property of + /// reports used to link all reports that can be used + /// with a particular data source. + /// + public static string ReportKey + { + get + { + return "MemoList"; + } + } /// /// Returns the Detailed report key @@ -298,9 +298,9 @@ namespace GZTW.AyaNova.BLL } } - #endregion + #endregion - #region Static methods + #region Static methods /// /// Internal method used by list factory @@ -310,16 +310,16 @@ namespace GZTW.AyaNova.BLL return (MemoList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords)); } - /// - /// Get all Memo (filtered by crit) - /// - /// Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code + /// + /// Get all Memo (filtered by crit) + /// + /// Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code /// list of objects - - public static MemoList GetList(string xmlCriteria) - { + + public static MemoList GetList(string xmlCriteria) + { return (MemoList)DataPortal.Fetch(new Criteria(xmlCriteria, null, -1)); - } + } /// /// Takes a single ID and returns a "list" of one object @@ -349,75 +349,62 @@ namespace GZTW.AyaNova.BLL return (MemoList)DataPortal.Fetch(new Criteria("", IDList, -1)); } - /// - /// Return an empty list - /// used for initializing grid - /// - /// - public static MemoList GetEmptyList() - { - return new MemoList(); - } + /// + /// Return an empty list + /// used for initializing grid + /// + /// + public static MemoList GetEmptyList() + { + return new MemoList(); + } - #endregion + #endregion - #region DAL DATA ACCESS - /// - /// - protected override void DataPortal_Fetch(object Criteria) - { + #region DAL DATA ACCESS + /// + /// + protected override void DataPortal_Fetch(object Criteria) + { + + Criteria crit = (Criteria)Criteria; - Criteria crit = (Criteria)Criteria; - - SafeDataReader dr = null; + SafeDataReader dr = null; DateTime dtNow = DBUtil.CurrentWorkingDateTime; - try - { + try + { if (crit.IDList != null) { - //v8 Migrate related change - //this is a workaround to get all the memos even though the current user is not the recipient of all of them - if (crit.IDList.Count == 1 && crit.IDList[0] == new Guid("{BD608E8A-820C-46D1-9D81-4CCB6E71B213}"))//v8 migrate plugin id + //Case 556 + System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); + sbIN.Append(" WHERE (aMemo.aID in ("); + foreach (Guid gItem in crit.IDList) { - dr = DBUtil.GetReaderFromSQLString( - "SELECT aMemo.aID, aMemo.aCreated, " + - "aMemo.aViewed, aMemo.aReplied, aMemo.aSubject, aMemo.aMessage, " + - "aMemo.aFromID, aMemo.aToId, " + - "'first' as afirstname, 'last' as alastname, 'ii' as ainitials, 'en' as aemployeenumber, 'r' as aregionname " + - "FROM aMemo order by amemo.acreated"); + sbIN.Append("'"); + sbIN.Append("{"); + sbIN.Append(gItem.ToString().ToUpperInvariant()); + sbIN.Append("}"); + sbIN.Append("',"); } - else - { - //Case 556 - System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); - sbIN.Append(" WHERE (aMemo.aID in ("); - foreach (Guid gItem in crit.IDList) - { - sbIN.Append("'"); - sbIN.Append("{"); - sbIN.Append(gItem.ToString().ToUpperInvariant()); - sbIN.Append("}"); - sbIN.Append("',"); - } - sbIN.Length = sbIN.Length - 1; - sbIN.Append(")) "); - - //************************************************************ - dr = DBUtil.GetReaderFromSQLString( - "SELECT aMemo.aID, aMemo.aCreated, " + - "aMemo.aViewed, aMemo.aReplied, aMemo.aSubject, aMemo.aMessage, " + - "aMemo.aFromID, aUser.aFirstName, aUser.aLastName, aUser.aInitials, AREGION.ANAME AS AREGIONNAME, " + - "aUser.aEmployeeNumber FROM aMemo " + - - " LEFT OUTER JOIN aUser ON aMemo.aFromID = aUser.aID " + - " LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " + - sbIN.ToString() + " " + - AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)); - } - - + sbIN.Length = sbIN.Length - 1; + sbIN.Append(")) "); + + //************************************************************ + dr = DBUtil.GetReaderFromSQLString( + "SELECT aMemo.aID, aMemo.aCreated, " + + "aMemo.aViewed, aMemo.aReplied, aMemo.aSubject, aMemo.aMessage, " + + "aMemo.aFromID, aUser.aFirstName, aUser.aLastName, aUser.aInitials, AREGION.ANAME AS AREGIONNAME, " + + "aUser.aEmployeeNumber FROM aMemo " + + + " LEFT OUTER JOIN aUser ON aMemo.aFromID = aUser.aID " + + " LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " + + sbIN.ToString() + " " + + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)); + + + } else { @@ -426,7 +413,7 @@ namespace GZTW.AyaNova.BLL "aMemo.aViewed, aMemo.aReplied, aMemo.aSubject, aMemo.aMessage, " + "aMemo.aFromID, aUser.aFirstName, aUser.aLastName, aUser.aInitials, AREGION.ANAME AS AREGIONNAME, " + "aUser.aEmployeeNumber FROM aMemo " + - + " LEFT OUTER JOIN aUser ON aMemo.aFromID = aUser.aID " + " LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " + "WHERE (aMemo.aToID = @ID) " + @@ -441,45 +428,45 @@ namespace GZTW.AyaNova.BLL dr = DBUtil.GetReaderFromSQLString(q, CurrentUserID); } - while (dr.Read()) - { - //******************************************* - MemoListInfo info = new MemoListInfo(); + while(dr.Read()) + { + //******************************************* + MemoListInfo info=new MemoListInfo(); - info.mID = dr.GetGuid("aID"); - - info.mCreated = DBUtil.ToLocal(dr.GetSmartDate("aCreated")); - info.mCreatedRelative = new GridRelativeTimeCellItem(rtfm.Format(dtNow, info.mCreated)); - info.mFrom = new GridNameValueCellItem( - dr.GetGuid("aFromID"), - User.NameFormatter(dr.GetString("aFirstName"), dr.GetString("aLastName"), dr.GetString("aInitials"), + info.mID=dr.GetGuid("aID"); + + info.mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated")); + info.mCreatedRelative = new GridRelativeTimeCellItem(rtfm.Format(dtNow,info.mCreated)); + info.mFrom=new GridNameValueCellItem( + dr.GetGuid("aFromID"), + User.NameFormatter(dr.GetString("aFirstName"),dr.GetString("aLastName"),dr.GetString("aInitials"), dr.GetString("aEmployeeNumber"), dr.GetString("AREGIONNAME"), AyaBizUtils.GlobalSettings.DefaultScheduleableUserNameDisplayFormat) - , RootObjectTypes.User); + ,RootObjectTypes.User); info.mSubject = new GridNameValueCellItem( dr.GetGuid("aID"), - dr.GetString("aSubject"), + dr.GetString("aSubject"), RootObjectTypes.Memo); - - info.mViewed = dr.GetBoolean("aViewed"); - info.mReplied = dr.GetBoolean("aReplied"); + + info.mViewed=dr.GetBoolean("aViewed"); + info.mReplied=dr.GetBoolean("aReplied"); info.mMessage = dr.GetString("aMessage"); + + InnerList.Add(info); + //******************************************* + } + } + finally + { + if(dr!=null) dr.Close(); + } - InnerList.Add(info); - //******************************************* - } - } - finally - { - if (dr != null) dr.Close(); - } + + } + #endregion - - } - #endregion - - #region criteria + #region criteria /// /// Criteria for identifying existing object /// @@ -496,8 +483,8 @@ namespace GZTW.AyaNova.BLL MaxRecords = _MaxRecords; } } - #endregion - - }//end MemoList + #endregion + + }//end MemoList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL \ No newline at end of file diff --git a/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/UserMemoIdList.cs b/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/UserMemoIdList.cs new file mode 100644 index 0000000..4a5b34b --- /dev/null +++ b/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/UserMemoIdList.cs @@ -0,0 +1,188 @@ +/////////////////////////////////////////////////////////// +// UserMemoIdList.cs +// Implementation of Class UserMemoIdList +// CSLA type: Read only collection +// Created on: 11-Dec-2008 +// Object design: John +// Coded: 11-Dec-2008 +/////////////////////////////////////////////////////////// + +using System; +using System.Data; +using GZTW.Data; +using CSLA.Data; +using CSLA; + +namespace GZTW.AyaNova.BLL +{ + /// + /// List of UserMemoIds for internal migration processing + /// + /// + [Serializable] + public class UserMemoIdList : ReadOnlyCollectionBase + { + #region Data structure + /// + /// + /// + [Serializable] + public struct UserMemoIdListInfo + { + + public Guid mID; + + + /// + /// + /// + /// + public bool Equals(UserMemoIdListInfo obj) + { + return this.mID.Equals(obj.mID); + } + + }//end UserMemoIdListInfo + #endregion + + #region Constructor + + protected UserMemoIdList() + { + // AllowSort=false; + // AllowFind=true; + // AllowEdit=false; + // AllowNew=false; + // AllowRemove=false; + } + + #endregion + + #region Business properties and methods + + /// + /// Get item by index + /// + /// + public UserMemoIdListInfo this[int Item] + { + + get + { + return (UserMemoIdListInfo)List[Item]; + } + } + + + /// + /// Returns UserMemoIdListInfo item that matches passed in itemid value + /// + /// + public UserMemoIdListInfo this[Guid ItemID] + { + + get + { + foreach (UserMemoIdListInfo child in List) + { + if (child.mID == ItemID) return child; + } + throw new ArgumentException("UserMemoIdList: ID not found:\r\n" + ItemID.ToString()); + + } + } + #endregion + + #region contains + /// + /// Check if item in collection + /// + /// + public bool Contains(UserMemoIdListInfo obj) + { + foreach (UserMemoIdListInfo child in List) + { + if (child.Equals(obj)) return true; + } + return false; + + } + #endregion + + #region Static methods + /// + /// Get all for user + /// + /// + + public static UserMemoIdList GetList(Guid UserId) + { + return (UserMemoIdList)DataPortal.Fetch(new Criteria(UserId)); + } + + + + + #endregion + + #region DAL DATA ACCESS + /// + /// + protected override void DataPortal_Fetch(object Criteria) + { + Criteria crit = (Criteria)Criteria; + SafeDataReader dr = null; + try + { + //case 1163 + //SmartDate rightnow=new SmartDate(DateTime.Now); + DateTime dtNowUTC = DateTime.Now.ToUniversalTime(); + + dr = DBUtil.GetReaderFromSQLString( + //************************************************************ + "SELECT AMEMO.AID FROM AMEMO WHERE ATOID=@ID",crit.ID + //************************************************************ + ) + ; + + + while (dr.Read()) + { + //******************************************* + UserMemoIdListInfo info = new UserMemoIdListInfo(); + info.mID = dr.GetGuid("aID"); + + InnerList.Add(info); + //******************************************* + } + } + finally + { + if (dr != null) dr.Close(); + } + + + } + #endregion + + #region criteria + /// + /// Criteria for identifying existing object + /// + [Serializable] + private class Criteria + { + + + public Guid ID; + public Criteria(Guid _ID) + { + ID = _ID; + } + + } + #endregion + + }//end UserMemoIdList + +}//end namespace GZTW.AyaNova.BLL \ No newline at end of file