Пример #1
0
        // DataTableMappingCollection object
        /// <summary>
        /// Call the dialog to edit the TableMappings
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider">Service provider.</param>
        /// <param name="value">DataTableMappingCollection object.</param>
        /// <returns></returns>
        public override object EditValue(
			ITypeDescriptorContext context,
			IServiceProvider       provider,
			object                 value)
        {
            if (context          != null  &&
                context.Instance != null  &&
                provider         != null)
            {
                IWindowsFormsEditorService edSvc =
                    (IWindowsFormsEditorService)provider.GetService(
                    typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    System.ComponentModel.Design.IDesignerHost host =
                        provider.GetService(
                            typeof(System.ComponentModel.Design.IDesignerHost))
                        as System.ComponentModel.Design.IDesignerHost;
                    if (host == null)
                    {
                        System.Windows.Forms.MessageBox.Show(
                            "The IDesignerHost service interface " +
                            "could not be obtained to process the request.",
                            "Table Mappings");
                        return value;
                    }

                    System.ComponentModel.Design.IComponentChangeService chgSvc =
                        provider.GetService(
                        typeof(System.ComponentModel.Design.IComponentChangeService))
                        as System.ComponentModel.Design.IComponentChangeService;
                    if (chgSvc == null)
                    {
                        System.Windows.Forms.MessageBox.Show(
                            "The IComponentChangeService service interface " +
                            "could not be obtained to process the request.",
                            "Table Mappings");
                        return value;
                    }

                    if (!context.OnComponentChanging())
                    {
                        System.Windows.Forms.MessageBox.Show(
                            "The component is not permitted to be changed.",
                            "Table Mappings");
                        return value;
                    }

                    System.ComponentModel.Design.DesignerTransaction
                        designerTxn = host.CreateTransaction("TableMapping");

                    DbDataAdapter adapter = (DbDataAdapter)context.Instance;
                    Form form = new TableMapForm( adapter );

                    chgSvc.OnComponentChanging(adapter, null);
                    using (form)
                    {
                        using (designerTxn)
                        {
                            try
                            {
                                DialogResult result = edSvc.ShowDialog( form );
                                if (result == DialogResult.OK)
                                    designerTxn.Commit();
                                else
                                    designerTxn.Cancel();
                            }
                            finally
                            {
                                chgSvc.OnComponentChanged(adapter, null, null, null);
            //								context.OnComponentChanged();
                            }
                        }
                    }
                }  // end if (edSvc != null)
            } // end if context is OK
            return value;
        }
Пример #2
0
        /// <summary>
        /// Call the dialog to edit the TableMappings
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider">Service provider.</param>
        /// <param name="value">DataTableMappingCollection object.</param>
        /// <returns></returns>
        public override object EditValue(
            ITypeDescriptorContext context,
            IServiceProvider provider,
            object value)                              // DataTableMappingCollection object
        {
            if (context != null &&
                context.Instance != null &&
                provider != null)
            {
                IWindowsFormsEditorService edSvc =
                    (IWindowsFormsEditorService)provider.GetService(
                        typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    System.ComponentModel.Design.IDesignerHost host =
                        provider.GetService(
                            typeof(System.ComponentModel.Design.IDesignerHost))
                        as System.ComponentModel.Design.IDesignerHost;
                    if (host == null)
                    {
                        System.Windows.Forms.MessageBox.Show(
                            "The IDesignerHost service interface " +
                            "could not be obtained to process the request.",
                            "Table Mappings");
                        return(value);
                    }

                    System.ComponentModel.Design.IComponentChangeService chgSvc =
                        provider.GetService(
                            typeof(System.ComponentModel.Design.IComponentChangeService))
                        as System.ComponentModel.Design.IComponentChangeService;
                    if (chgSvc == null)
                    {
                        System.Windows.Forms.MessageBox.Show(
                            "The IComponentChangeService service interface " +
                            "could not be obtained to process the request.",
                            "Table Mappings");
                        return(value);
                    }

                    if (!context.OnComponentChanging())
                    {
                        System.Windows.Forms.MessageBox.Show(
                            "The component is not permitted to be changed.",
                            "Table Mappings");
                        return(value);
                    }

                    System.ComponentModel.Design.DesignerTransaction
                        designerTxn = host.CreateTransaction("TableMapping");

                    DbDataAdapter adapter = (DbDataAdapter)context.Instance;
                    Form          form    = new TableMapForm(adapter);

                    chgSvc.OnComponentChanging(adapter, null);
                    using (form)
                    {
                        using (designerTxn)
                        {
                            try
                            {
                                DialogResult result = edSvc.ShowDialog(form);
                                if (result == DialogResult.OK)
                                {
                                    designerTxn.Commit();
                                }
                                else
                                {
                                    designerTxn.Cancel();
                                }
                            }
                            finally
                            {
                                chgSvc.OnComponentChanged(adapter, null, null, null);
//								context.OnComponentChanged();
                            }
                        }
                    }
                }         // end if (edSvc != null)
            }             // end if context is OK
            return(value);
        }