0% found this document useful (0 votes)
47 views

Sample VB Solution

This document contains an answer sheet for an end of semester examination on Advanced Visual Basic .NET Programming. It includes questions on creating classes and properties to represent art objects with validation, calculating the age of a painting, displaying values in message boxes, inheriting from a base class, and performing CRUD operations on an artist database with a user interface and data binding.

Uploaded by

Amoasi D' Oxygen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Sample VB Solution

This document contains an answer sheet for an end of semester examination on Advanced Visual Basic .NET Programming. It includes questions on creating classes and properties to represent art objects with validation, calculating the age of a painting, displaying values in message boxes, inheriting from a base class, and performing CRUD operations on an artist database with a user interface and data binding.

Uploaded by

Amoasi D' Oxygen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

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 One
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)

Public Property Art_Id() As String


Get
Return artId

End Get
Set(value As String)
artId = value
End Set
End Property

Public Property Artist_Id() As String


Get
Return artistId

End Get
Set(value As String)
artistId = value
End Set
End Property

Public Property Artist_Description() As String


Get
Return description

End Get
Set(value As String)
description = value

End Set
End Property

Public Property DateOfCommissioning() As Date


Get
Return datecommissioned
End Get
Set(value As Date)
datecommissioned = value
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 GetPaintingAge() As Integer
Return (Date.Now.Year - DateOfCommissioning.Year)
End Function

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)

Code for Sub Question d)

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


Button1.Click
Dim myart = New Art
End Sub

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

Sample User Interface for Sub Question e)


Code for Sub Question e)
Dim artid As String
Dim artistid As String
Dim description As String
Dim datecommissioned As String

artid = artid_tb.Text
artistid = artistid_tb.Text
description = description_tb.Text
datecommissioned = date_commissioned_tb.Text
datecommissioned = Convert.ToDateTime("01-04-2014")

myart.Art_Id = artid
myart.Artist_Id = artistid
myart.Artist_Description = description
myart.DateOfCommissioning = datecommissioned

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).

Sample User Interface for Sub Question f)


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)


Class DerivedArt
Inherits Art

End Class
Question Two.
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).

Sample User Interface for Sub Question b)


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("EXAMDATABASE").Rows(inc).Delete()

maxrows = maxrows - 1
inc = 0
dataadapter.Update(dataset, "EXAMDATABASE")
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.

Sample User Interface for Sub Question a)


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

b. Create a functionality in your web App that will enable a user to search for an Artist, and if
the Artist is found, the user can then select it to display details of the Artist as well as the list
of all the Arts/painting created by that artist on a new webpage

Sample User Interface for Sub Question b)


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