public void RemoveTableFromCanvas(TableModel tableModel) { try { TableObject[] tableObjectsArray = this.FindVisualControls(typeof(TableObject)).TryCast <TableObject>(); TableObject tableObject = tableObjectsArray.FirstOrDefault(t => t.Table.TableName.ToLower() == tableModel.TableName.ToLower()); if (tableObject == null) { return; } this.Children.Remove(tableObject); if (this.RemoveTable != null) { foreach (KeyValuePair <string, DatabaseRelation> relation in tableObject.ColumnRelationModel) { this.Children.Remove(relation.Value.LinePath[0]); this.Children.Remove(relation.Value.LinePath[1]); this.columnRelationModel.Remove(relation.Key); } this.RemoveTable?.Invoke(this, tableModel); this.CanvasChanged?.Invoke(this, tableModel); Integrity.RemoveTableMapping(tableModel); } } catch (Exception err) { MessageBox.Show(err.InnerExceptionMessage()); } }
private void TableObject_Remove(object sender, TableModel tableModel) { this.Children.Remove((TableObject)sender); if (this.RemoveTable != null) { TableObject tableObject = (TableObject)sender; foreach (KeyValuePair <string, DatabaseRelation> relation in tableObject.ColumnRelationModel) { this.Children.Remove(relation.Value.LinePath[0]); this.Children.Remove(relation.Value.LinePath[1]); this.columnRelationModel.Remove(relation.Key); } this.RemoveTable?.Invoke(this, tableModel); this.CanvasChanged?.Invoke(this, tableModel); Integrity.RemoveTableMapping(tableModel); } }