/// <summary> /// Construye el objeto DataModelSilverlight desde un objeto DataModel cargado. /// </summary> /// <param name="dataModel">objeto DataModel usado para construir</param> public void SetDataModel(DataModel dataModel) { this.dataModel = dataModel; this.tables = new List <IConnection>(); // Construye y dibuja las tablas. foreach (Table table in dataModel.Tables) { TableSilverlight tableSilverlight = new TableSilverlight(table); AtachEvents(tableSilverlight); tables.Add(tableSilverlight); Canvas.SetLeft(tableSilverlight, tableSilverlight.XCoordinateRelativeToParent); Canvas.SetTop(tableSilverlight, tableSilverlight.YCoordinateRelativeToParent); this.canvasDraw.Add(tableSilverlight); Canvas.SetZIndex(tableSilverlight, zindexValueForWidgets); tableSilverlight.UpdateLayout(); } // Construye y dibuja las relaciones. foreach (Relation relation in dataModel.Relations) { int SourcePosition = dataModel.Tables.IndexOf(relation.Source); int TargetPosition = dataModel.Tables.IndexOf(relation.Target); ConnectionSilverlight connection = new ConnectionSilverlight(tables[SourcePosition], tables[TargetPosition], relation.RelationType); connection.Relation = relation; connection.Change += new EventHandler(connection_Change); connection.Reset += new EventHandler(connection_Reseted); connection.Loaded += new EventHandler(connection_Loaded); this.canvasDraw.Children.Add(connection.MyMenuWidget); Canvas.SetZIndex(connection.MyMenuWidget, ZindexValueForConnections + 1); canvasDraw.Children.Add(connection.Path); Canvas.SetZIndex(connection.Path, ZindexValueForConnections); ConnectionsSilverlight.Add(connection); } }
/// <summary> /// Crea el objeto SilverlightConnection. /// </summary> /// <param name="from">Objeto IConnection origen de la conexión.</param> /// <param name="targetTable">Objeto IConnection Destino de la conexión.</param> private void CreateConnection(IConnection from, IConnection target) { if (from == null) { throw new ArgumentNullException("from", "from can not be null."); } if (target == null) { throw new ArgumentNullException("target", "target can not be null."); } TableSilverlight fromTableSilverlight = (from as TableSilverlight); TableSilverlight targetTableSilverlight = (target as TableSilverlight); if (fromTableSilverlight == null) { throw new NullReferenceException("fromTableSilverlight can not be null in method CreateConnection in class DataModelDesignerSilverlight."); } if (targetTableSilverlight == null) { throw new NullReferenceException("targetTableSilverlight can not be null in method CreateConnection in class DataModelDesignerSilverlight."); } Error error = DataModel.CheckDuplicatedConnection(fromTableSilverlight.Table, targetTableSilverlight.Table); if (error != null) { Dialog.ShowErrorDialog(SilverlightVisualDesigners.Properties.Resources.InvalidConnectionError, error.Description, this.LayoutRoot); return; } ConnectionSilverlight connection = new ConnectionSilverlight(from, target, selectedRelationType); connection.Change += new EventHandler(connection_Change); connection.Reset += new EventHandler(connection_Reseted); AddRelation(connection); ConnectionsSilverlight.Add(connection); }