Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/NotifyPopUp.cs
2018-06-29 19:47:36 +00:00

198 lines
4.8 KiB
C#

///////////////////////////////////////////////////////////
// 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
/// <summary>
/// AyaNova NotifyPopUp used to insert new
/// notification popup messages into the queue
/// </summary>
[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
/// <summary>
/// Private constructor to prevent direct instantiation
/// </summary>
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;
}
/// <summary>
/// paramaterless constructor used for DeleteItem static method call
/// </summary>
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));
}
/// <summary>
/// Delete popup message
/// </summary>
/// <param name="_ID"></param>
public static void DeleteItem(Guid _ID)
{
DataPortal.Delete(new Criteria(_ID));
}
#endregion
#region DAL DATA ACCESS
#region Update
/// <summary>
/// Called by DataPortal to delete/add/update data into the database
/// </summary>
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
/// <summary>
/// Remove a Client record .
/// </summary>
/// <param name="Criteria"></param>
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
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[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