using System; namespace Dakota.Models { internal class Datenelement : Dateneinheit { private string _Value; private bool _IsDecimal; public int MinStellen { get; set; } public int MaxStellen { get; set; } public Feldart Feldart { get; set; } public Datenelement(string title) { Title = title; _IsDecimal = 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 (!_IsDecimal && (_Value.Length < MinStellen || _Value.Length > MaxStellen)) { throw new NotImplementedException("Error Code: 3483091097897"); } return _Value; } public void SetFilledIntValue(int value, int length) { if (value.ToString().Length > length) throw new ArgumentOutOfRangeException("length", $"the length of {value} is bigger than len {length}"); SetValue(value.ToString("D" + length.ToString())); } 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; _IsDecimal = false; } public void SetDecimalValue(Decimal input) { var dec = input.ToString("#.00").Replace(".", ","); var tester = Math.Abs(input).ToString("#.00").Replace(".", ""); if (tester.Length < MinStellen || tester.Length > MaxStellen) { throw new NotImplementedException("Error Code: 3483091097895"); } else { _Value = dec; } _IsDecimal = true; } } }