Inventory System: Managing data using a database#
Fig. 30 Hand in a filing cabinet.
CC BY-SA 4.0. By Watty62. Source: Wikimedia Commons#
We will introduce databases for data input and output.
What are the business data that we input in/ output from our inventory system?
How is data currently input and output?
What are the advantages & disadvantages of this approach?
Demo#
Order processing with a database in the background. On the top, the tab `Order` shows the order data in the database. These are two orders by customers `Ramanda` and `Totoro`.
The video on the right shows three aspects of using a database:
When we process one order, this is reflected in the database after we refresh
Order.If we restart the program, then the state is preserved in the database
If we change the database data, we can change the data shown by the program
Requirements#
Similar to previous week, build on the previous problem.
Your program must use a database called
inventory.sqlitefor getting the data for queued orders instead of static data through C#.Create the database using the example inventory data from last weeks.
If you used a
DictforStock, then change it to aListofItems and introduce aQuantityinIteminstead.The database framework we will use cannot navigate through dictionaries but lists.
Modify your class diagram if needed.
Record a demonstration of your project similar to the video on the right.
Tips#
Read the database as the first step in
MainWindow(). Otherwise orders may end up not being initialized which leads to empty list on the GUIWhen reading the database, use
.Include().ThenIncludestatements to load aggregated classes. For exampleOrderBookneeds to includeQueuedOrders, which in turn needs to includeOrderLinesand finallyOrderLinesneeds to includeItemlike this:
public void ReadDatabase()
{
OrderBook = Db.OrderBooks
.Include(o => o.QueuedOrders)
.ThenInclude(o => o.OrderLines)
.ThenInclude(o => o.Item)
.Include(o => o.ProcessedOrders)
.ThenInclude(o => o.OrderLines)
.ThenInclude(o => o.Item)
.ToList()[0];
}
Write to the database after processing each order.