ITPub博客

首页 > 数据库 > 数据库开发技术 > DBReader/Classes/ResultSet

DBReader/Classes/ResultSet

原创 数据库开发技术 作者:njms 时间:2007-09-11 23:09:31 0 删除 编辑

/**
*
* DBReader 1.0, Access to SAP tables using SAP's .Net Connector.
*
* Author: hardteck
* Email: hardteck@web.de
*
* Last modified: Fr, 17. Okt 2003, 11:31:25
*/
namespace SAPReader {
using System;
using System.Collections;
using SAPReader.SAPKernel;

///


/// A ResultSet gathers a set of ResultLines.
/// It is used by SAPReader.TableReader to store the
/// rows returned by RFC_READ_TABLE.
///
///

public class ResultSet {
///
/// Set of ResultColumns.
///

protected System.Collections.Hashtable cols = null;
///
/// The constructor.
///

public ResultSet(){
this.cols = new Hashtable();
}
///
/// Adds an entry to the resultset. Note that the order of
/// insertion should follow one of the main two natural
/// traversals of the table: row-by-row, or column-by-column.
/// Additionally, the caller is responsible for making all columns
/// the same size to prevent access violations at a later
/// traversal.
///

/// Fieldname of the column the entry is designated for.
/// The entry to add.
public void addEntry(RFC_DB_FLD field, string entry){
ResultColumn col = null;
if(this.cols.Contains(field.Fieldname)){
col = (ResultColumn)this.cols[field.Fieldname];
}
if(col == null){
col = new ResultColumn(field);
this.cols.Add(field.Fieldname, col);
}
col.addEntry(entry);
}
///
/// The number of ResultLines in the set.
///

public int RowCount {
get{return this.cols.Count;}
}
///
/// Returns the number of rows of the set.
/// If the number of rows for all the columns
/// is not equal, an exception is thrown.
///

public int LineCount {
get{
int maxLineCount = this.MinLineCount;
int minLineCount = this.MinLineCount;
if(maxLineCount != minLineCount){
throw new System.Exception(
"The ResultSet contains unequal rows."
);
}
return minLineCount;
}
}
///
/// Returns the number of rows the longest
/// column in the set contains.
///

public int MaxLineCount {
get{
int maxLineCount = 0;
foreach(string field in this.cols.Keys){
ResultColumn col = (ResultColumn)this.cols[field];
if(col.Count > maxLineCount){
maxLineCount = col.Count;
}
}
return maxLineCount;
}
}
///
/// Returns the number of rows the shortest
/// column in the set contains.
///

public int MinLineCount {
get{
int minLineCount = int.MaxValue;
foreach(string field in this.cols.Keys){
ResultColumn col = (ResultColumn)this.cols[field];
if(col.Count < minLineCount){
minLineCount = col.Count;
}
}
return minLineCount;
}
}
///
/// Clear the set.
///

public void Clear(){
this.cols.Clear();
}
///
/// Access to the i-th ResultColumn.
/// This method returns a complete column. For direct access
/// to a certain field of the column use
/// instead.
///

public SAPReader.ResultColumn this[string fieldName]{
get{return (ResultColumn)this.cols[fieldName];}
}//indexer
///
/// Returns an entry at the specified row of the column
/// determined by the given fieldname. Note that counting
/// rows starts at 0.
///

/// Fieldname of the column.
/// Number of the row starting at 0.
///
public string getEntryAt(string fieldName, int row){
if(this.cols.Contains(fieldName)){
ResultColumn col = (ResultColumn)this.cols[fieldName];
return col.getEntryAt(row);
}
return null;
}
}//ResultSet
}

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/232040/viewspace-969002/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    15
  • 访问量
    53957