0% found this document useful (0 votes)
171 views13 pages

Istn 3si Practical Task 6 Extension - Testprep2

This document outlines instructions for modifying an existing movie rental database to include additional functionality. Specifically, it describes: 1. Adding a "Quantity on Hand" field to the existing Movie table. 2. Creating a new Customer table to store customer details. 3. Creating a new MovieHire table to record details of movies rented by customers, including decreasing the Quantity on Hand for the rented movie. The instructions provide SQL commands and code snippets to make these changes to the database structure and create interfaces to allow customers to register, view movie details, and record a movie rental. The goal is to link all parts of the rental process together in a web application.

Uploaded by

Thabo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views13 pages

Istn 3si Practical Task 6 Extension - Testprep2

This document outlines instructions for modifying an existing movie rental database to include additional functionality. Specifically, it describes: 1. Adding a "Quantity on Hand" field to the existing Movie table. 2. Creating a new Customer table to store customer details. 3. Creating a new MovieHire table to record details of movies rented by customers, including decreasing the Quantity on Hand for the rented movie. The instructions provide SQL commands and code snippets to make these changes to the database structure and create interfaces to allow customers to register, view movie details, and record a movie rental. The goal is to link all parts of the rental process together in a web application.

Uploaded by

Thabo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

ISTN 3SI PRACTICAL TASK 6…Cont’d (Read, Display, and Update)

In this extension of Practical Task 6, you are required to do the following:

1. Adjust the design of the Movie Table to include a field for Quantity on Hand (QOH).
2. Create a new table that records details of customers
3. Create a new table that records the hiring of a movie by a customer

Part One – Adjust the Movie Table

The objective in Part One is to modify the design of the Movie table so that an extra field is
added. The new field that needs to be added is a fieled to record the QOH of a movie. This
can be easily accomplished via Sql Server Management Studio
by…Tools>>Options>>Designers>> ….and uncheck the Prevent saving changes…option.

Hereafter, add on a new field named QOH


You should also add some fictitious data into this field via SQL Server Management Studio.

Just as a confirmation, display the Movie table with the new field data showing on a web
page.

Part Two – Create a new Table that Records Customers’ Details

Design a new table for recording details of new customer. The design is shown below:

Please take note of the Primary Key (PK) and auto-increment setting.
Create a page on your website that enables a new customer to be registered. This page will
have to be linked u to the main menu, as shown in the 2nd menu option in the screenshot
below:

DIV tags were used In order to achieve the layout on the page, The Register New Customer
logo was created by the following DIV statement:

<div style="font-family: Algerian; background-color: #C0C0C0; text-align: center;


font-weight: bold; position: relative;">
<h1 style="color: #800000" >REGISTER NEW CUSTOMER</h1></div>

The processing sequence to register a new customer is as follows:

1. New customer details are entered


2. The Register Customer button is pressed. The insertion of a new customer is done
via a Sql Data Source (SQLDS) which is quite convenient for this purpose. The Insert
parameters are the Customer First Name, surname and cell-phone number. These
values are obtained via the textboxes on the web page. The trick is to use the
SQLDS and generate the Insert query but more importantly, you need to point the
SQLDS wizard to the correct Insert parameters. This is done quite routinely as was
the case with the previous prac.
3. There is however a slight complication this time around. Because the Cust_ID field is
an auto-increment field, once a new customer record is inserted into the database,
there is no way of knowing what the customer’s ID is. In order to resolve this problem,
the SQL function named Scope_Identity() is invoked. The purpose of the function is
to add a new record into the database and then return the primary key of the newly
inserted record. However, in order to achieve this you will have add a new parameter
to the Sql statement that has been generated by the SQLDS wizard as shown above.
This is now an output parameter that retrieves the ID of the newly inserted record.

So add a new select statement to the Sql statement generated above…


Select @CustID=Scope_Identity()
The New Sql Statement will now read:
INSERT INTO [TblCustomer] ([Cust_FirstName], [Cust_Surname], [Cust_CellNo])
VALUES (@Cust_FirstName, @Cust_Surname, @Cust_CellNo); Select
@CustID=Scope_Identity()

In the dialog box of the SQLDS wizard, press the refresh parameters button. The
newly added parameter should now appear in the listbox. Configure this parameter
so that it has a default value of 0, is set as an output parameter and a datatype of
int32
4. Once the SQLDS has been configured, the final part of processing entails
 The actual insertion of the customer record….this is easily done by writing the
event handler code for the clicking of the “Register Customer” button and adding
the following code: SqlDS.Insert() ….note the name of the SqlDS depends on the
name that you used.
 Add a label control that displays the CustomerID of the newly inserted customer
record…this is discussed in Point 5 below:

5. Once the Customer record has been inserted into the database table named
Customer, the challenge is to find an appropriate event handler that will immediately
return the newly inserted CustmerID. The problem is resolved by making use of the
Inserted method/event handler of the SQLDS.

So double click this event handler and add in the following code (after having placed a
label that will display the customer code, on the web page):

lblCustID.Text = e.Command.Parameters("@CustID").Value

As a summary, the sequence of processing entails the adding of a new customer onto the
Customer table and returning the customer’s ID for the convenience of the newly registered
customer.

So, when a customer enters his/her details and registers (presses the register button), the
system should insert the new customer and display the newly inserted customer’s ID as a
label on the web page…illustrated below:
...and if you want to verify that the new customer has been inserted into the database, you
can create a new web page that simply displays all the records from the customer table…as
shown below:

Part Three – Create a New Table that records the Hiring of a New Movie

Create a New table, named MovieHire to record the hiring of a movie.

For the final part, you are required to be as innovative as possible with the interface so that
once a movie s hired, the details of the hire are recorded and the QOH of the movie is
decreased by one.

As a sample of the interface design, the following user interaction sequence will be used.

 The user is required to provide his/her CustomerID


 The system retrieves the customer’s details and displays it to the customer
 The system presents the user with a list of movies
 The user selects a movie for hire
 This transaction is recorded…from a processing perspective, this entails the
recording of the new hire transaction as well as a decrease of the QOH of the movie
that was hired

The interface plan is to create a 2 columnar structure…by now you should now how to do this.

In the first column, the customer details are captured via a textbox where the customer is
required to enter his/her customer id. The DIV tag is used to create this layout – An outer
DIV as well as an inner DIV
The 3rd inner DIV tag contains a label that displays the current date and time. To achieve
this, you have to make use of the PageLoad Event Handler. This is accessed by finding an
empty area in your web page and double-clicking the mouse in this area to open up the evet
handling code for the PageLoad Event. This event fires as soon as the Web page loads.
When this happens, the Label is populated with the current date and time. The code for this
aspect of the processing is:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
lblDateTime.Text = Date.Now()
End Sub

Drag and drop a Gridview and SqlDS control onto the left hand column of the web page. The
DataGrid Control is not shown when the Web page is displayed, because the customer has
not entered his/her ID as yet. Configure the SQLDS so that it displays the Customer table.
However, you need to invoked the Where clause because the datagrid is populated with
Customer details where the CustomerID matches the CustomerID that is typed into the
textbox. The screenshots below show some of the design required for this aspect of the
solution.
The final code thus far for this page is:

Protected Sub btnFindCustomer_Click(sender As Object, e As System.EventArgs) Handles


btnFindCustomer.Click
GridShowCust.DataBind()
End Sub

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load


lblDateTime.Text = Date.Now()
End Sub

…so when the user enters his/her Customer ID, the Find Customer button is pressed, the
system responds as follows:
…now that we have obtained the customer’s details, let’s display the movie details.
However, in order to present the user with a comprehensive listing of all the movie details,
we will display an inner join between the Movie and MovieType table via a GridView. Also,
ensure that the rows of the gridview are selectable so that we are able to capture the
following details:
 MovieID for insertion into the MovieHire Table. The MovieHire table requires the
following:
 CustID – can be obtained from the gridview/textbox in the first column of the web
page
 MoviedID – can be obtained from the gridview showing the movie details in the 2nd
column of the web page
 Date and Time – obtained from the label in the 1st column of the web page
So, drag and drop a dropdown list box and a gridview into the 2nd column of the web page.

The idea is that the user selects the movie name from the dropdown list and the mocie
details are displayed in the gridview. This is similar to the processing in Page 2 of your
website.

Use a SQLDS and create an inner join between the Movie Table and MovieType table so
that the display looks like…arrange the 2nd column of the web page by making use of te DIV
tag…the code below gives you an idea of how to do this…
<div style="border-color:#800000; border-style:solid; float: left; width: 45%">
<div style="width: 100%; background-color: #CCCCFF; font-family: Arial; font-size: medium;
font-weight: bold; text-align: center;">MOVIE DETAILS
</div>
<div style="float: left; width: 45%">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</div>
<div style="float: left; width: 45%">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</div>
Now all that is required is to record the hiring of the selected movie for the current customer.
This is easy to do because all that needs to be done is to insert the CustID, Date and
MovieID into the MovieHire Table. To do this, you need to drag and drop a SQLDS and
select the records from the MovieHire Table….

…and then tweak the InsertQuery


,,, …note…the CustID is
obtained from the textbox.
Adjust the Interface to enable the insertion of the Hire Movie details when the user presses
the Hire Movie button

As soon as the Hire Movie button is pressed, the hiring of the new movie is recorded. You
can create a page that displays all movies hired and link up this page to the main menu so
that the latest hiring of a movie is shown.

…and finally, let’s do an update of data.

The Update processing will involve the QOH field in the Movie Table.

Firstly, we’ll check that the Quantity on Hand is greater than 0. If it is, then we adjust the
QOH by subtracting one from it, to record the new hire transaction. The update is done by
making use of a SQLDS that points to the Movie table – basically select all the records from
the Movie Table – but do this via the Sql statement option
Delete any SQL queries that may already exist in the Update tab …now write your own
query

The Sql simply adds 2 parameters to the Update statement …the trick is to pass the correct
values to these parameters in the code

Also, set the ConflctDetection Property of the SQLDS to OverwriteChanges…

The full code for the Hire Movie button is shown below:
Protected Sub btnHireMovie_Click(sender As Object, e As System.EventArgs) Handles btnHireMovie.Click
If GridViewMovieDetail.Rows(0).Cells(2).Text > 0 Then ‘ a reference to QOH
SQLDSInsertMovieHire.Insert()
SqlDSMovieUpdate.UpdateParameters.Item("MovieID").DefaultValue =
GridViewMovieDetail.Rows(0).Cells(0).Text
SqlDSMovieUpdate.UpdateParameters.Item("QOH").DefaultValue =
GridViewMovieDetail.Rows(0).Cells(2).Text - 1
SqlDSMovieUpdate.Update()
GridViewMovieDetail.DataBind()
Else
lblHireStatus.Text = "No Copies of the Movie in Stock"
End If
The Interaction Sequence will be:

….before the hire


…after the hire

You might also like