/// <summary> /// Deletes the specified object from the <c>Brand</c> table. /// </summary> /// <param name="value">The <see cref="BrandRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(BrandRow value) { return DeleteByPrimaryKey(value.BrandName); }
/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="BrandRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="BrandRow"/> object.</returns> protected virtual BrandRow MapRow(DataRow row) { BrandRow mappedObject = new BrandRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "PkID" dataColumn = dataTable.Columns["PkID"]; if(!row.IsNull(dataColumn)) mappedObject.PkID = (int)row[dataColumn]; // Column "BrandName" dataColumn = dataTable.Columns["BrandName"]; if(!row.IsNull(dataColumn)) mappedObject.BrandName = (string)row[dataColumn]; // Column "B2CBrandName" dataColumn = dataTable.Columns["B2CBrandName"]; if(!row.IsNull(dataColumn)) mappedObject.B2CBrandName = (string)row[dataColumn]; // Column "SalesOrg" dataColumn = dataTable.Columns["SalesOrg"]; if(!row.IsNull(dataColumn)) mappedObject.SalesOrg = (string)row[dataColumn]; // Column "DC" dataColumn = dataTable.Columns["DC"]; if(!row.IsNull(dataColumn)) mappedObject.DC = (string)row[dataColumn]; return mappedObject; }
/// <summary> /// Updates a record in the <c>Brand</c> table. /// </summary> /// <param name="value">The <see cref="BrandRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(BrandRow value) { string sqlStr = "UPDATE [dbo].[Brand] SET " + "[B2CBrandName]=" + _db.CreateSqlParameterName("B2CBrandName") + ", " + "[SalesOrg]=" + _db.CreateSqlParameterName("SalesOrg") + ", " + "[DC]=" + _db.CreateSqlParameterName("DC") + " WHERE " + "[BrandName]=" + _db.CreateSqlParameterName("BrandName"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "B2CBrandName", value.B2CBrandName); AddParameter(cmd, "SalesOrg", value.SalesOrg); AddParameter(cmd, "DC", value.DC); AddParameter(cmd, "BrandName", value.BrandName); 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="BrandRow"/> objects.</returns> protected virtual BrandRow[] 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 pkIDColumnIndex = reader.GetOrdinal("PkID"); int brandNameColumnIndex = reader.GetOrdinal("BrandName"); int b2CBrandNameColumnIndex = reader.GetOrdinal("B2CBrandName"); int salesOrgColumnIndex = reader.GetOrdinal("SalesOrg"); int dcColumnIndex = reader.GetOrdinal("DC"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while(reader.Read()) { ri++; if(ri > 0 && ri <= length) { BrandRow record = new BrandRow(); recordList.Add(record); record.PkID = Convert.ToInt32(reader.GetValue(pkIDColumnIndex)); record.BrandName = Convert.ToString(reader.GetValue(brandNameColumnIndex)); if(!reader.IsDBNull(b2CBrandNameColumnIndex)) record.B2CBrandName = Convert.ToString(reader.GetValue(b2CBrandNameColumnIndex)); record.SalesOrg = Convert.ToString(reader.GetValue(salesOrgColumnIndex)); record.DC = Convert.ToString(reader.GetValue(dcColumnIndex)); if(ri == length && 0 != totalRecordCount) break; } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return (BrandRow[])(recordList.ToArray(typeof(BrandRow))); }
/// <summary> /// Adds a new record into the <c>Brand</c> table. /// </summary> /// <param name="value">The <see cref="BrandRow"/> object to be inserted.</param> public virtual void Insert(BrandRow value) { string sqlStr = "INSERT INTO [dbo].[Brand] (" + "[BrandName], " + "[B2CBrandName], " + "[SalesOrg], " + "[DC]" + ") VALUES (" + _db.CreateSqlParameterName("BrandName") + ", " + _db.CreateSqlParameterName("B2CBrandName") + ", " + _db.CreateSqlParameterName("SalesOrg") + ", " + _db.CreateSqlParameterName("DC") + ");SELECT @@IDENTITY"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "BrandName", value.BrandName); AddParameter(cmd, "B2CBrandName", value.B2CBrandName); AddParameter(cmd, "SalesOrg", value.SalesOrg); AddParameter(cmd, "DC", value.DC); value.PkID = Convert.ToInt32(cmd.ExecuteScalar()); }