Beispiel #1
0
 public RateDto()
 {
     timeOfDay       = TimeOfDay.Flat;
     typeOfDayChoice = TypeOfDayChoice.RegularDay;
     firstIncrLen    = 60;
     addIncrLen      = 60;
 }
        //TODO: Whay is pTimeOfDayPolicy NOT used?
        void loadRates(int pRateInfoId, TypeOfDayChoice pTypeOfDayChoice)
        {
            var _rates = new List <Rate>();

            using (var _db = new Rbr_Db()) {
                var _timeOfDayPeriodRows = _db.TimeOfDayPeriodCollection.GetByRate_info_id_Type_of_day_choice(pRateInfoId, (byte)pTypeOfDayChoice);
                foreach (var _timeOfDayPeriodRow in _timeOfDayPeriodRows)
                {
                    var _rateRow = _db.RateCollection.GetByPrimaryKey(_timeOfDayPeriodRow.Rate_info_id, _timeOfDayPeriodRow.Type_of_day_choice, _timeOfDayPeriodRow.Time_of_day);
                    var _rate    =
                        new Rate(_timeOfDayPeriodRow.Start_hour,
                                 _timeOfDayPeriodRow.Stop_hour,
                                 _timeOfDayPeriodRow.TimeOfDay,
                                 _rateRow.First_incr_length,
                                 _rateRow.Add_incr_length,
                                 _rateRow.First_incr_cost,
                                 _rateRow.Add_incr_cost);

                    _rates.Add(_rate);
                }
            }

            if (_rates.Count == 0)
            {
                throw new Exception(string.Format("NO RATES, RateInfoId={0}", pRateInfoId));
            }
            rates = _rates.ToArray();
        }
Beispiel #3
0
        void setRates(TypeOfDayChoice pTypeOfDayChoice, TimeOfDayPolicy pTimeOfDayPolicy, DayTimeDto[] pDayTimePeriods, RateDto[] pRateList, bool pIsPotentiallyUnknownDayPolicy)
        {
            if (!validateTimePeriods(pDayTimePeriods, pTimeOfDayPolicy))
            {
                throw new ArgumentException("Invalid TimePeriod(s) for TypeOfDayChoice: [" + pTypeOfDayChoice + "] TimeOfDayPolicy: [" + pTimeOfDayPolicy + "]");
            }

            if (pTypeOfDayChoice == TypeOfDayChoice.RegularDay)
            {
                regularDay = new DayTypeDto(pDayTimePeriods, pTimeOfDayPolicy, true, pIsPotentiallyUnknownDayPolicy);

                regularDayRateEntry = new TypeOfDayRateEntryDto {
                    TypeOfDayChoice = pTypeOfDayChoice, Rates = pRateList
                };
            }
            if (pTypeOfDayChoice == TypeOfDayChoice.Weekend)
            {
                weekend = new DayTypeDto(pDayTimePeriods, pTimeOfDayPolicy, true, pIsPotentiallyUnknownDayPolicy);

                weekendRateEntry = new TypeOfDayRateEntryDto {
                    TypeOfDayChoice = pTypeOfDayChoice, Rates = pRateList
                };
            }
            if (pTypeOfDayChoice == TypeOfDayChoice.Holiday)
            {
                holiday = new DayTypeDto(pDayTimePeriods, pTimeOfDayPolicy, true, pIsPotentiallyUnknownDayPolicy);

                holidayRateEntry = new TypeOfDayRateEntryDto {
                    TypeOfDayChoice = pTypeOfDayChoice, Rates = pRateList
                };
            }
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public TypeOfDayRow GetByRateInfoIDTypeOfDayChoice(int pRateInfoID, TypeOfDayChoice pTypeOfDayChoice)
        {
            string _sqlStr = "SELECT * FROM [dbo].[TypeOfDay] WHERE " +
                             "[" + TypeOfDayRow.rate_info_id_DbName + "]=" + base.Database.CreateSqlParameterName(TypeOfDayRow.rate_info_id_PropName) +
                             " AND " +
                             "[" + TypeOfDayRow.type_of_day_choice_DbName + "]=" + base.Database.CreateSqlParameterName(TypeOfDayRow.type_of_day_choice_PropName);
            IDbCommand _cmd = base.Database.CreateCommand(_sqlStr);

            AddParameter(_cmd, TypeOfDayRow.rate_info_id_PropName, pRateInfoID);
            AddParameter(_cmd, TypeOfDayRow.type_of_day_choice_PropName, (byte)pTypeOfDayChoice);

            using (IDataReader _reader = _cmd.ExecuteReader()) {
                TypeOfDayRow[] _tempArray = MapRecords(_reader);
                return(_tempArray.Length == 0 ? null : _tempArray[0]);
            }
        }
Beispiel #6
0
        /*
         * Brazil|55|ROC_CEL|RegularDay|Blocked|0am-1am|0/0|0.0|0.0
         * Brazil|55|ROC_CEL|RegularDay|Night|11pm-11pm|30/6|0.1110000|0.1164000
         * Brazil|55|ROC_CEL|RegularDay|Day|2pm-9pm|1/1|0.2220000|0.2264000
         * Brazil|55|ROC_CEL|RegularDay|Eve|10pm-10pm|60/60|0.3330000|0.3364000
         *
         * OR
         *
         * Brazil|55|ROC_CEL|Weekend|Blocked|0am-1am|0/0|0.0|0.0
         * Brazil|55|ROC_CEL|Weekend|Peak|8am-8pm|30/6|0.1110000|0.1164000
         * Brazil|55|ROC_CEL|Weekend|OffPeak|2am-7am,9pm-11pm|1/1|0.2220000|0.2264000
         *
         * OR
         *
         * Brazil|55|ROC_CEL|Holiday|Blocked|0am-1am|0/0|0.0|0.0
         * Brazil|55|ROC_CEL|Holiday|Flat|2am-11pm|30/6|0.1110000|0.1164000
         */

        bool parseDayChoice(TypeOfDayChoice pTypeOfDayChoice, string[] pRouteLines)
        {
            TimeOfDayPolicy _timeOfDayPolicy;
            bool            _isPotentiallyUnknownDayPolicy;

            if (!parsePolicy(pRouteLines, out _timeOfDayPolicy, out _isPotentiallyUnknownDayPolicy))
            {
                return(false);
            }

            var _dayTimeList = new List <DayTimeDto>();
            var _rateList    = new List <RateDto>();

            foreach (string _routeLine in pRouteLines)
            {
                try {
                    //string[] _rateFields = _routeLine.Split(Configuration.Configuration.Instance.ImportExport_FieldDelimiter);
                    TimeOfDay _timeOfDay = parseTimeOfDay(_timeOfDayPolicy, _routeLine);

                    _dayTimeList.AddRange(parseDayTimeList(_timeOfDay, _routeLine));

                    _rateList.Add(parseRate(pTypeOfDayChoice, _timeOfDay, _routeLine));
                }
                catch (Exception _ex) {
                    badRouteLines.Add(_routeLine);
                    //TODO: T.LogRbr(LogSeverity.Error, "RatingInfoDto.parseDayChoice", string.Format("Exception:\r\n{0}", _ex));
                    return(false);
                }
            }

            try {
                setRates(pTypeOfDayChoice, _timeOfDayPolicy, _dayTimeList.ToArray(), _rateList.ToArray(), _isPotentiallyUnknownDayPolicy);
            }
            catch (Exception _ex) {
                badRouteLines.AddRange(pRouteLines);
                //TODO: T.LogRbr(LogSeverity.Error, "RatingInfoDto.parseDayChoice", string.Format("Exception2:\r\n{0}", _ex));
                return(false);
            }
            return(true);
        }
 internal TypeOfDayEntity(int pRateInfoId, TypeOfDayChoice pTypeOfDayChoice)
 {
     rateInfoId = pRateInfoId;
     loadRates(pRateInfoId, pTypeOfDayChoice);
 }
Beispiel #8
0
        public TimeOfDayPeriodRow GetByRateInfoIdTypeOfDayChoiceHour(int pRateInfoId, TypeOfDayChoice pTypeOfDayChoice, int pHour)
        {
            string _whereSql =
                "[" + TimeOfDayPeriodRow.rate_info_id_DbName + "]=" +
                Database.CreateSqlParameterName(TimeOfDayPeriodRow.rate_info_id_PropName) +
                " AND " +
                "[" + TimeOfDayPeriodRow.type_of_day_choice_DbName + "]=" +
                Database.CreateSqlParameterName(TimeOfDayPeriodRow.type_of_day_choice_PropName) +
                " AND " +
                "(" + Database.CreateSqlParameterName("pHour") +
                " BETWEEN [" + TimeOfDayPeriodRow.start_hour_DbName + "] AND [" + TimeOfDayPeriodRow.stop_hour_DbName + "]" +
                ")";

            IDbCommand _cmd = CreateGetCommand(_whereSql, null);

            AddParameter(_cmd, TimeOfDayPeriodRow.rate_info_id_PropName, pRateInfoId);
            AddParameter(_cmd, TimeOfDayPeriodRow.type_of_day_choice_PropName, (byte)pTypeOfDayChoice);
            Database.AddParameter(_cmd, "pHour", DbType.Int16, pHour);

            using (IDataReader _reader = _cmd.ExecuteReader()) {
                TimeOfDayPeriodRow[] _temp = MapRecords(_reader);
                return(0 == _temp.Length ? null : _temp[0]);
            }
        }