private bool ValidateSelection(RelationshipItemPanel panel) { GrilleColumn column = panel.SelectedColumn(); GrilleRelationshipItem item = this.Relationship.GetItemByColumn(column); if (item == null || item == panel.RelationshipItem) { return(true); } if (item != null) { String title = ""; String message = ""; if (panel.RelationshipItem == null) { if (item.primary) { title = "Wrong selection"; } } MessageDisplayer.DisplayWarning(title, message); return(false); } return(true); }
private void OnDeleted(object item) { RelationshipItemPanel panel = (RelationshipItemPanel)item; if (panel.RelationshipItem != null) { if (this.Relationship == null) { this.Relationship = GetNewRelationship(); } this.Relationship.RemoveItem(panel.RelationshipItem); this.panel.Children.Remove(panel); if (this.ActiveItemPanel != null && this.ActiveItemPanel == panel) { this.ActiveItemPanel = (RelationshipItemPanel)this.panel.Children[this.panel.Children.Count - 1]; } int index = 1; foreach (object pan in this.panel.Children) { ((RelationshipItemPanel)pan).Index = index++; } if (Changed != null) { Changed(); } if (ItemDeleted != null && panel.RelationshipItem != null) { ItemDeleted(panel.RelationshipItem); } if (panel.RelationshipItem.column.type != ParameterType.SCOPE.ToString()) { return; } if (panel.RelationshipItem.primary) { this.Grid.RelatedColumnsDataSource.Add(panel.RelationshipItem.column); } else { this.Grid.PrimaryColumnsDataSource.Add(panel.RelationshipItem.column); } } }
private bool OnItemChanged(object item) { RelationshipItemPanel panel = (RelationshipItemPanel)item; if (this.Relationship == null) { this.Relationship = GetNewRelationship(); } if (ValidateSelection(panel)) { bool isNew = panel.RelationshipItem == null; GrilleColumn oldColumn = isNew ? null : panel.RelationshipItem.column; panel.Fill(); if (isNew) { this.Relationship.AddItem(panel.RelationshipItem); } else { this.Relationship.UpdateItem(panel.RelationshipItem); } OnChanged(panel.RelationshipItem, isNew); if (panel.RelationshipItem.primary) { this.Grid.RelatedColumnsDataSource.Remove(panel.RelationshipItem.column); this.Grid.RelatedColumnsDataSource.Add(oldColumn); } else { this.Grid.PrimaryColumnsDataSource.Remove(panel.RelationshipItem.column); this.Grid.PrimaryColumnsDataSource.Add(oldColumn); } return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="relationship"></param> public void Display(Grille grid) { this.Grid = grid; this.panel.Children.Clear(); int index = 1; if (this.Relationship == null) { this.ActiveItemPanel = new RelationshipItemPanel(grid, index, IsPrimary); AddItemPanel(this.ActiveItemPanel); return; } foreach (GrilleRelationshipItem item in this.Relationship.itemListChangeHandler.Items) { if (IsPrimary == item.primary) { RelationshipItemPanel itemPanel = new RelationshipItemPanel(grid, item, IsPrimary); AddItemPanel(itemPanel); index++; } } this.ActiveItemPanel = new RelationshipItemPanel(grid, index, IsPrimary); AddItemPanel(this.ActiveItemPanel); }
protected void AddItemPanel(RelationshipItemPanel itemPanel) { itemPanel.Changed += OnItemChanged; itemPanel.Deleted += OnDeleted; this.panel.Children.Add(itemPanel); }