Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
52 views

Database Programming by Examples-Assignment Student

Vb

Uploaded by

Mligo Clemence
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Database Programming by Examples-Assignment Student

Vb

Uploaded by

Mligo Clemence
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

1

Task-2

Question 1) Define and explain the terms.

a) Tables

A table in database is a data object used to store data. Tables have the following features:

* Data is stored in a table with a structure of rows and columns.


* Columns must be pre-defined with names, types and constrains.

For example, a table called Address may have columns defined to store different elements of an address like, street
number, city, country, postal code, etc.

b) Fields

Fields are the columns in databases. Each field can only hold one data type at any time. e.g. a field
for a date will always, and only, hold a date. Fields can be either fixed or variable in length. They
contain a piece of specific information from a record

c) Records

A record contains all the information about a single 'member' of a table. In a students table, each
student's details (name, date of birth, contact details, and so on) will be contained in its own
record.

d) Index

Index is a summary table which lets you quickly lookup the contents of any record in a table. Think
of how you use an index to a book: as a quick jumping off point to finding full information about a
subject. A database index works in a similar way. You can create an index on any field in a table.
Example, you have a customer table which contains customer numbers, names, addresses and
other details. You can make indexes based on any information, such as the customers' customer
number, last name + first name (a composite index based on more than one field), or postal code.
Then, when you're searching for a particular customer or group of customers, you can use the
index to speed up the search. This increase in performance may not be noticeable in a table
containing a hundred records; in a database of thousands of records it will be a blessing.

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
2

e) Query

A query is an inquiry into the database using the SELECT statement. A query is used to extract
data from the database in a readable format according to the user's request. For instance, if you
have an employee table, you might issue a SQL statement that returns the employee who is paid the
most. This request to the database for usable employee information is a typical query that can be
performed in a relational database.

f) Record set

Recordset is a data structure that consists of a group of database records, and can either come
from a base table or as the result of a query to the table.

The concept is common to a number of platforms, notably Microsoft's Data Access Objects (DAO)
and ActiveX Data Objects (ADO). The Recordset object contains a Fields collection and a
Properties collection. At any time, the Recordset object refers to only a single record within the set
as the current record.

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
3

2) Show the structure of ADO.NET connectivity in Visual Basic.NET with an example?

The database part of .NET, called ADO.NET, offers significant improvements in interoperability,
ease of programming and maintenance, and performance. It is an evolutionary advance from
Microsoft's earlier database technology, called simply ADO (for ActiveX Data Objects).

The process of making a connection is as follows

1) Create a connection string that contains all the needed information, such as the data
source, used name, and password. For example:

Module Module1
Public conn As New SqlClient.SqlConnection
Public Sub connect()
conn.ConnectionString = "initial catalog=sms;data source=mhasan;user id=sa;password=sa;"
End Sub
End Module

The line “Public conn As New SqlClient.SqlConnection” means create a new SQLserver connection.

Initial catalog is the database name

Data source is the name of the computer or server where the SQLServer is installed.

User id is the user name used to connect to the SQLServer

Password is the password used to connect to SQLServer.

Connections

There are two ADO.NET classes to create a connection to a database. The SqlConnection class is
used for connections to Microsoft SQL Server databases (version 7 and later), and the
OleDbConnection class is used for connections to databases that support the OLE DB technology
(for example, Access, Oracle, SQL Server versions 6.5 and earlier, and third party SQL products).

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
4

3) Design and implement a simple lottery Automation system with start button, stop button and
label box. While the start button is pressed the mobile numbers stored in the table should be
displayed in the label boxes and should change within a time span of 1 sec. On pressing the stop
button, the winner name and address should be displayed to the user?

Click event of
“start” button

Me.Width = 356
Timer1.Start()

Form load event

GroupBox2.Visible = False
Me.Width = 356

Timertick event
Click event of “stop” button
connect()
conn.Open() Timer1.Stop()
comm.CommandText = "select * from lottery" GroupBox2.Visible = True
comm.CommandType = CommandType.Text Me.Width = 690
comm.Connection = conn Label4.Text = dt.Rows(i - 1).Item(1)
adp.SelectCommand = comm Label5.Text = dt.Rows(i - 1).Item(2)
adp.Fill(dt)
Label1.Text = dt.Rows(i).Item(0)
i=i+1
conn.Close()

Declarations for the program

Public Class Form1


Dim adp As New SqlClient.SqlDataAdapter
Dim comm As New SqlClient.SqlCommand
Dim dt As New DataTable
Dim i As Integer
End class
Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database
Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
5

Screenshots of the program while it is running

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
6

4) Create a Visual Basic.NET Application for the given scenario. The database name IBS and the
table name as courses and the fields as course ID, course Name, Duration and affiliations. While
executing the application the records in the field course ID should be loaded to the combo boxes
and on selecting a particular course id, the corresponding values like course Name, Duration and
affiliations for that course should be displayed in the corresponding Text boxes.

Form load event

TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
dt.Clear()
connect()
conn.Open()
comm.CommandText = "select course_id from
courses"
comm.CommandType = CommandType.Text
Declarations for the program comm.Connection = conn
adp.SelectCommand = comm
Public Class Form1 adp.Fill(dt)
Dim adp As New SqlClient.SqlDataAdapter Dim i As Integer
Dim dt, dt2 As New DataTable For i = 0 To dt.Rows.Count - 1
Dim comm As New SqlClient.SqlCommand ComboBox1.Items.Add(dt.Rows(i).Item(0))
End class Next
conn.Close()

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
7

Click event of combobox (combobox text changed


event)
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
dt2.Clear()
connect()
conn.Open()
comm.CommandText = "select * from courses
where course_id='" & ComboBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt2)
TextBox1.Text = dt2.Rows(0).Item(1)
TextBox2.Text = dt2.Rows(0).Item(2)
TextBox3.Text = dt2.Rows(0).Item(3)
conn.Close()

Module Module1
Public conn As New SqlClient.SqlConnection

Public Sub connect()


conn.ConnectionString="initial catalog=IBS;data source=MHASAN;user
id=sa;password=sa;"
End Sub

End Module

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
8

5) Using Data Grid control, display all the contents in the table courses, when a Visual Basic.NET
application is executed. On clicking a particular row or column that particular course details for
which the user has selected should be displayed in the corresponding text boxes.

Form Load event


GroupBox1.Visible = False
connect()
conn.Open()
comm.CommandText = "select * from courses"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()

DataGridview cell click event

GroupBox1.Visible = True
TextBox1.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(0)
TextBox2.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(1)
TextBox3.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(2)
TextBox4.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(3)

Declaration for the program Codes for the module

Public Class Form1 Module Module1


Dim comm As New SqlClient.SqlCommand Public conn As New SqlClient.SqlConnection
Dim adp As New SqlClient.SqlDataAdapter Public Sub connect()
Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database
Dim dt As New DataTable conn.ConnectionString = "initial catalog=IBS;data
Programming
End class source=MHASAN;user id=sa;password=sa;"
Student Id: MIDSE 552 End Sub Student Name:
Mohamed Hassan
9

6) Create a table called enquiry with the fields, applicant name, course opted for, mobile number,
date of enquiry and comments. Design a form in VB.NET with these fields and it should have
option to add new enquiry, and search options like search by name of the applicant, date of enquiry
and view all enquiry. Use menu edition, Data Grid, and MDI form to do the question?

Click event of the “add new query” menustrip item

Form1.Show()

Click event of the “Search” menustrip item

Form2.Show()

Click event of the “add” button


Form load event
connect()
Label6.Text = Format(Date.Today, "MM/dd/yyyy") conn.Open()
connect() comm.CommandText = "insert into enquiry values('" &
conn.Open() TextBox1.Text & "','" & ComboBox1.Text & "','" &
comm.CommandText = "select course_id from courses" TextBox2.Text & "','" & Label6.Text & "','" &
comm.CommandType = CommandType.Text RichTextBox1.Text & "')"
comm.Connection = conn comm.CommandType = CommandType.Text
adp.SelectCommand
Module Title: Advanced= comm Visual Programming comm.Connection
(Vb.Net) = conn
Assignment Title: Database
adp.Fill(dt) comm.ExecuteNonQuery()
Programming
Dim i As Integer conn.Close()
For i =Id:
Student 0 ToMIDSE
dt.Rows.Count
552- 1 Student Name:
MsgBox("record added")
ComboBox1.Items.Add(dt.Rows(i).Item(0))
Mohamed
Next Hassan
conn.Close()
10

Clikc event of “Textbox1” Closeup event of “datetime picker”

dt.Clear() dt.Clear()
connect() connect()
conn.Open() conn.Open()
comm.CommandText = "select * from enquiry where comm.CommandText = "select * from enquiry where
applicant_name like '" & TextBox1.Text & "%" & "'" date_of_enquiry='" & Format(DateTimePicker1.Value,
comm.CommandType = CommandType.Text "dd/MM/yyyy") & "'"
comm.Connection = conn comm.CommandType = CommandType.Text
adp.SelectCommand = comm comm.Connection = conn
adp.Fill(dt) adp.SelectCommand = comm
DataGridView1.DataSource = dt adp.Fill(dt)
conn.Close() if dt.rows.count=0 then
else
DataGridView1.DataSource = dt
End if
conn.Close()

TextBox2_TextChanged event

connect()
conn.Open()
comm.CommandText = "select * from enquiry
where mobile_number like '" & TextBox2.Text & "%" &
"'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
Click event of the “view all enquiry” linked textbox

GroupBox5.Visible = True
GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox4.Visible = False
dt.Clear()
connect()
conn.Open()
Module Title: Advanced
comm.CommandText = "select *Visual Programming
from enquiry" (Vb.Net) Assignment Title: Database
comm.CommandType
Programming = CommandType.Text
comm.Connection = conn
Student Id: MIDSE
adp.SelectCommand 552
= comm Student Name:
Mohamed
adp.Fill(dt) Hassan
DataGridView1.DataSource = dt
conn.Close()
11

Public Class Form1


Public comm As New SqlClient.SqlCommand
Public adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
End class

Module Module1
Public conn As New SqlClient.SqlConnection
Public Sub connect()
conn.ConnectionString = "initial catalog=IBS;data source=MHASAN;user id=sa;password=sa;"
End Sub
End Module

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
12

7) Follow the procedure as said in question 6 and on displaying the details in the corresponding
text boxes, the Course ID text box should be disabled. On making the necessary editing, and when
the user presses the update button, the newly updated records from the form should be updated to
the table as well as Grid values / details should be updated automatically?

“Gridvalues” function

dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from enquiry"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()

Form load event

GroupBox1.Enabled = False
gridvalues()

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
13

Cell click event of the “Datagrid”

GroupBox1.Enabled = True
ComboBox1.Enabled = False
TextBox1.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(0)
ComboBox1.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(1)
TextBox2.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(2)
TextBox3.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(3)
RichTextBox1.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(4)

Cell click event of “update” button

connect()
conn.Open()
comm.CommandText = "update enquiry set
applicant_name='" & TextBox1.Text &
"',mobile_number='" & TextBox2.Text &
"',date_of_enquiry='" & TextBox3.Text &
"',comments='" & RichTextBox1.Text & "' where
course_opted='" & ComboBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
conn.Close()
MsgBox("record updated")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ComboBox1.Text = ""
RichTextBox1.Text = ""
gridvalues() adp.Fill(dt)
conn.Close()

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
14

Public Class Form1


Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt, dt1, dt2 As New DataTable
End class

Module Module1
Public conn As New SqlClient.SqlConnection
Public Sub connect()
conn.ConnectionString = "initial catalog=IBS;data source=MHASAN;user id=sa;password=sa;"
End Sub
End Module

8) Follow the procedure as said in question 6 and on displaying the details in the corresponding
text boxes, the Course ID textbox should be disabled. Create a button with the caption “Delete”
and on pressing the “Delete” button that particular record should be deleted from the table. As
well as the Grid values / details should be updated automatically?

Form Load event

GroupBox1.Enabled = False
gridvalues()

“gridvalues” Function

dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from enquiry"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
15

Cell click event of the datagrid

ComboBox1.Enabled = False
GroupBox1.Enabled = True
TextBox1.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(0)
ComboBox1.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(1)
TextBox2.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(2)
TextBox3.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(3)
RichTextBox1.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(4)

Click event of the “delete” button

dt.Clear()
connect()
conn.Open()
comm.CommandText = "delete enquiry where course_opted='" & ComboBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
conn.Close()
MsgBox("record deleted")
Module Title: Advanced Visual Programming (Vb.Net)
gridvalues() Assignment Title: Database
TextBox1.Text
Programming = ""
TextBox2.Text = ""
Student Id: MIDSE
TextBox3.Text = "" 552 Student Name:
ComboBox1.Text
Mohamed = ""
Hassan
RichTextBox1.Text = ""
16

Public Class Form1


Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
End class

Module Module1
Public conn As New SqlClient.SqlConnection
Public Sub connect()
conn.ConnectionString = "initial catalog=IBS;data source=MHASAN;user id=sa;password=sa;"
End Sub
End Module

9) Design a simple application using VB.NET for library Management where the should be options
for

a) Adding books

b) Searching books by

i) Name

II) ID

III) Publisher

IV) Author

c) Edit book details

d) Delete a book

e) Issues

f) Returns

g) Members

i) add member
Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database
Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
17

ii) Search member

1) by Name

2) By ID

III) delete Member

IV) Edit member Details

While member makes a book request the system should check whether the member has already
borrowed the maximum book or not. If not the system should check whether the book is available in
the stock. If so issues have to be recorded. While a member returns a book the system should check
whether the due_date has exceeded or not. If so the corresponding fine has to be calculated. For
each day exceeded the fine should be 50 laaree. While adding a member along with the details, add
the photo of the member to the database using the image tool.

Generate a Report for the Fine collected, and member details using crystal report. The
should be functions like

1) View monthly fine amount collected.

2) View fine amount collected for a particular date/day.

3) View a particular member detail by giving the member id.

Login
Click eventform
of the “login” button Clikc event of the “Cancel” button

If TextBox1.Text = "" Then TextBox1.Text = ""


MsgBox("Please fill the user name field")
ElseIf TextBox2.Text = "" Then
TextBox2.Text = ""
MsgBox("Please fill the password field")
Else
dt.Clear() Declarations for the “login” form
fname = TextBox1.Text
connect()
conn.Open() Public Class login
comm.CommandText = "select * from login where user_name='" & Dim comm As New SqlClient.SqlCommand
TextBox1.Text & "'"
Dim adp As New SqlClient.SqlDataAdapter
comm.CommandType = CommandType.Text
comm.Connection = conn Dim dt As New DataTable
adp.SelectCommand = comm Public codes
Module fname, flevel, fpassword, dname,
adp.Fill(dt) dpassword As String
If dt.Rows.Count = 0 Then
MsgBox("Invalid user name")
End classModule1
Module
Else Public conn As New SqlClient.SqlConnection
fpassword = TextBox2.Text Public buttontext As String
dpassword = dt.Rows(0).Item("user_password")
If fpassword = dpassword Then Public Sub connect()
MsgBox("Login successful") conn.ConnectionString = "initial
MDIParent1.Show() catalog=library;data source=MHASAN;user
flevel = dt.Rows(0).Item("user_level")
id=sa;password=sa;"
Me.Hide()
If (flevel = "user") Then End Sub
MDIParent1.LoginToolStripMenuItem.Enabled = False Public Sub edite()
Module EndTitle:
If Advanced Visual Programming (Vb.Net) Assignment Title: Database
buttontext = "Edit"
Programming End Sub
Else
Student Id: MIDSE
MsgBox("Invalid 552
password") Student Name:
Public Sub del()
End If
Mohamed Hassan buttontext = "Delete"
End If End Sub
conn.Close()
End If
End Module
18

Mdiparent form

Imports System.Windows.Forms

Public Class MDIParent1

Private Sub AddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


AddToolStripMenuItem.Click
addbook.Show()
Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database
Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
19

End Sub

Private Sub SearchBooksToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


SearchBooksToolStripMenuItem.Click
search.Show()
End Sub

Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


EditToolStripMenuItem.Click
edite()
Form1.Show()

End Sub

Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


DeleteToolStripMenuItem.Click
del()
Form1.Show()
End Sub

Private Sub SearchToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


SearchToolStripMenuItem.Click
member_search.Show()
End Sub

Private Sub AddToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


AddToolStripMenuItem1.Click
member_add.Show()
End Sub

Private Sub DeleteToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


DeleteToolStripMenuItem1.Click
del()
member_edit_delete.Show()
End Sub

Private Sub EditToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


EditToolStripMenuItem1.Click
edite()
member_edit_delete.Show()
End Sub

Private Sub IssuesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


IssuesToolStripMenuItem.Click
issues.Show()
End Sub

Private Sub ReturnsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


ReturnsToolStripMenuItem.Click
returns.Show()
End Sub

Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


ToolStripStatusLabel1.Text = "Date : " & Format(Date.Now, "MM/dd/yyyy")
ToolStripStatusLabel2.Text = "User Name :" & login.fname
End Sub

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
20

Private Sub AddToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


AddToolStripMenuItem2.Click
login_add.Show()
End Sub

Private Sub EditToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


EditToolStripMenuItem2.Click
login_delete_edit.Show()
login_delete_edit.Button1.Text = "edit"
End Sub

Private Sub DeleteToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


DeleteToolStripMenuItem2.Click
login_delete_edit.Show()
login_delete_edit.Button1.Text = "delete"
End Sub

Private Sub MonthlyFineToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MonthlyFineToolStripMenuItem.Click
monthly_fine.Show()
End Sub

Private Sub FineForADayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


FineForADayToolStripMenuItem.Click
report_day.Show()
End Sub

Private Sub MemberToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MemberToolStripMenuItem.Click
report_member_id.Show()
End Sub
End Class

Login table details

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
21

Only “administrator” user_level users can LoginToolStripMenuItem is


change the login details for the system disabled for system users
users. whose user_level is “user”.

If the system user is an


“administrator” then it is
enabled.

Click event of the “add book” button

If TextBox1.Text = "" Then


MsgBox("Please fill book id field")
ElseIf TextBox2.Text = "" Then
MsgBox("Please enter a book name")
ElseIf TextBox3.Text = "" Then
MsgBox("Please enter a publisher")
addbook form ElseIf TextBox4.Text = "" Then
MsgBox("Please enter an author")
ElseIf TextBox5.Text = "" Then
addbook form MsgBox("Please enter book cost")
ElseIf TextBox6.Text = "" Then
MsgBox("Please enter an isbn number")

Else
connect()
Form load event (generating auto increment book number) conn.Open()
TextBox1.Enabled = False comm.CommandText = "insert into book values('" &
connect() TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text &
conn.Open() "','" & TextBox4.Text & "'," & TextBox5.Text & ",'" &
comm.CommandText = "select * from book" TextBox6.Text & "')"
comm.CommandType = CommandType.Text comm.CommandType = CommandType.Text
comm.Connection = conn comm.Connection = conn
adp.SelectCommand = comm comm.ExecuteNonQuery()
adp.Fill(dt) conn.Close()
Dim id, bid As String MsgBox("Record added")
Dim newid, rowcount As Integer TextBox1.Text = " "
rowcount = dt.Rows.Count TextBox2.Text = " "
TextBox3.Text = " "
If rowcount = 0 Then TextBox4.Text = " "
TextBox1.Text = "B001" TextBox5.Text = " "
Module
Else Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database
TextBox6.Text = " "
Programming
id = dt.Rows(rowcount - 1).Item(0) End If
newid = id.Substring(3,
Student Id: MIDSE 552 1) + 1 Student Name:
bid = id.Substring(0, 3)
Mohamed Hassan
TextBox1.Text = bid & newid
End If
conn.Close()
22

Declarations for the “addbook” form

Public Class addbook

Dim comm As New SqlClient.SqlCommand


Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTabl

End class

Form 1 (Edit and delete books)

Form load event


Form1 Design View (edit/delete books)
GroupBox1.Visible = False
gridvalues()

gridvalues function
Cell click event of “DataGridView1”
Public Sub gridvalues()
dt.Clear()
GroupBox1.Visible = True
connect()
TextBox1.Enabled = False
conn.Open() =
TextBox1.Text
comm.CommandText = "select * from book"
dt.Rows(DataGridView1.CurrentRow.Index).Item(0)
comm.CommandType
TextBox2.Text = = CommandType.Text
comm.Connection = conn
dt.Rows(DataGridView1.CurrentRow.Index).Item(1)
adp.SelectCommand
TextBox3.Text = = comm
adp.Fill(dt)
Module Title: Advanced Visual Programming (Vb.Net) Assignment
DataGridView1.DataSource = dt
Title: Database
dt.Rows(DataGridView1.CurrentRow.Index).Item(2)
TextBox4.Text =
Programming conn.Close()
dt.Rows(DataGridView1.CurrentRow.Index).Item(3)
End Sub
TextBox5.Text =
Student Id: MIDSE 552 Student Name:
dt.Rows(DataGridView1.CurrentRow.Index).Item(4)
Mohamed Hassan TextBox6.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(5)
Button1.Text = buttontext
23

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
24

Click event of the button ( if the Mdiparents book edit is pressed then button text become “edit” . if the Mdiparents book delete is
pressed then button text become “delete”)

If Button1.Text = "Edit" Then


connect()
conn.Open()
comm.CommandText = "update book set book_name='" & TextBox2.Text & "',publisher='" & TextBox3.Text & "',author='" &
TextBox4.Text & "',cost=" & TextBox5.Text & ",isbn='" & TextBox6.Text & "' where book_id='" & TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
conn.Close()
MsgBox("book details updated")
gridvalues()
ElseIf Button1.Text = "Delete" Then
connect()
conn.Open()
comm.CommandText = "delete from book where book_id = '" & TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
conn.Close()
MsgBox("book deleted")
gridvalues()
End If

TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
25

Declarations for form1

Public Class Form1

Dim comm As New SqlClient.SqlCommand


Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable

End class

Search form for book

Click event of textbox (textchange ivent)

dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from book where isbn
like '" & TextBox6.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database
conn.Close()
Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
26

Public Class search


Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTabl

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = False
GroupBox8.Visible = False
GroupBox9.Visible = False
End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


Handles LinkLabel1.LinkClicked
GroupBox2.Visible = True
GroupBox3.Visible = False
GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = False
GroupBox8.Visible = False
GroupBox9.Visible = True
dt.Clear()
End Sub

Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


Handles LinkLabel2.LinkClicked
dt.Clear()
GroupBox2.Visible = False
GroupBox3.Visible = True
GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = False
GroupBox8.Visible = False
GroupBox9.Visible = True
End Sub

Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


Handles LinkLabel3.LinkClicked
dt.Clear()
GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox4.Visible = True
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = False
GroupBox8.Visible = False
GroupBox9.Visible = True
End Sub
Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database
Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
27

Private Sub LinkLabel4_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


Handles LinkLabel4.LinkClicked
dt.Clear()
GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox4.Visible = False
GroupBox5.Visible = True
GroupBox6.Visible = False
GroupBox7.Visible = False
GroupBox8.Visible = False
GroupBox9.Visible = True
End Sub

Private Sub LinkLabel5_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


Handles LinkLabel5.LinkClicked
dt.Clear()
GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = True
GroupBox7.Visible = False
GroupBox8.Visible = False
GroupBox9.Visible = True
End Sub

Private Sub LinkLabel7_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = False
GroupBox8.Visible = True
GroupBox9.Visible = True
End Sub

Private Sub LinkLabel6_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = True
GroupBox8.Visible = False
GroupBox9.Visible = False
End Sub

Private Sub LinkLabel6_LinkClicked_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


Handles LinkLabel6.LinkClicked
dt.Clear()
GroupBox2.Visible = False
GroupBox3.Visible = False
GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = True
GroupBox8.Visible = False
GroupBox9.Visible = True
End Sub

Private Sub LinkLabel7_LinkClicked_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)


Handles LinkLabel7.LinkClicked
dt.Clear()
GroupBox2.Visible = False
GroupBox3.Visible = False

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
28

GroupBox4.Visible = False
GroupBox5.Visible = False
GroupBox6.Visible = False
GroupBox7.Visible = False
GroupBox8.Visible = True
GroupBox9.Visible = True
ComboBox1.Items.Add("Yes")
ComboBox1.Items.Add("No")
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from book where book_id like '" & TextBox1.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from book where book_name like '" & TextBox2.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from book where publisher like '" & TextBox3.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
End Sub

Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from book where author like '" & TextBox4.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
End Sub

Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from book where cost like '" & TextBox5.Text & "%" & "'"
comm.CommandType = CommandType.Text

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
29

comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
End Sub

Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from book where isbn like '" & TextBox6.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


ComboBox1.SelectedIndexChanged
dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from book where available like '" & ComboBox1.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
End Sub
End Class

Click event of the “Add” button

If TextBox1.Text = "" Then


MsgBox("Please enter an id")
ElseIf TextBox2.Text = "" Then
MsgBox("Please enter a name")
ElseIf TextBox3.Text = "" Then
MsgBox("Please enter a permanent address")
ElseIf TextBox4.Text = "" Then
Form Load event (Auto incrementing member id)
MsgBox("please enter present address")
ElseIf TextBox5.Text = "" Then
TextBox1.Enabled = False
MsgBox("Please enter national id number")
connect()
ElseIf TextBox6.Text = "" Then
conn.Open()
member_add
MsgBox("pleaseform
enter (To add
contact members)
number")
comm.CommandText = "select * from member"
Else
comm.CommandType = CommandType.Text
comm.Connection = conn
connect()
adp.SelectCommand = comm
conn.Open()
Clickcomm.CommandText
event of “browse” button adp.Fill(dt)
= "insert into member values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" &
Dim id, textid As String
TextBox4.Text & "','" & TextBox5.Text & "'," & TextBox6.Text & ",'" & pfilename & "')"
OpenFileDialog1.Filter = "picture files(*.jpg)|*.jpg" Dim newid, rcount As Integer
comm.CommandType = CommandType.Text
If OpenFileDialog1.ShowDialog = rcount = dt.Rows.Count
comm.Connection = conn
Module Title: Advanced
Windows.Forms.DialogResult.OK
comm.ExecuteNonQuery() Then Visual Programming (Vb.Net) Assignment Title: Database
If rcount = 0 Then
PictureBox1.Image = TextBox1.Text = "M001"
conn.Close()
Programming
Image.FromFile(OpenFileDialog1.FileName) Else
MsgBox("member added")
id = dt.Rows(rcount - 1).Item(0)
Student
End If Id: MIDSE 552
pfilename = OpenFileDialog1.FileName Student Name:
newid = id.Substring(3, 1) + 1
End If
TextBox2.Text = ""
Mohamed Hassan
TextBox3.Text = ""
textid = id.Substring(0, 3)
TextBox1.Text = textid & newid
TextBox4.Text = ""
End If
TextBox5.Text = ""
conn.Close()
TextBox6.Text = ""
30

Click event of “textbox1” (TextBox1_TextChanged) Cell click of DataGrid (DataGridView1_CellClick)

dt.Clear() Label14.Text =
connect() dt.Rows(DataGridView1.CurrentRow.Index).Item(0)
conn.Open() Label15.Text =
comm.CommandText = "select * from member where member_id like '" & dt.Rows(DataGridView1.CurrentRow.Index).Item(1)
TextBox1.Text & "%" & "'" Label16.Text =
Member_search
comm.CommandType form (To search members)
= CommandType.Text dt.Rows(DataGridView1.CurrentRow.Index).Item(2)
comm.Connection = conn Label17.Text =
adp.SelectCommand = comm dt.Rows(DataGridView1.CurrentRow.Index).Item(3)
adp.Fill(dt) Label18.Text =
GroupBox9.Visible = True dt.Rows(DataGridView1.CurrentRow.Index).Item(4)
If dt.Rows.Count = 0 Then Label19.Text =
Else dt.Rows(DataGridView1.CurrentRow.Index).Item(5)
Module Title: Advanced
DataGridView1.DataSource = dt Visual Programming (Vb.Net) PictureBox1.Image
Assignment = Title: Database
Programming
Label14.Text = dt.Rows(0).Item(0) Image.FromFile(dt.Rows(DataGridView1.CurrentRow.Index).Ite
Label15.Text = dt.Rows(0).Item(1) m(6))
Student Id: MIDSE
Label16.Text 552
= dt.Rows(0).Item(2) End Sub Student Name:
Label17.Text = dt.Rows(0).Item(3)
Mohamed Hassan
Label18.Text = dt.Rows(0).Item(4)
Label19.Text = dt.Rows(0).Item(5)
PictureBox1.Image = Image.FromFile(dt.Rows(0).Item(6))
End If
31

Public Class member_search


Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
Private Sub member_search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GroupBox9.Visible = False
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from member where member_id like '" & TextBox1.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
GroupBox9.Visible = True
If dt.Rows.Count = 0 Then
Else

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
32

DataGridView1.DataSource = dt
Label14.Text = dt.Rows(0).Item(0)
Label15.Text = dt.Rows(0).Item(1)
Label16.Text = dt.Rows(0).Item(2)
Label17.Text = dt.Rows(0).Item(3)
Label18.Text = dt.Rows(0).Item(4)
Label19.Text = dt.Rows(0).Item(5)
PictureBox1.Image = Image.FromFile(dt.Rows(0).Item(6))
End If

conn.Close()
End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from member where name like '" & TextBox2.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
If dt.Rows.Count = 0 Then
Else
DataGridView1.DataSource = dt
GroupBox9.Visible = True
Label14.Text = dt.Rows(0).Item(0)
Label15.Text = dt.Rows(0).Item(1)
Label16.Text = dt.Rows(0).Item(2)
Label17.Text = dt.Rows(0).Item(3)
Label18.Text = dt.Rows(0).Item(4)
Label19.Text = dt.Rows(0).Item(5)
PictureBox1.Image = Image.FromFile(dt.Rows(0).Item(6))
End If
conn.Close()
End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from member where permanent_address like '" & TextBox3.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
If dt.Rows.Count = 0 Then
Else
DataGridView1.DataSource = dt
GroupBox9.Visible = True
Label14.Text = dt.Rows(0).Item(0)
Label15.Text = dt.Rows(0).Item(1)
Label16.Text = dt.Rows(0).Item(2)
Label17.Text = dt.Rows(0).Item(3)
Label18.Text = dt.Rows(0).Item(4)
Label19.Text = dt.Rows(0).Item(5)
PictureBox1.Image = Image.FromFile(dt.Rows(0).Item(6))
End If
conn.Close()
End Sub

Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged


dt.Clear()
connect()
conn.Open()

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
33

comm.CommandText = "select * from member where present_address like '" & TextBox4.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
If dt.Rows.Count = 0 Then
Else
DataGridView1.DataSource = dt
GroupBox9.Visible = True
Label14.Text = dt.Rows(0).Item(0)
Label15.Text = dt.Rows(0).Item(1)
Label16.Text = dt.Rows(0).Item(2)
Label17.Text = dt.Rows(0).Item(3)
Label18.Text = dt.Rows(0).Item(4)
Label19.Text = dt.Rows(0).Item(5)
PictureBox1.Image = Image.FromFile(dt.Rows(0).Item(6))
End If
conn.Close()
End Sub

Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from member where national_id like '" & TextBox5.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
If dt.Rows.Count = 0 Then
Else
DataGridView1.DataSource = dt
GroupBox9.Visible = True
Label14.Text = dt.Rows(0).Item(0)
Label15.Text = dt.Rows(0).Item(1)
Label16.Text = dt.Rows(0).Item(2)
Label17.Text = dt.Rows(0).Item(3)
Label18.Text = dt.Rows(0).Item(4)
Label19.Text = dt.Rows(0).Item(5)
PictureBox1.Image = Image.FromFile(dt.Rows(0).Item(6))
End If
conn.Close()
End Sub

Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from member where contact_number like '" & TextBox6.Text & "%" & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
If dt.Rows.Count = 0 Then
Else
DataGridView1.DataSource = dt
GroupBox9.Visible = True
Label14.Text = dt.Rows(0).Item(0)
Label15.Text = dt.Rows(0).Item(1)
Label16.Text = dt.Rows(0).Item(2)
Label17.Text = dt.Rows(0).Item(3)
Label18.Text = dt.Rows(0).Item(4)
Label19.Text = dt.Rows(0).Item(5)
PictureBox1.Image = Image.FromFile(dt.Rows(0).Item(6))
End If
conn.Close()
End Sub

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
34

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


GroupBox9.Hide()
End Sub

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles


DataGridView1.CellClick
Label14.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(0)
Label15.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(1)
Label16.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(2)
Label17.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(3)
Label18.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(4)
Label19.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(5)
PictureBox1.Image = Image.FromFile(dt.Rows(DataGridView1.CurrentRow.Index).Item(6))
End Sub

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
35

mebmer_edit_delete form (to edit and delete members)

Form load event

gridvalues()

Gridvalues function codes

dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from member"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()

Cell click event of DataGridView1


TextBox1.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(0)
TextBox2.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(1)
TextBox3.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(2)
TextBox4.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(3)
TextBox5.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(4)
TextBox6.Text =
dt.Rows(DataGridView1.CurrentRow.Index).Item(5)
TextBox1.Enabled = False
Button1.Text = buttontext

Click event of the button

If Button1.Text = "Delete" Then


dt.Clear()
connect()
conn.Open()
comm.CommandText = "delete from member where member_id='"
& TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
MsgBox("member details deleted")
conn.Close()
ElseIf Button1.Text = "Edit" Then
dt.Clear()
connect()
comm.CommandText = "update member set name='" &
TextBox2.Text & "',permanent_address='" & TextBox3.Text &
"',present_address='" & TextBox4.Text & "',national_id='" &
TextBox5.Text & "',contact_number=" & TextBox6.Text & " where
member_id='" & TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
Module Title: Advanced Visual Programming (Vb.Net) MsgBox("memberAssignment
details updated") Title: Database
conn.Close()
Programming End If
Student Id: MIDSE 552 gridvalues() Student Name:
Mohamed Hassan
36

Declaration for the member_edit_delete form

Public Class member_edit_delete


Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
End class

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
37

issues form (to record the issued book details)

click event of the “member or not” button form load event


TextBox2.Enabled = False
dt.Clear() Button1.Enabled = False
connect() Button2.Enabled = False
conn.Open()
comm.CommandText = "select * from member where member_id='" & TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm Declaration for the issues form
adp.Fill(dt)
If dt.Rows.Count = 0 Then Public Class issues
MsgBox("not a member") Dim comm As New
TextBox1.Text = "" SqlClient.SqlCommand
GoTo c Dim adp As New
Else SqlClient.SqlDataAdapter
MsgBox("member") Dim dt, dt2, dt3 As New DataTable
TextBox2.Enabled = True End class
End If
conn.Close()
dt2.Clear()
connect()
conn.Open()
comm.CommandText = "select * from issue where member_id='" & TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt2)
If (dt2.Rows.Count = 0) Then
TextBox1.Enabled = True
MsgBox("2 books can be borrowed")
Label5.Text = Format(Date.Now, "MM/dd/yyyy")
Label6.Text = Format(DateAdd(DateInterval.Day, 14, Date.Now), "MM/dd/yyyy")
Button2.Enabled = True
ElseIf (dt2.Rows.Count = 1) Then
MsgBox("1 book can be borrowed")
TextBox2.Enabled = True
Label5.Text = Format(Date.Now, "MM/dd/yyyy")
Module Title:=Advanced
Label6.Text Visual Programming
Format(DateAdd(DateInterval.Day, (Vb.Net)
14, Date.Now), "MM/dd/yyyy") Assignment Title: Database
Button2.Enabled = True
Programming
Else
Student Id: MIDSE
MsgBox("Can't borrow552
more than 2 books") Student Name:
TextBox2.Enabled = False
Mohamed Hassan
Button1.Enabled = False
End If
c:
conn.Close()
38

Click event of the “book available or not” button

dt3.Clear()
connect()
conn.Open()
comm.CommandText = "select * from issue where book_id='" &
TextBox2.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt3)
If dt3.Rows.Count = 1 Then
MsgBox("book is not availble")
TextBox2.Text = ""
Else
MsgBox("Book Available")
TextBox2.Enabled = True
Button1.Enabled = True
Label8.Text = login.fname
End If
Click event of the “Add” button conn.Close()

dt.Clear()
connect()
conn.Open()
comm.CommandText = "insert into issue values('" &
TextBox1.Text & "','" & TextBox2.Text & "','" & Label5.Text & "','"
& Label6.Text & "','" & Label8.Text & "')"
comm.CommandType = CommandType.Text
comm.Connection = conn
comm.ExecuteNonQuery()
conn.Close()

MsgBox("book issued")
TextBox1.Text = ""
TextBox2.Text = ""
Label5.Text = ""
Label6.Text = ""
Label8.Text = ""
TextBox2.Enabled = False
Button1.Enabled = False
Button2.Enabled = False

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
39

returns form ( to keep records of the fines collected and to return books )

click event of “search” button

dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from issue where book_id='"
& TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
Label7.Text = dt.Rows(0).Item(0)
Label8.Text = dt.Rows(0).Item(3)
return_date = Label8.Text
Label9.Text = Format(Date.Now, "MM/dd/yyyy")
returned_date = Label9.Text
dayselapsed = DateDiff(DateInterval.Day, return_date,
returned_date, FirstDayOfWeek.Sunday)
If dayselapsed > 14 Then
fine = 0.5 * dayselapsed
Label11.Text = Format(fine, "#.00")
Label10.Text = dayselapsed
Button1.Visible = True
conn.Close()
Else
Label10.Text = "0"
Label11.Text = "0"
dt.Clear()
conn.Close()
connect()
conn.Open()
comm.CommandText = "delete from issue where
book_id='" & TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
conn.Close()
MsgBox("book returned")
conn.Close()
End If

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
40

dt.Clear()
connect()
conn.Open()
comm.CommandText = "insert into fine values('" & TextBox1.Text
& "','" & Label7.Text & "', '" & Label8.Text & "','" & Label9.Text & "',"
& Label10.Text & "," & Label11.Text & ")"
comm.CommandType = CommandType.Text
comm.Connection = conn
comm.ExecuteNonQuery()
conn.Close()
MsgBox("fine details added")
conn.Close()

dt.Clear()
connect()
conn.Open()
comm.CommandText = "delete from issue where book_id='" &
TextBox1.Text & "'"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
conn.Close()
MsgBox("book returned")
conn.Close()
TextBox1.Text = ""
Label7.Text = ""
Label8.Text = ""
Label9.Text
Declarations = ""
for the form
Module ClassTitle:
Label10.Text
Public Advanced Visual Programming
returns= "" (Vb.Net) Assignment Title: Database
DimLabel11.Text
comm As =
New ""
Programming SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Student
Dim
form dt As
load Id:
NewMIDSE
event DataTable 552 Student Name:
Dim dayselapsed As Integer
Mohamed Hassan
Dim return_date, returned_date As Date
Button1.Visible = False
Dim fine As Double
End class
41

login_add form (to add system users)

Click event of the “Add” button

If TextBox1.Text = "" Then


MsgBox("Please fill user name")
ElseIf TextBox2.Text = "" Then
MsgBox("Please fill password field")
ElseIf ComboBox1.Text = "" Then
MsgBox("Please select user level")
Else
connect()
conn.Open()
comm.CommandText = "insert into login values('" & TextBox1.Text
& "','" & TextBox2.Text & "','" & ComboBox1.Text & "')"
comm.CommandType = CommandType.Text
comm.Connection = conn
comm.ExecuteNonQuery()
MsgBox("user added")
Form Load event conn.Close()

ComboBox1.Items.Add("administrator") TextBox1.Text = ""


ComboBox1.Items.Add("user") TextBox2.Text = ""
ComboBox1.Text = ""
End If

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
42

login_delete_edit form (to delete and edit system users)

Form load event

TextBox1.Enabled = False
TextBox2.Enabled = False
ComboBox1.Enabled = False
Button1.Enabled = False
gridvalues()
ComboBox1.Items.Add("user")
ComboBox1.Items.Add("administrator")

function for gridvalues

Public Sub gridvalues()


dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from login"
comm.CommandType = CommandType.Text
comm.Connection = conn
adp.SelectCommand = comm
adp.Fill(dt)
Click event of the “edit” or “delete” button DataGridView1.DataSource = dt
conn.Close()
If (Button1.Text = "edit") Then End Sub
dt.Clear()
connect()
conn.Open() Cell click event of DataGridView1(DataGridView1_CellClick)
comm.CommandText = "update login set user_password='" &
TextBox2.Text & "', user_level='" & ComboBox1.Text & "' where TextBox1.Text =
user_name='" & TextBox1.Text & "'" dt.Rows(DataGridView1.CurrentRow.Index).Item(0)
comm.CommandType = CommandType.Text TextBox2.Text =
comm.Connection = conn dt.Rows(DataGridView1.CurrentRow.Index).Item(1)
adp.SelectCommand = comm Button1.Enabled = True
adp.Fill(dt) TextBox1.Enabled = False
conn.Close() TextBox2.Enabled = True
MsgBox("login details edited") ComboBox1.Enabled = True
gridvalues()
ElseIf (Button1.Text = "delete") Then
dt.Clear()
connect()
conn.Open()
comm.CommandText = "delete from login where user_name='" &
Module
TextBox1.Text Title:
& "'" Advanced Visual Programming (Vb.Net) Assignment Title: Database
comm.CommandType = CommandType.Text
Programming
comm.Connection = conn
Student Id: MIDSE
adp.SelectCommand 552
= comm Student Name:
adp.Fill(dt)
Mohamed Hassan
conn.Close()
MsgBox("login details deleted")
gridvalues()
End If
43

Declarations for the “login_delete_edit” form

Public Class login_delete_edit


Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
End Class

Module Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database


Programming
Student Id: MIDSE 552 Student Name:
Mohamed Hassan
44

monthly_fine form (to generate Report for monthly fine collected)

Declarations for the monthly_fine form

Public Class monthly_fine


Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
Dim startdate, enddate As String
End Class

DateTimePicke2_CloseUp Event

enddate = Format(DateTimePicker2.Value, "MM/dd/yyyy")

Click event of the “fine” button

dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from fine where
returned_date>='" & startdate & "' and returned_date<='" &
enddate & "'"
Module Title: Advanced
comm.CommandType Visual Programming (Vb.Net)
= CommandType.Text Assignment Title: Database
Programming
comm.Connection = conn
DateTimePicker1_CloseUp Event
adp.SelectCommand = comm
Student Id: MIDSE 552
adp.Fill(dt) Student Name:
Dim rpt AsHassan
New CrystalReport1 startdate = Format(DateTimePicker1.Value, "MM/dd/yyyy")
Mohamed
rpt.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rpt
conn.Close()
45

report_day form (to generate fine collected amount for a particular day)

Declarations for the report_day Declarations for the report_day

Public Class report_day ddate = Format(DateTimePicker1.Value, "MM/dd/yyyy")


Dim ddate As String
Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
End Class

Click event of the “fine/day” button

connect()
conn.Open()
comm.CommandText = "select * from fine where returned_date='" & ddate & "'"
comm.CommandType
Module Title: Advanced= CommandType.Text
Visual Programming (Vb.Net) Assignment Title: Database
comm.Connection = conn
Programming
adp.SelectCommand = comm
adp.Fill(dt)
Student
Dim rpt2Id: MIDSE
As New 552
CrystalReport2 Student Name:
Mohamed Hassan
rpt2.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rpt2
conn.Close()
46

report_member_id form (to generate report for member details by searching for a given
member id)

Declaration for the “report_member_id” form

Public Class report_member_id


Dim comm As New SqlClient.SqlCommand
Dim adp As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
End Class

Click event of “Search” button

dt.Clear()
connect()
conn.Open()
comm.CommandText = "select * from member where member_id='" &
TextBox1.Text
Module & "'" Advanced Visual Programming (Vb.Net)
Title: Assignment Title: Database
comm.CommandType = CommandType.Text
Programming
comm.Connection = conn
adp.SelectCommand = comm
Student Id: MIDSE 552
adp.Fill(dt) Student Name:
Mohamed
Dim rpt3 AsHassan
New CrystalReport3
rpt3.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rpt3
conn.Close()

You might also like