Exemplo n.º 1
0
        /// <summary>
        /// Adds a DataRelation to the DataRelationCollection.
        /// </summary>
        /// <param name="relation">The DataRelation to add to the collection.</param>
        public void Add(DataRelation relation)
        {
            // To prevent endless recursion
            if (inTransition == relation)
            {
                return;
            }

            inTransition = relation;

            try {
                CollectionChangeEventArgsDerived e = new CollectionChangeEventArgsDerived(CollectionChangeActionDerived.Add, relation);
                OnCollectionChanging(e);

                this.AddCore(relation);
                if (relation.RelationName == string.Empty)
                {
                    relation.RelationName = GenerateRelationName();
                }

                e = new CollectionChangeEventArgsDerived(CollectionChangeActionDerived.Add, relation);
                OnCollectionChanged(e);
            } finally {
                inTransition = null;
            }
        }
Exemplo n.º 2
0
 internal void OnCollectionChanged(CollectionChangeEventArgsDerived ccevent)
 {
     if (CollectionChanged != null)
     {
         CollectionChanged(this, ccevent);
     }
 }
Exemplo n.º 3
0
 protected virtual void OnCollectionChanged(CollectionChangeEventArgsDerived ccevent)
 {
     if (CollectionChanged != null)
     {
         CollectionChanged(this, ccevent);
     }
 }
Exemplo n.º 4
0
 private void OnCollectionMetaDataChanged(CollectionChangeEventArgsDerived ccevent)
 {
     if (CollectionMetaDataChanged != null)
     {
         CollectionMetaDataChanged(this, ccevent);
     }
 }
 private void SchemaChanged(object sender, CollectionChangeEventArgsDerived e)
 {
     if ((e.Action == CollectionChangeActionDerived.Remove))
     {
         this.InitVars();
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Raises the OnCollectionChanging event.
 /// </summary>
 /// <param name="ccevent">A CollectionChangeEventArgsDerived that contains the event data.</param>
 internal void OnCollectionChanging(CollectionChangeEventArgsDerived ccevent)
 {
     if (CollectionChanged != null)
     {
         //FIXME: this is not right
         //CollectionChanged(this, ccevent);
         throw new NotImplementedException();
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Clears the collection of any columns.
        /// </summary>
        public void Clear()
        {
            CollectionChangeEventArgsDerived e = new CollectionChangeEventArgsDerived(CollectionChangeActionDerived.Refresh, this);

            // its not necessary to check if each column in the collection can removed.
            // Can simply check, if there are any constraints/relations related to the table,
            // in which case, throw an exception.
            // Also, shudnt check for expression columns since all the columns in the table
            // are being removed.
            if (parentTable.Constraints.Count != 0 ||
                parentTable.ParentRelations.Count != 0 ||
                parentTable.ChildRelations.Count != 0)
            {
                foreach (DataColumn col in this)
                {
                    string s = GetColumnDependency(col);
                    if (s != String.Empty)
                    {
                        throw new ArgumentException("Cannot remove this column, because it is part of the" + s);
                    }
                }
            }

            if (parentTable.DataSet != null)
            {
                foreach (DataTable table in parentTable.DataSet.Tables)
                {
                    foreach (Constraint c in table.Constraints)
                    {
                        if (!(c is ForeignKeyConstraint) ||
                            ((ForeignKeyConstraint)c).RelatedTable != parentTable)
                        {
                            continue;
                        }
                        throw new ArgumentException(
                                  String.Format(
                                      "Cannot remove this column, because it is part of the constraint {0} on the table {1}",
                                      c.ConstraintName, table.TableName));
                    }
                }
            }

            foreach (DataColumn col in this)
            {
                col.ResetColumnInfo();
            }

            columnFromName.Clear();
            autoIncrement.Clear();
            columnNameCount.Clear();
            base.List.Clear();
            defaultColumnIndex = 1;
            OnCollectionChanged(e);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Removes the specified DataColumn object from the collection.
        /// </summary>
        /// <param name="column">The DataColumn to remove.</param>
        public void Remove(DataColumn column)
        {
            if (column == null)
            {
                throw new ArgumentNullException("column", "'column' argument cannot be null.");
            }

            if (!Contains(column.ColumnName))
            {
                throw new ArgumentException("Cannot remove a column that doesn't belong to this table.");
            }

            string dependency = GetColumnDependency(column);

            if (dependency != String.Empty)
            {
                throw new ArgumentException("Cannot remove this column, because it is part of " + dependency);
            }

            CollectionChangeEventArgsDerived e = new CollectionChangeEventArgsDerived(CollectionChangeActionDerived.Remove, column);

            int ordinal = column.Ordinal;

            UnregisterName(column.ColumnName);
            base.List.Remove(column);

            // Reset column info
            column.ResetColumnInfo();

            //Update the ordinals
            for (int i = ordinal; i < this.Count; i++)
            {
                this[i].Ordinal = i;
            }

            if (parentTable != null)
            {
                parentTable.OnRemoveColumn(column);
            }

            if (column.AutoIncrement)
            {
                autoIncrement.Remove(column);
            }

            column.PropertyChanged -= new PropertyChangedEventHandler(ColumnPropertyChanged);

            OnCollectionChanged(e);
        }
        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 OnColumnRemoved(object sender, CollectionChangeEventArgsDerived args)
        {
            if (!(args.Element is DataColumnCollection))
            {
                return;
            }

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

            DataColumnCollection columnCollection = (DataColumnCollection)args.Element;

            if (_cachedColumn != null && columnCollection != null && (columnCollection.IndexOf(_cachedColumn)) == -1)
            {
                DropCached(columnCollection, null);
            }
        }
Exemplo n.º 11
0
        public void Remove(DataRelation relation)
        {
            // To prevent endless recursion
            if (inTransition == relation)
            {
                return;
            }

            inTransition = relation;

            if (relation == null)
            {
                return;
            }

            try {
                // check if the list doesnot contains this relation.
                if (!(List.Contains(relation)))
                {
                    throw new ArgumentException("Relation doesnot belong to this Collection.");
                }

                CollectionChangeEventArgsDerived e = new CollectionChangeEventArgsDerived(CollectionChangeActionDerived.Remove, relation);
                OnCollectionChanging(e);

                RemoveCore(relation);
                string name = "Relation" + index;
                if (relation.RelationName == name)
                {
                    index--;
                }

                e = new CollectionChangeEventArgsDerived(CollectionChangeActionDerived.Remove, relation);
                OnCollectionChanged(e);
            } finally {
                inTransition = null;
            }
        }
Exemplo n.º 12
0
 protected virtual void OnCollectionChanging(CollectionChangeEventArgsDerived ccevent)
 {
     // LAME Spec: No associated events and it doesn't update CollectionChanged
     // event too as specified in MSDN
     // throw new NotImplementedException ();
 }
 private void Constraints_CollectionChanged(object sender, CollectionChangeEventArgsDerived e)
 {
     collectionChanged = true;
 }
Exemplo n.º 14
0
 private void Relations_CollectionChanged(object sender, CollectionChangeEventArgsDerived e)
 {
     changesCounter++;
 }
 private void Constraints_CollectionChangedHandler(object sender, CollectionChangeEventArgsDerived e)
 {
     CollectionChangedFlag = true;
 }
Exemplo n.º 16
0
 private void Columns_CollectionChanged1(object sender, CollectionChangeEventArgsDerived e)
 {
     eventOccured = true;
 }
Exemplo n.º 17
0
 private void Columns_CollectionChanged(object sender, CollectionChangeEventArgsDerived e)
 {
     counter++;
     change_element = e.Element;
 }