public IEnumerable <Suppliers> GetAll()
        {
            var sqlExpression = "SELECT * FROM Suppliers";

            var connection = new MyDBConnection();

            connection.OpenConnection();

            SqlDataAdapter adapter = new SqlDataAdapter(sqlExpression, connection.Connection);
            var            ds      = new DataSet();

            adapter.Fill(ds);

            connection.CloseConnection();

            var list = new List <Suppliers>();

            foreach (DataRow x in ds.Tables[0].Rows)
            {
                var id   = x.ItemArray[0];
                var name = x.ItemArray[1];

                list.Add(new Suppliers((int)id, (string)name));
            }
            return(list);
        }
        public IEnumerable <Suppliers> GetSuppliersByMaxCategory(ref int counted)    //4 query
        {
            var connection = new MyDBConnection();

            connection.OpenConnection();

            var sqlExpression = "SELECT v.supplier, s.supplierId, counted " +
                                "FROM V5 v " +
                                "JOIN Suppliers s ON v.supplier = s.name " +
                                "ORDER BY counted DESC";

            SqlDataAdapter adapter = new SqlDataAdapter(sqlExpression, connection.Connection);
            var            ds      = new DataSet();

            adapter.Fill(ds);

            connection.CloseConnection();

            counted = Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[1]);
            var list = new List <Suppliers>();

            foreach (DataRow x in ds.Tables[0].Rows)
            {
                if ((int)x.ItemArray[2] != counted)
                {
                    break;
                }
                var id   = x.ItemArray[1];
                var name = x.ItemArray[0];

                list.Add(new Suppliers((int)id, (string)name));
            }
            return(list);
        }
        private void SetupGeneratedStatements()
        {
            // Generate the Insert, Update and Delete statements using mysql DB so that we can test the exact strings.
            var databaseConnection = MyDBConnection.GetDatabaseConfig(DatabaseConfig.MySql).GetDatabaseConnection();

            _insertSql = new InsertStatementGenerator(_filledCircle, databaseConnection).Generate();
            _updateSql = new UpdateStatementGenerator(_filledCircle, databaseConnection).Generate();
            _deleteSql = new DeleteStatementGenerator(_filledCircle, databaseConnection).Generate();
        }
        public override void TestFixtureSetup()
        {
            if (DatabaseConnection.CurrentConnection != null &&
                DatabaseConnection.CurrentConnection.GetType() == typeof(DatabaseConnectionMySql))
            {
                return;
            }
            DatabaseConnection.CurrentConnection =
                new DatabaseConnectionMySql("MySql.Data", "MySql.Data.MySqlClient.MySqlConnection");
            DatabaseConnection.CurrentConnection.ConnectionString =
                MyDBConnection.GetDatabaseConfig().GetConnectionString();
            DatabaseConnection.CurrentConnection.GetConnection();

            BORegistry.DataAccessor = new DataAccessorDB();
        }
Exemplo n.º 5
0
        public static void CreateContactPersonAddressTable(string cpAddressTableName, string cpTableName)
        {
            if (BORegistry.DataAccessor is DataAccessorInMemory)
            {
                return;
            }
            if (BORegistry.DataAccessor is DataAccessorMultiSource)
            {
                return;
            }

            var databaseConfig = MyDBConnection.GetDatabaseConfig();
            var migrator       = new Migrator(databaseConfig);

            migrator.DirectMigrateUp(new Migration_Temp_ContactPersonAddress(cpAddressTableName, cpTableName));
        }
Exemplo n.º 6
0
        public void init()
        {
            _mockBo     = new MockBO();
            _propDefCol = _mockBo.PropDefCol;

            _RelKeyDef = new RelKeyDef();
            IPropDef propDef = _propDefCol["MockBOID"];

            RelPropDef relPropDef = new RelPropDef(propDef, "MockBOProp1");

            _RelKeyDef.Add(relPropDef);

            _multipleRelationshipDef = new MultipleRelationshipDef("Relation1", typeof(MockBO),
                                                                   _RelKeyDef, false, "",
                                                                   DeleteParentAction.DeleteRelated);


            _singleRelationshipDef = new SingleRelationshipDef("Single", typeof(MockBO),
                                                               _RelKeyDef, false,
                                                               DeleteParentAction.DeleteRelated);
            DatabaseConnection.CurrentConnection.ConnectionString = MyDBConnection.GetConnectionString();
        }
        public Suppliers GetById(int id)
        {
            var connection = new MyDBConnection();

            connection.OpenConnection();

            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.SelectCommand = new SqlCommand("SELECT * FROM Suppliers WHERE supplierId = @id",
                                                   connection.Connection);

            var idParam = new SqlParameter("@id", id);

            adapter.SelectCommand.Parameters.Add(idParam);

            var ds = new DataSet();

            adapter.Fill(ds);

            connection.CloseConnection();

            return(new Suppliers(id, (string)ds.Tables[0].Rows[0].ItemArray[1]));
        }
        public Categories GetById(int id)
        {
            var connection = new MyDBConnection();

            connection.OpenConnection();

            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.SelectCommand = new SqlCommand("SELECT * FROM Categories WHERE categoryId = @id",
                                                   connection.Connection);

            var idParam = new SqlParameter("@id", id);

            adapter.SelectCommand.Parameters.Add(idParam);

            var ds = new DataSet();

            adapter.Fill(ds);

            connection.CloseConnection();

            return(new Categories(id, ds.Tables[0].Rows[0].ItemArray[1].ToString()));
        }
Exemplo n.º 9
0
        private static InsertStatementGenerator CreateInsertStatementGenerator(IBusinessObject shape, string databaseVendor)
        {
            var databaseConnection = MyDBConnection.GetDatabaseConfig(databaseVendor).GetDatabaseConnection();

            return(new InsertStatementGenerator(shape, databaseConnection));
        }
        private static UpdateStatementGenerator CreateUpdateStatementGenerator(IBusinessObject businessObject, string databaseVendor)
        {
            var databaseConnection = MyDBConnection.GetDatabaseConfig(databaseVendor).GetDatabaseConnection();

            return(new UpdateStatementGenerator(businessObject, databaseConnection));
        }