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

            // Column "Box_id"
            dataColumn = dataTable.Columns["Box_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Box_id = (int)row[dataColumn];
            }
            // Column "Date_created"
            dataColumn = dataTable.Columns["Date_created"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Date_created = (System.DateTime)row[dataColumn];
            }
            // Column "Date_activated"
            dataColumn = dataTable.Columns["Date_activated"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Date_activated = (System.DateTime)row[dataColumn];
            }
            return(mappedObject);
        }
Example #2
0
        /// <summary>
        /// Updates a record in the <c>Box</c> table.
        /// </summary>
        /// <param name="value">The <see cref="BoxRow"/>
        /// object used to update the table record.</param>
        /// <returns>true if the record was updated; otherwise, false.</returns>
        public virtual bool Update(BoxRow value)
        {
            string sqlStr = "UPDATE [dbo].[Box] SET " +
                            "[date_created]=" + _db.CreateSqlParameterName("Date_created") + ", " +
                            "[date_activated]=" + _db.CreateSqlParameterName("Date_activated") +
                            " WHERE " +
                            "[box_id]=" + _db.CreateSqlParameterName("Box_id");
            IDbCommand cmd = _db.CreateCommand(sqlStr);

            AddParameter(cmd, "Date_created", value.Date_created);
            AddParameter(cmd, "Date_activated",
                         value.IsDate_activatedNull ? DBNull.Value : (object)value.Date_activated);
            AddParameter(cmd, "Box_id", value.Box_id);
            return(0 != cmd.ExecuteNonQuery());
        }
Example #3
0
        /// <summary>
        /// Adds a new record into the <c>Box</c> table.
        /// </summary>
        /// <param name="value">The <see cref="BoxRow"/> object to be inserted.</param>
        public virtual void Insert(BoxRow value)
        {
            string sqlStr = "INSERT INTO [dbo].[Box] (" +
                            "[box_id], " +
                            "[date_created], " +
                            "[date_activated]" +
                            ") VALUES (" +
                            _db.CreateSqlParameterName("Box_id") + ", " +
                            _db.CreateSqlParameterName("Date_created") + ", " +
                            _db.CreateSqlParameterName("Date_activated") + ")";
            IDbCommand cmd = _db.CreateCommand(sqlStr);

            AddParameter(cmd, "Box_id", value.Box_id);
            AddParameter(cmd, "Date_created", value.Date_created);
            AddParameter(cmd, "Date_activated",
                         value.IsDate_activatedNull ? DBNull.Value : (object)value.Date_activated);
            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.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="BoxRow"/> objects.</returns>
        protected virtual BoxRow[] 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 box_idColumnIndex         = reader.GetOrdinal("box_id");
            int date_createdColumnIndex   = reader.GetOrdinal("date_created");
            int date_activatedColumnIndex = reader.GetOrdinal("date_activated");

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

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

                    record.Box_id       = Convert.ToInt32(reader.GetValue(box_idColumnIndex));
                    record.Date_created = Convert.ToDateTime(reader.GetValue(date_createdColumnIndex));
                    if (!reader.IsDBNull(date_activatedColumnIndex))
                    {
                        record.Date_activated = Convert.ToDateTime(reader.GetValue(date_activatedColumnIndex));
                    }

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

            totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
            return((BoxRow[])(recordList.ToArray(typeof(BoxRow))));
        }
 public void RemoveBoxRow(BoxRow row) {
     this.Rows.Remove(row);
 }
 public void AddBoxRow(BoxRow row) {
     this.Rows.Add(row);
 }
 public BoxRowChangeEvent(BoxRow row, global::System.Data.DataRowAction action) {
     this.eventRow = row;
     this.eventAction = action;
 }
Example #8
0
 /// <summary>
 /// Deletes the specified object from the <c>Box</c> table.
 /// </summary>
 /// <param name="value">The <see cref="BoxRow"/> object to delete.</param>
 /// <returns>true if the record was deleted; otherwise, false.</returns>
 public bool Delete(BoxRow value)
 {
     return(DeleteByPrimaryKey(value.Box_id));
 }