82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
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.IsBlank(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.IsBlank()) && StringUtil.GetLength(value) != maxLen)
|
|
return SetErrorState(attributeName + " must be " + maxLen.ToString() + " character" + ((maxLen > 1) ? "s" : "") + " in length");
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// S o r t C o l u m n s
|
|
//-------------------------------------------------------------------
|
|
protected void AddRandomSortColumn (SacsHierarchyItem.Params prm, HashSet<String> sortColumns)
|
|
{
|
|
if (!prm.RandomOrder) return;
|
|
if (sortColumns.Any())
|
|
{
|
|
SaLogger.Warn($"{SysUtil.Fn} RandomOrder requested with other sort columns specified. [{prm.GetType().Name}]");
|
|
return;
|
|
}
|
|
sortColumns.Add(DbQuery.GetRandomOrderSortColumn());
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|