Modified:
trunk/MySql.VisualStudio/DbObjects/ForeignKey.cs
trunk/MySql.VisualStudio/DbObjects/Table.cs
trunk/MySql.VisualStudio/Editors/ForeignKeyDialog.Designer.cs
trunk/MySql.VisualStudio/Editors/ForeignKeyDialog.cs
Log:
added code to update fk name if it has not been manually set
Modified: trunk/MySql.VisualStudio/DbObjects/ForeignKey.cs
===================================================================
--- trunk/MySql.VisualStudio/DbObjects/ForeignKey.cs 2008-12-12 16:50:22 UTC (rev 1486)
+++ trunk/MySql.VisualStudio/DbObjects/ForeignKey.cs 2008-12-15 18:47:08 UTC (rev 1487)
@@ -9,6 +9,7 @@
public ForeignKey(Table t)
{
Table = t;
+ SetName(String.Format("FK_{0}_{0}", t.Name), true);
}
private Table Table { get; set; }
@@ -23,6 +24,30 @@
{
return Name;
}
+ public bool NameSet { get; set; }
+
+ public void SetName(string name, bool makeUnique)
+ {
+ string proposedName = name;
+ int uniqueIndex = 0;
+
+ if (makeUnique)
+ {
+ while (true)
+ {
+ bool found = false;
+ foreach (ForeignKey k in Table.ForeignKeys)
+ if (k.Name == proposedName)
+ {
+ found = true;
+ break;
+ }
+ if (!found) break;
+ proposedName = String.Format("{0}_{1}", name, ++uniqueIndex);
+ }
+ }
+ Name = proposedName;
+ }
}
enum MatchOption
Modified: trunk/MySql.VisualStudio/DbObjects/Table.cs
===================================================================
--- trunk/MySql.VisualStudio/DbObjects/Table.cs 2008-12-12 16:50:22 UTC (rev 1486)
+++ trunk/MySql.VisualStudio/DbObjects/Table.cs 2008-12-15 18:47:08 UTC (rev 1487)
@@ -236,28 +236,6 @@
return newIndex;
}
- public ForeignKey CreateForeignKeyWithUniqueName()
- {
- ForeignKey fk = new ForeignKey(this);
- string baseName = String.Format("FK_{0}_{0}", Name);
- string proposedName = baseName;
- int uniqueIndex = 0;
- while (true)
- {
- bool found = false;
- foreach (ForeignKey k in fkeys)
- if (k.Name == proposedName)
- {
- found = true;
- break;
- }
- if (!found) break;
- proposedName = String.Format("{0}_{1}", baseName, ++uniqueIndex);
- }
- fk.Name = proposedName;
- return fk;
- }
-
private void ParseTableData(DataRow tableRow)
{
/* dt.Columns.Add("TABLE_TYPE", typeof(string));
Modified: trunk/MySql.VisualStudio/Editors/ForeignKeyDialog.Designer.cs
===================================================================
--- trunk/MySql.VisualStudio/Editors/ForeignKeyDialog.Designer.cs 2008-12-12 16:50:22 UTC (rev 1486)
+++ trunk/MySql.VisualStudio/Editors/ForeignKeyDialog.Designer.cs 2008-12-15 18:47:08 UTC (rev 1487)
@@ -179,11 +179,12 @@
//
// fkName
//
+ this.fkName.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.foreignKeyBindingSource, "Name", true));
this.fkName.Location = new System.Drawing.Point(342, 36);
this.fkName.Name = "fkName";
this.fkName.Size = new System.Drawing.Size(301, 23);
this.fkName.TabIndex = 14;
- this.fkName.DataBindings.Add(new Binding("Text", foreignKeyBindingSource, "Name"));
+ this.fkName.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.fkName_KeyPress);
//
// label4
//
@@ -231,44 +232,55 @@
//
// matchType
//
+ this.matchType.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.foreignKeyBindingSource, "Match", true));
this.matchType.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.matchType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.matchType.DataSource = Enum.GetValues(typeof(MatchOption));
+ this.matchType.Items.AddRange(new object[] {
+ MySql.Data.VisualStudio.DbObjects.MatchOption.Full,
+ MySql.Data.VisualStudio.DbObjects.MatchOption.Partial,
+ MySql.Data.VisualStudio.DbObjects.MatchOption.Simple});
this.matchType.Location = new System.Drawing.Point(536, 125);
this.matchType.MinimumSize = new System.Drawing.Size(4, 10);
this.matchType.Name = "matchType";
this.matchType.Size = new System.Drawing.Size(107, 24);
this.matchType.TabIndex = 16;
- this.matchType.DataBindings.Add(new Binding("SelectedItem", foreignKeyBindingSource, "Match"));
//
// deleteAction
//
+ this.deleteAction.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.foreignKeyBindingSource, "DeleteAction", true));
this.deleteAction.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.deleteAction.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.deleteAction.DataSource = Enum.GetValues(typeof(ReferenceOption));
+ this.deleteAction.Items.AddRange(new object[] {
+ MySql.Data.VisualStudio.DbObjects.ReferenceOption.NoAction,
+ MySql.Data.VisualStudio.DbObjects.ReferenceOption.Cascade,
+ MySql.Data.VisualStudio.DbObjects.ReferenceOption.Restrict,
+ MySql.Data.VisualStudio.DbObjects.ReferenceOption.SetNull});
this.deleteAction.Location = new System.Drawing.Point(536, 95);
this.deleteAction.MinimumSize = new System.Drawing.Size(4, 10);
this.deleteAction.Name = "deleteAction";
this.deleteAction.Size = new System.Drawing.Size(107, 24);
this.deleteAction.TabIndex = 9;
- this.deleteAction.DataBindings.Add(new Binding("SelectedItem", foreignKeyBindingSource, "DeleteAction"));
//
// updateAction
//
+ this.updateAction.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.foreignKeyBindingSource, "UpdateAction", true));
this.updateAction.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.updateAction.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.updateAction.FormattingEnabled = true;
- this.updateAction.DataSource = Enum.GetValues(typeof(ReferenceOption));
+ this.updateAction.Items.AddRange(new object[] {
+ MySql.Data.VisualStudio.DbObjects.ReferenceOption.NoAction,
+ MySql.Data.VisualStudio.DbObjects.ReferenceOption.Cascade,
+ MySql.Data.VisualStudio.DbObjects.ReferenceOption.Restrict,
+ MySql.Data.VisualStudio.DbObjects.ReferenceOption.SetNull});
this.updateAction.Location = new System.Drawing.Point(342, 95);
this.updateAction.MinimumSize = new System.Drawing.Size(4, 10);
this.updateAction.Name = "updateAction";
this.updateAction.Size = new System.Drawing.Size(107, 24);
this.updateAction.TabIndex = 8;
- this.updateAction.DataBindings.Add(new Binding("SelectedItem", foreignKeyBindingSource, "UpdateAction"));
-
//
// refTable
//
+ this.refTable.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.foreignKeyBindingSource, "ReferencedTable", true));
this.refTable.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.refTable.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.refTable.FormattingEnabled = true;
@@ -278,7 +290,6 @@
this.refTable.Size = new System.Drawing.Size(301, 24);
this.refTable.TabIndex = 4;
this.refTable.SelectedIndexChanged += new System.EventHandler(this.refTable_SelectedIndexChanged);
- this.refTable.DataBindings.Add(new Binding("SelectedItem", foreignKeyBindingSource, "ReferencedTable"));
//
// ForeignKeyDialog
//
Modified: trunk/MySql.VisualStudio/Editors/ForeignKeyDialog.cs
===================================================================
--- trunk/MySql.VisualStudio/Editors/ForeignKeyDialog.cs 2008-12-12 16:50:22 UTC (rev 1486)
+++ trunk/MySql.VisualStudio/Editors/ForeignKeyDialog.cs 2008-12-15 18:47:08 UTC (rev 1487)
@@ -61,7 +61,7 @@
private void addButton_Click(object sender, EventArgs e)
{
- ForeignKey key = tableNode.Table.CreateForeignKeyWithUniqueName();
+ ForeignKey key = new ForeignKey(tableNode.Table);
foreignKeyBindingSource.Add(key);
}
@@ -93,7 +93,20 @@
private void refTable_SelectedIndexChanged(object sender, EventArgs e)
{
- fkGridColumn.HeaderText = refTable.Items[refTable.SelectedIndex].ToString();
+ string refTableName = refTable.Items[refTable.SelectedIndex].ToString();
+ fkGridColumn.HeaderText = refTableName;
+ if (foreignKeyBindingSource.Current == null) return;
+
+ ForeignKey key = foreignKeyBindingSource.Current as ForeignKey;
+ if (key.NameSet) return;
+ string name = String.Format("FK_{0}_{1}", tableNode.Table.Name, refTableName);
+ key.SetName(name, true);
}
+
+ private void fkName_KeyPress(object sender, KeyPressEventArgs e)
+ {
+ ForeignKey key = foreignKeyBindingSource.Current as ForeignKey;
+ key.NameSet = true;
+ }
}
}
| Thread |
|---|
| • Connector/NET commit: r1487 - in trunk/MySql.VisualStudio: DbObjects Editors | rburnett | 15 Dec |