/// <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="TimeOfDayPeriodRow"/> objects.</returns> protected virtual TimeOfDayPeriodRow[] 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 rate_info_idColumnIndex = reader.GetOrdinal("rate_info_id"); int type_of_day_choiceColumnIndex = reader.GetOrdinal("type_of_day_choice"); int start_hourColumnIndex = reader.GetOrdinal("start_hour"); int stop_hourColumnIndex = reader.GetOrdinal("stop_hour"); int time_of_dayColumnIndex = reader.GetOrdinal("time_of_day"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { TimeOfDayPeriodRow record = new TimeOfDayPeriodRow(); recordList.Add(record); record.Rate_info_id = Convert.ToInt32(reader.GetValue(rate_info_idColumnIndex)); record.Type_of_day_choice = Convert.ToByte(reader.GetValue(type_of_day_choiceColumnIndex)); record.Start_hour = Convert.ToInt16(reader.GetValue(start_hourColumnIndex)); record.Stop_hour = Convert.ToInt16(reader.GetValue(stop_hourColumnIndex)); record.Time_of_day = Convert.ToByte(reader.GetValue(time_of_dayColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((TimeOfDayPeriodRow[])(recordList.ToArray(typeof(TimeOfDayPeriodRow)))); }
/// <summary> /// Updates a record in the <c>TimeOfDayPeriod</c> table. /// </summary> /// <param name="value">The <see cref="TimeOfDayPeriodRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(TimeOfDayPeriodRow value) { string sqlStr = "UPDATE [dbo].[TimeOfDayPeriod] SET " + "[stop_hour]=" + _db.CreateSqlParameterName("Stop_hour") + ", " + "[time_of_day]=" + _db.CreateSqlParameterName("Time_of_day") + " WHERE " + "[rate_info_id]=" + _db.CreateSqlParameterName("Rate_info_id") + " AND " + "[type_of_day_choice]=" + _db.CreateSqlParameterName("Type_of_day_choice") + " AND " + "[start_hour]=" + _db.CreateSqlParameterName("Start_hour"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Stop_hour", value.Stop_hour); AddParameter(cmd, "Time_of_day", value.Time_of_day); AddParameter(cmd, "Rate_info_id", value.Rate_info_id); AddParameter(cmd, "Type_of_day_choice", value.Type_of_day_choice); AddParameter(cmd, "Start_hour", value.Start_hour); return(0 != cmd.ExecuteNonQuery()); }
/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="TimeOfDayPeriodRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="TimeOfDayPeriodRow"/> object.</returns> protected virtual TimeOfDayPeriodRow MapRow(DataRow row) { TimeOfDayPeriodRow mappedObject = new TimeOfDayPeriodRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Rate_info_id" dataColumn = dataTable.Columns["Rate_info_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Rate_info_id = (int)row[dataColumn]; } // Column "Type_of_day_choice" dataColumn = dataTable.Columns["Type_of_day_choice"]; if (!row.IsNull(dataColumn)) { mappedObject.Type_of_day_choice = (byte)row[dataColumn]; } // Column "Start_hour" dataColumn = dataTable.Columns["Start_hour"]; if (!row.IsNull(dataColumn)) { mappedObject.Start_hour = (short)row[dataColumn]; } // Column "Stop_hour" dataColumn = dataTable.Columns["Stop_hour"]; if (!row.IsNull(dataColumn)) { mappedObject.Stop_hour = (short)row[dataColumn]; } // Column "Time_of_day" dataColumn = dataTable.Columns["Time_of_day"]; if (!row.IsNull(dataColumn)) { mappedObject.Time_of_day = (byte)row[dataColumn]; } return(mappedObject); }
/// <summary> /// Adds a new record into the <c>TimeOfDayPeriod</c> table. /// </summary> /// <param name="value">The <see cref="TimeOfDayPeriodRow"/> object to be inserted.</param> public virtual void Insert(TimeOfDayPeriodRow value) { string sqlStr = "INSERT INTO [dbo].[TimeOfDayPeriod] (" + "[rate_info_id], " + "[type_of_day_choice], " + "[start_hour], " + "[stop_hour], " + "[time_of_day]" + ") VALUES (" + _db.CreateSqlParameterName("Rate_info_id") + ", " + _db.CreateSqlParameterName("Type_of_day_choice") + ", " + _db.CreateSqlParameterName("Start_hour") + ", " + _db.CreateSqlParameterName("Stop_hour") + ", " + _db.CreateSqlParameterName("Time_of_day") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Rate_info_id", value.Rate_info_id); AddParameter(cmd, "Type_of_day_choice", value.Type_of_day_choice); AddParameter(cmd, "Start_hour", value.Start_hour); AddParameter(cmd, "Stop_hour", value.Stop_hour); AddParameter(cmd, "Time_of_day", value.Time_of_day); cmd.ExecuteNonQuery(); }
/// <summary> /// Deletes the specified object from the <c>TimeOfDayPeriod</c> table. /// </summary> /// <param name="value">The <see cref="TimeOfDayPeriodRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(TimeOfDayPeriodRow value) { return(DeleteByPrimaryKey(value.Rate_info_id, value.Type_of_day_choice, value.Start_hour)); }