private void replasekeys(bool onCascadeDelete) { MySqlDataReader keys = controller.getKeys(null, controller.getDataBase); string onDelete = ""; if (onCascadeDelete) { onDelete = "ON DELETE CASCADE"; } while (keys.Read()) { string table = keys.GetString("TABLE_NAME"); string column = keys.GetString("COLUMN_NAME"); string refTable = keys.GetString("REFERENCED_TABLE_NAME"); string refColumn = keys.GetString("REFERENCED_COLUMN_NAME"); string key = keys.GetString("CONSTRAINT_NAME"); string newKey = "ALTER TABLE " + table + " ADD CONSTRAINT " + key + " FOREIGN KEY (" + column + ") REFERENCES " + refTable + "(" + refColumn + ")" + onDelete + ";"; string dropKey = "ALTER TABLE " + table + " DROP FOREIGN KEY `" + key + "`;"; controller.addCommand(dropKey); controller.addCommand(newKey); } keys.Close(); controller.RunTransactions(); }
private void addComponents(DataGridViewColumnCollection columns) { Dictionary <string, List <string> > keys = getListOfKeys(controller.getKeys(tableName, database)); int x = 10, y = 20; for (int a = 0; a < columns.Count; a++) { Label l = new Label(); l.AutoSize = true; l.Text = columns[a].HeaderText; l.Parent = panel1; Control box; if (keys != null && keys.ContainsKey(columns[a].HeaderText)) { box = new ComboBox(); foreach (string s in keys[columns[a].HeaderText]) { ((ComboBox)box).Items.Add(s); box.Size = new Size(100, 18); } } else { box = new TextBox(); } if (a != 0) { x += box.Location.X + box.Width + 10; } box.Location = new Point(x, y); l.Location = new Point(x, y / 4); box.Parent = panel1; map.Add(l, box); } }