예제 #1
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 ISO8583 type of the value that is going to be stored.</param>
        /// <param name="value">The value to store.s</param>
        /// <param name="originalValue">The original value of field</param>
        /// <param name="req">Indicates the requiremts (M,C, CE, ME, O )</param>
        public IsoValue(IsoType t, Parsing.ConfigParser.Base configBase, Object value, String originalValue, String req)
        {
            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;
            b    = configBase;
            this.originalValue = originalValue;
            requirements       = req;
            if (t == IsoType.LLVAR || type == IsoType.LLLVAR)
            {
                length = value.ToString().Length;
            }
            else
            {
                length = IsoTypeHelper.GetLength(t);
            }
        }
예제 #2
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));
            }

            if (type == IsoType.AMOUNT)
            {
                if (fval is Decimal)
                {
                    return(IsoTypeHelper.Format((Decimal)fval, type, 12));
                }
                else
                {
                    return(IsoTypeHelper.Format(Convert.ToDecimal(fval), type, 12));
                }
            }

            if (fval is DateTime)
            {
                return(IsoTypeHelper.Format((DateTime)fval, type));
            }

            return(fval.ToString());
        }
예제 #3
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 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>
        /// <param name="req">Indicates the requiremts (M,C, CE, ME, O )</param>
        /// <param name="subData">Collection of subDatas (SubField/SubElements) of field</param>
        public IsoValue(IsoType t, Parsing.ConfigParser.Base configBase, Object val, Int32 len, String originalValue, String req, Dictionary <Int32, IsoValue> subData)
        {
            if (val == null)
            {
                throw new ArgumentException("Value cannot be null");
            }

            type         = t;
            fval         = val;
            length       = len;
            b            = configBase;
            this.subData = subData;
            requirements = req;
            FormatOriginalValue();

            if (length == 0 && IsoTypeHelper.NeedsLength(t))
            {
                throw new ArgumentException("Length must be greater than zero");
            }

            if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
            {
                length = val.ToString().Length;
            }
        }
예제 #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 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>
        /// <param name="originalValue">The original value of field</param>
        /// <param name="req">Indicates the requiremts (M,C, CE, ME, O )</param>
        /// <param name="typeElement">Indicates the Type of Element (Field, SubField, SubElement)</param>
        public IsoValue(IsoType t, Parsing.ConfigParser.Base configBase, Object val, Int32 len, String originalValue, String req, TypeElement typeElement, Dictionary <Int32, IsoValue> subData, Int32 subElementIDLength, Int32 lengthLengthSubElement)
        {
            if (val == null)
            {
                throw new ArgumentException("Value cannot be null");
            }

            type                        = t;
            fval                        = val;
            length                      = len;
            this.originalValue          = originalValue;
            requirements                = req;
            this.typeElement            = typeElement;
            this.subElementIDLength     = subElementIDLength;
            this.lengthLengthSubElement = lengthLengthSubElement;
            this.subData                = subData;
            b = configBase;

            if (typeElement == TypeElement.Field || typeElement == TypeElement.SubField)
            {
                if (length == 0 && IsoTypeHelper.NeedsLength(t))
                {
                    throw new ArgumentException("Length must be greater than zero");
                }
            }

            if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
            {
                length = val.ToString().Length;
            }
        }
예제 #5
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 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>
        /// <param name="originalValue">The original value of field</param>
        public IsoValue(IsoType t, Parsing.ConfigParser.Base configBase, Object val, Int32 len, String originalValue, TypeElement typeElement)
        {
            if (val == null)
            {
                throw new ArgumentException("Value cannot be null");
            }

            type               = t;
            fval               = val;
            length             = len;
            b                  = configBase;
            this.originalValue = originalValue;

            if (typeElement == TypeElement.Field || typeElement == TypeElement.SubField)
            {
                if (length == 0 && IsoTypeHelper.NeedsLength(t))
                {
                    throw new ArgumentException("Length must be greater than zero");
                }
            }

            if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
            {
                length = val.ToString().Length;
            }
        }
예제 #6
0
        private void FormatOriginalValue()
        {
            if (subData != null)
            {
                if (subData.Count > 0)
                {
                    String orgValue = "";
                    foreach (KeyValuePair <Int32, IsoValue> sub in subData)
                    {
                        orgValue += sub.Value.originalValue;
                    }

                    originalValue = orgValue;
                    return;
                }
            }

            switch (type)
            {
            case IsoType.NUMERIC:
                originalValue = IsoTypeHelper.Format(fval.ToString(), type, length);
                break;

            case IsoType.ALPHA:
                originalValue = IsoTypeHelper.Format(fval.ToString(), type, length);
                break;

            case IsoType.DATE10:
                originalValue = IsoTypeHelper.Format(Convert.ToDateTime(fval), type);
                break;

            case IsoType.DATE12:
                originalValue = IsoTypeHelper.Format(Convert.ToDateTime(fval), type);
                break;

            case IsoType.DATE6:
                originalValue = IsoTypeHelper.Format(Convert.ToDateTime(fval), type);
                break;

            case IsoType.DATE4:
                originalValue = IsoTypeHelper.Format(Convert.ToDateTime(fval), type);
                break;

            case IsoType.DATE_EXP:
                originalValue = IsoTypeHelper.Format(Convert.ToDateTime(fval), type);
                break;

            case IsoType.TIME:
                originalValue = IsoTypeHelper.Format(Convert.ToDateTime(fval), type);
                break;

            case IsoType.AMOUNT:
                originalValue = IsoTypeHelper.Format(Convert.ToDecimal(fval), type, length);
                break;
            }
        }