/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="WholesaleRateHistoryRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="WholesaleRateHistoryRow"/> object.</returns> protected virtual WholesaleRateHistoryRow MapRow(DataRow row) { WholesaleRateHistoryRow mappedObject = new WholesaleRateHistoryRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Wholesale_route_id" dataColumn = dataTable.Columns["Wholesale_route_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Wholesale_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>WholesaleRateHistory</c> table. /// </summary> /// <param name="value">The <see cref="WholesaleRateHistoryRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(WholesaleRateHistoryRow value) { string sqlStr = "UPDATE [dbo].[WholesaleRateHistory] SET " + "[date_off]=" + _db.CreateSqlParameterName("Date_off") + ", " + "[rate_info_id]=" + _db.CreateSqlParameterName("Rate_info_id") + " WHERE " + "[wholesale_route_id]=" + _db.CreateSqlParameterName("Wholesale_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, "Wholesale_route_id", value.Wholesale_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="WholesaleRateHistoryRow"/> objects.</returns> protected virtual WholesaleRateHistoryRow[] 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 wholesale_route_idColumnIndex = reader.GetOrdinal("wholesale_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) { WholesaleRateHistoryRow record = new WholesaleRateHistoryRow(); recordList.Add(record); record.Wholesale_route_id = Convert.ToInt32(reader.GetValue(wholesale_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((WholesaleRateHistoryRow[])(recordList.ToArray(typeof(WholesaleRateHistoryRow)))); }
/// <summary> /// Adds a new record into the <c>WholesaleRateHistory</c> table. /// </summary> /// <param name="value">The <see cref="WholesaleRateHistoryRow"/> object to be inserted.</param> public virtual void Insert(WholesaleRateHistoryRow value) { string sqlStr = "INSERT INTO [dbo].[WholesaleRateHistory] (" + "[wholesale_route_id], " + "[date_on], " + "[date_off], " + "[rate_info_id]" + ") VALUES (" + _db.CreateSqlParameterName("Wholesale_route_id") + ", " + _db.CreateSqlParameterName("Date_on") + ", " + _db.CreateSqlParameterName("Date_off") + ", " + _db.CreateSqlParameterName("Rate_info_id") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Wholesale_route_id", value.Wholesale_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(); }
//------------------------------------- Private ---------------------------------------------- void exportWholesaleRates() { try { countries = new SortedList <string, CountryRecord>(); using (var _db = new Rbr_Db()) { ServiceDto _service = getService(_db); RouteRow[] _baseRouteRows = _db.RouteCollection.GetByCallingPlanIdRoutingPlanId(_service.CallingPlanId, args.RoutingPlanId); if (_baseRouteRows == null || _baseRouteRows.Length <= 0) { reportStatus(LogSeverity.Status, "DialPlanExporter.exportWholesaleRates", "WARNING: No Routes to Export..."); 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); WholesaleRouteRow _wholesaleRouteRow = _db.WholesaleRouteCollection.GetByServiceIdBaseRouteId(_service.ServiceId, _baseRouteRow.Route_id); if (_wholesaleRouteRow == null) { continue; } if (_countryRecord == null || _countryRecord.Name != _baseRouteRow.Name) { _countryRecord = getCountryRecord(_db, _baseRouteRow); } RouteRecord _routeRecord = getRouteRecord(_baseRouteRow, _countryRecord); _countryRecord.Routes.Add(_routeRecord.FullName, _routeRecord); WholesaleRateHistoryRow _wholesaleRateHistoryRow = _db.WholesaleRateHistoryCollection.GetByWholesaleRouteIdDate(_wholesaleRouteRow.Wholesale_route_id, DateTime.Today); if (_wholesaleRateHistoryRow != null) { RatingInfoDto _ratingInfo = RatingManager.GetRatingInfo(_db, _wholesaleRateHistoryRow.Rate_info_id, false); if (_ratingInfo == null) { reportStatus(LogSeverity.Critical, "DialPlanExporter.exportWholesaleRates", string.Format("RatingInfo == null, {0}", _wholesaleRateHistoryRow.Rate_info_id)); continue; } _routeRecord.RatingInfo = _ratingInfo; reportStatus(LogSeverity.Status, "DialPlanExporter.exportWholesaleRates", string.Format("Exporting Rates for Route: {0}", _routeRecord.FullName)); _sw.Write(_routeRecord.GetRatesAsString(args.PerMinute)); } } } } } catch (Exception _ex) { reportStatus(LogSeverity.Critical, "DialPlanExporter.exportWholesaleRates", string.Format("Exception:\r\n{0}", _ex)); throw; } }
/// <summary> /// Deletes the specified object from the <c>WholesaleRateHistory</c> table. /// </summary> /// <param name="value">The <see cref="WholesaleRateHistoryRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(WholesaleRateHistoryRow value) { return(DeleteByPrimaryKey(value.Wholesale_route_id, value.Date_on)); }