public void LoadColumns(SqlDataConnection connection, params DBTable[] tables)
        {
            foreach (DBTable table in tables)
            {
                if (table.Name == "Categories" && table.Columns.Count == 0)
                {
                    DBColumn categoryIdColumn = new DBColumn {
                        Name = "CategoryID", ColumnType = DBColumnType.Int32
                    };
                    table.AddColumn(categoryIdColumn);
                    DBColumn categoryNameColumn = new DBColumn {
                        Name = "CategoryName", ColumnType = DBColumnType.String
                    };
                    table.AddColumn(categoryNameColumn);
                }
                if (table.Name == "Products" && table.Columns.Count == 0)
                {
                    DBColumn categoryIdColumn = new DBColumn {
                        Name = "CategoryID", ColumnType = DBColumnType.Int32
                    };
                    table.AddColumn(categoryIdColumn);
                    DBColumn productNameColumn = new DBColumn {
                        Name = "ProductName", ColumnType = DBColumnType.String
                    };
                    table.AddColumn(productNameColumn);

                    DBForeignKey foreignKey = new DBForeignKey(
                        new[] { categoryIdColumn },
                        "Categories",
                        CustomDBSchemaProvider.CreatePrimaryKeys("CategoryID"));
                    table.ForeignKeys.Add(foreignKey);
                }
            }
        }
コード例 #2
0
        IEnumerable <DevExpress.DataAccess.Sql.SqlDataConnection> IConnectionStorageService.GetConnections()
        {
            if (!File.Exists(FileName))
            {
                try
                {
                    //Create empty XML file
                    XmlDocument doc  = new XmlDocument();
                    XmlElement  root = doc.CreateElement(xmlRootName);
                    doc.AppendChild(root);
                    doc.Save(FileName);

                    //Add a connection to the XML file:

                    SqlDataConnection defaultConnection = GetConnection(); //GetConnectionsFromXml(); // new CustomSqlDataConnection("Default Connection", new MsSqlConnectionParameters("localhost", "NORTHWIND", "sa", "dx", MsSqlAuthorizationType.SqlServer));
                    SaveConnection(defaultConnection.Name, defaultConnection, true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Cannot create '{0}' file because of exception:{1}{1}{2}", FileName,
                                                  Environment.NewLine, ex.Message));
                    return(null);
                }
            }

            return(IncludeApplicationConnections ?
                   DefaultStorage.GetConnections().Union(GetConnectionsFromXml()) :
                   GetConnectionsFromXml());
        }
コード例 #3
0
        public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList)
        {
            // Check permissions

            var dbTables = connection.GetDBSchema().Tables;

            return(dbTables.Where(t => t.Name == "Categories" || t.Name == "Products").ToArray());
        }
        public void TestNew()
        {
            Filename = Path.GetTempFileName();
            File.Delete(Filename);

            SqlDataConnection.New(Filename);
            Assert.IsTrue(SqlDataConnection.IsOpen());
        }
        public void TestOpen_InvalidFile()
        {
            Filename = Path.GetTempFileName();

            Assert.Throws <FileLoadException>(new TestDelegate(
                                                  delegate
            {
                SqlDataConnection.Open(Filename);
            }));
        }
コード例 #6
0
        public void LoadColumns(SqlDataConnection connection, params DBTable[] tables)
        {
            foreach (DBTable table in tables)
            {
                if (table.Name == "Categories" && table.Columns.Count == 0)
                {
                    DBColumn categoryIdColumn = new DBColumn {
                        Name = "CategoryID"
                    };
                    table.AddColumn(categoryIdColumn);
                    DBColumn categoryNameColumn = new DBColumn {
                        Name = "CategoryName"
                    };
                    table.AddColumn(categoryNameColumn);
                }
                if (table.Name == "Products" && table.Columns.Count == 0)
                {
                    DBColumn categoryIdColumn = new DBColumn {
                        Name = "CategoryID"
                    };
                    table.AddColumn(categoryIdColumn);
                    DBColumn supplierIdColumn = new DBColumn {
                        Name = "SupplierID"
                    };
                    table.AddColumn(supplierIdColumn);
                    DBColumn productNameColumn = new DBColumn {
                        Name = "ProductName"
                    };
                    table.AddColumn(productNameColumn);

                    DBForeignKey foreignKey1 = new DBForeignKey(
                        new[] { categoryIdColumn },
                        "Categories",
                        CustomDBSchemaProvider.CreatePrimaryKeys("CategoryID"));
                    table.ForeignKeys.Add(foreignKey1);
                    DBForeignKey foreignKey2 = new DBForeignKey(
                        new[] { supplierIdColumn },
                        "Suppliers",
                        CustomDBSchemaProvider.CreatePrimaryKeys("SupplierID"));
                    table.ForeignKeys.Add(foreignKey2);
                }
                if (table.Name == "Suppliers" && table.Columns.Count == 0)
                {
                    DBColumn supplierIdColumn = new DBColumn {
                        Name = "SupplierID"
                    };
                    table.AddColumn(supplierIdColumn);
                    DBColumn companyNameColumn = new DBColumn {
                        Name = "CompanyName"
                    };
                    table.AddColumn(companyNameColumn);
                }
            }
        }
コード例 #7
0
        public DBSchema GetSchema(SqlDataConnection connection)
        {
            //Load DB Schema without loading columns
            DBSchema defaultSchema = connection.GetDBSchema(false);

            //Select only required tables/views/procedures
            DBTable[]           tables           = defaultSchema.Tables.Where((table) => { return(!table.Name.StartsWith("Order")); }).ToArray();
            DBTable[]           views            = defaultSchema.Views.ToArray();
            DBStoredProcedure[] storedProcedures = defaultSchema.StoredProcedures.ToArray();
            //Create a new schema
            return(new DBSchema(tables, views, storedProcedures));
        }
コード例 #8
0
        public bool SaveConnection(SqlDataConnection connection)
        {
            try
            {
                XmlDocument doc  = new XmlDocument();
                XmlElement  root = null;
                if (File.Exists(FileName))
                {
                    doc.Load(FileName);
                    root = doc.DocumentElement;
                    if (root != null)
                    {
                        if (root.Name != xmlRootName)
                        {
                            MessageBox.Show(string.Format("Document element is '{0}', '{1}' expected",
                                                          root.Name, xmlRootName));
                            return(false);
                        }
                        if (root.SelectSingleNode(string.Format("Connection[Name = '{0}']", connection.Name)) != null)
                        {
                            return(false);
                        }
                    }
                }
                if (root == null)
                {
                    root = doc.CreateElement(xmlRootName);
                    doc.AppendChild(root);
                }

                XmlElement nameElement = doc.CreateElement("Name");
                nameElement.AppendChild(doc.CreateTextNode(connection.Name));

                XmlElement connectionStringElement = doc.CreateElement("ConnectionString");
                connectionStringElement.AppendChild(doc.CreateTextNode(connection.CreateConnectionString()));

                XmlElement connectionElement = doc.CreateElement("Connection");
                connectionElement.AppendChild(nameElement);
                connectionElement.AppendChild(connectionStringElement);

                root.AppendChild(connectionElement);
                doc.Save(FileName);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Cannot save connection to '{0}' because of exception:{1}{1}{2}", FileName,
                                              Environment.NewLine, ex.Message));
                return(false);
            }
        }
        public void TestBackup()
        {
            Filename = Path.GetTempFileName();
            File.Delete(Filename);

            SqlDataConnection.New(Filename);

            string backup = Path.GetTempFileName();

            Assert.IsTrue(SqlDataConnection.Backup(backup));

            SqlDataConnection.Close();
            Assert.IsFalse(SqlDataConnection.Backup(backup));

            File.Delete(backup);
        }
コード例 #10
0
        public void TestFlush()
        {
            Filename = Path.GetTempFileName();
            File.Delete(Filename);

            SqlDataConnection.New(Filename);

            SqlDataConnection.Flush();
            SqlDataConnection.Flush(true);
            SqlDataConnection.Flush(false);

            SqlDataConnection.DbConnection.Close();
            SqlDataConnection.Flush();
            SqlDataConnection.Flush(true);
            SqlDataConnection.Flush(false);
        }
コード例 #11
0
    public override DBTable[] GetTables(SqlDataConnection connection, params string[] tableList)
    {
        var result = base.GetTables(connection, tableList);

        var userName = contextAccessor.HttpContext.Session.GetString("CurrentUser");

        if (userName == "Admin")
        {
            return(result);
        }
        else if (userName == "User")
        {
            return(result.Where(t => t.Name == "Cars").ToArray());
        }
        else
        {
            return(new DBTable[0]);
        }
    }
コード例 #12
0
        public void TestNew_FileExists()
        {
            Filename = Path.GetTempFileName();

            Assert.Throws <FileLoadException>(new TestDelegate(
                                                  delegate
            {
                SqlDataConnection.New(Filename);
            }));

            File.Delete(Filename);
            SqlDataConnection.New(Filename);

            Assert.Throws <InvalidOperationException>(new TestDelegate(
                                                          delegate
            {
                SqlDataConnection.New(Filename);
            }));
        }
コード例 #13
0
        protected override void CleanupImpl()
        {
            if (SqlDataConnection != null)
            {
                if (SqlDataConnection.IsOpen())
                {
                    SqlDataConnection.Close();
                }

                SqlDataConnection.Dispose();
            }

            SqlDataConnection = null;

            if (!string.IsNullOrEmpty(Filename) && File.Exists(Filename))
            {
                File.Delete(Filename);
            }
        }
コード例 #14
0
        public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList)
        {
            var cp = connection.ConnectionParameters as Access97ConnectionParameters;

            if (cp != null && cp.FileName.Contains("nwind.mdb"))
            {
                if (tables != null)
                {
                    return(tables);
                }

                tables    = new DBTable[3];
                tables[0] = new DBTable("Categories");
                tables[1] = new DBTable("Products");
                tables[2] = new DBTable("Suppliers");
            }
            else
            {
                tables = new DBTable[0];
            }
            return(tables);
        }
        public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList)
        {
            if (connection.Name == "nwindConnection")
            {
                if (tables != null)
                {
                    return(tables);
                }
                tables = new DBTable[2];

                DBTable categoriesTable = new DBTable("Categories");
                tables[0] = categoriesTable;

                DBTable productsTable = new DBTable("Products");
                tables[1] = productsTable;
            }
            else
            {
                tables = new DBTable[0];
            }
            return(tables);
        }
コード例 #16
0
        /// <summary>
        /// Performs the initial tasks before executing a query.
        /// </summary>
        /// <param name="oCmd">Command object holding the query.</param>
        private void InitQuery(SqlCommand oCmd)
        {
            // set Connection
            blnLocalConn = (this.oConn == null);
            if (blnLocalConn)
            {
                oConn        = new SqlDataConnection();
                blnLocalConn = true;
                oConn.Open();
            }
            oCmd.Connection = oConn.oConn;

            // set Command
            oCmd.CommandTimeout = 0;
            oCmd.CommandText    = this.strCommandText;
            oCmd.CommandType    = (this.blnSP ? CommandType.StoredProcedure : CommandType.Text);

            // set Parameters
            foreach (object oItem in this.oParameters)
            {
                //System.Diagnostics.Debug.Print(oItem.ToString() +" : "+ ((SqlParameter)oItem).Value);
                oCmd.Parameters.Add((SqlParameter)oItem);
            }
        }
コード例 #17
0
 public DbContext(SqlDataConnection connection, ILoggerFactory loggerFactory)
 {
     _connection    = connection;
     _loggerFactory = loggerFactory;
 }
コード例 #18
0
 public void LoadColumns(SqlDataConnection connection, params DBTable[] tables)
 {
     provider.LoadColumns(connection, tables);
 }
コード例 #19
0
 public void Test_FlushWneClosed()
 {
     SqlDataConnection.Flush();
     SqlDataConnection.Flush(true);
     SqlDataConnection.Flush(false);
 }
コード例 #20
0
        public DBTable[] GetViews(SqlDataConnection connection, params string[] viewList)
        {
            return(provider.GetViews(connection, viewList)

                   .ToArray());
        }
コード例 #21
0
 public DBStoredProcedure[] GetProcedures(SqlDataConnection connection, params string[] procedureList)
 {
     return(provider.GetProcedures(connection, procedureList)
            .Where(storedProcedure => storedProcedure.Arguments.Count == 0)
            .ToArray());
 }
コード例 #22
0
 public void LoadColumns(SqlDataConnection connection, params DBTable[] tables)
 {
     //Load columns for current tables
     connection.LoadDBColumns(tables);
 }
コード例 #23
0
 public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList)
 {
     return(provider.GetTables(connection, tableList)
            .ToArray());
 }
コード例 #24
0
 public void LoadColumns(SqlDataConnection connection, params DBTable[] tables)
 {
 }
 QueryBuilderRunner CreateQueryBuilderRunner(DBSchema dbSchema, SqlDataConnection sqlDataConnection, QueryBuilderEditQueryContext context)
 {
     return(cbHidePreview.Checked ? new NoPreviewQueryBuilderRunner(dbSchema, sqlDataConnection, context) : new QueryBuilderRunner(dbSchema, sqlDataConnection, context));
 }
コード例 #26
0
 public DBStoredProcedure[] GetProcedures(SqlDataConnection connection, params string[] procedureList)
 {
     return(Array.Empty <DBStoredProcedure>());
 }
コード例 #27
0
 public DBTable[] GetViews(SqlDataConnection connection, params string[] viewList)
 {
     return(Array.Empty <DBTable>());
 }
コード例 #28
0
 public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList)
 {
     return(provider.GetTables(connection, tableList)
            .Where(table => table.Name.Equals("_PersonaJuridica"))
            .ToArray());
 }
コード例 #29
0
 public DBTable[] GetViews(SqlDataConnection connection, params string[] viewList)
 {
     DBTable[] views = new DBTable[0];
     return(views);
 }
コード例 #30
0
 public DBStoredProcedure[] GetProcedures(SqlDataConnection connection, params string[] procedureList)
 {
     DBStoredProcedure[] storedProcedures = new DBStoredProcedure[0];
     return(storedProcedures);
 }