99 lines
2.6 KiB
C#
99 lines
2.6 KiB
C#
using Dakota.Models.Schlüssels;
|
|
using System;
|
|
|
|
namespace Dakota.Models.Daten
|
|
{
|
|
internal class Datenelement : Dateneinheit
|
|
{
|
|
private protected string _Value;
|
|
private protected bool _IgnoreCheck;
|
|
|
|
public int MinStellen { get; set; }
|
|
public int MaxStellen { get; set; }
|
|
public Feldart Feldart { get; set; }
|
|
|
|
public Datenelement(string title)
|
|
{
|
|
Title = title;
|
|
|
|
_IgnoreCheck = false;
|
|
}
|
|
public Datenelement(string title, int min, int max, Feldart art) : this(title)
|
|
{
|
|
MinStellen = min;
|
|
MaxStellen = max;
|
|
Feldart = art;
|
|
}
|
|
public Datenelement(string title, int count, Feldart art) : this(title, count, count, art)
|
|
{
|
|
|
|
}
|
|
|
|
public override string GetValue()
|
|
{
|
|
if (!HasValue())
|
|
{
|
|
if (Feldart == Feldart.Muss)
|
|
{
|
|
// Auffüllen
|
|
throw new ArgumentOutOfRangeException(Title, _Value, "muss gefühlt sein");
|
|
// throw new NotImplementedException("Error Code: 3483091097896");
|
|
}
|
|
else
|
|
{
|
|
// Leer lassen
|
|
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
if (!_IgnoreCheck && (_Value.Length < MinStellen || _Value.Length > MaxStellen))
|
|
{
|
|
throw new NotImplementedException("Error Code: 3483091097897");
|
|
}
|
|
|
|
return _Value;
|
|
}
|
|
|
|
public void ClearValue()
|
|
{
|
|
_Value = null;
|
|
}
|
|
public override bool HasValue()
|
|
{
|
|
return !string.IsNullOrEmpty(_Value);
|
|
}
|
|
public void SetValue(int value)
|
|
{
|
|
if (Feldart == Feldart.Kann && value == 0)
|
|
return;
|
|
|
|
SetValue(value.ToString());
|
|
}
|
|
public void SetValue(Schlüssel schlussel)
|
|
{
|
|
if (schlussel is null)
|
|
return;
|
|
SetValue(schlussel.Value);
|
|
}
|
|
public void SetValue(string value)
|
|
{
|
|
if (value is null)
|
|
return;
|
|
|
|
if (value.Length < MinStellen || value.Length > MaxStellen)
|
|
{
|
|
throw new ArgumentOutOfRangeException(Title, value, $"Wertebereich: min:max = ({MinStellen}:{MaxStellen})");
|
|
}
|
|
//else
|
|
//{
|
|
// throw new ArgumentOutOfRangeException(Title, value, "value ist kein string");
|
|
//}
|
|
|
|
DakotaValidator.ClearTextString(value);
|
|
|
|
_Value = value;
|
|
}
|
|
}
|
|
}
|