/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="tblItemRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="tblItemRow"/> object.</returns> protected virtual tblItemRow MapRow(DataRow row) { tblItemRow mappedObject = new tblItemRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Item_Id" dataColumn = dataTable.Columns["Item_Id"]; if (!row.IsNull(dataColumn)) { mappedObject.Item_Id = (int)row[dataColumn]; } // Column "Item_Name" dataColumn = dataTable.Columns["Item_Name"]; if (!row.IsNull(dataColumn)) { mappedObject.Item_Name = (string)row[dataColumn]; } // Column "Item_Type_Id" dataColumn = dataTable.Columns["Item_Type_Id"]; if (!row.IsNull(dataColumn)) { mappedObject.Item_Type_Id = (int)row[dataColumn]; } // Column "Status" dataColumn = dataTable.Columns["Status"]; if (!row.IsNull(dataColumn)) { mappedObject.Status = (bool)row[dataColumn]; } return(mappedObject); }
/// <summary> /// Adds a new record into the <c>tblItem</c> table. /// </summary> /// <param name="value">The <see cref="tblItemRow"/> object to be inserted.</param> public virtual void Insert(tblItemRow value) { IDbCommand cmd = _db.CreateCommand("dbo._tblItem_Insert", true); AddParameter(cmd, "Item_Name", value.Item_Name); AddParameter(cmd, "Item_Type_Id", value.Item_Type_Id); AddParameter(cmd, "Status", value.Status); value.Item_Id = Convert.ToInt32(cmd.ExecuteScalar()); }
/// <summary> /// Updates a record in the <c>tblItem</c> table. /// </summary> /// <param name="value">The <see cref="tblItemRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(tblItemRow value) { IDbCommand cmd = _db.CreateCommand("dbo._tblItem_Update", true); AddParameter(cmd, "Item_Name", value.Item_Name); AddParameter(cmd, "Item_Type_Id", value.Item_Type_Id); AddParameter(cmd, "Status", value.Status); AddParameter(cmd, "Item_Id", value.Item_Id); 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="tblItemRow"/> objects.</returns> protected virtual tblItemRow[] 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 item_IdColumnIndex = reader.GetOrdinal("Item_Id"); int item_NameColumnIndex = reader.GetOrdinal("Item_Name"); int item_Type_IdColumnIndex = reader.GetOrdinal("Item_Type_Id"); int statusColumnIndex = reader.GetOrdinal("Status"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { tblItemRow record = new tblItemRow(); recordList.Add(record); record.Item_Id = Convert.ToInt32(reader.GetValue(item_IdColumnIndex)); record.Item_Name = Convert.ToString(reader.GetValue(item_NameColumnIndex)); record.Item_Type_Id = Convert.ToInt32(reader.GetValue(item_Type_IdColumnIndex)); record.Status = Convert.ToBoolean(reader.GetValue(statusColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((tblItemRow[])(recordList.ToArray(typeof(tblItemRow)))); }
/// <summary> /// Deletes the specified object from the <c>tblItem</c> table. /// </summary> /// <param name="value">The <see cref="tblItemRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(tblItemRow value) { return(DeleteByPrimaryKey(value.Item_Id)); }