private void FillGroup(LayoutGroup group, DialogLayoutViewModel vm)
        {
            if (vm.Source != null)
            {
                group.DataContext = vm.Source;
            }

            foreach (var field in vm.Fields.OrderBy(p => p.Order).ToArray())
            {
                var oldLayout = FindName(field.Name);
                if (oldLayout != null)
                {
                    continue;
                }

                LayoutItem layoutItem;
                if (field.FieldType == typeof(Button) || field.FieldType == typeof(IFooterMenu))
                {
                    var button = new Button
                    {
                        Content = field.Caption,
                        HorizontalContentAlignment = HorizontalAlignment.Left
                    };

                    if (vm.FontSize > 0)
                    {
                        button.FontSize = vm.FontSize;
                    }

                    layoutItem = new LayoutItem
                    {
                        Name       = field.Name,
                        IsEnabled  = !field.IsEnabled.HasValue || field.IsEnabled.Value,
                        Visibility = field.Visible ? Visibility.Visible : Visibility.Collapsed,
                        Content    = button
                    };
                }
                else
                {
                    layoutItem = new CustomDataLayoutItem(field)
                    {
                        IsVisibilitySetOutside    = true,
                        IsDisplayFormatSetOutside = true,
                        //ParentViewModelSource = vm.ParentViewModelSource,
                    };
                }

                if (vm.FontSize > 0)
                {
                    layoutItem.FontSize = vm.FontSize;
                }

                layoutItem.Tag = field;

                //т.к. испоьзуем ExpandoObject - регистрируем здесь
                RegisterName(field.Name, layoutItem);
                group.Children.Add(layoutItem);
            }
        }
        private void FillArtGroup(ArtItem art, CustomDataLayoutControl group)
        {
            NameScope.SetNameScope(group, new NameScope());
            var fields = art.Fields;

            foreach (var field in fields)
            {
                var layoutItem = new CustomDataLayoutItem(field)
                {
                    IsVisibilitySetOutside    = true,
                    IsDisplayFormatSetOutside = true,
                    ToolTipIns = CreateCustomSuperToolTip(field)
                };

                group.Children.Add(layoutItem);
            }
            group.UpdateLayout();
        }
        private void FillGroup(LayoutGroup group)
        {
            if (_model.Source != null)
            {
                group.DataContext = _model.Source;
            }

            Action <Control, ValueDataField> setPropertiesHandler = (control, valueDataField) =>
            {
                if (_model.FontSize > 0)
                {
                    control.FontSize = _model.FontSize;
                }

                control.Tag = valueDataField;

                //т.к. испоьзуем ExpandoObject - регистрируем здесь
                RegisterName(valueDataField.Name, control);
            };

            var layoutGroups = new Dictionary <string, LayoutGroup>();

            foreach (var field in _model.Fields.OrderBy(p => p.Order).ToArray())
            {
                var oldLayout = FindName(field.Name);
                if (oldLayout != null)
                {
                    continue;
                }

                UIElement child = null;
                if (field.FieldType == typeof(FooterMenu) || field.FieldType == typeof(Button) || field.FieldType == typeof(IFooterMenu))
                {
                    var button = new Button
                    {
                        Content = field.Caption,
                        HorizontalContentAlignment = HorizontalAlignment.Left
                    };

                    if (_model.FontSize > 0)
                    {
                        button.FontSize = _model.FontSize;
                    }

                    var layoutItem = new LayoutItem
                    {
                        Name       = field.Name,
                        IsEnabled  = !field.IsEnabled.HasValue || field.IsEnabled.Value,
                        Visibility = field.Visible ? Visibility.Visible : Visibility.Collapsed,
                        Content    = button
                    };
                    setPropertiesHandler(layoutItem, field);
                    child = layoutItem;
                }
                else
                {
                    var layoutItem = new CustomDataLayoutItem(_model.IsWfDesignMode, field)
                    {
                        IsVisibilitySetOutside    = true,
                        IsDisplayFormatSetOutside = true
                    };
                    setPropertiesHandler(layoutItem, field);

                    var layoutGroupName = LayoutGroupHelper.GetLayoutGroupNameFromField(field, _model.IsWfDesignMode);
                    if (string.IsNullOrEmpty(layoutGroupName))
                    {
                        child = layoutItem;
                    }
                    else
                    {
                        LayoutGroup layoutGroup;
                        if (!layoutGroups.ContainsKey(layoutGroupName))
                        {
                            layoutGroup = LayoutGroupHelper.CreateLayoutGroup(layoutGroupName);
                            layoutGroups[layoutGroupName] = layoutGroup;
                            RegisterName(layoutGroupName, layoutGroup);
                            group.Children.Add(layoutGroup);
                        }

                        layoutGroup = layoutGroups[layoutGroupName];
                        layoutGroup.Children.Add(layoutItem);
                    }
                }

                if (child != null)
                {
                    group.Children.Add(child);
                }
            }
        }
Esempio n. 4
0
        private void FillGroup(LayoutGroup group, ICustomModelHandler vm)
        {
            var inPropertyEditMode = false;
            var isOldLayout        = false;

            //TODO: по хорошему нужно писать свой контрол на остнове DataLayout-а (научить правильно биндиться, понимать аттрибуты и т.д.)
            if (vm.Source != null)
            {
                group.DataContext = vm.Source;
            }
            var pe = vm as IPropertyEditHandler;

            if (pe != null)
            {
                inPropertyEditMode = pe.InPropertyEditMode;
            }
            foreach (var field in vm.Fields.OrderBy(p => p.Order).ToArray())
            {
                bool?isMergedProperty = null;
                if (inPropertyEditMode)
                {
                    isMergedProperty = pe.IsMergedPropery(field.Name);
                }

                var oldLayout = FindName(field.Name);
                if ((isOldLayout = oldLayout != null) && !field.IsChangeLookupCode)
                {
                    var li = oldLayout as CustomDataLayoutItem;
                    if (li != null)
                    {
                        li.SetLabelProperties(field);
                        li.Visibility = field.Visible ? Visibility.Visible : Visibility.Hidden;
                        if (field.IsEnabled.HasValue)
                        {
                            li.IsReadOnly = !field.IsEnabled.Value;
                        }

                        if (field.SetFocus)
                        {
                            li.SetFocus = field.SetFocus;
                        }

                        li.Binding = new Binding(string.IsNullOrEmpty(field.FieldName) ? field.Name : field.FieldName)
                        {
                            Mode = BindingMode.TwoWay,
                            UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                            ValidatesOnDataErrors = true,
                        };
                    }
                    else
                    {
                        var layItem = oldLayout as LayoutItem;
                        if (layItem != null)
                        {
                            layItem.Visibility = field.Visible ? Visibility.Visible : Visibility.Hidden;
                            if (field.IsEnabled.HasValue)
                            {
                                layItem.IsEnabled         = field.IsEnabled.Value;
                                layItem.Content.IsEnabled = field.IsEnabled.Value;
                            }
                        }
                    }
                    continue;
                }

                var isChangeName = false;
                if (Regex.IsMatch(field.Name, @"^[0-9]"))
                {
                    field.Name   = "_" + field.Name;
                    isChangeName = true;
                }

                LayoutItem  layoutItem;
                LayoutGroup foundGroup = null;
                var         index      = 0;

                if (oldLayout != null)
                {
                    foundGroup = ObjectViewBase.SearchGroup(group, (UIElement)oldLayout);
                    if (foundGroup == null)
                    {
                        continue;
                    }
                    index = foundGroup.Children.IndexOf((UIElement)oldLayout);
                    if (index < 0)
                    {
                        continue;
                    }
                    foundGroup.Children.Remove((UIElement)oldLayout);
                    UnregisterName(((FrameworkElement)oldLayout).Name);
                }

                if (typeof(Button).IsAssignableFrom(field.FieldType))
                {
                    Key currKey;
                    layoutItem = new LayoutItem()
                    {
                        Name       = field.Name,
                        IsEnabled  = !field.IsEnabled.HasValue || field.IsEnabled.Value,
                        Visibility = field.Visible ? Visibility.Visible : Visibility.Collapsed,

                        Content = new CustomButton
                        {
                            Content = field.Caption,
                            Command = vm.MenuCommand,

                            HotKey           = Enum.TryParse(field.HotKey, out currKey) ? currKey : Key.None,
                            CommandParameter = new KeyValuePair <string, object>(field.Name, field.Value),
                            Visibility       = field.Visible ? Visibility.Visible : Visibility.Collapsed,
                            IsEnabled        = !field.IsEnabled.HasValue || field.IsEnabled.Value
                        }
                    };
                }
                else
                {
                    layoutItem = new CustomDataLayoutItem(field)
                    {
                        IsVisibilitySetOutside    = true,
                        IsDisplayFormatSetOutside = true,
                        IsLabelFontWeightBold     = field.IsLabelFontWeightBold,
                        ParentViewModelSource     = (vm is ICPV) ? vm.ParentViewModelSource : null,
                        LookupButtonEnabled       = field.LookupButtonEnabled,
                        ToolTipIns       = CreateCustomSuperToolTip(field),
                        IsMergedProperty = isMergedProperty
                    };
                }

                //т.к. испоьзуем ExpandoObject - регистрируем здесь
                RegisterName(field.Name, layoutItem);
                if (isChangeName)
                {
                    field.Name = field.Name.Substring(1);
                }

                if (oldLayout != null && index > -1)
                {
                    foundGroup.Children.Insert(index, layoutItem);
                }
                else
                {
                    group.Children.Add(layoutItem);
                }
            }

            if (!isOldLayout)
            {
                objectDataLayout.RestoreLayout(vm.LayoutValue);
            }
            if (vm.InsertFromAvailableItems && objectDataLayout.AvailableItems.Count > 0)
            {
                foreach (var p in objectDataLayout.AvailableItems.ToArray())
                {
                    objectDataLayout.AvailableItems.Remove(p);
                    objectDataLayout.Children.Add(p);
                }
            }
        }
        private void FillGroup(LayoutGroup group, ICustomModelHandler vm)
        {
            //TODO: по хорошему нужно писать свой контрол на остнове DataLayout-а (научить правильно биндиться, понимать аттрибуты и т.д.)
            if (vm.Source != null)
            {
                group.DataContext = vm.Source;
            }

            //HACK: всегда берем последний элемент (с макс. order'ом) для SpinEdit'а
            var maxorder = vm.Fields.Max(p => p.Order);

            foreach (var field in vm.Fields.OrderBy(p => p.Order).ToArray())
            {
                var oldLayout = FindName(field.Name);
                if (oldLayout != null)
                {
                    continue;
                }

                var isChangeName = false;
                if (Regex.IsMatch(field.Name, @"^[0-9]"))
                {
                    field.Name   = "_" + field.Name;
                    isChangeName = true;
                }

                LayoutItem layoutItem;
                if (maxorder > 0 && field.Order == maxorder)
                {
                    layoutItem = new LayoutItem
                    {
                        Name          = field.Name,
                        LabelPosition = field.LabelPosition.To(LayoutItemLabelPosition.Left),
                        Label         = new Label {
                            Content = field.Caption
                        },
                        IsEnabled  = !field.IsEnabled.HasValue || field.IsEnabled.Value,
                        Visibility = field.Visible ? Visibility.Visible : Visibility.Hidden,
                        Content    = spinEdit
                    };
                }
                else
                {
                    layoutItem = new CustomDataLayoutItem(field)
                    {
                        IsVisibilitySetOutside    = true,
                        IsDisplayFormatSetOutside = true,
                        IsLabelFontWeightBold     = field.IsLabelFontWeightBold,
                        ParentViewModelSource     = vm.Source,
                        ToolTipIns = CreateCustomSuperToolTip(field),
                    };
                    ((CustomDataLayoutItem)layoutItem).SetLabelProperties(field);
                }

                //т.к. испоьзуем ExpandoObject - регистрируем здесь
                RegisterName(field.Name, layoutItem);
                if (isChangeName)
                {
                    field.Name = field.Name.Substring(1);
                }
                group.Children.Add(layoutItem);
            }

            objectDataLayout.RestoreLayout(vm.LayoutValue);
            if (vm.InsertFromAvailableItems && objectDataLayout.AvailableItems.Count > 0)
            {
                foreach (var p in objectDataLayout.AvailableItems.ToArray())
                {
                    objectDataLayout.AvailableItems.Remove(p);
                    objectDataLayout.Children.Add(p);
                }
            }
        }
        private void FillGroup(LayoutGroup group, DialogSourceViewModel vm)
        {
            //TODO: по хорошему нужно писать свой контрол на остнове DataLayout-а (научить правильно биндиться, понимать аттрибуты и т.д.)
            if (vm.Source != null)
            {
                group.DataContext = vm.Source;
            }
            group.Children.Clear();
            var setfocus = false;

            var layoutGroups = new Dictionary <string, LayoutGroup>();

            foreach (var field in vm.Fields.OrderBy(p => p.Order).ToArray())
            {
                var oldLayout = FindName(field.Name);
                if (oldLayout != null)
                {
                    continue;
                }
                if (field.SetFocus)
                {
                    setfocus = true;
                }

                UIElement child = null;
                if (field.FieldType == typeof(Button) || field.FieldType == typeof(CustomButton))
                {
                    var layoutItem = new LayoutItem
                    {
                        Name       = field.Name,
                        IsEnabled  = field.IsEnabled.HasValue && field.IsEnabled.Value,
                        Visibility = field.Visible ? Visibility.Visible : Visibility.Collapsed,
                        Content    = MenuHelper.CreateCustomButton(field, vm.MenuCommand, vm.FontSize, false)
                    };
                    RegisterName(field.Name, layoutItem);
                    child = layoutItem;
                }
                else if (field.FieldType == typeof(IFooterMenu) || field.FieldType == typeof(FooterMenu))
                {
                    MenuHelper.CreateFooterMenu(footerMenuControl, field, vm.MenuCommand, vm.FontSize, false);
                    continue;
                }
                else
                {
                    var layoutItem = new CustomDataLayoutItem(vm.IsWfDesignMode, field)
                    {
                        IsVisibilitySetOutside    = true,
                        IsDisplayFormatSetOutside = true,

                        FontSize = vm.FontSize,

                        IsReadOnlySetOutside = true,
                        TooltipDisable       = true,
                        CloseDialogCommand   = vm.MenuCommand
                    };
                    RegisterName(field.Name, layoutItem);

                    var layoutGroupName = LayoutGroupHelper.GetLayoutGroupNameFromField(field, vm.IsWfDesignMode);
                    if (string.IsNullOrEmpty(layoutGroupName))
                    {
                        child = layoutItem;
                    }
                    else
                    {
                        LayoutGroup layoutGroup;
                        if (!layoutGroups.ContainsKey(layoutGroupName))
                        {
                            layoutGroup = LayoutGroupHelper.CreateLayoutGroup(layoutGroupName);
                            layoutGroups[layoutGroupName] = layoutGroup;
                            RegisterName(layoutGroupName, layoutGroup);
                            group.Children.Add(layoutGroup);
                        }

                        layoutGroup = layoutGroups[layoutGroupName];
                        layoutGroup.Children.Add(layoutItem);
                    }
                }

                if (child != null)
                {
                    group.Children.Add(child);
                }
            }

            if (!setfocus)
            {
                KeyHelper.SetFocusElement(group.Children);
            }

            objectDataLayout.RestoreLayout(vm.LayoutValue);
        }
        private void FillGroup(dynamic obj, LayoutGroup group, object parentData, SettingDisplay displaySetting)
        {
            bool inPropertyEditMode = false;

            if (obj != null)
            {
                group.DataContext = obj;
            }

            //TODO: по хорошему нужно писать свой контрол на остнове DataLayout-а (научить правильно биндиться, понимать аттрибуты и т.д.)
            var vm = (IObjectViewModel)DataContext;
            var pe = vm as IPropertyEditHandler;

            if (pe != null)
            {
                inPropertyEditMode = pe.InPropertyEditMode;
            }
            var fields = vm.GetDataFields(displaySetting);
            //var sub = DataContext as IObjectMemoryViewModel;
            var read = true;

            if (vm.Mode == ObjectViewModelMode.MemoryObject)
            {
                read = vm.IsEditEnable;
            }
            foreach (var field in fields)
            {
                // если в режиме PropertyEdit то не показываем вложенные коллекции
                if (inPropertyEditMode && typeof(IList).IsAssignableFrom(field.FieldType))
                {
                    continue;
                }
                bool?isMergedProperty = null;
                if (inPropertyEditMode)
                {
                    isMergedProperty = pe.IsMergedPropery(field.Name);
                }
                var oldLayout = FindName(field.Name);
                if (oldLayout != null && !field.IsChangeLookupCode)
                {
                    var li = oldLayout as CustomDataLayoutItem;
                    if (li != null)
                    {
                        li.Visibility = field.Visible ? Visibility.Visible : Visibility.Hidden;
                        if (field.IsEnabled.HasValue)
                        {
                            li.IsReadOnly = !field.IsEnabled.Value;
                        }
                        li.IsMergedProperty = isMergedProperty;
                        li.ApplyProperties();
                    }
                    continue;
                }

                var index = new int();
                if (oldLayout != null)
                {
                    index = group.Children.IndexOf((UIElement)oldLayout);
                    if (index < 0)
                    {
                        continue;
                    }
                    group.Children.Remove((UIElement)oldLayout);
                    UnregisterName(((FrameworkElement)oldLayout).Name);
                }

                var layoutItem = new CustomDataLayoutItem(field)
                {
                    IsVisibilitySetOutside    = true,
                    IsDisplayFormatSetOutside = true,
                    ParentViewModelSource     = parentData,
                    ToolTipIns = CreateCustomSuperToolTip(field),
                    IsReadOnlyRightDependcy = !read,
                    ParentViewModel         = vm,
                    IsMergedProperty        = isMergedProperty
                };

                var formulaBinding = CreateFormulaBinding(obj as IIsNew, field.FieldName);
                if (formulaBinding != null)
                {
                    layoutItem.FormulaBinding = formulaBinding;
                    BindingOperations.SetBinding(layoutItem, CustomDataLayoutItem.InFormulaModeProperty,
                                                 new Binding("InFormulaMode")
                    {
                        Source = vm, Mode = BindingMode.TwoWay
                    });
                }

                if (oldLayout != null && index > -1)
                {
                    group.Children.Insert(index, layoutItem);
                }
                else
                {
                    group.Children.Add(layoutItem);
                }
            }
            group.UpdateLayout();
        }