コード例 #1
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="SAPFileCheckRow"/> objects.</returns>
        protected virtual SAPFileCheckRow[] 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 fileTypeColumnIndex = reader.GetOrdinal("FileType");
            int thresholdColumnIndex = reader.GetOrdinal("Threshold");
            int previousLineCountColumnIndex = reader.GetOrdinal("PreviousLineCount");
            int currentLineCountColumnIndex = reader.GetOrdinal("CurrentLineCount");
            int localeColumnIndex = reader.GetOrdinal("Locale");

            System.Collections.ArrayList recordList = new System.Collections.ArrayList();
            int ri = -startIndex;
            while(reader.Read())
            {
                ri++;
                if(ri > 0 && ri <= length)
                {
                    SAPFileCheckRow record = new SAPFileCheckRow();
                    recordList.Add(record);

                    record.FileType = Convert.ToString(reader.GetValue(fileTypeColumnIndex));
                    record.Threshold = Convert.ToInt32(reader.GetValue(thresholdColumnIndex));
                    if (!reader.IsDBNull(previousLineCountColumnIndex))
                        record.PreviousLineCount = Convert.ToInt32(reader.GetValue(previousLineCountColumnIndex));
                    if (!reader.IsDBNull(currentLineCountColumnIndex))
                        record.CurrentLineCount = Convert.ToInt32(reader.GetValue(currentLineCountColumnIndex));
                    record.Locale = Convert.ToString(reader.GetValue(localeColumnIndex));

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

            totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
            return (SAPFileCheckRow[])(recordList.ToArray(typeof(SAPFileCheckRow)));
        }
コード例 #2
0
 /// <summary>
 /// Converts <see cref="System.Data.DataRow"/> to <see cref="SAPFileCheckRow"/>.
 /// </summary>
 /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param>
 /// <returns>A reference to the <see cref="SAPFileCheckRow"/> object.</returns>
 protected virtual SAPFileCheckRow MapRow(DataRow row)
 {
     SAPFileCheckRow mappedObject = new SAPFileCheckRow();
     DataTable dataTable = row.Table;
     DataColumn dataColumn;
     // Column "FileType"
     dataColumn = dataTable.Columns["FileType"];
     if(!row.IsNull(dataColumn))
         mappedObject.FileType = (string)row[dataColumn];
     // Column "Threshold"
     dataColumn = dataTable.Columns["Threshold"];
     if(!row.IsNull(dataColumn))
         mappedObject.Threshold = (int)row[dataColumn];
     // Column "PreviousLineCount"
     dataColumn = dataTable.Columns["PreviousLineCount"];
     if(!row.IsNull(dataColumn))
         mappedObject.PreviousLineCount = (int)row[dataColumn];
     // Column "CurrentLineCount"
     dataColumn = dataTable.Columns["CurrentLineCount"];
     if(!row.IsNull(dataColumn))
         mappedObject.CurrentLineCount = (int)row[dataColumn];
     // Column "Locale"
     dataColumn = dataTable.Columns["Locale"];
     if (!row.IsNull(dataColumn))
         mappedObject.FileType = (string)row[dataColumn];
     return mappedObject;
 }
コード例 #3
0
 /// <summary>
 /// Updates a record in the <c>SAPFileCheck</c> table.
 /// </summary>
 /// <param name="value">The <see cref="SAPFileCheckRow"/>
 /// object used to update the table record.</param>
 /// <returns>true if the record was updated; otherwise, false.</returns>
 public virtual bool Update(SAPFileCheckRow value)
 {
     string sqlStr = "UPDATE [dbo].[SAPFileCheck] SET " +
         "[PreviousLineCount]=" + _db.CreateSqlParameterName("PreviousLineCount") + ", " +
         "[CurrentLineCount]=" + _db.CreateSqlParameterName("PreviousLineCount") +
         " WHERE " +
         "[FileType]=" + _db.CreateSqlParameterName("FileType") + " AND " +
         "[Locale]=" + _db.CreateSqlParameterName("Locale");
     IDbCommand cmd = _db.CreateCommand(sqlStr);
     AddParameter(cmd, "PreviousLineCount", value.PreviousLineCount);
     AddParameter(cmd, "CurrentLineCount", value.CurrentLineCount);
     AddParameter(cmd, "FileType", value.FileType);
     AddParameter(cmd, "Locale", value.Locale);
     return 0 != cmd.ExecuteNonQuery();
 }