public static void ShowTablesData(String schemaName) { DbController dbc = null; if (String.IsNullOrEmpty(schemaName)) { dbc = new DbController(DbHelper.OpenNewConnection()); } else { dbc = new DbController(DbHelper.OpenNewConnection(), schemaName); } IList <Address> addresses = dbc.GetAddresses(); foreach (Address addr in addresses) { GFXDTestRunner.OnTestEvent(new TestEventArgs("Address: " + addr.ToString())); } IList <Supplier> suppliers = dbc.GetSuppliers(); foreach (Supplier supp in suppliers) { GFXDTestRunner.OnTestEvent(new TestEventArgs("Supplier: " + supp.ToString())); } IList <Category> categories = dbc.GetCategories(); foreach (Category cat in categories) { GFXDTestRunner.OnTestEvent(new TestEventArgs("Category: " + cat.ToString())); } IList <Product> products = dbc.GetProducts(); foreach (Product prod in products) { GFXDTestRunner.OnTestEvent(new TestEventArgs("Product: " + prod.ToString())); } IList <Customer> customers = dbc.GetCustomers(); foreach (Customer cust in customers) { GFXDTestRunner.OnTestEvent(new TestEventArgs("Customer: " + cust.ToString())); } IList <Order> orders = dbc.GetOrders(); foreach (Order ord in orders) { GFXDTestRunner.OnTestEvent(new TestEventArgs("Order: " + ord.ToString())); } IList <OrderDetail> ordDetails = dbc.GetOrderDetails(); foreach (OrderDetail ordDetail in ordDetails) { GFXDTestRunner.OnTestEvent(new TestEventArgs("OrderDetail: " + ordDetail.ToString())); } }
public static void ShowTablesData(String schemaName) { DbController dbc = null; if (String.IsNullOrEmpty(schemaName)) dbc = new DbController(DbHelper.OpenNewConnection()); else dbc = new DbController(DbHelper.OpenNewConnection(), schemaName); IList<Address> addresses = dbc.GetAddresses(); foreach (Address addr in addresses) GFXDTestRunner.OnTestEvent(new TestEventArgs("Address: " + addr.ToString())); IList<Supplier> suppliers = dbc.GetSuppliers(); foreach (Supplier supp in suppliers) GFXDTestRunner.OnTestEvent(new TestEventArgs("Supplier: " + supp.ToString())); IList<Category> categories = dbc.GetCategories(); foreach (Category cat in categories) GFXDTestRunner.OnTestEvent(new TestEventArgs("Category: " + cat.ToString())); IList<Product> products = dbc.GetProducts(); foreach (Product prod in products) GFXDTestRunner.OnTestEvent(new TestEventArgs("Product: " + prod.ToString())); IList<Customer> customers = dbc.GetCustomers(); foreach (Customer cust in customers) GFXDTestRunner.OnTestEvent(new TestEventArgs("Customer: " + cust.ToString())); IList<Order> orders = dbc.GetOrders(); foreach (Order ord in orders) GFXDTestRunner.OnTestEvent(new TestEventArgs("Order: " + ord.ToString())); IList<OrderDetail> ordDetails = dbc.GetOrderDetails(); foreach (OrderDetail ordDetail in ordDetails) GFXDTestRunner.OnTestEvent(new TestEventArgs("OrderDetail: " + ordDetail.ToString())); }
private static void PopulateTables(String schemaName) { DbController dbc = null; if (String.IsNullOrEmpty(schemaName)) { dbc = new DbController(DbHelper.OpenNewConnection()); } else { dbc = new DbController(DbHelper.OpenNewConnection(), schemaName); } IList <Product> prodList = new List <Product>(); long startAddressId = addressPKeySeed; long startSupplierId = supplierPKeySeed; long startCategoryId = categoryPKSeed; long startProductId = productPKSeed; long startCustomerId = customerPKSeed; long startOrderId = orderPKSeed; for (int i = 0; i < numSuppliers; i++) { Address address = (Address)ObjectFactory.Create(ObjectType.Address); address.AddressId = startAddressId++; dbc.AddAddress(address); Supplier supplier = (Supplier)ObjectFactory.Create(ObjectType.Supplier); supplier.SupplierId = startSupplierId++; supplier.Address = address; dbc.AddSupplier(supplier); for (int j = 0; j < numCategoriesPerSupplier; j++) { Category category = (Category)ObjectFactory.Create(ObjectType.Category); category.CategoryId = startCategoryId++; dbc.AddCategory(category); for (int k = 0; k < numProductsPerCategory; k++) { Product product = (Product)ObjectFactory.Create(ObjectType.Product); product.ProductId = startProductId++; product.Category = category; product.Supplier = supplier; dbc.AddProduct(product); // to be referenced by OrderDetail prodList.Add(product); } } } int prodCount = 0; for (int i = 0; i < numCustomers; i++) { Address address = (Address)ObjectFactory.Create(ObjectType.Address); address.AddressId = startAddressId++; dbc.AddAddress(address); Customer customer = (Customer)ObjectFactory.Create(ObjectType.Customer); customer.CustomerId = startCustomerId++; customer.Address = address; dbc.AddCustomer(customer); for (int j = 0; j < numOrdersPerCustomer; j++) { Order order = (Order)ObjectFactory.Create(ObjectType.Order); order.OrderId = startOrderId++; order.Customer = customer; dbc.AddOrder(order); for (int k = 0; k < numOrderDetailsPerOrder; k++) { OrderDetail ordDetail = (OrderDetail)ObjectFactory.Create(ObjectType.OrderDetail); ordDetail.OrderId = order.OrderId; ordDetail.ProductId = prodList[prodCount].ProductId; ordDetail.UnitPrice = prodList[prodCount++].RetailPrice; dbc.AddOrderDetail(ordDetail); if (prodCount == prodList.Count) { prodCount = 0; } } } } //ShowTablesData(schemaName); }
private static void PopulateTables(String schemaName) { DbController dbc = null; if (String.IsNullOrEmpty(schemaName)) dbc = new DbController(DbHelper.OpenNewConnection()); else dbc = new DbController(DbHelper.OpenNewConnection(), schemaName); IList<Product> prodList = new List<Product>(); long startAddressId = addressPKeySeed; long startSupplierId = supplierPKeySeed; long startCategoryId = categoryPKSeed; long startProductId = productPKSeed; long startCustomerId = customerPKSeed; long startOrderId = orderPKSeed; for (int i = 0; i < numSuppliers; i++) { Address address = (Address)ObjectFactory.Create(ObjectType.Address); address.AddressId = startAddressId++; dbc.AddAddress(address); Supplier supplier = (Supplier)ObjectFactory.Create(ObjectType.Supplier); supplier.SupplierId = startSupplierId++; supplier.Address = address; dbc.AddSupplier(supplier); for (int j = 0; j < numCategoriesPerSupplier; j++) { Category category = (Category)ObjectFactory.Create(ObjectType.Category); category.CategoryId = startCategoryId++; dbc.AddCategory(category); for (int k = 0; k < numProductsPerCategory; k++) { Product product = (Product)ObjectFactory.Create(ObjectType.Product); product.ProductId = startProductId++; product.Category = category; product.Supplier = supplier; dbc.AddProduct(product); // to be referenced by OrderDetail prodList.Add(product); } } } int prodCount = 0; for (int i = 0; i < numCustomers; i++) { Address address = (Address)ObjectFactory.Create(ObjectType.Address); address.AddressId = startAddressId++; dbc.AddAddress(address); Customer customer = (Customer)ObjectFactory.Create(ObjectType.Customer); customer.CustomerId = startCustomerId++; customer.Address = address; dbc.AddCustomer(customer); for (int j = 0; j < numOrdersPerCustomer; j++) { Order order = (Order)ObjectFactory.Create(ObjectType.Order); order.OrderId = startOrderId++; order.Customer = customer; dbc.AddOrder(order); for (int k = 0; k < numOrderDetailsPerOrder; k++) { OrderDetail ordDetail = (OrderDetail)ObjectFactory.Create(ObjectType.OrderDetail); ordDetail.OrderId = order.OrderId; ordDetail.ProductId = prodList[prodCount].ProductId; ordDetail.UnitPrice = prodList[prodCount++].RetailPrice; dbc.AddOrderDetail(ordDetail); if (prodCount == prodList.Count) prodCount = 0; } } } //ShowTablesData(schemaName); }