64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using System;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
|
|
namespace Sarand.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
public abstract class SacsItemMgr : SaErrorStateItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Static initialisation.
|
|
static SacsItemMgr ()
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SacsItemMgr ()
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Disposal.
|
|
protected override void Dispose (bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
|
|
//-------------------------------------------------------------------
|
|
// V a l i d a t i o n
|
|
//-------------------------------------------------------------------
|
|
// String attribute validation (mandatory and maximum length.
|
|
// If the value fails the validation, an exception is set:
|
|
protected bool IsValidValue (String value, String attributeName, long maxLen, bool mandatory = false, bool fixedLen = false)
|
|
{
|
|
// Check for mandatory values:
|
|
if (mandatory && StringUtil.IsEmpty(value))
|
|
return SetErrorState(attributeName + " is blank");
|
|
// Check that value does not exceed the maximum number of characters:
|
|
if (maxLen > 0 && StringUtil.GetLength(value) > maxLen)
|
|
return SetErrorState(attributeName + " must not exceed " + maxLen.ToString() + " character" + ((maxLen > 1) ? "s" : ""));
|
|
// Check that fixed length values are the specified length:
|
|
if (fixedLen && maxLen > 0 && (mandatory || !value.IsEmpty()) && StringUtil.GetLength(value) != maxLen)
|
|
return SetErrorState(attributeName + " must be " + maxLen.ToString() + " character" + ((maxLen > 1) ? "s" : "") + " in length");
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|