using System; using Ease.Core.Model; using Ease.Core.Utility; namespace HRM.BO { public abstract class AuditTrailBase : ObjectTemplate { #region Declaration & Constructor protected int _createdBy; protected int? _modifiedBy; protected DateTime _createdDate; protected DateTime? _modifiedDate; public AuditTrailBase() { _modifiedBy = null; _modifiedDate = null; _createdBy = int.MinValue; _createdDate = DateTime.Today; } #endregion #region Properties public int CreatedBy { set { _createdBy = value; } get { return _createdBy; } } public DateTime CreatedDate { set { _createdDate = value; } get { return _createdDate; } } public int? ModifiedBy { set { _modifiedBy = value; } get { return _modifiedBy; } } public DateTime? ModifiedDate { set { _modifiedDate = value; } get { return _modifiedDate; } } #endregion #region Functions public virtual void SetAuditTrailProperties(DateTime auTime, int userID) { if (IsNew) { _createdBy = userID; _createdDate = auTime; } _modifiedBy = userID; _modifiedDate = auTime; } protected virtual void SetAuditTrailProperties() { //if (UserSP.CurrentUser != null) // this.SetAuditTrailProperties(GlobalFunctions.GetOperationDate(), UserSP.CurrentUser.ID); //else // this.SetAuditTrailProperties(GlobalFunctions.GetOperationDate(), User.CurrentUser.ID); } public AuditTrailBase CopyObject() { AuditTrailBase atb = ObjectUtility.CreateInstance(GetType().FullName, new object[] { }, GetType()) as AuditTrailBase; //foreach (FieldInfo fi in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) // fi.SetValue(atb, fi.GetValue(this)); return atb; } public void SetObjectID(int id) { this.SetID(id); } #endregion } #region Payroll public abstract class BasicBaseObject : AuditTrailBase { protected int _sequence; protected EnumStatus _status; protected int _IDInteger; public int Sequence { get { return this._sequence; } set { if (this._sequence != value) { this._sequence = value; } } } public int IDInteger { get { if (this.ID <= 0) return 0; else return this.ID; } } public virtual EnumStatus Status { get { return this._status; } set { this._status = value; } } protected virtual void SetBasicBaseObject(DateTime auTime, int userID) { base.SetAuditTrailProperties(auTime, userID); if (this._sequence <= 0) { throw new ServiceException("Sequence can not be zero."); } } public int GetNextSequence(string tableName) { int sequence = 0; return sequence; } public void UpdateStatus(string tableName, EnumStatus status) { } protected override void SetAuditTrailProperties() { //if (base.IsNew == true && _status != EnumStatus.Active) //base.SetAuditTrailProperties(DateTime.Today, User.CurrentUser.ID); base.SetAuditTrailProperties(DateTime.Today, 1); } public void SetAuditTrails() { //base.SetAuditTrailProperties(DateTime.Today, User.CurrentUser.ID); base.SetAuditTrailProperties(DateTime.Today, 1); } protected virtual void SetBasicBaseObjectProperties() { // this.SetAuditTrailProperties(GlobalFunctions.GetOperationDate(), User.CurrentUser.ID); } } public abstract class UpdateAuditTrail : ObjectTemplate { protected int? _modifiedBy; protected DateTime? _modifiedDate; public int? ModifiedBy { get { return this._modifiedBy; } set { if (this._modifiedBy != value) this._modifiedBy = value; } } public DateTime? ModifiedDate { get { return this._modifiedDate; } set { if (this._modifiedDate != value) this._modifiedDate = value; } } protected virtual void SetAuditTrailProperties(DateTime auTime, int userID) { if (!this.IsNew) { _modifiedBy = userID; _modifiedDate = auTime; } } protected virtual void SetAuditTrailProperties() { //this.SetAuditTrailProperties(GlobalFunctions.GetOperationDate(), User.CurrentUser.ID); } } #endregion }