Files
Common-VS2019/SacsBusinessDbas/Dbas/UpdateLog/SaUpdateLogConsole_Dbas.cs
T

141 lines
4.8 KiB
C#

using System;
using System.Collections.Generic;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Dbas;
using Sarand.Net.Standard.Base.UpdateLog;
namespace Sarand.Net.Standard.Dbas.UpdateLog
{
//=======================================================================
public abstract class SaUpdateLogConsole_Dbas : SaUpdateLogConsole
{
//-------------------------------------------------------------------
// Data members.
private SaUpdateLogMgr_Dbas updateLogMgr = null;
//-------------------------------------------------------------------
// Static initialisation.
static SaUpdateLogConsole_Dbas ()
{
}
//-------------------------------------------------------------------
// Construction.
protected SaUpdateLogConsole_Dbas (ISacsDatabase database)
{
Database = database;
updateLogMgr = new SaUpdateLogMgr_Dbas(this);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (updateLogMgr != null) updateLogMgr.Dispose(); updateLogMgr = null;
}
base.Dispose(disposing);
}
//-------------------------------------------------------------------
// Properties.
internal ISacsDatabase Database { get; set; }
public override bool DatabaseIsValid { get { return updateLogMgr.DatabaseIsValid; } }
public override bool CanUpdateDatabase { get { return updateLogMgr.CanUpdateDatabase; } }
//-------------------------------------------------------------------
// Update Log form.
public override bool ShowUpdateLogDialog (ShowUpdateLogConfig config)
{
ClearErrorState();
if (ShowUpdateLogDialogFn != null)
ShowUpdateLogDialogFn(this, config);
return false;
}
// Method to display Update Log dialog.
protected delegate bool ShowUpdateLogDialogFunction (SaUpdateLogConsole codeTypeConsole, ShowUpdateLogConfig config);
protected abstract ShowUpdateLogDialogFunction ShowUpdateLogDialogFn { get; }
//*******************************************************************
// U p d a t e L o g E n t r i e s
//*******************************************************************
// Log updates.
public override bool LogUpdates (SaUpdateLogItemMonitor updateLogItemMonitor)
{
ClearErrorState();
if (!updateLogMgr.LogUpdates(updateLogItemMonitor, updateLogItemMonitor.DbUpdateInfo))
SetErrorState(updateLogMgr.ErrorStateMessage);
return OK;
}
//-------------------------------------------------------------------
// Retrieve list of updates that match the specified params:
public override bool ItemHasLogEntries (ItemId itemId)
{
ClearErrorState();
SaUpdateLogEntry.Params prmUpdateLog = new SaUpdateLogEntry.Params();
prmUpdateLog.IncludedItemIds.Add(itemId);
return LogEntriesExist(prmUpdateLog);
}
public override bool LogEntriesExist (SaUpdateLogEntry.Params prmUpdateLog)
{
ClearErrorState();
return (updateLogMgr.GetLogEntryCount(prmUpdateLog) > 0);
}
public override long GetLogEntryCount (SaUpdateLogEntry.Params prmUpdateLog)
{
ClearErrorState();
return updateLogMgr.GetLogEntryCount(prmUpdateLog);
}
public override SaUpdateLogEntry GetLogEntry (ItemId itemId, String attrName, DateTime loggedAt)
{
ClearErrorState();
return updateLogMgr.GetLogEntry(itemId, attrName, loggedAt);
}
public override List<SaUpdateLogEntry> GetLogEntries (SaUpdateLogEntry.Params prmUpdateLog)
{
ClearErrorState();
return updateLogMgr.GetLogEntryList(prmUpdateLog);
}
//-------------------------------------------------------------------
// Create a new item data.
public override SaUpdateLogEntry CreateLogEntry (ItemId itemId, String attrName)
{
ClearErrorState();
return updateLogMgr.CreateLogEntry(itemId, attrName);
}
//-------------------------------------------------------------------
// Store item data.
public override bool StoreLogEntry (SaUpdateLogEntry logEntry, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (updateLogMgr.LogEntryExists(logEntry))
{
if (!updateLogMgr.InsertLogEntry(logEntry, dbUpdateInfo))
SetErrorState(updateLogMgr.ErrorStateMessage);
}
else
{
if (!updateLogMgr.UpdateLogEntry(logEntry, dbUpdateInfo))
SetErrorState(updateLogMgr.ErrorStateMessage);
}
return OK;
}
public override bool RemoveLogEntry (SaUpdateLogEntry logEntry, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
throw new NotSupportedException("Update Log Entries can not be removed");
}
public override bool ClearLogEntriesForItem (ItemId itemId, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!updateLogMgr.ClearLogEntriesForItem(itemId, dbUpdateInfo))
SetErrorState(updateLogMgr.ErrorStateMessage);
return !HasErrorState ();
}
//-------------------------------------------------------------------
}
//=======================================================================
}