Esempio n. 1
0
        public override string CreateText(AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IDatabaseSource     db      = appobj.FindDatabaseConnection(connpack);
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            if (conn != null && objpath != null && conn.SystemConnection != null)
            {
                string text = conn.InvokeR <string>((Func <string>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    string sql = GetSelect(objpath);
                    using (var cmd = conn.SystemConnection.CreateCommand())
                    {
                        cmd.CommandText = sql;
                        using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                        {
                            if (reader.Read())
                            {
                                return(reader[m_colnumber].SafeToString());
                            }
                        }
                    }
                    return("");
                });
                return(text);
            }
            return("");
        }
Esempio n. 2
0
        public override void GetObjectList(List <AppObject> objs, AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath objpath = appobj.GetObjectPath();
            var        tsrc    = appobj.TableSource;

            //IDatabaseSource conn = appobj.FindDatabaseConnection(connpack);
            if (tsrc == null)
            {
                return;
            }
            if (!tsrc.Connection.IsOpened)
            {
                return;
            }
            var ts = tsrc.InvokeLoadStructure(TableStructureMembers.Columns | TableStructureMembers.PrimaryKey | TableStructureMembers.ForeignKeys);

            foreach (var col in ts.Columns)
            {
                var cobj = new ColumnAppObject();
                cobj.Column = new ColumnStructure(col);
                cobj.FillFromTable(tsrc);
                cobj.FillRelatedConstraints(ts.Constraints);
                objs.Add(cobj);
            }
        }
Esempio n. 3
0
        public override void GetObjectList(List <AppObject> objs, AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath      objpath = appobj.GetObjectPath();
            IDatabaseSource conn    = appobj.FindDatabaseConnection(connpack);

            if (conn != null && conn.Connection.IsOpened)
            {
                var dbmem = new DatabaseStructureMembers();
                dbmem.IgnoreSystemObjects = true;
                if (_Type.ObjectType == "table")
                {
                    dbmem.TableList = true;
                }
                else
                {
                    var smem = new SpecificObjectMembers {
                        ObjectList = true
                    };
                    dbmem.SpecificObjectOverride[_Type.ObjectType] = smem;
                }
                var dbs = conn.InvokeLoadStructure(dbmem, null);
                if (_Type.ObjectType == "table")
                {
                    foreach (var tbl in dbs.Tables)
                    {
                        var o = new TableAppObject();
                        o.FillFromDatabase(conn);
                        o.DbObjectName = tbl.FullName;
                        objs.Add(o);
                    }
                }
                else
                {
                    if (dbs.SpecificObjects.ContainsKey(_Type.ObjectType))
                    {
                        foreach (var spec in dbs.SpecificObjects[_Type.ObjectType])
                        {
                            var o = new SpecificObjectAppObject();
                            o.FillFromDatabase(conn);
                            o.DbObjectName = spec.ObjectName;
                            o.DbObjectType = _Type.ObjectType;
                            objs.Add(o);
                        }
                    }
                }
            }
            objs.SortByKey(o => o.ToString());
        }
Esempio n. 4
0
        public override void GetData(AppObject appobj, ConnectionPack connpack, out System.Data.DataTable data, out DatAdmin.Scripting.ObjectGrid grid)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            data = null;
            grid = null;
            if (conn != null && conn.IsOpened && conn.SystemConnection != null)
            {
                data = conn.InvokeR <DataTable>((Func <DataTable>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    return(LoadSchema(conn.SystemConnection, objpath));
                });
            }
        }
Esempio n. 5
0
        public override void GetData(AppObject appobj, ConnectionPack connpack, out System.Data.DataTable data, out DatAdmin.Scripting.ObjectGrid grid)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            data = null;
            grid = null;
            if (conn != null && objpath != null)
            {
                data = InvokerExtension.InvokeR <DataTable>(conn, (Func <DataTable>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    return(m_dbtype.LoadOverview(conn.SystemConnection, objpath));
                });
            }
        }
Esempio n. 6
0
        public override void GetObjectList(List <AppObject> objs, AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath      objpath = appobj.GetObjectPath();
            IDatabaseSource conn    = appobj.FindDatabaseConnection(connpack);

            if (conn != null && conn.Connection.IsOpened)
            {
                var ts = conn.InvokeLoadTableStructure(objpath.ObjectName, TableStructureMembers.ConstraintsNoRefs);
                foreach (var cnt in ts.Constraints)
                {
                    var cobj = new ConstraintAppObject();
                    cobj.Constraint = Constraint.CreateCopy(cnt);
                    cobj.FillFromTable(conn.GetTable(objpath.ObjectName));
                    objs.Add(cobj);
                }
            }
            objs.SortByKey(o => o.ToString());
        }
Esempio n. 7
0
        public override void CreateNew(AppObject appobj, ConnectionPack connpack)
        {
            var tp = _Type;

            if (tp.ObjectType == "table")
            {
                var pars = new AlterTableEditorPars {
                    SavedCallback = RefreshList
                };
                MainWindow.Instance.OpenContent(new TableEditFrame(appobj.CreateDatabaseConnection(), null, pars));
            }
            else
            {
                var dbconn = appobj.FindDatabaseConnection(connpack);
                var dbtype = dbconn.Dialect.GetSpecificObjectType(tp.ObjectType);
                if (dbconn.DatabaseCaps.ExecuteSql)
                {
                    OpenQueryParameters pars    = new OpenQueryParameters();
                    IPhysicalConnection newconn = dbconn.Connection.Clone();
                    string dbname = appobj.FindDatabaseName();
                    if (dbname != null)
                    {
                        newconn.AfterOpen += ConnTools.ChangeDatabaseCallback(dbname);
                    }
                    pars.GenerateSql = delegate(IPhysicalConnection conn)
                    {
                        return(dbtype.GenerateCreateNew(conn.SystemConnection, appobj.GetObjectPath()));
                    };
                    pars.HideDesign       = true;
                    pars.ExecutedCallback = RefreshList;
                    MainWindow.Instance.OpenContent(new QueryFrame(newconn, pars));
                }
                else
                {
                    string sql  = dbtype.GenerateCreateNew(dbconn.Connection.SystemConnection, appobj.GetObjectPath());
                    var    pars = new ObjectEditorPars {
                        SavedCallback = RefreshList
                    };
                    var frm = new SpecificObjectFrame(dbconn, tp.ObjectType, sql, pars);
                    MainWindow.Instance.OpenContent(frm);
                }
            }
        }
Esempio n. 8
0
        public override string CreateText(AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IDatabaseSource     db      = appobj.FindDatabaseConnection(connpack);
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);
            var sobj = appobj as SpecificObjectAppObject;

            if (conn != null && objpath != null)
            {
                string text = conn.InvokeR <string>((Func <string>) delegate()
                {
                    ISpecificObjectStructure so = db.LoadSpecificObjectDetail(sobj.DbObjectType, objpath.ObjectName);
                    return(conn.Dialect.GenerateScript(dmp => { dmp.CreateSpecificObject(so); }, AppObjectSqlGeneratorBase.TemplateFormatProps));
                });
                if (conn.Dialect != null)
                {
                    text = conn.Dialect.ReformatSpecificObject(sobj.DbObjectType, text);
                }
                return(text);
            }
            return("");
        }
Esempio n. 9
0
        public override void GetData(AppObject appobj, ConnectionPack connpack, out System.Data.DataTable data, out DatAdmin.Scripting.ObjectGrid grid)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            data = null;
            grid = null;
            if (conn != null && conn.IsOpened)
            {
                data = conn.InvokeR <DataTable>((Func <DataTable>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    using (DbCommand cmd = conn.SystemConnection.CreateCommand())
                    {
                        cmd.CommandText = GetSelect(objpath);
                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            return(reader.ToDataTable());
                        }
                    }
                });
            }
        }
Esempio n. 10
0
        public override string CreateText(AppObject appobj, ConnectionPack connpack)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IDatabaseSource     db      = appobj.FindDatabaseConnection(connpack);
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);
            ITableSource        tbl     = appobj.FindTableConnection(connpack);

            if (conn != null && objpath != null)
            {
                string text = conn.InvokeR <string>((Func <string>) delegate()
                {
                    if (conn.SystemConnection != null)
                    {
                        conn.SystemConnection.SafeChangeDatabase(objpath);
                    }
                    var sw  = new StringWriter();
                    var gen = new GenSql_CreateTable();
                    gen.GenerateCreateTable(tbl, sw, conn.GetAnyDialect());
                    return(sw.ToString());
                });
                return(text);
            }
            return("");
        }
Esempio n. 11
0
        public override string CreateHtml(AppObject appobj, ConnectionPack connpack, IDictionary <string, object> outnames)
        {
            ObjectPath          objpath = appobj.GetObjectPath();
            IPhysicalConnection conn    = appobj.FindPhysicalConnection(connpack);

            if (conn != null && conn.IsOpened)
            {
                return(conn.InvokeR <string>((Func <string>) delegate()
                {
                    string rowcount = "???", colcount = "???";
                    if (conn.SystemConnection != null)
                    {
                        var dbcache = conn.Cache.Database(appobj.GetObjectPath().DbName);

                        var dialect = conn.GetAnyDialect();

                        bool dbset = false;
                        rowcount = (string)dbcache.Get("htmlinfowidget_rows", objpath.ObjectName.ToString());
                        if (rowcount == null)
                        {
                            if (!dbset)
                            {
                                conn.SystemConnection.SafeChangeDatabase(objpath);
                                dbset = true;
                            }

                            rowcount = conn.SystemConnection.ExecuteScalar("SELECT COUNT(*) FROM " + dialect.QuoteFullName(objpath.ObjectName)).ToString();
                            try
                            {
                                int ival = Int32.Parse(rowcount);
                                rowcount = ival.FormatInt();
                            }
                            catch { }
                            dbcache.Put("htmlinfowidget_rows", objpath.ObjectName.ToString(), rowcount);
                        }

                        colcount = (string)dbcache.Get("htmlinfowidget_cols", objpath.ObjectName.ToString());
                        if (colcount == null)
                        {
                            if (!dbset)
                            {
                                conn.SystemConnection.SafeChangeDatabase(objpath);
                                dbset = true;
                            }
                            using (var cmd = conn.SystemConnection.CreateCommand())
                            {
                                cmd.CommandText = "SELECT * FROM " + dialect.QuoteFullName(objpath.ObjectName);
                                using (var reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly))
                                {
                                    colcount = reader.GetSchemaTable().Rows.Count.ToString();
                                }
                                dbcache.Put("htmlinfowidget_cols", objpath.ObjectName.ToString(), colcount);
                            }
                        }
                    }
                    else
                    {
                        var db = appobj.FindDatabaseConnection(connpack);
                        if (db != null)
                        {
                            var ts = db.InvokeLoadTableStructure(objpath.ObjectName, TableStructureMembers.ColumnNames);
                            colcount = ts.Columns.Count.ToString();
                        }
                        //var tbl = appobj.FindTableConnection(connpack);
                        //if (tbl != null)
                        //{
                        //    var tabdata = tbl.GetTabularData();
                        //    if (tabdata != null)
                        //    {
                        //        int? rcnt = tabdata.LoadRowCount(new TableDataSetProperties());
                        //        if (rcnt != null) rowcount = rcnt.ToString();
                        //    }
                        //}
                    }

                    HtmlGenerator gen = new HtmlGenerator();
                    gen.BeginHtml(objpath.ObjectName.ToString(), HtmlGenerator.HtmlObjectViewStyle);
                    if (ShowTableName)
                    {
                        gen.Heading(objpath.ObjectName.ToString(), 2);
                    }
                    gen.PropsTableBegin();
                    gen.PropTableRow("s_row_count", rowcount);
                    gen.PropTableRow("s_column_count", colcount);
                    gen.PropsTableEnd();
                    return gen.HtmlText;
                }));
            }
            return("");
        }