105 lines
2.7 KiB
C#
105 lines
2.7 KiB
C#
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()
|
|
{
|
|
_IsDecimal = false;
|
|
}
|
|
|
|
public Datenelement(int min, int max, Feldart art) : this()
|
|
{
|
|
MinStellen = min;
|
|
MaxStellen = max;
|
|
Feldart = art;
|
|
}
|
|
|
|
public Datenelement(int count, Feldart art) : this(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 NotImplementedException("Error Code: 3483091097894");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new NotImplementedException("Error Code: 3483091097893");
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|