Example #1
0
        RateDto parseRate(TypeOfDayChoice pTypeOfDayChoice, TimeOfDay pTimeOfDay, string pRouteLine)
        {
            var  _routeFields = pRouteLine.Split(AppConstants.ImportExport_FieldDelimiter);
            byte _firstIncr;
            byte _addIncr;

            parseIncrements(_routeFields[RouteLineFields.Increments], out _firstIncr, out _addIncr);
            if (!validateIncrement(pTimeOfDay, _firstIncr, _addIncr))
            {
                throw new ArgumentException(string.Format("Invalid Increment: [{0}/{1}] for TypeOfDayChoice={2}, TimeOfDay={3}, Route line={4}", _firstIncr, _addIncr, pTypeOfDayChoice, pTimeOfDay, pRouteLine));
            }

            if (_routeFields.Length == 9)
            {
                //Increments
                decimal _firstIncrCost;
                decimal.TryParse(_routeFields[RouteLineFields.FirstIncrCost], out _firstIncrCost);
                decimal _addIncrCost;
                decimal.TryParse(_routeFields[RouteLineFields.AddIncrCost], out _addIncrCost);
                if (!validateCost(pTimeOfDay, _firstIncrCost, _addIncrCost))
                {
                    throw new ArgumentException(string.Format("Invalid Cost [{0},{1}] for TypeOfDayChoice={2}, TimeOfDay={3}, Route line={4}", _firstIncrCost, _addIncrCost, pTypeOfDayChoice, pTimeOfDay, pRouteLine));
                }

                var _rate = new RateDto
                {
                    TypeOfDayChoice = pTypeOfDayChoice,
                    TimeOfDay       = pTimeOfDay,
                    FirstIncrLen    = _firstIncr,
                    AddIncrLen      = _addIncr,
                    FirstIncrCost   = _firstIncrCost,
                    AddIncrCost     = _addIncrCost
                };
                return(_rate);
            }

            if (_routeFields.Length == 8)
            {
                //PerMinute
                decimal _perMinuteCost;
                decimal.TryParse(_routeFields[RouteLineFields.FirstIncrCost], out _perMinuteCost);
                var _rate = new RateDto
                {
                    TypeOfDayChoice = pTypeOfDayChoice,
                    TimeOfDay       = pTimeOfDay,
                    FirstIncrLen    = _firstIncr,
                    AddIncrLen      = _addIncr
                };
                _rate.FirstIncrCost = _rate.GetFirstIncrAmount(_perMinuteCost, _firstIncr, _addIncr);
                _rate.AddIncrCost   = _rate.GetAddIncrAmount(_perMinuteCost, _firstIncr, _addIncr);
                if (!validateCost(pTimeOfDay, _rate.FirstIncrCost, _rate.AddIncrCost))
                {
                    throw new ArgumentException(string.Format("Invalid Cost [{0},{1}] for TypeOfDayChoice={2} TimeOfDay={3}, Route line={4}", _rate.FirstIncrCost, _rate.AddIncrCost, pTypeOfDayChoice, pTimeOfDay, pRouteLine));
                }
                return(_rate);
            }
            throw new Exception(string.Format("Number of RouteFields incorrect, {0}", pRouteLine));
        }
Example #2
0
        public RateDto MakeClone()
        {
            RateDto _clone = new RateDto();

            _clone.RateInfoId      = 0;
            _clone.AddIncrCost     = addIncrCost;
            _clone.AddIncrLen      = addIncrLen;
            _clone.FirstIncrCost   = firstIncrCost;
            _clone.FirstIncrLen    = firstIncrLen;
            _clone.TimeOfDay       = timeOfDay;
            _clone.TypeOfDayChoice = typeOfDayChoice;

            return(_clone);
        }