internal static RatedRouteDto Get(Rbr_Db pDb, CarrierAcctDto pCarrierAcct, CarrierRouteRow pCarrierRouteRow) { if (pCarrierRouteRow == null) { return(null); } var _activeCarrierRouteEPMapCount = pDb.CarrierAcctEPMapCollection.GetActiveCountByCarrierRouteId(pCarrierRouteRow.Carrier_route_id); var _carrierRouteState = (_activeCarrierRouteEPMapCount > 0) ? RouteState.Valid : RouteState.NoActiveEndpoints; if (pCarrierAcct.IsRatingEnabled) { //get Rates status bool _allRatesValid; CarrierRateHistoryRow _carrierRateHistoryRow = pDb.CarrierRateHistoryCollection.GetByCarrierRouteIdDate(pCarrierRouteRow.Carrier_route_id, DateTime.Today); if (_carrierRateHistoryRow == null) { _allRatesValid = false; } else { _allRatesValid = pDb.RateCollection.HasAllValidRates(_carrierRateHistoryRow.Rate_info_id); } _carrierRouteState = (_allRatesValid) ? _carrierRouteState | RouteState.Valid : _carrierRouteState | RouteState.NoRates; } var _baseRoute = RoutingManager.GetBaseRoute(pDb, pCarrierRouteRow.Route_id); var _route = mapToRoute(pCarrierRouteRow, pCarrierAcct, _baseRoute, _carrierRouteState); return(_route); }
/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="CarrierRateHistoryRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="CarrierRateHistoryRow"/> object.</returns> protected virtual CarrierRateHistoryRow MapRow(DataRow row) { CarrierRateHistoryRow mappedObject = new CarrierRateHistoryRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Carrier_route_id" dataColumn = dataTable.Columns["Carrier_route_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Carrier_route_id = (int)row[dataColumn]; } // Column "Date_on" dataColumn = dataTable.Columns["Date_on"]; if (!row.IsNull(dataColumn)) { mappedObject.Date_on = (System.DateTime)row[dataColumn]; } // Column "Date_off" dataColumn = dataTable.Columns["Date_off"]; if (!row.IsNull(dataColumn)) { mappedObject.Date_off = (System.DateTime)row[dataColumn]; } // Column "Rate_info_id" dataColumn = dataTable.Columns["Rate_info_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Rate_info_id = (int)row[dataColumn]; } return(mappedObject); }
/// <summary> /// Updates a record in the <c>CarrierRateHistory</c> table. /// </summary> /// <param name="value">The <see cref="CarrierRateHistoryRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(CarrierRateHistoryRow value) { string sqlStr = "UPDATE [dbo].[CarrierRateHistory] SET " + "[date_off]=" + _db.CreateSqlParameterName("Date_off") + ", " + "[rate_info_id]=" + _db.CreateSqlParameterName("Rate_info_id") + " WHERE " + "[carrier_route_id]=" + _db.CreateSqlParameterName("Carrier_route_id") + " AND " + "[date_on]=" + _db.CreateSqlParameterName("Date_on"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Date_off", value.Date_off); AddParameter(cmd, "Rate_info_id", value.Rate_info_id); AddParameter(cmd, "Carrier_route_id", value.Carrier_route_id); AddParameter(cmd, "Date_on", value.Date_on); return(0 != cmd.ExecuteNonQuery()); }
/// <summary> /// Reads data from the provided data reader and returns /// an array of mapped objects. /// </summary> /// <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the table.</param> /// <param name="startIndex">The index of the first record to map.</param> /// <param name="length">The number of records to map.</param> /// <param name="totalRecordCount">A reference parameter that returns the total number /// of records in the reader object if 0 was passed into the method; otherwise it returns -1.</param> /// <returns>An array of <see cref="CarrierRateHistoryRow"/> objects.</returns> protected virtual CarrierRateHistoryRow[] MapRecords(IDataReader reader, int startIndex, int length, ref int totalRecordCount) { if (0 > startIndex) { throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero."); } if (0 > length) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero."); } int carrier_route_idColumnIndex = reader.GetOrdinal("carrier_route_id"); int date_onColumnIndex = reader.GetOrdinal("date_on"); int date_offColumnIndex = reader.GetOrdinal("date_off"); int rate_info_idColumnIndex = reader.GetOrdinal("rate_info_id"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { CarrierRateHistoryRow record = new CarrierRateHistoryRow(); recordList.Add(record); record.Carrier_route_id = Convert.ToInt32(reader.GetValue(carrier_route_idColumnIndex)); record.Date_on = Convert.ToDateTime(reader.GetValue(date_onColumnIndex)); record.Date_off = Convert.ToDateTime(reader.GetValue(date_offColumnIndex)); record.Rate_info_id = Convert.ToInt32(reader.GetValue(rate_info_idColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((CarrierRateHistoryRow[])(recordList.ToArray(typeof(CarrierRateHistoryRow)))); }
/// <summary> /// Adds a new record into the <c>CarrierRateHistory</c> table. /// </summary> /// <param name="value">The <see cref="CarrierRateHistoryRow"/> object to be inserted.</param> public virtual void Insert(CarrierRateHistoryRow value) { string sqlStr = "INSERT INTO [dbo].[CarrierRateHistory] (" + "[carrier_route_id], " + "[date_on], " + "[date_off], " + "[rate_info_id]" + ") VALUES (" + _db.CreateSqlParameterName("Carrier_route_id") + ", " + _db.CreateSqlParameterName("Date_on") + ", " + _db.CreateSqlParameterName("Date_off") + ", " + _db.CreateSqlParameterName("Rate_info_id") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Carrier_route_id", value.Carrier_route_id); AddParameter(cmd, "Date_on", value.Date_on); AddParameter(cmd, "Date_off", value.Date_off); AddParameter(cmd, "Rate_info_id", value.Rate_info_id); cmd.ExecuteNonQuery(); }
void exportCarrierRates() { try { countries = new SortedList <string, CountryRecord>(); using (var _db = new Rbr_Db()) { CarrierAcctDto _carrierAcct = getCarrierAcct(_db); RouteRow[] _baseRouteRows = _db.RouteCollection.GetByCalling_plan_id(_carrierAcct.CallingPlan.CallingPlanId); if (_baseRouteRows == null || _baseRouteRows.Length <= 0) { reportStatus(LogSeverity.Status, "DialPlanExporter.exportCarrierRates", "WARNING: No Routes to Process..."); return; } _baseRouteRows = RoutingManager.SortRouteRows(_baseRouteRows); string _filePath = getFilePath(); using (var _sw = new StreamWriter(_filePath, false)) { _sw.WriteLine(args.PerMinute ? RatesFileHeaderCostPerMinute : RatesFileHeaderCostPerIncrements); int _index = 0; CountryRecord _countryRecord = null; foreach (RouteRow _baseRouteRow in _baseRouteRows) { host.ReportProgress(_index++ *100 / _baseRouteRows.Length); CarrierRouteRow _carrierRouteRow = _db.CarrierRouteCollection.GetByCarrierAcctIdRouteId(_carrierAcct.CarrierAcctId, _baseRouteRow.Route_id); if (_carrierRouteRow == null) { continue; } if (_countryRecord == null || _countryRecord.Name != _baseRouteRow.Name) { _countryRecord = getCountryRecord(_db, _baseRouteRow); } RouteRecord _routeRecord = getRouteRecord(_baseRouteRow, _countryRecord); _countryRecord.Routes.Add(_routeRecord.FullName, _routeRecord); CarrierRateHistoryRow _carrierRateHistoryRow = _db.CarrierRateHistoryCollection.GetByCarrierRouteIdDate(_carrierRouteRow.Carrier_route_id, DateTime.Today); if (_carrierRateHistoryRow != null) { RatingInfoDto _ratingInfo = RatingManager.GetRatingInfo(_db, _carrierRateHistoryRow.Rate_info_id, false); if (_ratingInfo == null) { reportStatus(LogSeverity.Critical, "DialPlanExporter.exportCarrierRates", string.Format("RatingInfo == null, {0}", _carrierRateHistoryRow.Rate_info_id)); continue; } _routeRecord.RatingInfo = _ratingInfo; reportStatus(LogSeverity.Status, "DialPlanExporter.exportCarrierRates", string.Format("Exporting Rates for Route: {0}", _routeRecord.FullName)); _sw.Write(_routeRecord.GetRatesAsString(args.PerMinute)); } } } } } catch (Exception _ex) { TimokLogger.Instance.LogRbr(LogSeverity.Critical, "DialPlanExporter.exportCarrierRates", _ex.ToString()); throw; } }
/// <summary> /// Deletes the specified object from the <c>CarrierRateHistory</c> table. /// </summary> /// <param name="value">The <see cref="CarrierRateHistoryRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(CarrierRateHistoryRow value) { return(DeleteByPrimaryKey(value.Carrier_route_id, value.Date_on)); }