ShoppingCart

Click Here to Download this Answer Instantly

 

 

Requirements
1) Use proper naming conventions for all objects and variables and add suitable comments to your code where necessary to clarify your work.
2) Database Schema: Create a new database named ShoppingCart.mdf in your project:
a. Add a table named Invoices with the following definition. The InvoiceID is a primary key.
CREATE TABLE [dbo].[Invoices]
(
[InvoiceID] INT NOT NULL PRIMARY KEY,
[InvoiceDate] DATETIME NOT NULL,
[Shipped] BIT NULL,
[CustomerName] NVARCHAR(50) NULL,
[CustomerAddress] NVARCHAR(100) NULL,
[CustomerEmail] NVARCHAR(50) NULL
)
b. Add a table named InvoiceItems with the following definition. The InvoiceID is a foreign key to match the parent Invoices table.
CREATE TABLE [dbo].[InvoiceItems]
(
[ItemID] INT NOT NULL PRIMARY KEY,
[InvoiceID] INT NOT NULL,
[ItemName] NVARCHAR(50) NOT NULL,
[ItemDescription] NVARCHAR(50) NOT NULL,
[ItemPrice] DECIMAL(19, 4) NOT NULL,
[ItemQuantity] INT NOT NULL
)
c. Notice that the Invoices table does not contain any subtotal, tax or total prices. These values will be calculated from the list of Invoice Items.
3) Form Design: Create a suitable form layout similar to the sample below with 2 listboxes (one for each table). Below each listbox, place textboxes for each field in the corresponding database table.
Use any layout you like but provide suitable labels and meaningful textbox names.
4) Form Buttons: Add buttons to each set of form fields for SAVE, DELETE, and NEW functionality.
5) Data Objects:
a. Create a class for an Invoice with suitable properties to hold the data for a record from the Invoices table.
b. Create a class for an InvoiceItem with suitable properties to hold the data for a record from the InvoiceItems table.
c. Each class should have a ToString() method to allow the listboxes to display the required row of data (see the sample form below)
Using the Lab Demonstration Applications as guides, create a new application that models a Shopping Cart. Your application will have 2 tables, one for Invoices (one record per invoice) and a related table for the list of items for each invoice. Allow a user to view, add new records, and update or delete existing records from the database.
Requirements
1) Use proper naming conventions for all objects and variables and add suitable comments to your code where necessary to clarify your work.
2) Database Schema:Create a new database named ShoppingCart.mdf in your project:
a. Add a table named Invoices with the following definition. The InvoiceID is a primary key.
CREATE TABLE [dbo].[Invoices]
(
[InvoiceID] INT NOT NULL PRIMARY KEY,
[InvoiceDate] DATETIME NOT NULL,
[Shipped] BIT NULL,
[CustomerName] NVARCHAR(50) NULL,
[CustomerAddress] NVARCHAR(100) NULL,
[CustomerEmail] NVARCHAR(50) NULL
)
b. Add a table named InvoiceItems with the following definition. The InvoiceID is a foreign key to match the parent Invoices table.
CREATE TABLE [dbo].[InvoiceItems]
(
[ItemID] INT NOT NULL PRIMARY KEY,
[InvoiceID] INT NOT NULL,
[ItemName] NVARCHAR(50) NOT NULL,
[ItemDescription] NVARCHAR(50) NOT NULL,
[ItemPrice] DECIMAL(19, 4) NOT NULL,
[ItemQuantity] INT NOT NULL
)
c. Notice that the Invoices table does not contain any subtotal, tax or total prices. These values will be calculated from the list of Invoice Items.
3) Form Design: Create a suitable form layout similar to the sample below with 2 listboxes (one for each table). Below each listbox, place textboxes for each field in the corresponding database table.
Use any layout you like but provide suitable labels and meaningful textbox names.
4) Form Buttons: Add buttons to each set of form fields for SAVE, DELETE, and NEW functionality.
5) Data Objects:
a. Create a class for an Invoice with suitable properties to hold the data for a record from the Invoices table.
b. Create a class for an InvoiceItem with suitable properties to hold the data for a record from the InvoiceItems table.
c. Each class should have a ToString() method to allow the listboxes to display the required row of data (see the sample form below)
Sample Form
6) General Functionality:
a. When the user selects an Invoice row in the Invoices Listbox at the top of the form:
i. the details for that Invoice should appear in the Invoice Record form fields below.
ii. a full list of the Invoice Items for that Invoice should appear in the Invoice Items Listbox.
b. When the user selects an Invoice Item record in the Invoice Items Listbox, the details of that Invoice Item record should appear in the form fields at the bottom of the form.
c. The Subtotal, PST, GST and Total Amounts should be calculated and shown in the appropriate textboxes below the Invoice Items listbox. The user should not enter data in these textboxes – these values will be managed by your code. (Set the IsReadOnly property to true on these textboxes)
d. The SAVE / DELETE / NEW buttons should allow the user to modify or add new Invoice records and Invoice Item records.
7) Initialization:
a. When the application starts – Load the Invoice records into the Invoices listbox:
i. open a connection to the database.
ii. use a SQLCommand object to load a SQLDataReader with all the Invoice records from the Invoices Table.
iii. Loop through and read the SQLDataReader and create an Invoice object for each record
iv. add this object to a List of Invoice objects, and also add it to the Invoices listbox.
8) Invoices Listbox SelectionChanged – When the user selects an Invoice row from the Invoices ListBox:
a. show the details of that Invoice record in the form fields below the listbox.
b. load the Invoice Item records into the Invoice Items listbox:
i. open a connection to the database
ii. use a SQLCommand object to load a SQLDataReader with all the Invoice Items from the InvoiceItems table