private void AddNewRelation(DatabaseRelation relation)
        {
            RelationEditor editor = new RelationEditor(relation);

            bool?result = editor.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            relation.DatabaseRelationDelete += this.DatabaseRelation_Delete;

            UIElement tableControl = this.FindVisualControls(typeof(TableObject)).FirstOrDefault(t => ((TableObject)t).Table.TableName == editor.DatabaseRelation.ChildTable);

            UIElement parentTableControl = this.FindVisualControls(typeof(TableObject)).FirstOrDefault(t => ((TableObject)t).Table.TableName == editor.DatabaseRelation.ParentTable);

            UIElement[] tableControls = this.FindVisualControls(typeof(TableObject));

            if (tableControl != null)
            {
                TableObject childTable = (TableObject)tableControl;

                string dictionaryKey = $"{editor.DatabaseRelation.ParentTable}||{editor.DatabaseRelation.ChildTable}";

                childTable.ColumnRelationModel.Add(dictionaryKey, editor.DatabaseRelation);

                this.columnRelationModel.Add(dictionaryKey, editor.DatabaseRelation);

                this.DrawRelation((TableObject)parentTableControl, tableControls, new KeyValuePair <string, DatabaseRelation>(dictionaryKey, editor.DatabaseRelation));
            }
        }
        private async Task EditPerson(ParentWithChildren parentWithChildren)
        {
            //in a real world app you would pass _people in and allow the selectable items source to dynamically change
            var editor = new RelationEditor(parentWithChildren, _people.Items.ToArray());

            //TODO: Investigate why selectable state is being held onto ny the Dialog
            await DialogHost.Show(editor, (object sender, DialogClosingEventArgs eventArgs) =>
            {
                //use the .Edit method as it is more efficient when apply multiple changes
                _relations.Edit(innerCache =>
                {
                    //extract the new relations
                    var newRelations = editor.Children
                                .Where(c => c.IsSelected).Select(selectable => new Relation(parentWithChildren.Parent, (Person)selectable))
                                .ToArray();

                    //remove old ones
                    var toRemove = innerCache
                        .Items.Where(r => r.Parent == parentWithChildren.Parent && !newRelations.Contains(r))
                        .ToArray();

                    innerCache.Remove(toRemove);
                    innerCache.AddOrUpdate(newRelations);
                });
            });
        }
        private async Task EditPerson(ParentWithChildren parentWithChildren)
        {
            //in a real world app you would pass _people in and allow the selectable items source to dynamically change
            var editor = new RelationEditor(parentWithChildren, _people.Items.ToArray());

            //TODO: Investigate why selectable state is being held onto ny the Dialog
            await DialogHost.Show(editor, (object sender, DialogClosingEventArgs eventArgs) =>
            {
                //use the .Edit method as it is more efficient when apply multiple changes
                _relations.Edit(innerCache =>
                {
                    //extract the new relations
                    var newRelations = editor.Children
                                       .Where(c => c.IsSelected).Select(selectable => new Relation(parentWithChildren.Parent, (Person)selectable))
                                       .ToArray();

                    //remove old ones
                    var toRemove = innerCache
                                   .Items.Where(r => r.Parent == parentWithChildren.Parent && !newRelations.Contains(r))
                                   .ToArray();

                    innerCache.Remove(toRemove);
                    innerCache.AddOrUpdate(newRelations);
                });
            });
        }
示例#4
0
    public string[] GetSelectedIds()
    {
        //non-relational mode
        if (RelationEditor == null)
        {
            var values = Eval(ID) as IEnumerable;
            if (values != null)
            {
                return(values.Cast <object>().Select(v => Convert.ToString(v)).ToArray());
            }
            else
            {
                return(new string[0]);
            }
        }

        bool isEmptyId = AssertHelper.IsFuzzyEmpty(EntityId);

        // special hack for autoincrement "new row" ids... TBD: refactor
        if (EntityId is int || EntityId is long)
        {
            if (Convert.ToInt64(EntityId) == 0)
            {
                isEmptyId = true;
            }
        }
        if (isEmptyId)
        {
            if (DefaultValueServiceName != null)
            {
                var defaultValuePrv = WebManager.GetService <IProvider <object, object> >(DefaultValueServiceName);
                var defaultValues   = defaultValuePrv.Provide(DefaultDataContext ?? this.GetContext());
                if (defaultValues != null)
                {
                    var list = new List <string>();
                    if (defaultValues is IList)
                    {
                        foreach (object defaultVal in (IList)defaultValues)
                        {
                            list.Add(Convert.ToString(defaultVal));
                        }
                    }
                    else
                    {
                        list.Add(Convert.ToString(defaultValues));
                    }
                    return(list.ToArray());
                }
            }
            return(new string[0]);
        }
        // select visible ids
        return(RelationEditor.GetToKeys(EntityId).Select(o => Convert.ToString(o)).ToArray());
    }
示例#5
0
        public void Set(object fromKey, IEnumerable toKeys)
        {
            var oldToKeys = GetToKeys(fromKey);

            RelationEditor.Set(fromKey, toKeys);
            var logContext = new LogContext()
            {
                FromKey       = fromKey,
                RelationName  = RelationName,
                AddedToKeys   = toKeys.Cast <object>().Where(toKey => !DalcRelationEditor.Contains(toKey, oldToKeys)).ToArray(),
                RemovedToKeys = oldToKeys.Cast <object>().Where(oldToKey => !DalcRelationEditor.Contains(oldToKey, toKeys)).ToArray()
            };

            WriteLog.Execute(logContext);
        }
示例#6
0
 public object[] GetToKeys(object fromKey)
 {
     return(RelationEditor.GetToKeys(fromKey));
 }
示例#7
0
 protected void Save()
 {
     RelationEditor.Set(EntityId, GetControlSelectedIds());
 }