Sample program
This reference is accompanied by a sample program (download source). This part describes a complete plan of what this program should do.
The program is an order taking management system for a small restaurant. In order to keep things simple, only one table is used. We also assume there is one database hand-held in the device.
The program we describe below has been widely simplified in order to keep the example as limited to the goals as possible. The word simplicity indicates places in which we have considerably exceeded realistic design, or otherwise a note under the title "simplicity considerations".
Scenario and Analysis
The restaurant with which we deal is a small one containing 6 tables.
It is a fast-food, family-owned place, in which one waiter is working.
There is also one cook, making the dishes.
There are 4 optional items to choose from: a hamburger, french-fries, Coke and mineral water.
Each table has 4 seats next to it.
Work flows as follows:
Waiter takes the order from the customers. He indicates into his Pocket PC what each one has ordered.
When done, the waiter goes to the kitchen and tells the cook what was ordered. He tells the cook what was the table number. simplicity at least we could have print the order. We will skip this now.
Cook makes the dishes and places them on the bar, with a note indicating table number.
The waiter in turn serves them to the customers, and indicates in the database this order was served.
simplicity Note: of course, stage 2 here is a bit awkward. It is much preferred to have data automatically synchronized with a central server and have the cook watching a screen hang on the wall indicating exactly which order should now be cooked, with its number. As this involves synchronizing between two copies of the database, it exceeds this reference's scope. Same is true about the diversity of choises: we have simplified it a lot and limited ourselves to 4 items, without duplications, so that we will not have to use more than one database table.
Yet this simple example is pretty realistic. Such a restaurant, serving a very limited choice of dishes yet is crowded can be seen here. Note especially this photo, where the waitress' hand-held device is clearly shown.
Program Design
Datebase:
One database will be used and called Rest.
One table will be used, and called t_orders ("t_" stands for table).
t_orders will contain the following fields:
ID (integer) - each record has a unique ID. This will be the table's primary key.
Sum (decimal numer) - the total sum of this order. simplicity: Currently this is calculated manually.
TableNum (integer) - table number (1 to 6). simplicity: we will not check validation of input here.
SeatNum (integer) - the seat number next to the table. simplicity: no validation checks here either.
Hamburger (boolean) - did this customer order a hamburger.
French (boolean) - did this customer order french fries.
Coke (boolean) - did this customer order a Coke.
Water (boolean) - did this customer order mineral water.
isServed (boolean) - is this order served yet? the waiter a box when serving the order.
Time - time this order was accepted.
Note:
Since SQLite does not contain boolean nor date/time data types, all boolean data will be kept as integer, where 0 indicates False and 1 indicates True. Time will be kept as text.
This program is about to be built using the multitier architecture. It will contain a business logic layer that will implement the following methods:
Get all data of a single order with a given ID.
Add an order to the order list.
Update an order with a given ID in the order list.
Delete an order with a given ID from the list.
Return a list of all orders containing given values in the TableNum or the isServed field.
User Interface (UI)
Order details: a form containing all order data. This form contains Save, Cancel and Delete buttons.
Orders list: a list of orders, filtered as described in the filtering form. The list contains an option to show Order details form for each order.
Filtering form: the place to indicate which orders should be displayed in the orders list. Contains a "Go" buttons which displays the list. Possible filters are:
Table number
Served/Not served
Date served
Main menu: containing the buttons:
New order
Orders list
Source code
Each part of the source code is thoroughly explained in the relevant part. The complete code is here
Next page - Step 1 - adding SQL support to your application