Esempio 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);
                }
            });
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private void DeattachEditControls()
        {
            if (this.FormModel == null)
            {
                return;
            }

            foreach (Control editControl in this.Control.GetEditControls())
            {
                ControlExchange exchange = ControlExchange.Get(editControl);
                if (exchange != null)
                {
                    exchange.Deattach();
                }
            }
        }
Esempio n. 5
0
        private void ContentChanged()
        {
            foreach (string name in this.FormModel.GetProperties())
            {
                Control editControl = this.Control.GetEditControl(name);
                if (editControl == null)
                {
                    continue;
                }

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

                IServiceProvider serviceProvider = this.GetServiceProvider();
                exchange.ContentChanged(editControl, this.FormModel, name, serviceProvider);
            }
        }
Esempio n. 6
0
        protected virtual void UpdateStructure()
        {
            if (this.FormModel == null)
            {
                return;
            }

            TControl control = this.Control;

            foreach (Control editControl in control.GetEditControls())
            {
                ControlExchange exchange = ControlExchange.Get(editControl);
                if (exchange != null)
                {
                    exchange.DoNotListen(editControl, this.Control_Changed);
                }
            }

            this.DeattachEditControls();

            control.UpdateControls();

            this.AttachEditControls();

            foreach (Control editControl in control.GetEditControls())
            {
                ControlExchange exchange = ControlExchange.Get(editControl);
                if (exchange != null)
                {
                    exchange.Listen(editControl, this.Control_Changed);
                }
            }

            this.ContentChanged();
            this.WholeForm2Control();
        }