You are on page 1of 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) Programming Student Id: MIDSE 552 Mohamed Hassan Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

Screenshots of the program while it is running

Module Title: Advanced Visual Programming (Vb.Net) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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 comm.Connection = conn adp.SelectCommand = comm adp.Fill(dt) Dim i As Integer For i = 0 To dt.Rows.Count - 1 ComboBox1.Items.Add(dt.Rows(i).Item(0)) Next conn.Close()

Declarations for the program Public Class Form1 Dim adp As New SqlClient.SqlDataAdapter Dim dt, dt2 As New DataTable Dim comm As New SqlClient.SqlCommand End class

Module Title: Advanced Visual Programming (Vb.Net) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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 id=sa;password=sa;" End Sub End Module catalog=IBS;data source=MHASAN;user

Module Title: Advanced Visual Programming (Vb.Net) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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 adpTitle: Advanced Visual Programming (Vb.Net) Sub connect() As New SqlClient.SqlDataAdapter Public Module 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 Student Name: End Sub

Mohamed Hassan

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

10

Clikc event of Textbox1 dt.Clear() connect() conn.Open() comm.CommandText = "select * from enquiry where applicant_name like '" & TextBox1.Text & "%" & "'" comm.CommandType = CommandType.Text comm.Connection = conn adp.SelectCommand = comm adp.Fill(dt) DataGridView1.DataSource = dt conn.Close()

Closeup event of datetime picker dt.Clear() connect() conn.Open() comm.CommandText = "select * from enquiry where date_of_enquiry='" & Format(DateTimePicker1.Value, "dd/MM/yyyy") & "'" comm.CommandType = CommandType.Text comm.Connection = conn adp.SelectCommand = comm adp.Fill(dt) 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*Visual Programming comm.CommandText = "select from enquiry" comm.CommandType = CommandType.Text Programming comm.Connection = conn Student Id: MIDSEcomm adp.SelectCommand = 552 adp.Fill(dt) Mohamed Hassan DataGridView1.DataSource = dt conn.Close()

(Vb.Net)

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Assignment Title: Database gridvalues() TextBox1.Text = "" Programming TextBox2.Text = "" Student Id: MIDSE 552 Student Name: TextBox3.Text = "" 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) Programming Student Id: MIDSE 552 Mohamed Hassan Assignment Title: Database Student Name:

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 formlogin button Click event of the
If TextBox1.Text = "" Then MsgBox("Please fill the user name field") ElseIf TextBox2.Text = "" Then MsgBox("Please fill the password field") Else dt.Clear() fname = TextBox1.Text connect() conn.Open() comm.CommandText = "select * from login where user_name='" & TextBox1.Text & "'" comm.CommandType = CommandType.Text comm.Connection = conn adp.SelectCommand = comm adp.Fill(dt) If dt.Rows.Count = 0 Then MsgBox("Invalid user name") Else fpassword = TextBox2.Text dpassword = dt.Rows(0).Item("user_password") If fpassword = dpassword Then MsgBox("Login successful") MDIParent1.Show() flevel = dt.Rows(0).Item("user_level") Me.Hide() If (flevel = "user") Then ModuleMDIParent1.LoginToolStripMenuItem.Enabled = False Title: Advanced Visual Programming End If

Clikc event of the Cancel button TextBox1.Text = "" TextBox2.Text = ""

Declarations for the login form Public Class login Dim comm As New SqlClient.SqlCommand Dim adp As New SqlClient.SqlDataAdapter Dim dt As New DataTable Public fname, Module codes flevel, fpassword, dname, dpassword As String End classModule1 Module Public conn As New SqlClient.SqlConnection Public buttontext As String Public Sub connect() conn.ConnectionString = "initial catalog=library;data source=MHASAN;user id=sa;password=sa;" End Sub Public Sub edite() (Vb.Net) Assignment Title: Database buttontext = "Edit" End Sub Public Sub del() Student Name: buttontext = "Delete" End Sub End Module

Programming Else Student Id: MIDSE 552 MsgBox("Invalid password") End If Mohamed Hassan
End If conn.Close() End If

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

21

Only administrator user_level users can change the login details for the system users.

LoginToolStripMenuItem is disabled for system 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") ElseIf TextBox4.Text = "" Then MsgBox("Please enter an author") ElseIf TextBox5.Text = "" Then MsgBox("Please enter book cost") ElseIf TextBox6.Text = "" Then MsgBox("Please enter an isbn number")

addbook form
addbook form

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 Title: Advanced Visual Programming (Vb.Net) Assignment Title: Database Else TextBox6.Text = " " Programming id = dt.Rows(rowcount - 1).Item(0) End If newid = id.Substring(3, 1) + 1 Student Id: MIDSE 552 Student Name: bid = id.Substring(0, 3) Mohamed Hassan & newid TextBox1.Text = bid 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 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 = CommandType.Text TextBox2.Text = comm.Connection = conn dt.Rows(DataGridView1.CurrentRow.Index).Item(1) adp.SelectCommand = comm TextBox3.Text = adp.Fill(dt) dt.Rows(DataGridView1.CurrentRow.Index).Item(2) (Vb.Net) Assignment Title: Database DataGridView1.DataSource = dt TextBox4.Text = conn.Close() dt.Rows(DataGridView1.CurrentRow.Index).Item(3) End Sub TextBox5.Text = Student Name: dt.Rows(DataGridView1.CurrentRow.Index).Item(4) TextBox6.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(5) Button1.Text = buttontext

Form1 Design View (edit/delete books)

Module Title: Advanced Visual Programming Programming Student Id: MIDSE 552 Mohamed Hassan

23

Module Title: Advanced Visual Programming (Vb.Net) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

24

Click event of the button ( if the Mdiparents book pressed then button text become delete)

edit is pressed then button text become edit . if the Mdiparents book

delete is

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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 Assignment Title: Database conn.Close()

Module Title: Advanced Visual Programming (Vb.Net) Programming Student Id: MIDSE 552 Mohamed Hassan

Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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 MsgBox("please enter present address") ElseIf TextBox5.Text = "" Then MsgBox("Please enter national id number") ElseIf TextBox6.Text = "" Then MsgBox("please enter contact number") member_add form (To add members) Else

Form Load event (Auto incrementing member id)

TextBox1.Enabled = False connect() conn.Open() comm.CommandText = "select * from member" comm.CommandType = CommandType.Text comm.Connection = conn connect() adp.SelectCommand = comm conn.Open() adp.Fill(dt) Click event of browse button comm.CommandText = "insert into member values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & Dim id, textid As String TextBox4.Text & "','" & TextBox5.Text & "'," & TextBox6.Text & ",'" & pfilename & "')" Dim newid, rcount As Integer OpenFileDialog1.Filter = "picture files(*.jpg)|*.jpg" comm.CommandType = CommandType.Text rcount = dt.Rows.Count If OpenFileDialog1.ShowDialog = comm.Connection = conn If rcount Module Title: Advanced Visual Programming (Vb.Net) = 0 Then Assignment Title: Database Windows.Forms.DialogResult.OK Then comm.ExecuteNonQuery() TextBox1.Text = "M001" PictureBox1.Image = conn.Close() Programming Else Image.FromFile(OpenFileDialog1.FileName) MsgBox("member added") id = dt.Rows(rcount - 1).Item(0) pfilename = OpenFileDialog1.FileName Student Id: MIDSE 552 Student Name: End If newid = id.Substring(3, 1) + 1 End If TextBox2.Text = "" textid = id.Substring(0, 3) Mohamed Hassan TextBox3.Text = "" 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 = comm.CommandType = CommandType.Text dt.Rows(DataGridView1.CurrentRow.Index).Item(2) Member_search form (To search members) 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 Visual Programming (Vb.Net) PictureBox1.Image = Assignment Title: Database DataGridView1.DataSource = dt Label14.Text = dt.Rows(0).Item(0) Image.FromFile(dt.Rows(DataGridView1.CurrentRow.Index).Ite Programming Label15.Text = dt.Rows(0).Item(1) m(6)) Student Id: MIDSE 552 Student Name: Label16.Text = dt.Rows(0).Item(2) End Sub 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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) MsgBox("member details updated") Title: Database (Vb.Net) Assignment conn.Close() End If gridvalues() Student Name:

Module Title: Advanced Visual Programming Programming Student Id: MIDSE 552 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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

37

issues form (to record the issued book details)

click event of the member or not button

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

form load event TextBox2.Enabled = False Button1.Enabled = False Button2.Enabled = False

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 conn.Close()

Click event of the Add button 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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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 = form Declarations for the"" Module Title: "" Label10.Text = Public Class returns Advanced Visual Programming Label11.Text = Dim comm As New Programming"" SqlClient.SqlCommand Dim adp As New SqlClient.SqlDataAdapter Student Id: MIDSE 552 Dim dt event form load As New DataTable Dim dayselapsed As Integer Mohamed Hassan Dim return_date, returned_date As Date Button1.Visible = False Dim fine As Double End class

(Vb.Net)

Assignment Title: Database Student Name:

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") conn.Close() TextBox1.Text = "" TextBox2.Text = "" ComboBox1.Text = "" End If

Form Load event ComboBox1.Items.Add("administrator") ComboBox1.Items.Add("user")

Module Title: Advanced Visual Programming (Vb.Net) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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) DataGridView1.DataSource = dt conn.Close() End Sub Cell click event of DataGridView1(DataGridView1_CellClick) TextBox1.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(0) TextBox2.Text = dt.Rows(DataGridView1.CurrentRow.Index).Item(1) Button1.Enabled = True TextBox1.Enabled = False TextBox2.Enabled = True ComboBox1.Enabled = True

Click event of the edit or delete button If (Button1.Text = "edit") Then dt.Clear() connect() conn.Open() comm.CommandText = "update login set user_password='" & TextBox2.Text & "', user_level='" & ComboBox1.Text & "' where user_name='" & TextBox1.Text & "'" comm.CommandType = CommandType.Text comm.Connection = conn adp.SelectCommand = comm adp.Fill(dt) conn.Close() MsgBox("login details edited") gridvalues() ElseIf (Button1.Text = "delete") Then dt.Clear() connect() conn.Open() comm.CommandText = "delete from login where user_name='" & Module Title: Advanced Visual Programming TextBox1.Text & "'" comm.CommandType = CommandType.Text Programming = conn comm.Connection adp.SelectCommand = 552 Student Id: MIDSE comm adp.Fill(dt) Mohamed Hassan conn.Close() MsgBox("login details deleted") gridvalues() End If

(Vb.Net)

Assignment Title: Database Student Name:

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) Programming Student Id: MIDSE 552 Mohamed Hassan

Assignment Title: Database Student Name:

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 Visual Assignment Title: Database comm.CommandType = CommandType.Text Programming (Vb.Net) comm.Connection = conn Programming DateTimePicker1_CloseUp Event adp.SelectCommand = comm Student Id: MIDSE 552 Student Name: adp.Fill(dt) startdate = Format(DateTimePicker1.Value, "MM/dd/yyyy") Dim rpt As New CrystalReport1 Mohamed Hassan 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 Public Class report_day Dim ddate As String Dim comm As New SqlClient.SqlCommand Dim adp As New SqlClient.SqlDataAdapter Dim dt As New DataTable End Class

Declarations for the report_day ddate = Format(DateTimePicker1.Value, "MM/dd/yyyy")

Click event of the fine/day button connect() conn.Open() comm.CommandText = "select * from fine where returned_date='" & ddate & "'" comm.CommandType = CommandType.Text Module Title: Advanced Visual Programming (Vb.Net) comm.Connection = conn Programming = comm adp.SelectCommand adp.Fill(dt) Student Id: New CrystalReport2 Dim rpt2 As MIDSE 552 rpt2.SetDataSource(dt) Mohamed Hassan CrystalReportViewer1.ReportSource = rpt2 conn.Close()

Assignment Title: Database Student Name:

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 Title: Advanced Visual Programming (Vb.Net) comm.CommandType = CommandType.Text comm.Connection Programming = conn adp.SelectCommand = comm Student Id: MIDSE 552 adp.Fill(dt) Dim rpt3 Hassan MohamedAs New CrystalReport3 rpt3.SetDataSource(dt) CrystalReportViewer1.ReportSource = rpt3 conn.Close()

Assignment Title: Database Student Name:

You might also like