Example #1
0
        public BaseIndexConstraint GetCreatedKey()
        {
            BaseIndexConstraint index = null;

            if (tabControl.SelectedTab == tabPageFK)
                index = new ForeignKeyConstraint();
            else if (rbPrimaryKey.Checked)
                index = new PrimaryKeyConstraint();
            else if (rbUnique.Checked)
                index = new UniqueConstraint();
            else if (rbIndex.Checked)
                index = new Index();
            else
                throw new Exception("Please select an index/constraint type");

            index.ColumnNames = new List<string>();
            index.Name = txtKeyName.Text.MakeFileName();
            if (index is ForeignKeyConstraint)
            {
                ForeignKeyConstraint fk = index as ForeignKeyConstraint;
                foreach (Panel panel in pnlForeignTableColumns.Controls)
                    fk.ColumnNames.Add(((panel.Controls[1] as ComboBox).SelectedItem as Column).Name);
                fk.RefConstraintName = (comboForeignTableKeys.SelectedItem as BaseIndexConstraint).Name;
                fk.RefTableName = (comboForeignTableKeys.SelectedItem as BaseIndexConstraint).Table.Name;
            }
            else
            {
                foreach (KeyColumn fd in keyColumnBindingSource.DataSource as List<KeyColumn>)
                    if (fd.Selected)
                        index.ColumnNames.Add(fd.Name);
            }
            return index;
        }
Example #2
0
 public override string Fix(Panel p)
 {
     ComboBox cb = p.Controls[1] as ComboBox;
     if (cb.SelectedItem is Table)
     {
         Table = cb.SelectedItem as Table;
         ForeignKeyConstraint fk = new ForeignKeyConstraint()
         {
             ColumnNames = new List<string>() { Column.Name },
             Name = string.Format("FK_{0}_{1}_{2}", Column.Table.Name, Column.Name, Table.Name),
             RefConstraintName = Table.Constraints.Find(c => c is PrimaryKeyConstraint).Name,
             RefTableName = Table.Name
         };
         Column.Table.Constraints.Add(fk);
         string sql = Provider.Database.GetSQLConstraintAdd(fk);
         Column.Table.Constraints.Remove(fk);
         return sql;
     }
     return "";
 }
Example #3
0
 public override void ApplyToMetadata(Panel p)
 {
     ComboBox cb = p.Controls[1] as ComboBox;
     if (cb.SelectedItem is Table)
     {
         Table = cb.SelectedItem as Table;
         ForeignKeyConstraint fk = new ForeignKeyConstraint()
         {
             ColumnNames = new List<string>() { Column.Name },
             Name = string.Format("FK_{0}_{1}_{2}", Column.Table.Name, Column.Name, Table.Name),
             RefConstraintName = Table.GetPrimaryKeyConstraint().Name,
             RefTableName = Table.Name
         };
         Column.Table.Constraints.Add(fk);
     }
 }