Example #1
0
        /// <summary>
        /// Converts <see cref="System.Data.DataRow"/> to <see cref="BedInfoRow"/>.
        /// </summary>
        /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param>
        /// <returns>A reference to the <see cref="BedInfoRow"/> object.</returns>
        protected virtual BedInfoRow MapRow(DataRow row)
        {
            BedInfoRow mappedObject = new BedInfoRow();
            DataTable  dataTable    = row.Table;
            DataColumn dataColumn;

            // Column "BedIDD"
            dataColumn = dataTable.Columns["BedIDD"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.BedIDD = (int)row[dataColumn];
            }
            // Column "BedName"
            dataColumn = dataTable.Columns["BedName"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.BedName = (string)row[dataColumn];
            }
            // Column "RatePerDay"
            dataColumn = dataTable.Columns["RatePerDay"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.RatePerDay = (int)row[dataColumn];
            }
            // Column "BedType"
            dataColumn = dataTable.Columns["BedType"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.BedType = (string)row[dataColumn];
            }
            return(mappedObject);
        }
Example #2
0
        /// <summary>
        /// Adds a new record into the <c>BedInfo</c> table.
        /// </summary>
        /// <param name="value">The <see cref="BedInfoRow"/> object to be inserted.</param>
        public virtual void Insert(BedInfoRow value)
        {
            SqlCommand cmd = _db.CreateCommand("dbo._BedInfo_Insert", true);

            AddParameter(cmd, "BedName", value.BedName);
            AddParameter(cmd, "RatePerDay",
                         value.IsRatePerDayNull ? DBNull.Value : (object)value.RatePerDay);
            AddParameter(cmd, "BedType", value.BedType);
            value.BedIDD = Convert.ToInt32(cmd.ExecuteScalar());
        }
Example #3
0
        /// <summary>
        /// Updates a record in the <c>BedInfo</c> table.
        /// </summary>
        /// <param name="value">The <see cref="BedInfoRow"/>
        /// object used to update the table record.</param>
        /// <returns>true if the record was updated; otherwise, false.</returns>
        public virtual bool Update(BedInfoRow value)
        {
            SqlCommand cmd = _db.CreateCommand("dbo._BedInfo_Update", true);

            AddParameter(cmd, "BedName", value.BedName);
            AddParameter(cmd, "RatePerDay",
                         value.IsRatePerDayNull ? DBNull.Value : (object)value.RatePerDay);
            AddParameter(cmd, "BedType", value.BedType);
            AddParameter(cmd, "BedIDD", value.BedIDD);

            return(0 != cmd.ExecuteNonQuery());
        }
Example #4
0
        /// <summary>
        /// Reads data from the provided data reader and returns
        /// an array of mapped objects.
        /// </summary>
        /// <param name="reader">The <see cref="System.Data.SqlDataReader"/> 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="BedInfoRow"/> objects.</returns>
        protected virtual BedInfoRow[] MapRecords(SqlDataReader 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 bedIDDColumnIndex     = reader.GetOrdinal("BedIDD");
            int bedNameColumnIndex    = reader.GetOrdinal("BedName");
            int ratePerDayColumnIndex = reader.GetOrdinal("RatePerDay");
            int bedTypeColumnIndex    = reader.GetOrdinal("BedType");

            System.Collections.ArrayList recordList = new System.Collections.ArrayList();
            int ri = -startIndex;

            while (reader.Read())
            {
                ri++;
                if (ri > 0 && ri <= length)
                {
                    BedInfoRow record = new BedInfoRow();
                    recordList.Add(record);

                    record.BedIDD = Convert.ToInt32(reader.GetValue(bedIDDColumnIndex));
                    if (!reader.IsDBNull(bedNameColumnIndex))
                    {
                        record.BedName = Convert.ToString(reader.GetValue(bedNameColumnIndex));
                    }
                    if (!reader.IsDBNull(ratePerDayColumnIndex))
                    {
                        record.RatePerDay = Convert.ToInt32(reader.GetValue(ratePerDayColumnIndex));
                    }
                    if (!reader.IsDBNull(bedTypeColumnIndex))
                    {
                        record.BedType = Convert.ToString(reader.GetValue(bedTypeColumnIndex));
                    }

                    if (ri == length && 0 != totalRecordCount)
                    {
                        break;
                    }
                }
            }

            totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
            return((BedInfoRow[])(recordList.ToArray(typeof(BedInfoRow))));
        }
Example #5
0
 /// <summary>
 /// Deletes the specified object from the <c>BedInfo</c> table.
 /// </summary>
 /// <param name="value">The <see cref="BedInfoRow"/> object to delete.</param>
 /// <returns>true if the record was deleted; otherwise, false.</returns>
 public bool Delete(BedInfoRow value)
 {
     return(DeleteByPrimaryKey(value.BedIDD));
 }