示例#1
0
 public void AddRelation(T person)
 {
     if (!Relations.Contains(person))
     {
         Relations.Add(person);
     }
 }
示例#2
0
        // get relations from schema
        private void GetRelations(OleDbConnection conn)
        {
            var dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, null);

            foreach (DataRow dr in dt.Rows)
            {
                // get primary/foreign table and column names
                string pkTableName  = (string)dr[PK_TABLE_NAME];
                string fkTableName  = (string)dr[FK_TABLE_NAME];
                string pkColumnName = (string)dr[PK_COLUMN_NAME];
                string fkColumnName = (string)dr[FK_COLUMN_NAME];

                // make sure both tables are in our DataSet
                if (Tables.Contains(pkTableName) && Tables.Contains(fkTableName))
                {
                    // make sure tables are different
                    if (pkTableName != fkTableName)
                    {
                        // get unique relation name
                        string relationName = pkTableName + '_' + fkTableName;
                        if (Relations.Contains(relationName))
                        {
                            relationName += Relations.Count.ToString();
                        }

                        // add to collection
                        DataColumn pkColumn = Tables[pkTableName].Columns[pkColumnName];
                        DataColumn fkColumn = Tables[fkTableName].Columns[fkColumnName];
                        Relations.Add(relationName, pkColumn, fkColumn, true);
                    }
                }
            }
        }
示例#3
0
        private void Load()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Title            = "Open Diagram";
            dialog.Filter           = "Diagram files (*.dia)|*.dia";
            dialog.RestoreDirectory = true;

            if ((bool)dialog.ShowDialog())
            {
                // Load data from file
                IFormatter formatter = new BinaryFormatter();
                FileStream s         = new FileStream(dialog.FileName, FileMode.Open);

                try
                {
                    ObservableCollection <Klass> t = (ObservableCollection <Klass>)formatter.Deserialize(s);
                    // Clear existing Klasses and Relations
                    Klasses.Clear();
                    Relations.Clear();

                    // Add loaded data
                    foreach (Klass k in t)
                    {
                        // Add Klass
                        Klasses.Add(k);

                        // Add Relations
                        foreach (Relation r in k.Relations)
                        {
                            if (!Relations.Contains(r))
                            {
                                Relations.Add(r);
                            }
                        }
                    }

                    _filepath = dialog.FileName;
                }
                catch (Exception)
                {
                    MessageBox.Show("Please choose a valid Diagram file.");
                }
            }
        }
示例#4
0
        /// <summary>
        /// enable a specific relation
        ///
        /// </summary>
        /// <returns>void</returns>
        protected void EnableRelation(TTypedRelation ARelation)
        {
            DataTable Table1;
            DataTable Table2;

            Table1 = Tables[ARelation.FTable1];
            Table2 = Tables[ARelation.FTable2];

            if ((Table1 != null) && (Table2 != null))
            {
//MessageBox.Show("Enabling Relation: " + ARelation.FName + " (" + ARelation.FTable1.ToString() + "; " + ARelation.FTable2.ToString() + ")...");
//MessageBox.Show("Relation Keys: " + ARelation.FName + " (" + ARelation.FKey1[0].ToString() + "; " + ARelation.FKey2[0].ToString() + ")");
                if ((!Relations.Contains(ARelation.FName)))
                {
                    Relations.Add(ARelation.FName,
                                  GetDataColumnArrayFromString(Table1, ARelation.FKey1), // parentcolumn
                                  GetDataColumnArrayFromString(Table2, ARelation.FKey2), // childcolumn
                                  ARelation.FCreateConstraints);

//                    MessageBox.Show("Enabled Relation: " + ARelation.FName + " (" + ARelation.FKey1.ToString() + "; " + ARelation.FKey2.ToString());
                }
            }
        }
示例#5
0
        /// <summary>
        /// Removes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public bool Remove(Property item)
        {
            if ((item == null) || string.IsNullOrWhiteSpace(item.PropertyName))
            {
                return(false);
            }
            bool res = false;

            if (PrimaryKey != null)
            {
                if (PrimaryKey.Keys.Contains(item.PropertyName))
                {
                    PrimaryKey.Keys.Remove(item.PropertyName);
                    res = true;
                }
            }

            if (Properties.Contains(item.PropertyName))
            {
                Properties.Remove(item.PropertyName);
                res = true;
            }
            else if (Relations.Contains(item.PropertyName))
            {
                Relations.Remove(item.PropertyName);
                res = true;
            }

            if (AllProperties.Contains(item.PropertyName))
            {
                AllProperties.Remove(item.PropertyName);
                res = true;
            }

            return(res);
        }
示例#6
0
 public bool IsBroken()
 => (RelationType == RelationType.Father || RelationType == RelationType.Mother) &&
 Relations.Contains(new Relation(From, To, RelationType));