Ejemplo n.º 1
0
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             IDatabaseConnectionUserExt dbu = context.Instance as IDatabaseConnectionUserExt;
             if (dbu != null)
             {
                 if (!(dbu.DatabaseConnection != null && dbu.DatabaseConnection.ConnectionObject != null && dbu.DatabaseConnection.ConnectionObject.IsConnectionReady))
                 {
                     ConnectionItem       ci  = dbu.DatabaseConnection;
                     DlgConnectionManager dlg = new DlgConnectionManager();
                     dlg.UseProjectScope = true;
                     dlg.SetSelection(ci);
                     if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                     {
                         dbu.DatabaseConnection = dlg.SelectedConnection;
                     }
                 }
                 if (dbu.DatabaseConnection != null && dbu.DatabaseConnection.ConnectionObject != null && dbu.DatabaseConnection.ConnectionObject.IsConnectionReady)
                 {
                     string   v  = value as string;
                     string[] vs = dbu.DatabaseConnection.ConnectionObject.GetTableNames();
                     if (vs != null && vs.Length > 0)
                     {
                         ValueList list = new ValueList(edSvc, vs, v);
                         edSvc.DropDownControl(list);
                         if (list.MadeSelection)
                         {
                             value = list.Selection;
                         }
                     }
                 }
             }
         }
     }
     return(base.EditValue(context, provider, value));
 }
Ejemplo n.º 2
0
        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)
                {
                    IDatabaseTableUser tbu = context.Instance as IDatabaseTableUser;
                    if (tbu != null)
                    {
                        if (!(tbu.DatabaseConnection != null && tbu.DatabaseConnection.ConnectionObject != null && tbu.DatabaseConnection.ConnectionObject.IsConnectionReady))
                        {
                            ConnectionItem       ci  = tbu.DatabaseConnection;
                            DlgConnectionManager dlg = new DlgConnectionManager();
                            dlg.UseProjectScope = true;
                            dlg.SetSelection(ci);
                            if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                            {
                                tbu.DatabaseConnection = dlg.SelectedConnection;
                            }
                        }
                        if (string.IsNullOrEmpty(tbu.TableName))
                        {
                            TypeSelectorTable ts = new TypeSelectorTable();
                            tbu.TableName = ts.EditValue(context, provider, string.Empty) as string;
                        }
                        if (!string.IsNullOrEmpty(tbu.TableName))
                        {
                            if (tbu.DatabaseConnection != null &&
                                tbu.DatabaseConnection.ConnectionObject != null &&
                                tbu.DatabaseConnection.ConnectionObject.IsConnectionReady)
                            {
                                FieldList fl = tbu.DatabaseConnection.ConnectionObject.GetTableFields(tbu.TableName);
                                if (fl != null)
                                {
                                    string[] names = new string[fl.Count];
                                    for (int i = 0; i < names.Length; i++)
                                    {
                                        names[i] = fl[i].Name;
                                    }
                                    FieldList sels = value as FieldList;
                                    string[]  ss;
                                    if (sels == null)
                                    {
                                        FieldCollection fc = value as FieldCollection;
                                        if (fc == null)
                                        {
                                            ss = new string[] { };
                                        }
                                        else
                                        {
                                            ss = new string[fc.Count];
                                            for (int i = 0; i < fc.Count; i++)
                                            {
                                                ss[i] = fc[i].Name;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ss = new string[sels.Count];
                                        for (int i = 0; i < sels.Count; i++)
                                        {
                                            ss[i] = sels[i].Name;
                                        }
                                    }
                                    UserControlSelectFieldNames fns = new UserControlSelectFieldNames();

                                    fns.LoadData(edSvc, names, ss);
                                    edSvc.DropDownControl(fns);
                                    if (fns.SelectedStrings != null)
                                    {
                                        FieldCollection newFields = new FieldCollection();
                                        for (int i = 0; i < fns.SelectedStrings.Length; i++)
                                        {
                                            EPField f = fl[fns.SelectedStrings[i]];
                                            if (f != null)
                                            {
                                                newFields.AddField(f);
                                            }
                                        }
                                        value = newFields;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }
 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)
         {
             ConnectionItem       ci  = value as ConnectionItem;
             DlgConnectionManager dlg = new DlgConnectionManager();
             dlg.UseProjectScope = true;
             dlg.SetSelection(ci);
             if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
             {
                 if (dlg.SelectedConnection != null)
                 {
                     PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(context.Instance);
                     PropertyDescriptor           p;
                     p = ps["Reserved"];
                     if (p != null)
                     {
                         p.SetValue(context.Instance, Guid.NewGuid().GetHashCode());
                     }
                     p = ps["ConnectionID"];
                     if (p != null)
                     {
                         p.SetValue(context.Instance, new Guid(dlg.SelectedConnection.Filename));
                     }
                     value = dlg.SelectedConnection;
                     if (VPLUtil.CurrentProject != null)
                     {
                         dlg.SelectedConnection.UpdateUsage(VPLUtil.CurrentProject.ProjectFile);
                     }
                     else
                     {
                         dlg.SelectedConnection.UpdateUsage(Application.ExecutablePath);
                     }
                     IDevClassReferencer dcr = context.Instance as IDevClassReferencer;
                     if (dcr == null)
                     {
                         IClassId classPointer = context.Instance as IClassId;
                         if (classPointer != null)
                         {
                             dcr = classPointer.ObjectInstance as IDevClassReferencer;
                         }
                     }
                     if (dcr == null)
                     {
                         ICustomEventMethodType cemt = context.Instance as ICustomEventMethodType;
                         if (cemt != null)
                         {
                             dcr = cemt.ObjectValue as IDevClassReferencer;
                         }
                     }
                     if (dcr == null)
                     {
                         IDevClassReferencerHolder dcrh = context.Instance as IDevClassReferencerHolder;
                         if (dcrh != null)
                         {
                             dcr = dcrh.DevClass;
                         }
                     }
                     if (dcr != null)
                     {
                         IDevClass dc = dcr.GetDevClass();
                         if (dc != null)
                         {
                             dc.NotifyChange(context.Instance, "SqlQuery");
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }