/////////////////////////////////////////////////////////// // NotifyPopUp.cs // Implementation of Class NotifyPopUp // CSLA type: Editable Root // Created on: 18-Oct-2005 // Object design: John // Coded: John 18-Oct-2005 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using GZTW.Data; using CSLA; using System.Threading; using CSLA.Security; namespace GZTW.AyaNova.BLL { #pragma warning disable 1591 /// /// AyaNova NotifyPopUp used to insert new /// notification popup messages into the queue /// [Serializable] public class NotifyPopUp : BusinessBase { #region Attributes private Guid _ID; private string _Message; private Guid _ToUserID; private Guid _RootObjectID; private RootObjectTypes _RootObjectType; private DateTime _DeliveryDate; #endregion #region Constructor /// /// Private constructor to prevent direct instantiation /// private NotifyPopUp(RootObjectTypes RootObjectType,Guid RootObjectID, Guid ToUserID,string Message) { _ID=Guid.NewGuid(); _DeliveryDate = DBUtil.CurrentWorkingDateTime; _RootObjectType=RootObjectType; _RootObjectID=RootObjectID; _ToUserID=ToUserID; if(Message.Length>4000) _Message=Message.Substring(0,4000); else _Message=Message; } /// /// paramaterless constructor used for DeleteItem static method call /// private NotifyPopUp() { } #endregion #region Static methods public static void SendPopUp(RootObjectTypes RootObjectType,Guid RootObjectID, Guid ToUserID,string Message) { DataPortal.Update(new NotifyPopUp(RootObjectType, RootObjectID,ToUserID, Message)); } /// /// Delete popup message /// /// public static void DeleteItem(Guid _ID) { DataPortal.Delete(new Criteria(_ID)); } #endregion #region DAL DATA ACCESS #region Update /// /// Called by DataPortal to delete/add/update data into the database /// protected override void DataPortal_Update() { //This might become a feature in future to remove old entries to //stop them from piling up when someone is away etc // //Remove any entries older than 30 days // DBCommandWrapper cmTrim = DBUtil.GetCommandFromSQL( // "DELETE FROM aNotifyPopUp " + // "WHERE (aDeliveryDate < @THIRTYDAYSAGO)" // ); // cmTrim.AddInParameter("@THIRTYDAYSAGO",DbType.DateTime,DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime.AddDays(-30))); // // DBUtil.DB.ExecuteNonQuery(cmTrim); // //Insert log entry DBCommandWrapper cm = DBUtil.GetCommandFromSQL( "INSERT INTO aNotifyPopUp (aID, aRootObjectType, aRootObjectID, " + "aDeliveryDate, aToUserID, aMessage ) " + "VALUES (@ID, @RootObjectType,@RootObjectID, " + "@DeliveryDate, @ToUserID, @Message )" ); cm.AddInParameter("@RootObjectID",DbType.Guid,this._RootObjectID); cm.AddInParameter("@ID",DbType.Guid,this._ID); cm.AddInParameter("@RootObjectType",DbType.Int16,(int)this._RootObjectType); cm.AddInParameter("@ToUserID",DbType.Guid,this._ToUserID); cm.AddInParameter("@DeliveryDate",DbType.DateTime, DBUtil.ToUTC(this._DeliveryDate)); cm.AddInParameter("@Message",DbType.String,this._Message); DBUtil.DB.ExecuteNonQuery(cm); } #endregion #region Delete /// /// Remove a Client record . /// /// protected override void DataPortal_Delete(object Criteria) { Criteria crit = (Criteria)Criteria; //Delete object and child objects DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aNotifyPopUp 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); // Commit the transaction transaction.Commit(); } catch { // Rollback transaction transaction.Rollback(); throw; } finally { connection.Close(); } } } #endregion delete #endregion dal data access #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Guid ID; public Criteria(Guid _ID) { ID=_ID; } } #endregion }//end NotifyPopUp #pragma warning restore 1591 }//end Subjectspace GZTW.AyaNova.BLL