Exemple #1
0
        /// <summary>
        /// 为所有属性生成自动折行的编辑器列表。
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="properties"></param>
        protected FrameworkElement GenerateWrappingEditors(DetailLogicalView detailView, IEnumerable <WPFEntityPropertyViewMeta> properties)
        {
            var panel = new WrapPanel
            {
                Orientation = detailView.Meta.DetailAsHorizontal ? Orientation.Horizontal : Orientation.Vertical
            };

            var wp = new WrapPanel();

            panel.Children.Add(wp);
            foreach (var propertyView in properties)
            {
                if (propertyView.DetailNewLine)
                {
                    wp = new WrapPanel();
                    panel.Children.Add(wp);
                }

                wp.Children.Add(new EditorHost {
                    EntityProperty = propertyView
                });
            }

            return(EnableScoller(panel, panel.Orientation));
        }
Exemple #2
0
        /// <summary>
        /// 根据 DetailLayoutMode 的值生成动态布局的表单。
        /// </summary>
        /// <param name="detailView"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        protected FrameworkElement GenerateEditors(
            DetailLogicalView detailView,
            IEnumerable <WPFEntityPropertyViewMeta> properties,
            DetailLayoutMode layoutMode
            )
        {
            if (detailView is QueryLogicalView)
            {
                return(this.GenerateGridEditors(detailView, properties));
            }

            switch (layoutMode)
            {
            case DetailLayoutMode.Dynamic:
                if (detailView.CalculateColumnsCount(properties) == 1)
                {
                    return(this.GenerateGridEditors(detailView, properties));
                }
                else
                {
                    return(this.GenerateWrappingEditors(detailView, properties));
                }

            case DetailLayoutMode.Wrapping:
                return(this.GenerateWrappingEditors(detailView, properties));

            case DetailLayoutMode.AutoGrid:
                return(this.GenerateGridEditors(detailView, properties));

            default:
                return(this.GenerateWrappingEditors(detailView, properties));
            }
        }
Exemple #3
0
        /// <summary>
        /// 为某实体类构建一个详细面板视图
        /// </summary>
        /// <param name="entityViewInfo"></param>
        /// <returns></returns>
        public DetailLogicalView CreateDetailView(WPFEntityViewMeta entityViewInfo)
        {
            var view = new DetailLogicalView(entityViewInfo);

            this.InitDetailView(view);

            this.OnViewCreated(view);

            return(view);
        }
        protected override void OnServiceInvoking(DetailLogicalView detailView, CancelEventArgs e)
        {
            base.OnServiceInvoking(detailView, e);

            var entity = detailView.Current as PurchaseOrder;
            if (entity.StorageInDirectly)
            {
                var btn = App.MessageBox.Show("您选择了直接入库,系统将会为本次采购自动生成一张相应的入库单。\r\n是否继续?".Translate(), MessageBoxButton.YesNo);
                if (btn == MessageBoxResult.No) e.Cancel = true;
            }
        }
Exemple #5
0
        /// <summary>
        /// 则使用 TabControl 或者 GroupBox 把每个组分开生成,并添加到最终的容器控件中返回。
        /// </summary>
        /// <param name="detailView"></param>
        /// <param name="groups"></param>
        /// <returns></returns>
        protected FrameworkElement GenerateGroups(DetailLogicalView detailView, IList <WPFDetailPropertyGroup> groups)
        {
            if (detailView.Meta.DetailGroupingMode == DetailGroupingMode.GroupBox)
            {
                var groupsPanel = new StackPanel();

                foreach (var group in groups)
                {
                    var panel = this.GenerateEditors(detailView, OrderedDetailProperties(group.Properties), group.LayoutMode ?? detailView.Meta.DetailLayoutMode);

                    groupsPanel.Children.Add(new GroupBox
                    {
                        Header = new Label {
                            Content = group.GroupLabel.Translate()
                        },
                        Content = panel
                    });
                }

                return(groupsPanel);
            }
            else
            {
                var tabControl = new TabControl {
                    TabStripPlacement = Dock.Left
                };

                foreach (var group in groups)
                {
                    var panel = this.GenerateEditors(detailView, OrderedDetailProperties(group.Properties), group.LayoutMode ?? detailView.Meta.DetailLayoutMode);

                    tabControl.Items.Add(new TabItem
                    {
                        Header = new Label {
                            Content = group.GroupLabel.Translate()
                        },
                        //这里需要使用 AdornerDecorator,否则在页签切换后会造成验证状态丢失。
                        Content = new AdornerDecorator
                        {
                            Child = panel
                        }
                    });
                }

                return(tabControl);
            }
        }
Exemple #6
0
        /// <summary>
        /// 使用 AutoGrid 来生成表单。
        /// </summary>
        /// <param name="detailView"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        protected FrameworkElement GenerateGridEditors(DetailLogicalView detailView, IEnumerable <WPFEntityPropertyViewMeta> properties)
        {
            var panel = new AutoGrid
            {
                ColumnsCount = detailView.CalculateColumnsCount(properties),
                Orientation  = detailView.Meta.DetailAsHorizontal ? Orientation.Horizontal : Orientation.Vertical
            };

            foreach (var propertyView in properties)
            {
                panel.Children.Add(new EditorHost {
                    EntityProperty = propertyView
                });
            }

            return(EnableScoller(panel, panel.Orientation));
        }
Exemple #7
0
        private void InitDetailView(DetailLogicalView view)
        {
            var control = this._uiFactory.CreateDetailPanel(view);

            view.SetControl(control);
        }
Exemple #8
0
 protected virtual void OnServiceInvoking(DetailLogicalView detailView, CancelEventArgs e)
 {
 }
Exemple #9
0
        /// <summary>
        /// 生成一个AutoGrid,用于承载所有的字段显示控件。
        /// </summary>
        /// <param name="detailView">逻辑视图</param>
        /// <returns></returns>
        public Form CreateDetailPanel(DetailLogicalView detailView)
        {
            if (detailView == null)
            {
                throw new ArgumentNullException("detailView");
            }

            Form form = null;

            var meta = detailView.Meta;

            if (meta.DetailPanelType == null)
            {
                /*********************** 代码块解释 *********************************
                 * 表单自动生成解释:
                 *
                 * 首先,所有属性分组,如果:
                 * 1. 没有分组时,根据 DetailLayoutMode 的值,分以下两种情况来生成表单:
                 * * 使用 AutoGrid 作为 Editor 的容器,以保证每个 Editor 有动态的宽度。
                 * * 使用 WrapPanel 作为 Editor 的容器,使得实现 Editor 的自动换行。(此时 Editor 应该有最小的宽度。)
                 * 2. 如果分为多个组,则使用 TabControl 或者使用 GroupBox 把每个组分开生成,每个组则都使用上一条算法进行生成。
                 *
                 * 最外围的容器是 Form 控件,它的 VerticalScrollBarVisibility 在样式中将被设置为 Auto,
                 * 而 HorizontalScrollBarVisibility 则为 Disable。
                 *
                 * 这样,整体设计上,保证竖直方向上有滚动条,水平方向上是动态宽度或动态换行。
                 **********************************************************************/

                form = new Form();

                var groups = meta.DetailGroups;
                if (groups.Count > 0)
                {
                    form.Content = this.GenerateGroups(detailView, groups);
                }
                else
                {
                    var properties = OrderedDetailProperties(meta.EntityProperties);
                    form.Content = this.GenerateEditors(detailView, properties, meta.DetailLayoutMode);
                }

                //var groups = meta.OrderedEntityProperties().Where(pv => pv.CanShowIn(ShowInWhere.Detail))
                //    .GroupBy(pv => pv.DetailGroupName).ToArray();
                //if (groups.Length == 0) throw new InvalidOperationException(meta.EntityType.FullName + " 没有属性在表单中显示时,不能生成表单控件。");

                //if (groups.Length == 1)
                //{
                //    form.Content = this.GenerateEditors(detailView, groups[0]);
                //}
                //else
                //{
                //    form.Content = this.GenerateGroups(detailView, groups);
                //}
            }
            //自定义表单布局
            else
            {
                form = Activator.CreateInstance(meta.DetailPanelType) as Form;
                if (form == null)
                {
                    throw new InvalidProgramException("自定义面板必须是 Form 元素。");
                }
            }

            form.DetailView = detailView;

            //即时调用 EditorHost 的 ApplyTemplate 方法,
            //可以使 EditorHost 即时生成 PropertyEditor,而不是等到界面 Loaded 时再生成。
            ApplyEditorHostTemplate(form);

            return(form);
        }
Exemple #10
0
 private void InitDetailView(DetailLogicalView view)
 {
     var control = this._uiFactory.CreateDetailPanel(view);
     view.SetControl(control);
 }
Exemple #11
0
        /// <summary>
        /// 为某实体类构建一个详细面板视图
        /// </summary>
        /// <param name="entityViewInfo"></param>
        /// <returns></returns>
        public DetailLogicalView CreateDetailView(WPFEntityViewMeta entityViewInfo)
        {
            var view = new DetailLogicalView(entityViewInfo);

            this.InitDetailView(view);

            this.OnViewCreated(view);

            return view;
        }
Exemple #12
0
        /// <summary>
        /// 为所有属性生成自动折行的编辑器列表。
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="properties"></param>
        protected FrameworkElement GenerateWrappingEditors(DetailLogicalView detailView, IEnumerable<WPFEntityPropertyViewMeta> properties)
        {
            var panel = new WrapPanel
            {
                Orientation = detailView.Meta.DetailAsHorizontal ? Orientation.Horizontal : Orientation.Vertical
            };

            var wp = new WrapPanel();
            panel.Children.Add(wp);
            foreach (var propertyView in properties)
            {
                if (propertyView.DetailNewLine)
                {
                    wp = new WrapPanel();
                    panel.Children.Add(wp);
                }

                wp.Children.Add(new EditorHost { EntityProperty = propertyView });
            }

            return EnableScoller(panel, panel.Orientation);
        }
Exemple #13
0
        /// <summary>
        /// 则使用 TabControl 或者 GroupBox 把每个组分开生成,并添加到最终的容器控件中返回。
        /// </summary>
        /// <param name="detailView"></param>
        /// <param name="groups"></param>
        /// <returns></returns>
        protected FrameworkElement GenerateGroups(DetailLogicalView detailView, IList<WPFDetailPropertyGroup> groups)
        {
            if (detailView.Meta.DetailGroupingMode == DetailGroupingMode.GroupBox)
            {
                var groupsPanel = new StackPanel();

                foreach (var group in groups)
                {
                    var panel = this.GenerateEditors(detailView, OrderedDetailProperties(group.Properties), group.LayoutMode ?? detailView.Meta.DetailLayoutMode);

                    groupsPanel.Children.Add(new GroupBox
                    {
                        Header = new Label { Content = group.GroupLabel.Translate() },
                        Content = panel
                    });
                }

                return groupsPanel;
            }
            else
            {
                var tabControl = new TabControl { TabStripPlacement = Dock.Left };

                foreach (var group in groups)
                {
                    var panel = this.GenerateEditors(detailView, OrderedDetailProperties(group.Properties), group.LayoutMode ?? detailView.Meta.DetailLayoutMode);

                    tabControl.Items.Add(new TabItem
                    {
                        Header = new Label { Content = group.GroupLabel.Translate() },
                        //这里需要使用 AdornerDecorator,否则在页签切换后会造成验证状态丢失。
                        Content = new AdornerDecorator
                        {
                            Child = panel
                        }
                    });
                }

                return tabControl;
            }
        }
Exemple #14
0
        /// <summary>
        /// 使用 AutoGrid 来生成表单。
        /// </summary>
        /// <param name="detailView"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        protected FrameworkElement GenerateGridEditors(DetailLogicalView detailView, IEnumerable<WPFEntityPropertyViewMeta> properties)
        {
            var panel = new AutoGrid
            {
                ColumnsCount = detailView.CalculateColumnsCount(properties),
                Orientation = detailView.Meta.DetailAsHorizontal ? Orientation.Horizontal : Orientation.Vertical
            };

            foreach (var propertyView in properties)
            {
                panel.Children.Add(new EditorHost { EntityProperty = propertyView });
            }

            return EnableScoller(panel, panel.Orientation);
        }
Exemple #15
0
        /// <summary>
        /// 根据 DetailLayoutMode 的值生成动态布局的表单。
        /// </summary>
        /// <param name="detailView"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        protected FrameworkElement GenerateEditors(
            DetailLogicalView detailView,
            IEnumerable<WPFEntityPropertyViewMeta> properties,
            DetailLayoutMode layoutMode
            )
        {
            if (detailView is QueryLogicalView)
            {
                return this.GenerateGridEditors(detailView, properties);
            }

            switch (layoutMode)
            {
                case DetailLayoutMode.Dynamic:
                    if (detailView.CalculateColumnsCount(properties) == 1)
                    {
                        return this.GenerateGridEditors(detailView, properties);
                    }
                    else
                    {
                        return this.GenerateWrappingEditors(detailView, properties);
                    }
                case DetailLayoutMode.Wrapping:
                    return this.GenerateWrappingEditors(detailView, properties);
                case DetailLayoutMode.AutoGrid:
                    return this.GenerateGridEditors(detailView, properties);
                default:
                    return this.GenerateWrappingEditors(detailView, properties);
            }
        }
Exemple #16
0
        /// <summary>
        /// 生成一个AutoGrid,用于承载所有的字段显示控件。
        /// </summary>
        /// <param name="detailView">逻辑视图</param>
        /// <returns></returns>
        public Form CreateDetailPanel(DetailLogicalView detailView)
        {
            if (detailView == null) throw new ArgumentNullException("detailView");

            Form form = null;

            var meta = detailView.Meta;
            if (meta.DetailPanelType == null)
            {
                /*********************** 代码块解释 *********************************
                 * 表单自动生成解释:
                 *
                 * 首先,所有属性分组,如果:
                 * 1. 没有分组时,根据 DetailLayoutMode 的值,分以下两种情况来生成表单:
                 * * 使用 AutoGrid 作为 Editor 的容器,以保证每个 Editor 有动态的宽度。
                 * * 使用 WrapPanel 作为 Editor 的容器,使得实现 Editor 的自动换行。(此时 Editor 应该有最小的宽度。)
                 * 2. 如果分为多个组,则使用 TabControl 或者使用 GroupBox 把每个组分开生成,每个组则都使用上一条算法进行生成。
                 *
                 * 最外围的容器是 Form 控件,它的 VerticalScrollBarVisibility 在样式中将被设置为 Auto,
                 * 而 HorizontalScrollBarVisibility 则为 Disable。
                 *
                 * 这样,整体设计上,保证竖直方向上有滚动条,水平方向上是动态宽度或动态换行。
                **********************************************************************/

                form = new Form();

                var groups = meta.DetailGroups;
                if (groups.Count > 0)
                {
                    form.Content = this.GenerateGroups(detailView, groups);
                }
                else
                {
                    var properties = OrderedDetailProperties(meta.EntityProperties);
                    form.Content = this.GenerateEditors(detailView, properties, meta.DetailLayoutMode);
                }

                //var groups = meta.OrderedEntityProperties().Where(pv => pv.CanShowIn(ShowInWhere.Detail))
                //    .GroupBy(pv => pv.DetailGroupName).ToArray();
                //if (groups.Length == 0) throw new InvalidOperationException(meta.EntityType.FullName + " 没有属性在表单中显示时,不能生成表单控件。");

                //if (groups.Length == 1)
                //{
                //    form.Content = this.GenerateEditors(detailView, groups[0]);
                //}
                //else
                //{
                //    form.Content = this.GenerateGroups(detailView, groups);
                //}
            }
            //自定义表单布局
            else
            {
                form = Activator.CreateInstance(meta.DetailPanelType) as Form;
                if (form == null) throw new InvalidProgramException("自定义面板必须是 Form 元素。");
            }

            form.DetailView = detailView;

            //即时调用 EditorHost 的 ApplyTemplate 方法,
            //可以使 EditorHost 即时生成 PropertyEditor,而不是等到界面 Loaded 时再生成。
            ApplyEditorHostTemplate(form);

            return form;
        }