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);
 }
        public List <InterfaceElementProperty> GetProperties()
        {
            ClassPointer cp = this.ClassTypePointer;

            if (cp != null)
            {
                if (!cp.IsInterface)
                {
                    throw new DesignerException("Invalid interface pointer. Class Id:{0}", cp.ClassId);
                }
                if (cp.ObjectInstance == null)
                {
                    throw new DesignerException("Interface object not loaded. Class Id:{0}", cp.ClassId);
                }
                InterfaceClass ifc = VPLUtil.GetObject(cp.ObjectInstance) as InterfaceClass;
                if (ifc == null)
                {
                    throw new DesignerException("Invalid interface pointer. object:{0}", cp.ObjectInstance);
                }
                return(ifc.Properties);
            }
            else
            {
                Type t = this.VariableLibType;
                if (t == null)
                {
                    throw new DesignerException("Invalid interface pointer. VariableLibType is null.");
                }
                if (t.IsInterface)
                {
                    List <InterfaceElementProperty> ls = new List <InterfaceElementProperty>();
                    PropertyInfo[] mifs = VPLUtil.GetProperties(t);
                    if (mifs != null && mifs.Length > 0)
                    {
                        for (int i = 0; i < mifs.Length; i++)
                        {
                            if (!mifs[i].IsSpecialName)
                            {
                                InterfaceElementProperty em = new InterfaceElementProperty(this, mifs[i]);
                                ls.Add(em);
                            }
                        }
                    }
                    return(ls);
                }
                else
                {
                    throw new DesignerException("Invalid interface pointer. Type is not an interface:{0}.", t);
                }
            }
        }
Exemplo n.º 3
0
 public ClassProperties(ClassInstancePointer owner)
 {
     _pointer = owner;
     _owner   = VPLUtil.GetObject(owner.ObjectInstance);
 }
        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);
        }