private void ForeignKeyForm_Load(object sender, EventArgs e) { FormDesign.SetFormLeft(this); DataFilled = false; FillCombo(); ForeignKeyObject = GetFK(FKName); txtConstraintName.Text = $@"FK_{TableName}_{NewNr}"; UpdateForeignKeyObject(); old_constraint_name = ForeignKeyObject.Name; SetEnables(); DataToEdit(); SetAutocompeteObjects(_tables); DataFilled = true; if (!string.IsNullOrEmpty(TableName)) { cbSourceTable.Text = TableName; } MakeSQL(); splitContainer1.SplitterDistance = 500; txtConstraintName.Enabled = !(BearbeitenMode == StateClasses.EditStateClass.eBearbeiten.eEdit); }
private static string CreateDROPTableFKConstraintDLL(ForeignKeyClass constraint) { var sb = new StringBuilder(); if (constraint.SourceTableName != null) { sb.Append("ALTER TABLE "); sb.Append(constraint.SourceTableName); sb.Append(" DROP CONSTRAINT " + constraint.Name + ";" + Environment.NewLine); sb.Append($@"{SQLPatterns.Commit}{Environment.NewLine}{Environment.NewLine}"); } return(sb.ToString()); }
public ForeignKeyForm(Form parent, DBRegistrationClass dbReg, List <TableClass> tables, string tableName, ForeignKeyClass foreignKeys, int newNr) { InitializeComponent(); this.MdiParent = parent; _tables = tables; _foreignKeys = foreignKeys; NewNr = newNr; FKName = (_foreignKeys == null) ? $@"FK_{TableName}_{NewNr}" : foreignKeys.Name; TableName = tableName; DataFilled = false; _dbReg = dbReg; _localNotify.Register4Error(Notify_OnRaiseErrorHandler); _localNotify.Register4Info(Notify_OnRaiseInfoHandler); }
private void UpdateForeignKeyObject() { if (ForeignKeyObject != null) { //Existierenter FK cbSourceTable.Text = ForeignKeyObject.SourceTableName; cbDestinationTable.Text = ForeignKeyObject.DestTableName; txtConstraintName.Text = "FK_NEW"; } else { //Neuer FK ForeignKeyObject = new ForeignKeyClass(); ForeignKeyObject.Name = txtConstraintName.Text; ForeignKeyObject.DestTableName = cbDestinationTable.Text.Trim(); ForeignKeyObject.SourceTableName = cbSourceTable.Text.Trim(); //GetSourceFieldsFromTableObject(ForeignKeyObject.SourceTableName); FillDestFields(ForeignKeyObject.DestTableName); FillSourceFields(ForeignKeyObject.SourceTableName); if (cbSourceTable.Items.Count > 0) { cbSourceTable.SelectedIndex = 0; } if (cbDestinationTable.Items.Count > 0) { cbDestinationTable.SelectedIndex = 0; } if (cbSourceTableFields.Items.Count > 0) { cbSourceTableFields.SelectedIndex = 0; } if (cbDestinationTableFields.Items.Count > 0) { cbDestinationTableFields.SelectedIndex = 0; } } }
// ALTER TABLE TADRESSEN ADD CONSTRAINT FK_TADRESSEN FOREIGN KEY(TPLZ_ID) REFERENCES TPLZ(ID) ON UPDATE CASCADE; public static string CreateAlterTabelForeignKeyConstraintDLL(ForeignKeyClass constraint, eCreateMode cmode) { StringBuilder sb = new StringBuilder(); // ALTER TABLE TADRESSEN ADD CONSTRAINT FK_TADRESSEN FOREIGN KEY(TPLZ_ID) REFERENCES TPLZ(ID) ON UPDATE CASCADE; // -> //ALTER TABLE #REPLACE_TABLE ADD CONSTRAINT #REPLACE_CONSTRAINTNAME FOREIGN KEY(#REPLACE_COLUMNS) REFERENCES #REPLACE_REFERENCES_TABLE (#REPLACE_REFERENCES_COLUMNS) ON UPDATE #UPDATE_TYPE;"; if (constraint != null) { if ((cmode == eCreateMode.drop) || (cmode == eCreateMode.recreate)) { sb.Append(CreateDROPTableFKConstraintDLL(constraint)); sb.Append($@"{SQLPatterns.Commit}{Environment.NewLine}{Environment.NewLine}"); } if ((cmode == eCreateMode.create) || (cmode == eCreateMode.recreate)) { string cmd = SQLPatterns.AddForeignKeyConstraintPattern.Replace(SQLPatterns.ConstraintKey, constraint.Name).Replace(SQLPatterns.ColumnKey, MakeConcatedStr(constraint.SourceFields, ",")).Replace(SQLPatterns.TableKey, constraint.SourceTableName); cmd = cmd.Replace(SQLPatterns.ReferenceTableKey, constraint.DestTableName).Replace(SQLPatterns.ReferenceColumnKey, MakeConcatedStr(constraint.DestFields, ",")); sb.Append(cmd); } } return(sb.ToString()); }
private void ForeignKeyForm_Load(object sender, EventArgs e) { DataFilled = false; FillCombo(); ForeignKeyObject = GetFK(FKName); txtConstraintName.Text = $@"FK_{TableName}_NEW"; UpdateForeignKeyObject(); old_constraint_name = ForeignKeyObject.Name; SetEnables(); DataToEdit(); ac = new AutocompleteClass(fctSQL, _dbReg); ac.RefreshAutocompleteForDatabase(); DataFilled = true; if (!string.IsNullOrEmpty(TableName)) { cbSourceTable.Text = TableName; } MakeSQL(); splitContainer1.SplitterDistance = 500; txtConstraintName.Enabled = !(BearbeitenMode == StateClasses.EditStateClass.eBearbeiten.eEdit); }
public ForeignKeyForm(Form parent, DBRegistrationClass dbReg, List <TableClass> tables, string tableName, ForeignKeyClass foreignKeys) { InitializeComponent(); this.MdiParent = parent; Tables = tables; if (foreignKeys == null) { FKName = ""; } else { FKName = foreignKeys.Name; } TableName = tableName; DataFilled = false; _dbReg = dbReg; _localNotify.Notify.OnRaiseErrorHandler += Notify_OnRaiseErrorHandler; _localNotify.Notify.OnRaiseInfoHandler += Notify_OnRaiseInfoHandler; }