You are on page 1of 12

END OF SECOND SEMESTER EXAMINATIONS - 2019/2020

ACADEMIC YEAR

FACULTY OF COMPUTING AND INFORMATION SYSTEMS

DEPARTMENT OF INFORMATION SYSTEMS

END OF SEMESTER EXAMNATION / TAKE HOME EXAMANINATION

ANSWER SHEET

CICS 314: ADVANCED VISUAL BASIC .NET PROGRAMMING

STUDENT INFORMATION
INDEX NUMBER: 040917007
FULL NAME: Ebenezer Amoasi Yeboah
PROGRAMME: BSC INFORMATION TECHNOLOGY
LEVEL: 300
SESSION: Morning- Regular
LECTURER: Mr. Samuel Oppong
QUESTION 1
a) Create a class for the Art in case one and create member variables for any four (4)
properties.

Code for Sub Question a)


Public Class Art
Private artId As String
Private artistId As String
Private description As String
Private datecommissioned As Date

End Class

b) Create a property procedure to write values into and read values from each of the
member variables created in (a) above. Be mindful to implements all necessary
validation.

Code for Sub Question b)

'Write and Read Art Type


Public Property ArtType As String
Get
Return type
End Get
Set(ByVal value As String)

If value = String.Empty Then


MessageBox.Show("Please, Art Type Must Be A String")
Else
type = value
End If

End Set
End Property

'Write and Read Art Length


Public Property ArtLength As Double
Get
Return length
End Get
Set(ByVal value As Double)

If IsNumeric(value) Then
length = value
Else
MessageBox.Show("Please, Art Length Must Be A Number")
End If

End Set
End Property

'Write and Read Art Width


Public Property ArtWidth As Double
Get
Return width
End Get
Set(ByVal value As Double)

If IsNumeric(value) Then
width = value

Else
MessageBox.Show("Please, Art Width Must Be A Number")
End If

End Set
End Property

'Write and Read Art Description


Public Property ArtDescription As String
Get
Return description
End Get
Set(ByVal value As String)

If value = String.Empty Then


MessageBox.Show("Please, Art Description Must Be A String")
Else
description = value
End If

End Set
End Property

c) Create a Method to calculate the Age of the painting using the CommissioningDate
and the current date

Code for Sub Question c)


Public Function CalculateAge(ByVal commission_date As Date) As Integer
Dim currentDate As Date = Now
age = currentDate.Year - commission_date.Year

Return age
End Function

'Write and Read Art Age


Public Property ArtAge As Integer
Get
Return age
End Get
Set(ByVal value As Integer)

age = value

End Set
End Property

d) In the Click Event of a button that lies on Form1, create an instance of the Class
created in (a)

User Interface for Sub Question d)

Private Sub btnArt_Click(sender As Object, e As EventArgs) Handles btnArt.Clic


Dim newArt As New Art
End Sub

e) Assign values to the properties created in (b) using Textboxes that are on Form1.
Code for Sub Question e)

'ART TYPE'
If cmbType.SelectedIndex = -1 Then
MessageBox.Show("Please, Choose An Art Type")
cmbType.Select()

Else
newArt.ArtType = cmbType.Text
End If

'ART LENGTH'
If txtLength.Text <> String.Empty Then

If IsNumeric(txtLength.Text) Then
newArt.ArtLength = CDbl(txtLength.Text)

Else
MessageBox.Show("Please, Art Length Must Be A Number")
txtLength.Select()
End If

Else
MessageBox.Show("Please, Fill The Art Length Entry")
txtLength.Select()
End If

'ART WIDTH
If txtWidth.Text <> String.Empty Then

If IsNumeric(txtWidth.Text) Then
newArt.ArtWidth = CDbl(txtWidth.Text)

Else
MessageBox.Show("Please, Art Width Must Be A Number")
txtWidth.Select()
End If

Else
MessageBox.Show("Please, Fill The Art Width Entry")
txtWidth.Select()
End If

'ART DESCRIPTION
If txtDescription.Text = String.Empty Then
MessageBox.Show("Please, Fill The Art Description Entry")
txtDescription.Select()

Else
newArt.ArtDescription = txtDescription.Text
End If

'ART AGE'
newArt.ArtAge = CInt(newArt.CalculateAge(dtpDateOfCommission.Value))
MessageBox.Show("Art Details" & vbNewLine & vbNewLine & "Type: " &
newArt.ArtType & vbNewLine & "Length: " & newArt.ArtLength & vbNewLine & "Width: " &
newArt.ArtWidth & vbNewLine & "Description: " & newArt.ArtDescription & vbNewLine &
"Age: " & newArt.ArtAge & "yrs")

End Sub

f) Using a message box control, display the values assigned to the properties in (e) as
well as the Age of the Painting in (c).
Code for Sub Question f)

MessageBox.Show("Art ID: " + myart.Art_Id & Environment.NewLine &


"Artist ID:" + myart.Artist_Id & Environment.NewLine &
"Description: " + myart.Artist_Description &
Environment.NewLine & "Date Commissioned: " +
myart.DateOfCommissioning.ToString() & Environment.NewLine &
"Paintings Age: " +
myart.GetPaintingAge.ToString + "years")

g) Create a Derived Class from the class in (a) Class

Code for Sub Question g)


Public Class BabyArt
Inherits Art
End Class

QUESTION 2
a) Using the Database structure in figure 1, create a database in Microsoft Access OR Microsoft
SQL server and populate each table with at least fifteen (15) appropriate records. Then, you
are required to design an appropriate user interface, connect it to the database, retrieve and
display all Artist records in a DataGrid View control on the interface.

Sample User Interface for Sub Question a)


Code for Sub Question a)
Dim connString As String = “paste the path to your access database file here”
Dim Myconnection As OleDbConnection
Dim dbda As OleDbDataAdapter
Dim dbds As DataSet
Dim tables As DataTableCollection
Dim source As New BindingSource

Try
Myconnection = New OleDbConnection
Myconnection.ConnectionString = connString
dbds = New DataSet
tables = dbds.Tables
dbda = New OleDbDataAdapter("Select * from [Artist_TB]", Myconnection)
dbda.Fill(dbds, "Artist_TB")
Dim view As New DataView(tables(0))
source.DataSource = view
DataGridView1.DataSource = view
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

b) Create functionalities for a user to be able to ADD new Records to the database, Delete and
Update Existing Records(using appropriate user interfaces).

Code for Sub Question b)

Private Sub AddNewRecords_Load(sender As Object, e As EventArgs) Handles MyBase.Load


loadAllArtist()
addnewArtistbtn.Enabled = False
updateArtistbtn.Enabled = False
deleteArtistbtn.Enabled = False
artistIdlabel.Visible = False
artistid_txtbox.Visible = False

End Sub

Private Sub updateArtistbtn_Click(sender As Object, e As EventArgs) Handles


updateArtistbtn.Click
updateArtist()

End Sub

Private Sub saveArtist_Click(sender As Object, e As EventArgs) Handles saveArtist.Click


commitArtist()
End Sub

Private Sub deleteArtistbtn_Click(sender As Object, e As EventArgs) Handles


deleteArtistbtn.Click
deleteArtist()
End Sub

Private Sub commitArtist()

Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
If fulllname_txtbox.Text <> "" And gender_txtbox.Text <> "" And
phonenumber_txtbox.Text <> "" And address_txtbox.Text <> "" And email_txtbox.Text <> ""
Then
sql = "insert into Artist_TB([FullName], [Gender], [PhoneNumber], [Address], [E-
mail]) " & "values(?,?,?,?,?)"

Dim olecommand As OleDbCommand = New OleDbCommand(sql, conn)


olecommand.Parameters.Add(New OleDbParameter("FullName",
CType(fulllname_txtbox.Text, String)))
olecommand.Parameters.Add(New OleDbParameter("Gender",
CType(gender_txtbox.Text, String)))
olecommand.Parameters.Add(New OleDbParameter("PhoneNumber",
CType(phonenumber_txtbox.Text, String)))
olecommand.Parameters.Add(New OleDbParameter("Address",
CType(address_txtbox.Text, String)))
olecommand.Parameters.Add(New OleDbParameter("E-mail",
CType(email_txtbox.Text, String)))

Try
olecommand.ExecuteNonQuery()
olecommand.Dispose()
conn.Close()
MessageBox.Show("New Artist Inserted Successfully")
addnewArtistbtn.Enabled = True
updateArtistbtn.Enabled = True
deleteArtistbtn.Enabled = True
artistIdlabel.Visible = True
artistid_txtbox.Visible = True
saveArtist.Enabled = False

Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
Else
MessageBox.Show("All fields cannot be empty")
Return
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub

Private Sub updateArtist()

Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim cb As New OleDb.OleDbCommandBuilder(dataadapter)
dataset.Tables("Artist_TB").Rows(inc).Item(0) = artistid_txtbox.Text
dataset.Tables("Artist_TB").Rows(inc).Item(1) = fulllname_txtbox.Text
dataset.Tables("Artist_TB").Rows(inc).Item(2) = gender_txtbox.Text
dataset.Tables("Artist_TB").Rows(inc).Item(0) = phonenumber_txtbox.Text
dataset.Tables("Artist_TB").Rows(inc).Item(0) = address_txtbox.Text
dataset.Tables("Artist_TB").Rows(inc).Item(0) = email_txtbox.Text
dataadapter.Update(dataset, "Artist_TB")
MessageBox.Show("Artist Updated Successfully")
clearFilds()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

Private Sub loadAllArtist()

Try
conn = New OleDbConnection
conn.ConnectionString = connString
conn.Open()
dataset = New DataSet
tables = dataset.Tables
dataadapter = New OleDbDataAdapter("Select * from [Artist_TB]", conn)
dataadapter.Fill(dataset, "Artist_TB")
conn.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Dim view As New DataView(tables(0))
source.DataSource = view
artistDataGridView.DataSource = view
End Sub

Private Sub deleteArtist()

If MessageBox.Show("Do you really want to Delete this Record?",


"Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) = DialogResult.No Then
MsgBox("Operation Cancelled")
Exit Sub
Else
Dim cb As New OleDb.OleDbCommandBuilder(dataadapter)
dataset.Tables("PG DATABASE").Rows(inc).Delete()
maxrows = maxrows - 1
inc = 0
dataadapter.Update(dataset, "PG DATABASE")
clearFilds()

End If
End Sub

TOP LEVEL VARIABLES THIS CODE GOES TO THE TOP

Dim connString As String = “paste the path to your access database file here”
Dim conn As OleDbConnection
Dim dataadapter As OleDbDataAdapter
Dim dataset As DataSet
Dim tables As DataTableCollection
Dim source As New BindingSource
Dim sql As String
Dim inc As Integer
Dim maxrows As Integer

Question Three.

a. Using the Database created in 2 (a), you are required to create a website/web App, design
an appropriate webpage, connect it to the database, retrieve and display all Collector
records in a GridView control on the Webpage.

Code for Sub Question a)


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)Handles Me.Load
Dim dbLocation = “paste the path to your access database file here”
LoadCollectorGridView(dbLocation)
End Sub

Private Sub LoadCollectorGridView(dbLocation As String)


Dim con = New OleDbConnection(““paste the path to your access database file here””)
Dim cmd = New OleDbCommand("SELECT * FROM Collector_TB", con)
Dim olda = New OleDbDataAdapter(cmd)
Dim dt = New DataTable()
olda.Fill(dt)
ArtistGridView.DataSource = dt
ArtistGridView.DataBind()
End Sub
Code for Sub Question b)

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


Dim dbLocation = “paste the path to your access database file here”
LoadArtGridView(dbLocation)
LoadArtistGridView(dbLocation)

End Sub

Private Sub LoadArtGridView(dbLocation As String)


Dim con = New OleDbConnection(“C:\Users\Kojo Yeboah\Desktop\Exams\Advance
VB\VB-Online Exam\VB-Online Exam\bin\Debug\PG Database.accdb”)
Dim cmd = New OleDbCommand("SELECT * FROM Art_TB", con)
Dim olda = New OleDbDataAdapter(cmd)
Dim dt = New DataTable()
olda.Fill(dt)
ArtGridView.DataSource = dt
ArtGridView.DataBind()
con.Close()
End Sub

Private Sub LoadArtistGridView(dbLocation As String)


Dim con = New OleDbConnection(“paste the path to your access database file here”)
Dim cmd = New OleDbCommand("SELECT * FROM Artist_TB", con)
Dim olda = New OleDbDataAdapter(cmd)
Dim dt = New DataTable()
olda.Fill(dt)
CollectorGridView.DataSource = dt
CollectorGridView.DataBind()
End Sub

You might also like