106 lines
3.1 KiB
C#
106 lines
3.1 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 DakotaException($"Das Feld \"{Title}\" muss gefüllt sein!");
|
|
}
|
|
else
|
|
{
|
|
// Leer lassen
|
|
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
if (!_IgnoreCheck)
|
|
{
|
|
if(_Value.Length < MinStellen)
|
|
{
|
|
throw new DakotaException($"Das Feld \"{Title}\" hat bei der Auswertung {_Value.Length} Stellen ergeben! Nach Vorgabe muss es jedoch mindestens {MinStellen} Stellen haben");
|
|
}
|
|
else if (_Value.Length > MaxStellen)
|
|
{
|
|
throw new DakotaException($"Das Feld \"{Title}\" hat bei der Auswertung {_Value.Length} Stellen ergeben! Nach Vorgabe darf es jedoch maximal {MaxStellen} Stellen haben");
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
throw new DakotaException($"Das Feld \"{Title}\" hat bei der Erstellung {_Value.Length} Stellen ergeben! Nach Vorgabe muss es jedoch mindestens {MinStellen} Stellen haben");
|
|
}
|
|
|
|
if (value.Length > MaxStellen)
|
|
{
|
|
throw new DakotaException($"Das Feld \"{Title}\" hat bei der Erstellung {_Value.Length} Stellen ergeben! Nach Vorgabe darf es jedoch maximal {MaxStellen} Stellen haben");
|
|
}
|
|
|
|
DakotaValidator.ClearTextString(value);
|
|
|
|
_Value = value;
|
|
}
|
|
}
|
|
}
|