Spring 2007 – UNC Charlotte

Group 3 members:  Bryan VonCannon  Semir Ajsic  Ryan Fink  Paris Smith  Richard Jones (dropped course)  Larrie McLester (dropped course)

Online Computer Store Final Report - Design

ITCS – 3160 - 001

Document last updated: April 17, 2007 The University of North Carolina at Charlotte

Page 1 of 16 Document Revision History

Please be advised that this is a living document stored in an electronic format. Please refer to the document storage location for its latest version.

Version Date(s) Explanation Author(s) # 1 1/17/2007 Document creation; group members added S.A., R.F., P.S., B.V. 1.1 1/18/2007 Topic selected All 1.2 1/23/2007 Added system requirements; entities; functions for All customers; functions for employees 2 1/30/2007 Developed ER Diagram based on the system All requirements and entities 2.1 2/1/2007 Developed the schema design S.A., B.V. 2.2 2/15/2007 Fixed misspellings; updated formatting B.V. 3.0 2/17/2007 Populated the Database; Created SQL scripts for the S.A., R.F. thru tables and constraints; also created SQL scripts of data 2/25/2007 to populate the tables 3.1 3/15/2007 Query Design All 4.0 4/3/2007 Cleaned and updated schema design S.A. 4.2 4/5/2007 Query optimization; Normalization All 5.0 4/17/2007 Conclusions and future work All

Page 2 of 16 Table of Contents

1.0 – Introduction...... 4 2.0 – Requirements Analysis...... 4 3.0 – ER Diagram...... 4 4.0 – Relational DB Design / Schema Design...... 4 5.0 – Normalization...... 4 6.0 – Physical Database Design...... 4 7.0 – GUI Design...... 4 8.0 – Conclusion and future work...... 4

Page 3 of 16 1.0 – Introduction

Our group is creating an online computer store. This online computer store will have all the necessary parts in order to handle all important store transactions. Customers are able to search for products in our database based on the product name. If they would like to make a purchase then they must register for an account. Upon registering a user can add items to purchase or add items to their wish list to save for a later purchase.

We first put together a brief list of what we wanted the system to be able to do. Using these requirements we developed an ER diagram. Using this ER diagram we were able to see how many relationships and entities we would have. From here we created a schema and physical database design.

Page 4 of 16 2.0 – Requirements Analysis

High Level System Overview – This system will allow customers to purchase computer accessories and allow employees to manage the computer store inventory and order / transaction status. It is a full fledge computer store application having all the necessary functions to manage the store online.

Customer – A customer must have an account in our system to purchase computer equipment. If the user does not have an account, they will need to register. Upon registering, the user will input their: first name, last name, email address, date of birth, phone number, address, city, state, zip code, password, and country. The first name, last name, and email address are required. There is also a unique cID attached to every customer record. If a user has not entered in their address information then we can’t process their order / transaction. The users will login with their cID (user ID) and password.

Employee – Employee’s information is stored in a separate entity. New employee’s information that will need to be kept is their: first name, last name, address, city, state, zip code, country, and password. There is also a unique eID attached to every employee record; this will serve as their username. Employees are assumed to have administrator level access to the entire system.

Manufacturers – Each manufacturer that sells their products with us have their information stored in a manufacturer entity. The information that is stored here is: manufacturer name, phone number, address, city, state, zip, and country. Each manufacturer also has a unique mID that is used throughout the entire system.

Products – All Products are stored in an independent product entity. The product data that is kept here is: manufacturer ID, product name, inventory (number of units in stock), and price of product. There is a pID which is the primary key for each product. The mID is a foreign key back to the manufacturers table.

Shopping Kart – Customers can add items to a shopping kart. The shopping is a temporary area to add items before a user checks out. The shopping kart entity holds this information: cID and pID. The cID is a foreign key back to the customer entity and the pID is a foreign key to the product entity. This way we can keep track of what customer has which products in their shopping kart.

Wish List – Customers can add items to a wish list, which is a temporary location to save items that the user doesn’t want to purchase yet. The wish list entity will hold the following information: customer ID and product ID. This is precisely the same information as the shopping kart because if the customer ever wants to purchases these items, they can be easily transferred to the shopping kart entity.

Once a customer purchases certain items from their shopping kart, two main things happen. A new transaction is stored in the transaction entity and all the individual items are moved from the wish list to the transaction items entity. The transaction entity stores the following information: transaction ID, customer ID, transaction status, transaction date, shipment date, credit card number, and credit card expiration date. The transaction items entity stores the following information: transaction ID and product

Page 5 of 16 ID. The transaction entity is specifically for the overall transaction information and transaction items entity is for the items tied to that transaction. This will allow one transaction ID to exist for one checkout with multiple products underneath that transaction.

Entities: 1. Customer 2. Employee 3. Manufacturer 4. Products 5. Shopping_kart 6. Wish List 7. Transaction 8. Transaction Items

Functions that is available to customers:  Register for an account  Login / Logout  Update their profile  Search products  Search manufacturers  Add and remove items to their wish list  Add and remove items to their shopping kart  Submit a transaction / order  View transaction / order status

Functions that is available to Employees:  Create new employee profiles  Update their employee profile  Update and add manufacturers  Update, add, delete products  Update transaction / order status

Page 6 of 16 3.0 – ER Diagram

Page 7 of 16 4.0 – Relational DB Design / Schema Design

Customer cID Password First_Name Last_Name Email DOB Phone_Number Address City State Zip Country

Manufacturer mID Name Phone_Number Address City State Zip Country

Products pID mID PName Inventory Price

Shopping_Cart cID pID

Transaction transID cID pID Status Trans_Date Ship_Date CCNum CC_Exp

Transaction_Items transID pID

Wish_List cID pID

Employee eID Password First_Name Last_Name Address City State Zip Country

Page 8 of 16 5.0 – Normalization

Trying to design the entities in a way that would give us the least duplication of data was a difficult task.

We split up many different aspects of the system into independent tables.

1. Manufacturer Table – We placed all the manufacturer information in a separate entity because if

we placed this information in the product table, and multiple products had the same manufacturer

information, this would be a lot of data being duplicated. Thus more space used.

2. Products Table – The products table is a separate entity obviously because the products are

used in just about every relationship in the system. The system would be un-maintainable if we

stored the each product information separately in the wish list table, shopping cart table, or the

transaction items table.

The space saved from moving these two entities to their own independent data set will continue to grow rapidly the more data that is entered into the system. Maintaining the system with separate independent data sets is very simple.

More normalization – Upon realization, we imagined splitting up the data into smaller sub sets. We noticed though that the more normalized the data is, the more joins you have to do between tables and this slows the application down. Performance was a big factor in stopping where we did.

Page 9 of 16 6.0 – Physical Database Design

The following SQL DDL scripts were used to create the tables on the UNCC Oracle database.

Oracle 10g Database: http://coit-ora01.uncc.edu:5560/isqlplus/

We first started with the entities that weren’t dependent on any other tables; namely Customer, Manufacturer, and Employee table. From there we go in order of dependencies.

CREATE TABLE Customer ( cID CHAR(9), Password CHAR(7), First_Name CHAR(20), Last_Name CHAR(20), Email CHAR(30), DOB DATE, Phone_Number CHAR(10), Address CHAR(25), City CHAR(20), State CHAR(2), Zip Integer, Country CHAR(3), PRIMARY KEY (cID) );

CREATE TABLE Manufacturer ( mID CHAR(10), Name CHAR(20), Phone_Number CHAR(10), Address CHAR(25), City CHAR(20), State CHAR(2), Zip Integer, Country CHAR(3), PRIMARY KEY (mID) );

CREATE TABLE Products ( pID CHAR(10), mID CHAR(10), PName CHAR(50), Inventory Integer, Price Integer, PRIMARY KEY (pID), FOREIGN KEY (mID) REFERENCES Manufacturer );

CREATE TABLE Shopping_Cart ( cID CHAR(9), pID CHAR(20),

Page 10 of 16 FOREIGN KEY (cID) REFERENCES Customer, FOREIGN KEY (pID) REFERENCES Products );

CREATE TABLE Transaction ( transID CHAR(10), cID CHAR(9), Status CHAR(10), Trans_Date DATE, Ship_Date DATE, CCNum Integer, CC_Exp Integer, PRIMARY KEY (transID), FOREIGN KEY (cID) REFERENCES Customer );

CREATE TABLE Transaction_Items ( transID CHAR(10), pID CHAR(20), FOREIGN KEY (transID) REFERENCES Transaction, FOREIGN KEY (pID) REFERENCES Products );

CREATE TABLE Wish_List ( cID CHAR(9), pID CHAR(20), FOREIGN KEY (cID) REFERENCES Customer, FOREIGN KEY (pID) REFERENCES Products );

CREATE TABLE Employee ( eID CHAR(9), password CHAR(7), First_Name CHAR(20), Last_Name CHAR(20), Address CHAR(25), City CHAR(20), State CHAR(2), Zip Integer, Country CHAR(3), PRIMARY KEY (eID) );

The following SQL scripts were used to populate all of the tables with sample data. Once we have all of the entities created from the scripts above, we can start to populate data in the tables.

1- Adding new customers

INSERT INTO Customer (cID, Password, First_Name, Last_Name, Email, DOB, Phone_Number, Address, City, State, Zip, Country) VALUES ('sajsic987','abc1234','Semir','Ajsic','[email protected]',TO_DATE('01-01- 1900','MM/DD/YYYY'), '7041111111','PO BOX 1','Charlotte','NC',28205,'USA');

Page 11 of 16 INSERT INTO Customer (cID, Password, First_Name, Last_Name, Email, DOB, Phone_Number, Address, City, State, Zip, Country) VALUES ('jdoe12345','1234567','John','Doe','[email protected]',TO_DATE('01-01- 1900','MM/DD/YYYY'), '7042222222','PO BOX 2','Charlotte','NC',28215,'USA');

INSERT INTO Customer (cID, Password, First_Name, Last_Name, Email, DOB, Phone_Number, Address, City, State, Zip, Country) VALUES ('mouse_567','minie12','Minie','Mouse','[email protected]',TO_DATE('01-01- 1900','MM/DD/YYYY'), '7043333333','PO BOX 3','Charlotte','NC',28225,'USA');

INSERT INTO Customer (cID, Password, First_Name, Last_Name, Email, DOB, Phone_Number, Address, City, State, Zip, Country) VALUES ('mickey_21','mickey','Mickey','Mouse','[email protected]',TO_DATE('01-01- 1900','MM/DD/YYYY'), '7044442233','PO BOX 21','Charlotte','NC',28211,'USA');

INSERT INTO Customer (cID, Password, First_Name, Last_Name, Email, DOB, Phone_Number, Address, City, State, Zip, Country) VALUES ('ppan_2007','abcd123','Peter','Pan','[email protected]',TO_DATE('01-01- 1900','MM/DD/YYYY'), '7041112131','PO BOX 14','Charlotte','NC',28262,'USA');

2- Adding new manufacturers

INSERT INTO Manufacturer (mID, Name, Phone_Number, Address, City, State, Zip, Country) VALUES ('hdcom12345','HD Computers','8005555555','PO BOX 11','Charlotte','NC',28215,'USA');

INSERT INTO Manufacturer (mID, Name, Phone_Number, Address, City, State, Zip, Country) VALUES ('tosh_45678','Toshiba','8003334455','PO BOX 8000','Charlston','SC',11111,'USA');

INSERT INTO Manufacturer (mID, Name, Phone_Number, Address, City, State, Zip, Country) VALUES ('compact123','Compact Electronics','8005532233','1122 some address','Miami','FL',33221,'USA');

INSERT INTO Manufacturer (mID, Name, Phone_Number, Address, City, State, Zip, Country) VALUES ('apple_comp','Apple Computers','8009990087','PO BOX 435','Charlotte','NC',28231,'USA');

INSERT INTO Manufacturer (mID, Name, Phone_Number, Address, City, State, Zip, Country) VALUES ('Dellc_2007','Dell Computers','2324445678','PO BOX 1568','San Francisco','CA',33241,'USA');

3- Adding new products

INSERT INTO Products (pID, mID, PName, Inventory, Price) VALUES ('a000000001','hdcom12345','Laptop s2000',4,'899.95');

INSERT INTO Products (pID, mID, PName, Inventory, Price) VALUES ('a000000002','tosh_45678','Toshiba Tecra S1 Charger',2,'89.45');

INSERT INTO Products (pID, mID, PName, Inventory, Price) VALUES ('a000000003','compact123','Wireless Mouse',1,'49.95');

Page 12 of 16 INSERT INTO Products (pID, mID, PName, Inventory, Price) VALUES ('a000000004','apple_comp','iMac G5',3,'2599.78');

INSERT INTO Products (pID, mID, PName, Inventory, Price) VALUES ('a000000005','Dellc_2007','Inspiron 700m',9,'1395.24');

4- Adding new employees

INSERT INTO Employee (eID, Password, First_Name, Last_Name, Address, City, State, Zip, Country) VALUES ('abc123456','123abc7','Water','Fountain','1111 Some Street name','Charlotte','NC',28262,'USA');

INSERT INTO Employee (eID, Password, First_Name, Last_Name, Address, City, State, Zip, Country) VALUES ('bbb1234aa','1234567','Uncle','Sam','123 street dr','Charlotte','NC',28212,'USA');

INSERT INTO Employee (eID, Password, First_Name, Last_Name, Address, City, State, Zip, Country) VALUES ('empid1234','abcdef1','Mouse','Darn','113-c nefound st','Raleigh','NC',27555,'USA');

INSERT INTO Employee (eID, Password, First_Name, Last_Name, Address, City, State, Zip, Country) VALUES ('Bob_23_cc','anskjab','Bob','Parker','223 Central st, apt 3','Wadesboro','NC',27252,'USA');

INSERT INTO Employee (eID, Password, First_Name, Last_Name, Address, City, State, Zip, Country) VALUES ('snowman12','snowman','Snowman','Winter','20 Frozen land dr','Gastonia','NC',28211,'USA');

4- Wish List

Customers can create a wish list from the search performed above using the SQL as follows:

INSERT INTO Wish_List (cID, pID) VALUES ('existing cID','')

The wish list will be saved under the customer id and they can access it and modify it (using the SQL bellow) any time they log in to their account.

DELETE FROM Wish_List W WHERE W.pID = ''

UPDATE wish_List W SET W.pID = ''

5- Shopping Cart Query Design

Creating a shopping cart happens before the actual transaction. It will only show the customers what items they have selected to buy and they can continue shopping and come back to the shopping cart later. Once the customer clicks on Buy Products, they will be taken to the Transaction page to complete their transaction and enter the purchasing information.

Page 13 of 16 5.1- Adding shopping cart items

INSERT INTO Shopping_Cart (cID, pID) VALUES ('sajsic987','a000000001')

5.2- Removing shopping cart items

DELETE FROM Shopping_Cart S WHERE S.pID = ' a000000001'

5.3- Updating shopping cart items

UPDATE Shopping_Cart S SET S.pID =

6- Searching for Products

SELECT M.mID, P.pID FROM Manufacturer M, Products P WHERE M.mID = P.mID AND P.PName =

7- Creating a transaction (checkout)

Transactions are processed from the items in the shopping cart. The user selects which items from their shopping cart they want to buy. When they select all the products they want, and click on Buy Products all the items are moved to the transaction items table and a new transaction record is created.

SELECT C.cID, P.pID, T.transID FROM Customer C, Product P, Transaction T WHERE C.cID = T.cID AND P.pID = T.pID AND T.transID = 'New Transaction ID'

INSERT INTO Transaction (transID, cID, pID, Status, Trans_Date, Ship_Date, CCNum, CC_Exp) VALUES ('new transID','existing cID','existing pID','ready to ship',01-01-1900 ,01-01- 1900,0000111122223333,012)

After the customer buys the item, decrease the Inventory in the Products table and reset the Transaction.

Page 14 of 16 7.0 – GUI Design

Online Computer Store Application: http://coit-servlet01.uncc.edu:8080/bavoncan/compstore/index.jsp

We will show our system live in our class presentation but here is our homepage for the system. It may look really simple and plain but the core functionality is in the database and front end code (which can’t be seen).

Technology We have used Java Server Pages (JSP) technology along with Java Database Connectivity (JDBC) to access the Oracle database. The SQL used for the application is embedded within the code in the front end. Since JSPs are complied into Java Servlets, all of this code and SQL is never seen by the user using “view source” in their browser. This makes the system very secure.

Page 15 of 16 8.0 – Conclusion and future work

The design of our Online Computer Store has been a success. We took the initial requirements of the system, wrote function system requirements, developed an ER diagram, and created the physical database design.

We used the skills taught this semester to successful create our first application front end to database.

Page 16 of 16