Istn 3si Practical Task 6 Extension - Testprep2
Istn 3si Practical Task 6 Extension - Testprep2
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
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.
Just as a confirmation, display the Movie table with the new field data showing on a web
page.
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:
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
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 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:
…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….
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.
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
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: