Ejemplo n.º 1
0
        public static Measure TryParse(string text, PhysicalQuantity pq = null, CultureInfo culture = null)
        {
            if (culture == null)
            {
                culture = CultureInfo.InvariantCulture;
            }

            if (pq == null)
            {
                var pqstart = text.LastIndexOf('[') + 1;
                if (pqstart != 0)
                {
                    var pqname = text.Substring(pqstart, text.Length - pqstart - 1);
                    pq = PQCollection.PhysicalQuantities.First(w => w.Name == pqname);

                    text = text.Substring(0, pqstart - 1);
                }
            }

            if (pq != null && pq.Equals(PQCollection.Adimensional))
            {
                double n;
                if (double.TryParse(text, NumberStyles.Number | NumberStyles.AllowExponent, culture, out n))
                {
                    var res   = new Measure(n, MUCollection.Adimensional.adim);
                    var regex = new Regex("([0-9.]*)([eE])(.*)");
                    var q     = regex.Match(text);
                    if (q.Success)
                    {
                        res.ExpPref = int.Parse(q.Groups[3].Value);
                    }

                    return(res);
                }
            }
            else
            {
                var s = text.Trim();

                MeasureUnit mu = null;

                if (pq == null)
                {
                    var all_mus = MUCollection.MeasureUnits;

                    foreach (var _mu in all_mus.OrderByDescending(w => w.Name.Length))
                    {
                        if (s.EndsWith(_mu.ToString()))
                        {
                            mu = _mu;
                            break;
                        }
                    }

                    if (mu == null)
                    {
                        return(null);
                    }

                    // ambiguity between different pq with same mu name
                    if (all_mus.Count(r => r.ToString() == mu.ToString()) != 1)
                    {
                        return(null);
                    }
                }
                else
                {
                    foreach (var _mu in pq.MeasureUnits.OrderByDescending(w => w.Name.Length))
                    {
                        if (s.EndsWith(_mu.ToString()))
                        {
                            mu = _mu;
                            break;
                        }
                    }
                }

                if (mu == null)
                {
                    return(null);
                }

                s = s.StripEnd(mu.ToString());

                double n;
                if (double.TryParse(s, NumberStyles.Number | NumberStyles.AllowExponent, culture, out n))
                {
                    var res = new Measure(n, mu);

                    var regex = new Regex("([0-9.]*)([eE])(.*)");
                    var q     = regex.Match(s);
                    if (q.Success)
                    {
                        res.ExpPref = int.Parse(q.Groups[3].Value);
                    }

                    return(res);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public TransportPerformanceRecord()
        {
            MapField(2, 12, "Identificatie detailrecord").Numeric().Getter(x => Id.ToString());
            MapField(14, 9, "Burgerservicenummer").Numeric().Getter(x => BurgerServiceNumber.ToString());
            MapField(23, 4, "UZOVI-nummer").Numeric().Getter(x => UzoviId.ToString());

            MapField(57, 1, "Doorsturen toegestaan").Numeric().Getter(x =>
            {
                if (AllowForwarding)
                {
                    return("1");
                }
                else
                {
                    return("0");
                }
            });

            MapField(58, 1, "Indicatie ongeval").Alphanumeric().Getter(x => {
                if (!DueToAccident.HasValue)
                {
                    return("O");
                }
                else if (DueToAccident.Value)
                {
                    return("J");
                }
                else
                {
                    return("N");
                }
            });
            MapField(59, 4, "Code bestemming vervoer").Numeric().Getter(x => TransportDestinationCode.ToString());
            MapField(63, 3, "Aanduiding prestatiecodelijst").Numeric().Getter(x => PerformanceCodeList.ToString());
            MapField(66, 6, "Prestatiecode").Numeric().Getter(x => PerformanceCode.ToString());

            MapField(100, 8, "Zorgverlenerscode vervoerder").Numeric().Getter(x => CareProviderAgbId.ToString());
            MapField(108, 8, "Datum prestatie").Numeric().Getter(x => PerformanceDate.ToString("yyyyMMdd"));
            MapField(116, 4, "Vertrektijd vervoer").Numeric();

            MapField(144, 5, "Huisnummer herkomst").Numeric();
            MapField(220, 5, "Huisnummer bestemming").Numeric();

            MapField(272, 1, "Eenheid rit/prestatie").Numeric().Getter(x => MeasureUnit.ToString("D"));
            MapField(273, 4, "Aantal (rit)eenheden").Numeric().Getter(x => UnitCount.ToString());
            MapField(277, 8, "Tarief prestatie (incl. BTW)").Numeric().Getter(x => Math.Round(UnitPrice * 100).ToString());

            MapField(285, 8, "Bedrag toeslag").Numeric();

            MapField(293, 8, "Berekend bedrag (incl. BTW)").Numeric().Getter(x => Math.Round(TotalAmount * 100).ToString());
            MapField(301, 1, "Indicatie debet/credit").Alphanumeric().Getter(x =>
            {
                if (TotalAmount >= 0)
                {
                    return("D");
                }
                else
                {
                    return("C");
                }
            });

            MapField(302, 4, "BTW percentage declaratiebedrag").Numeric();
            MapField(306, 8, "Declaratiebedrag (incl. BTW)").Numeric().Getter(x => Math.Round(InvoicedAmount * 100).ToString());
            MapField(314, 1, "Indicatie debet/credit").Alphanumeric().Getter(x =>
            {
                if (InvoicedAmount >= 0)
                {
                    return("D");
                }
                else
                {
                    return("C");
                }
            });

            // Set default values.
            AllowForwarding = true;
            MeasureUnit     = TransportMeasureUnit.Kilometer;
        }