I took on the issue that dealt with storing information on equipment. Looking at the ERD, there are three tables that relate to this.
- Equipmennt. This table stores information on each piece of equipment.
- Equipment_Type. This table stores a list of equipment categories
- Equipment_Allocation. This table stores information on where and when equipment is allocated
My code base followed the following code architecture. This was decided by the group after undertaking the ToDoList example.
- Database class for CRUD operations was added to the Data folder
- The table structures were added to the models folder
- The views and their underlying code were added to the Views folder.
The table structures were added to the models architucture. The example below (fig 1) is for the Equipment Allocation table. The knowledge gained from last week was applied in the method of adding a foreign key. Furthermore, I learnt that SQLite does not use the DATE data structure, ratht that the dates are stored in strings.
fig 1 (Equipment Table model)
A seperate database class was created to store the CRUD functions for the Equipment related tables. In figure 2, the InitiateDataBase method creates a new local database if it does not already exists
fig 2 (Initiate Database and tables)
The code below shows 2 CRUD methods in the database class. They have comments placed on top to add Doxygen documents, have single responsbility and short. Improvments would include changing the name strings in line 80 to something more meaningfull, such as names_returned. The SQL statement for the GetEquipment method is vulnerable to SQL injection attacks as the serach query is embedded in the statement. Given the scope of this project, it was decided not to add protection this week. However, this is something I will learn and implement in future projects.
There are three seperate views for the graphical interface which was added to the view model. A equipment UI was created with three buttons: add equipment type, add equipment and allocate equipment.
Error capturing was added to the Add Equipment Page. Fig 3 shows an error message when data fields are null prior to saving. Fig 4 shows the code that validates user input by checking if the editor boxes is null. If so, it returns false.
Fig 4 shows how the error capture is handled if the validation is false, by the use of a condition. If it is false, a error message will apear as in fig 3, otherwise it will save the record
fig 3(Error capturing)
fig 4(Validate user input method)
fig 5(Error capture handling in AddEquipment method)
I undertook the code view (fig 6). Whilst most of the code was clean, it did lack comments and some lines of code was commented out. I provided this in a feedback (fig 7) and requested for changes.
fig 6 (Code Review Example)
fig 7(Review feedback)
Documentation was undertaken using Doxygen and added to the Document folder in the repo. Fig 7 is an example
My Project
|
static async Task | InitiateDataBase () |
Check if local database exists. Creates new one with table if it does not exist. | |
static async Task< int > | GetEquipmentTypeForeignKey (string eType) |
Gets equipment type id number. | |
static async Task | ListEquipment (Equipment eq) |
Add Equipment to database. | |
static async Task | AddEquipment (Equipment eq) |
Add Equipment to database. | |
static async Task< string[]> | GetEquipmentType () |
Return list of equipment types from database. | |
static async Task< List< Equipment > > | GetEquipment (string name) |
Return list of equipment from database based the the search condition of equipment name. | |
static async Task | AddEquipmentAllocation (Equipment_Allocation ea) |
Add equipment allocation to database. | |
static async Task | AddEquipmentType (Equipment_type et) |
Add Equipment type to database. | |
Definition at line 8 of file EquipmentDB.cs.
◆ AddEquipment()
|
static |
◆ AddEquipmentAllocation()
|
static |
Add equipment allocation to database.
- Parameters
-
ea
- Returns
Definition at line 108 of file EquipmentDB.cs.
◆ AddEquipmentType()
|
static |
Add Equipment type to database.
- Parameters
-
et
- Returns
Definition at line 120 of file EquipmentDB.cs.
◆ GetEquipment()
|
static |
Return list of equipment from database based the the search condition of equipment name.
- Parameters
-
name
- Returns
Definition at line 95 of file EquipmentDB.cs.
◆ GetEquipmentType()
|
static |
◆ GetEquipmentTypeForeignKey()
|
static |
Gets equipment type id number.
- Parameters
-
eType
- Returns
- Foreign Key
Definition at line 38 of file EquipmentDB.cs.
◆ InitiateDataBase()
|
static |
Check if local database exists. Creates new one with table if it does not exist.
- Returns
Definition at line 19 of file EquipmentDB.cs.
◆ ListEquipment()
|
static |
The documentation for this class was generated from the following file:
- UNDAC Project/Data/EquipmentDB.cs
Generated by
fig 7(Documentation fo the EquipmentDB database class)
The following reflections were made from this portfolio
-
There could be a debate of having a database class for each of the equipment related tables. However, it was decided to keep them in one database class using the following that the InitateDataBase function creates all related equipoment tables. This was decided to do this in one function given that they are linked with foreign keys. This was to minimise the risk of tables not being created properly if a foreign key does not yet reference an existing table. Furthermore, given that there were only 8 methods, it was decided that this was not too much for one class.
-
Whilst using a local database in the early development, I have recognise that this is problematic in the following ways 2.1 There is the requirement for features to be merged into the development branch in order to sync the local database with changes due to added tables. 2.2 Datasets would need to be provded to be added to the local database to sync up data. 2.3 Not having a fully sync database would provide difficulty in testing for system wide compatability.
-
No unit tesing was put in place. I was able to figure out using mock tests for this week. This is an area I recognise I need to gain knowledge and skilsl on for both the project module for semester 2, as well as for professional practice.
-
Given that SQL injection vulnerability was recognised, I would need to read up on optimising SQL statments to mitigate for these risks.