Files
BeWoPlaner/Dakota/Models/Daten/Datenelement.cs

89 lines
2.3 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 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 SetValue(int value)
{
SetValue(value.ToString());
}
public void SetValue(Schlüssel schlussel)
{
SetValue(schlussel.Value);
}
public void SetValue(string value)
{
if (value is string)
{
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;
_IgnoreCheck = false;
}
}
}