495 lines
22 KiB
C#
495 lines
22 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
|
using Sarand.BusinessMgr.Net.Standard.Dbas.Bus;
|
|
using Sarand.BusinessMgr.Net.Standard.Dbas.Internal;
|
|
using Sarand.BusinessMgr.Net.Standard.Dbas.UpdateLog;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Sarand.Net.Standard.Dbas.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Mgr
|
|
{
|
|
//=======================================================================
|
|
partial class SbmAssetMgr_Dbas
|
|
{
|
|
//*******************************************************************
|
|
// A s s e t C a t e g o r y
|
|
//*******************************************************************
|
|
// Utilities.
|
|
private List<StringPair> GetLogProperties(SbmAssetProcess assetProcess)
|
|
{
|
|
return new List<StringPair>()
|
|
{
|
|
new StringPair("Id",SysId.ToString(assetProcess.Id)),
|
|
new StringPair("Seq",assetProcess.Seq),
|
|
new StringPair("Status",assetProcess.StatusCode)
|
|
};
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get AssetProcess.
|
|
public override SbmAssetProcess GetAssetProcess(SbmAssetProcess.Params prm)
|
|
{
|
|
return GetAssetProcess(GetAssetProcessQueryFilter(prm).Concat(" AND ", "(", ")"));
|
|
}
|
|
private SbmAssetProcess GetAssetProcess(String filter)
|
|
{
|
|
ClearErrorState();
|
|
long count = GetAssetProcessCount(filter);
|
|
if (count == 0) return null;
|
|
if (count != 1)
|
|
{
|
|
SetErrorState("Multiple Asset Processes found");
|
|
return null;
|
|
}
|
|
SbmAssetProcess assetProcess = null;
|
|
// Query data.
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
SaAssetProcess_Db dbAssetProcess = new SaAssetProcess_Db(DbInfo);
|
|
dbAssetProcess.PopulateFrom(dbCommand, aliasAssetProcess, filter);
|
|
assetProcess = CreateAssetProcess(dbAssetProcess);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SetErrorState("Database query exception");
|
|
SaLogger.Warn(GetType().Name + ".GetAssetProcess\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
|
}
|
|
}
|
|
return assetProcess;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Create AssetProcess.
|
|
public override SbmAssetProcess CreateAssetProcess(Sbm.AssetType assetType)
|
|
{
|
|
ClearErrorState();
|
|
SbmAssetProcess assetProcess = null;
|
|
if (assetType > 0)
|
|
assetProcess = new SbmAssetProcess_Dbas(Internals, new SysId(), null, AffiliateId_Owner, 0);
|
|
else SetErrorState("Asset type not identified");
|
|
return assetProcess;
|
|
}
|
|
private SbmAssetProcess_Dbas CreateAssetProcess(SaAssetProcess_Db dbAssetProcess)
|
|
{
|
|
ClearErrorState();
|
|
SbmAssetProcess_Dbas assetProcess = new SbmAssetProcess_Dbas(Internals, new SysId(dbAssetProcess._Id), new SysId(dbAssetProcess._AssetId), new SysId(dbAssetProcess._ProcessId), (ushort)dbAssetProcess._Flags);
|
|
PopulateFrom(dbAssetProcess, assetProcess);
|
|
return assetProcess;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate AssetProcess.
|
|
public override bool IsValidAssetProcessData(SbmAssetProcess.Data data, SbmAssetProcess.ErrField errField)
|
|
{
|
|
ClearErrorState();
|
|
if (!base.IsValidAssetProcessData(data, errField)) return false;
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Insert AssetProcess.
|
|
public override bool InsertAssetProcess(SbmAssetProcess assetProcess, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".InsertAssetProcess";
|
|
ClearErrorState();
|
|
if (!IsValidAssetProcess(assetProcess)) return false;
|
|
if (SysId.IsValid(assetProcess.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
SaAssetProcess_Db dbAssetProcess = new SaAssetProcess_Db(DbInfo);
|
|
PopulateTo(dbAssetProcess, assetProcess, dbUpdateInfo);
|
|
if (SaAssetProcess_Db.FieldsNonId.Contains("Id"))
|
|
{
|
|
// Generate next Id.
|
|
dbAssetProcess._Id = SysId.ToInt(db.GetNextId("AssetProcess", dbUpdateInfo));
|
|
}
|
|
dbAssetProcess.ExecuteInsertCommand(dbCommand);
|
|
assetProcess.Id = new SysId(dbAssetProcess._Id);
|
|
assetProcess.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Inserted. " + GetLogProperties(assetProcess).Concat(": ").Concat("", "\n\t"));
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Update AssetProcess.
|
|
public override bool UpdateAssetProcess(SbmAssetProcess assetProcess, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".UpdateAssetProcess";
|
|
ClearErrorState();
|
|
if (!IsValidAssetProcess(assetProcess)) return false;
|
|
if (!SysId.IsValid(assetProcess.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
|
if (!assetProcess.Changed)
|
|
{
|
|
if (DebugMode) SaLogger.Debug(fn + " Data not changed. " + GetLogProperties(assetProcess).Concat(": ").Concat("", "\n\t"));
|
|
return true;
|
|
}
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
// Retrieve AssetProcess.
|
|
dbConnection.Open();
|
|
SaAssetProcess_Db dbAssetProcess = new SaAssetProcess_Db(DbInfo);
|
|
dbAssetProcess.PopulateFrom(dbCommand, aliasAssetProcess, "Id=" + SysId.ToString(assetProcess.Id));
|
|
SbmUpdateLogItemMonitor_AssetProcess updateLogMonitor = new SbmUpdateLogItemMonitor_AssetProcess(Internals, CreateAssetProcess(dbAssetProcess));
|
|
|
|
// Update properties.
|
|
PopulateTo(dbAssetProcess, assetProcess, dbUpdateInfo);
|
|
dbAssetProcess.ExecuteUpdateCommand(dbCommand);
|
|
assetProcess.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Updated. " + GetLogProperties(assetProcess).Concat(": ").Concat("", "\n\t"));
|
|
|
|
// Record updates.
|
|
updateLogMonitor.RecordUpdatedValues(assetProcess);
|
|
updateLogMonitor.LogUpdates();
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Delete AssetProcess.
|
|
public override bool AssetProcessCanBeDeleted(SbmAssetProcess assetProcess)
|
|
{
|
|
ClearErrorState();
|
|
if (!base.AssetProcessCanBeDeleted(assetProcess)) return false;
|
|
return true;
|
|
}
|
|
public override bool DeleteAssetProcess(SbmAssetProcess assetProcess, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".DeleteAssetProcess";
|
|
ClearErrorState();
|
|
if (!AssetProcessCanBeDeleted(assetProcess)) return false;
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
// Retrieve AssetProcess.
|
|
dbConnection.Open();
|
|
SaAssetProcess_Db dbAssetProcess = new SaAssetProcess_Db(DbInfo);
|
|
dbAssetProcess.PopulateFrom(dbCommand, aliasAssetProcess, "Id=" + assetProcess.Id.ToString());
|
|
// Delete AssetProcess.
|
|
dbCommand.CommandType = System.Data.CommandType.Text;
|
|
dbCommand.CommandText = "DELETE FROM " + SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess) + " WHERE Id=" + SysId.ToString(assetProcess.Id) + ";";
|
|
dbCommand.ExecuteNonQuery();
|
|
assetProcess.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Deleted. " + GetLogProperties(assetProcess).Concat(": ").Concat("", "\n\t"));
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Copy data properties to and from database.
|
|
private void PopulateTo(SaAssetProcess_Db dbAssetProcess, SbmAssetProcess assetProcess, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
dbAssetProcess._Id = assetProcess.Id.ToInt();
|
|
dbAssetProcess._AssetId = assetProcess.AssetId.ToInt();
|
|
dbAssetProcess._Seq = assetProcess.Seq.ToShort();
|
|
dbAssetProcess._ProcessId = assetProcess.ProcessId.ToInt();
|
|
dbAssetProcess._RequiredOn = assetProcess.RequiredOn;
|
|
dbAssetProcess._ExpectedOn = assetProcess.ExpectedOn;
|
|
dbAssetProcess._ProcessedOn = assetProcess.ProcessedOn;
|
|
// Common properties.
|
|
dbAssetProcess._Notes = assetProcess.Notes;
|
|
dbAssetProcess._Status = SacsSystem.GetStatusCode(assetProcess.Status);
|
|
dbAssetProcess._Flags = (short)assetProcess.Flags;
|
|
if (!SysId.IsValid(assetProcess.Id))
|
|
{
|
|
dbAssetProcess._CreateOn = DateTime.UtcNow;
|
|
dbAssetProcess._CreateBy = dbUpdateInfo.UserId.ToInt();
|
|
dbAssetProcess._CreateHost = dbUpdateInfo.Host;
|
|
}
|
|
dbAssetProcess._UpdateOn = DateTime.UtcNow;
|
|
dbAssetProcess._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
|
dbAssetProcess._UpdateHost = dbUpdateInfo.Host;
|
|
}
|
|
private void PopulateFrom(SaAssetProcess_Db dbAssetProcess, SbmAssetProcess assetProcess)
|
|
{
|
|
//assetProcess.Id = new SysId(dbAssetProcess._Id);
|
|
assetProcess.AssetId = new SysId(dbAssetProcess._AssetId);
|
|
assetProcess.Seq = dbAssetProcess._Seq.ToString();
|
|
assetProcess.ProcessId = new SysId(dbAssetProcess._ProcessId);
|
|
assetProcess.RequiredOn = dbAssetProcess._RequiredOn;
|
|
assetProcess.ExpectedOn = dbAssetProcess._ExpectedOn;
|
|
assetProcess.ProcessedOn = dbAssetProcess._ProcessedOn;
|
|
// Common properties.
|
|
assetProcess.Notes = dbAssetProcess._Notes;
|
|
assetProcess.Status = SacsSystem.GetStatusForCode(dbAssetProcess._Status);
|
|
assetProcess.SetCreateStamp(dbAssetProcess._CreateOn, new SysId(dbAssetProcess._CreateBy), dbAssetProcess._CreateHost);
|
|
assetProcess.SetUpdateStamp(dbAssetProcess._UpdateOn, new SysId(dbAssetProcess._UpdateBy), dbAssetProcess._UpdateHost);
|
|
assetProcess.AcceptChanges();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// AssetProcess column definitions.
|
|
private static readonly String aliasAssetProcess = "aAstPrc";
|
|
private static readonly String prefixAssetProcess = "AstProcess_";
|
|
private void SetAssetProcessColDfn
|
|
(ColumnDfn col, String caption, int width, SbmDbDfn.ColumnIdx dbCol,
|
|
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
|
String alias = "", String prefix = "")
|
|
{
|
|
if (String.IsNullOrEmpty(alias) && SbmDbDfn.GetTableForColumn(dbCol) == SbmDbDfn.TableIdx.SaAssetProcess)
|
|
alias = aliasAssetProcess;
|
|
col.Set(caption, width, (int)dbCol, prefix + SbmDbDfn.GetColumnName(dbCol, false), SbmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
|
if (dataType == DataValue.DataType.String && dbCol != SbmDbDfn.ColumnIdx.Unknown)
|
|
col.MaxLength = (int)SbmDbDfn.GetColTextLen(dbCol);
|
|
}
|
|
//-------------------------------------------------------------------
|
|
// Getting prmAssetProcess column definition.
|
|
public override ColumnDfn GetAssetProcessColumnDfn(SbmAssetProcess.Column columnId, string caption = "", int width = 0)
|
|
{
|
|
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
|
switch (columnId)
|
|
{
|
|
case SbmAssetProcess.Column.Pos:
|
|
SetAssetProcessColDfn(columnDfn, "Pos", 45, SbmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
|
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
|
columnDfn.ReadOnly = true;
|
|
columnDfn.Resizable = false;
|
|
break;
|
|
case SbmAssetProcess.Column.Id:
|
|
SetAssetProcessColDfn(columnDfn, "Id", 60, SbmDbDfn.ColumnIdx.SaAssetProcess_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
// AssetProcess Properties.
|
|
case SbmAssetProcess.Column.AssetId:
|
|
SetAssetProcessColDfn(columnDfn, "Id", 45, SbmDbDfn.ColumnIdx.SaAssetProcess_AssetId, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SbmAssetProcess.Column.Seq:
|
|
SetAssetProcessColDfn(columnDfn, "Desc Brief", 120, SbmDbDfn.ColumnIdx.SaAssetProcess_Seq);
|
|
break;
|
|
case SbmAssetProcess.Column.ProcessId:
|
|
SetAssetProcessColDfn(columnDfn, "Process Id", 45, SbmDbDfn.ColumnIdx.SaAssetProcess_ProcessId, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SbmAssetProcess.Column.RequiredOn:
|
|
break;
|
|
case SbmAssetProcess.Column.ExpectedOn:
|
|
break;
|
|
case SbmAssetProcess.Column.ProcessedOn:
|
|
break;
|
|
|
|
// Common properties.
|
|
case SbmAssetProcess.Column.Notes:
|
|
SetAssetProcessColDfn(columnDfn, "Notes", 200, SbmDbDfn.ColumnIdx.SaAssetProcess_Notes);
|
|
break;
|
|
case SbmAssetProcess.Column.Flag:
|
|
SetAssetProcessColDfn(columnDfn, "Flags", 40, SbmDbDfn.ColumnIdx.SaAssetProcess_Flags, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
break;
|
|
case SbmAssetProcess.Column.Status:
|
|
SetAssetProcessColDfn(columnDfn, "Status", 50, SbmDbDfn.ColumnIdx.SaAssetProcess_Status, ColumnAlignment.Center);
|
|
break;
|
|
case SbmAssetProcess.Column.Status_Desc:
|
|
SetAssetProcessColDfn(columnDfn, "Status", 50, SbmDbDfn.ColumnIdx.SaAssetProcess_Status);
|
|
break;
|
|
case SbmAssetProcess.Column.Status_Ind:
|
|
SetAssetProcessColDfn(columnDfn, "Status", 50, SbmDbDfn.ColumnIdx.SaAssetProcess_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
|
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
|
break;
|
|
case SbmAssetProcess.Column.CreateOn_Date:
|
|
SetAssetProcessColDfn(columnDfn, "Created", 65, SbmDbDfn.ColumnIdx.SaAssetProcess_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.DateFormat = "d-MMM-yy";
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SbmAssetProcess.Column.UpdateOn_Date:
|
|
SetAssetProcessColDfn(columnDfn, "Updated", 65, SbmDbDfn.ColumnIdx.SaAssetProcess_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.DateFormat = "d-MMM-yy";
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
}
|
|
if (!String.IsNullOrEmpty(caption))
|
|
columnDfn.Caption = caption;
|
|
if (width > 0)
|
|
columnDfn.Width = width;
|
|
return columnDfn;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// AssetProcess query filter.
|
|
public override List<string> GetAssetProcessQueryFilter(SbmAssetProcess.Params prm)
|
|
{
|
|
List<String> filter = new List<String>();
|
|
|
|
// AssetProcess Id.
|
|
String includedIds = prm.IncludedIds.Concat(",");
|
|
String colAssetProcess_Id = SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_Id, aliasAssetProcess);
|
|
if (!includedIds.IsEmpty())
|
|
filter.Add(colAssetProcess_Id + " IN (" + includedIds + ")");
|
|
String excludedIds = prm.ExcludedIds.Concat(",");
|
|
if (!excludedIds.IsEmpty())
|
|
filter.Add(colAssetProcess_Id + " NOT IN (" + excludedIds + ")");
|
|
|
|
if (filter.Count < 1 && prm.IncludeDefaultFilter) filter.Add("1=1");
|
|
return filter;
|
|
}
|
|
|
|
// AssetProcess sort columns.
|
|
public List<String> GetAssetProcessSortColumns(SbmAssetProcess.Params prm)
|
|
{
|
|
// Sort sequence:
|
|
List<String> sortColumnCodes = new List<String>();
|
|
foreach (var columnDfn in prm.SortColumns)
|
|
{
|
|
// Need to ensure correct alias used for AssetProcess columns in case of conflict.
|
|
String sortCol = String.Empty;
|
|
if (SbmDbDfn.GetTableForColumn((SbmDbDfn.ColumnIdx)columnDfn.DbColumn) == SbmDbDfn.TableIdx.SaAssetProcess)
|
|
{
|
|
sortCol = SbmDbDfn.GetColumnNameQual((SbmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasAssetProcess);
|
|
}
|
|
else
|
|
{
|
|
sortCol = columnDfn.DataName;
|
|
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
|
sortCol = columnDfn.SortDataName;
|
|
}
|
|
if (!sortCol.IsEmpty())
|
|
{
|
|
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
|
sortColumnCodes.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
|
}
|
|
}
|
|
sortColumnCodes.RemoveBlanks();
|
|
if (sortColumnCodes.IsEmpty())
|
|
{
|
|
// Default sort columns:
|
|
sortColumnCodes.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_AssetId, aliasAssetProcess) + " ASC");
|
|
}
|
|
return sortColumnCodes;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// AssetProcess count.
|
|
private long GetAssetProcessCount(String filter)
|
|
{
|
|
ClearErrorState();
|
|
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess) + " As " + aliasAssetProcess, filter);
|
|
}
|
|
public override long GetAssetProcessCount(SbmAssetProcess.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
return GetAssetProcessCount(GetAssetProcessQueryFilter(prm).Concat(" AND ", "(", ")"));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// AssetProcess list.
|
|
public override List<SbmAssetProcess> GetAssetProcessList(SbmAssetProcess.Params prm)
|
|
{
|
|
List<SbmAssetProcess> AssetProcesses = new List<SbmAssetProcess>();
|
|
DbQuery qry = new DbQuery(db.DbmsType);
|
|
qry.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess), aliasAssetProcess);
|
|
SaAssetProcess_Db dbAssetProcess = new SaAssetProcess_Db(DbInfo);
|
|
qry.Columns.AddRange(dbAssetProcess.ExistingColumnNames);
|
|
qry.Filters.AddRange(GetAssetProcessQueryFilter(prm));
|
|
qry.OrderBy.AddRange(GetAssetProcessSortColumns(prm));
|
|
// Query data.
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
dbCommand.CommandText = qry.BuildQuery(prm.ResultsPaging);
|
|
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
|
{
|
|
while (dbDataReader.Read())
|
|
{
|
|
dbAssetProcess = new SaAssetProcess_Db(DbInfo);
|
|
dbAssetProcess.PopulateFrom(dbDataReader);
|
|
AssetProcesses.Add(CreateAssetProcess(dbAssetProcess));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn(GetType().Name + ".GetAssetProcessList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
|
}
|
|
}
|
|
return AssetProcesses;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// AssetProcess query execution.
|
|
public override DbResultSet ExecuteAssetProcessQuery(List<ColumnDfn> columns, SbmAssetProcess.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
//---------------------------------------------------------------------
|
|
// Construct build database query.
|
|
DbQuery query = new DbQuery(db.DbmsType);
|
|
query.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess), aliasAssetProcess);
|
|
|
|
// AssetProcess Properties - add columns as defined in query list.
|
|
if (columns.HasId((int)SbmAssetProcess.Column.AssetId))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_AssetId, aliasAssetProcess), prefixAssetProcess + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAssetProcess_AssetId, false));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.Seq))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_Seq, aliasAssetProcess), prefixAssetProcess + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAssetProcess_Seq, false));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.ProcessId))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_ProcessId, aliasAssetProcess), prefixAssetProcess + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAssetProcess_ProcessId, false));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.RequiredOn))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_RequiredOn, aliasAssetProcess), prefixAssetProcess + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAssetProcess_RequiredOn, false));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.ExpectedOn))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_ExpectedOn, aliasAssetProcess), prefixAssetProcess + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAssetProcess_ExpectedOn, false));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.ProcessedOn))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_ProcessedOn, aliasAssetProcess), prefixAssetProcess + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SaAssetProcess_ProcessedOn, false));
|
|
|
|
// Common Properties
|
|
if (columns.HasId((int)SbmAssetProcess.Column.Notes))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_Notes, aliasAssetProcess));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.Flag))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_Flags, aliasAssetProcess));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.Status) || columns.HasId((int)SbmAssetProcess.Column.Status_Desc) || columns.HasId((int)SbmAssetProcess.Column.Status_Ind))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_Status, aliasAssetProcess));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.CreateOn_Date))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_CreateOn, aliasAssetProcess));
|
|
if (columns.HasId((int)SbmAssetProcess.Column.UpdateOn_Date))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.SaAssetProcess_UpdateOn, aliasAssetProcess));
|
|
|
|
//---------------------------------------------------------------------
|
|
// Populate filter.
|
|
query.Filters.AddRange(GetAssetProcessQueryFilter(prm));
|
|
|
|
if (prm.IncludedIds.Count != 1)
|
|
{
|
|
// Configure sort sequence.
|
|
foreach (String sortColumn in GetAssetProcessSortColumns(prm))
|
|
query.OrderBy.Add(sortColumn);
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
|
return DbResultSet_DataReader.ExecuteQuery(db, query.BuildQuery(prm.ResultsPaging));
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|