Beispiel #1
0
        public FrameworkElement CreateControl(FormItemContext context)
        {
            MatchResult     result       = MatchResult.No;
            ControlSinkBase selectedSink = null;

            lock (_lock)
            {
                for (int i = 0; i < _sinklist.Count; i++)
                {
                    var tempresult = _sinklist[i].MatchTest(context);
                    if (tempresult > result)
                    {
                        result       = tempresult;
                        selectedSink = _sinklist[i];
                    }
                }
            }

            if (result == MatchResult.No)
            {
                throw new Exception(string.Format("No suitable Control Sink for {0}.{1}", context.DataType.Name, context.PropertyInfo.Name));
            }
            else
            {
                return(selectedSink.CreateControl(context));
            }
        }
        public FrameworkElement CreateControl(FormItemContext context)
        {
            MatchResult result = MatchResult.No;
            ControlSinkBase selectedSink = null;

            lock (_lock)
            {
                for (int i = 0; i < _sinklist.Count; i++)
                {
                    var tempresult = _sinklist[i].MatchTest(context);
                    if (tempresult > result)
                    {
                        result = tempresult;
                        selectedSink = _sinklist[i];
                    }
                }
            }

            if (result == MatchResult.No)
                throw new Exception(string.Format("No suitable Control Sink for {0}.{1}", context.DataType.Name, context.PropertyInfo.Name));
            else
            {
                return selectedSink.CreateControl(context);
            }
        }
 FrameworkElement OnCreateControl(FormItemContext context, FrameworkElement ctl)
 {
     if (CreateControlCallback != null)
     {
         return(CreateControlCallback(context, ctl));
     }
     else
     {
         return(ctl);
     }
 }
Beispiel #4
0
        public override MatchResult MatchTest(FormControlLib.FormItemContext context)
        {
            var attr = context.PropertyInfo.GetCustomAttribute(typeof(UIHintAttribute)) as UIHintAttribute;

            if (context.PropertyInfo.PropertyType == typeof(string) &&
                attr != null &&
                string.Equals(attr.UIHint, "address", StringComparison.OrdinalIgnoreCase))
            {
                return(MatchResult.Recommanded);
            }
            else
            {
                return(MatchResult.No);
            }
        }
        private void filed_changed(object sender, SelectionChangedEventArgs e)
        {
            var controlop  = new ControlAndOperator();
            var pinfo      = field_cb.SelectedValue as PropertyInfo;
            var ctlcontext = new FormItemContext(_type, pinfo);

            controlop.InputControl = InputControlBuilder.CreateControl(ctlcontext);
            if (pinfo.PropertyType.Name.Equals("string", StringComparison.OrdinalIgnoreCase))
            {
                controlop.UseStringOperator = true;
            }
            else
            {
                controlop.UseNumberOperator = true;
            }

            if (CreateControlCallback != null)
            {
                controlop = CreateControlCallback(ctlcontext, controlop);
            }

            _bindobject = Activator.CreateInstance(_type);
            controlop.InputControl.DataContext = _bindobject;
            input_br.Child = controlop.InputControl;

            operator_cb.ItemsSource = null;
            if (controlop.UseStringOperator)
            {
                operator_cb.ItemsSource = EnumNameValuePair.EnumToList(typeof(StringOperator));
            }
            else if (controlop.UseNumberOperator)
            {
                operator_cb.ItemsSource = EnumNameValuePair.EnumToList(typeof(NumberOperator));
            }

            operator_cb.SelectedIndex = 0;

            if (pinfo.PropertyType.IsEnum)
            {
                operator_cb.IsEnabled = false;
            }
            else
            {
                operator_cb.IsEnabled = true;
            }
        }
Beispiel #6
0
        public override System.Windows.FrameworkElement CreateControl(FormControlLib.FormItemContext context)
        {
            // create control
            var inputctl = new AddressCombobox();

            // set style
            inputctl.Style = Application.Current.Resources["edit_controlbase"] as Style;

            // set binding
            var binding = new Binding(context.PropertyInfo.Name)
            {
                Mode = BindingMode.TwoWay,
            };

            inputctl.SetBinding(WatermarkTextBox.TextProperty, binding);

            // set validation
            CustomValidation.SetValidationOptOut(inputctl);

            return(inputctl);
        }
        internal FrameworkElement RenderSelectUserControl(FormItemContext context, WarehouseContext dbcontext,
			User selecteduser = null)
        {
            var options = (from u in dbcontext.Users
                select new NameValuePair
                {
                    Name = u.Name,
                    Description = u.IdentificationNumber,
                    Value = u
                }).ToList();
            var ctl = new ComboBoxSink().CreateControlForLookup(context, options);

            if (selecteduser != null)
            {
                var selectedop = options.FirstOrDefault(o => ((User) o.Value).UserId == selecteduser.UserId);
                ((ComboBox) ctl).SelectedValue = selectedop.Value;
            }
            return ctl;
        }
        public void RenderForm(object data, bool isreadonly)
        {
            DataContext = data;
            var datatype = data.GetType();

            if (InputControlBuilder == null)
            {
                InputControlBuilder = new ControlsBuilder();
            }

            root.Children.Clear();
            _errlabels.Clear();
            _editctls.Clear();

            var props  = datatype.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);
            int rownum = 0;

            for (int i = 0; i < props.Count(); i++)
            {
                var fieldcontext = new FormItemContext(data, datatype, props[i], ControlType.None);

                // determine if create field
                bool suggestion = true;
                var  attr0      = props[i].GetCustomAttribute(typeof(EditableAttribute)) as EditableAttribute;
                var  attr1      = props[i].GetCustomAttribute(typeof(KeyAttribute)) as KeyAttribute;
                if (attr1 != null ||
                    (attr0 != null && !attr0.AllowEdit))
                {
                    suggestion = false;
                }
                if (DetermineFieldCreationCallback != null)
                {
                    suggestion = DetermineFieldCreationCallback(fieldcontext, suggestion);
                }
                if (!suggestion)
                {
                    continue;
                }

                // add row
                root.RowDefinitions.Add(new RowDefinition
                {
                    Height = new GridLength(0, GridUnitType.Auto)
                });

                var rowcontainer = new StackPanel();
                rowcontainer.Orientation = Orientation.Horizontal;
                Grid.SetRow(rowcontainer, rownum);
                root.Children.Add(rowcontainer);

                // label
                var   lbcontext = new FormItemContext(data, datatype, props[i], ControlType.Label);
                Label label     = new Label();
                var   attr      = props[i].GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute;
                if (attr != null)
                {
                    if (!string.IsNullOrEmpty(attr.Name))
                    {
                        label.Content = attr.Name;
                    }
                    if (!string.IsNullOrEmpty(attr.Description))
                    {
                        label.ToolTip = attr.Description;
                    }
                }
                if (label.Content == null)
                {
                    label.Content = props[i].Name;
                }
                StyleHelper.ApplyStyle(label);
                var labelctl = OnCreateControl(lbcontext, label);
                rowcontainer.Children.Add(labelctl);

                // editable
                var editcontext = new FormItemContext(data, datatype, props[i], ControlType.Editable);
                var editctl     = InputControlBuilder.CreateControl(editcontext);
                editctl = OnCreateControl(editcontext, editctl);
                if (isreadonly)
                {
                    editctl.IsEnabled = false;
                }
                rowcontainer.Children.Add(editctl);
                _editctls.Add(editctl);

                // error label
                var errtb = new TextBlock();
                if (!isreadonly)
                {
                    errtb.Tag = props[i].Name;

                    var errbinding = new Binding
                    {
                        Source = editctl,
                        Path   = CustomValidation.GetValidationMsgBindingPath(editctl)
                    };
                    errtb.SetBinding(TextBlock.TextProperty, errbinding);
                    StyleHelper.ApplyStyle(errtb, FormControlConstrants.VALIDATION_ERROR_STYLE);
                    rowcontainer.Children.Add(errtb);
                    _errlabels.Add(errtb);
                }

                if (LayoutControlCallback != null)
                {
                    LayoutControlCallback(this.root, label, editctl, errtb);
                }

                rownum++;
            }

            if (isreadonly)
            {
                ConfirmButton.Visibility = Visibility.Collapsed;
            }
        }
 FrameworkElement OnCreateControl(FormItemContext context, FrameworkElement ctl)
 {
     if (CreateControlCallback != null)
     {
         return CreateControlCallback(context, ctl);
     }
     else
         return ctl;
 }
        public void RenderForm(object data, bool isreadonly)
        {
            DataContext = data;
            var datatype = data.GetType();
            if (InputControlBuilder == null)
                InputControlBuilder = new ControlsBuilder();

            root.Children.Clear();
            _errlabels.Clear();
            _editctls.Clear();

            var props = datatype.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);
            int rownum = 0;
            for (int i = 0; i < props.Count(); i++)
            {
                var fieldcontext = new FormItemContext(data, datatype, props[i], ControlType.None);

                // determine if create field
                bool suggestion = true;
                var attr0 = props[i].GetCustomAttribute(typeof(EditableAttribute)) as EditableAttribute;
                var attr1 = props[i].GetCustomAttribute(typeof(KeyAttribute)) as KeyAttribute;
                if (attr1 != null ||
                    (attr0 != null && !attr0.AllowEdit))
                {
                    suggestion = false;
                }
                if (DetermineFieldCreationCallback != null)
                {
                    suggestion = DetermineFieldCreationCallback(fieldcontext, suggestion);
                }
                if (!suggestion)
                {
                    continue;
                }

                // add row
                root.RowDefinitions.Add(new RowDefinition
                {
                    Height = new GridLength(0, GridUnitType.Auto)
                });

                var rowcontainer = new StackPanel();
                rowcontainer.Orientation = Orientation.Horizontal;
                Grid.SetRow(rowcontainer,rownum);
                root.Children.Add(rowcontainer);

                // label
                var lbcontext = new FormItemContext(data, datatype, props[i], ControlType.Label);
                Label label = new Label();
                var attr = props[i].GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute;
                if (attr != null)
                {
                    if (!string.IsNullOrEmpty(attr.Name))
                    {
                        label.Content = attr.Name;
                    }
                    if (!string.IsNullOrEmpty(attr.Description))
                    {
                        label.ToolTip = attr.Description;
                    }
                }
                if (label.Content == null)
                    label.Content = props[i].Name;
                StyleHelper.ApplyStyle(label);
                var labelctl = OnCreateControl(lbcontext, label);
                rowcontainer.Children.Add(labelctl);

                // editable
                var editcontext = new FormItemContext(data, datatype, props[i], ControlType.Editable);
                var editctl = InputControlBuilder.CreateControl(editcontext);
                editctl = OnCreateControl(editcontext, editctl);
                if (isreadonly)
                    editctl.IsEnabled = false;
                rowcontainer.Children.Add(editctl);
                _editctls.Add(editctl);

                // error label
                var errtb = new TextBlock();
                if (!isreadonly)
                {
                    errtb.Tag = props[i].Name;

                    var errbinding = new Binding
                    {
                        Source = editctl,
                        Path = CustomValidation.GetValidationMsgBindingPath(editctl)
                    };
                    errtb.SetBinding(TextBlock.TextProperty, errbinding);
                    StyleHelper.ApplyStyle(errtb, FormControlConstrants.VALIDATION_ERROR_STYLE);
                    rowcontainer.Children.Add(errtb);
                    _errlabels.Add(errtb);
                }

                if (LayoutControlCallback != null)
                    LayoutControlCallback(this.root, label, editctl, errtb);

                rownum++;
            }

            if (isreadonly)
            {
                ConfirmButton.Visibility = Visibility.Collapsed;
            }
        }
        private void filed_changed(object sender, SelectionChangedEventArgs e)
        {
            var controlop = new ControlAndOperator();
            var pinfo=field_cb.SelectedValue as PropertyInfo;
            var ctlcontext = new FormItemContext(_type, pinfo);
            controlop.InputControl= InputControlBuilder.CreateControl(ctlcontext);
            if (pinfo.PropertyType.Name.Equals("string", StringComparison.OrdinalIgnoreCase))
            {
                controlop.UseStringOperator = true;
            }
            else
                controlop.UseNumberOperator = true;

            if (CreateControlCallback != null)
                controlop = CreateControlCallback(ctlcontext, controlop);

            _bindobject = Activator.CreateInstance(_type);
            controlop.InputControl.DataContext = _bindobject;
            input_br.Child = controlop.InputControl;

            operator_cb.ItemsSource = null;
            if (controlop.UseStringOperator)
                operator_cb.ItemsSource = EnumNameValuePair.EnumToList(typeof(StringOperator));
            else if (controlop.UseNumberOperator)
                operator_cb.ItemsSource = EnumNameValuePair.EnumToList(typeof(NumberOperator));

            operator_cb.SelectedIndex = 0;

            if (pinfo.PropertyType.IsEnum)
            {
                operator_cb.IsEnabled = false;
            }else
            {
                operator_cb.IsEnabled = true;
            }
        }