Beispiel #1
0
 /// <summary>
 /// Returns the string representation of the stored value, which
 /// varies a little depending on its type: NUMERIC and ALPHA values
 /// are returned padded to the specified length of the field either
 /// with zeroes or spaces; AMOUNT values are formatted to 12 digits
 /// as cents; date/time values are returned with the specified format
 /// for their type. LLVAR and LLLVAR values are returned as they are.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     if (_type == IsoType.NUMERIC || _type == IsoType.ALPHA)
     {
         return(IsoTypeHelper.Format(_fval.ToString(), _type, _length));
     }
     else if (_type == IsoType.AMOUNT)
     {
         if (_fval is decimal)
         {
             return(IsoTypeHelper.Format((decimal)_fval, _type, 12));
         }
         else
         {
             return(IsoTypeHelper.Format(Convert.ToDecimal(_fval), _type, 12));
         }
     }
     else if (_fval is DateTime)
     {
         return(IsoTypeHelper.Format((DateTime)_fval, _type));
         //TAM ADDED to PAD F an the end of Packed VAR
     }
     else if (_type == IsoType.LLVAR || _type == IsoType.LLLVAR)
     {
         return(IsoTypeHelper.Format(_fval.ToString(), _type, _length));
     }
     return(_fval.ToString());
 }
Beispiel #2
0
        /// <summary>
        /// Creates an IsoValue with the given values and stores it in the specified index.
        /// </summary>
        /// <param name="index">The field index (2 to 128)</param>
        /// <param name="value">An object value to store inside an IsoValue.</param>
        /// <param name="t">The ISO8583 for this value.</param>
        /// <param name="length">The length of the value (useful only for NUMERIC and ALPHA types).</param>
        public void SetValue(int index, object value, IsoType t, int length)
        {
            if (index < 2 || index > 128)
            {
                throw new ArgumentOutOfRangeException(nameof(index), "Index must be between 2 and 128");
            }

            if (value == null)
            {
                _fields.Remove(index);
            }
            else
            {
                IsoValue v = null;
                v = IsoTypeHelper.NeedsLength(t) ? new IsoValue(t, value, length) : new IsoValue(t, value);
                _fields[index] = v;
            }
        }
Beispiel #3
0
 /// <summary> Creates a new instance to store a value of a fixed-length type. Fixed-length types are DATE4, DATE_EXP, DATE10, TIME, AMOUNT. </summary>
 /// <param name="t">The <see cref="IsoType"/> (8583) type of the value that is going to be stored.</param>
 /// <param name="value">The value to store.s</param>
 public IsoValue(IsoType t, object value)
 {
     if (value == null)
     {
         throw new ArgumentException("Value cannot be null");
     }
     if (IsoTypeHelper.NeedsLength(t))
     {
         throw new ArgumentException("Use IsoValue constructor for Fixed-value types");
     }
     _type = t;
     _fval = value;
     if (t == IsoType.LLVAR || _type == IsoType.LLLVAR || t == IsoType.LLVARnp || _type == IsoType.LLLVARnp)
     {
         _length = value.ToString().Length;
     }
     else
     {
         _length = IsoTypeHelper.GetLength(t);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Creates a new instance to store a value of a given type. This constructor
 /// is used for variable-length types (LLVAR, LLLVAR, ALPHA, NUMERIC) -
 /// variable in the sense that that length of the value does not depend
 /// solely on the ISO type.
 /// </summary>
 /// <param name="t">the <see cref="IsoType"/> ISO8583 type of the value to be stored.</param>
 /// <param name="val">The value to be stored.</param>
 /// <param name="len">The length of the field.</param>
 public IsoValue(IsoType t, object val, int len)
 {
     if (val == null)
     {
         throw new ArgumentException("Value cannot be null");
     }
     _type   = t;
     _fval   = val;
     _length = len;
     if (_length < 0 && IsoTypeHelper.NeedsLength(t))
     {
         throw new ArgumentException("Length must be greater than zero");
     }
     else if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
     {
         _length = val.ToString().Length;
         //@@@ TAM
     }
     else if (t == IsoType.LLVARnp || t == IsoType.LLLVARnp)
     {
         _length = val.ToString().Length * 2;
     }
 }