Exemplo n.º 1
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)
         {
             EasyUpdator eu = context.Instance as EasyUpdator;
             if (eu == null)
             {
                 object   pointer;
                 IClassId ic = context.Instance as IClassId;
                 if (ic != null)
                 {
                     pointer = ic.ObjectInstance;
                 }
                 else
                 {
                     pointer = context.Instance;
                 }
                 if (pointer != null)
                 {
                     eu = VPLUtil.GetObject(pointer) as EasyUpdator;
                 }
             }
             if (eu != null)
             {
                 SQLNoneQuery sq = value as SQLNoneQuery;
                 if (sq == null)
                 {
                     sq = new SQLNoneQuery();
                 }
                 sq.SetConnection(eu.DatabaseConnection);
                 bool bOK = eu.DatabaseConnection.ConnectionObject.IsConnectionReady;
                 if (!bOK)
                 {
                     DlgConnectionManager dlgC = new DlgConnectionManager();
                     dlgC.UseProjectScope = true;
                     if (edSvc.ShowDialog(dlgC) == System.Windows.Forms.DialogResult.OK)
                     {
                         eu.DatabaseConnection = dlgC.SelectedConnection;
                         sq.SetConnection(dlgC.SelectedConnection);
                         bOK = true;
                     }
                 }
                 if (bOK)
                 {
                     dlgPropSQLNonQuery dlg = new dlgPropSQLNonQuery();
                     dlg.LoadData(sq);
                     if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                     {
                         value = dlg.objRet;
                     }
                 }
             }
         }
     }
     return(value);
 }
Exemplo n.º 2
0
 private void toolStripButtonSelect_Click(object sender, EventArgs e)
 {
     if (_dlgUsage != enumDlgUsage.All)
     {
         DlgConnectionManager dlg = new DlgConnectionManager();
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             if (dlg.SelectedConnection != null)
             {
                 bool bFound = false;
                 foreach (ConnectionItem ci in _connectionList)
                 {
                     if (ci != null && ci.ConnectionGuid == dlg.SelectedConnection.ConnectionGuid)
                     {
                         bFound = true;
                     }
                 }
                 if (!bFound)
                 {
                     _connectionList.Add(dlg.SelectedConnection);
                 }
                 bFound = false;
                 for (int i = 0; i < treeView1.Nodes.Count; i++)
                 {
                     TreeNodeConnectionItem tn = treeView1.Nodes[i] as TreeNodeConnectionItem;
                     if (tn != null)
                     {
                         if (tn.OwnerItem.ConnectionGuid == dlg.SelectedConnection.ConnectionGuid)
                         {
                             bFound = true;
                             treeView1.SelectedNode = tn;
                             break;
                         }
                     }
                 }
                 if (!bFound)
                 {
                     TreeNodeConnectionItem tnc = new TreeNodeConnectionItem(dlg.SelectedConnection);
                     treeView1.Nodes.Add(tnc);
                     treeView1.SelectedNode = tnc;
                 }
             }
         }
     }
 }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
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)
         {
             EasyQuery qry = value as EasyQuery;
             if (qry == null)
             {
                 qry = new EasyQuery();
             }
             bool bOK = qry.IsConnectionReady;
             if (!bOK)
             {
                 DlgConnectionManager dlgC = new DlgConnectionManager();
                 if (edSvc.ShowDialog(dlgC) == System.Windows.Forms.DialogResult.OK)
                 {
                     qry.DatabaseConnection = dlgC.SelectedConnection;
                     bOK = true;
                 }
             }
             if (bOK)
             {
                 dlgQueryBuilder dlg = new dlgQueryBuilder();
                 QueryParser     qp  = new QueryParser();
                 qp.LoadData(qry);
                 dlg.LoadData(qp);
                 if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                 {
                     qp.checkQueryreadOnly(qp.query);
                     value = qp.query;
                 }
             }
         }
     }
     return(value);
 }
Exemplo n.º 5
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);
 }
        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)
                {
                    IQuery qry = context.Instance as IQuery;
                    if (qry == null)
                    {
                        IClassId classPointer = context.Instance as IClassId;
                        if (classPointer != null)
                        {
                            qry = VPLUtil.GetObject(classPointer.ObjectInstance) as IQuery;
                        }
                    }
                    if (qry == null)
                    {
                        ICustomEventMethodType cemt = context.Instance as ICustomEventMethodType;
                        if (cemt != null)
                        {
                            qry = cemt.ObjectValue as IQuery;
                        }
                    }
                    if (qry != null)
                    {
                        IDatabaseAccess da = qry as IDatabaseAccess;
                        if (da != null)
                        {
                            if (da.OnBeforeSetSQL())
                            {
                                if (context.PropertyDescriptor != null)
                                {
                                    da.SetSqlContext(context.PropertyDescriptor.Name);
                                }
                            }
                            else
                            {
                                return(value);
                            }
                        }
                        bool bOK = qry.IsConnectionReady;
                        if (!bOK)
                        {
                            DlgConnectionManager dlgC = new DlgConnectionManager();
                            dlgC.UseProjectScope = true;
                            if (edSvc.ShowDialog(dlgC) == System.Windows.Forms.DialogResult.OK)
                            {
                                qry.DatabaseConnection = dlgC.SelectedConnection;
                                bOK = true;
                            }
                        }
                        if (bOK)
                        {
                            if (qry.IsConnectionReady)
                            {
                                dlgQueryBuilder dlg = new dlgQueryBuilder();
                                QueryParser     qp  = new QueryParser();
                                qp.LoadData(qry.QueryDef);
                                dlg.LoadData(qp);
                                if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                                {
                                    IDevClassReferencer dcr = qry as IDevClassReferencer;
                                    if (dcr != null)
                                    {
                                        IDevClass dc = dcr.GetDevClass();
                                        if (dc != null)
                                        {
                                            dc.NotifyBeforeChange(context.Instance, "SqlQuery");
                                        }
                                    }
                                    qp.checkQueryreadOnly(qp.query);
                                    qry.CopyFrom(qp.query);
                                    if (da != null && !(da is EasyGrid))
                                    {
                                        da.Query();                                        //make the query and get SQL
                                    }
                                    value = qp.query.SQL.Clone();                          //qry.SQL.Clone();

                                    if (context.PropertyDescriptor.IsReadOnly)
                                    {
                                        IDatabaseAccess eq = qry as IDatabaseAccess;
                                        if (eq != null)
                                        {
                                            if (eq.NeedDesignTimeSQL)
                                            {
                                                eq.SQL = (SQLStatement)value;
                                            }
                                            else
                                            {
                                                PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(qry);
                                                ISqlUser eds = qry as ISqlUser;
                                                if (eds != null)
                                                {
                                                }
                                                else
                                                {
                                                    //SQL property is read-only and will not get designer notified
                                                    //For EasyGrid it will cause other properties changes.
                                                    eq.SQL = (SQLStatement)value;
                                                }
                                            }
                                        }

                                        if (dcr != null)
                                        {
                                            IDevClass dc = dcr.GetDevClass();
                                            if (dc != null)
                                            {
                                                dc.NotifyChange(context.Instance, "SqlQuery");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }