79 lines
3.2 KiB
C#
79 lines
3.2 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.UpdateLog;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.UpdateLog
|
|
{
|
|
//=======================================================================
|
|
public class SbmUpdateLogItemMonitor : SaUpdateLogItemMonitor
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Configuration.
|
|
public new class Config : SaUpdateLogItemMonitor.Config
|
|
{
|
|
public Config(SbmInternals internals) :
|
|
base(internals.UpdateLogConsole, internals.DbUpdateInfo)
|
|
{
|
|
Internals = internals;
|
|
}
|
|
public SbmInternals Internals { get; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Config config;
|
|
private SbmSessionConsole sessionConsole { get { return config.Internals.SessionConsole; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SbmUpdateLogItemMonitor(Config config) : base(config)
|
|
{
|
|
this.config = config;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public ISbmUserOrganisationContext UserContext { get { return config.Internals.UserContext; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Internal utilities.
|
|
protected virtual bool IsColumnChangeLogged(SbmDbDfn.ColumnIdx columnIdx)
|
|
{
|
|
if (!config.UpdateLogConsole.CanUpdateDatabase) return false;
|
|
if (!sessionConsole.IsColumnChangeLogged(UserContext, columnIdx)) return false;
|
|
return true;
|
|
}
|
|
protected bool RecordAttrValue(SbmDbDfn.ColumnIdx columnIdx, String value, bool newValue)
|
|
{
|
|
return RecordAttrValue(columnIdx, new DataValue(value), newValue);
|
|
}
|
|
protected bool RecordAttrValue(SbmDbDfn.ColumnIdx columnIdx, int value, bool newValue, bool blankZeroValue = true)
|
|
{
|
|
return RecordAttrValue(columnIdx, new DataValue(value == 0 && blankZeroValue ? "" : value.ToString()), newValue);
|
|
}
|
|
protected bool RecordAttrValue(SbmDbDfn.ColumnIdx columnIdx, decimal value, bool newValue, bool blankZeroValue = true, ushort decimals = 2)
|
|
{
|
|
return RecordAttrValue(columnIdx, new DataValue(value == 0.0m && blankZeroValue ? "" : value.ToString("N" + decimals.ToString())), newValue);
|
|
}
|
|
protected bool RecordAttrValue(SbmDbDfn.ColumnIdx columnIdx, DateTime value, bool newValue, bool includeTime = true)
|
|
{
|
|
return RecordAttrValue(columnIdx, new DataValue(DateUtil.Format(value, (includeTime ? "d-MMM-yyyy HH:mm" : "d-MMM-yyyy"))), newValue);
|
|
}
|
|
protected bool RecordAttrValue(SbmDbDfn.ColumnIdx columnIdx, DataValue value, bool newValue)
|
|
{
|
|
ClearErrorState();
|
|
if (!IsColumnChangeLogged(columnIdx)) return true;
|
|
String attrName = SbmDbDfn.GetColumnName(columnIdx, false);
|
|
if (attrName.IsEmpty()) return SetErrorState("Blank attribute name [" + columnIdx.ToString() + "]");
|
|
return RecordAttrValue(attrName, value, newValue);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|