예제 #1
0
        public override void UpdateObject(DataUIMapper dm)
        {
            if (dm.DataSource == null)
            {
                return;
            }

            foreach (MapperInfo mi in dm.Mappings)
            {
                if ((mi.DataProperty != null) && (mi.ControlProperty != null) && (mi.ControlID != null))
                {
                    object control = this.FindControl(mi.ControlID);
                    if (control == null)
                    {
                        continue;
                    }

                    try
                    {
                        System.Type   ctrlType  = TypeHelper.GetTypeOfProperty(control, mi.ControlProperty);
                        PropertyInfo  ctrlPI    = ctrlType.GetProperty(mi.ControlProperty);
                        System.Type   dataType  = TypeHelper.GetTypeOfProperty(dm.DataSource, mi.DataProperty);
                        PropertyInfo  dataPI    = dataType.GetProperty(mi.DataProperty);
                        TypeConverter converter = TypeDescriptor.GetConverter(dataPI.PropertyType);
                        object        value     = ctrlPI.GetValue(control, new object[0]);
                        dataPI.SetValue(dm.DataSource, converter.ConvertFrom(value), new object[0]);
                    }
                    catch { }
                }
            }
        }
예제 #2
0
        public override void UpdateUI(DataUIMapper dm)
        {
            if (dm.DataSource == null)
            {
                return;
            }

            foreach (MapperInfo mi in dm.Mappings)
            {
                if ((mi.DataProperty != null) && (mi.ControlProperty != null) && (mi.ControlID != null))
                {
                    object control = this.FindControl(mi.ControlID);
                    if (control == null)
                    {
                        continue;
                    }
                    try
                    {
                        System.Type  dataType = TypeHelper.GetTypeOfProperty(dm.DataSource, mi.DataProperty);
                        PropertyInfo dataPI   = dataType.GetProperty(mi.DataProperty);
                        object       value    = dataPI.GetValue(dm.DataSource, new object[0]);
                        MemberHelper.SetControlDisplay(control, mi, value);
                    }
                    catch { }
                }
            }
        }
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            CodeDomSerializer serial = GetConfiguredSerializer(manager, value);

            if (serial == null)
            {
                return(null);
            }

            CodeStatementCollection statements = (CodeStatementCollection)serial.Serialize(manager, value);

            PropertyDescriptor prop = TypeDescriptor.GetProperties(value)["WebMapping"];
            MapperInfo         info = (MapperInfo)prop.GetValue(value);

            DataUIMapper dm = (DataUIMapper)
                              DesignUtils.ProviderProperty.GetValue(prop, new object[0]);

            //Attach the view mappings to the control attributes.
            if (info.ControlProperty != String.Empty && info.DataProperty != String.Empty)
            {
                CodeExpression     ctlref = SerializeToExpression(manager, value);
                CodeCastExpression cast   = new CodeCastExpression(typeof(IAttributeAccessor), ctlref);

                statements.Add(new CodeMethodInvokeExpression(
                                   cast, "SetAttribute", new CodeExpression[] {
                    new CodePrimitiveExpression("DIM_Mapper"),
                    new CodePrimitiveExpression(manager.GetName(dm))
                }));
                statements.Add(new CodeMethodInvokeExpression(
                                   cast, "SetAttribute", new CodeExpression[] {
                    new CodePrimitiveExpression("DIM_Format"),
                    new CodePrimitiveExpression(info.Format)
                }));
                statements.Add(new CodeMethodInvokeExpression(
                                   cast, "SetAttribute", new CodeExpression[] {
                    new CodePrimitiveExpression("DIM_DataProperty"),
                    new CodePrimitiveExpression(info.DataProperty)
                }));
                statements.Add(new CodeMethodInvokeExpression(
                                   cast, "SetAttribute", new CodeExpression[] {
                    new CodePrimitiveExpression("DIM_ControlProperty"),
                    new CodePrimitiveExpression(info.ControlProperty)
                }));
            }
            return(statements);
        }
예제 #4
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            object retvalue = value;

            try
            {
                IDesignerHost host             = (IDesignerHost)context.GetService(typeof(IDesignerHost));
                IWindowsFormsEditorService srv = (IWindowsFormsEditorService)context.GetService(typeof(IWindowsFormsEditorService));

                if (srv != null && host != null)
                {
                    DataUIMapper dm       = (DataUIMapper)context.Instance;
                    IDesigner    designer = host.GetDesigner(dm);

                    MappingsEditorForm form = new MappingsEditorForm(designer);
                    //form.SetMappings(dm.Mappings);

                    form.Host         = host;
                    form.DataUIMapper = dm;

                    //Show form.
                    if (srv.ShowDialog(form) == DialogResult.OK)
                    {
                        MapperInfoList mappings = form.GetMappings();
                        context.PropertyDescriptor.SetValue(context.Instance, mappings);

                        //if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        //{
                        //    MapperInfoList mappings = form.GetMappings();
                        //    context.PropertyDescriptor.SetValue(context.Instance, mappings);
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(
                    "��������ʱ�쳣: " + ex.ToString());
            }

            return(retvalue);
        }
예제 #5
0
 public abstract void UpdateObject(DataUIMapper dm);
예제 #6
0
 public abstract void UpdateUI(DataUIMapper dm);
예제 #7
0
 public virtual void Connect(DataUIMapper dataUIMapper, object controlsContainer)
 {
     this._dm         = dataUIMapper;
     this._dm.Adapter = this;
 }
예제 #8
0
 public override void Connect(DataUIMapper dataUIMapper, object controlsContainer)
 {
     base.Connect(dataUIMapper, controlsContainer);
     host = controlsContainer as Control;
 }
예제 #9
0
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            CodeDomSerializer serial = GetBaseComponentSerializer(manager);

            if (serial == null)
            {
                return(null);
            }

            CodeStatementCollection statements = (CodeStatementCollection)serial.Serialize(manager, value);

            //serializer for web controls.
            if (!(manager.GetSerializer(typeof(System.Web.UI.Control), typeof(CodeDomSerializer)) is WebControlSerializer))
            {
                manager.AddSerializationProvider(new WebControlSerializationProvider());
            }

            IDesignerHost host = (IDesignerHost)manager.GetService(typeof(IDesignerHost));

            if (host.RootComponent == value)
            {
                return(statements);
            }

            statements.AddRange(GetCommentHeader("Mapper code"));
            DataUIMapper   cn    = (DataUIMapper)value;
            CodeExpression cnref = SerializeToExpression(manager, value);

            #region Mapping property serialization

            CodePropertyReferenceExpression propref = new CodePropertyReferenceExpression(cnref, "Mappings");
            foreach (MapperInfo mi in cn.Mappings)
            {
                MapperInfo info = mi;
                if (info.ControlID != String.Empty && info.ControlProperty != null &&
                    info.DataProperty != String.Empty)
                {
                    object ctl = manager.GetInstance(info.ControlID);
                    //if (ctl == null)
                    //{
                    //    manager.ReportError(String.Format("Control '{0}' associated with the view mapping in controller '{1}' doesn't exist in the page.", info.ControlID, manager.GetName(value)));
                    //    continue;
                    //}
                    if (ctl.GetType().GetProperty(info.ControlProperty) == null)
                    {
                        manager.ReportError(String.Format("Control property '{0}' in control '{1}' associated with the view mapping in datauimapper '{2}' doesn't exist.", info.ControlProperty, info.ControlID, manager.GetName(value)));
                        continue;
                    }

                    statements.Add(
                        new CodeMethodInvokeExpression(
                            propref, "Add",
                            new CodeExpression[]
                    {
                        new CodeObjectCreateExpression(
                            typeof(MapperInfo),
                            new CodeExpression[] {
                            new CodePrimitiveExpression(info.ControlID),
                            new CodePrimitiveExpression(info.ControlProperty),
                            new CodePrimitiveExpression(info.DataProperty), new CodePrimitiveExpression((int)info.Format)
                        }
                            )
                    }
                            ));
                }
            }

            #endregion

            statements.Add(
                new CodeCommentStatement("Connect the host environment."));

            if (host.RootComponent as System.Windows.Forms.Form != null)
            {
                CodeObjectCreateExpression adapter = new CodeObjectCreateExpression(typeof(Adapter.WindowsFormsAdapter), new CodeExpression[0]);
                CodeExpression             connect = new CodeMethodInvokeExpression(adapter, "Connect",
                                                                                    new CodeExpression[] {
                    cnref,
                    new CodeThisReferenceExpression(),
                });
                statements.Add(connect);
            }
            else if (host.RootComponent as System.Web.UI.Page != null)
            {
                CodeObjectCreateExpression adapter = new CodeObjectCreateExpression(typeof(Adapter.WebFormsAdapter), new CodeExpression[0]);
                CodeExpression             connect = new CodeMethodInvokeExpression(adapter, "Connect",
                                                                                    new CodeExpression[] {
                    cnref,
                    new CodeThisReferenceExpression(),
                });
                statements.Add(connect);
            }

            return(statements);
        }