211 lines
9.1 KiB
C#
211 lines
9.1 KiB
C#
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 System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.Net.Standard.Base.Interfaces
|
|
{
|
|
//=======================================================================
|
|
public partial class SaInterfaceMgr
|
|
{
|
|
|
|
//*******************************************************************
|
|
// I n t e r f a c e s
|
|
//*******************************************************************
|
|
// Associated data.
|
|
public abstract bool InterfaceHasProcesses (SysId id);
|
|
public abstract bool InterfaceHasDataItems (SysId id);
|
|
// Process sequence.
|
|
public abstract int GetMaxProcessSequenceForInterface (SysId interfaceId, SaInterfaceProcessDirection processDirection);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve individual interfaces.
|
|
public abstract bool InterfaceExistsById (SysId id);
|
|
public abstract bool InterfaceExistsByCode (String code);
|
|
public abstract SaInterface GetInterfaceById (SysId id);
|
|
public abstract SaInterface GetInterfaceByContextCode (String context, String code);
|
|
public abstract SaInterface GetInterface (SaInterface.Params prm);
|
|
|
|
// Create Interface.
|
|
public abstract SaInterface CreateInterface (String context, SaInterfaceCategory category, short type);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate Interface.
|
|
public bool IsValidInterface (SaInterface interfaceObj)
|
|
{
|
|
ClearErrorState();
|
|
if (interfaceObj == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
|
return IsValidInterfaceData(interfaceObj.GetData(), new SaInterface.ErrField());
|
|
}
|
|
public virtual bool IsValidInterfaceData (SaInterface.Data data, SaInterface.ErrField errField)
|
|
{
|
|
ClearErrorState();
|
|
if (errField.Context != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Context, "context", (long)SaInterfaceDbDfn.GetColTextLen(SaInterfaceDbDfn.ColumnIdx.SaInterface_Context)))
|
|
{
|
|
errField.Context = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.Category != SacsHierarchyItem.ValidValue.Ignore && (int)data.Category < 1)
|
|
{
|
|
errField.Category = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState("Category must be supplied");
|
|
}
|
|
if (errField.Type != SacsHierarchyItem.ValidValue.Ignore && data.Type < 1)
|
|
{
|
|
errField.Type = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState("Type must be supplied");
|
|
}
|
|
if (errField.Code != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Code, "code", (long)SaInterfaceDbDfn.GetColTextLen(SaInterfaceDbDfn.ColumnIdx.SaInterface_Code), true))
|
|
{
|
|
errField.Code = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
// Code must be only alphanumeric with hyphens and underscores.
|
|
String codeTest = data.Code.Replace("-","").Replace("_","");
|
|
if (StringUtil.IsEmpty(codeTest) || !StringUtil.IsAlphaNumeric(codeTest))
|
|
{
|
|
SetErrorState("Code must only consts if letters, numbers, hyphens and underscores, and have at least one letter or number");
|
|
errField.Code = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
// Code must be unique.
|
|
SaInterface interfaceByCode = GetInterfaceByContextCode(data.Context, data.Code);
|
|
if (interfaceByCode != null && !data.Id.Equals(interfaceByCode.Id))
|
|
{
|
|
SetErrorState("Code is already in use by the '" + interfaceByCode.Caption + "' interface.");
|
|
errField.Code = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
// Caption.
|
|
if (errField.Caption != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Caption, "caption", (long)SaInterfaceDbDfn.GetColTextLen(SaInterfaceDbDfn.ColumnIdx.SaInterface_Caption), true))
|
|
{
|
|
errField.Caption = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
// Common properties.
|
|
if (errField.Notes != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Notes, "notes", (long)SaInterfaceDbDfn.GetColTextLen(SaInterfaceDbDfn.ColumnIdx.SaInterface_Notes)))
|
|
{
|
|
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore && !SaInterface.ValidStatuses.Contains(data.Status))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState(ErrorMessage.InvalidStatus);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Interface database interface.
|
|
public abstract bool InsertInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool UpdateInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo);
|
|
public virtual bool InterfaceCanBeDeleted (SaInterface interfaceObj)
|
|
{
|
|
ClearErrorState();
|
|
if (InterfaceHasProcesses(interfaceObj.Id)) return SetErrorState("Interface has processes");
|
|
if (InterfaceHasDataItems(interfaceObj.Id)) return SetErrorState("Interface has data items");
|
|
return true;
|
|
}
|
|
public abstract bool DeleteInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Interface list.
|
|
public abstract ColumnDfn GetInterfaceColumnDfn (SaInterface.Column columnId, String caption = "", int width = 0);
|
|
public abstract List<String> GetInterfaceQueryFilter (SaInterface.Params prm);
|
|
public abstract long GetInterfaceCount (SaInterface.Params prm);
|
|
public abstract List<SaInterface> GetInterfaceList (SaInterface.Params prm);
|
|
public abstract DbResultSet ExecuteInterfaceQuery (List<ColumnDfn> columns, SaInterface.Params prm);
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Extract and format result set data value where specific handling is required.
|
|
/// <para>Where response is an invalid data value, format value using column.FormatValue(values).</para>
|
|
/// </summary>
|
|
public virtual DataValue GetInterfaceDataValue (ColumnDfn column, NamedValue.Map values)
|
|
{
|
|
DataValue value = new DataValue();
|
|
switch ((SaInterface.Column)column.Id)
|
|
{
|
|
//-----------------------------------------------------------
|
|
// Category.
|
|
case SaInterface.Column.Category_Desc:
|
|
{
|
|
SaInterfaceCategory category = (SaInterfaceCategory)StringUtil.ToInt(values.GetValue(column.DataName).ToString());
|
|
value = new DataValue(interfaceCategories.GetCodeForType(category, category.ToString()));
|
|
}
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Type.
|
|
case SaInterface.Column.Type_Desc:
|
|
{
|
|
String context = values.GetValue(GetInterfaceColumnDfn(SaInterface.Column.Context).DataName).ToString();
|
|
SaInterfaceCategory category = (SaInterfaceCategory)StringUtil.ToInt(values.GetValue(GetInterfaceColumnDfn(SaInterface.Column.Category).DataName).ToString());
|
|
short type = StringUtil.ToShort(values.GetValue(column.DataName).ToString());
|
|
String typeDesc = InterfaceConsole.GetInterfaceTypeDesc(context, category, type);
|
|
if (StringUtil.IsEmpty(typeDesc)) typeDesc = type.ToString();
|
|
value = new DataValue(typeDesc);
|
|
}
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Item type.
|
|
case SaInterface.Column.Active_Y:
|
|
case SaInterface.Column.Active_TickCross:
|
|
case SaInterface.Column.Active_Ind:
|
|
{
|
|
ushort flags = (ushort)values.GetValue(column.DataName).AsLong();
|
|
bool activeInterface = SacsHierarchyItem.GetFlag(flags, SaInterface.Flag_Active);
|
|
if (column.Id == (int)SaInterface.Column.Active_Y)
|
|
value = new DataValue(activeInterface ? "Y" : "");
|
|
else if (column.Id == (int)SaInterface.Column.Active_Ind)
|
|
value = new DataValue(activeInterface ? DataValue.TriStateType.Green : DataValue.TriStateType.Red);
|
|
else
|
|
value = new DataValue(activeInterface);
|
|
}
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Notes.
|
|
case SaInterface.Column.Notes:
|
|
{
|
|
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
|
}
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Status.
|
|
case SaInterface.Column.Status_Desc:
|
|
case SaInterface.Column.Status_Ind:
|
|
{
|
|
String statusCode = values.GetValue(column.DataName).ToString();
|
|
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
|
if (column.Id == (int)SaInterface.Column.Status_Desc)
|
|
{
|
|
String statusDesc = SacsSystem.GetStatusDescForCode(statusCode);
|
|
value = new DataValue(statusDesc);
|
|
}
|
|
else if (column.Id == (int)SaInterface.Column.Status_Ind)
|
|
{
|
|
DataValue.TriStateType triState = DataValue.TriStateType.Unknown;
|
|
if (status == SaStatus.Current || status == SaStatus.Active)
|
|
triState = DataValue.TriStateType.Green;
|
|
value = new DataValue(triState);
|
|
}
|
|
}
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
}
|
|
return value;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|