Example #1
0
        private static SimpleTable BuildSimpleTable(DataTable table)
        {
            SimpleTable newtable = new SimpleTable();

            foreach (DataColumn column in table.Columns)
            {
                newtable.Columns.Add(column.ColumnName);
            }

            foreach (DataRow row in table.Rows)
            {
                object[]  items  = row.ItemArray;
                SimpleRow newrow = newtable.Rows.Add();

                for (int i = 0; i < items.Length; i++)
                {
                    object item = items[i];
                    if (item != DBNull.Value)
                    {
                        newrow[i] = item;
                    }
                }
            }

            return(newtable);
        }
Example #2
0
        private static SimpleTable BuildSimpleTable(IDataReader reader)
        {
            SimpleTable newtable = new SimpleTable();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                newtable.Columns.Add(reader.GetName(i));
            }

            while (reader.Read())
            {
                SimpleRow newrow = newtable.Rows.Add();

                for (int i = 0; i < reader.FieldCount; i++)
                {
                    object item = reader[i];

                    if (item != DBNull.Value)
                    {
                        newrow[i] = item;
                    }
                }
            }

            return(newtable);
        }
        public SimpleRow Add()
        {
            SimpleRow newRow = new SimpleRow(table);

            rows.Add(newRow);

            return(newRow);
        }
Example #4
0
        private static SimpleTable BuildSimpleTable(IEnumerable collection)
        {
            SimpleTable newtable = new SimpleTable();

            PropertyInfo[] props;
            object         obj    = null;
            SimpleRow      newrow = null;

            int idx = 0;

            foreach (object item in collection)
            {
                props  = item.GetType().GetProperties();
                newrow = newtable.Rows.Add();

                foreach (PropertyInfo prop in props)
                {
                    if (idx == 0)
                    {
                        if (prop.CanRead &&
                            ((prop.PropertyType == typeof(String)) ||
                             (prop.PropertyType == typeof(Char)) ||
                             (prop.PropertyType == typeof(Byte)) ||
                             (prop.PropertyType == typeof(Int64)) ||
                             (prop.PropertyType == typeof(Int32)) ||
                             (prop.PropertyType == typeof(Int16)) ||
                             (prop.PropertyType == typeof(UInt64)) ||
                             (prop.PropertyType == typeof(UInt32)) ||
                             (prop.PropertyType == typeof(UInt16)) ||
                             (prop.PropertyType == typeof(Boolean)) ||
                             (prop.PropertyType == typeof(Decimal)) ||
                             (prop.PropertyType == typeof(Double)) ||
                             (prop.PropertyType == typeof(DateTime)) ||
                             (prop.PropertyType == typeof(TimeSpan)))
                            )
                        {
                            newtable.Columns.Add(prop.Name);
                        }
                    }

                    if (newtable.Columns.IndexOf(prop.Name) != -1)
                    {
                        obj = prop.GetGetMethod().Invoke(item, null);
                        newrow[prop.Name] = obj;
                    }
                }

                idx++;
            }

            return(newtable);
        }
 public SimpleRow this[int rowIndex]
 {
     get
     {
         if ((rowIndex >= 0) && (rowIndex < rows.Count))
         {
             return(rows[rowIndex] as SimpleRow);
         }
         else if (rowIndex == rows.Count)
         {
             SimpleRow row = this.Add();
             return(row);
         }
         else
         {
             throw new IndexOutOfRangeException("Index " + rowIndex + " is out of range. This SimpleTable has a row length of " + rows.Count + ".");
         }
     }
 }
	/// </summary>