Пример #1
0
        public void CopyTo()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add("Table1");
            tbcol.Add("Table2");
            tbcol.Add("Table3");
            tbcol.Add("Table4");

            DataTable[] array = new DataTable[4];
            /* copying to the beginning of the array */
            tbcol.CopyTo(array, 0);
            Assert.Equal(4, array.Length);
            Assert.Equal("Table1", array[0].TableName);
            Assert.Equal("Table2", array[1].TableName);
            Assert.Equal("Table3", array[2].TableName);
            Assert.Equal("Table4", array[3].TableName);

            /* copying with in a array */
            DataTable[] array1 = new DataTable[6];
            tbcol.CopyTo(array1, 2);
            Assert.Equal(null, array1[0]);
            Assert.Equal(null, array1[1]);
            Assert.Equal("Table1", array1[2].TableName);
            Assert.Equal("Table2", array1[3].TableName);
            Assert.Equal("Table3", array1[4].TableName);
            Assert.Equal("Table4", array1[5].TableName);
        }
Пример #2
0
        public void RemoveAt()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            tbcol.Add("table1");

            try
            {
                tbcol.RemoveAt(-1);
                Assert.False(true);
            }
            catch (IndexOutOfRangeException e)
            {
            }
            try
            {
                tbcol.RemoveAt(101);
                Assert.False(true);
            }
            catch (IndexOutOfRangeException e)
            {
            }
            tbcol.RemoveAt(1);
            Assert.Equal(1, tbcol.Count);
            tbcol.RemoveAt(0);
            Assert.Equal(0, tbcol.Count);
        }
Пример #3
0
        public void AddException4()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add("SameTableName");
            tbcol.Add("SameTableName");
        }
Пример #4
0
        public void RemoveAt()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            tbcol.Add("table1");

            try
            {
                tbcol.RemoveAt(-1);
                Fail("the index was out of bound: must have failed");
            }
            catch (IndexOutOfRangeException e)
            {
            }
            try
            {
                tbcol.RemoveAt(101);
                Fail("the index was out of bound: must have failed");
            }
            catch (IndexOutOfRangeException e)
            {
            }
            tbcol.RemoveAt(1);
            AssertEquals("test#5", 1, tbcol.Count);
            tbcol.RemoveAt(0);
            AssertEquals("test#6", 0, tbcol.Count);
        }
        public void CopyTo()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add("Table1");
            tbcol.Add("Table2");
            tbcol.Add("Table3");
            tbcol.Add("Table4");

            DataTable [] array = new DataTable[4];
            /* copying to the beginning of the array */
            tbcol.CopyTo(array, 0);
            Assert.AreEqual(4, array.Length, "test#01");
            Assert.AreEqual("Table1", array[0].TableName, "test#02");
            Assert.AreEqual("Table2", array[1].TableName, "test#03");
            Assert.AreEqual("Table3", array[2].TableName, "test#04");
            Assert.AreEqual("Table4", array[3].TableName, "test#05");

            /* copying with in a array */
            DataTable [] array1 = new DataTable[6];
            tbcol.CopyTo(array1, 2);
            Assert.AreEqual(null, array1[0], "test#06");
            Assert.AreEqual(null, array1[1], "test#07");
            Assert.AreEqual("Table1", array1[2].TableName, "test#08");
            Assert.AreEqual("Table2", array1[3].TableName, "test#09");
            Assert.AreEqual("Table3", array1[4].TableName, "test#10");
            Assert.AreEqual("Table4", array1[5].TableName, "test#11");
        }
Пример #6
0
        public void Add()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            int i, j;

            i = 0;

            foreach (DataTable table in tbcol)
            {
                Assert.Equal(_tables[i].TableName, table.TableName);
                j = 0;
                foreach (DataColumn column in table.Columns)
                {
                    Assert.Equal(_tables[i].Columns[j].ColumnName, column.ColumnName);
                    j++;
                }
                i++;
            }

            tbcol.Add(_tables[1]);
            i = 0;
            foreach (DataTable table in tbcol)
            {
                Assert.Equal(_tables[i].TableName, table.TableName);
                j = 0;
                foreach (DataColumn column in table.Columns)
                {
                    Assert.Equal(_tables[i].Columns[j].ColumnName, column.ColumnName);
                    j++;
                }
                i++;
            }
        }
Пример #7
0
        public void AddException2()
        {
            /* table already exist in the collection */
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            tbcol.Add(_tables[0]);
        }
Пример #8
0
        private void FillData()
        {
            var descriptions = new List <string>()
            {
                "Across all our software products and services, our focus is on helping our customers achieve their goals. Our key principles – thoroughly understanding our customers' business objectives, maintaining a strong emphasis on quality, and adhering to the highest ethical standards – serve as the foundation for everything we do."
            };

            // Products table
            var productsDataTable = new DataTable("Products");

            DataColumnCollection productsColumns = productsDataTable.Columns;

            // Add columns
            productsColumns.Add("Name");
            productsColumns.Add("Size", typeof(float));
            productsColumns.Add("Weight", typeof(float));
            productsColumns.Add("Quantity", typeof(uint));
            productsColumns.Add("Description");

            DataRowCollection productsRows = productsDataTable.Rows;

            // Add rows
            productsRows.Add("Gadget", 120f, 900f, 2, descriptions[s_rnd.Next(descriptions.Count)]);
            productsRows.Add("Widget", 20f, 20f, 25, descriptions[s_rnd.Next(descriptions.Count)]);
            productsRows.Add("Doohickey", 74f, 90f, 100, descriptions[s_rnd.Next(descriptions.Count)]);

            DataTableCollection tables = _dataSet.Tables;

            tables.Add(productsDataTable);

            // Data table
            var dataDataTable = new DataTable("Data");

            DataColumnCollection dataColumns = dataDataTable.Columns;

            // Add columns
            dataColumns.Add("ID", typeof(int));
            dataColumns.Add("Product");
            dataColumns.Add("Country", typeof(Country));
            dataColumns.Add("Color", typeof(DrawColor));
            dataColumns.Add("Price", typeof(decimal));
            dataColumns.Add("Change", typeof(decimal));
            dataColumns.Add("History", typeof(int[]));
            dataColumns.Add("Discount", typeof(decimal));
            dataColumns.Add("Rating", typeof(int));
            dataColumns.Add("Active", typeof(bool));
            dataColumns.Add("Date", typeof(DateTime));

            tables.Add(dataDataTable);

            // Creating relation between products and data
            _dataSet.Relations.Add("Products",
                                   dataColumns["Product"], productsColumns["Name"], false);

            _flexGrid.DataSource = _dataSet;
            _flexGrid.DataMember = "Data";
            _flexGrid.Cols.Remove("Products");
        }
Пример #9
0
        public void ToStringTest()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add("Table1");
            tbcol.Add("Table2");
            tbcol.Add("Table3");
            Assert.Equal("System.Data.DataTableCollection", tbcol.ToString());
        }
Пример #10
0
        public void Count()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            AssertEquals("test#1", 1, tbcol.Count);
            tbcol.Add(_tables[1]);
            AssertEquals("test#2", 2, tbcol.Count);
        }
Пример #11
0
        public void Count()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            Assert.Equal(1, tbcol.Count);
            tbcol.Add(_tables[1]);
            Assert.Equal(2, tbcol.Count);
        }
Пример #12
0
 public void AddException4()
 {
     Assert.Throws <DuplicateNameException>(() =>
     {
         DataTableCollection tbcol = _dataset[0].Tables;
         tbcol.Add("SameTableName");
         tbcol.Add("SameTableName");
     });
 }
Пример #13
0
 public void AddException2()
 {
     AssertExtensions.Throws <ArgumentException>(null, () =>
     {
         /* table already exist in the collection */
         DataTableCollection tbcol = _dataset[0].Tables;
         tbcol.Add(_tables[0]);
         tbcol.Add(_tables[0]);
     });
 }
Пример #14
0
        public void RemoveAt()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            tbcol.Add("table1");

            Assert.Throws <IndexOutOfRangeException>(() => tbcol.RemoveAt(-1));

            Assert.Throws <IndexOutOfRangeException>(() => tbcol.RemoveAt(101));
            tbcol.RemoveAt(1);
            Assert.Equal(1, tbcol.Count);
            tbcol.RemoveAt(0);
            Assert.Equal(0, tbcol.Count);
        }
Пример #15
0
        public void AddException1()
        {
            DataTableCollection tbcol = _dataset[0].Tables;
            DataTable           tb    = null;

            tbcol.Add(tb);
        }
Пример #16
0
        private void tablePart_RowChanged(object sender, DataRowChangeEventArgs e)
        {
            DataTable itsTable = null;

            switch (e.Action)
            {
            case DataRowAction.Add:
                try { itsTable = tables.Add(e.Row.ItemArray[0].ToString()); }
                catch (DuplicateNameException) { return; }
                itsTable.ExtendedProperties.Add("RelatedRow", e.Row);
                itsTable.Columns.Add("Key");
                itsTable.Columns.Add("Value");
                itsTable.Columns.Add("Description");
                break;

            case DataRowAction.Change:
                foreach (DataTable t in tables)
                {
                    if (t.ExtendedProperties.ContainsKey("RelatedRow") &&
                        e.Row.Equals(t.ExtendedProperties["RelatedRow"] as DataRow))
                    {
                        itsTable           = t;
                        itsTable.TableName = e.Row.ItemArray[0].ToString();
                        break;
                    }
                }
                break;
            }
        }
Пример #17
0
        /// <summary>
        /// Method to add a <see cref="FeatureDataTable"/> to this set.
        /// </summary>
        /// <remarks>If <paramref name="item"/> belongs to a different <see cref="FeatureDataSet"/>,
        /// this method attempts to remove it from that. If that is not possible, <paramref name="item"/>
        /// is copied (<see cref="DataTable.Copy"/>) and the copy is then added.
        /// </remarks>
        /// <param name="item">The feature data table to add</param>
        public void Add(FeatureDataTable item)
        {
            var itemDataSet = item.DataSet;

            if (itemDataSet != null)
            {
                if (itemDataSet.Tables.CanRemove(item))
                {
                    itemDataSet.Tables.Remove(item);
                }
                else
                {
                    item = (FeatureDataTable)item.Copy();
                }
            }
            _dataTables.Add(item);
        }
Пример #18
0
 public void AddException1()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         DataTableCollection tbcol = _dataset[0].Tables;
         DataTable tb = null;
         tbcol.Add(tb);
     });
 }
Пример #19
0
        protected override Task DoTaskWork(string osmFile, AttributeRegistry attributeRegistry)
        {
            var watch = Stopwatch.StartNew();

            ExecuteSqlCmd("TRUNCATE TABLE WayCreation");
            ExecuteSqlCmd("TRUNCATE TABLE WayTag");

            var dWays = new DataTable();

            dWays.TableName       = "WayCreation";
            dWays.MinimumCapacity = MaxRowCountInMemory;
            dWays.Columns.Add("wayId", typeof(long));
            dWays.Columns.Add("nodeId", typeof(long));
            dWays.Columns.Add("sort");

            var dWayTags = new DataTable();

            dWayTags.TableName       = "WayTag";
            dWayTags.MinimumCapacity = MaxRowCountInMemory;
            dWayTags.Columns.Add("WayId", typeof(long));
            dWayTags.Columns.Add("Typ", typeof(int));
            dWayTags.Columns.Add("Info", typeof(string));

            var insertingTask = Task.Factory.StartNew(() => StartInserting());
            var reader        = osmFile.EndsWith(".pbf") ?
                                (IOsmReader) new PbfOsmReader() :
                                (IOsmReader) new XmlOsmReader();

            foreach (var way in reader.ReadWays(osmFile, attributeRegistry))
            {
                if (!_timeOffset.HasValue)
                {
                    watch.Stop();
                    _timeOffset = watch.Elapsed.TotalSeconds;
                }
                _countOfInsertedWays++;
                var sort = 0;

                foreach (var node in way.NodeRefs)
                {
                    dWays = AddToCollection(dWays, way.WayId, node, sort++);
                }

                foreach (var tag in way.Tags)
                {
                    dWayTags = AddToCollection(dWayTags, way.WayId, tag.Typ, tag.Value);
                }
            }

            DataTableCollection.Add(dWays);
            DataTableCollection.Add(dWayTags);
            DataTableCollection.CompleteAdding();

            Trace.WriteLine(string.Format("Inserted {0} ways", _countOfInsertedWays));
            return(insertingTask.Result);
        }
Пример #20
0
        public void IndexOf()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            tbcol.Add("table1");
            tbcol.Add("table2");

            Assert.Equal(0, tbcol.IndexOf(_tables[0]));
            Assert.Equal(-1, tbcol.IndexOf(_tables[1]));
            Assert.Equal(1, tbcol.IndexOf("table1"));
            Assert.Equal(2, tbcol.IndexOf("table2"));

            Assert.Equal(0, tbcol.IndexOf(tbcol[0]));
            Assert.Equal(1, tbcol.IndexOf(tbcol[1]));
            Assert.Equal(-1, tbcol.IndexOf("_noTable_"));
            DataTable tb = new DataTable("new_table");

            Assert.Equal(-1, tbcol.IndexOf(tb));
        }
Пример #21
0
        public void IndexOf()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            tbcol.Add("table1");
            tbcol.Add("table2");

            AssertEquals("test#1", 0, tbcol.IndexOf(_tables[0]));
            AssertEquals("test#2", -1, tbcol.IndexOf(_tables[1]));
            AssertEquals("test#3", 1, tbcol.IndexOf("table1"));
            AssertEquals("test#4", 2, tbcol.IndexOf("table2"));

            AssertEquals("test#5", 0, tbcol.IndexOf(tbcol[0]));
            AssertEquals("test#6", 1, tbcol.IndexOf(tbcol[1]));
            AssertEquals("test#7", -1, tbcol.IndexOf("_noTable_"));
            DataTable tb = new DataTable("new_table");

            AssertEquals("test#8", -1, tbcol.IndexOf(tb));
        }
        public void IndexOf()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            tbcol.Add("table1");
            tbcol.Add("table2");

            Assert.AreEqual(0, tbcol.IndexOf(_tables[0]), "test#1");
            Assert.AreEqual(-1, tbcol.IndexOf(_tables[1]), "test#2");
            Assert.AreEqual(1, tbcol.IndexOf("table1"), "test#3");
            Assert.AreEqual(2, tbcol.IndexOf("table2"), "test#4");

            Assert.AreEqual(0, tbcol.IndexOf(tbcol[0]), "test#5");
            Assert.AreEqual(1, tbcol.IndexOf(tbcol[1]), "test#6");
            Assert.AreEqual(-1, tbcol.IndexOf("_noTable_"), "test#7");
            DataTable tb = new DataTable("new_table");

            Assert.AreEqual(-1, tbcol.IndexOf(tb), "test#8");
        }
Пример #23
0
 public static void AddOrMerge(this DataTableCollection tables, DataTable dt)
 {
     if (tables.Contains(dt.TableName))
     {
         tables[dt.TableName].Merge(dt);
     }
     else
     {
         tables.Add(dt);
     }
 }
Пример #24
0
        public DataTable CreateVirtualTable(bool useAllFields = false)
        {
            DataTableCollection tables = HostDataSet.Tables;

            if (!tables.Contains(TableName))
            {
                DataTable table = DataSetUtil.CreateDataTable(TableName, useAllFields ? fScheme.AllFields : fScheme.Fields);
                tables.Add(table);
                return(table);
            }
            return(tables[TableName]);
        }
Пример #25
0
        public void Clear()
        {
            DataTableCollection tbcol = _dataset[0].Tables;

            tbcol.Add(_tables[0]);
            tbcol.Clear();
            Assert.Equal(0, tbcol.Count);

            tbcol.AddRange(new DataTable[] { _tables[0], _tables[1] });
            tbcol.Clear();
            Assert.Equal(0, tbcol.Count);
        }
Пример #26
0
        protected override Task DoTaskWork(string osmFile, AttributeRegistry attributeRegistry)
        {
            var reader = osmFile.EndsWith(".pbf")
                                ? (IOsmReader) new PbfOsmReader()
                                : (IOsmReader) new XmlOsmReader();

            ExecuteSqlCmd("TRUNCATE TABLE [dbo].[tRelationCreation]");
            ExecuteSqlCmd("TRUNCATE TABLE [dbo].[tRelationTag]");

            var dRelationCreation = new DataTable {
                MinimumCapacity = MaxRowCountInMemory
            };

            dRelationCreation.TableName = "tRelationCreation";
            dRelationCreation.Columns.Add("RelationId", typeof(long));
            dRelationCreation.Columns.Add("Ref", typeof(long));
            dRelationCreation.Columns.Add("Type");
            dRelationCreation.Columns.Add("Role");
            dRelationCreation.Columns.Add("Sort");

            var dRelationTags = new DataTable {
                MinimumCapacity = MaxRowCountInMemory
            };

            dRelationTags.TableName = "tRelationTag";
            dRelationTags.Columns.Add("RelationId", typeof(long));
            dRelationTags.Columns.Add("Typ");
            dRelationTags.Columns.Add("Info");

            var insertingTask = Task.Factory.StartNew(() => StartInserting());

            foreach (var relation in reader.ReadRelations(osmFile, attributeRegistry))
            {
                _countOfInsertedRelations++;
                var sort = 0;
                foreach (var member in relation.Members)
                {
                    dRelationCreation = AddToCollection(dRelationCreation, relation.RelationId, member.Ref, member.Type, member.Role, sort++);
                }

                foreach (var tag in relation.Tags)
                {
                    dRelationTags = AddToCollection(dRelationTags, relation.RelationId, tag.Typ, tag.Value);
                }
            }

            DataTableCollection.Add(dRelationCreation);
            DataTableCollection.Add(dRelationTags);
            DataTableCollection.CompleteAdding();

            Trace.WriteLine(string.Format("Inserted {0} relations", _countOfInsertedRelations));
            return(insertingTask.Result);
        }
Пример #27
0
        // sectionName - i.e. "providerconfiguration"
        private static void HandleProviders(DataSet config, object configContext, XmlNode section, string sectionName)
        {
            DataTableCollection tables    = config.Tables;
            DataTable           dataTable = tables[sectionName];
            bool tableExisted             = (null != dataTable);

            dataTable = DbProviderDictionarySectionHandler.CreateStatic(dataTable, configContext, section);
            if (!tableExisted)
            {
                tables.Add(dataTable);
            }
        }
Пример #28
0
        private static void HandleProviders(DataSet config, object configContext, XmlNode section, string sectionName)
        {
            DataTableCollection tables = config.Tables;
            DataTable           table  = tables[sectionName];
            bool flag = null != table;

            table = DbProviderDictionarySectionHandler.CreateStatic(table, configContext, section);
            if (!flag)
            {
                tables.Add(table);
            }
        }
Пример #29
0
        public Altaxo.Data.DataTable CreateNewTable(string worksheetName, bool bCreateDefaultColumns)
        {
            var dt1 = new Altaxo.Data.DataTable(worksheetName);

            if (bCreateDefaultColumns)
            {
                dt1.DataColumns.Add(new Altaxo.Data.DoubleColumn(), "A", Altaxo.Data.ColumnKind.X);
                dt1.DataColumns.Add(new Altaxo.Data.DoubleColumn(), "B");
            }

            DataTableCollection.Add(dt1);

            return(dt1);
        }
Пример #30
0
        public void Equals()
        {
            DataTableCollection tbcol1 = _dataset[0].Tables;
            DataTableCollection tbcol2 = _dataset[1].Tables;
            DataTableCollection tbcol3;

            tbcol1.Add(_tables[0]);
            tbcol2.Add(_tables[1]);
            tbcol3 = tbcol1;

            Assert.Same(tbcol1, tbcol3);

            Assert.NotSame(tbcol1, tbcol2);
        }