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

            // Column "ProvId"
            dataColumn = dataTable.Columns["ProvId"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.ProvId = (int)row[dataColumn];
            }
            // Column "ProvNameEng"
            dataColumn = dataTable.Columns["ProvNameEng"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.ProvNameEng = (string)row[dataColumn];
            }
            // Column "Prov_Code"
            dataColumn = dataTable.Columns["Prov_Code"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Prov_Code = (string)row[dataColumn];
            }
            return(mappedObject);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a new record into the <c>lkpProvince</c> table.
        /// </summary>
        /// <param name="value">The <see cref="lkpProvinceRow"/> object to be inserted.</param>
        public virtual void Insert(lkpProvinceRow value)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._lkpProvince_Insert", true);

            AddParameter(cmd, "ProvNameEng", value.ProvNameEng);
            AddParameter(cmd, "Prov_Code", value.Prov_Code);
            value.ProvId = Convert.ToInt32(cmd.ExecuteScalar());
        }
Beispiel #3
0
        /// <summary>
        /// Updates a record in the <c>lkpProvince</c> table.
        /// </summary>
        /// <param name="value">The <see cref="lkpProvinceRow"/>
        /// object used to update the table record.</param>
        /// <returns>true if the record was updated; otherwise, false.</returns>
        public virtual bool Update(lkpProvinceRow value)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._lkpProvince_Update", true);

            AddParameter(cmd, "ProvNameEng", value.ProvNameEng);
            AddParameter(cmd, "Prov_Code", value.Prov_Code);
            AddParameter(cmd, "ProvId", value.ProvId);
            return(0 != cmd.ExecuteNonQuery());
        }
Beispiel #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="lkpProvinceRow"/> objects.</returns>
        protected virtual lkpProvinceRow[] 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 provIdColumnIndex      = reader.GetOrdinal("ProvId");
            int provNameEngColumnIndex = reader.GetOrdinal("ProvNameEng");
            int prov_CodeColumnIndex   = reader.GetOrdinal("Prov_Code");

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

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

                    record.ProvId      = Convert.ToInt32(reader.GetValue(provIdColumnIndex));
                    record.ProvNameEng = Convert.ToString(reader.GetValue(provNameEngColumnIndex));
                    if (!reader.IsDBNull(prov_CodeColumnIndex))
                    {
                        record.Prov_Code = Convert.ToString(reader.GetValue(prov_CodeColumnIndex));
                    }

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

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