Esempio n. 1
0
        public void IndexOf()
        {
            DataRelationCollection drcol = _dataset.Relations;
            DataRelation           dr1   = new DataRelation("CustOrder"
                                                            , _dataset.Tables["Customer"].Columns["custid"]
                                                            , _dataset.Tables["Order"].Columns["custid"]);
            DataRelation dr2 = new DataRelation("ItemOrder"
                                                , _dataset.Tables["Item"].Columns["itemid"]
                                                , _dataset.Tables["Order"].Columns["custid"]);

            drcol.Add(dr1);
            drcol.Add(dr2);

            Assert.Equal(0, drcol.IndexOf(dr1));
            Assert.Equal(1, drcol.IndexOf(dr2));

            Assert.Equal(0, drcol.IndexOf("CustOrder"));
            Assert.Equal(1, drcol.IndexOf("ItemOrder"));

            Assert.Equal(0, drcol.IndexOf(drcol[0]));
            Assert.Equal(1, drcol.IndexOf(drcol[1]));

            Assert.Equal(-1, drcol.IndexOf("_noRelation_"));
            DataRelation newdr = new DataRelation("newdr"
                                                  , _dataset.Tables["Customer"].Columns["custid"]
                                                  , _dataset.Tables["Order"].Columns["custid"]);

            Assert.Equal(-1, drcol.IndexOf(newdr));
        }
        public void IndexOf()
        {
            DataRelationCollection drcol = _dataset.Relations;
            DataRelation           dr1   = new DataRelation("CustOrder"
                                                            , _dataset.Tables ["Customer"].Columns ["custid"]
                                                            , _dataset.Tables ["Order"].Columns ["custid"]);
            DataRelation dr2 = new DataRelation("ItemOrder"
                                                , _dataset.Tables ["Item"].Columns ["itemid"]
                                                , _dataset.Tables ["Order"].Columns ["custid"]);

            drcol.Add(dr1);
            drcol.Add(dr2);

            Assert.That(drcol.IndexOf(dr1), Is.EqualTo(0), "test#1");
            Assert.That(drcol.IndexOf(dr2), Is.EqualTo(1), "test#2");

            Assert.That(drcol.IndexOf("CustOrder"), Is.EqualTo(0), "test#3");
            Assert.That(drcol.IndexOf("ItemOrder"), Is.EqualTo(1), "test#4");

            Assert.That(drcol.IndexOf(drcol [0]), Is.EqualTo(0), "test#5");
            Assert.That(drcol.IndexOf(drcol [1]), Is.EqualTo(1), "test#6");

            Assert.That(drcol.IndexOf("_noRelation_"), Is.EqualTo(-1), "test#7");
            DataRelation newdr = new DataRelation("newdr"
                                                  , _dataset.Tables ["Customer"].Columns ["custid"]
                                                  , _dataset.Tables ["Order"].Columns ["custid"]);

            Assert.That(drcol.IndexOf(newdr), Is.EqualTo(-1), "test#8");
        }
        public void IndexOf()
        {
            DataRelationCollection drcol = _dataset.Relations;
            DataRelation           dr1   = new DataRelation("CustOrder"
                                                            , _dataset.Tables["Customer"].Columns["custid"]
                                                            , _dataset.Tables["Order"].Columns["custid"]);
            DataRelation dr2 = new DataRelation("ItemOrder"
                                                , _dataset.Tables["Item"].Columns["itemid"]
                                                , _dataset.Tables["Order"].Columns["custid"]);

            drcol.Add(dr1);
            drcol.Add(dr2);

            AssertEquals("test#1", 0, drcol.IndexOf(dr1));
            AssertEquals("test#2", 1, drcol.IndexOf(dr2));

            AssertEquals("test#3", 0, drcol.IndexOf("CustOrder"));
            AssertEquals("test#4", 1, drcol.IndexOf("ItemOrder"));

            AssertEquals("test#5", 0, drcol.IndexOf(drcol[0]));
            AssertEquals("test#6", 1, drcol.IndexOf(drcol[1]));

            AssertEquals("test#7", -1, drcol.IndexOf("_noRelation_"));
            DataRelation newdr = new DataRelation("newdr"
                                                  , _dataset.Tables["Customer"].Columns["custid"]
                                                  , _dataset.Tables["Order"].Columns["custid"]);

            AssertEquals("test#8", -1, drcol.IndexOf(newdr));
        }
 private void AddRelation(DataColumn parentChapterColumn, DataColumn chapterColumn)
 {
     if (this._dataSet != null)
     {
         string                 columnName   = chapterColumn.ColumnName;
         DataRelation           relation     = new DataRelation(columnName, new DataColumn[] { parentChapterColumn }, new DataColumn[] { chapterColumn }, false);
         int                    num          = 1;
         string                 relationName = columnName;
         DataRelationCollection relations    = this._dataSet.Relations;
         while (-1 != relations.IndexOf(relationName))
         {
             relationName = columnName + num;
             num++;
         }
         relation.RelationName = relationName;
         relations.Add(relation);
     }
 }
        private void OnRelationRemoved(object sender, CollectionChangeEventArgsDerived args)
        {
            if (!(args.Element is DataRelationCollection))
            {
                return;
            }

            if (args.Action != CollectionChangeActionDerived.Remove)
            {
                return;
            }

            DataRelationCollection relationCollection = (DataRelationCollection)args.Element;

            if (_cachedRelation != null && relationCollection != null && (relationCollection.IndexOf(_cachedRelation)) == -1)
            {
                DropCached(null, relationCollection);
            }
        }
        private void AddRelation(DataColumn parentChapterColumn, DataColumn chapterColumn)   // MDAC 71613
        {
            if (null != this.dataSet)
            {
                string name = /*parentChapterColumn.ColumnName + "_" +*/ chapterColumn.ColumnName;                                                   // MDAC 72815

                DataRelation relation = new DataRelation(name, new DataColumn[] { parentChapterColumn }, new DataColumn[] { chapterColumn }, false); // MDAC 71878

                int    index = 1;
                string tmp   = name;
                DataRelationCollection relations = this.dataSet.Relations;
                while (-1 != relations.IndexOf(tmp))
                {
                    tmp = name + index;
                    index++;
                }
                relation.RelationName = tmp;
                relations.Add(relation);
            }
        }