Exemplo n.º 1
0
        private void Form2Control(string name)
        {
            this.form2Control.Do(
                () =>
            {
                IFormModel formModel = this.FormModel;
                if (formModel == null)
                {
                    return;
                }

                Control editControl = this.Control.GetEditControl(name);
                if (editControl == null)
                {
                    return;
                }

                ControlExchange exchange = ControlExchange.Get(editControl);
                if (exchange == null)
                {
                    return;
                }

                try
                {
                    object value = formModel.GetPropertyValue(name);
                    exchange.SetValue(editControl, value);
                }
                catch (Exception e)
                {
                    this.ErrorProvider.SetError(editControl, e.Message);
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Crea la etiqueta.
        /// </summary>
        protected virtual Control CreateLabel(string name)
        {
            IFormModel formModel = this.FormModel;

            PropertyDescription propDescription = formModel.GetDescription(name);

            Label label = new Label();

            label.Name         = name + "_label";
            label.Text         = propDescription.Label;
            label.AutoEllipsis = this.LabelAutoEllipsis;
            label.TextAlign    = this.LabelTextAlign;
            label.AutoSize     = this.LabelAutoSize;
            label.Anchor       = this.LabelAnchor;
            label.Dock         = this.LabelDock;
            label.Padding      = this.LabelPadding;
            label.Margin       = this.LabelMargin;

            string description = propDescription.Description;

            if (!string.IsNullOrEmpty(description))
            {
                ToolTip toolTip = new ToolTip();
                toolTip.SetToolTip(label, description);
            }

            return(label);
        }
Exemplo n.º 3
0
        private void Control2Form(Control editControl)
        {
            IFormModel formModel = this.FormModel;

            if (formModel == null)
            {
                return;
            }

            ControlExchange exchange = ControlExchange.Get(editControl);

            if (exchange == null)
            {
                return;
            }

            try
            {
                string name  = exchange.PopertyName;
                object value = exchange.GetValue(editControl);
                formModel.SetPropertyValue(name, value);

                this.ErrorProvider.SetError(editControl, null);
            }
            catch (Exception e)
            {
                this.ErrorProvider.SetError(editControl, e.Message);
            }
        }
Exemplo n.º 4
0
        public FormPresenter(IFormView view, IFormModel model)
        {
            this.view  = view;
            this.model = model;

            this.view.SubmitButtonClick += OnSubmitButtonClick;
            view.ViewLoad += OnViewLoad;
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Crea el editor.
        /// </summary>
        protected virtual Control CreateEditor(string name, ErrorProvider errorProvider)
        {
            IFormModel formModel = this.FormModel;

            PropertyDescription propDescription = formModel.GetDescription(name);
            Type tipo = formModel.GetPropertyType(name);

            // Se busca la fabrica de editores.
            IEditorFactory editorFactory = propDescription.EditorFactory ?? this.DefaultEditorFactory;

            Contract.Assert(editorFactory != null);

            ViewProperties[] viewProperties  = formModel.GetViewProperties(name).ToArray();
            IServiceProvider serviceProvider = this.GetServiceProvider();

            // Se crea el control mediante la fabrica de editores.
            Control editor = (Control)editorFactory.Create(tipo, viewProperties, serviceProvider);

            if (editor == null)
            {
                Log <FormViewControl <TControl> > .ErrorFormat("No se encuentra mapeo para la propiedad de formulario {0} [{1}]", formModel, name);

                editor      = new System.Windows.Forms.Label();
                editor.Text = "<ERROR>";
            }

            //editor.Site = mySite;
            editor.Name     = name;
            editor.Enabled  = true;
            editor.AutoSize = this.EditorAutoSize;
            editor.Anchor   = this.EditorAnchor;
            editor.Dock     = this.EditorDock;
            editor.Padding  = this.EditorPadding;
            editor.Margin   = this.EditorMargin;

            string description = propDescription.Description;

            if (!string.IsNullOrEmpty(description))
            {
                ToolTip toolTip = new ToolTip();
                toolTip.SetToolTip(editor, description);
            }

            ControlExchange exchange = ControlExchange.Get(editor);

            if (exchange != null)
            {
                exchange.PopertyName = name;
            }

            return(editor);
        }
Exemplo n.º 6
0
        public override void ContentChanged(ComboBox editControl, IFormModel formModel, string name, IServiceProvider serviceProvider)
        {
            IEnumerable <ViewProperties> viewProperties = formModel.GetViewProperties(name);
            IRefList refList = viewProperties.OfType <RefListProperties>().Select(rlp => rlp.RefList).FirstOrDefault();

            if (refList != null)
            {
                IEnumerable items;
                if (formModel is IRefFormObject)
                {
                    object formObject = ((IRefFormObject)formModel).FormObject;
                    items = refList.GetItems(serviceProvider, formObject);
                }
                else
                {
                    items = refList.GetItems(serviceProvider, null);
                }
                editControl.Items.Clear();
                editControl.Items.AddRange(items.Cast <object>().ToArray());
            }
        }
Exemplo n.º 7
0
            private void AddProperties(IDictionary <string, PropertyData> properties, bool showCategories)
            {
                IFormModel formModel = this.FormView.FormModel;

                int maxColumnProperties = 1;

                this.ColumnCount = maxColumnProperties * 3;

                // Se asigna el estilo a las columnas.
                for (int i = 0; i < maxColumnProperties; i++)
                {
                    this.ColumnStyles.Add(new ColumnStyle(this.LabelColumnStyle.SizeType, this.LabelColumnStyle.Width));
                    this.ColumnStyles.Add(new ColumnStyle(this.ControlColumnStyle.SizeType, this.ControlColumnStyle.Width));
                    this.ColumnStyles.Add(new ColumnStyle(this.ErrorColumnStyle.SizeType, this.ErrorColumnStyle.Width));
                }

                // Se rellena la tabla.
                if (!showCategories)
                {
                    foreach (PropertyData data in formModel.GetProperties().Select(name => properties.GetSafe(name)))
                    {
                        this.AddProperty(data);
                    }
                }
                else
                {
                    foreach (string category in formModel.GetCategories())
                    {
                        PropertyData firstOrDefault = formModel.GetProperties(category).Select(name => properties.GetSafe(name)).FirstOrDefault();
                        if (firstOrDefault != null)
                        {
                            this.AddCategory(firstOrDefault.CategoryControl, formModel.GetProperties(category).Select(name => properties.GetSafe(name)));
                        }
                    }
                }
            }
 public static MvcHtmlString FormData(this HtmlHelper htmlHelper, IFormModel model)
 {
     Assert.ArgumentNotNull(model, "model");
     Assert.IsNotNull(model.Item, "IFormModel.Item cannot be null");
     return(htmlHelper.Hidden("__AjaxFormData", model.Item.ID.ToShortID().ToString()));
 }
Exemplo n.º 9
0
        protected IDictionary <string, PropertyData> BuildControls(bool showCategories)
        {
            IFormModel formModel = this.FormModel;

            Dictionary <string, Control>      categories = new Dictionary <string, Control>();
            Dictionary <string, PropertyData> lines      = new Dictionary <string, PropertyData>();

            if (formModel == null)
            {
                return(lines);
            }

            if (showCategories)
            {
                foreach (string category in formModel.GetCategories())
                {
                    Contract.Assert(!string.IsNullOrWhiteSpace(category));

                    Control categoryControl = this.CreateCategory(category);
                    categories.Add(category, categoryControl);
                }
            }

            foreach (string name in formModel.GetProperties())
            {
                try
                {
                    PropertyDescription propDescription = formModel.GetDescription(name);

                    PropertyData line = new PropertyData();
                    line.Name = name;

                    // Se crea y configura el editor.
                    Control editorControl = this.CreateEditor(name, this.ErrorProvider);
                    line.EditorControl = editorControl;

                    // Se trata la etiqueta.
                    if (!propDescription.HideLabel)
                    {
                        // Se crea y configura la etiqueta.
                        Control labelControl = this.CreateLabel(name);
                        line.LabelControl = labelControl;
                    }

                    string category = propDescription.Category;
                    line.Category = category;

                    if (showCategories)
                    {
                        Control categoryControl = categories[category];
                        line.CategoryControl = categoryControl;
                    }

                    lines.Add(name, line);
                }
                catch (Exception e)
                {
                    Log <FormViewControl <TControl> > .Error(e);
                }
            }

            return(lines);
        }
Exemplo n.º 10
0
 public virtual void ContentChanged(object control, IFormModel formModel, string name, IServiceProvider serviceProvider)
 {
 }