Sales-and-Inventory-System-for-Chain-Stores...
ICT499 CAPSTONE PROJECT COURSE
SALES AND INVENTORY SYSTEM FOR CHAIN STORES (AMUSEMENT CENTER) FINAL REPORT JANUARY 2008
NAME: PI: PROJECT CODE: TUTOR: SUBMISSION DATE:
LEE CHANGJIN K0604033 JAN08/BHICT/03 MS NORSHIDA SELAMAT 24th OCTOBER 2008
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
ABSTRACT Methods of data storing and data processing are crucial to every business. Usually, companies overlooked the process of deriving the data. As long the data is obtained, how it is obtained really does not matter anymore. Some companies are still using papers with some usage of office related programs like Microsoft Words or Excel to store or process data. Using papers to process data can be time consuming and inefficient. This project is to demonstrate the how database system can be used to better manage and process data using stored procedures and triggers. The strategy adopted to achieve the objectives includes project management to better monitor and plan for the project progress, adopting of the database application lifecycle to develop the database system, reference and review of literatures to improve on completing this project. MySQL is used as the DBMS for this project. This project provides details on the EAR Model of the database system. Triggers and stored procedures are written and tested to fulfill the system objectives and any enterprise constraints. This project only covers the designing and testing of the database system. To be able to implement into usable system still need integration to GUI application. Businesses using database system the right way, should help to automate tedious manual tasks, making processing data more efficient and with great chance, minimize any human errors in the manual tasks. Areas such as security issue and distributed system deployment can be looked into in the future to improve on this project.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 2 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
ACKNOWLEDGEMENTS I would like to take this opportunity to express my deepest gratitude to the following individuals who have given me tremendous support and help in completing my Final Year Project. ‘Thank you, Ms Norishida Selamat.’ It is a pleasure to have Ms Norishida as my project supervisor, a great tutor with patience and thoughtfulness. With her worthy advice and invaluable guidance, she has guided me on this journey to complete my Final Year Project. I would like to thank Aidan Wee who used to be the business manager of Valibel Technologies Pte Ltd. He had shared with me the limitation of the amusement center operation and provided useful information to aid me in my project. Through him, I have gotten my project title and system objectives. I would like to thank my business partner for his extended understanding and abundant patience he has had given me, allowing me to have a balanced commitment between my Final Year Project and my startup business. Finally, I must thank my Mom and Dad for their loving care and inestimable morale support throughout this bumpy year. ‘Love ya, Mum & Dad!’
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 3 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
CDROM REPORT This report includes a CD with the following contents. 1) Final Year Report – ICT499_K0604033.doc 2) Gantt Chart – gantt_chart_K0604033.xls or gantt_chart_K0604033.pdf 3) The full schema – full_schema.sql 4) Test script to populate the database – test_script.sql 5) Backup database – k0604033_backup.sql 6) Acrobat Reader 9.0 Installer 7) MySQL Community Server 5.0 Installer 8) MySQL GUI Tools 5.0 Installer
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 4 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
TABLE OF CONTENTS ABSTRACT .................................................................................................................................. 2 ACKNOWLEDGEMENTS ............................................................................................................. 3 CD‐ROM REPORT ....................................................................................................................... 4 TABLE OF CONTENTS ................................................................................................................. 5 1.
2.
3.
INTRODUCTION ................................................................................................................. 8 1.1.
PROJECT TITLE ........................................................................................................... 8
1.2.
PROJECT AIMS ........................................................................................................... 8
1.3.
CONTEXT BACKGROUND ........................................................................................... 9
1.4.
SYSTEM DEFINITION ................................................................................................ 10
1.5.
SYSTEM OBJECTIVES ................................................................................................ 11
1.6.
METHODOLOGY ADOPTED ...................................................................................... 13
1.7.
RESOURCES USED .................................................................................................... 15
1.8.
LITERATURE REVIEW................................................................................................ 16
1.9.
PROJECT MANAGEMENT ......................................................................................... 18
CONCEPTUAL DESIGNING................................................................................................ 21 2.1.
ER DIAGRAM............................................................................................................ 21
2.2.
ENTITY DEFINITION & DESCRIPTION ....................................................................... 23
2.3.
RELATIONSHIP DESCRIPTION................................................................................... 24
2.4.
ATTRIBUTE DESCRIPTION ........................................................................................ 26
2.5.
CHANGES TO EAR MODEL ....................................................................................... 32
LOGICAL DESIGNING........................................................................................................ 33 3.1.
4.
RELATIONAL HEADINGS........................................................................................... 33
PHYSICAL DESIGNING ...................................................................................................... 35
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 5 of 81
LEE CHANGJIN (K0604033)
5.
6.
7.
JAN08/BHICT/03
4.1.
CREATE TABLE STATEMENTS ................................................................................... 35
4.2.
TRIGGER STATEMENTS ............................................................................................ 36
4.3.
STORED PROCEDURE STATEMENTS ........................................................................ 38
4.4.
FUNCTION STATEMENTS ......................................................................................... 40
4.5.
VIEW STATEMENTS.................................................................................................. 42
DATABASE TESTING ......................................................................................................... 43 5.1.
ENTITY TESTING ....................................................................................................... 43
5.2.
REFERENTIAL INTEGRITY TESTING........................................................................... 44
5.3.
DATA DOMAIN TESTING .......................................................................................... 45
5.4.
CARDINALITY TESTING............................................................................................. 45
5.5.
SYSTEM OBJECTIVE CHECKLIST................................................................................ 46
5.6.
SYSTEM OBJECTIVE TESTING ................................................................................... 48
CONCLUSION ................................................................................................................... 58 6.1.
CRITICAL REVIEW & REFLECTIONS........................................................................... 58
6.2.
RECOMMENDATIONS .............................................................................................. 60
6.3.
CONCLUSION ........................................................................................................... 60
APPENDICES..................................................................................................................... 61 7.1.
APPENDIX A: SQL SCHEMA ...................................................................................... 61
7.2.
APPENDIX B: SQL TABLE POPULATION .................................................................... 72
7.3.
APPENDIX C: GANTT CHART .................................................................................... 75
7.4.
APPENDIX D: OTHERS .............................................................................................. 77
8.
REFERENCES .................................................................................................................... 80
9.
GLOSSARY ........................................................................................................................ 81
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 6 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
LISTS OF FIGURES AND TABLES FIGURE 1.1 THE DATABASE DEVELOPMENT LIFECYCLE FOR THE PROJECT. FIGURE 1.2 THE NETWORK DIAGRAM USED DURING THE PROJECT FIGURE 1.3 CRITICAL PATH FIGURE 2.1 ER DIAGRAM FIGURE 4.1 CREATE TABLE STATEMENT FOR FACILITY FIGURE 4.2 TRIGGER STATEMENT FOR BEFORE_FACILITY_UPDATE FIGURE 4.3 STORED PROCEDURE STATEMENT FOR ADDSALES FIGURE 4.4 FUNCTION STATEMENT FOR CALCULATEPAYABLE FIGURE 4.5 VIEW CREATE STATEMENT FOR FACILITYCENTERPROMOVIEW FIGURE 5.1 SUCCESSFUL INSERT INTO TABLE FACILITY BY OMITTING THE PRIMARY KEY. FIGURE 5.2 SUCCESSFUL INSERT INTO TABLE FACILITY USING NULL FOR PRIMARY KEY. FIGURE 5.3 UNSUCCESSFUL INSERTING OF DATA INTO TABLE FACILITY. FIGURE 5.4 UNSUCCESSFUL INSERT INTO TABLE FACILITY USING INVALID FOREIGN KEY. FIGURE 5.5 UNSUCCESSFUL INSERT INTO TABLE FACILITY USING WRONG DATA TYPE. FIGURE 5.6 UNSUCCESSFUL INSERT WITH REFERENTIAL INTEGRITY ERROR FOR CARDINALITY CHECKING.
13 19 20 21 35 37 40 41 42 43 43 44 44 45 46
TABLE 1.1 WORK BREAKDOWN STRUCTURE TABLE 2.1 ENTITY DEFINITION & DESCRIPTION TABLE 2.2 RELATIONSHIP DESCRIPTION TABLE 2.3 ATTRIBUTE DESCRIPTON FOR FACILITY TABLE 2.4 ATTRIBUTE DESCRIPTION FOR ARCADE TABLE 2.5 ATTRIBUTE DESCRIPTION OF GAME TABLE 2.6 ATTRIBUTE DESCRIPTION FOR INVENTORY TABLE 2.7 ATTRIBUTE DESCRIPTION FOR INVENTORYLOG TABLE 2.8 ATTRIBUTE DESCRIPTION FOR CENTER TABLE 2.9 ATTRIBUTE DESCRIPTION FOR PROMOTION TABLE 2.10 ATTRIBUTE DESCRIPTION FOR CENTERPROMOTION TABLE 2.11 ATTRIBUTE DESCRIPTION FOR SALES TABLE 2.12 ATTRIBUTE DESCRIPTION FOR LANBILLIARDSALES TABLE 2.13 ATTRIBUTE DESCRIPTION FOR ARCADECARDSALES TABLE 2.14 ATTRIBUTE DESCRIPTION FOR ARCADECARD TABLE 2.15 ATTRIBUTE DESCRIPTION FOR MEMBER TABLE 2.16 ATTRIBUTE DESCRIPTION FOR REDEEMITEM TABLE 2.17 ATTRIBUTE DESCRIPTION FOR REDEMPTION TABLE 4.1 TRIGGERS DESCRIPTION AND SCOPE TABLE 4.2 STORED PROCEDURE DESCRIPTION AND SCOPE TABLE 5.1 CODES THAT FULFILL INVENTORY SYSTEM OBJECTIVES TABLE 5.2 CODES THAT FULFILL SALES SYSTEM OBJECTIVE TABLE 5.3 CODES THAT FULFILL MEMBER SYSTEM OBJECTIVES
18 24 25 26 26 27 27 27 27 28 28 29 29 29 30 31 31 32 37 39 47 47 48
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 7 of 81
LEE CHANGJIN (K0604033)
1.
JAN08/BHICT/03
INTRODUCTION
1.1.
PROJECT TITLE
I had chosen ‘Design and Implementation of a Database’ as my project track. This is due to my interest in data management and I want to learn how I can manage data with a database to provide useful yet relevant data for a specific need from a user. It is interesting to discover how a database system can store such gigantic amount of data and yet still able to sort out relevant data within seconds with just a few lines of query scripting. The project title that I will be working on is as titled: Sales and Inventory System for Chain Stores (Amusement Center).
1.2.
PROJECT AIMS
In general, by undergoing this project, it allows me to access my standards in planning and managing a project and apply what I have had learnt in UniSIM. Setting my criteria and schedule to develop this project and fulfilling them is a challenging experience for me. During the process of this project, I am able to identify my weaknesses in the various stages of project management. By knowing these weaknesses, improvement plans were made and scheduled by me to improve on my weak areas. Thus, the experience and knowledge gained by doing this project definitely helps me be better in my project management skill in further projects. A database system is widely used to provide a central control of data where the data is accessed and used by multiple users for different purposes. Different users might need the same data for different purposes. Hence, by developing a database solution, it should solve and enhance the operational limitation faced by the company. The company should be able to manage its data more efficiently with the database system.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 8 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
1.3.
CONTEXT BACKGROUND
Introduction Valibel Technologies Ptd Ltd is one of the pioneers in the family entertainment business. Incorporate in 1983, Valibel aims to excel in family entertainment and to achieve top standards in service and products to meet its business goals. Currently, Valibel manages a chain of 6 amusement centers. The facilities These amusement centers can provide up to 3 different types of facilities namely, Arcade machines, LAN stations and billiard tables. The arcade machines are categories into different genres such as shooting, racing and sport. Each arcade machines will have its game title and its credit price for one game play. For LAN stations and billiard tables, customer pays for the usage by hourly rate. Inventory There is an inventory warehouse to hold the facilities. When a facility requires servicing, it is send to the inventory. After servicing is done, it will be send back to the former center if required. New facility is send to the inventory before deploying to any centers. The facilities are either in a center or in the inventory. If a facility needs to be relocated to other center, it has to be sent back to the inventory first before deploying to the center. Arcade cards Arcard cards are sold in all centers. Customers are required to buy arcade cards to play the arcade machines. Arcade cards are available in different total credit value which cost differently. For example, a customer pays S$5 for a 6 dollars credit value card. Promotions A center can only have one promotion at any one time. The promotion can be for a particular facility or for the entire center. The promotion will have a start date and end date as promotion period. A promotion will give a discount off the total bill either by an amount
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 9 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
or by a certain percentage with minimum spending. Promotions are strictly not applicable to member. Sales Sales record is generated when customers buy arcade cards or pay for LAN/billiard usages. If the customer is a member, the customer will enjoy member pricing if any. The sales of the arcade cards are recorded down on a piece of sales report form by the respective counter staff of each center. The forms are collected from each center and send to the main office for accounting at the end of the day. The sales of the LAN stations and billiard tables are managed by a Marco32 system where the respective counter staff prints the sales receipt of each center at the end of the day. The sales receipts are also collected and send to the main office for accounting at the end of the day. The sales records from these forms and receipts are then keyed into Excel sheet for better management of the sales data and accounting purpose. Membership A customer can become a member by filling up the membership form. Information to be captured includes member number, name, identity number (i.e. NRIC or passport number), gender, date of birth, address, contact, email and occupation. For every facility a member has spent on, the member will earn member points. Member can use to points to redeem for gift items and other prizes. Member points will be reset back to zero when the member expiry point date has past.
1.4.
SYSTEM DEFINITION
A centralize system
Valibel has plan for a centralize system to quicken its operations.
An inventory system that can keep records on which facility has been send back for servicing and where a particular facility is previously allocated and when is that action executed. A logging feature to log every event in the inventory for tracking purposes.
A sale system that is used to manage the sales records of the arcade cards, as well as sales records of LAN station and billiard table usage. The sales system will be able to facilitate any member rates or promotions.
A member system used to manage the member points and redemption of items.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 10 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
1.5.
SYSTEM OBJECTIVES
The system objectives are represented in the brackets as the respective modules alias which will be use in this report to represent a particular system objective. For example, the system objective of Inventory System point 1 will be represented as ‘IS: Point 1’. Inventory System (IS) 1. The system will be able to add new facility records into the inventory. The system will log this event. 2. The system will be able to change where the facility is to be deployed. If facility is currently in a center, changing the center will move the facility to the inventory to be redeployed. The system will log this event. 3. The system will be able to move facility records from centers that require maintenance servicing back to the inventory. The system will log this event. 4. The system will be able to move facility record back to the center it should be deployed to when the maintenance servicing is done. The system will log this event. Sales (SA) 1. The system will be able to register one particular promotion to a center. 2. The system will be able to ensure that a center can only have one promotion at any one time. 3. The system will be able to generate sales record on a. A normal basis when there is no promotion and the customer is not a member. b. A promotion basis if the center is having a promotion. c. A membership basis if the customer is a member. 4. The system will be able to ensure that the promotion privilege will not be applicable if the sale is from a member. Member (ME) 1. The system will be able to accumulate the member points for any sales generated by member where for every S$0.10 spent, 1 point will be accumulated. ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 11 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
2. The system will be able to ensure that the member has sufficient member points for deduction before registering any redemption made by the member. 3. The system will be able to reset the member points back to zero when the member point expiry date has past. A new member point expiry date will be extended by 1 year.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 12 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
1.6.
METHODOLOGY ADOPTED
Every project adopts a certain SDLC as it adheres the important phases that are essential for developers namely planning, analysis, design, implementation and testing. In figure 1.1 shows a similar to SDLC structure which I am be adopting for my project. This is a database development lifecycle which I referenced from the book ‘Database System’ on page 272. I have tailored the development lifecycle to use it as a guideline for my project. In figure 1.1 shows my database development lifecycle.
Gathering of User Requirements Database Design Analysis of Requirements
Database System Definition
Conceptual Design
Logical Design
Physical Design
Database Testing
Figure 1.1 The database development lifecycle for the project.
During the requirement gathering phase, I conducted an interview with the business development manager. I brainstormed some questions to ask which I have appended in the Appendix D: OTHERS, and shortlist the critical ones for the interview. Through the interview and some chatting I have a better understand of the company background and operation flow. I have obtained 2 forms related to the company operation namely the membership registration form and the sales tracking form. Refer to appendix for the form.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 13 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
With the requirements then defining the system definition and objectives, I begin on conceptual designing of the database system. I had done revision and reference to have a better idea on how to do the E‐A‐R (Entity‐Attribute‐Relationship) model. It involved defining the entities, each entry’s attributes, the relationship between the entities and their description. I had iterated at this stage a few time due to changes on the E‐A‐R model. Logical design stage is where I done the relationship headings and finalizing the details to begin on designing and creating the schema. As I am not very good with triggers and stored procedures, I did research and referencing on books to websites. I was lucky to found a good book, ‘Pro MySQL’, which gives excellent example of creating triggers and stored procedures. Well doing the codes, small testing is done to see if the code works. I did not complete all the codes and script before moving to testing stage. What I did was that after finish the inventory system, I jumped into testing the inventory system and went back to debug if bugs were found. This process iterates for a few times before I move on to the next module, sales system and so on. I used the same method, for the next two parts of the database system. Once I done all of them, I did a whole system check again to see if there is any loopholes or bugs that I had missed. Indeed, bugs were found and I had to go back to the concerns area to solve the bugs. In a way, a lot of iteration from various stages to precedent stage occurred where changes were made and fine tuning was done to the database system. Until all the system objectives are fulfilled and test, that is when I worked on my report. From there I did research and referencing on how to write a good report.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 14 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
1.7.
RESOURCES USED
I have had visited National Libraries and SIM’s library for research and revision. Some of the books that I had borrowed were used for literature research, while some others were used to gain more knowledge and revise on my relevant experiences to do this project. National Libraries provide a wider range of books for reference which some which I required cannot be found in SIM library. However, SIM Library does provide other materials which National Libraries do not have. SIM Library has provided a collection of past Capstone Project Reports which I have referenced for the content structure and how past project students did their report. These reports that I have referenced gave me an insight of the standard of the report and how I can improvise when doing mine. Other then libraries, I have use the internet to search for relevant information for further research. Surfing on internet is like a treasure hunt. With Google’s powerful search engine, I am able to find worthy websites for reference. A computer with the necessary software installed is crucial for this project too. Luckily, I have a laptop with Microsoft Office installed. Hence, I can work on my report even at night. Though SIM does provide work station for students to use, it is definitely more flexible and easier with one that I own it. Towards the end of the project, I will prepare my presentation on my laptop. As I am using MySQL as my DBMS, I would need to download and install MySQL Community Server. I have chosen MySQL as this DBMS is an open source database and is proclaimed to be the world’s most popular open source database by the global community. Other then it is free, I have some experience using it since my polytechnic days. I have also installed MySQL GUI Tools to assist me in managing my database for this project. It provides GUI features for me to interact with the DBMS with much ease. Meeting room or study area is also one of the resources required. I have had monthly meeting with my tutor to follow up the project status and enquire for my tutor’s advice. Our tutor will book a meeting room in SIM for the monthly meeting. Once in a while, I would meet up with other students doing the 499 capstone project to share and help each other. We usually meet up in SIM and grab any available study area or use the open lab session available.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 15 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
1.8.
LITERATURE REVIEW
For more information regarding the materials that I have referenced, refer to ‘Reference’ section at the end of this report. Database Systems (Book) I found this book in the UniSIM library when looking for database related information for my project. This book provides a lot of information which I used it to guide me in doing the project. First, my SDLC is derived from this book, Chapter 9, section 9.2, The Database Application Lifecycle. I reference the diagram on page 272 and used it as a guidance to structure my SDLC. In the end, I used its term Database Application Lifecycle instead of SDLC. The Database Application Lifecycle is similar to of a SDLC which consist the requirement gathering, designing and testing of the system. I also reference chapter 11, Entity‐Relationship Modeling to get some guideline to work on my ER diagram. Particularly on Section 11.3, Attributes, to familiarize with the different type of attributes namely single, composite, multi‐valued, derived and keys. However, this book is useful for my conceptual design where it help me plan and set my ER model. It does not provide much help in trigger and stored procedure which I will need to get familiarizes to work on my physical design stage of the database system. It is not a wonder book but it did help me get started. Pro MySQL (Book) During my ICT 315 course in school, trigger and stored procedure is taught only on the surface, we were taught to know the pseudo code for the trigger but not really go in depth to try it. Hence, trigger and stored procedure is one area I must research on. This book is introduced to me by my friend, as I was asking around if there are any good books which teach trigger and stored procedure on MySQL. I managed to find it in West Mall National Library. On the cover, it quotes ‘The Expert’s Voice In Open Source’. Indeed, it gives me great details on creating triggers, stored procedure and more. All my codes would not be possible without this book. I had tried out their example trigger and stored procedure before working on mine. Chapter 9, Stored Procedures, Building Stored Procedure on Page 354, teaches the creating of stored procedure in a step by step explanation which I followed closely. Same for Chapter 10 on Functions and Chapter 11 on Triggers, it guided me on creating my SQL schema. ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 16 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
If someone is learning how to use trigger, stored procedure and functions on MySQL, I will surely recommend this book to him/her. It is a book that covers a very specific area; people with specialized need on MySQL will find it very useful. This book has given my great assistance in completing my physical design and SQL schema. From there, I was able to move on to testing the schema. MySQL 5.0 Reference Manual This manual is one material I cannot miss out as I want to know more about MySQL. It covers most of the general information about MySQL. As it is available easily online, I just need an internet connection browse it or I can even download it to my computer. I referenced chapter 10, Data Type, which give a general description, enough for understand and application, of all the data type used in MySQL. There is where I found the usage of string data type ENUM will only give a value from a list of values. Chapter 12 SQL Statement syntax, 12.1.9 Create Table syntax, is a section I used to check my CREATE statement and for explanation in my report. I also reference other section on CREATE trigger syntax, stored procedure and functions. Anyway in my opinion, it is just a reference manual without good example and explanations. It is a good source to get to know MySQL and provide some general information to the area I am looking for. However, if I want to know more in depth information on a specific area, I will need to source for better materials. A Guide to the Project Management Body of Knowledge (Book) I got to know this book from my ICT 317 course. It is given to me on the last day of course. Though the publication is four years ago, it is still a very good book on project management. I referenced on the chapter, Project Scope Management on page 103 to page 118 on the guidelines to plan my project scope and derive my work breakdown structure (WBS). Some reference on page 131 to know more about network diagram. Though the book does give good knowledge of project management but it serves more like guidelines to me. As this project is a one man show instead of a team, the book is good for theories reading, not for trying them out.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 17 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
1.9.
PROJECT MANAGEMENT
Work Breakdown Structure This is the work breakdown structure after the completion of the project without the potion on the initial report and presentation. Task 3. Gather Requirements 3.1. Literature study 3.2. Interview with key personnel 3.2.1.Prepare interview questions 3.2.2.Conduct interview 4. Database Design 4.1. Conceptual design 4.1.1.Literature study 4.1.2.Requirement Analysis 4.1.3.Identify entity and relationship types 4.1.4.Identify attributes for entity and relationship 4.1.5.Determine attribute domains 4.1.6.Determine candidate and primary key attributes 4.2. Logical design 4.2.1.Literature study 4.2.2.Define the relationship Headings 4.3. Physical design 4.3.1.Literature study 4.3.2.Create Table Statements 4.3.3.Trigger Statements 4.3.4.Stored Procedures Statements 4.3.5.Function Statements 4.3.6.View Statements 5. Database Testing 5.1. Literature study 5.2. Implementing of tables 5.3. Populate data 5.4. Testing of schemas 6. Final Report 6.1. Literature study 6.2. Doing of final report
Preceding Activity 2 ‐ 3.1 ‐ 3.2.1 ‐ 3 ‐ ‐ ‐ ‐ ‐ ‐ 4.1 ‐ 4.2 ‐ ‐ ‐ ‐ ‐ ‐ 4.3 ‐ ‐ ‐ ‐ 4, 5, 6 ‐ ‐
Estimated Time 9hrs 4hrs 5hrs 4hrs 1hr 104hrs 38hrs 10hrs 4hrs 6hrs 8hrs 4hrs 6hrs 16hrs 6hrs 10hrs 50hrs 10hrs 8hrs 8hrs 8hrs 8hrs 8hrs 80hrs 10hrs 10hrs 10hrs 50hrs 70hrs 10hrs 60hrs
Table 1.1 Work Breakdown Structure
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 18 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Network Diagram
Conceptual Design
Logical Design
Physical Design
Database Testing
Create Table Statements
Test Create Table & populate data
Triggers Statements
Test Triggers Statements
Stored procedure Statements
Test Stored procedure Statements
Function Statements
Test Function Statements
View Statements
Test View Statements
Report
Figure 1.2 The network diagram used during the project
I did not follow the tasks in order as shown in the WBS when doing the tasks. Instead, I broke up Task 3 Physical Design and Task 4 Database Testing into smaller specific tasks as shown in the network diagram. Upon completing the sub task of Physical Design, I moved to test the sub task. For example, after Task ‘Create Table Statements’ was done, I move to the Task ‘Test Create Table & Populate Data’. I chose to do it this way because it is more feasible to complete one component and test it before moving to the next component. Completing all the sub tasks in Physical Design then move on to testing might take me more time to test. Imagine, when there is a bug, I need to check all the sub tasks if I do not know where the bug is from.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 19 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Completing a sub task and then test it gives me the option to trial and error the sub task and perfect it before moving to the next one. Instead of completing task by task listed in the WBS, I completed by fulfilling system objective by system objective. The pattern of doing it can be seen on the Gantt chart. Please refer to Appendix C: Gantt chart. Critical Path Physical Design
Conceptual Design
Report writing
Logical Design
Database Testing
Figure 1.3 Critical Path
By doing the Physical Design and Database Testing concurrently, this is my critical path. From the Gantt chart, I took much more time to complete the testing from the estimated as I spent some time debugging my code. Partly is due to me not familiar with trigger and stored procedure.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 20 of 81
LEE CHANGJIN (K0604033)
2.
JAN08/BHICT/03
CONCEPTUAL DESIGNING
2.1.
ER DIAGRAM
Inventory facilityNo{PK} toDeployAt
InventoryLog facilityNo{PK} invLogDatetime{PK} 1..N invDescription
stores
1..1
1..N Facility facilityNo{PK} 1..N facilityType facilityStatus normalPrice memberPrice
willHave
Arcade facilityNo{PK}
1..1
has
{Optional}
1..N plays 1..1 Game gameNo{PK} gameTitle genre
1..1 1..1 Center centerNo {PK} name
creates ArcadeCardSales 1..N salesNo{PK}
1..1
1..N
make
1..1
1..N LanBilliardSales salesNo{PK} startTime endTime
relatesTo hosts 1..1 ArcadeCard arcadeCardNo{PK} normalCardPrice memberCardPrice cardValue
1..N CenterPromotion centerNo{PK} promotionNo{PK} startdate{PK} enddate{PK}
1..1 Promotion promotionNo{PK} description rateType rate minSpent promoType
Sales salesNo{PK} salesType salesDatetime amtPayable 1..N generates
1..N appliesTo
{Mandatory, Or}
Redemption memberNo{PK redeemItemNo{PK} redeemDatetime{PK} 1..N belongsTo 1..1 RedeemItem redeemItemNo{PK} redeemDesc pointsCost
1..1 Member memberNo {PK} name 1..1 1..N identityNo makes gender dob address email contact occupation memberCardNo joinedDate points pointsExpiry
Figure 2.1 ER Diagram
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 21 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Constraints: 1.
A new facility must be deployed to the inventory first.
2.
A facility must be sent back to the inventory first before deploying to other center.
3.
If the value of toDeployAt of table Inventory is not null, the value must exist as a value of CenterNo of table Center.
4.
A center can only have one active promotion at any one time.
5.
Member points will be reset to ‘0’ when the point expiry date is past.
6.
Member point expiry date is extended for a year upon expiry.
7.
Member points cannot be negative.
8.
Redemption is not applicable if the member does not have sufficient points for deduction.
Assumption: 1. A facility not allocated to any center must be in the inventory. 2. Member rate is used instead of the promotion rate when a member pays in a center which is having a promotion. 3. For every $0.10 spent by a member, 1 point is award to the member. The constraints and assumptions are mostly derived from the system objectives.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 22 of 81
LEE CHANGJIN (K0604033)
2.2.
JAN08/BHICT/03
ENTITY DEFINITION & DESCRIPTION
Entity
Definition/Description
Facility
(facilityNo, facilityType, facilityStatus, normalPrice, memberPrice) Each instance of Facility holds details of a facility which can be a LAN-station, a billiard table or an arcade machine.
Arcade
(facilityNo) Each instance of Arcade is a sub-type of instance Facility.
Game
(gameNo, gameTitle, genre) Each instance of Game holds the details of the game played on an arcade machine.
Inventory
(facilityNo, toDeployAt) There is only an instance of Inventory which record the facilities that are under-servicing and newly purchased.
InventoryLog
(facilityNo, invLogDatetime, invDescription) Each instance of InventoryLog records the logging details of a particular facility in the inventory.
Center
(centerNo, name) Each instance of Center holds the details of an amusement center.
Promotion
(promotionNo, promoDescription, rateType, rate, minSpent, promoType) Each instance of Promotion holds the details of a promotion.
CenterPromotion
(centerNo, promotionNo, startDate, endDate) Each instance of CenterPromotion records an amusement center having a particular promotion.
Sales
(salesNo, salesType, salesDateTime, amtPayable, memberNo) Each instance of Sales records the sales details.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 23 of 81
LEE CHANGJIN (K0604033) LanBilliardSales
JAN08/BHICT/03
(salesNo, startTime, endTime, facilityNo) Each instance of LanBilliardSales records the sales details of a particular facility.
ArcadeCard
(arcadeCardNo, normalCardPrice, memberCardPrice, cardValue) Each instance of ArcadeCard holds the details of an arcade card type.
ArcadeCardSales
(salesNo, arcadeCardNo, centerNo) Each instance of ArcadeCardSales records the sales details of a particular arcade card.
Member
(memberNo, name, identityNo, gender, dob, address, email, contact, occupation, memberCardNo, joinedDate, points, pointsExpiry) Each instance of Member holds details of an individual member.
RedeemItem
(redeemItemNo, redeemDesc, pointCost) Each RedeemItem holds the details of a redeemable item.
Redemption
(memberNo, redeemItemNo, redeemDateTime) Each Redemption records the details of a redeemable item redeemed by a particular member.
Table 2.1 Entity Definition & Description
2.3.
RELATIONSHIP DESCRIPTION
Relationship
Description/Justification
stores
An Inventory stores Facilities. An Inventory can be empty, but a Facility must be either in an Inventory or Center.
willHave
A Facility will have InventoryLogs. A Facility has InventoryLogs, but an InventoryLog must belong to a Facility.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 24 of 81
LEE CHANGJIN (K0604033) has
JAN08/BHICT/03
A Center has Facilities. A Center must have at least one Facilities but Facility must be either in an Inventory or Center.
plays
An Arcade plays a game. An Arcade plays one game, but a game can be played on many Arcades.
creates
A Facility creates LanBilliardSales. A Facility can creates many LanBilliardSales, but a LanBilliardSales must be from a Facility.
hosts
A Center hosts a CenterPromotion. A Center can hosts one CenterPromotion at any one time, but a CenterPromotion must belong to a Center.
appliesTo
A promotion is applied to CenterPromotions. A promotion can be applied to many CenterPromotions, but a CenterPromotion must have a Promotion
makes
A Center makes ArcadeCardSales. A Center can makes many ArcadeCardSales, but an ArcadeCardSales must be from a Center.
relatesTo
An ArcadeCard is related to each ArcadeCardSales. An ArcadeCard can be related to many ArcadeCardSales, but an ArcadeCardSales must have an ArcadeCard.
generates
A Member generates Sales. A Member can generates many Sales, but a Sales need not be from a Member.
makes
A Member makes a Redemption. A Member can makes many Redemptions, but a Redemption must be applied from a Member.
belongsTo
A RedeemItem belongs to each Redemption. A RedeemItem can belongs to many Redemption, but a Redemption must have a RedeemItem.
Table 2.2 Relationship Description
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 25 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
2.4.
ATTRIBUTE DESCRIPTION
Facility Attribute
Description
Data type
Null
Primary key of each facility
Int(10)
No
facilityType
Either: ‘lan’ for LAN station, ‘bill’ for Billiard table, ‘arc’ for Arcade machine
Enum(‘lan’,’bill’,’arc’) No
facilityStatus
Either: ‘0’ for Maintance, ‘1’ for Operational
Enum(‘0’,’1’)
No
normalPrice
For LAN station and billiard table will be hourly rate. For arcade machine will be the credit price for one play. E.g. 7.50
Decimal(5,2)
No
Same as above, only the price is of member rate for the facilities. E.g. 7.50
Decimal(5,2)
Yes
facilityNo
memberPrice
Table 2.3 Attribute Descripton for Facility
Arcade Attribute
Description
Data type
Null
Primary key of the facility
Int(10)
No
Description
Data type
Null
Primary key of the game
Int(10)
No
facilityNo
Table 2.4 Attribute Description for Arcade
Game Attribute GameNo
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 26 of 81
LEE CHANGJIN (K0604033) gameTitle
JAN08/BHICT/03
Arcade machine’s game title. E.g. Time Crisis 4
Text
No
Arcade machine’s game genre. E.g. Shooting
Text
No
Description
Data type
Null
Foreign key of FACILITY
Int(10)
No
The center number the facility is going to be deployed at.
Int(10)
Yes
Description
Data type
Null
Foreign key of FACILITY
Int(10)
No
invLogDatetime
Datetime of this action from inventory. E.g. 2008-10-01 18:20:00
Datetime
No
invDescription
Description of the action from inventory
Text
No
Description
Data type
Null
Primary key of the center
Int(10)
No
Name of the center. E.g. Funland Sembawang
Text
No
genre
Table 2.5 Attribute Description of Game
Inventory Attribute facilityNo
toDeployAt
Table 2.6 Attribute Description for Inventory
InventoryLog Attribute facilityNo
Table 2.7 Attribute Description for InventoryLog
Center Attribute centerNo
name
Table 2.8 Attribute Description for Center
Promotion
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 27 of 81
LEE CHANGJIN (K0604033) Attribute
JAN08/BHICT/03
Description
Data type
Null
Primary key of promotion
Int(10)
No
Promotion details
Text
No
rateType
Either: ‘amt’ which means amount. ‘per’ which means percentage.
Enum(‘amt’,’per’)
No
rate
The rate for the discount. E.g. rate is ‘5’ and rateType is percentage. It will be a 5% discount. Else it will be an S$5 discount.
Int(3)
No
minSpent
Minimum spending of a customer in order to enjoy this promotion
Int(2)
No
promoType
Either: ‘lan’ for LAN station, ‘bill’ for Billiard table, ‘arc’ for Arcade machine
Enum(‘lan’,’bill’,’arc’,’all’) No
promotionNo
promoDescription
Table 2.9 Attribute Description for Promotion
CenterPromotion Attribute
Description
Data type
Null
Composite Primary Key
Int(10)
No
Composite Primary Key
Int(10)
No
startDate
Composite Primary Key; start date of this promotion for this center
Datetime
No
endDate
Composite Primary Key; end date of this promotion for this center
Datetime
No
centerNo
promotionNo
Table 2.10 Attribute Description for CenterPromotion
Sales ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 28 of 81
LEE CHANGJIN (K0604033) Attribute
JAN08/BHICT/03
Description
Data type
Null
Primary key of a sales record
Int(10)
No
Either: ‘lan’ for LAN station, ‘bill’ for Billiard table, ‘arc’ for Arcade machine
Enum(‘lan’,’bill’,’arc’) No
Datetime of this sales record E.g. 2008-10-01 18:20:56
Datetime
No
Computered attribute; amount to be paid by customer E.g. 39.70
Decimal(10,2)
No
salesNo
salesType
salesDatetime
amtPayable
Table 2.11 Attribute Description for Sales
LanBilliardSales Attribute
Description
Data type
Null
Primary key of the sales record
Int(10)
No
startTime
Start time when customer used the LAN station or Billiard table E.g. 18:20:56
Time
No
endTime
End time when customer used the LAN station or Billiard table E.g. 18:20:56
Time
No
Description
Data type
Null
Primary key of the sales record
Int(10)
No
salesNo
Table 2.12 Attribute Description for LanBIlliardSales
ArcardCardSales Attribute salesNo
Table 2.13 Attribute Description for ArcadeCardSales
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 29 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
ArcadeCard Attribute
Description
Data type
Null
Primary key for the arcade card
Int(10)
No
Cost price of arcade card E.g. 5.00
Decimal(5,2)
No
Member cost price of arcade card E.g. 4.00
Decimal(5,2)
No
The credit value in the card E.g. 6.00
Decimal(5,2)
No
Description
Data type
Null
Primary key for member
Int(10)
No
Name of member
text
No
NRIC or passport number
text
No
Gender. Either: ‘M’ for Male, ‘F’ for Female
Enum(‘M’,’F’)
No
Date of birth E.g. 1980-10-01
Date
No
Address
Text
No
Email address
Text
No
arcadeCardNo
normalCardPrice
memberCardPrice
cardValue
Table 2.14 Attribute Description for ArcadeCard
Member Attribute memberNo
name
identityNo
gender
dob
address
email
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 30 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
contact Contact number
Int(10)
No
Occupation
Text
No
memberCardNo
Member card number allocated to the member
Int(10)
No
joinedDate
Date of customer becomes a member E.g. 2000-10-01
Date
No
Points
Computered attribute; points member has for redemption
Int(10)
No
Date of expiry for the points E.g. 2009-10-01
Date
No
Description
Data type
Null
Primary key for redeem item
Int(10)
No
Redeem item description
Text
No
Points required to redeem the item E.g. 5000
Int(10)
No
Description
Data type
Null
Composite Primary Key
Int(10)
No
Composite Primary Key
Int(10)
No
occupation
pointsExpiry
Table 2.15 Attribute Description for Member
RedeemItem Attribute redeemItemNo
redeemDesc
pointsCost
Table 2.16 Attribute Description for RedeemItem
Redemption Attribute memberNo
redeemItemNo
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 31 of 81
LEE CHANGJIN (K0604033) redeemDatetime
Composite Primary Key; Datetime of the redemption
JAN08/BHICT/03
Datetime
No
Table 2.17 Attribute Description for Redemption
2.5.
CHANGES TO EAR MODEL
All the generalization has been removed as I am not familiar or taught to design the database with generalization. I have combined the child entity to the parent entity. This will give me new constraints to take care of. For example, game number is mandatory attribute for facility that is an Arcade but is not needed for facility that is a LAN station or Billiard table. This change will be reflected from the relational heading onwards.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 32 of 81
LEE CHANGJIN (K0604033)
3.
JAN08/BHICT/03
LOGICAL DESIGNING
3.1.
RELATIONAL HEADINGS
Facility (facilityNo, CenterNo, facilityType, facilityStatus, normalPrice, memberPrice, gameNo) Changes: Arcade entity is being merged to Facility entity. This is done to remove generalization of the entity. The supertype will hold the attributes of the subtype. Game (gameNo, gameTitle, genre)
Inventory (facilityNo, toDeployAt)
InventoryLog (facilityNo, invLogDatetime, invDescription)
Center (centerNo, name)
Promotion (promotionNo, promoDescription, rateType, rate, minSpent,promoType)
CenterPromotion (centerNo, promotionNo, startDate, endDate)
Sales (salesNo, salesType, salesDateTime, amtPayable, memberNo, startTime, endTime, facilityNo, arcadeCardNo, centerNo) Changes: LanBilliardSales entity and ArcadeCardSales entity are merged to Sales entity.
ArcadeCard (arcadeCardNo, normalCardPrice, memberCardPrice, cardValue)
Member (memberNo, name, identityNo, gender, dob, address, email, contact, occupation, memberCardNo, joinedDate, points, pointsExpiry) ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 33 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
RedeemItem (redeemItemNo, redeemDesc, pointCost)
Redemption (memberNo, redeemItemNo, redeemDateTime)
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 34 of 81
LEE CHANGJIN (K0604033)
4.
JAN08/BHICT/03
PHYSICAL DESIGNING
4.1.
CREATE TABLE STATEMENTS
In my ER Diagram, there are a total of 15 entities. After combining the generalised child entity to its parent, I have 12 entities. Hence, there are a total of 12 CREATE TABLE statements in my SQL schema. I have picked the CREATE TABLE statements for Facility which has the most complex code. The rest of the CREATE TABLE statements are more or less having the same format and structure. For the full SQL schema for this project, please refer to Appendix A: SQL Schema. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.
CREATE TABLE `facility` ( `facilityNo` int(10) unsigned NOT NULL auto_increment, `centerNo` int(10) unsigned default NULL, `facilityType` enum('lan','bill','arc') NOT NULL, `facilityStatus` enum('0','1') NOT NULL default '0', `normalPrice` decimal(5,2) NOT NULL default '0.00', `MemberPrice` decimal(5,2) default '0.00', `gameNo` int(10) unsigned default NULL, PRIMARY KEY (`facilityNo`), KEY `Facility_Index1` USING BTREE (`centerNo`), KEY `Facility_Index2` USING BTREE(`gameNo`), CONSTRAINT `FK_facility_1` FOREIGN KEY (`centerNo`) REFERENCES `center` (`centerNo`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `FK_facility_2` FOREIGN KEY (`gameNo`) REFERENCES `game` (`gameNo`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Figure 4.1 CREATE TABLE statement for Facility
The syntax for CREATE TABLE statements can be easily obtained from MySQL documentation in MySQL homepage. Line 1 starts the CREATE TABLE statement for creating the table named ‘facility’. Line 2 to line 8 defines the column name of the table. Each column name will need to define the column definitions. Usually the data type, length of data type if any, if it can be NULL or NOT NULL and if it has a DEFAULT value. UNSIGNED is used to define a numeric data type that cannot have negative value. AUTO_INCREMENT is used to generate a unique identifier for new rows, usually used on a primary key column. ENUM is an enumeration string object data type by MySQL which can only have one value from a list of values. Line 9 defines the PRIMARY KEY of the table.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 35 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Line 10 and line 11 defines the KEY that need to be indexed for faster retrieval of row. BTREE, a tree data structure, is the index type used for indexing. Line 12 and line 13 defines the foreign key constraint for the table. Line 14 and line 15 defines the referential actions for the foreign key. ON DELETE NO ACTION defines that no action is to be taken when DELETE statement is executed on the referenced row that exist in the child row. ON UPDATE CASCADE defines that when UPDATE statement is executed on the referenced row, the respective child rows matching the foreign key will be updated as well. Line 20 defines the DBMS engine for the table. InnoDB is used as it is the engine that obeys the referential integrity protocol. DEFAULT CHARSET defines the default character set for the table which uses the UTF8 unicode character set.
4.2.
TRIGGER STATEMENTS
The table below defines the triggers used for the system with a brief description of the trigger usage and its scope. Trigger Name
Description/Scope of trigger
before_facility_insert
The trigger to be executed before a record is inserted into facility table.
after_facility_insert
before_facility_update
1. To erase any center number when creating facility. 2. To erase any game number when facility is not an Arcade. 3. To check if game number is provide when facility is an Arcade. The trigger to be executed after a record is inserted into facility table. 1. To set the new facility in the inventory (IS: Point 1) 2. Do the logging of this event. (IS: Point 1) The trigger to be executed before a record is updated in the facility table. 1. If facility needs maintenance, move the facility to inventory and log this event. (IS: Point 3) 2. If facility is operational, move the facility back to the center and log this event. (IS: Point 4) 3. If facility needs to redeploy to another center, send it back
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 36 of 81
LEE CHANGJIN (K0604033)
after_sales_insert
JAN08/BHICT/03 to the inventory first. (IS: Point 2) The trigger to be executed before a record is inserted in the sales table. 1. Add the points from the sales to the member. (ME: Point 1)
Table 4.1 Triggers description and scope
I have picked the trigger before_facility_update which has the most complex code to explain. The other triggers more or less have the same format and structure. 1. DELIMITER // 2. CREATE TRIGGER `before_facility_update` BEFORE UPDATE ON facility 3. FOR EACH ROW 4. BEGIN 5. SET @facilityStatus = NEW.facilityStatus; 6. SET @facilityStatusOld = OLD.facilityStatus; 7. SET @facilityNo = NEW.facilityNo; 8. SET @centerNo = NEW.centerNo; 9. SET @centerNoOld = OLD.centerNo; 10. 11. IF @facilityStatus = 0 THEN 12. INSERT INTO inventory (facilityNo, toDeployAt) 13. VALUES (@facilityNo, @centerNo); 14. CALL LogInventory(@FacilityNo,@centerNo,2); 15. SET NEW.centerNo = NULL; 16. END IF; 17. 18. IF @facilityStatus = 1 AND @facilityStatus != @facilityStatusOld THEN 19. SET NEW.centerNo = (SELECT toDeployAt FROM inventory WHERE facilityNo = @facilityNo); 20. 21. DELETE FROM inventory WHERE facilityNo = @facilityNo; 22. CALL LogInventory(@facilityNo,NEW.centerNo,3); 23. END IF; 24. 25. IF @centerNoOld @centerNo AND @facilityStatus = '1' THEN 26. INSERT INTO inventory (facilityNo, toDeployAt) 27. VALUES (@facilityNo, @centerNo); 28. CALL LogInventory(@facilityNo,@centerNo,4); 29. SET NEW.centerNo = NULL; 30. SET NEW.facilityStatus = '0'; 31. END IF; 32. 33. END 34. // 35. DELIMITER; Figure 4.2 Trigger statement for before_facility_update
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 37 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Line 2 starts the create statement for the trigger. BEFORE UPDATE ON defines that the trigger is to be executed before update is done to the facility table. Line 3 defines that the scope of the trigger is executed for each row inserted. Line 4 defines the start of the trigger. Line 5 to line 9 defines the user defined variables used in the trigger. Line 10 to line 16 defines the scope of Point 1 mentioned above: If facility needs maintenance, move the facility to inventory and log this event. Line 18 to line 23 defines the scope of Point 2 mentioned above: If facility is operational, move the facility back to the center and log this event. Line 25 to line 31 defines the scope of Point 3 mentioned above: If facility needs to redeploy to another center, send it back to the inventory first. Line 33 defines the end of the trigger.
4.3.
STORED PROCEDURE STATEMENTS
The table below defines the stored procedure used for the system with a brief description of the stored procedure usage and its scope. Stored procedure Name
Description/Scope of stored procedure
System Objectives
AddFacility
Add a Facility
IS: Point1
InvToInventory
Move Facility to Inventory
IS: Point 3
InvToCenter
Move Facility to Center
IS: Point 4
InvChangeCenter
Change the Center of Facility
IS: Point 2
LogInventory
Logging of event in the inventory
IS: Point 1 to 4
AddSales
SA: Point 3 to 4
AddPromotionToCenter
Add a Sales record for LAN station and billiard facility type. Add a Sales record for an arcade card sales Add Promotion to a Center
SA: Point 1 to 2
AddPoints
Add points to the Member
ME: Point 1
AddSalesArcadeCard
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 38 of 81
SA: Point 3 to 4
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
RedeemItem
Redemption of item by Member
ME: Point 2
MemberPointChecking
Check for Member point expiry date
ME: Point 3
Table 4.2 Stored procedure description and scope
I have picked the stored procedure AddSales to explain, which has the most complex code. 1. DELIMITER // 2. CREATE PROCEDURE `AddSales` 3. ( 4. facNo INTEGER, 5. startTime TIME, 6. endTime TIME, 7. memNo INTEGER 8. ) 9. proc:BEGIN 10. SET @price = 0.0; 11. SET @facilityNo = facNo; 12. #Check IF member number is valid. IF not valid, leave procedure. Only NULL or valid member number is accepted. 13. IF memNo IS NOT NULL THEN 14. IF isMember(memNo) IS NOT NULL THEN 15. SET @memberNo = memNo; 16. SET @Price = getMemberPrice(@facilityNo); 17. ELSE 18. SELECT 'Procedure call ends. Member does not exist. ' AS Error; 19. LEAVE proc; 20. END IF; 21. ELSE 22. SET @memberNo = NULL; 23. SET @price = getNormalPrice(@facilityNo); 24. END IF; 25. 26. SET @centerNo = getFacilityCenter(@facilityNo); 27. IF @centerNo IS NOT NULL THEN 28. SET @facilityType = getFacilityType(@facilityNo); 29. IF @facilityType != 'arc' THEN 30. SET @amtpayable = calculatePayable(startTime,endTime,@price,@centerNo,@facilityType, @memberNo); 31. INSERT INTO sales VALUES (NULL,@facilityType,NOW(),@amtpayable,@memberNo,startTime,endTime, @facilityNo,NULL,@centerNo); 32. ELSE 33. SELECT 'Facility type is Arcade. Not Applicable for this procedure call.' AS Error; 34. END IF; 35. ELSE 36. SELECT 'Facility is in Inventory or invalid.' AS Error; 37. END IF; 38. END proc; 39. // ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 39 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
40. DELIMITER ; Figure 4.3 Stored procedure statement for Addsales
Line 2 starts the create statement for the stored procedure. Line 3 to line 8 defines the parameters needed for the stored procedure. Line 9 defines the start of the stored procedure with proc as the label for the block code. Line 10 and Line 11 initializes some user defined variables. Line 13 to Line 24 will set the price for a member or non member and the member number if any. The codes check if the member number is valid. If member number is not valid, LEAVE proc statement will exit the block code. Only NULL value or valid member number is accepted. Line 26 is used to get the center number of the facility. Line 27 check if the facility is in a center, then goes to line 28. If not in a center, goes to line 36. Line 28 gets the facility type of the facility. Line 29 to line34 checks if the facility type is not an Arcade, then calculate the payable using function calculatePayable and add the sales record. If it is an Arcade, then shows an error that this transaction is not applicable for arcade facility. Line 36 check if facility is not in a center, shows an error that this facility is in inventory. Line 38 defines the end of this stored procedure.
4.4.
FUNCTION STATEMENTS
Functions more or less works the same like stored procedure but function is used to return one specific value when called. Most of the functions I have are small function call which returns a value. I have picked the most complex function to explain. 1. DELIMITER // 2. CREATE FUNCTION `calculatePayable` (startTime TIME, endTime TIME, price DECIMAL(10,2), cenNo INTEGER, facType TEXT, memNo INTEGER) 3. RETURNS DECIMAL(10,2) 4. code: BEGIN 5. SET @centerNo = cenNo; 6. SET @memberNo = memNo; 7. SET @facilityType = facType; 8. SET @promoType = getPromotionType(@centerNo); ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 40 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
9. SET @minspent = getPromotionMinimumSpent(@centerNo); 10. SET @amtPayable = TIME_TO_SEC(TIMEDIFF(endTime,startTime))/3600 * price; 11. IF @memberNo IS NULL AND @promoType != 'arc' AND @promoType = @facilityType AND @amtPayable >= @minspent THEN 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
SET @rateType = getPromotionRateType(@centerNo); SET @rate = getPromotionRate(@centerNo); IF @rateType = 'per' THEN SET @amtPayable = @amtPayable - (@amtPayable*@rate/100); ELSE SET @amtPayable = @amtPayable - @rate; END IF; END IF; SET @result = CAST(@amtPayable AS DECIMAL(10,2)); RETURN @result; END code; // DELIMITER;
Figure 4.4 Function statement for calculatePayable
Line 2 starts the create statement for the function with the parameters needed for the function. Line 3 defines the return data type for this function Line 4 defines the start of the function with code as the label for the block of codes. Line 5 to 7 defines some user defined values required in the function Line 8 calls a function to obtain the promotion type. Line 9 calls a function to obtain the minimum expenditure to qualify for the promotion. Line 10 calculates the normal payable or member payable for the facility usage. Line 11 does a few checks to validate if the payable quality for the promotion discount. The criteria includes that the payable is not from a member, the promotion type is not for an Arcade, the promotion type matches the facility type and the minimum payable is at least met. Line 12 and line 13 gets the promotion rate type and rate respectively. Line 14 to line 18 calculates the discount to be given. Line 20 sets the value to be returned Line 21 returns the value to the caller. Line 22 defines the end of the function. ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 41 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
4.5.
VIEW STATEMENTS
Views are used to simplify complex queries. What’s more is that normal SELECT statement can be executed on the complex query if it is in a View. This make it very handy for coding functions which I shared by experience in the Critical Review and Reflections section of Chapter 6 Conclusion. I have created 2 Views. CREATE VIEW `facilitycenterpromoview` AS SELECT facilityNo AS facilityNo, centerNo AS centerNo, promotionNo AS promotionNo, facilityType AS facilityType, normalPrice AS normalPrice, memberPrice AS memberPrice, gameTitle AS arcadeGameTitle, genre AS arcadeGenre, name AS centerName, startDate AS promoStartDate, endDate AS promoEndDate, description AS promoDesc, rateType AS promoRateType, rate AS promoRate, minspent AS promoMinSpent, promoType as promoType FROM facility LEFT JOIN center USING (centerNo) LEFT JOIN centerpromotion USING (centerNo) LEFT JOIN promotion USING (promotionNo) LEFT JOIN game USING (gameNo) WHERE endDate >= CURDATE() OR endDate IS NULL; // Figure 4.5 View create statement for facilitycenterpromoview
This View shows the centers which has or does not has a promotion and the details on the current promotion. Only the current promotion for each center is retrieved. From this view, I can easily know which facility is in which center or in inventory and what promotion the center is having for the facility in that center. I have created functions based on this View. With the facility number, facilityNo, I can straight away obtain the promotion details if any without the need to know which center the facility is in or the promotion number.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 42 of 81
LEE CHANGJIN (K0604033)
5.
JAN08/BHICT/03
DATABASE TESTING
5.1.
ENTITY TESTING
For my tables, I have used auto increment for my primary keys. Hence at inserting, I either omit the primary key column (Figure 5.1) or set value to NULL if I did put it in (Figure 5.2). Both ways are successful when inserting.
Figure 5.1 Successful insert into table Facility by omitting the primary key.
Figure 5.2 Successful insert into table Facility using NULL for primary key.
When creating the tables, codes are used to define those columns that are primary key. This allows the DBMS to perform entity integrity checking. The DBMS will capture the error as shown in Figure 5.3 if there is a duplicate of primary key in the table when inserting data.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 43 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Figure 5.3 Unsuccessful inserting of data into table Facility.
5.2.
REFERENTIAL INTEGRITY TESTING
Likewise, the DBMS will handle the referential integrity checking. To demonstrate, I have attempted to insert an invalid gameNo foreign key. The result of inserting is unsuccessful as shown in Figure 5.4. This is possible when the foreign key constraint is defined during creating of tables.
Figure 5.4 Unsuccessful insert into table Facility using invalid foreign key.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 44 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
5.3.
DATA DOMAIN TESTING
Data domain constraint checking can be done by the DBMS when the data type is defined in the schema when creating the tables. For demonstration, I have attempted to insert a text value on a decimal data domain. The outcome shown in Figure 5.5 demonstrates that the inserting is unsuccessful.
Figure 5.5 Unsuccessful insert into table Facility using wrong data type.
5.4.
CARDINALITY TESTING
In my ER diagram, it is optional for a Facility to be an Arcade. If a Facility is an Arcade, it must have a Game. I have combined the Facility entity and Arcade entity into one table. Meaning when inserting a Facility as an Arcade, it must provide the value for gameNo. Refer to the schema for table Facility, value gameNo is an optional value as it can be NULL. Normal insert query is not able to perform cardinality testing. Hence, I have used trigger, before_facility_insert, to capture this constraint and manipulate it into a referential integrity error to prevent the inserting. As MySQL does not support INSTEAD OF functionality like MSSQL for trigger, I have used the following code manipulation in my trigger for capturing this constraint which give an error shown in figure 5.6 when inserting.
CREATE TRIGGER `before_facility_insert` BEFORE INSERT ON facility FOR EACH ROW BEGIN …… ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 45 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
IF NEW.facilityType = 'arc' AND NEW.gameNo IS NULL THEN SET NEW.gameNo = 'gameNo_not_defined'; END IF; ……
Figure 5.6 Unsuccessful insert with referential integrity error for cardinality checking.
On the other hand, Figure 5.2 demonstrates a successful insert query when insert a non Arcade facility (LAN Station) with gameNo value as NULL.
5.5.
SYSTEM OBJECTIVE CHECKLIST
This checklist is an overview of which triggers and stored procedures are used to fulfill the system objective. There are a couple of common functions which are not listed as those functions are called within the trigger or stored procedures. Please refer to the Appendix A: SQL Schema for more information on the functions. Inventory System System Objective
Trigger/Stored procedure Used
1. The system will be able to add new facility records into the inventory. The system will log this event.
Store: AddFacility Trigger: before_facility_insert Trigger: after_facility_insert Store: LogInventory Store: InvChangeCenter Trigger: before_facility_update Store: LogInventory
2. The system will be able to change where the facility is to be deployed. If facility is currently in a center, changing the
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 46 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
center will move the facility to the inventory to be redeployed. The system will log this event. 3. The system will be able to move facility records from centers that require maintenance servicing back to the inventory. The system will log this event.
Store: InvToInventory Trigger: before_facility_update Store: LogInventory
4. The system will be able to move facility record back to the center it should be deployed to when the maintenance servicing is done. The system will log this event.
Store: InvToCenter Trigger: before_facility_update Store: LogInventory
Table 5.1 Codes that fulfill Inventory system objectives
Sales System Objective
Trigger/ Stored procedure Used
1. The system will be able to register one particular promotion to a center.
Store: AddPromotionToCenter
2. The system will be able to ensure that a center can only have one promotion at any one time.
Store: AddPromotionToCenter
3. The system will be able to generate sales Store: AddSales OR record on Store: AddSalesArcadeCard a. A normal basis when there is no promotion and the customer is not a member. b. A membership basis if the customer is a member. c. A promotion basis if the center is having a promotion. 4. The system will be able to ensure that the promotion privilege will not be applicable if the sale is from a member.
Store: AddSales OR Store: AddSalesArcadeCard
Table 5.2 Codes that fulfill Sales system objective
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 47 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Member System Objective
Trigger/ Stored procedure Used
1. The system will be able to accumulate the member points for any sales generated by member where for every S$1 spent, 10 points will be accumulated.
Trigger: after_sales_insert Store: AddPoints
2. The system will be able to ensure that the member has sufficient member points for deduction before registering any redemption made by the member.
Store: RedeemItem Store: AddPoints
3. The system will be able to reset the member points back to zero when the member point expiry date has past. A new member point expiry date will be given by the system.
Store: MemberPointChecking
Table 5.3 Codes that fulfill member system objectives
5.6.
SYSTEM OBJECTIVE TESTING
With the checklist in the previous section, I have conducted testing for each of the objectives to demonstrate that the objectives are met. I have combined some of the objectives as they are linked or is of similar functionality. Inventory System, SI: Point 1 The system will be able to add new facility records into the inventory. The system will log this event. Statement for execution: A. CALL AddFacility(‘lan’, 3, 2.5, NULL); Result:
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 48 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
As shown in the screen captures below, the facility is successfully inserted and is in the inventory. Logging of this event is also successfully. This demonstrates that the system fulfills Point 1.
Figure 5.7a ‐ Successful executing of statement.
Figure 5.7b ‐ Facility1 is inserted.
Figure 5.7c ‐ Facility1 is in the inventory.
Figure 5.7d ‐ This event is logged.
Inventory System, SI: Point 2 The system will be able to change where the facility is to be deployed. If facility is currently in a center, changing the center will move the facility to the inventory to be redeployed. The system will log this event. Statement for execution: A. CALL InvChangeCenter (1,1); B. CALL InvChangeCenter (2,2); Result: ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 49 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Currently, there are 2 facilities. Facility1 is in inventory and Facility2 is in Center 1. Facility1 does not have any Center appointed to it.
Figure 5.8a ‐ Facility1 has not allocated a center and Facility2 is in a center.
Figure 5.8b ‐ Facility1 is in inventory with no center allocated yet.
Executing the statements demonstrated that the objective is met. Facility1 now is in inventory and to be deployed to Center1. Facility2 is moved back to inventory and to be deployed to Center 2 which is shown in the inventory log as well. This demonstrates that the system fulfills Point 2.
Figure 5.8c ‐ Facility2 is sent back to inventory upon changing center.
Figure 5.8d ‐ Facility2 is in the inventory. Both facilities are allocated a center each.
Figure 5.8e ‐ This event is logged.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 50 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Inventory System, SI: Point 3 & Point 4 3) The system will be able to move facility records from centers that require maintenance servicing back to the inventory. The system will log this event. 4) The system will be able to move facility record back to the center it should be deployed to when the maintenance servicing is done. The system will log this event. Statement for execution: A. CALL InvToCenter(1); Result: I have used Point 4 to do the testing as both serve similar functionality. Currently both facilities are in the inventory. Executing the statement shows that Facility1 is sent to Center1 and this event is logged. This demonstrates that the system fulfills Point 4 as well as Point 3.
Figure 5.9a ‐ Facility1 is in Center1 after executing the statement.
Figure 5.9b ‐ Facility1 is not in the inventory after executing the statement.
Figure 5.9c ‐ This event is logged.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 51 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Sales System, SA: Point 1 & Point 2 1) The system will be able to register one particular promotion to a center. 2) The system will be able to ensure that a center can only have one promotion at any one time. Statement for execution: A. CALL AddPromotionToCenter(1, 7, CURDATE(), DATE_ADD(CURDATE(), INTERVAL 1 WEEK)); Result: Executing the statement adds Promotion7 to Center1 for 1 week starting from the current date as shown below. From the View centerpromoview, it shows that Center1 is currently having Promotion7. This demonstrates that the system fulfills Point 1.
Figure 5.10a ‐ Center1 is having a promotion.
Executing the statement, adding other promotion to the current center causes an error message stating that Center1 is currently having a promotion as shown below. The attempted adding of the promotion is ignored. This demonstrates that the system fulfills Point 2.
Figure 5.10b ‐ Center1 cannot have another promotion.
Sales System, SA: Point 3 & Point 4 3) The system will be able to generate sales record on a) A normal basis when there is no promotion and the customer is not a member. b) A promotion basis if the center is having a promotion. c) A membership basis if the customer is a member. ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 52 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
4) The system will be able to ensure that the promotion privilege will not be applicable if the sale is from a member. Statement for execution: A. CALL AddSales(3, '11:00:00', '15:00:00', NULL); B. CALL AddSales(1, '11:00:00', '15:00:00', NULL); C. CALL AddSales(1, '11:00:00', '18:00:00', NULL); D. CALL AddSales(1, '11:00:00', '15:00:00', 1); E. CALL AddSales(1, '11:00:00', '18:00:00', 1); Result: Currently, Center1 is having Promotion7 which states that any LAN station usage of $15 and more will have a 10% deduction. Executing Statement (A) generates sales record for Facility3, a Billiard Table. 4 hours of billiard at $7 per hours cost $28 and the center is having promotion for LAN station. This demonstrate the system fulfill the objective of Point 3(a).
Figure 5.11a ‐ Sales record generated from executing Statement (A).
Executing Statement (B) generates sales record for Facility1, a LAN station. 4 hours of LAN at $3 per hours cost $12 but it is not given a 10% discount as the sales did not have a minimum expenditure of $15. Executing Statement (C) shows a 10% discount otherwise for a 7hours LAN. This demonstrate the system fulfill the objective of Point 3(b).
Figure 5.11b ‐ New sales record generated from executing Statement (B) & (C).
Executing Statement (D) generates sales record for Facility1, a LAN station. 4 hours of LAN at $2.50 per hours cost $10 for member. This demonstrate the system fulfill the objective of Point 3(c). Executing Statement (E) generates sales record for Facility1, a LAN station. 7 hours of LAN at $2.50 per hours cost $17.50 for member. Even though the center is having promotion for ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 53 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
LAN, the promotion privilege is not applicable for a sales record from a member. This demonstrate the system fulfill the objective of Point 4.
Figure 5.11c ‐ New sales record generated from executing Statement (D) & (E).
Member System, ME: Point 1 The system will be able to accumulate the member points for any sales generated by member where for every S$0.10 spent, 1 point will be accumulated. Statement for execution: A. CALL AddSales(3, '11:00:00', '15:00:00', 1); Result: As shown in the screen capture below, Member1 currently has 2275 points.
Figure 5.12a ‐ Member1 currently has 2275 points.
Executing Statement (A) will generate a sales record of $24.80 for Member1. Hence, a total of 248 points is added to Member1’s points. Before, Member1 has total points of 2275 adding 248 from the Billiard usage to give 2523. This demonstrate the system fulfill the objective of Point 1.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 54 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Figure 5.12b ‐ Generate a sales record of $24.80 for Member1.
Figure 5.12c ‐ Member1 now has 2523 points after paying for the Billiard usage.
Member System, ME: Point 2 The system will be able to ensure that the member has sufficient member points for deduction before registering any redemption made by the member. Statement for execution: A. CALL RedeemItem(1,14); B. CALL RedeemItem(1,15); Result: As shown in the screen capture below, Item14 cost 1000 points and Item15 cost 5000 points.
Figure 5.13a ‐ Points cost for Item14 and Item15
In Figure 5.12c shows that Member1 currently has 2523 points. After executing Statement (A), 1000 points is deducted from Member1 and the redemption is registered. ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 55 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Figure 5.13b ‐ Member1 now has 1523 after redeeming Item14.
Figure 5.13c ‐ The redemption is recorded.
Next, executing Statement (B) shows that Member1 does not have enough points to redeem Item15 and the redemption is ignored. This demonstrate the system fulfill the objective of Point 2.
Figure 5.13d ‐ Member1 does not have enough points to redeem Item15.
Member System, ME: Point 3 The system will be able to reset the member points back to zero when the member point expiry date has past. A new member point expiry date will be extended by 1 year. Statement for execution: A. CALL MemberPointChecking(); Result: Member3’s points expiry date is expired. After executing Statement (A), Member3 points is reset to 0 and the points expiry date is extended by 1 year. This demonstrate the system fulfill the objective of Point 3.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 56 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Figure 5.14a ‐ Member3 points and expiry date before executing Statement (A).
Figure 5.14b ‐ Member3 points and expiry date after executing Statement (A).
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 57 of 81
LEE CHANGJIN (K0604033)
6.
JAN08/BHICT/03
CONCLUSION
6.1.
CRITICAL REVIEW & REFLECTIONS
Creating Functions based on Views While I was creating the functions for my system, I realized that if I need to make any changes to the table structure, I will need to tediously modify all the functions which are based on that table e.g. table name. Moreover, in some logic, I need to call 2 functions in order to get the data. For example, a center can have promotion. Hence, to get the promotion data of that center, I will to use the center number to calls a function to obtain the promotion number, with it calls another function to obtain data relating to that promotion. I was thinking aloud, hey this is rather not efficient. How can I make the coding friendlier in the long run? That is when Views come into my mind. I have recoded my functions to query from the Views. When there are any changes to the individual table structure used to create that View, I just need to modify the View instead of all the functions rely on that table. Modifying one time than many, it really makes code modification easier. By making complex query into View, I can do simply SELECT query on the View to obtain the data I want. From the example mentioned earlier, I have created View centerpromoview which left join center and promotion data. Hence with the center number, I can call one function to obtain promotion data if the center has one. Refer to the View centerpromoview in Appendix A: SQL Schema. Project Management Vs. Time Management Even though I have taken up Project Management course in UniSIM, I still need tremendous practice and hands on to be good in it. Single project management is still manageable for me. However, I am in a situation where I need to manage multiple projects other than my academic project. At time when time is a constraint, I need to prioritize and jeopardize the time allocated for my academic project. I still need to improve on my planning and time management to better control my situation. How I can improve on this is to learn and practice risk management. Conducting Interviews Before going for the interview with the business manager of Valibel Technologies Pte Ltd for requirement gathering, I have planned some interview questions to be asked. I thought I am ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 58 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
well prepared with the list of questions and I can ask systematically. However, I was wrong. Even though I had the questions orderly listed to be asked, the tendency of hopping between questions is still high. This is due to interviewee sometime talks about information related to another question instead of the one being asked. Then I got out of hand with the questions I want to ask. I should have made the questions into a checklist which is better to manage. How I can improve is the make a template for interview questions, and improves on it as I conduct more requirement gathering. With the template, it can be more efficiency in future interviews. Using MySQL as the DBMS I have chosen MySQL over other DBMS is because I am some prior knowledge in MySQL then other DBMS. Learning to create triggers and stored procedure in MySQL will be an asset to me. However, doing this project in MySQL gave me an insight of the limitation of this DBMS. For the DBMS to have referential integrity, I have to use InnoDB storage engine. Some limitation is that MySQL does not support CHECK constraints on domain data and the trigger does not support INSTEAD OF functionality like MSSQL. As MySQL is an open source database and is very widely used, users will want improvements and all this common functionality among the different databases might be in the MySQL development pipeline. Nevertheless, it is better to measure the scope and objectives of the system and to evaluate before deciding on which DBMS to use for the project. Database coding and syntax Though I love programming, but I have never really gone in depth for database programming. For my practice, I usually would program a web application to interact with the database, and the database is just mainly for querying (SELECT, UPDATE and DELETE). Most of the checking will be done by the web server before interacting with the database to execute the query. From this project, I have learnt much on database programming using trigger and stored procedure which will be an asset to me when I take on future web application projects. Writing a good report English language is one of my worst subjects. Hence when doing this report, I do not have the confidence to produce a good report. Even though, I have read up on materials on how to write a good report, language flow and structure still play a major part in the reporting. What is the point of doing the report if the reader gets the wrong meaning? This is one area I am weak in and need great practices to improve. ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 59 of 81
LEE CHANGJIN (K0604033)
6.2.
JAN08/BHICT/03
RECOMMENDATIONS
Before the birth of this project idea, I am thinking of a general database system which can accommodate any general chain stores. The system will be able to give trend analysis. However, this project is focus on database design, creating triggers and stored procedures. Showing trend analysis becomes rather inapplicable for this project as trend analysis requires complex join of normal querying. Trend analysis module with GUI can be an add‐on project to this database system. Other areas which this project can look into include the security issue of using MySQL and deployment of the database system in a distributed environment.
6.3.
CONCLUSION
The database system I have done for this project has met its system objectives. All this is possible with triggers and stored procedures call to check on the constraints of the system objectives. It is a challenge to me as this project is purely on database scripting which I am not good in it and the ICT315 course which I took is a very general introduction into database which did not really go in depth on triggers and stored procedures. Although I am familiar with web server scripting like PHP, I cannot use it for this project. Nevertheless, it is a good experience to explore into database scripting. In my report, section 1.6 Methodology Adopted, I shared how I did my project. In my general view, what was planned before effects what I was doing later. If there does not have a development lifecycle to serve me as a guideline, I would have been in a mess, not knowing where to carry on. A good planning definitely leads to better and efficient work. From this project, I have developed a learning process for myself. For area where I am new or need improvement on, I will need to conduct research on the related area, understand the information I am researching on, practices with hands on, evaluate what I have hands on and done, then research on area I am weak in or unsure of. So this learning process iterates at every stage in the development lifecycle, and I should improve on the process with other small sub processes that I have learnt. In this way or another way, putting what I have learnt into practice is the best way to strengthen my areas. (About 7500 words for content without include the header, caption, figures and tables.)
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 60 of 81
LEE CHANGJIN (K0604033)
7.
JAN08/BHICT/03
APPENDICES
7.1.
APPENDIX A: SQL SCHEMA
CREATE TABLE SCHEMA Table: game DROP TABLE IF EXISTS `game`; CREATE TABLE `game` ( `gameNo` int(10) unsigned NOT NULL auto_increment, `gameTitle` text NOT NULL, `genre` text NOT NULL, PRIMARY KEY (`gameNo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: center DROP TABLE IF EXISTS `center`; CREATE TABLE `center` ( `centerNo` int(10) unsigned NOT NULL auto_increment, `name` text NOT NULL, PRIMARY KEY (`centerNo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: promotion DROP TABLE IF EXISTS `promotion`; CREATE TABLE `promotion` ( `promotionNo` int(10) unsigned NOT NULL auto_increment, `description` text NOT NULL, `ratetype` enum('amt','per') NOT NULL, `rate` int(3) unsigned NOT NULL, `minspent` int(2) NOT NULL default '0', `promoType` enum('lan','bill','arc','all') NOT NULL, PRIMARY KEY (`promotionNo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: member DROP TABLE IF EXISTS `member`; CREATE TABLE `member` ( `memberNo` int(10) unsigned NOT NULL auto_increment, `name` text NOT NULL, `identityNo` text NOT NULL, `gender` enum('M','F') NOT NULL, `dob` date NOT NULL, `address` text NOT NULL, `email` text NOT NULL, `contact` int(10) unsigned NOT NULL, `occupation` text NOT NULL, `memberCardNo` int(10) unsigned NOT NULL, `joinedDate` date NOT NULL, `points` int(10) unsigned NOT NULL, ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 61 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
`pointsExpiry` date NOT NULL, PRIMARY KEY (`memberNo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: arcadecard DROP TABLE IF EXISTS `arcadecard`; CREATE TABLE `arcadecard` ( `arcadeCardNo` int(10) unsigned NOT NULL auto_increment, `normalCardPrice` decimal(5,2) NOT NULL, `memberCardPrice` decimal(5,2) NOT NULL, `cardValue` decimal(5,2) NOT NULL, PRIMARY KEY (`arcadeCardNo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: redeemitem DROP TABLE IF EXISTS `redeemitem`; CREATE TABLE `redeemitem` ( `redeemItemNo` int(10) unsigned NOT NULL auto_increment, `redeemDesc` text NOT NULL, `pointsCost` int(10) unsigned NOT NULL, PRIMARY KEY (`redeemItemNo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: facility DROP TABLE IF EXISTS `facility`; CREATE TABLE `facility` ( `facilityNo` int(10) unsigned NOT NULL auto_increment, `centerNo` int(10) unsigned default NULL, `facilityType` enum('lan','bill','arc') NOT NULL, `facilityStatus` enum('0','1') NOT NULL default '0', `normalPrice` decimal(5,2) NOT NULL default '0.00', `MemberPrice` decimal(5,2) default '0.00', `gameNo` int(10) unsigned default NULL, PRIMARY KEY (`facilityNo`), KEY `Facility_Index1` USING BTREE (`centerNo`), KEY `Facility_Index2` USING BTREE(`gameNo`), CONSTRAINT `FK_facility_1` FOREIGN KEY (`centerNo`) REFERENCES `center` (`centerNo`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `FK_facility_2` FOREIGN KEY (`gameNo`) REFERENCES `game` (`gameNo`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: inventory DROP TABLE IF EXISTS `inventory`; CREATE TABLE `inventory` ( `facilityNo` int(10) unsigned NOT NULL, `toDeployAt` int(10) unsigned default NULL, PRIMARY KEY (`facilityNo`), KEY `Inventory_Index1` USING BTREE (`facilityNo`), CONSTRAINT `FK_inventory_1` FOREIGN KEY (`facilityNo`) REFERENCES `facility` (`facilityNo`) ON DELETE CASCADE ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 62 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: inventorylog DROP TABLE IF EXISTS `inventorylog`; CREATE TABLE `inventorylog` ( `facilityNo` int(10) unsigned NOT NULL, `invLogDatetime` datetime NOT NULL, `invDescription` text NOT NULL, PRIMARY KEY (`facilityNo`,`invLogDatetime`), KEY `InventoryLog_Index1` USING BTREE (`facilityNo`), CONSTRAINT `FK_inventorylog_1` FOREIGN KEY (`facilityNo`) REFERENCES `facility` (`facilityNo`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: centerpromotion DROP TABLE IF EXISTS `centerpromotion`; CREATE TABLE `centerpromotion` ( `centerNo` int(10) unsigned NOT NULL, `promotionNo` int(10) unsigned NOT NULL, `startDate` datetime NOT NULL, `endDate` datetime NOT NULL, PRIMARY KEY (`centerNo`,`promotionNo`,`startDate`,`endDate`), KEY `CenterPromotion_Index1` USING BTREE (`centerNo`), KEY `CenterPromotion_Index2` USING BTREE (`promotionNo`), CONSTRAINT `FK_centerpromotion_1` FOREIGN KEY (`centerNo`) REFERENCES `center` (`centerNo`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_centerpromotion_2` FOREIGN KEY (`promotionNo`) REFERENCES `promotion` (`promotionNo`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: sales DROP TABLE IF EXISTS `sales`; CREATE TABLE `sales` ( `salesNo` int(10) unsigned NOT NULL auto_increment, `salesType` enum('lan','bill','arc') NOT NULL, `salesDatetime` datetime NOT NULL, `amtPayable` decimal(10,2) NOT NULL, `memberNo` int(10) unsigned default NULL, `startTime` time NULL, `endTime` time NULL, `facilityNo` int(10) unsigned default NULL, `arcadeCardNo` int(10) unsigned NULL, `centerNo` int(10) unsigned default NULL, PRIMARY KEY (`salesNo`), KEY `Sales_Index1` USING BTREE (`memberNo`), KEY `Sales_Index2` USING BTREE (`facilityNo`), KEY `Sales_Index3` USING BTREE (`arcadeCardNo`), KEY `Sales_Index4` USING BTREE (`centerNo`), CONSTRAINT `FK_sales_1` FOREIGN KEY (`memberNo`) REFERENCES `member` (`memberNo`) ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 63 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `FK_sales_2` FOREIGN KEY (`facilityNo`) REFERENCES `facility` (`facilityNo`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `FK_sales_3` FOREIGN KEY (`arcadeCardNo`) REFERENCES `arcadecard` (`arcadeCardNo`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `FK_sales_4` FOREIGN KEY (`centerNo`) REFERENCES `center` (`centerNo`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Table: redemption DROP TABLE IF EXISTS `redemption`; CREATE TABLE `redemption` ( `redeemDatetime` datetime NOT NULL, `redeemItemNo` int(10) unsigned NOT NULL, `memberNo` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`redeemDatetime`,`redeemItemNo`,`memberNo`), KEY `Redemption_Index1` USING BTREE (`redeemItemNo`), KEY `Redemption_Index2` USING BTREE (`memberNo`), CONSTRAINT `FK_redemption_1` FOREIGN KEY (`memberNo`) REFERENCES `member` (`memberNo`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `FK_redemption_2` FOREIGN KEY (`redeemItemNo`) REFERENCES `redeemitem` (`redeemItemNo`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE VIEWS SCHEMA
View: centerpromoview DELIMITER // DROP VIEW IF EXISTS `centerpromoview` // #Showing the centers which has or does not has a promotion and the details on the current promotion. Only the current promotion for each center is retrieved. CREATE VIEW `centerpromoview` AS SELECT centerNo AS centerNo, promotionNo AS promotionNo, name AS centerName, startDate AS promoStartDate, endDate AS promoEndDate, description AS promoDesc, rateType AS promoRateType, rate AS promoRate, minspent AS promoMinSpent, promoType as promoType ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 64 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
FROM center LEFT JOIN centerpromotion USING (centerNo) LEFT JOIN promotion using (promotionNo) WHERE endDate >= CURDATE() OR endDate IS NULL; // DELIMITER ;
View: facilitycenterpromoview DELIMITER // DROP VIEW IF EXISTS `facilitycenterpromoview` // #Showing the facility which has or does not has a promotion and the details on the current promotion and the center which the facility is in. Only the current promotion for each center is retrieved. CREATE VIEW `facilitycenterpromoview` AS SELECT facilityNo AS facilityNo, centerNo AS centerNo, promotionNo AS promotionNo, facilityType AS facilityType, normalPrice AS normalPrice, memberPrice AS memberPrice, gameTitle AS arcadeGameTitle, genre AS arcadeGenre, name AS centerName, startDate AS promoStartDate, endDate AS promoEndDate, description AS promoDesc, rateType AS promoRateType, rate AS promoRate, minspent AS promoMinSpent, promoType as promoType FROM facility LEFT JOIN center USING (centerNo) LEFT JOIN centerpromotion USING (centerNo) LEFT JOIN promotion USING (promotionNo) LEFT JOIN game USING (gameNo) WHERE endDate >= CURDATE() OR endDate IS NULL; // DELIMITER ;
CREATE TRIGGER SCHEMA Trigger: before_facility_insert DELIMITER // DROP TRIGGER IF EXISTS `before_facility_insert` // CREATE TRIGGER `before_facility_insert` BEFORE INSERT ON facility FOR EACH ROW BEGIN SET @center = NEW.centerNo; SET NEW.centerNo = NULL; IF NEW.facilityStatus 0 THEN SET NEW.facilityStatus = '0'; END IF; IF NEW.facilityType 'arc' THEN SET NEW.gameNo = NULL; END IF; IF NEW.facilityType = 'arc' AND NEW.gameNo IS NULL THEN SET NEW.gameNo = 'gameNo_not_defined'; END IF; ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 65 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
END // DELIMITER;
Trigger: after_facility_insert DELIMITER // DROP TRIGGER IF EXISTS `after_facility_insert` // CREATE TRIGGER `after_facility_insert` AFTER INSERT ON facility FOR EACH ROW BEGIN SET @newFacility = NEW.facilityNo; INSERT INTO inventory (facilityNo, toDeployAt) VALUES (@newFacility,@center); CALL LogInventory(@newFacility,@center,1); END // DELIMITER;
Trigger: before_facility_update DELIMITER // DROP TRIGGER IF EXISTS `before_facility_update` // CREATE TRIGGER `before_facility_update` BEFORE UPDATE ON facility FOR EACH ROW BEGIN SET @facilityStatus = NEW.facilityStatus; SET @facilityStatusOld = OLD.facilityStatus; SET @facilityNo = NEW.facilityNo; SET @centerNo = NEW.centerNo; SET @centerNoOld = OLD.centerNo; IF @facilityStatus = 0 THEN INSERT INTO inventory (facilityNo, toDeployAt) VALUES (@facilityNo, @centerNo); CALL LogInventory(@FacilityNo,@centerNo,2); SET NEW.centerNo = NULL; END IF; IF @facilityStatus = 1 AND @facilityStatus != @facilityStatusOld THEN SET NEW.centerNo = (SELECT toDeployAt FROM inventory WHERE facilityNo = @facilityNo); DELETE FROM inventory WHERE facilityNo = @facilityNo; CALL LogInventory(@facilityNo,NEW.centerNo,3); END IF; IF @centerNoOld @centerNo AND @facilityStatus = '1' THEN INSERT INTO inventory (facilityNo, toDeployAt) VALUES (@facilityNo, @centerNo); CALL LogInventory(@facilityNo,@centerNo,4); SET NEW.centerNo = NULL; SET NEW.facilityStatus = '0'; END IF; END // DELIMITER;
Trigger: after_sales_insert DELIMITER // DROP TRIGGER IF EXISTS `after_sales_insert` // CREATE TRIGGER `after_sales_insert` AFTER INSERT ON sales ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 66 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
FOR EACH ROW BEGIN CALL AddPoints(NEW.memberNo,FLOOR(NEW.amtpayable*10)); END // DELIMITER;
CREATE STORED PROCEDURE SCHEMA Stored procedure: AddFacility DELIMITER // DROP PROCEDURE IF EXISTS `AddFacility` // CREATE PROCEDURE `AddFacility` ( facilityType CHAR(4), normalPrice DECIMAL(5,2), memberPrice DECIMAL(5,2), gameNo INTEGER ) BEGIN IF facilityType NOT IN ('lan','bill','arc') THEN SELECT 'Facility Type is invalid. Use \'lan\', \'bill\' or \'arc\'' AS Error; ELSEIF facilityType = 'arc' AND gameNo IS NULL THEN SELECT 'Please provide game number for the arcade facility.' AS Error; ELSE INSERT INTO `facility` ( `facilityType`, `normalPrice`, `MemberPrice`, `gameNo` ) VALUES (facilityType, normalPrice, memberPrice, gameNo); END IF; END// DELIMITER ;
Stored procedure: InvToInventory DELIMITER // DROP PROCEDURE IF EXISTS `InvToInventory` // CREATE PROCEDURE `InvToInventory` ( facNo INTEGER ) BEGIN SET @facilityNo = facNo; If getFacilityCenter(@facilityNo) IS NOT NULL THEN UPDATE facility SET facilityStatus = '0' WHERE facilityNo = @facilityNo; ELSE SELECT 'Facility is already in inventory.' AS Error; END IF; END// DELIMITER ; ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 67 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Stored procedure: InvToCenter DELIMITER // DROP PROCEDURE IF EXISTS `InvToCenter` // CREATE PROCEDURE `InvToCenter` ( facNo INTEGER ) proc:BEGIN SET @facilityNo = facNo; IF getDeployAt(@facilityNo) IS NULL THEN SELECT 'Facility has not set which center to deploy to.' AS Error; LEAVE proc; END IF; If getFacilityCenter(@facilityNo) IS NULL THEN UPDATE facility SET facilityStatus = '1' WHERE facilityNo = @facilityNo; ELSE SELECT 'Facility is already in a center.' AS Error; END IF; END proc; // DELIMITER ;
Stored procedure: InvChangeCenter DELIMITER // DROP PROCEDURE IF EXISTS `InvChangeCenter` // CREATE PROCEDURE `InvChangeCenter` ( facNo INTEGER, cenNo INTEGER ) BEGIN SET @facilityNo = facNo; SET @changeCenter = cenNo; If getFacilityCenter(@facilityNo) IS NULL THEN UPDATE inventory SET toDeployAt = @changeCenter WHERE facilityNo = @facilityNo; ELSE UPDATE facility SET centerNo = @changeCenter WHERE facilityNo = @facilityNo; END IF; END// DELIMITER ;
Stored procedure: LogInventory DELIMITER // DROP PROCEDURE IF EXISTS `LogInventory` // CREATE PROCEDURE `LogInventory` ( facilityNo INTEGER, centerNo INTEGER, logType INTEGER ) BEGIN DECLARE description TEXT; IF logType != '' THEN SET @facilityType = (SELECT getFacilityName(facilityNo)); ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 68 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
SET @centerName = (SELECT getCenterName(centerNo)); CASE logType WHEN 1 THEN SET description = CONCAT('Facility ',facilityNo,' (', @facilityType,') is added to inventory.'); WHEN 2 THEN SET description = CONCAT('Facility ',facilityNo,' (', @facilityType,') is sent to inventory for maintainance.'); WHEN 3 THEN SET description = CONCAT('Facility ',facilityNo,' (', @facilityType,') is sent back to Center ', centerNo, ' (',@centerName,').'); WHEN 4 THEN SET description = CONCAT('Facility ',facilityNo,' (', @facilityType,') is sent back to inventory to be sent to Center ', centerNo, ' (',@centerName,').'); END CASE; INSERT INTO inventorylog VALUES (facilityNo, NOW(), description); END IF; END // DELIMITER;
Stored procedure: AddPoints DELIMITER // DROP PROCEDURE IF EXISTS `AddPoints` // CREATE PROCEDURE `AddPoints` ( memNo INTEGER, pts INTEGER ) proc:BEGIN SET @memberNo = memNo; SET @points = pts; UPDATE member SET points = points + @points WHERE memberNo = @memberNo; END proc; // DELIMITER ;
Stored procedure: RedeemItem DELIMITER // DROP PROCEDURE IF EXISTS `RedeemItem` // CREATE PROCEDURE `RedeemItem` ( memNo INTEGER, reItem INTEGER ) proc:BEGIN SET @memberNo = memNo; SET @redeemItemNo = reItem; #Get the points to redeem the redeem item and check if redeem item is exist. SET @pointsRedeemed = (SELECT getRedeemItemPoints(@redeemItemNo)); IF @pointsRedeemed IS NULL THEN SELECT 'Procedure call ends. Redeem Item does not exist. ' AS Error; LEAVE proc; END IF; #Get the points of the member and check if member is exist. SET @pointsLeft = (SELECT getMemberPoints(@memberNo)); ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 69 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
IF @pointsLeft IS NULL THEN SELECT 'Procedure call ends. Member does not exist. ' AS Error; LEAVE proc; END IF; IF @pointsLeft > @pointsRedeemed THEN INSERT INTO redemption VALUES (NOW(),@redeemItemNo,@memberNo); CALL AddPoints(@memberNo,-@pointsRedeemed); ELSE SELECT 'Member does not have enough points to redeem the item.' AS Error; END IF; END proc; // DELIMITER ;
Stored procedure: MemberPointChecking DELIMITER // DROP PROCEDURE IF EXISTS `MemberPointChecking` // CREATE PROCEDURE `MemberPointChecking` ( ) proc:BEGIN UPDATE member SET points = 0, pointsExpiry = DATE_ADD(pointsExpiry,INTERVAL 1 YEAR) WHERE pointsExpiry = @minspent THEN SET @rateType = getPromotionRateType(@centerNo); SET @rate = getPromotionRate(@centerNo); IF @rateType = 'per' THEN SET @price = @price - (@price*@rate/100); ELSE SET @price = @price - @rate; END IF; ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 71 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
END IF; END IF; INSERT INTO sales VALUES (NULL,'arc',NOW(),@price,@memberNo,NULL,NULL,NULL,@arcadeCardNo,@cent erNo); ELSE SELECT 'Arcade Center does not exist.' AS Error; END IF; END proc; // DELIMITER ;
Stored procedure: AddPromotionToCenter DELIMITER // DROP PROCEDURE IF EXISTS `AddPromotionToCenter` // CREATE PROCEDURE `AddPromotionToCenter` ( cenNo INTEGER, promoNo INTEGER, startDate DATE, endDate DATE ) proc:BEGIN SET @centerNo = cenNo; SET @promotionNo = promoNo; IF getCenterPromotion(@centerNo) IS NULL THEN INSERT INTO centerpromotion VALUES (@centerNo,@promotionNo,startDate,endDate); ELSE SELECT CONCAT('Center ', @centerNo, ' is currently having promotion.') AS Error; END IF; END proc; // DELIMITER ;
7.2.
APPENDIX B: SQL TABLE POPULATION
DEFAULT DATA POPULATION Default Data Population: arcadecard INSERT INTO arcadecard (arcadeCardNo, normalCardPrice, memberCardPrice, cardValue) VALUES (1, 2, 2, 2), (2, 5, 4, 5), (3, 10, 8, 10), (4, 15, 10, 15), (5, 25, 18, 25), (6, 50, 30, 50);
Default Data Population: center ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 72 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
INSERT INTO center (centerNo, name) VALUES (1, 'Funland Bedok'), (2, 'Funland Bishan'), (3, 'Funland East Coast'), (4, 'Funland Educare Centre'), (5, 'Funland Sembawang'), (6, 'Funland Yishun 10'), (7, 'Cyberbyte Bugis'), (8, 'Cyberbyte Snookerium Clementi'), (9, 'Cyberbyte Snookerium Paradiz'), (10, 'Ang Mo Kio Snookerium');
Default Data Population: game INSERT INTO game (gameNo, gameTitle, genre) VALUES (1, 'Time Crisis 2', 'Shooting'), (2, 'Time Crisis 3', 'Shooting'), (3, 'Time Crisis 4', 'Shooting'), (4, 'House Of The Dead 3', 'Shooting'), (5, 'House Of The Dead 4', 'Shooting'), (6, 'Initial D 3', 'Racing'), (7, 'Initial D 4', 'Racing'), (8, 'Midnight Tune 3', 'Racing'), (9, 'Pinball Fire', 'Pinball Machine '), (10, 'Raw Thrills', 'Racing'), (11, 'Stacker', 'Prize Merchandiser'), (12, 'Grab A Doll', 'Claw & Skill Crane Machine'), (13, 'Lollipop Lucky', 'Claw & Skill Crane Machine'), (14, 'The Three Kingdoms', 'Platform'), (15, 'Football Championship', 'Sports');
Default Data Population: member INSERT INTO member (memberNo, name, identityNo, gender, dob, address, email, contact, occupation, memberCardNo, joinedDate, points, pointsExpiry) VALUES (1, 'Andrew Wee Kim Soo', 'S8020938A', 'M', '1980-05-24', '218 Orchard Road (S)238851', '
[email protected]', 92373629, 'Banker', 928349495, '2002-01-11', 2000, '2010-08-31'), (2, 'Lim Jingyin', 'S8406273B', 'F', '1984-07-02', '795 Ang Mo Kio Avenue 1 (S)569976', '
[email protected]', 86738293, 'Student', 983920311, '2008-02-15', 2000, '2010-02-15'), (3, 'Gan Kee Sim', 'S8588432J', 'M', '1985-03-07', '248 Choa Chu Kang Avenue 2 (S)680248', '
[email protected]', 81239123, 'Student', 928347771, '2007-07-31', 2000, '2008-07-31'), (4, 'Betty Su Kim Ling', 'S8947384C', 'F', '1989-09-22', '720 Woodlands Avenue 6 (S)730720', '
[email protected]', 97382937, 'Student', 912348372, '2007-12-23', 2000, '2008-12-23'), (5, 'Gary Tan Seng', 'S8321138D', 'M', '1983-06-21', '55 Chua Chun Kang Road (S)345643', '
[email protected]', 94532349, 'Student', 912381239, '2007-01-11', 2000, '2009-08-15');
Default Data Population: promotion INSERT INTO promotion (promotionNo, description, ratetype, rate, minspent, promoType) VALUES (1, '5% off for LAN usage', 'per', 5, 0, 'lan'), (2, '5% off for billiard usage', 'per', 5, 0, 'bill'), (3, '5% off for purchase of arcade card', 'per', 5, 0, 'arc'), (4, '5% off spending at this center', 'per', 5, 0, 'all'), ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 73 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
(5, '$2 off LAN usage with a minimum spending of $10', 'amt', 2, 10, 'lan'), (6, '$2 off billiard usage with a minimum spending of $10', 'amt', 2, 10, 'bill'), (7, '10% off LAN usage with minimum spending of $15', 'per', 10, 15, 'lan'), (8, '10% off billiard usage with minimum spending of $15', 'per', 10, 15, 'bill'), (9, '$1 off with $5 and above arcade card purchased', 'amt', 1, 5, 'arc'), (10, '$3 off with $10 and above arcade card purchased', 'amt', 3, 10, 'arc'), (11, '$10 off with $25 and above arcade card purchased', 'amt', 10, 25, 'arc');
Default Data Population: redeemitem INSERT INTO redeemitem (redeemItemNo, redeemDesc, pointsCost) VALUES (1, 'Beautiful Sticker', 50), (2, 'Pencil Box', 150), (3, 'Candy Sweets', 150), (4, 'Small Teddy Bear', 150), (5, 'Medium Teddy Bear', 250), (6, 'Big Teddy Bear', 450), (7, 'Gaint Teddy Bear', 1500), (8, 'Stylish Watch', 200), (9, 'Baseball Cap', 120), (10, 'Funland T-shirt', 220), (11, 'Handheld Game', 350), (12, 'Cool Sunglasses', 300), (13, 'Can Drink', 80), (14, 'Mobile Phone', 1000), (15, '32" LCD TV', 5000), (16, 'Mini Home Threatre System', 2000), (17, 'MP3 Player 1GB', 500), (18, 'MP3 Player 2GB', 1100), (19, 'MP3 Player 4GB', 2500), (20, 'Thumb Drive 2GB', 900), (21, 'Basketball', 350), (22, 'Soccerball', 350);
*Other data can be populate by calling the Stored Procedures.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 74 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
7.3.
APPENDIX C: GANTT CHART
Starting of the Project till the submission of initial report
Second part of the Project from requirement gathering till the submission of this Final Report.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 75 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Schedule Meeting with Tutor Task 7. Meeting With Tutor 7.1. Meeting 01 7.2. Meeting 02 7.3. Meeting 03 7.4. Meeting 04 7.5. Meeting 05 7.6. Meeting 06 7.7. Meeting 07 7.8. Meeting 08 7.9. Meeting 09 7.10. Meeting 10 8. Workshop 8.1. Workshop 01 8.2. Workshop 02 8.3. Workshop 06
Day Mon Wed Wed Wed Sat Sat Sat Sat Sat Mon Sat Sat Sat
Date 02 Feb 20 Feb 26 Mar 16 Apr 31 May 28 Jun 26 Jul 23 Aug 13 Sep 13 Oct 16 Feb 23 Feb 16 Aug
Allocated 25hrs 2.5hrs 2.5hrs 2.5hrs 2.5hrs 2.5hrs 2.5hrs 2.5hrs 2.5hrs 2.5hrs 2.5hrs 8.5hrs 2.5hrs 3hrs 3hrs
Attendants Attended Attended Attended Attended Attended Attended Attended Unavailable Attended Oversea Attended Attended Oversea
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 76 of 81
LEE CHANGJIN (K0604033)
7.4.
JAN08/BHICT/03
APPENDIX D: OTHERS
Interview form
User Requirements Interview Questions Project Title: Sales and Inventory System for Chain Stores (Amusement Center)
1) Company background. a. How many centers? b. How does each center operate in general? 2) Company’s operation workflow a. Is company using any system? b. What is the company sales operation? c. What is the company logistic operation? d. Any repeating tasks? e. Any exceptional cases? 3) Information that is of importance to the user. (Content Identification) a. What are the data that need to be store? b. What information user currently uses? c. Any forms? d. How is the data currently stored? 4) Open questions. a. What are the problems the user encounter? b. What concerns the user has on the current system? c. What the user wants the system to be capable of? d. What are the expectations? 5) User to prioritize the information importance. (Prioritization) a. What user wants to do with the information? b. How user wants to see the information? 6) Defining the major user requirements if any. 7) Anything the user wants to point out?
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 77 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Membership Form
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 78 of 81
LEE CHANGJIN (K0604033)
JAN08/BHICT/03
Sales Tracking Form
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 79 of 81
LEE CHANGJIN (K0604033)
8.
JAN08/BHICT/03
REFERENCES
[ 1 ] Chen, Peter P. (1976) The Entity-Relationship Model - Toward a Unified View of Data. ACM Transactions on Database Systems, Vol 1. Issue 1. pp.9-36 [ 2 ] Powell, Gavin. (c2006) Beginning database design. Indianapolis: Wiley Publishing. 0764574906 [ 3 ] Lans, Rick F. van der. (c2007) SQL for MySQL Developers: A Comprehensive Tutorial and Reference. Upper Saddle River, NJ : Addison-Wesley. 0131497359 [ 4 ] Peltier, Jon Gantt Charts in Microsoft Excel. http://pubs.logicalexpressions.com/pub0009/LPMArticle.asp?ID=343 [viewed 14/02/2008] [ 5 ] Holohan, Ron 6 Steps to Successful Schedules. http://www.projectsmart.co.uk/6-steps-to-successful-schedules.html [viewed 13/02/2008] [ 6 ] Christina, Low and Daphne, Pan (2007) The Write Right Guide. http://www.cdtl.nus.edu.sg/wrg/ [viewed 14/02/2008] [ 7 ] Connolly, Thomas M. and Begg, Carolyn E. (2002) Database Systems – A Practical Approach to Design, Implementation, and Management. 3rd Ed. Harlow: Addison-Wesley/Pearson. 0201708574 [ 8 ] Project Management Institute. (2004) A Guide to the Project Management Body of Knowledge (PMBOK Guides). Third Edition. Newtown Square, Pa.: Project Management Institute. 193069945X [ 9 ] Kruckenberg, Michael. and Pipes, Jay. (c2005) Pro MySQL. Berkeley, CA : New York : Apress. 159059505X [ 10 ]
MySQL AB, 2008 Sun Microsystems, Inc., MySQL 5.0 Reference Manual.
http://dev.mysql.com/doc/refman/5.0/en/index.html [viewed 16/05/2008] ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 80 of 81
LEE CHANGJIN (K0604033)
9.
JAN08/BHICT/03
GLOSSARY
SDLC DBMS GUI
WBS E‐A‐R Model
Systems Development Life Cycle relates to models or methodologies that people use to develop systems A DataBase Management System is computer software designed for the purpose of managing databases based on a variety of data models. A Graphical User Interface is a type of user interface which allows people to interact with electronic devices such as computers. It offers graphical icons, and visual indicators as opposed to text‐based interfaces, typed command labels or text navigation to fully represent the information and actions available to a user. Work Breakdown Structure is a tree structure listing of tasks commonly used in project management. Entity – Attribute – Relationship Model used in database design.
ICT499 CAPSTONE PROJECT COURSE FINAL REPORT JANUARY 2008 81 of 81