Exemple #1
0
        /*
         * We parse this Zoned-Decimal format by Hex Value
         */
        protected override Decimal getTypedValue(byte[] bytes, Dictionary <string, string> settings)
        {
            string input = ElementExtend.BytesToHex(bytes);

            var  numbers  = input.ToUpper().Replace("F", "").Replace("D", "");
            bool negative = this.IsSigned && input.ToUpper().Contains("D");

            return(Decimal.Parse((negative ? "-" : "") + numbers) / (decimal)BigInteger.Pow(10, this.DecimalPlaces));
        }
Exemple #2
0
        protected override Decimal getTypedValue(byte[] bytes, Dictionary <string, string> settings)
        {
            string input = ElementExtend.BytesToHex(bytes);

            if (input.EndsWith("D"))
            {
                input = "-" + input;
            }
            input = input.Replace("F", "").Replace("D", "");

            return(Decimal.Parse(input) / (decimal)BigInteger.Pow(10, this.DecimalPlaces));
        }
Exemple #3
0
        protected override void setTypedValue(decimal value, byte[] bytes, Dictionary <string, string> settings)
        {
            // get integer part and fractional part
            var integal  = (UInt64)Math.Abs(Math.Truncate(value));
            var fraction = (UInt64)(Math.Abs(value) - integal).ShiftBy10(this.DecimalPlaces);

            // number only, fill leading zero and trailing zero
            var input = integal.ToString()
                        + (this.DecimalPlaces > 0
                            ? fraction.ToString().PadRight(this.DecimalPlaces, '0')
                            : "");

            input = input + (this.IsSigned && value < 0 ? "D" : "F");
            input = input.PadLeft(this.LengthOfBytes * 2, '0');

            Buffer.BlockCopy(ElementExtend.HexToBytes(input), 0, bytes, 0, bytes.Length);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using (var stream = File.Open(args[0], FileMode.Open))
            {
                var group = CopybookParser.parse("test", stream);
                PrintElement(group, 1);

                dynamic record = new Data(group);


                Console.WriteLine(record.Name);
                Console.WriteLine(record.CLIRTVO_REC.Name);
                Console.WriteLine(record.CLIRTVO_REC.MESSAGE_HEADER.Name);

                record.CLIRTVO_REC.MESSAGE_HEADER.MSGIDA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                Console.WriteLine(ElementExtend.BytesToHex(record.CLIRTVO_REC.MESSAGE_HEADER.MSGIDA.GetBytes()));

                string result = record.CLIRTVO_REC.MESSAGE_HEADER.MSGIDA;
                Console.WriteLine(result);

                record.CLIRTVO_REC.MESSAGE_HEADER.MSGLNG = 12345;
                Console.WriteLine(ElementExtend.BytesToHex(record.CLIRTVO_REC.MESSAGE_HEADER.MSGLNG.GetBytes()));
                decimal msglng = record.CLIRTVO_REC.MESSAGE_HEADER.MSGLNG;
                Console.WriteLine(msglng);

                record.CLIRTVO_REC.MESSAGE_HEADER.MSGCNT = -123.456;
                Console.WriteLine(ElementExtend.BytesToHex(record.CLIRTVO_REC.MESSAGE_HEADER.MSGCNT.GetBytes()));
                decimal msgcnt = record.CLIRTVO_REC.MESSAGE_HEADER.MSGCNT;
                Console.WriteLine(msgcnt);

                record.CLIRTVO_REC.MESSAGE_DATA.BGEN_XXXXX[0].BGEN_XXXXX_TRANS_NO1 = 1234;
                Console.WriteLine(ElementExtend.BytesToHex(record.CLIRTVO_REC.MESSAGE_DATA.BGEN_XXXXX[0].BGEN_XXXXX_TRANS_NO1.GetBytes()));
                decimal tran_no1 = record.CLIRTVO_REC.MESSAGE_DATA.BGEN_XXXXX[0].BGEN_XXXXX_TRANS_NO1;
                Console.WriteLine(tran_no1);


                record.CLIRTVO_REC.MESSAGE_DATA.BGEN_XXXXX[1].BGEN_XXXXX_TRANS_NO3 = -123.12;
                Console.WriteLine(ElementExtend.BytesToHex(record.CLIRTVO_REC.MESSAGE_DATA.BGEN_XXXXX[1].BGEN_XXXXX_TRANS_NO3.GetBytes()));
                decimal tran_no3 = record.CLIRTVO_REC.MESSAGE_DATA.BGEN_XXXXX[1].BGEN_XXXXX_TRANS_NO3;
                Console.WriteLine(tran_no3);


                //record.CLIRTVO_REC.MESSAGE_HEADER.MSGIDA = Encoding.UTF32.GetBytes("香港湾仔");
            }
        }
Exemple #5
0
        protected override void setTypedValue(Decimal value, byte[] bytes, Dictionary <string, string> settings)
        {
            // get integer part and fractional part
            var integal  = (UInt64)Math.Abs(Math.Truncate(value));
            var fraction = (UInt64)(Math.Abs(value) - integal).ShiftBy10(this.DecimalPlaces);

            // fill the trailing zero of fraction, and leading zero for the whole
            var numbers = (integal.ToString()
                           + (this.DecimalPlaces > 0 ? fraction.ToString().PadRight(this.DecimalPlaces, '0') : "")
                           )
                          .PadLeft(this.NumberOfDigits, '0');

            // translate
            numbers = "F" + String.Join("F", numbers.ToArray());
            if (this.IsSigned && value < 0)
            {
                numbers = numbers.ReplaceAt(numbers.LastIndexOf('F'), 'D');
            }

            Buffer.BlockCopy(ElementExtend.HexToBytes(numbers), 0, bytes, 0, bytes.Length);
        }