Пример #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("");
        }
Пример #2
0
        public override string CreateHtml(AppObject appobj, ConnectionPack connpack, IDictionary <string, object> outnames)
        {
            HtmlGenerator       gen   = new HtmlGenerator();
            IPhysicalConnection pconn = appobj.FindPhysicalConnection(connpack);
            string dbversion          = null;

            if (pconn != null && pconn.SystemConnection != null)
            {
                try
                {
                    dbversion = pconn.SystemConnection.ServerVersion;
                }
                catch
                {
                    dbversion = null;
                }
            }
            IStoredConnection scon = pconn.StoredConnection;

            gen.BeginHtml(VersionInfo.ProgramTitle, HtmlGenerator.HtmlObjectViewStyle);
            gen.Heading(Texts.Get("s_properties"), 2);
            gen.PropsTableBegin();
            if (scon != null)
            {
                gen.PropTableRow("s_path", scon.FileName);
            }
            var attr = XmlTool.GetRegisterAttr(scon);

            if (attr != null)
            {
                gen.PropTableRow("s_database_engine", attr.Title ?? attr.Name);
            }
            if (scon != null)
            {
                gen.PropTableRow("s_host", scon.GetDataSource());
                gen.PropTableRow("s_database", scon.ExplicitDatabaseName);
                gen.PropTableRow("s_login", scon.GetLogin());
            }
            else
            {
                gen.PropTableRow("s_path", pconn.PhysicalFactory.GetDataSource());
            }
            if (dbversion != null)
            {
                gen.PropTableRow("s_version", dbversion);
            }
            gen.PropsTableEnd();
            gen.EndHtml();
            return(gen.HtmlText);
        }
Пример #3
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));
                });
            }
        }
Пример #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 && objpath != null)
            {
                data = InvokerExtension.InvokeR <DataTable>(conn, (Func <DataTable>) delegate()
                {
                    conn.SystemConnection.SafeChangeDatabase(objpath);
                    return(m_dbtype.LoadOverview(conn.SystemConnection, objpath));
                });
            }
        }
Пример #5
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("");
        }
Пример #6
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());
                        }
                    }
                });
            }
        }
Пример #7
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("");
        }
Пример #8
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("");
        }
Пример #9
0
 public static IPhysicalConnection FindPhysicalConnection(this AppObject appobj)
 {
     return(appobj.FindPhysicalConnection(appobj.ConnPack));
 }