You are on page 1of 150

ST.

XAVIER’S COLLEGE OF MANAGEMENT AND


TECHNOLOGY

COACHING MANAGEMENT SYSTEM


Submitted To

ARYABHATTA KNOWLEDGE UNIVERSITY

In partial fulfillment of

Course: - Bachelor’s in Computer Application [BCA]

Under the guidance of Mr. Rakesh Pathak, Asst. Prof., Dept. of Computer
Science

By: Group members with university roll number

Shivam Kumar Keshri (18303302045)

Satyam Shivam (18303302049)


Acknowledgement

Each step is a small blessing, a little victory that brings us an incomparable sense of
pure, unadulterated joy. As this is our first project, it was difficult for us to develop
it all alone. We are fortunate that we are surrounded by people who are expert in
their respective fields and thus shared their knowledge with us and made our work
easier.

Firstly, we would like thank the almighty god for all the blessings which he bestowed
upon us and kept us patient during this whole development process. We would like
to thank our college’s Principal- Fr. Dr. T Nishant, SJ, who was very cooperative
and helped us in time management, wherever we lagged behind the schedule.

We would specially like to thank our project guide- Mr. Rakesh pathak, who always
kept motivating us and also helped us wherever we needed him to clear our doubts.
We would also thank all the faculty members of BCA department who supported us
in development process by suggesting us to add new features in our project.
Certificate

This is to certify that the project entitled Coaching Management System submitted
to Aryabhatta Knowledge University in fulfillment of the requirement for the award
of Degree of Bachelors in computer applications [BCA]; the matter embodied in this
project is a genuine work done by me.

…………………………………. ………………………………

Signature of the Principal Signature of the Project Guide


Fr. Dr. T Nishant, SJ Mr. Rakesh Pathak
St. Xavier’s College of Management Asst. Professor
And Technology, Patna Dept. Of Computer Science

…………………………….

Signature of Student Superintendent


Aryabhatta Knowledge University
Patna, Bihar
Declaration

We, hereby declare that the work being presented in this project, titled “Coaching
Management System” as a part of course curriculum of Bachelor In Computer
Application [BCA], is an authentic record of my own work carried out under the
guidance of Mr. Rakesh Pathak, Asst. Prof. in the Dept of Computer Science , St.
Xavier’s College of Management And Technology, Patna.

Name: Satyam Shivam

Course: Bachelors in Computer Application


Reg. No. : 18303302049

Name: Shivam Kumar Keshri

Course: Bachelors in Computer Application


Reg. No. : 18303302045
Introduction

The title of our project is “Coaching Management System”.

This project will handle whole the activities of the coaching. CMS has most of
facilities that a modern coaching requires to computerize its day-to-day jobs.

It provides facilities to keep the record of student, fees, taking exams, teaching and
non-teaching staff with all their required details along with all required transaction
handling. It has facilities to generate various types of reports, which are required by
the management during normal business operation to operate the business
effectively.

Purpose: The purpose of the project is to build an application program that can
reduce the manual work for managing the records of the students, teachers and fees.

Project scope: The scope of this software is local i.e. it should be accessed within a
system (PC, Laptop).

Objectives
This project records the details of students, teachers, users, exams, results and fees. The
purpose of the project is to build an application program to reduce the manual work
for managing the records of students, teachers, users, exams, results and fees. It displays
the details ofstudents, teachers, users, exams, results, answer sheets, fees paid,
remaining unpaid fees. It maintains error free database and easily incorporates the
future developments and changes.

In other word we can say that our project has the following objectives:-

• Make all the system computerize

• Reduce time consumption


• Reduce error scope
• All system management are automated
• Centralized database management

• Easy operation for operator of the system

• No paper work requirement

Software and hardware requirement for development


of this Windows Form Application

Hardware requirements:

• RAM : 4 GB RAM minimum (8 GB recommended)


• Screen resolution : 1280 x 800 minimum screen resolution
• Processor : i3(minimum)
Software requirements:

• Operating system : Microsoft Windows 10 ( 64-bit)


• Language : VB.NET, SQL
• IDE : Visual Studio 2019
• Database : SQL Server 2019, Microsoft SQL Server
Management Studio 2018
Software requirement justification

Visual Studio 2019: It is simple, easy to understand and implement. It allows us to


create software interface and code in an easy-to-use graphical environment.

SQL Server 2019: It allows us to Integrate data from structured and unstructured
data sources.

Microsoft SQL Server management studio 18: It is RDBMS that run on the
SQL. It has capacity to support a huge variety of transaction processing as well
as business intelligence and analytics in corporate IT environments.

SQL: : It can be used to share and manage data, particularly data that is found in
relational database management systems, which include organized into tables.
Multiple files, each containing tables of data, also may be related together by a
common field. Using SQL, you can query, update, and reorganize data, as well as
create and modify the schema of a database system and control access to its data.

Microsoft Windows 10: Windows 10 has a feature to thwart ransomware


from locking up a user's work and personal documents on their computer. The
Windows Defender Security Center tool in Windows 10 lets us whitelist, or
approve, which apps can access and change files saved in the Desktop,
Documents, Music, Pictures and Videos folders.
SRS for CMS (Coaching Management System) Overall
description

Product perspective: Computerize various book keeping activities


associated with its operations. It is a new software.

Product features: CMS is developed for

1. Admin can add, update, delete and display students, teachers, users, classes,
streams, subjects, fees, exams into database.

2. Admin and Teacher can view result and answer sheet of students.
3. Admin, Teacher and Student can change his/her password.
4. Teacher can add, update, delete and display questions for exams.
5. Students can give their exam and view his/her result or answer sheet.
6. Getting details of student and their remaining unpaid fees.

Non-Functional Requirements

• Performance requirements
The Application is such that it stands up to the user expectations
The response of all the operation is good
Response to user’s errors and undesired situations has been taken care of
to ensure that the Application operates without any uncertainty

• Only authorized users are allowed to enter into the system and work. It
providing an extensive role based authorization.
Feasibility study
Technical Feasibility
The system is proposed to be developed for window form application.
Therefore we have chosen the visual basic as our front end and SQL server
2019 as backend.
Economic Feasibility
Since this project is a partial fulfillment of our Degree course Bachelor in
computer application. So money related concerns has not come and the project
has been developed by our team member without charging any cost.
Schedule Feasibility
Time evaluation is the most important consideration in the development of
project. The time schedule required for the developed of this project is very
important since more development time effort machine time, cost and cause
delay in the development of other systems. A reliable Coaching Management
System can be developed in the considerable amount of time.

Behavioral Feasibility

The proposed system is also behaviorally feasible as it is very user friendly. The
users can easily learn to use the system and can adapt themselves according to
the system.
Modular design:

Teacher
eeeerer
Admin Student

Modules

Admin Module

• Login
• Dashboard
• Manage Education
• Manage Exam
• Manage Student
• Manage Fees
• View Result
• Answer Sheet
• Manage Teacher
• Manage User
• Setting
Teacher Module

• Login
• Dashboard
• Manage Question
• View Result
• Answer Sheet
• Settings

Student Module

• Login
• Dashboard
• Exam
• Result
• settings
PROCESS LOGIC OF MODULE:
ADMIN MODULE

LOGIN

• ADMIN: ENTER ADMIN USER TYPE, USER NAME AND


PASSWORD AND HIT LOGIN BUTTON
• APPLICATION: VERIFY CREDENTIAL IF FOUND TRUE THEN
INTENT TO ADMIN DASHBOARD
• APPLICATION: VIEW DASHBOARD WHICH INCLUDE ALL
SYSTEM FEATURES LIKE TOTAL STUDENT ASSIGNED,
TOTAL TEACHER ASSIGNED ETC.

MANAGE EDUCATION

• ADMIN: CLICK ON MANAGE EDUCATION BUTTON


• APPLICATION: ADD, UPDATE, AND DELETE CLASS,
STREAM, AND SUBJECT IN THE DATABASE
• APPLICATION: DISPLAY ALL ASSIGNED CLASS

MANAGE STUDENT

• ADMIN: CLICK ON MANAGE STUDENT BUTTON


• APPLICATION: ADD AND UPDATE ALL THE STUDENT
DETAIL BY FILLING STUDENT REGISTRATION NUMBER,
NAME, GENDER, EMAIL ADDRESS, AGE, CLASS , STREAM,
SUBJECT ETC IN THE DATABASE
• APPLICATION: DISPLAY ALL ASSIGNED STUDENT

MANAGE FEES

• ADMIN: CLICK ON MANAGE FEES BUTTON


• APPLICATION: CHECK AND UPDATE ALL THE STUDENT
FEES DETAIL BY FILLING STUDENT REGISTRATION NO.
• APPLICATION: DISPLAY ALL RECORDED STUDENT FEES
DETAIL LIKE FEE PAID AND DUES

MANAGE EXAM

• ADMIN: CLICK ON MANAGE EXAM BUTTON


• APPLICATION: ADD AND UPDATE EXAM FOR SELECTED
CLASS
• APPLICATION: ASSIGN TIME DURATION, NO OF
QUESTION AND MARKS FOR EXAM

VIEW RESULT

• ADMIN: CLICK ON VIEW RESULT BUTTON


• APPLICATION: SEARCH AND VIEW ALL EXAM RESULT OF
RECORDED STUDENT IN THE DATABASE

ANSWER SHEET

• ADMIN: CLICK ON ANSWER SHEET BUTTON


• APPLICATION: SEARCH AND VIEW ANSWER SHEET OF
ALL RECORDED STUDENT BY ENTERING HIS/HER CLASS
NAME AND REGISTRATION NO IN THE DATABASE

MANAGE TEACHER

• ADMIN: CLICK ON MANAGE TEACHER BUTTON


• APPLICATION: ADD AND UPDATE ALL THE TEACHER
DETAIL BY FILLING TEACHER ID, NAME, PHONE NO,
ADDRESS, SALARY ETC. IN THE DATABASE
• APPLICATION: DISPLAY ALL ASSIGNED TEACHER

MANAGE USER

• ADMIN: CLICK ON MANAGE USER BUTTON


• APPLICATION: ADD AND UPDATE USER NAME AND
PASSWORD FOR SELECTED USER TYPE

SETTINGS

• ADMIN: CLICK ON SETTINGS BUTTON


• APPLICATION: CHANGE USER NAME BY ENTERING OLD
USERNAME AND NEW USERNAME
• APPLICATION: CHANGE PASSWORD BY ENTERING OLD
PASSWORD AND NEW PASSWORD
TEACHER MODULE

LOGIN

• TEACHER: ENTER TEACHER USER TYPE, USER NAME AND


PASSWORD AND HIT LOGIN BUTTON
• APPLICATION: VERIFY CREDENTIAL IF FOUND TRUE THEN
INTENT TO ADMIN DASHBOARD
• APPLICATION: VIEW DASHBOARD WHICH INCLUDE
TEACHER ID AND TEACHER NAME

MANAGE QUESTION

• TEACHER: CLICK ON MANAGE QUESTION BUTTON


• APPLICATION: ADD AND UPDATE EXAM QUESTION
CONSISTING OF FOUR OPTION (A, B, C, D) AND ONE
CORRECT ANSWER FOR THE SELECTED CLASS

VIEW RESULT

• TEACHER: CLICK ON VIEW RESULT BUTTON


• APPLICATION: SEARCH AND VIEW ALL EXAM RESULT OF
RECORDED STUDENT IN THE DATABASE

ANSWER SHEET

• TEACHER: CLICK ON ANSWER SHEET BUTTON


• APPLICATION: SEARCH AND VIEW ANSWER SHEET OF
ALL RECORDED STUDENT BY ENTERING HIS/HER CLASS
NAME AND REGISTRATION NO IN THE DATABASE

SETTINGS

• TEACHER: CLICK ON SETTINGS BUTTON


• APPLICATION: CHANGE PASSWORD BY ENTERING OLD
PASSWORD AND NEW PASSWORD
STUDENT MODULE

LOGIN

• STUDENT: ENTER STUDENT USER TYPE, USER NAME AND


PASSWORD AND HIT LOGIN BUTTON
• APPLICATION: VERIFY CREDENTIAL IF FOUND TRUE THEN
INTENT TO ADMIN DASHBOARD
• APPLICATION: VIEW DASHBOARD WHICH INCLUDE
STUDENT NAME, REG NO, TOTAL EXAM GIVEN, EXAM
LEFT ETC.

EXAM

• STUDENT: CLICK ON EXAM BUTTON


• APPLICATION: STUDENT GIVE EXAM BY CLICKING ON
START EXAM BUTTON WHICH SHOW ALL THE QUESTION
OF THAT SUBJECT AND ALSO SHOW TIME DURATION FOR
THAT EXAM

RESULT

• STUDENT: CLICK ON RESULT BUTTON


• APPLICATION: VIEW RESULT WHICH SHOW COMPLETE
ANALYSIS OF YOUR EXAM RESULT I.E. NO OF CORRECT
QUESTION, INCORRECT QUESTION AND ALSO SHOW
YOUR OVERALL PERCENTAGE

SETTINGS

• TEACHER: CLICK ON SETTINGS BUTTON


• APPLICATION: CHANGE PASSWORD BY ENTERING OLD
PASSWORD AND NEW PASSWORD
FLOWCHART

Admin flowchart:
Teacher flowchart:
Student flowchart:
USE CASE DIAGRAM

Admin:
Teacher:

Student:
Screenshots of Admin module:

LOGIN PAGE

Screenshots of Admin module:

21
22
23
24
Screenshots of Student module

25
26
Screenshots of Teacher module:

27
VB FILE

Database_Connectivity.vb
Imports System.Data.SqlClient
Imports System.Data
Module Database_Connectivity
Public connectionString As String
Public cnn, con As SqlConnection
Public qry, qry1 As String
Public cmd, cmd1 As SqlCommand
Public dr, dr1 As SqlDataReader
Public ds As DataSet
Public Sub connection_open()
connectionString = "Data Source=.\SQLEXPRESS;Initial
Catalog=CMSDB;Integrated Security=True;"
cnn = New SqlConnection(connectionString)
Try
cnn.Open()
Catch ex As Exception
MsgBox("Cannnot open database connection...You need to setup
database", MsgBoxStyle.Critical)
End Try
End Sub
Public Sub connection_close()
cnn.Close()
End Sub
End Module

Admin_Dashboard_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Admin_Dashboard_Form


Dim TotalUsers, TotalClass, TotalTeachers, TotalStudents,
TotalStream, TotalSubject, TotalExam, TotalFeesRecieved, TotalFeesDues As
String

Public Sub ShowDashboardInfo()


Try
connection_close()
connection_open()

28
'Displaying total users
qry = "select count (*) from Login"
cmd = New SqlCommand(qry, cnn)
TotalUsers = cmd.ExecuteScalar
lblTotalUser.Text = TotalUsers

'Displaying total students


qry = "select count (*) from Students"
cmd = New SqlCommand(qry, cnn)
TotalStudents = cmd.ExecuteScalar
lblTotalSt.Text = TotalStudents

'Displaying total teachers


qry = "select count (*) from Teachers"
cmd = New SqlCommand(qry, cnn)
TotalTeachers = cmd.ExecuteScalar
lblTotalTe.Text = TotalTeachers

'Displaying total classes


qry = "select count (distinct(Class)) from Education"
cmd = New SqlCommand(qry, cnn)
TotalClass = cmd.ExecuteScalar
lblTotalClass.Text = TotalClass

'Displaying total streams


qry = "select count (distinct(Stream)) from Education"
cmd = New SqlCommand(qry, cnn)
TotalStream = cmd.ExecuteScalar
lblTotalStream.Text = TotalStream

'Displaying total subjects


qry = "select count (distinct(Subject)) from Education"
cmd = New SqlCommand(qry, cnn)
TotalSubject = cmd.ExecuteScalar
lblTotalSubject.Text = TotalSubject

'Displaying total exams


qry = "select count (*) from Exam"
cmd = New SqlCommand(qry, cnn)
TotalExam = cmd.ExecuteScalar
lblTotalExam.Text = TotalExam

'Displaying total fees received


qry = "select sum (FeePaid) from Fees"
cmd = New SqlCommand(qry, cnn)
TotalFeesRecieved = cmd.ExecuteScalar
29
lblFeesRec.Text = TotalFeesRecieved

'Displaying total fees due


qry = "select sum ((Fee)-(FeePaid)) from Fees"
cmd = New SqlCommand(qry, cnn)
TotalFeesDues = cmd.ExecuteScalar
lblFeesDue.Text = TotalFeesDues

lblUsertype.Text = Login_Form.cmbUserType.Text
lblUsername.Text = Login_Form.txtUserName.Text
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub My_Profile_Form_Load(sender As Object, e As EventArgs)


Handles MyBase.Load
ShowDashboardInfo()
End Sub
End Class

Admin_Panel_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Admin_Panel_Form


Private Sub btnExam_Click(sender As Object, e As EventArgs) Handles
btnAdExam.Click
With Manage_Exam_Form
.TopLevel = False
panelCentre.Controls.Add(Manage_Exam_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnTeacher_Click(sender As Object, e As EventArgs)


Handles btnAdTeacher.Click
With Manage_Teacher_Form
.TopLevel = False
panelCentre.Controls.Add(Manage_Teacher_Form)
.BringToFront()
30
.Show()
End With
End Sub

Private Sub Admin_Dashboard_Load(sender As Object, e As EventArgs)


Handles MyBase.Load
With Admin_Dashboard_Form
.TopLevel = False
panelCentre.Controls.Add(Admin_Dashboard_Form)
.BringToFront()
.Show()
End With

End Sub

Private Sub btnMyProfile_Click(sender As Object, e As EventArgs)


Handles btnAdDashboard.Click
Admin_Dashboard_Form.Refresh()

With Admin_Dashboard_Form
.TopLevel = False
panelCentre.Controls.Add(Admin_Dashboard_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnSettings_Click_1(sender As Object, e As EventArgs)


Handles btnAdSettings.Click
With Setting_Form
.TopLevel = False
panelCentre.Controls.Add(Setting_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnManageUser_Click(sender As Object, e As EventArgs)


Handles btnAdUser.Click
With Manage_User_Form
.TopLevel = False
panelCentre.Controls.Add(Manage_User_Form)
.BringToFront()
.Show()
End With
End Sub
31
Private Sub btnResult_Click(sender As Object, e As EventArgs) Handles
btnAdResult.Click
With View_Result_Form
.TopLevel = False
panelCentre.Controls.Add(View_Result_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnAnsSheet_Click(sender As Object, e As EventArgs)


Handles btnAdAnsSheet.Click
With Answer_Sheet_Form
.TopLevel = False
panelCentre.Controls.Add(Answer_Sheet_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnAdEducation_Click(sender As Object, e As EventArgs)


Handles btnAdEducation.Click
With Manage_Education_Form
.TopLevel = False
panelCentre.Controls.Add(Manage_Education_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnAdLogOut_Click(sender As Object, e As EventArgs)


Handles btnAdLogOut.Click
Me.Dispose()
End Sub

Private Sub btnAdStudent_Click(sender As Object, e As EventArgs)


Handles btnAdStudent.Click
With Manage_Student_Form
.TopLevel = False
panelCentre.Controls.Add(Manage_Student_Form)
.BringToFront()
.Show()
End With
End Sub

32
Private Sub btnAdFees_Click(sender As Object, e As EventArgs) Handles
btnAdFees.Click
With Manage_Fees_Form
.TopLevel = False
panelCentre.Controls.Add(Manage_Fees_Form)
.BringToFront()
.Show()
End With
End Sub

End Class

Answer_Sheet_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Answer_Sheet_Form


Dim QNo As Integer = 1
Dim MaxQNo As Integer
Dim CorrectAnswer, GivenAnswer As String
Dim AnswerSheetExist As Boolean
'Checking data exist or not
Public Sub CheckAnswerSheet()
If txtAnsSheetRegNo.Text <> "" And cmbAnsSheetClass.Text <> ""
And cmbAnsSheetCourse.Text <> "" And cmbAnsSheetSubject.Text <> "" Then
Try
connection_close()
connection_open()
qry = "SELECT * FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
AnswerSheetExist = True
Else
AnswerSheetExist = False
End If

33
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End If
End Sub

Private Sub btnAnsSheetSearch_Click(sender As Object, e As EventArgs)


Handles btnAnsSheetSearch.Click
SearchQues()
End Sub

Public Sub SearchQues()


If txtAnsSheetRegNo.Text = "" Or cmbAnsSheetClass.Text = "" Or
cmbAnsSheetCourse.Text = "" Or cmbAnsSheetSubject.Text = "" Then
MsgBox("Please enter RegNo, Class, Stream and Subject
details", MsgBoxStyle.Critical)
Else
CheckAnswerSheet()
If AnswerSheetExist = False Then
MsgBox("AnswerSheet does not exist.",
MsgBoxStyle.Critical)
Else
Try
'Searching data
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB,
OptionC, OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewAnsSheet.DataSource = dt
End Using
End Using
MaxQNo = MaxQuesValue()
ShowQuestion()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
34
End If
End Sub

'Showing answersheet data in textboxes


Public Sub ShowQuestion()
Try
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB, OptionC,
OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'
AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
txtAnsSheetQuesNo.Text = dr.Item("QuesNo").ToString
txtAnsSheetQuestion.Text = dr.Item("Question").ToString
txtAnsSheetOptionA.Text = dr.Item("OptionA").ToString
txtAnsSheetOptionB.Text = dr.Item("OptionB").ToString
txtAnsSheetOptionC.Text = dr.Item("OptionC").ToString
txtAnsSheetOptionD.Text = dr.Item("OptionD").ToString
txtAnsSheetAnswer.Text = dr.Item("Answer").ToString
txtAnsSheetGivenAns.Text =
dr.Item("GivenAnswer").ToString
QNo = CInt(dr.Item("QuesNo").ToString())
CorrectAnswer = dr.Item("Answer").ToString()
GivenAnswer = dr.Item("GivenAnswer").ToString()
ColourOptBtn()
End While
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End Sub

'Colouring option buttons green(if correct) and red(if wrong)


Public Sub ColourOptBtn()
If CorrectAnswer = "Option (A)" Then
txtAnsSheetOptionA.BackColor = Color.LimeGreen
txtAnsSheetOptionA.ForeColor = Color.White
ElseIf CorrectAnswer = "Option (B)" Then
35
txtAnsSheetOptionB.BackColor = Color.LimeGreen
txtAnsSheetOptionB.ForeColor = Color.White
ElseIf CorrectAnswer = "Option (C)" Then
txtAnsSheetOptionC.BackColor = Color.LimeGreen
txtAnsSheetOptionC.ForeColor = Color.White
ElseIf CorrectAnswer = "Option (D)" Then
txtAnsSheetOptionD.BackColor = Color.LimeGreen
txtAnsSheetOptionD.ForeColor = Color.White
Else
txtAnsSheetOptionA.BackColor = Color.White
txtAnsSheetOptionA.ForeColor = Color.Black

txtAnsSheetOptionB.BackColor = Color.White
txtAnsSheetOptionB.ForeColor = Color.Black

txtAnsSheetOptionC.BackColor = Color.White
txtAnsSheetOptionC.ForeColor = Color.Black

txtAnsSheetOptionD.BackColor = Color.White
txtAnsSheetOptionD.ForeColor = Color.Black
End If

If GivenAnswer = "Option (A)" And CorrectAnswer <> GivenAnswer


Then
txtAnsSheetOptionA.BackColor = Color.Red
txtAnsSheetOptionA.ForeColor = Color.White
ElseIf GivenAnswer = "Option (B)" And CorrectAnswer <>
GivenAnswer Then
txtAnsSheetOptionB.BackColor = Color.Red
txtAnsSheetOptionB.ForeColor = Color.White
ElseIf GivenAnswer = "Option (C)" And CorrectAnswer <>
GivenAnswer Then
txtAnsSheetOptionC.BackColor = Color.Red
txtAnsSheetOptionC.ForeColor = Color.White
ElseIf GivenAnswer = "Option (D)" And CorrectAnswer <>
GivenAnswer Then
txtAnsSheetOptionD.BackColor = Color.Red
txtAnsSheetOptionD.ForeColor = Color.White
End If

If GivenAnswer = "Option (A)" And CorrectAnswer = GivenAnswer


Then
txtAnsSheetOptionA.BackColor = Color.LimeGreen
txtAnsSheetOptionA.ForeColor = Color.White
ElseIf GivenAnswer = "Option (B)" And CorrectAnswer = GivenAnswer
Then
36
txtAnsSheetOptionB.BackColor = Color.LimeGreen
txtAnsSheetOptionB.ForeColor = Color.White
ElseIf GivenAnswer = "Option (C)" And CorrectAnswer = GivenAnswer
Then
txtAnsSheetOptionC.BackColor = Color.LimeGreen
txtAnsSheetOptionC.ForeColor = Color.White
ElseIf GivenAnswer = "Option (D)" And CorrectAnswer = GivenAnswer
Then
txtAnsSheetOptionD.BackColor = Color.LimeGreen
txtAnsSheetOptionD.ForeColor = Color.White
End If
End Sub

'Colouring option buttons white(if not viewed)


Public Sub DontColourOptButton()
txtAnsSheetOptionA.BackColor = Color.White
txtAnsSheetOptionA.ForeColor = Color.Black

txtAnsSheetOptionB.BackColor = Color.White
txtAnsSheetOptionB.ForeColor = Color.Black

txtAnsSheetOptionC.BackColor = Color.White
txtAnsSheetOptionC.ForeColor = Color.Black

txtAnsSheetOptionD.BackColor = Color.White
txtAnsSheetOptionD.ForeColor = Color.Black
End Sub
'Showing answersheet data in textboxes when previous and next button
clicked
Public Sub PrevNextQues()
DontColourOptButton()
CorrectAnswer = ""
GivenAnswer = ""
Try
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB, OptionC,
OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'
AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)

37
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
txtAnsSheetQuesNo.Text = dr.Item("QuesNo").ToString
txtAnsSheetQuestion.Text = dr.Item("Question").ToString
txtAnsSheetOptionA.Text = dr.Item("OptionA").ToString
txtAnsSheetOptionB.Text = dr.Item("OptionB").ToString
txtAnsSheetOptionC.Text = dr.Item("OptionC").ToString
txtAnsSheetOptionD.Text = dr.Item("OptionD").ToString
txtAnsSheetAnswer.Text = dr.Item("Answer").ToString
txtAnsSheetGivenAns.Text =
dr.Item("GivenAnswer").ToString
CorrectAnswer = dr.Item("Answer").ToString()
GivenAnswer = dr.Item("GivenAnswer").ToString()
ColourOptBtn()
End While
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End Sub

'Showing answersheet data in grid view when previous and next button
clicked
Public Sub ShowPrevNextAns()
Try
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB, OptionC,
OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'
AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewAnsSheet.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
38
End Try
End Sub

'Finding QNo whose value is maximum in answesheet


Public Function MaxQuesValue()
If txtAnsSheetRegNo.Text = "" Or cmbAnsSheetClass.Text = "" Or
cmbAnsSheetCourse.Text = "" Or cmbAnsSheetSubject.Text = "" Then
Return 0
Else
Try
connection_close()
connection_open()
qry = "SELECT MAX(QuesNo) AS MaxQNo FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MaxQNo")
End If
End Function
Private Sub btnAnsSheetNext_Click(sender As Object, e As EventArgs)
Handles btnAnsSheetNext.Click
QNo = txtAnsSheetQuesNo.Text
If QNo > MaxQNo Then
QNo = 1
Else
QNo += 1
End If
PrevNextQues()
ShowPrevNextAns()
End Sub

'Displaying all data from answersheet in grid view


Public Sub ShowAllAns()
Try
connection_close()
connection_open()

39
qry = "SELECT QuesNo, Question, OptionA, OptionB, OptionC,
OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewAnsSheet.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End Sub

Private Sub DataGridViewAnsSheet_CellClick(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridViewAnsSheet.CellClick
DontColourOptButton()
CorrectAnswer = ""
GivenAnswer = ""
QNo =
Convert.ToInt32(DataGridViewAnsSheet.SelectedCells.Item(0).Value.ToString
)
ShowQuestion()
End Sub

'Showing specific QNo answersheet data in textboxes


Public Sub SearchQuesNo()
DontColourOptButton()
CorrectAnswer = ""
GivenAnswer = ""
Try
If txtAnsSheetRegNo.Text = "" Or cmbAnsSheetClass.Text = ""
Or cmbAnsSheetCourse.Text = "" Or cmbAnsSheetSubject.Text = "" Or
txtAnsSheetQuesNo.Text = "" Then
MsgBox("Please enter RegNo, Class, Stream, Subject and
QNo details", MsgBoxStyle.Critical)
Else
QNo = txtAnsSheetQuesNo.Text
If QNo > MaxQNo Then
MsgBox("Q:No does not exist", MsgBoxStyle.Critical)
Else
40
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB,
OptionC, OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'
AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewAnsSheet.DataSource = dt
End Using
End Using
ShowQuestion()
End If
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End Sub

Private Sub btnAnsSheetSearchQNo_Click(sender As Object, e As


EventArgs) Handles btnAnsSheetSearchQNo.Click
MaxQNo = MaxQuesValue()
SearchQuesNo()
End Sub

Private Sub btnAnsSheetPrevious_Click(sender As Object, e As


EventArgs) Handles btnAnsSheetPrevious.Click
QNo = txtAnsSheetQuesNo.Text
If QNo < 1 Then
QNo = 1
Else
QNo -= 1
End If
PrevNextQues()
ShowPrevNextAns()
End Sub
Private Sub Answer_Sheet_Form_Load(sender As Object, e As EventArgs)
Handles MyBase.Load

41
QNo = 1
End Sub

Public Sub ClearAll()


txtAnsSheetAnswer.Text = ""
txtAnsSheetQuestion.Text = ""
txtAnsSheetOptionA.Text = ""
txtAnsSheetOptionB.Text = ""
txtAnsSheetOptionC.Text = ""
txtAnsSheetOptionD.Text = ""
txtAnsSheetGivenAns.Text = ""
txtAnsSheetAnswer.Text = ""
DataGridViewAnsSheet.DataSource = Nothing
DataGridViewAnsSheet.Refresh()
End Sub

Private Sub btnAnsSheetDelete_Click(sender As Object, e As EventArgs)


Handles btnAnsSheetDelete.Click
If txtAnsSheetRegNo.Text = "" Or cmbAnsSheetClass.Text = "" Or
cmbAnsSheetCourse.Text = "" Or cmbAnsSheetSubject.Text = "" Then
MsgBox("Please enter RegNo, Class, Stream and Subject
details", MsgBoxStyle.Critical)
Else
Try
'Checking Data
qry = "SELECT * FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("AnswerSheet Does Not Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
Else
If MsgBox("Are you sure you want to delete?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Deleting Data
qry1 = "DELETE FROM AnswerSheet
WHERE RegNo = '" & txtAnsSheetRegNo.Text & "'
AND Class = '" & cmbAnsSheetClass.Text & "'
AND Stream = '" & cmbAnsSheetCourse.Text & "'
AND Subject = '" & cmbAnsSheetSubject.Text & "'"
42
connection_open()
cmd1 = New SqlCommand(qry1, cnn)
cmd1.ExecuteNonQuery()
MsgBox("AnswerSheet Deleted Successfully!",
MsgBoxStyle.MsgBoxRight)
connection_close()
End If
End If
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try
End If
End Sub
Private Sub btnDisplayAllAns_Click(sender As Object, e As EventArgs)
Handles btnDisplayAllAns.Click
ShowAllAns()
End Sub

End Class

Login_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Login_Form


Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles
btnLogin.Click
If cmbUserType.Text = "" Or txtUserName.Text = "" Or
txtPassword.Text = "" Then
MsgBox("Please enter all data.", MsgBoxStyle.Critical)
Else
If cmbUserType.Text = "Student" Then
qry = "SELECT * FROM Login WHERE
UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUserName.Text & "'
AND Password = '" & txtPassword.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then

43
connection_close()
Student_Panel_Form.ShowDialog()
Else
MsgBox("Invalid Username and Password.",
MsgBoxStyle.Critical)
connection_close()
End If

ElseIf cmbUserType.Text = "Admin" Then


qry = "SELECT * FROM Login
WHERE UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUserName.Text & "'
AND Password = '" & txtPassword.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
connection_close()
Admin_Panel_Form.ShowDialog()
Else
MsgBox("Invalid Username and Password.",
MsgBoxStyle.Critical)
connection_close()
End If

ElseIf cmbUserType.Text = "Teacher" Then


qry = "SELECT * FROM Login WHERE
UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUserName.Text & "'
AND Password = '" & txtPassword.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
connection_close()
Teacher_Panel_Form.ShowDialog()
Else
MsgBox("Invalid Username and Password.",
MsgBoxStyle.Critical)
End If
connection_close()
Else
MsgBox("UserType doesnot exist.", MsgBoxStyle.Critical)
End If
End If
End Sub
44
Private Sub btnClose_Click_1(sender As Object, e As EventArgs)
Me.Close()
End Sub

Private Sub btnPasswordShow_Click(sender As Object, e As EventArgs)


Handles btnPasswordShow.Click
If btnPasswordShow.Text = "Show" Then
btnPasswordShow.Text = "Hide"
txtPassword.PasswordChar = ""
ElseIf btnPasswordShow.Text = "Hide" Then
btnPasswordShow.Text = "Show"
txtPassword.PasswordChar = "●"
End If
End Sub

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


MyBase.Load
cmbUserType.Select()
End Sub
End Class

Manage_Education_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Manage_Education_Form

Dim i As Integer
Dim EducationExist, CheckEducationExist As Boolean

Public Sub CheckEducationSearch()


Try
connection_close()
connection_open()
If cmbEducationClass.Text <> "" And cmbEducationStream.Text =
"" And cmbEducationSubject.Text = "" Then
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
45
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
End If
ElseIf cmbEducationClass.Text = "" And
cmbEducationStream.Text <> "" And cmbEducationSubject.Text = "" Then
qry = "SELECT * FROM Education
WHERE Stream = '" & cmbEducationStream.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
End If
ElseIf cmbEducationClass.Text = "" And
cmbEducationStream.Text = "" And cmbEducationSubject.Text <> "" Then
qry = "SELECT * FROM Education
WHERE Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
End If
ElseIf cmbEducationClass.Text <> "" And
cmbEducationStream.Text <> "" And cmbEducationSubject.Text = "" Then
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'
AND Stream = '" & cmbEducationStream.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
End If
ElseIf cmbEducationClass.Text <> "" And
cmbEducationStream.Text = "" And cmbEducationSubject.Text <> "" Then
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'
AND Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
46
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
End If
ElseIf cmbEducationClass.Text = "" And
cmbEducationStream.Text <> "" And cmbEducationSubject.Text <> "" Then
qry = "SELECT * FROM Education
WHERE Stream = '" & cmbEducationStream.Text & "'
AND Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
End If
ElseIf cmbEducationClass.Text <> "" And
cmbEducationStream.Text <> "" And cmbEducationSubject.Text <> "" Then
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'
AND Stream = '" & cmbEducationStream.Text & "'
AND Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
End If
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try

End Sub
Public Sub Education_disp()
Try
connection_close()
connection_open()
If cmbEducationClass.Text <> "" And cmbEducationStream.Text =
"" And cmbEducationSubject.Text = "" Then
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'"

47
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewEducation.DataSource = dt
End Using
End Using
ElseIf cmbEducationClass.Text = "" And
cmbEducationStream.Text <> "" And cmbEducationSubject.Text = "" Then
qry = "SELECT * FROM Education
WHERE Stream = '" & cmbEducationStream.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewEducation.DataSource = dt
End Using
End Using
ElseIf cmbEducationClass.Text = "" And
cmbEducationStream.Text = "" And cmbEducationSubject.Text <> "" Then
qry = "SELECT * FROM Education
WHERE Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewEducation.DataSource = dt
End Using
End Using
ElseIf cmbEducationClass.Text <> "" And
cmbEducationStream.Text <> "" And cmbEducationSubject.Text = "" Then
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'
AND Stream = '" & cmbEducationStream.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewEducation.DataSource = dt
End Using
End Using

48
ElseIf cmbEducationClass.Text <> "" And
cmbEducationStream.Text = "" And cmbEducationSubject.Text <> "" Then
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'
AND Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewEducation.DataSource = dt
End Using
End Using
ElseIf cmbEducationClass.Text = "" And
cmbEducationStream.Text <> "" And cmbEducationSubject.Text <> "" Then
qry = "SELECT * FROM Education
WHERE Stream = '" & cmbEducationStream.Text & "'
AND Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewEducation.DataSource = dt
End Using
End Using
ElseIf cmbEducationClass.Text <> "" And
cmbEducationStream.Text <> "" And cmbEducationSubject.Text <> "" Then
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'
AND Stream = '" & cmbEducationStream.Text & "'
AND Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewEducation.DataSource = dt
End Using
End Using
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End Sub
49
Private Sub btnExamSearch_Click(sender As Object, e As EventArgs)
Handles btnEducationSearch.Click
'Checking Validation
If cmbEducationClass.Text = "" And cmbEducationStream.Text = ""
And cmbEducationSubject.Text = "" Then
MsgBox("Please enter search details", MsgBoxStyle.Critical)
Else
DataGridViewEducation.DataSource = Nothing
DataGridViewEducation.Refresh()
CheckEducationSearch()
If EducationExist = True Then
'Show Exam in GridView
Try
connection_close()
connection_open()
Education_disp()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MsgBox("Exam does not exist", MsgBoxStyle.Critical)
End If
End If
End Sub

Public Sub DisplayAllEducation()


connection_close()
connection_open()
Try
qry = "SELECT * FROM Education"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewEducation.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

50
Private Sub btnExamDisplayAll_Click(sender As Object, e As EventArgs)
Handles btnEducationDisplayAll.Click
DisplayAllEducation()
End Sub

Private Sub btnExamClearAll_Click(sender As Object, e As EventArgs)


Handles btnEducationClearAll.Click
cmbEducationClass.Text = ""
cmbEducationStream.Text = ""
cmbEducationSubject.Text = ""
DataGridViewEducation.DataSource = Nothing
DataGridViewEducation.Refresh()
End Sub

Public Sub CheckEducation()


If cmbEducationClass.Text <> "" And cmbEducationStream.Text <> ""
And cmbEducationSubject.Text <> "" Then
Try
connection_close()
connection_open()
qry = "SELECT * FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'
AND Stream = '" & cmbEducationStream.Text & "'
AND Subject = '" & cmbEducationSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
i = dr.Item("Id")
CheckEducationExist = True
Else
CheckEducationExist = False
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End If
End Sub

Private Sub btnExamInsert_Click(sender As Object, e As EventArgs)


Handles btnEducationInsert.Click
'Checking Validation
If cmbEducationClass.Text = "" And cmbEducationStream.Text = ""
And cmbEducationSubject.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
51
CheckEducation()
If CheckEducationExist = True Then
MsgBox("Education already exist.", MsgBoxStyle.Critical)
ElseIf CheckEducationExist = False Then
'Inserting Data
Try
qry = "INSERT INTO Education (Class, Stream, Subject)
VALUES ('" & cmbEducationClass.Text & "',
'" & cmbEducationStream.Text & "',
'" & cmbEducationSubject.Text & "')"
connection_close()
connection_open()
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Education Added Successfully!",
MsgBoxStyle.Information, "Added Success")
DisplayAllEducation()
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try
End If
End If
End Sub

Private Sub btnExamUpdate_Click(sender As Object, e As EventArgs)


Handles btnEducationUpdate.Click
'Checking Validation
If cmbEducationClass.Text = "" And cmbEducationStream.Text = ""
And cmbEducationSubject.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
CheckEducation()
If CheckEducationExist = False Then
MsgBox("Education does not exist.", MsgBoxStyle.Critical)
ElseIf CheckEducationExist = True Then
If MsgBox("Are you sure you want to update?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Updating Data
Try
qry = "UPDATE Education
SET Class = '" & cmbEducationClass.Text & "',
Stream = '" & cmbEducationStream.Text & "',
Subject = '" & cmbEducationSubject.Text & "'
WHERE Id = '" & i & "'"
connection_close()
52
connection_open()
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Education Record Updated Successfully!",
MsgBoxStyle.Information, "Updated Success")
Education_disp()
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try
End If
End If
End If
End Sub

Private Sub btnExamDelete_Click(sender As Object, e As EventArgs)


Handles btnEducationDelete.Click
'Checking Validation
If cmbEducationClass.Text = "" And cmbEducationStream.Text = ""
And cmbEducationSubject.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
CheckEducation()
If CheckEducationExist = False Then
MsgBox("Education does not exist.", MsgBoxStyle.Critical)
ElseIf CheckEducationExist = True Then
If MsgBox("Are you sure you want to delete?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Deleting Data
Try
qry = "DELETE FROM Education
WHERE Class = '" & cmbEducationClass.Text & "'
AND Stream = '" & cmbEducationStream.Text & "'
AND Subject = '" & cmbEducationSubject.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Education Deleted Successfully!",
MsgBoxStyle.Information, "Deleted")
DisplayAllEducation()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If

Else
53
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End If
End If
End Sub
Private Sub DataGridViewEducation_CellClick(sender As Object, e As
DataGridViewCellEventArgs) Handles DataGridViewEducation.CellClick
Try
connection_close()
connection_open()
i =
Convert.ToInt32(DataGridViewEducation.SelectedCells.Item(0).Value.ToStrin
g)
qry = "SELECT * FROM Education WHERE id = '" & i & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
cmbEducationClass.Text = dr.Item("Class").ToString
cmbEducationStream.Text = dr.Item("Stream").ToString
cmbEducationSubject.Text = dr.Item("Subject").ToString
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

Manage_Exam_Form.vb
Imports System.Data.SqlClient
Imports System.Data
Public Class Manage_Exam_Form
Dim i As Integer
Dim Hr, Min, Sec, ExamDuration, TempHr, TempMin, TempSec, ShowTime As
Integer
Dim ExamExist, EducationExist As Boolean

Public Sub DisplayAllExam()


54
connection_close()
connection_open()
Try
qry = "SELECT * FROM Exam"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewExam.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnExamDisplayAll_Click(sender As Object, e As EventArgs)


Handles btnExamDisplayAll.Click
DisplayAllExam()
End Sub

Public Sub CheckExam()


If cmbExamClass.Text <> "" And cmbExamStream.Text <> "" And
cmbExamSubject.Text <> "" Then
Try
connection_close()
connection_open()
qry = "SELECT Class, Stream, Subject, TotalQues,
TotalMarks, TimeDuration FROM Exam
WHERE Class = '" & cmbExamClass.Text & "'
AND Stream = '" & cmbExamStream.Text & "'
AND Subject = '" & cmbExamSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
ExamExist = True
Else
ExamExist = False
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End If
End Sub

55
Private Sub DataGridViewExam_CellClick(sender As Object, e As
DataGridViewCellEventArgs) Handles DataGridViewExam.CellClick
Try
connection_close()
connection_open()
i =
Convert.ToInt32(DataGridViewExam.SelectedCells.Item(0).Value.ToString)
qry = "SELECT * FROM Exam WHERE Id = '" & i & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
cmbExamClass.Text = dr.Item("Class").ToString
cmbExamStream.Text = dr.Item("Stream").ToString
cmbExamSubject.Text = dr.Item("Subject").ToString
txtExamTotalQues.Text = dr.Item("TotalQues").ToString
txtExamTotalMarks.Text = dr.Item("TotalMarks").ToString

ShowTime = dr.Item("TimeDuration")

TempHr = ShowTime
TempMin = ShowTime
TempSec = ShowTime

If ShowTime > 3600 Then


TempHr /= 3600
txtHour.Text = TempHr
End If

If ShowTime > 60 Then


TempMin /= 60
txtMinute.Text = TempMin
End If

If ShowTime <= 60 Then


txtSecond.Text = TempSec
End If

End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
56
Private Sub btnExamSearch_Click(sender As Object, e As EventArgs)
Handles btnExamSearch.Click
'Checking Validation
If cmbExamClass.Text = "" And cmbExamStream.Text = "" And
cmbExamSubject.Text = "" Then
MsgBox("Please enter search details", MsgBoxStyle.Critical)
Else
CheckExam()
If ExamExist = True Then
'Show Exam in GridView
Try
connection_close()
connection_open()
Exam_disp()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MsgBox("Exam does not exist", MsgBoxStyle.Critical)
End If
End If
End Sub

Public Sub CheckTimeDuration()


Try
If txtHour.Text = "" Then
Hr = 0
Else
Hr = CInt(txtHour.Text)
End If
If txtMinute.Text = "" Then
Min = 0
Else
Min = CInt(txtMinute.Text)
End If
If txtSecond.Text = "" Then
Sec = 0
Else
Sec = CInt(txtSecond.Text)
End If
Catch ex As Exception
MsgBox("Invalid Inputs in Time Duration.",
MsgBoxStyle.Critical)
End Try
End Sub

57
Public Sub CheckEducation()
If cmbExamClass.Text <> "" And cmbExamStream.Text <> "" And
cmbExamSubject.Text <> "" Then
Try
connection_close()
connection_open()
qry = "SELECT * FROM Education
WHERE Class = '" & cmbExamClass.Text & "'
AND Stream = '" & cmbExamStream.Text & "'
AND Subject = '" & cmbExamSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End If
End Sub

Private Sub btnExamInsert_Click(sender As Object, e As EventArgs)


Handles btnExamInsert.Click
'Checking Validation
If cmbExamClass.Text = "" And cmbExamStream.Text = "" And
cmbExamSubject.Text = "" And txtExamTotalQues.Text = "" And
txtExamTotalMarks.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
CheckEducation()
CheckExam()
If EducationExist = False Then
MsgBox("Education does not exist.", MsgBoxStyle.Critical)
ElseIf ExamExist = True Then
MsgBox("Exam already exist.", MsgBoxStyle.Critical)
ElseIf EducationExist = True And ExamExist = False Then
CheckTimeDuration()
'Inserting Data
Try
ExamDuration = (Hr * 60 * 60) + (Min * 60) + Sec
qry = "INSERT INTO Exam (Class, Stream,
Subject,TotalQues, TotalMarks, TimeDuration)
VALUES ('" & cmbExamClass.Text & "',
58
'" & cmbExamStream.Text & "',
'" & cmbExamSubject.Text & "',
'" & txtExamTotalQues.Text & "',
'" & txtExamTotalMarks.Text & "',
'" & ExamDuration & "')"
connection_close()
connection_open()
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Exam Added Successfully!",
MsgBoxStyle.Information, "Added Success")
DisplayAllExam()
Catch ex As Exception
MsgBox("Invalid Inputs in Total Questions or Total
Marks.", MsgBoxStyle.Critical)
End Try
End If
End If
End Sub

Public Sub Exam_disp()


qry = "SELECT Class, Stream, Subject, TotalQues, TotalMarks,
TimeDuration FROM Exam
WHERE Class = '" & cmbExamClass.Text & "'
AND Stream = '" & cmbExamStream.Text & "'
AND Subject = '" & cmbExamSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewExam.DataSource = dt
End Using
End Using
End Sub

Private Sub btnExamUpdate_Click(sender As Object, e As EventArgs)


Handles btnExamUpdate.Click
'Checking Validation
If cmbExamClass.Text = "" And cmbExamStream.Text = "" And
cmbExamSubject.Text = "" And txtExamTotalQues.Text = "" And
txtExamTotalMarks.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
CheckEducation()
59
CheckExam()
If EducationExist = False Then
MsgBox("Education does not exist.", MsgBoxStyle.Critical)
ElseIf ExamExist = False Then
MsgBox("Exam does not exist.", MsgBoxStyle.Critical)
ElseIf EducationExist = True And ExamExist = True Then
If MsgBox("Are you sure you want to update?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Updating Data
CheckTimeDuration()
Try
ExamDuration = (Hr * 60 * 60) + (Min * 60) + Sec
qry = "UPDATE Exam
SET Class = '" & cmbExamClass.Text & "',
Stream = '" & cmbExamStream.Text & "',
Subject = '" & cmbExamSubject.Text & "',
TotalQues = '" & txtExamTotalQues.Text & "',
TotalMarks = '" & txtExamTotalMarks.Text & "',
TimeDuration = '" & ExamDuration & "'
WHERE Class = '" & cmbExamClass.Text & "'
AND Stream = '" & cmbExamStream.Text & "'
AND Subject = '" & cmbExamSubject.Text & "'"
connection_close()
connection_open()
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Exam Record Updated Successfully!",
MsgBoxStyle.Information, "Updated Success")
Exam_disp()
Catch ex As Exception
MsgBox("Invalid Inputs in Total Questions or
Total Marks.", MsgBoxStyle.Critical)
End Try
End If

End If
End If
End Sub
Private Sub btnExamDelete_Click(sender As Object, e As EventArgs)
Handles btnExamDelete.Click
'Checking Validation
If cmbExamClass.Text = "" And cmbExamStream.Text = "" And
cmbExamSubject.Text = "" And txtExamTotalQues.Text = "" And
txtExamTotalMarks.Text = "" Then

60
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
CheckEducation()
CheckExam()
If EducationExist = False Then
MsgBox("Education does not exist.", MsgBoxStyle.Critical)
ElseIf ExamExist = False Then
MsgBox("Exam does not exist.", MsgBoxStyle.Critical)
ElseIf EducationExist = True And ExamExist = True Then
If MsgBox("Are you sure you want to delete?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Deleting Data
Try
qry = "DELETE FROM Exam
WHERE Class = '" & cmbExamClass.Text & "'
AND Stream = '" & cmbExamStream.Text & "'
AND Subject = '" & cmbExamSubject.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Exam Deleted Successfully!",
MsgBoxStyle.Information, "Deleted")
DisplayAllExam()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If

Else
MsgBox("Invalid Inputs in Total Questions or Total
Marks.", MsgBoxStyle.Critical)
End If
End If
End Sub

Private Sub btnExamClearAll_Click(sender As Object, e As EventArgs)


Handles btnExamClearAll.Click
cmbExamClass.Text = ""
cmbExamStream.Text = ""
cmbExamSubject.Text = ""
txtExamTotalQues.Clear()
txtExamTotalMarks.Clear()
txtHour.Clear()
txtMinute.Clear()
txtSecond.Clear()
61
DataGridViewExam.DataSource = Nothing
DataGridViewExam.Refresh()
End Sub

End Class

Manage_Fees_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Manage_Fees_Form


Dim i As Integer
Dim TotalFees, FeePaid, FeeDues As Double
Private Sub btnStudentClear_Click(sender As Object, e As EventArgs)
Handles btnStudentClearAll.Click
txtStudentRegistrationNumber.Clear()
txtFee.Text = ""
txtFeePaid.Clear()
DataGridViewFees.DataSource = Nothing
DataGridViewFees.Refresh()
pnlResult.Refresh()
End Sub

Private Sub btnStudentSave_Click(sender As Object, e As EventArgs)


Handles btnStudentInsert.Click
'Checking Validation

If txtStudentRegistrationNumber.Text = "" Or txtFee.Text = "" Or


txtFeePaid.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
Try
'Checking Duplicacy
qry = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_close()
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
62
If dr.Read = False Then
MsgBox("Record Does Not Exists!",
MsgBoxStyle.Critical, "Null")
connection_close()
Else
'Inserting Data
Dim fee, fee_paid, balance As Integer
fee = txtFee.Text
fee_paid = txtFeePaid.Text
balance = fee - fee_paid
qry = "INSERT INTO Fees (RegNo, Fee, FeePaid) VALUES
('" & txtStudentRegistrationNumber.Text & "', '" & txtFee.Text & "', '"
& txtFeePaid.Text & "')"
connection_close()
connection_open()
qry1 = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = True Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
MsgBox("Fees Added Successfully!",
MsgBoxStyle.Information, "Added Success")
connection_close()
End If
End If
connection_close()
data_disp()
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If

End Sub

Public Sub data_disp()


Try
connection_close()
connection_open()
qry = "SELECT * FROM Fees WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
63
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewFees.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

Public Sub StudentInfoShow()


Try
connection_close()
connection_open()
i =
Convert.ToInt32(DataGridViewFees.SelectedCells.Item(1).Value.ToString)
qry = "SELECT * FROM Students WHERE RegNo = '" & i & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
lblFeeRegNo.Text = dr.GetString(1).ToString()
lblFeeName.Text = dr.GetString(2).ToString()
lblFeeClass.Text = dr.GetString(3).ToString()
lblFeeCourse.Text = dr.GetString(4).ToString()
lblFeeSubject.Text = dr.GetString(5).ToString()
lblFeeGender.Text = dr.GetString(6).ToString()
lblFeeAge.Text = dr.Item("Age")
lblFeePhNo.Text = dr.Item("PhNo")
lblFeeEmail.Text = dr.GetString(9).ToString()
lblFeeAddress.Text = dr.GetString(10).ToString()
pictureFeeStudent.Image =
Image.FromFile(dr.Item("Picture").ToString)

End While

connection_close()
connection_open()
i =
Convert.ToInt32(DataGridViewFees.SelectedCells.Item(1).Value.ToString)
qry = "SELECT * FROM Fees WHERE RegNo = '" & i & "'"
64
cmd = New SqlCommand(qry, cnn)
Dim dt1 As New DataTable()
Dim da1 As New SqlDataAdapter(cmd)
da1.Fill(dt1)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
TotalFees = CDbl(dr.Item("Fee").ToString())
'MsgBox(TotalFees)
FeePaid = CDbl(dr.Item("FeePaid").ToString())
'MsgBox(FeePaid)
FeeDues = TotalFees - FeePaid
'MsgBox(FeeDues)
lblFeeDues.Text = FeeDues.ToString
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btnStudentSearch_Click(sender As Object, e As EventArgs)
Handles btnStudentSearch.Click
If txtStudentRegistrationNumber.Text = "" Then
MsgBox("Please Enter Registration Number Detail",
MsgBoxStyle.Critical)
Else
Try
connection_close()
connection_open()

qry = "SELECT * FROM Fees WHERE RegNo = '" &


txtStudentRegistrationNumber.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewFees.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If
End Sub

65
Private Sub btnStudentDisplayAll_Click(sender As Object, e As
EventArgs)
Try
connection_close()
connection_open()
qry = "SELECT * FROM Fees"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewFees.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

Private Sub btnStudentUpdate_Click(sender As Object, e As EventArgs)


Handles btnStudentUpdate.Click
'Checking Validation
If txtStudentRegistrationNumber.Text = "" Or txtFee.Text = "" Or
txtFeePaid.Text = "" Then
MsgBox("Please Enter Registration Number",
MsgBoxStyle.Critical)
Else
Try
'Checking Data
qry = "SELECT * FROM Fees WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_close()
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("Record Does Not Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
Else
If MsgBox("Are you sure you want to update?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Updating Data

66
qry = "UPDATE Fees SET RegNo = '" &
txtStudentRegistrationNumber.Text & "', Fee = '" & txtFee.Text & "',
FeePaid = '" & txtFeePaid.Text & "' WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_close()
connection_open()
qry1 = "SELECT * FROM Fees WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = True Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
MsgBox("Fees Record Updated Successfully!",
MsgBoxStyle.Information, "Update Success")
connection_close()
End If
End If

End If

data_disp()
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If
End Sub

Private Sub DataGridViewFees_CellClick(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridViewFees.CellClick
Try
connection_close()
connection_open()
i =
Convert.ToInt32(DataGridViewFees.SelectedCells.Item(0).Value.ToString)
qry = "SELECT * FROM Fees WHERE Id = '" & i & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
txtStudentRegistrationNumber.Text =
dr.GetString(1).ToString()
67
txtFee.Text = dr.Item("Fee")
txtFeePaid.Text = dr.Item("FeePaid")
End While
StudentInfoShow()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnStudentDelete_Click(sender As Object, e As EventArgs)


Handles btnStudentDelete.Click
If txtStudentRegistrationNumber.Text = "" Then
MsgBox("Please Enter Registration Number",
MsgBoxStyle.Critical)
Else
Try
'Checking Data
qry = "SELECT * FROM Fees WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_close()
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("Record Does Not Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
End If
If MsgBox("Are you sure you want to delete?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
qry = "SELECT * FROM Fees WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_close()
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
qry1 = "DELETE FROM [dbo].[Fees]
WHERE RegNo = '" & txtStudentRegistrationNumber.Text
& "'"
connection_open()
cmd1 = New SqlCommand(qry1, cnn)
cmd1.ExecuteNonQuery()
MsgBox("Fees Record Deleted Successfully!",
MsgBoxStyle.Information, "Deleted")
68
connection_close()
data_disp()
Else
MsgBox("Fees Record Does Not Exists!",
MsgBoxStyle.Critical)
End If
End If

Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If
End Sub
Private Sub btnStudentDisplayAll_Click_1(sender As Object, e As
EventArgs) Handles btnStudentDisplayAll.Click
Try
connection_close()
qry = "SELECT * FROM Fees"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewFees.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

Manage_Question_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Manage_Question_Form


Dim QNo As Integer = 1
Dim MaxQNo As Integer = 1
Dim QuestionExist As Boolean
Dim ExamExist, EducationExist As Boolean

69
Public Sub ShowQuesInGridView()
Try
connection_close()
connection_open()
qry = "SELECT * FROM
Questions WHERE Class = '" & cmbClass.Text & "'
AND Stream = '" & cmbStream.Text & "'
AND Subject = '" & cmbSubject.Text & "'
AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewQuestion.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End Sub

Public Sub ShowAllQuesInGridView()


Try
connection_close()
connection_open()
qry = "SELECT * FROM
Questions WHERE Class = '" & cmbClass.Text & "'
AND Stream = '" & cmbStream.Text & "'
AND Subject = '" & cmbSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewQuestion.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
End Try
End Sub

Public Sub ShowQues()


Try
connection_close()
70
connection_open()
qry = "SELECT * FROM Questions
WHERE Class = '" & cmbClass.Text & "'
AND Stream = '" & cmbStream.Text & "'
AND Subject = '" & cmbSubject.Text & "'
AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read = True Then
cmbClass.Text = dr.GetString(1).ToString()
cmbStream.Text = dr.GetString(2).ToString()
cmbSubject.Text = dr.GetString(3).ToString()
txtQuesNo.Text = dr.Item("QuesNo")
txtQuestion.Text = dr.GetString(5).ToString()
txtOptionA.Text = dr.GetString(6).ToString()
txtOptionB.Text = dr.GetString(7).ToString()
txtOptionC.Text = dr.GetString(8).ToString()
txtOptionD.Text = dr.GetString(9).ToString()
cmbAnswer.Text = dr.GetString(10).ToString()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub CheckEducation()


If cmbClass.Text <> "" And cmbStream.Text <> "" And
cmbSubject.Text <> "" Then
Try
connection_close()
connection_open()
qry = "SELECT * FROM Education
WHERE Class = '" & cmbClass.Text & "'
AND Stream = '" & cmbStream.Text & "'
AND Subject = '" & cmbSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
EducationExist = True
Else
EducationExist = False
MsgBox("Education does not exist.",
MsgBoxStyle.Critical)
71
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
MsgBox(ex.Message)
End Try
End If
End Sub

Public Sub CheckExam()


If cmbClass.Text <> "" And cmbStream.Text <> "" And
cmbSubject.Text <> "" Then
Try
connection_close()
connection_open()
qry = "SELECT * FROM Exam
WHERE Class = '" & cmbClass.Text & "'
AND Stream = '" & cmbStream.Text & "'
AND Subject = '" & cmbSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
ExamExist = True
Else
ExamExist = False
MsgBox("Exam does not exist.", MsgBoxStyle.Critical)
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
MsgBox(ex.Message)
End Try
End If
End Sub

Public Sub CheckQuestion()


If cmbClass.Text <> "" And cmbStream.Text <> "" And
cmbSubject.Text <> "" Then
Try
connection_close()
connection_open()
qry = "SELECT * FROM Questions
WHERE Class = '" & cmbClass.Text & "'
AND Stream = '" & cmbStream.Text & "'
AND Subject = '" & cmbSubject.Text & "'
AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
72
If dr.Read = True Then
QuestionExist = True
Else
QuestionExist = False
End If
Catch ex As Exception
MsgBox("Invalid Inputs", MsgBoxStyle.Critical)
MsgBox(ex.Message)
End Try
End If
End Sub

Private Sub btnStudentSearch_Click(sender As Object, e As EventArgs)


Handles btnQuesSearch.Click
'Checking Validation
If cmbClass.Text = "" Or cmbStream.Text = "" Or cmbSubject.Text =
"" Then
MsgBox("Please enter search details", MsgBoxStyle.Critical)
Else
CheckEducation()
If EducationExist = True Then
CheckExam()
If ExamExist = True Then
QNo = 1
DataGridViewQuestion.DataSource = Nothing
DataGridViewQuestion.Refresh()
CheckQuestion()
If QuestionExist = True Then
MaxQNo = MaxQuesValue()
ShowAllQuesInGridView()
QNo = MaxQNo
ShowQues()
Else
MsgBox("Questions does not exist. Please add
Questions.", MsgBoxStyle.Critical)
txtQuesNo.Text = QNo
End If
End If
End If
End If
End Sub

Public Sub UpdateQues()


Try
connection_close()
connection_open()
73
qry = "UPDATE Questions
SET QuesNo = '" & QNo & "',
Class = '" & cmbClass.Text & "',
Stream = '" & cmbStream.Text & "',
Subject = '" & cmbSubject.Text & "',
Question = '" & txtQuestion.Text & "',
OptionA = '" & txtOptionA.Text & "',
OptionB = '" & txtOptionB.Text & "',
OptionC = '" & txtOptionC.Text & "',
OptionD = '" & txtOptionD.Text & "',
Answer = '" & cmbAnswer.Text & "'
WHERE QuesNo = '" & txtQuesNo.Text & "'"
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Student Record Updated Successfully!",
MsgBoxStyle.Information, "Added Success")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnQuesUpdate_Click(sender As Object, e As EventArgs)


Handles btnQuesUpdate.Click
If cmbClass.Text = "" Or cmbStream.Text = "" Or cmbSubject.Text =
"" Or txtQuesNo.Text = "" Or txtQuestion.Text = "" Or txtOptionA.Text =
"" Or txtOptionB.Text = "" Or txtOptionC.Text = "" Or txtOptionD.Text =
"" Or cmbAnswer.Text = "" Then
MsgBox("Please Enter Required Data", MsgBoxStyle.Critical)
Else
CheckEducation()
If EducationExist = True Then
CheckExam()
If ExamExist = True Then
QNo = txtQuesNo.Text
CheckQuestion()
If QuestionExist = True Then
If MsgBox("Are you sure you want to update?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
UpdateQues()
ShowAllQuesInGridView()
End If
Else
MsgBox("Question does not exist.",
MsgBoxStyle.Critical)
End If
End If
74
End If
End If
End Sub
Public Sub InsertQues()
Try
connection_close()
connection_open()
qry = "INSERT INTO Questions
(QuesNo, Class, Stream, Subject, Question, OptionA, OptionB,
OptionC, OptionD, Answer)
VALUES ('" & QNo & "',
'" & cmbClass.Text & "',
'" & cmbStream.Text & "',
'" & cmbSubject.Text & "',
'" & txtQuestion.Text & "',
'" & txtOptionA.Text & "',
'" & txtOptionB.Text & "',
'" & txtOptionC.Text & "',
'" & txtOptionD.Text & "',
'" & cmbAnswer.Text & "')"
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Question Added Successfully!",
MsgBoxStyle.Information, "Added Success")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnQuesInsert_Click(sender As Object, e As EventArgs)


Handles btnQuesInsert.Click
If cmbClass.Text = "" Or cmbStream.Text = "" Or cmbSubject.Text =
"" Or txtQuesNo.Text = "" Or txtQuestion.Text = "" Or txtOptionA.Text =
"" Or txtOptionB.Text = "" Or txtOptionC.Text = "" Or txtOptionD.Text =
"" Or cmbAnswer.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
CheckEducation()
If EducationExist = True Then
CheckExam()
If ExamExist = True Then
QNo = txtQuesNo.Text
CheckQuestion()

75
If QuestionExist = True Then
MaxQNo = MaxQuesValue()
If QNo < 1 Or QNo > (MaxQNo + 1) Then
MsgBox("Invalid Q.No:",
MsgBoxStyle.Information)
ElseIf QNo = 1 Then
MsgBox("Q.No: already exist.",
MsgBoxStyle.Critical)
ElseIf QNo = MaxQNo + 1 Then
InsertQues()
ShowAllQuesInGridView()
txtQuesNo.Text = QNo + 1
ClearQuesAns()
End If
ElseIf QuestionExist = False Then
If QNo = 1 Then
InsertQues()
ShowAllQuesInGridView()
txtQuesNo.Text = QNo + 1
ClearQuesAns()
Else
MaxQNo = MaxQuesValue()
If QNo = MaxQNo + 1 Then
InsertQues()
ShowAllQuesInGridView()
txtQuesNo.Text = QNo + 1
ClearQuesAns()
Else
MsgBox("Invalid Q.No:",
MsgBoxStyle.Critical)
End If
End If
End If
End If
End If
End If
End Sub

Public Sub DeleteQues()


Try
connection_close()
connection_open()
qry = "DELETE FROM Questions
WHERE QuesNo = '" & QNo & "'
AND Class = '" & cmbClass.Text & "'
AND Stream = '" & cmbStream.Text & "'
76
AND Subject = '" & cmbSubject.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Question Deleted Successfully!",
MsgBoxStyle.Information, "Deleted")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnQuesDelete_Click(sender As Object, e As EventArgs)


Handles btnQuesDelete.Click
If cmbClass.Text = "" Or cmbStream.Text = "" Or cmbSubject.Text =
"" Or txtQuesNo.Text = "" Or txtQuestion.Text = "" Or txtOptionA.Text =
"" Or txtOptionB.Text = "" Or txtOptionC.Text = "" Or txtOptionD.Text =
"" Or cmbAnswer.Text = "" Then
MsgBox("Please Enter Required Data", MsgBoxStyle.Critical)
Else
CheckEducation()
If EducationExist = True Then
CheckExam()
If ExamExist = True Then
QNo = txtQuesNo.Text
CheckQuestion()
If QuestionExist = True Then
If MsgBox("Are you sure you want to delete?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
DeleteQues()
ShowAllQuesInGridView()
End If
Else
MsgBox("Question does not exist.",
MsgBoxStyle.Critical)
End If
End If
End If
End If
End Sub

Public Sub ShowSelectedQues()


QNo =
Convert.ToInt32(DataGridViewQuestion.SelectedCells.Item(4).Value.ToString
)
ShowQues()
End Sub
77
Public Sub PrevNextQues()
Try
connection_close()
connection_open()
qry = "SELECT * FROM Questions
WHERE Class = '" & cmbClass.Text & "'
AND Stream = '" & cmbStream.Text & "'
AND Subject = '" & cmbSubject.Text & "'
AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
txtQuesNo.Text = dr.Item("QuesNo").ToString
txtQuestion.Text = dr.Item("Question").ToString
txtOptionA.Text = dr.Item("OptionA").ToString
txtOptionB.Text = dr.Item("OptionB").ToString
txtOptionC.Text = dr.Item("OptionC").ToString
txtOptionD.Text = dr.Item("OptionD").ToString
cmbAnswer.Text = dr.Item("Answer").ToString
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Function MaxQuesValue()


Try
connection_close()
connection_open()
qry = "select max(QuesNo) as MaxQNo from Questions where
Subject = '" & cmbSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MaxQNo")
End Function
Private Sub btnQuesNext_Click(sender As Object, e As EventArgs)
Handles btnQuesNext.Click
If DataGridViewQuestion.SelectionMode = True Then
78
QNo =
Convert.ToInt32(DataGridViewQuestion.SelectedCells.Item(4).Value.ToString
)
Else
QNo = txtQuesNo.Text
End If
MaxQNo = MaxQuesValue()
If QNo >= MaxQNo Then
QNo = MaxQNo + 1
txtQuesNo.Clear()
txtQuestion.Clear()
txtOptionA.Clear()
txtOptionB.Clear()
txtOptionC.Clear()
txtOptionD.Clear()
cmbAnswer.Text = ""
txtQuesNo.Text = QNo
Else
QNo += 1
PrevNextQues()
End If
End Sub

Private Sub btnQuesPrevious_Click(sender As Object, e As EventArgs)


Handles btnQuesPrevious.Click
If DataGridViewQuestion.SelectionMode = True Then
QNo =
Convert.ToInt32(DataGridViewQuestion.SelectedCells.Item(4).Value.ToString
)
Else
QNo = txtQuesNo.Text
End If
If QNo < 1 Then
QNo = 1
Else
QNo -= 1
End If
PrevNextQues()
End Sub

Private Sub DataGridViewQuestion_CellClick(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridViewQuestion.CellClick
ShowSelectedQues()
End Sub

Public Sub ClearQuesAns()


79
txtQuestion.Clear()
txtOptionA.Clear()
txtOptionB.Clear()
txtOptionC.Clear()
txtOptionD.Clear()
cmbAnswer.Text = ""
End Sub

Private Sub btnQuestionClearAll_Click(sender As Object, e As


EventArgs) Handles btnQuestionClearAll.Click
cmbClass.Text = ""
cmbStream.Text = ""
cmbSubject.Text = ""
txtQuesNo.Clear()
ClearQuesAns()
DataGridViewQuestion.DataSource = Nothing
DataGridViewQuestion.Refresh()
End Sub

End Class

Manage_Student_Form.vb
Imports System.Data.SqlClient
Imports System.Data
Public Class Manage_Student_Form
Dim i As Integer

Private Sub btnStudentClear_Click(sender As Object, e As EventArgs)


Handles btnStudentClearAll.Click
txtStudentRegistrationNumber.Clear()
txtStudentFullName.Clear()
txtStudentEmail.Clear()
txtStudentAddress.Clear()
txtPhoneNumber.Clear()
cmbStudentGender.Text = ""
cmbStudentClass.Text = ""
cmbStudentStream.Text = ""
cmbStudentSubject.Text = ""
pictureStudent.Image = Nothing
txtStudentAge.Clear()
DataGridViewStudent.DataSource = Nothing
DataGridViewStudent.Refresh()
80
End Sub

Private Sub btnStudentUploadPhoto_Click(sender As Object, e As


EventArgs) Handles btnStudentUploadPhoto.Click
With OFDStudent
.Title = "Select Student Photo"
.Filter = "Jpeg Images Only|*.jpg"
.FileName = ""
.Multiselect = False
.ShowDialog()
If .FileName <> "" Then
pictureStudent.Load(.FileName)
End If
End With
End Sub

Private Sub btnStudentSave_Click(sender As Object, e As EventArgs)


Handles btnStudentInsert.Click
'Checking Validation
If txtStudentRegistrationNumber.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
Try
'Checking Duplicacy
qry = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
MsgBox("Records Already Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
Else
'Inserting Data
qry = "INSERT INTO [dbo].[Students]
([RegNo]
,[Name]
,[Class]
,[Stream]
,[Subject]
,[Gender]
,[Age]
,[PhNo]
,[Email]
81
,[Address]
,[Picture])
VALUES
('" & txtStudentRegistrationNumber.Text & "'
,'" & txtStudentFullName.Text & "'
,'" & cmbStudentClass.Text & "'
,'" & cmbStudentStream.Text & "'
,'" & cmbStudentSubject.Text & "'
,'" & cmbStudentGender.Text & "'
,'" & txtStudentAge.Text & "'
,'" & txtPhoneNumber.Text & "'
,'" & txtStudentEmail.Text & "'
,'" & txtStudentAddress.Text & "'
,'" & pictureStudent.ImageLocation & "')"
connection_open()
qry1 = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = False Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
MsgBox("New Student Added Successfully!",
MsgBoxStyle.Information, "Added Success")
connection_close()
End If
End If
connection_close()
data_disp()
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If
End Sub

Public Sub data_disp()


Try
qry = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
82
DataGridViewStudent.DataSource = dt
End Using
End Using
Catch ex As Exception

End Try
End Sub

Private Sub btnStudentDelete_Click(sender As Object, e As EventArgs)


Handles btnStudentDelete.Click
If txtStudentRegistrationNumber.Text = "" Then
MsgBox("Please Enter Registration Number",
MsgBoxStyle.Critical)
Else
Try
'Checking Data
qry = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("Record Does Not Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
Else
If MsgBox("Are you sure you want to update?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
qry = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
qry1 = "DELETE FROM [dbo].[Students]
WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_open()
cmd1 = New SqlCommand(qry1, cnn)
cmd1.ExecuteNonQuery()
MsgBox("New Student Deleted Successfully!",
MsgBoxStyle.Information, "Deleted")
connection_close()
data_disp()
83
End If
End If
End If
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If
End Sub
Private Sub btnStudentSearch_Click(sender As Object, e As EventArgs)
Handles btnStudentSearch.Click
If txtStudentRegistrationNumber.Text = "" And
txtStudentFullName.Text = "" And txtStudentEmail.Text = "" And
cmbStudentClass.Text = "" And cmbStudentStream.Text = "" And
cmbStudentSubject.Text = "" Then
MsgBox("Please Enter Student Detail", MsgBoxStyle.Critical)
Else
Try
connection_close()
connection_open()

qry = "SELECT * FROM Students


WHERE RegNo = '" & txtStudentRegistrationNumber.Text & "'
OR Name = '" & txtStudentFullName.Text & "'
OR Email = '" & txtStudentEmail.Text & "'
OR Class = '" & cmbStudentClass.Text & "'
OR Stream = '" & cmbStudentStream.Text & "'
OR Subject = '" & cmbStudentSubject.Text & "'"

cmd = New SqlCommand(qry, cnn)


Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewStudent.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try
End If
End Sub

84
Private Sub btnStudentDisplayAll_Click(sender As Object, e As
EventArgs) Handles btnStudentDisplayAll.Click
Try
connection_close()
connection_open()
qry = "SELECT * FROM Students"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewStudent.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnStudentUpdate_Click(sender As Object, e As EventArgs)


Handles btnStudentUpdate.Click
'Checking Validation
If txtStudentRegistrationNumber.Text = "" Then
MsgBox("Please Enter Registration Number",
MsgBoxStyle.Critical)
Else
Try
'Checking Data
qry = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("Record Does Not Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
Else
If MsgBox("Are you sure you want to update?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Updating Data
qry = "UPDATE Students SET RegNo = '" &
txtStudentRegistrationNumber.Text & "', Name = '" &
txtStudentFullName.Text & "', Gender = '" & cmbStudentGender.Text & "',
Address = '" & txtStudentAddress.Text & "', PhNo = '" &
txtPhoneNumber.Text & "', Email = '" & txtStudentEmail.Text & "', Class =
85
'" & cmbStudentClass.Text & "', Stream = '" & cmbStudentStream.Text & "',
Subject = '" & cmbStudentSubject.Text & "', Picture = '" &
pictureStudent.ImageLocation & "', Age = '" & txtStudentAge.Text & "'
WHERE RegNo = '" & txtStudentRegistrationNumber.Text & "'"
connection_open()
qry1 = "SELECT * FROM Students WHERE RegNo = '" &
txtStudentRegistrationNumber.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = True Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
MsgBox("Student Record Updated
Successfully!", MsgBoxStyle.Information, "Added Success")
connection_close()
End If
End If
connection_close()
data_disp()
End If
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try
End If
End Sub

Private Sub Add_Student_Form_Load(sender As Object, e As EventArgs)


Handles MyBase.Load

End Sub

Private Sub DataGridViewStudent_CellClick(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridViewStudent.CellClick
Try
connection_open()
i =
Convert.ToInt32(DataGridViewStudent.SelectedCells.Item(0).Value.ToString)
qry = "SELECT * FROM Students WHERE Id = '" & i & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
86
While dr.Read
txtStudentRegistrationNumber.Text =
dr.GetString(1).ToString()
txtStudentFullName.Text = dr.GetString(2).ToString()
cmbStudentClass.Text = dr.GetString(3).ToString()
cmbStudentStream.Text = dr.GetString(4).ToString()
cmbStudentSubject.Text = dr.GetString(5).ToString()
cmbStudentGender.Text = dr.GetString(6).ToString()

txtStudentEmail.Text = dr.GetString(9).ToString()
txtStudentAddress.Text = dr.GetString(10).ToString()

txtPhoneNumber.Text = dr.Item("PhNo")
txtStudentAge.Text = dr.Item("Age")

pictureStudent.Image =
Image.FromFile(dr.Item("Picture").ToString)

End While
Catch ex As Exception

End Try
End Sub

Private Sub btnStudentClearPhoto_Click(sender As Object, e As


EventArgs) Handles btnStudentClearPhoto.Click
pictureStudent.Image = Nothing
End Sub
End Class

Manage_Teacher_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Manage_Teacher_Form


Dim i As Integer
Private Sub btnStudentClear_Click(sender As Object, e As EventArgs)
Handles btnTeacherClearAll.Click
txtTeacherId.Clear()
txtTeacherFullName.Clear()
87
txtTeacherEmail.Clear()
txtTeacherAddress.Clear()
txtTeacherPhoneNumber.Clear()
txtTeacherSalary.Text = ""
cmbTeacherGender.Text = ""
pictureTeacher.Image = Nothing
txtTeacherAge.Clear()
DataGridViewTeacher.DataSource = Nothing
DataGridViewTeacher.Refresh()
End Sub

Private Sub btnStudentUploadPhoto_Click(sender As Object, e As


EventArgs) Handles btnTeacherUploadPhoto.Click
With OFDTeacher
.Title = "Select Teacher Photo"
.Filter = "Jpeg Images Only|*.jpg"
.FileName = ""
.Multiselect = False
.ShowDialog()
If .FileName <> "" Then
pictureTeacher.Load(.FileName)
End If
End With
End Sub

Private Sub btnStudentSave_Click(sender As Object, e As EventArgs)


Handles btnTeacherInsert.Click
Try
'Checking Validation
If txtTeacherId.Text = "" Then
MsgBox("Please Enter All Required Fields",
MsgBoxStyle.Critical)
Else
'Checking Duplicacy
qry = "SELECT * FROM Teachers WHERE StaffId = '" &
txtTeacherId.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
MsgBox("Records Already Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
Else
'Inserting Data

88
qry = "INSERT INTO Teachers (StaffId, Name, Gender,
Address, PhNo, Email, Salary, Picture, Age) VALUES ('" &
txtTeacherId.Text & "', '" & txtTeacherFullName.Text & "', '" &
cmbTeacherGender.Text & "', '" & txtTeacherAddress.Text & "', '" &
txtTeacherPhoneNumber.Text & "', '" & txtTeacherEmail.Text & "', '" &
txtTeacherSalary.Text & "', '" & pictureTeacher.ImageLocation & "', '" &
txtTeacherAge.Text & "')"
connection_open()
qry1 = "SELECT * FROM Teachers WHERE StaffId = '" &
txtTeacherId.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = False Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
MsgBox("New Teacher Added Successfully!",
MsgBoxStyle.Information, "Added Success")
connection_close()
End If
End If
connection_close()
data_disp()
End If
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End Sub

Public Sub data_disp()


qry = "SELECT * FROM Teachers WHERE StaffId = '" &
txtTeacherId.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewTeacher.DataSource = dt
End Using
End Using
End Sub

89
Private Sub btnStudentDelete_Click(sender As Object, e As EventArgs)
Handles btnTeacherDelete.Click
If txtTeacherId.Text = "" Then
MsgBox("Please Enter Teacher Id", MsgBoxStyle.Critical)
Else
Try
'Checking Data
qry = "SELECT * FROM Teachers WHERE StaffId = '" &
txtTeacherId.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("Record Does Not Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
Else
If MsgBox("Are you sure you want to delete?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
qry = "SELECT * FROM Teachers WHERE StaffId = '"
& txtTeacherId.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
qry1 = "DELETE FROM [dbo].[Teachers]
WHERE StaffId = '" & txtTeacherId.Text & "'"
connection_open()
cmd1 = New SqlCommand(qry1, cnn)
cmd1.ExecuteNonQuery()
MsgBox("Teacher Deleted Successfully!",
MsgBoxStyle.Information, "Deleted")
connection_close()
data_disp()
End If
End If

End If
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If
End Sub

90
Private Sub btnStudentSearch_Click(sender As Object, e As EventArgs)
Handles btnTeacherSearch.Click
If txtTeacherId.Text = "" And txtTeacherFullName.Text = "" And
txtTeacherEmail.Text = "" And txtTeacherSalary.Text = "" Then
MsgBox("Please Enter Teacher Detail", MsgBoxStyle.Critical)
Else
Try
connection_open()
connection_close()
qry = "SELECT * FROM Teachers WHERE StaffId = '" &
txtTeacherId.Text & "' OR Name = '" & txtTeacherFullName.Text & "' OR
Email = '" & txtTeacherEmail.Text & "' OR Salary = '" &
txtTeacherSalary.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewTeacher.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If
End Sub

Private Sub btnStudentDisplayAll_Click(sender As Object, e As


EventArgs) Handles btnTeacherDisplayAll.Click
Try
connection_close()
qry = "SELECT * FROM Teachers"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewTeacher.DataSource = dt
End Using
End Using
Catch ex As Exception

End Try
End Sub
91
Private Sub btnStudentUpdate_Click(sender As Object, e As EventArgs)
Handles btnTeacherUpdate.Click
'Checking Validation
If txtTeacherId.Text = "" Then
MsgBox("Please Enter Teacher Id", MsgBoxStyle.Critical)
Else
Try
'Checking Data
qry = "SELECT * FROM Teachers WHERE StaffId = '" &
txtTeacherId.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("Record Does Not Exists!",
MsgBoxStyle.Critical, "Duplicate")
connection_close()
Else
If MsgBox("Are you sure you want to update?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Updating Data
qry = "UPDATE Teachers SET StaffId = '" &
txtTeacherId.Text & "', Name = '" & txtTeacherFullName.Text & "', Gender
= '" & cmbTeacherGender.Text & "', Address = '" & txtTeacherAddress.Text
& "', PhNo = '" & txtTeacherPhoneNumber.Text & "', Email = '" &
txtTeacherEmail.Text & "', Salary = '" & txtTeacherSalary.Text & "',
Picture = '" & pictureTeacher.ImageLocation & "', Age = '" &
txtTeacherAge.Text & "' WHERE StaffId = '" & txtTeacherId.Text & "'"
connection_open()
qry1 = "SELECT * FROM Teachers WHERE StaffId = '"
& txtTeacherId.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = True Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
MsgBox("Teacher Record Updated
Successfully!", MsgBoxStyle.Information, "Added Success")
connection_close()
End If
End If

End If
connection_close()
data_disp()
92
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try

End If
End Sub

Public Sub ShowImage()


Try
If cnn.State = 1 Then cnn.Close()
connection_open()
qry = "SELECT * FROM Teachers WHERE StaffId = '" &
txtTeacherId.Text & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
pictureTeacher.Image =
Image.FromFile(dr.Item("Picture").ToString)
End While
Catch ex As Exception

End Try
End Sub

Private Sub Add_Teacher_Form_Load(sender As Object, e As EventArgs)


Handles MyBase.Load

End Sub

Private Sub DataGridViewTeacher_CellClick(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridViewTeacher.CellClick
Try
connection_open()
i =
Convert.ToInt32(DataGridViewTeacher.SelectedCells.Item(0).Value.ToString)
qry = "SELECT * FROM Teachers WHERE Id = '" & i & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
93
txtTeacherId.Text = dr.GetString(1).ToString()
txtTeacherFullName.Text = dr.GetString(2).ToString()
txtTeacherSalary.Text = dr.Item("Salary")
cmbTeacherGender.Text = dr.GetString(4).ToString()
txtTeacherAge.Text = dr.Item("Age")
txtTeacherPhoneNumber.Text = dr.Item("PhNo")
txtTeacherEmail.Text = dr.GetString(7).ToString()
txtTeacherAddress.Text = dr.GetString(8).ToString()
ShowImage()
End While
Catch ex As Exception

End Try
End Sub

Private Sub btnTeacherClearPhoto_Click(sender As Object, e As


EventArgs) Handles btnTeacherClearPhoto.Click
pictureTeacher.Image = Nothing
End Sub

End Class

Manage_User_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Manage_User_Form


Dim i As Integer

Private Sub btnStudentClearAll_Click(sender As Object, e As


EventArgs) Handles btnStudentClearAll.Click
txtUsername.Clear()
txtPassword.Clear()
cmbUserType.Text = ""
DataGridViewUser.DataSource = Nothing
DataGridViewUser.Refresh()
End Sub

Private Sub btnStudentInsert_Click(sender As Object, e As EventArgs)


Handles btnStudentInsert.Click
'Checking Validation
94
If cmbUserType.Text = "" Or txtUsername.Text = "" Or
txtPassword.Text = "" Then
MsgBox("Please Enter All Data", MsgBoxStyle.Critical)
ElseIf cmbUserType.Text = "Admin" Or cmbUserType.Text = "Student"
Or cmbUserType.Text = "Teacher" Then
'Checking Duplicacy
qry = "SELECT * FROM Login
WHERE UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUsername.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
MsgBox("User Already Exists!", MsgBoxStyle.Critical,
"Duplicate")
connection_close()
Else
'Inserting Data
qry = "INSERT INTO Login (UserType, UserName, Password)
VALUES ('" & cmbUserType.Text & "', '" & txtUsername.Text & "', '" &
txtPassword.Text & "')"
connection_open()
qry1 = "SELECT * FROM Login
WHERE UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUsername.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = False Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
MsgBox("New User Added Successfully!",
MsgBoxStyle.Information, "Added Success")
connection_close()
End If
End If
connection_close()
data_disp()
Else
MsgBox("Invalid User Type.", MsgBoxStyle.Critical)
End If
End Sub

Public Sub data_disp()


qry = "SELECT * FROM Login WHERE UserName = '" & txtUsername.Text
& "'"
95
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewUser.DataSource = dt
End Using
End Using
End Sub

Private Sub btnStudentDelete_Click(sender As Object, e As EventArgs)


Handles btnStudentDelete.Click
If cmbUserType.Text = "" Or txtUsername.Text = "" Or
txtPassword.Text = "" Then
MsgBox("Please Enter All Data", MsgBoxStyle.Critical)
ElseIf cmbUserType.Text = "Student" Or cmbUserType.Text =
"Teacher" Then
'Checking Data
qry = "SELECT * FROM Login
WHERE UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUsername.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("User Does Not Exists!", MsgBoxStyle.Critical,
"Duplicate")
connection_close()
Else
If MsgBox("Are you sure you want to delete?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
qry = "SELECT * FROM Login
WHERE UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUsername.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
qry1 = "DELETE FROM [dbo].[Login]
WHERE UserName = '" & txtUsername.Text & "'"
connection_open()
cmd1 = New SqlCommand(qry1, cnn)
cmd1.ExecuteNonQuery()
MsgBox("User Deleted Successfully!",
MsgBoxStyle.Information, "Deleted")
connection_close()
96
data_disp()
End If
End If

End If
ElseIf cmbUserType.Text = "Admin" Then
MsgBox("You're not allowed to delete Admin.",
MsgBoxStyle.Critical)
Else
MsgBox("Invalid User Type.", MsgBoxStyle.Critical)
End If
End Sub

Private Sub btnStudentSearch_Click(sender As Object, e As EventArgs)


Handles btnStudentSearch.Click
If cmbUserType.Text = "" And txtUsername.Text = "" Then
MsgBox("Please Enter Usertype OR Username Detail",
MsgBoxStyle.Critical)
Else
Try
connection_close()
connection_open()
qry = "SELECT * FROM Login WHERE
UserType = '" & cmbUserType.Text & "'
OR UserName = '" & txtUsername.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewUser.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox("Invalid User Type.", MsgBoxStyle.Critical)
End Try
End If
End Sub
Private Sub btnStudentDisplayAll_Click(sender As Object, e As
EventArgs) Handles btnStudentDisplayAll.Click
connection_close()
qry = "SELECT * FROM Login"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()

97
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewUser.DataSource = dt
End Using
End Using
End Sub

Private Sub btnStudentUpdate_Click(sender As Object, e As EventArgs)


Handles btnStudentUpdate.Click
If cmbUserType.Text = "" Or txtUsername.Text = "" Or
txtPassword.Text = "" Then
MsgBox("Please Enter All Data", MsgBoxStyle.Critical)
ElseIf cmbUserType.Text = "Student" Or cmbUserType.Text =
"Teacher" Then
'Checking Data
qry = "SELECT * FROM Login
WHERE UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUsername.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then
MsgBox("User Does Not Exists!", MsgBoxStyle.Critical,
"Duplicate")
connection_close()
Else
If MsgBox("Are you sure you want to update?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
'Updating Data
qry = "UPDATE Login SET UserType = '" &
cmbUserType.Text & "', UserName = '" & txtUsername.Text & "', Password =
'" & txtPassword.Text & "' WHERE UserName = '" & txtUsername.Text & "'"
connection_open()
qry1 = "SELECT * FROM Login
WHERE UserType = '" & cmbUserType.Text & "'
AND UserName = '" & txtUsername.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = True Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
MsgBox("User Record Updated Successfully!",
MsgBoxStyle.Information, "Added Success")
connection_close()
98
End If
End If

End If
connection_close()
data_disp()
ElseIf cmbUserType.Text = "Admin" Then
MsgBox("You're not allowed to update Admin here. Go to
Settings and then update.", MsgBoxStyle.Critical)
Else
MsgBox("Invalid User Type.", MsgBoxStyle.Critical)
End If
End Sub

Private Sub Manage_User_Form_Load(sender As Object, e As EventArgs)


Handles MyBase.Load

End Sub

Private Sub DataGridViewUser_CellClick(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridViewUser.CellClick
Try
connection_open()
i =
Convert.ToInt32(DataGridViewUser.SelectedCells.Item(0).Value.ToString)
qry = "SELECT * FROM Login WHERE id = '" & i & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
cmbUserType.Text = dr.GetString(1).ToString()
txtUsername.Text = dr.GetString(2).ToString()
txtPassword.Text = dr.GetString(3).ToString()
End While
Catch ex As Exception

End Try
End Sub
End Class

99
Setting_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Setting_Form


Private Sub btnChangeUsername_Click(sender As Object, e As EventArgs)
Handles btnChangeUsername.Click
If Login_Form.cmbUserType.Text = "Student" Or
Login_Form.cmbUserType.Text = "Teacher" Then
MsgBox("You're not allowed to change Username! Please contact
Admin.", MsgBoxStyle.Critical, "Not Allowed")
ElseIf Login_Form.cmbUserType.Text = "Admin" Then
If txtOldUsername.Text = "" Or txtNewUsername.Text = "" Then
MsgBox("Please Enter All Details", MsgBoxStyle.Question,
"Enter details")
Else
connection_close()
connection_open()
qry = "SELECT * FROM Login WHERE UserName = '" &
txtOldUsername.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
connection_close()

connection_open()
qry = "UPDATE Login set UserName = '" &
txtNewUsername.Text & "' WHERE UserName = '" & txtOldUsername.Text & "'"
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Username Changed Successfully",
MsgBoxStyle.Information, "Success")
connection_close()
Else
connection_close()
MsgBox("Old Username is Invalid",
MsgBoxStyle.Critical, "Not Change")
End If
End If
End If
End Sub

Private Sub btnChangePassword_Click(sender As Object, e As EventArgs)


Handles btnChangePassword.Click
If txtOldPassword.Text = "" Or txtNewPassword.Text = "" Then
100
MsgBox("Please Enter All Details", MsgBoxStyle.Question,
"Enter details")
Else
connection_close()
connection_open()
qry = "SELECT * FROM Login WHERE Password = '" &
txtOldPassword.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
connection_close()

connection_open()
qry = "UPDATE Login set Password = '" &
txtNewPassword.Text & "' WHERE Password = '" & txtOldPassword.Text & "'
AND UserName = '" & Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
cmd.ExecuteNonQuery()
MsgBox("Password Changed Successfully",
MsgBoxStyle.Information, "Success")
connection_close()
Else
connection_close()
MsgBox("Old Password is Invalid", MsgBoxStyle.Critical,
"Not Change")
End If
End If
End Sub

Private Sub Setting_Form_Load(sender As Object, e As EventArgs)


Handles MyBase.Load
If Login_Form.cmbUserType.Text = "Student" Or
Login_Form.cmbUserType.Text = "Teacher" Then
PanelChangeUsername.Visible = False
End If
End Sub
End Class

Student_Dashboard_Form.vb
Imports System.Data.SqlClient
Imports System.Data

101
Public Class Student_Dashboard_Form
Dim ExamCompleted, ExamLeft, TotalExam, TotalSubjects As Integer
Dim RecentExamSubject As String
Dim RecentSubjectId As Integer
Public Sub ShowDashboardInfo()
Try
connection_close()
connection_open()
qry = "SELECT * FROM Students WHERE RegNo = '" &
Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
lblRegNo.Text = dr.Item("RegNo").ToString()
lblName.Text = dr.Item("Name").ToString()
lblClass.Text = dr.Item("Class").ToString()
lblStream.Text = dr.Item("Stream").ToString()
'lblSubject1.Text = dr.Item("Subject").ToString()
Else
MsgBox("Record Not Found. Try Again!")
End If

FindRecentExam()
lblSubject1.Text = RecentExamSubject

connection_close()
connection_open()

qry = "select count (RegNo) from Result


where RegNo = '" & Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
ExamCompleted = cmd.ExecuteScalar
lblExamCompleted.Text = ExamCompleted

qry = "select count (Subject) from Exam


where Class = '" & lblClass.Text & "'
and Stream = '" & lblStream.Text & "'"
cmd = New SqlCommand(qry, cnn)
TotalExam = cmd.ExecuteScalar
lblTotalExam.Text = TotalExam

ExamLeft = TotalExam - ExamCompleted

lblExamLeft.Text = ExamLeft

qry = "select count (Subject) from Students


102
where RegNo = '" & Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
TotalSubjects = cmd.ExecuteScalar
lblTotalExam.Text = TotalSubjects

Catch ex As Exception

End Try
End Sub

Public Sub FindRecentExam()


Try
connection_close()
connection_open()
qry = "select max(id) as RecentSubjectId from Exam
where Class = '" & lblClass.Text & "'
and Stream = '" & lblStream.Text & "'"

cmd = New SqlCommand(qry, cnn)


dr = cmd.ExecuteReader
dr.Read()
RecentSubjectId = dr.Item("RecentSubjectId")
Catch ex As Exception
MsgBox(ex.Message)
End Try

Try
connection_close()
connection_open()
qry = "select Subject from Exam where id = '" &
RecentSubjectId & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
RecentExamSubject = dr.Item("Subject")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Student_Dashboard_Form_Load(sender As Object, e As


EventArgs) Handles MyBase.Load
ShowDashboardInfo()
End Sub
End Class
103
Student_Exam_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Student_Exam_Form

Dim TimeDuration As Integer

Public Sub ShowExam()


connection_close()
connection_open()
Try
qry = "SELECT * FROM Exam
WHERE Class = '" & Student_Dashboard_Form.lblClass.Text & "'
And Stream = '" & Student_Dashboard_Form.lblStream.Text & "'
AND Subject = '" & Student_Dashboard_Form.lblSubject1.Text &
"'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
lblExamClass.Text = dr.Item("Class").ToString()
lblExamStream.Text = dr.Item("Stream").ToString()
lblExamSubject1.Text = dr.Item("Subject").ToString()
lblExamTotalQues.Text = dr.Item("TotalQues").ToString()
lblExamTotalMarks.Text = dr.Item("TotalMarks").ToString()
TimeDuration = dr.Item("TimeDuration")
lblExamTimeDur.Text = (TimeDuration / 60).ToString()
Else
MsgBox("Record Not Found. Try Again!")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub CheckQuestions()


connection_close()
connection_open()
Try
qry = "SELECT * FROM Questions
WHERE Class = '" & lblExamClass.Text & "'
And Stream = '" & lblExamStream.Text & "'

104
AND Subject = '" & lblExamSubject1.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
Student_Start_Exam_Form.ShowDialog()
Else
MsgBox("Questions Not Added Yet! Please Contact
Teacher.", MsgBoxStyle.Critical, "")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub CheckStudent()


connection_close()
connection_open()
Try
qry = "SELECT * FROM Result
WHERE RegNo = '" & Login_Form.txtUserName.Text & "'
AND Class = '" & lblExamClass.Text & "'
And Stream = '" & lblExamStream.Text & "'
AND Subject = '" & lblExamSubject1.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
MsgBox("You Already Have Given The Exam",
MsgBoxStyle.Critical, "")
connection_close()
Else
CheckQuestions()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnStartExam_Click(sender As Object, e As EventArgs)


Handles btnStartExam.Click
CheckStudent()
End Sub

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


MyBase.Load
ShowExam()
End Sub
105
End Class

Student_Panel_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Student_Panel_Form

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


btnStLogOut.Click
Me.Dispose()
End Sub

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


btnStExam.Click
Student_Exam_Form.Refresh()

With Student_Exam_Form
.TopLevel = False
panelCentre.Controls.Add(Student_Exam_Form)
.BringToFront()
.Show()
End With
End Sub

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


btnStResult.Click
CheckStudent()
End Sub

Private Sub btnStDashboard_Click(sender As Object, e As EventArgs)


Handles btnStDashboard.Click
Student_Dashboard_Form.Refresh()
With Student_Dashboard_Form
.TopLevel = False
panelCentre.Controls.Add(Student_Dashboard_Form)
.BringToFront()
.Show()
End With
End Sub

106
Private Sub Student_Pannel_Form_Load(sender As Object, e As
EventArgs) Handles MyBase.Load
Try
connection_close()
connection_open()
qry = "SELECT * FROM Students WHERE RegNo = '" &
Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
picStudent.Image =
Image.FromFile(dr.Item("Picture").ToString)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try

With Student_Dashboard_Form
.TopLevel = False
panelCentre.Controls.Add(Student_Dashboard_Form)
.BringToFront()
.Show()
End With
End Sub

Public Sub CheckStudent()


connection_close()
connection_open()
Try
qry = "SELECT * FROM Result
WHERE RegNo = '" & Login_Form.txtUserName.Text & "'
AND Class = '" & Student_Dashboard_Form.lblClass.Text & "'
And Stream = '" & Student_Dashboard_Form.lblStream.Text & "'
AND Subject = '" & Student_Dashboard_Form.lblSubject1.Text &
"'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
With Student_Result_Form
.TopLevel = False
panelCentre.Controls.Add(Student_Result_Form)
.BringToFront()
107
.Show()
End With
Else
MsgBox("You Haven't Given The Exam Yet!",
MsgBoxStyle.Critical, "")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnAdSettings_Click(sender As Object, e As EventArgs)


Handles btnAdSettings.Click
With Setting_Form
.TopLevel = False
panelCentre.Controls.Add(Setting_Form)
.BringToFront()
.Show()
End With
End Sub

End Class

Student_Result_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Student_Result_Form

Dim TotalQues, TotalMarks, MarksObtain As Integer


Dim Percentage As Double
Dim Attempt, Skipped, Correct, Wrong As Integer

Public Function MinAnsValue()


Try
connection_close()
connection_open()
qry = "select min(QuesNo) as MinQNo from AnswerSheet
where RegNo = '" & Login_Form.txtUserName.Text & "'
and Subject = '" & Student_Dashboard_Form.lblSubject1.Text &
"'"
cmd = New SqlCommand(qry, cnn)
108
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MinQNo")
End Function

Public Function MaxAnsValue()


Try
connection_close()
connection_open()
qry = "select max(QuesNo) as MaxQNo from AnswerSheet
where RegNo = '" & Login_Form.txtUserName.Text & "'
and Subject = '" & Student_Dashboard_Form.lblSubject1.Text &
"'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MaxQNo")
End Function

Public Function CountCorrectAns()


Try
connection_close()
connection_open()
qry = "select count(QuesNo) as Correct from AnswerSheet
where RegNo = '" & Login_Form.txtUserName.Text & "'
and Subject = '" & Student_Dashboard_Form.lblSubject1.Text &
"'
and Answer = GivenAnswer"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("Correct")
End Function

Public Function CountWrongAns()


Try
connection_close()
109
connection_open()
qry = "select count(QuesNo) as Wrong from AnswerSheet
where RegNo = '" & Login_Form.txtUserName.Text & "'
and Subject = '" & Student_Dashboard_Form.lblSubject1.Text &
"'
and Answer <> GivenAnswer"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("Wrong")
End Function

Public Sub CheckStudent()


connection_close()
connection_open()
Try
qry = "SELECT * FROM Result
WHERE RegNo = '" & Login_Form.txtUserName.Text & "'
AND Class = '" & Student_Dashboard_Form.lblClass.Text & "'
And Stream = '" & Student_Dashboard_Form.lblStream.Text & "'
AND Subject = '" & Student_Exam_Form.lblExamSubject1.Text &
"'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
With Student_ResultAnalysis_Form
.TopLevel = False

Student_Panel_Form.panelCentre.Controls.Add(Student_ResultAnalysis_Form)
.BringToFront()
.Show()
End With
Else
MsgBox("You Haven't Given The Exam Yet!",
MsgBoxStyle.Critical, "")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnResultAnalysis_Click_1(sender As Object, e As


EventArgs) Handles btnResultAnalysis.Click
110
CheckStudent()
End Sub

Public Function CountSkippedQues()


Try
connection_close()
connection_open()
qry = "select count(QuesNo) as Skipped from AnswerSheet
where RegNo = '" & Login_Form.txtUserName.Text & "'
and Subject = '" & Student_Dashboard_Form.lblSubject1.Text &
"'
and GivenAnswer = ''"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("Skipped")
End Function

Public Function CountAttemptedQues()


Try
connection_close()
connection_open()
qry = "select count(QuesNo) as Attempt from AnswerSheet
where RegNo = '" & Login_Form.txtUserName.Text & "'
and Subject = '" & Student_Dashboard_Form.lblSubject1.Text &
"'
and GivenAnswer <> ''"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("Attempt")
End Function

Private Sub Exam_Result_Form_Load(sender As Object, e As EventArgs)


Handles MyBase.Load
Try
connection_close()
connection_open()

111
qry = "SELECT * FROM Students WHERE RegNo = '" &
Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
lblRegNo.Text = dr.Item("RegNo").ToString()
lblName.Text = dr.Item("Name").ToString()
lblClass.Text = dr.Item("Class").ToString()
lblStream.Text = dr.Item("Stream").ToString()
ShowImage()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try

Try
connection_close()
connection_open()
qry = "SELECT * FROM Result WHERE
RegNo = '" & Login_Form.txtUserName.Text & "' AND Subject =
'" & Student_Dashboard_Form.lblSubject1.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
lblSubject.Text = dr.Item("Subject").ToString()

lblTotalQues.Text = dr.Item("TotalQues").ToString()
TotalQues = dr.Item("TotalQues")

lblTotalMarks.Text = dr.Item("TotalMarks").ToString()
TotalMarks = dr.Item("TotalMarks")

lblMarksScore.Text = dr.Item("MarksObtain").ToString()
MarksObtain = dr.Item("MarksObtain")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try

Percentage = (MarksObtain * 100) / TotalMarks


lblPercentage.Text = Percentage & " % "

Correct = CountCorrectAns()
Wrong = CountWrongAns()
Skipped = CountSkippedQues()
Attempt = CountAttemptedQues()
112
lblCorrectAns.Text = Correct.ToString
lblWrongAns.Text = Wrong.ToString
lblQuesSkipped.Text = Skipped.ToString
lblQuesAttempted.Text = Attempt.ToString
End Sub

Public Sub ShowImage()


Try
connection_close()
connection_open()
qry = "SELECT * FROM Students WHERE RegNo = '" &
Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
pictureStudent.Image =
Image.FromFile(dr.Item("Picture").ToString)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnResultAnalysis_Click(sender As Object, e As EventArgs)


With Student_ResultAnalysis_Form
.TopLevel = False

Student_Panel_Form.panelCentre.Controls.Add(Student_ResultAnalysis_Form)
.BringToFront()
.Show()
End With
End Sub

End Class

Student_ResultAnalysis_Form.vb
Imports System.Data.SqlClient
Imports System.Data
113
Public Class Student_ResultAnalysis_Form
Dim MaxQNo As Integer
Dim QuestionNo As Integer = 1
Dim CorrectAnswer, GivenAnswer As String

Public Sub ShowAllAns()


Try
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB, OptionC,
OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & Login_Form.txtUserName.Text & "' AND Class
= '" & Student_Dashboard_Form.lblClass.Text & "'
AND Stream = '" & Student_Dashboard_Form.lblStream.Text & "'
AND Subject = '" & Student_Dashboard_Form.lblSubject1.Text & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewResultAnalysis.DataSource = dt
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub ShowPrevNextAns()


Try
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB, OptionC,
OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & Login_Form.txtUserName.Text & "' AND Class
= '" & Student_Dashboard_Form.lblClass.Text & "'
AND Stream = '" & Student_Dashboard_Form.lblStream.Text & "'
AND Subject = '" & Student_Dashboard_Form.lblSubject1.Text & "'
AND QuesNo = '" & QuestionNo & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewResultAnalysis.DataSource = dt
114
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub ResultAnalysis_Load(sender As Object, e As EventArgs)


Handles MyBase.Load
MaxQNo = MaxQuesValue()
PrevNextQues()
ShowAllAns()
End Sub

Public Function MaxQuesValue()


Try
connection_close()
connection_open()
qry = "SELECT MAX(QuesNo) AS MaxQNo FROM AnswerSheet WHERE
RegNo = '" & Login_Form.txtUserName.Text & "' AND Class = '" &
Student_Dashboard_Form.lblClass.Text & "'
AND Stream = '" & Student_Dashboard_Form.lblStream.Text & "'
AND Subject = '" & Student_Dashboard_Form.lblSubject1.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MaxQNo")
End Function

Public Sub DontColourOptButton()


txtResultAnalysisOptionA.BackColor = Color.White
txtResultAnalysisOptionA.ForeColor = Color.Black

txtResultAnalysisOptionB.BackColor = Color.White
txtResultAnalysisOptionB.ForeColor = Color.Black

txtResultAnalysisOptionC.BackColor = Color.White
txtResultAnalysisOptionC.ForeColor = Color.Black

txtResultAnalysisOptionD.BackColor = Color.White
txtResultAnalysisOptionD.ForeColor = Color.Black
End Sub

115
Public Sub ColourOptBtn()
If CorrectAnswer = "Option (A)" Then
txtResultAnalysisOptionA.BackColor = Color.LimeGreen
txtResultAnalysisOptionA.ForeColor = Color.White
ElseIf CorrectAnswer = "Option (B)" Then
txtResultAnalysisOptionB.BackColor = Color.LimeGreen
txtResultAnalysisOptionB.ForeColor = Color.White
ElseIf CorrectAnswer = "Option (C)" Then
txtResultAnalysisOptionC.BackColor = Color.LimeGreen
txtResultAnalysisOptionC.ForeColor = Color.White
ElseIf CorrectAnswer = "Option (D)" Then
txtResultAnalysisOptionD.BackColor = Color.LimeGreen
txtResultAnalysisOptionD.ForeColor = Color.White
Else
txtResultAnalysisOptionA.BackColor = Color.White
txtResultAnalysisOptionA.ForeColor = Color.Black

txtResultAnalysisOptionB.BackColor = Color.White
txtResultAnalysisOptionB.ForeColor = Color.Black

txtResultAnalysisOptionC.BackColor = Color.White
txtResultAnalysisOptionC.ForeColor = Color.Black

txtResultAnalysisOptionD.BackColor = Color.White
txtResultAnalysisOptionD.ForeColor = Color.Black
End If

If GivenAnswer = "Option (A)" And CorrectAnswer <> GivenAnswer


Then
txtResultAnalysisOptionA.BackColor = Color.Red
txtResultAnalysisOptionA.ForeColor = Color.White
ElseIf GivenAnswer = "Option (B)" And CorrectAnswer <>
GivenAnswer Then
txtResultAnalysisOptionB.BackColor = Color.Red
txtResultAnalysisOptionB.ForeColor = Color.White
ElseIf GivenAnswer = "Option (C)" And CorrectAnswer <>
GivenAnswer Then
txtResultAnalysisOptionC.BackColor = Color.Red
txtResultAnalysisOptionC.ForeColor = Color.White
ElseIf GivenAnswer = "Option (D)" And CorrectAnswer <>
GivenAnswer Then
txtResultAnalysisOptionD.BackColor = Color.Red
txtResultAnalysisOptionD.ForeColor = Color.White
End If

116
If GivenAnswer = "Option (A)" And CorrectAnswer = GivenAnswer
Then
txtResultAnalysisOptionA.BackColor = Color.LimeGreen
txtResultAnalysisOptionA.ForeColor = Color.White
ElseIf GivenAnswer = "Option (B)" And CorrectAnswer = GivenAnswer
Then
txtResultAnalysisOptionB.BackColor = Color.LimeGreen
txtResultAnalysisOptionB.ForeColor = Color.White
ElseIf GivenAnswer = "Option (C)" And CorrectAnswer = GivenAnswer
Then
txtResultAnalysisOptionC.BackColor = Color.LimeGreen
txtResultAnalysisOptionC.ForeColor = Color.White
ElseIf GivenAnswer = "Option (D)" And CorrectAnswer = GivenAnswer
Then
txtResultAnalysisOptionD.BackColor = Color.LimeGreen
txtResultAnalysisOptionD.ForeColor = Color.White
End If
End Sub

Public Sub SearchQues()


DontColourOptButton()
CorrectAnswer = ""
GivenAnswer = ""
Try
If txtResultAnalysisQuesNo.Text = "" Then
MsgBox("Please Enter QNo", MsgBoxStyle.Critical)
Else
QuestionNo = txtResultAnalysisQuesNo.Text
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB,
OptionC, OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & Login_Form.txtUserName.Text & "' AND
Class = '" & Student_Dashboard_Form.lblClass.Text & "'
AND Stream = '" & Student_Dashboard_Form.lblStream.Text &
"' AND Subject = '" & Student_Dashboard_Form.lblSubject1.Text & "'
AND QuesNo = '" & QuestionNo & "'"
cmd = New SqlCommand(qry, cnn)
Using da As New SqlDataAdapter()
da.SelectCommand = cmd
Using dt As New DataTable()
da.Fill(dt)
DataGridViewResultAnalysis.DataSource = dt
End Using
End Using
ShowQuestion()
117
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub ShowQuestion()
Try
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB, OptionC,
OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & Login_Form.txtUserName.Text & "' AND Class
= '" & Student_Dashboard_Form.lblClass.Text & "'
AND Stream = '" & Student_Dashboard_Form.lblStream.Text & "'
AND Subject = '" & Student_Dashboard_Form.lblSubject1.Text & "'
AND QuesNo = '" & QuestionNo & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
txtResultAnalysisQuesNo.Text = dr.Item("QuesNo").ToString
txtResultAnalysisQuestion.Text =
dr.Item("Question").ToString
txtResultAnalysisOptionA.Text =
dr.Item("OptionA").ToString
txtResultAnalysisOptionB.Text =
dr.Item("OptionB").ToString
txtResultAnalysisOptionC.Text =
dr.Item("OptionC").ToString
txtResultAnalysisOptionD.Text =
dr.Item("OptionD").ToString
txtResultAnalysisAnswer.Text = dr.Item("Answer").ToString
txtResultAnalysisGivenAns.Text =
dr.Item("GivenAnswer").ToString
QuestionNo = CInt(dr.Item("QuesNo").ToString())
CorrectAnswer = dr.Item("Answer").ToString()
GivenAnswer = dr.Item("GivenAnswer").ToString()
ColourOptBtn()
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try

118
End Sub

Private Sub btnResultAnalysisSearch_Click(sender As Object, e As


EventArgs) Handles btnResultAnalysisSearch.Click
SearchQues()
End Sub

Public Sub PrevNextQues()


DontColourOptButton()
CorrectAnswer = ""
GivenAnswer = ""
Try
connection_close()
connection_open()
qry = "SELECT QuesNo, Question, OptionA, OptionB, OptionC,
OptionD, Answer, GivenAnswer FROM AnswerSheet
WHERE RegNo = '" & Login_Form.txtUserName.Text & "' AND Class
= '" & Student_Dashboard_Form.lblClass.Text & "'
AND Stream = '" & Student_Dashboard_Form.lblStream.Text & "'
AND Subject = '" & Student_Dashboard_Form.lblSubject1.Text & "'
AND QuesNo = '" & QuestionNo & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
txtResultAnalysisQuesNo.Text = dr.Item("QuesNo").ToString
txtResultAnalysisQuestion.Text =
dr.Item("Question").ToString
txtResultAnalysisOptionA.Text =
dr.Item("OptionA").ToString
txtResultAnalysisOptionB.Text =
dr.Item("OptionB").ToString
txtResultAnalysisOptionC.Text =
dr.Item("OptionC").ToString
txtResultAnalysisOptionD.Text =
dr.Item("OptionD").ToString
txtResultAnalysisAnswer.Text = dr.Item("Answer").ToString
txtResultAnalysisGivenAns.Text =
dr.Item("GivenAnswer").ToString
CorrectAnswer = dr.Item("Answer").ToString()
GivenAnswer = dr.Item("GivenAnswer").ToString()
ColourOptBtn()
End While
Catch ex As Exception
119
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnResultAnalysisNext_Click(sender As Object, e As


EventArgs) Handles btnResultAnalysisNext.Click
If QuestionNo > MaxQNo Then
QuestionNo = 1
Else
QuestionNo += 1
End If
PrevNextQues()
ShowPrevNextAns()
End Sub

Private Sub DataGridViewResultAnalysis_CellClick(sender As Object, e


As DataGridViewCellEventArgs) Handles
DataGridViewResultAnalysis.CellClick
DontColourOptButton()
CorrectAnswer = ""
GivenAnswer = ""
QuestionNo =
Convert.ToInt32(DataGridViewResultAnalysis.SelectedCells.Item(0).Value.To
String)
ShowQuestion()
End Sub

Private Sub btnResultAnalysisPrevious_Click(sender As Object, e As


EventArgs) Handles btnResultAnalysisPrevious.Click
If QuestionNo < 1 Then
QuestionNo = 1
Else
QuestionNo -= 1
End If
PrevNextQues()
ShowPrevNextAns()
End Sub

Private Sub btnDisplayAllAns_Click(sender As Object, e As EventArgs)


Handles btnDisplayAllAns.Click
ShowAllAns()
End Sub

Private Sub btnResultAnalysisBack_Click(sender As Object, e As


EventArgs) Handles btnResultAnalysisBack.Click
With Student_Result_Form
120
.TopLevel = False

Student_Panel_Form.panelCentre.Controls.Add(Student_Result_Form)
.BringToFront()
.Show()
End With
End Sub
End Class

Student_Start_Exam_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Student_Start_Exam_Form


Dim QNo, MaxQNo, MinQNo, TotalMarks, TotalQues, TempQNo, TempMinQNo,
TempMaxQNo, BtnQNo, TimeDuration As Integer
Dim m As Integer = 0
Dim s As Integer = 0
Dim ml As Integer = 0
Dim EachQuesMarks As Double
Dim MarksCount As Double
Public GivenAns, CorrectAns, ExamSubject, CheckAns, AnsSheetGivenAns,
KnowAnsBeforeUpdate, EmptyAns As String

Private Sub Start_Exam_Form_Load(sender As Object, e As EventArgs)


Handles MyBase.Load
ShowInfo()
TimerExam.Start()
GetTimeDuration()
ShowTimeDuration()
QNo = MinQuesValue()
TempQNo = MinQuesValue()
TempMinQNo = MinQuesValue()
MaxQNo = MaxQuesValue()
TempMaxQNo = MaxQuesValue()
TotalQues = TotalQuesValue()
TotalMarks = TotalMarksValue()
EachQuesMarks = (TotalMarks / TotalQues)
EmptyAns = ""
GivenAns = ""
ShowQuesButtons()
ShowQues()
121
End Sub

Public Sub ShowQuesButtons()


While TempMinQNo <= TempMaxQNo
If TempMinQNo = 1 Then
Button1.Visible = True
ElseIf TempMinQNo = 2 Then
Button2.Visible = True
ElseIf TempMinQNo = 3 Then
Button3.Visible = True
ElseIf TempMinQNo = 4 Then
Button4.Visible = True
ElseIf TempMinQNo = 5 Then
Button5.Visible = True
ElseIf TempMinQNo = 6 Then
Button6.Visible = True
ElseIf TempMinQNo = 7 Then
Button7.Visible = True
ElseIf TempMinQNo = 8 Then
Button8.Visible = True
ElseIf TempMinQNo = 9 Then
Button9.Visible = True
ElseIf TempMinQNo = 10 Then
Button10.Visible = True
ElseIf TempMinQNo = 11 Then
Button11.Visible = True
ElseIf TempMinQNo = 12 Then
Button12.Visible = True
ElseIf TempMinQNo = 13 Then
Button13.Visible = True
ElseIf TempMinQNo = 14 Then
Button14.Visible = True
ElseIf TempMinQNo = 15 Then
Button15.Visible = True
ElseIf TempMinQNo = 16 Then
Button16.Visible = True
ElseIf TempMinQNo = 17 Then
Button17.Visible = True
ElseIf TempMinQNo = 18 Then
Button18.Visible = True
ElseIf TempMinQNo = 19 Then
Button19.Visible = True
ElseIf TempMinQNo = 20 Then
Button20.Visible = True
ElseIf TempMinQNo = 21 Then
Button21.Visible = True
122
ElseIf TempMinQNo = 22 Then
Button22.Visible = True
ElseIf TempMinQNo = 23 Then
Button23.Visible = True
ElseIf TempMinQNo = 24 Then
Button24.Visible = True
ElseIf TempMinQNo = 25 Then
Button25.Visible = True
ElseIf TempMinQNo = 26 Then
Button26.Visible = True
ElseIf TempMinQNo = 27 Then
Button27.Visible = True
ElseIf TempMinQNo = 28 Then
Button28.Visible = True
ElseIf TempMinQNo = 29 Then
Button29.Visible = True
ElseIf TempMinQNo = 30 Then
Button30.Visible = True
End If
TempMinQNo += 1
End While
End Sub

Private Sub GetTimeDuration()


Try
connection_open()
qry = "SELECT * FROM Exam WHERE Class = '" & lblClass.Text &
"' AND Stream = '" & lblStream.Text & "' AND Subject = '" &
lblSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
TimeDuration = dr.Item("TimeDuration")
End If
connection_close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub ShowTimeDuration()


If TimeDuration = 0 Then
lblMin.Text = "0"
lblSec.Text = "0"
ElseIf TimeDuration < 60 And TimeDuration > 0 Then
lblMin.Text = "0"
123
lblSec.Text = TimeDuration.ToString()
ElseIf TimeDuration >= 60 Then
lblMin.Text = (TimeDuration / 60).ToString()
lblSec.Text = "0"
End If
End Sub

Private Sub ShowInfo()


Try
connection_open()
qry = "SELECT * FROM Students
WHERE RegNo = '" & Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
lblRegNo.Text = dr.Item("RegNo").ToString()
lblName.Text = dr.Item("Name").ToString()
lblClass.Text = dr.Item("Class").ToString()
lblStream.Text = dr.Item("Stream").ToString()
'lblSubject.Text = dr.Item("Subject").ToString()
lblSubject.Text = Student_Dashboard_Form.lblSubject1.Text
lblTimer.Text = TimerExam.ToString
End If
connection_close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Function MinQuesValue()


Try
connection_close()
connection_open()
qry = "select min(QuesNo) as MinQNo from Questions where
Subject = '" & lblSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MinQNo")
End Function

Public Function MinAnsValue()


Try
124
connection_close()
connection_open()
qry = "select min(QuesNo) as MinQNo from AnswerSheet where
Subject = '" & lblSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MinQNo")
End Function

Public Function MaxQuesValue()


Try
connection_close()
connection_open()
qry = "select max(QuesNo) as MaxQNo from Questions where
Subject = '" & lblSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MaxQNo")
End Function

Public Function MaxAnsValue()


Try
connection_close()
connection_open()
qry = "select max(QuesNo) as MaxQNo from AnswerSheet where
Subject = '" & lblSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MaxQNo")
End Function

Public Function TotalQuesValue()


Try
connection_close()
125
connection_open()
qry = "select count(QuesNo) as TotalQNo from Questions where
Subject = '" & lblSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("TotalQNo")
End Function

Public Function TotalMarksValue()


Try
connection_close()
connection_open()
qry = "select TotalMarks as TotalMarks from Exam where
Subject = '" & lblSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("TotalMarks")
End Function
Public Sub ShowBtnQues()
Try
connection_close()
connection_open()
qry = "SELECT * FROM Questions WHERE Class = '" &
lblClass.Text & "' AND Stream = '" & lblStream.Text & "' AND Subject = '"
& lblSubject.Text & "' AND QuesNo = '" & BtnQNo & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
txtQuesNo.Text = dr.Item("QuesNo")
txtQuestion.Text = dr.Item("Question").ToString()
rdbtnOptionA.Text = dr.Item("OptionA").ToString()
rdbtnOptionB.Text = dr.Item("OptionB").ToString()
rdbtnOptionC.Text = dr.Item("OptionC").ToString()
rdbtnOptionD.Text = dr.Item("OptionD").ToString()
lblAnswer.Text = dr.Item("Answer").ToString()
CorrectAns = lblAnswer.Text

126
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If BtnQNo = MaxQNo Then
btnExit.BackColor = Color.Green
End If
End Sub

Public Function BtnAnsCheck()


connection_close()
connection_open()
qry = "SELECT * FROM Answersheet
WHERE RegNo = '" & Login_Form.txtUserName.Text & "'
AND Class = '" & lblClass.Text & "'
AND Stream = '" & lblStream.Text & "'
AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & BtnQNo & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
Return True
Else
Return False
End If
End Function

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


Button1.Click
BtnQNo = CInt(Button1.Text)
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button1.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button2.Click
BtnQNo = CInt(Button2.Text)
If BtnAnsCheck() = True Then
127
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button2.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button3.Click
BtnQNo = CInt(Button3.Text)
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button3.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button4.Click
BtnQNo = CInt(Button4.Text)
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button4.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button5.Click
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
128
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button5.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button6.Click
BtnQNo = CInt(Button6.Text)
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button6.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button7.Click
BtnQNo = CInt(Button7.Text)
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button7.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button8.Click
BtnQNo = CInt(Button8.Text)
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
129
rdbtnOptionD.Checked = False
TempQNo = CInt(Button8.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button9.Click
BtnQNo = CInt(Button9.Text)
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button9.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


Button10.Click
BtnQNo = CInt(Button10.Text)
If BtnAnsCheck() = True Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
TempQNo = CInt(Button10.Text)
ShowAns()
Else
ShowBtnQues()
End If
End Sub

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


TimerExam.Tick
If TimeDuration = 0 Then
TimerExam.Stop()
Else
ml += 1
lblTimer.Text = m & " Min " & s & " Sec "
If ml = 100 Then
130
ml = 0
s += 1
lblTimer.Text = m & " : " & s & " : "
If s = TimeDuration Then
TimerExam.Stop()
m = 0
s = 0
ml = 0
lblTimer.Text = m & " : " & s & " : "
SunmitAndExit()
ElseIf s = 60 Then
s = 0
m += 1
lblTimer.Text = m & " : " & s & " : "
If m = TimeDuration / 60 Then
TimerExam.Stop()
m = 0
s = 0
ml = 0
lblTimer.Text = m & " : " & s & " : "
SunmitAndExit()
End If
End If
End If
End If
End Sub
Public Sub ShowQues()
Try
connection_close()
connection_open()
qry = "SELECT * FROM Questions WHERE Class = '" &
lblClass.Text & "' AND Stream = '" & lblStream.Text & "' AND Subject = '"
& lblSubject.Text & "' AND QuesNo = '" & QNo & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
txtQuesNo.Text = dr.Item("QuesNo")
txtQuestion.Text = dr.Item("Question").ToString()
rdbtnOptionA.Text = dr.Item("OptionA").ToString()
rdbtnOptionB.Text = dr.Item("OptionB").ToString()
rdbtnOptionC.Text = dr.Item("OptionC").ToString()
rdbtnOptionD.Text = dr.Item("OptionD").ToString()
lblAnswer.Text = dr.Item("Answer").ToString()
CorrectAns = lblAnswer.Text

131
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If QNo = MaxQNo Then
btnExit.BackColor = Color.Green
End If
End Sub

Public Function CheckRadioBtn()


If rdbtnOptionA.Checked = True Or rdbtnOptionB.Checked = True Or
rdbtnOptionC.Checked = True Or rdbtnOptionD.Checked = True Then
Return True
Else
Return False
End If
End Function

Public Sub ColorQuesButton()


If TempQNo = 1 Then
If CheckRadioBtn() = True Then
Button1.BackColor = Color.LimeGreen
Button1.ForeColor = Color.White
Else
Button1.BackColor = Color.Red
Button1.ForeColor = Color.White
End If
ElseIf TempQNo = 2 Then
If CheckRadioBtn() = True Then
Button2.BackColor = Color.LimeGreen
Button2.ForeColor = Color.White
Else
Button2.BackColor = Color.Red
Button2.ForeColor = Color.White
End If
ElseIf TempQNo = 3 Then
If CheckRadioBtn() = True Then
Button3.BackColor = Color.LimeGreen
Button3.ForeColor = Color.White
Else
Button3.BackColor = Color.Red
Button3.ForeColor = Color.White
End If
ElseIf TempQNo = 4 Then
If CheckRadioBtn() = True Then
Button4.BackColor = Color.LimeGreen
132
Button4.ForeColor = Color.White
Else
Button4.BackColor = Color.Red
Button4.ForeColor = Color.White
End If
ElseIf TempQNo = 5 Then
If CheckRadioBtn() = True Then
Button5.BackColor = Color.LimeGreen
Button5.ForeColor = Color.White
Else
Button5.BackColor = Color.Red
Button5.ForeColor = Color.White
End If
ElseIf TempQNo = 6 Then
If CheckRadioBtn() = True Then
Button6.BackColor = Color.LimeGreen
Button6.ForeColor = Color.White
Else
Button6.BackColor = Color.Red
Button6.ForeColor = Color.White
End If
ElseIf TempQNo = 7 Then
If CheckRadioBtn() = True Then
Button7.BackColor = Color.LimeGreen
Button7.ForeColor = Color.White
Else
Button7.BackColor = Color.Red
Button7.ForeColor = Color.White
End If
ElseIf TempQNo = 8 Then
If CheckRadioBtn() = True Then
Button8.BackColor = Color.LimeGreen
Button8.ForeColor = Color.White
Else
Button8.BackColor = Color.Red
Button8.ForeColor = Color.White
End If
ElseIf TempQNo = 9 Then
If CheckRadioBtn() = True Then
Button9.BackColor = Color.LimeGreen
Button9.ForeColor = Color.White
Else
Button9.BackColor = Color.Red
Button9.ForeColor = Color.White
End If
ElseIf TempQNo = 10 Then
133
If CheckRadioBtn() = True Then
Button10.BackColor = Color.LimeGreen
Button10.ForeColor = Color.White
Else
Button10.BackColor = Color.Red
Button10.ForeColor = Color.White
End If
End If
End Sub

Public Sub ShowAns()


Try
connection_close()
connection_open()
qry = "SELECT * FROM Answersheet
WHERE RegNo = '" & Login_Form.txtUserName.Text & "'
AND Class = '" & lblClass.Text & "'
AND Stream = '" & lblStream.Text & "'
AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & TempQNo & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
txtQuesNo.Text = dr.Item("QuesNo")
txtQuestion.Text = dr.Item("Question").ToString()
rdbtnOptionA.Text = dr.Item("OptionA").ToString()
rdbtnOptionB.Text = dr.Item("OptionB").ToString()
rdbtnOptionC.Text = dr.Item("OptionC").ToString()
rdbtnOptionD.Text = dr.Item("OptionD").ToString()
'CheckAns = dr.Item("Answer")
GivenAns = dr.Item("GivenAnswer")
If GivenAns = "Option (A)" Then
rdbtnOptionA.Checked = True
ElseIf GivenAns = "Option (B)" Then
rdbtnOptionB.Checked = True
ElseIf GivenAns = "Option (C)" Then
rdbtnOptionC.Checked = True
ElseIf GivenAns = "Option (D)" Then
rdbtnOptionD.Checked = True
End If
CheckAns = "ok"
Else
CheckAns = "not ok"
End If
Catch ex As Exception
MsgBox(ex.Message)
134
End Try

End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles
btnNext.Click
If (CheckAns = "ok" And TempQNo < (QNo - 1)) Then
UpdateAns()
Else
Save_Answer()
End If
If QNo < MaxQNo Then
rdbtnOptionA.Checked = False
rdbtnOptionB.Checked = False
rdbtnOptionC.Checked = False
rdbtnOptionD.Checked = False
GivenAns = ""
If (CheckAns = "ok" And TempQNo < (QNo - 1)) Then
CheckAns = "not ok"
TempQNo += 1
ShowAns()
Else
TempQNo += 1
QNo = TempQNo
ShowQues()
CheckAns = "right"
End If
End If
End Sub

Public Sub CalculateMarks()


MinQNo = MinAnsValue()
MaxQNo = MaxAnsValue()
While MinQNo <= MaxQNo
CorrectAns = ""
GivenAns = ""
Try
connection_close()
connection_open()
qry = "SELECT * FROM Answersheet WHERE RegNo = '" &
Login_Form.txtUserName.Text & "' AND Class = '" & lblClass.Text & "' AND
Stream = '" & lblStream.Text & "' AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & MinQNo & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader

135
If dr.Read Then
CorrectAns = dr.Item("Answer")
GivenAns = dr.Item("GivenAnswer")
If GivenAns = CorrectAns Then
MarksCount += EachQuesMarks
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
MsgBox("Error inside Calculate Marks.")
End Try
MinQNo += 1
End While
End Sub

Public Sub Save_Marks()


Save_Answer()
CalculateMarks()
connection_close()
'Checking Duplicacy Before Inserting Data
qry = "SELECT * FROM Result WHERE RegNo = '" & lblRegNo.Text & "'
AND Class = '" & lblClass.Text & "' AND Stream = '" & lblStream.Text & "'
AND Subject = '" & lblSubject.Text & "'"
connection_open()
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
connection_close()
Else
'Inserting Data
qry = "INSERT INTO Result ( RegNo, Class, Stream, Subject,
TotalQues, TotalMarks, MarksObtain) VALUES ('" & lblRegNo.Text & "', '" &
lblClass.Text & "', '" & lblStream.Text & "', '" & lblSubject.Text & "',
'" & TotalQues & "', '" & TotalMarks & "', '" & MarksCount & "')"
connection_open()
qry1 = "SELECT * FROM Result WHERE RegNo = '" & lblRegNo.Text
& "' AND Class = '" & lblClass.Text & "' AND Stream = '" & lblStream.Text
& "' AND Subject = '" & lblSubject.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = False Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
End If
connection_close()
136
End If
End Sub

Public Sub Save_Answer()


'Checking Duplicacy Before Inserting Data
connection_close()
connection_open()
qry = "SELECT * FROM AnswerSheet WHERE RegNo = '" &
Login_Form.txtUserName.Text & "' AND Class = '" & lblClass.Text & "' AND
Stream = '" & lblStream.Text & "' AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & txtQuesNo.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then

Else
'Inserting Data
connection_close()
connection_open()
qry = "INSERT INTO AnswerSheet (RegNo, Class, Stream,
Subject, QuesNo, Question, OptionA, OptionB, OptionC, OptionD, Answer,
GivenAnswer)
VALUES ('" & lblRegNo.Text & "', '" & lblClass.Text & "',
'" & lblStream.Text & "', '" & lblSubject.Text & "', '" & txtQuesNo.Text
& "', '" & txtQuestion.Text & "', '" & rdbtnOptionA.Text & "', '" &
rdbtnOptionB.Text & "', '" & rdbtnOptionC.Text & "', '" &
rdbtnOptionD.Text & "', '" & lblAnswer.Text & "', '" & GivenAns & "')"
qry1 = "SELECT * FROM AnswerSheet WHERE RegNo = '" &
Login_Form.txtUserName.Text & "' AND Class = '" & lblClass.Text & "' AND
Stream = '" & lblStream.Text & "' AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & txtQuesNo.Text & "'"
cmd1 = New SqlCommand(qry1, cnn)
dr = cmd1.ExecuteReader
If dr.Read() = False Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
End If
End If
ColorQuesButton()
GivenAns = ""
connection_close()
End Sub

Public Sub UpdateAns()


'Checking Duplicacy Before Updating Data
137
connection_close()
connection_open()
qry = "SELECT * FROM AnswerSheet WHERE RegNo = '" &
Login_Form.txtUserName.Text & "' AND Class = '" & lblClass.Text & "' AND
Stream = '" & lblStream.Text & "' AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & txtQuesNo.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read() Then
KnowAnsBeforeUpdate = dr.Item("Answer").ToString()
End If

connection_close()
connection_open()
qry = "SELECT * FROM AnswerSheet WHERE RegNo = '" &
Login_Form.txtUserName.Text & "' AND Class = '" & lblClass.Text & "' AND
Stream = '" & lblStream.Text & "' AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & txtQuesNo.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = False Then

Else
'Updating Data
connection_close()
connection_open()
qry1 = "SELECT * FROM AnswerSheet WHERE RegNo = '" &
Login_Form.txtUserName.Text & "' AND Class = '" & lblClass.Text & "' AND
Stream = '" & lblStream.Text & "' AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & txtQuesNo.Text & "'"
qry = "UPDATE AnswerSheet
SET RegNo = '" & Login_Form.txtUserName.Text & "'
, QuesNo = '" & txtQuesNo.Text & "'
, Class = '" & lblClass.Text & "'
, Stream = '" & lblStream.Text & "'
, Subject = '" & lblSubject.Text & "'
, Question = '" & txtQuestion.Text & "'
, OptionA = '" & rdbtnOptionA.Text & "'
, OptionB = '" & rdbtnOptionB.Text & "'
, OptionC = '" & rdbtnOptionC.Text & "'
, OptionD = '" & rdbtnOptionD.Text & "'
, Answer = '" & KnowAnsBeforeUpdate & "'
, GivenAnswer = '" & GivenAns & "'
WHERE RegNo = '" & Login_Form.txtUserName.Text & "'
AND Class = '" & lblClass.Text & "'
AND Stream = '" & lblStream.Text & "'
138
AND Subject = '" & lblSubject.Text & "'
AND QuesNo = '" & txtQuesNo.Text & "'"

cmd1 = New SqlCommand(qry1, cnn)


dr = cmd1.ExecuteReader
If dr.Read() = True Then
cmd = New SqlCommand(qry, cnn)
dr.Close()
cmd.ExecuteNonQuery()
connection_close()
End If
End If
ColorQuesButton()
End Sub

Private Sub rdbtnOptionA_CheckedChanged(sender As Object, e As


EventArgs) Handles rdbtnOptionA.CheckedChanged
GivenAns = "Option (A)"
If QNo = MaxQNo Then
btnExit.BackColor = Color.Green
End If
End Sub

Private Sub rdbtnOptionB_CheckedChanged(sender As Object, e As


EventArgs) Handles rdbtnOptionB.CheckedChanged
GivenAns = "Option (B)"
If QNo = MaxQNo Then
btnExit.BackColor = Color.Green
End If
End Sub

Private Sub rdbtnOptionC_CheckedChanged(sender As Object, e As


EventArgs) Handles rdbtnOptionC.CheckedChanged
GivenAns = "Option (C)"
If QNo = MaxQNo Then
btnExit.BackColor = Color.Green
End If
End Sub

Public Sub SunmitAndExit()


UpdateAns()
Save_Marks()
Me.Close()
With Student_Result_Form
.TopLevel = False

139
Student_Panel_Form.panelCentre.Controls.Add(Student_Result_Form)
.BringToFront()
.Show()
End With
End Sub

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


btnExit.Click
SunmitAndExit()
End Sub

Private Sub rdbtnOptionD_CheckedChanged(sender As Object, e As


EventArgs) Handles rdbtnOptionD.CheckedChanged
GivenAns = "Option (D)"
If QNo = MaxQNo Then
btnExit.BackColor = Color.Green
End If
End Sub
End Class

Teacher_Dashboard_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class Teacher_Dashboard_Form

Public Sub ShowDashboardInfo()


Try
connection_close()
connection_open()
qry = "SELECT * FROM Teachers
WHERE StaffId = '" & Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read Then
lblTeacherId.Text = dr.Item("StaffId").ToString()
lblName.Text = dr.Item("Name").ToString()
Else
MsgBox("Record Not Found. Try Again!")
End If
Catch ex As Exception
140
MsgBox(ex.Message)
End Try
End Sub

Private Sub Teacher_Dashboard_Form_Load(sender As Object, e As


EventArgs) Handles MyBase.Load
ShowDashboardInfo()
End Sub
End Class

Teacher_Panel_Form.vb
Imports System.Data.SqlClient
Imports System.Data
Public Class Teacher_Panel_Form
Dim Gender, Picture As String

Private Sub btnTeResult_Click(sender As Object, e As EventArgs)


Handles btnTeResult.Click
With View_Result_Form
.TopLevel = False
panelCentre.Controls.Add(View_Result_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnTeAnsSheet_Click(sender As Object, e As EventArgs)


Handles btnTeAnsSheet.Click
With Answer_Sheet_Form
.TopLevel = False
panelCentre.Controls.Add(Answer_Sheet_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnTeLogOut_Click(sender As Object, e As EventArgs)


Handles btnTeLogOut.Click
Me.Dispose()
End Sub

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

Try
If cnn.State = 1 Then cnn.Close()
connection_open()
qry = "SELECT * FROM Teachers
WHERE StaffId = '" & Login_Form.txtUserName.Text & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read = True Then
Gender = dr.Item("Gender").ToString
Picture = dr.Item("Picture").ToString
picTeacher.Image =
Image.FromFile(dr.Item("Picture").ToString)
End If
Catch ex As Exception

End Try
With Teacher_Dashboard_Form
.TopLevel = False
panelCentre.Controls.Add(Teacher_Dashboard_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnTeQuestion_Click(sender As Object, e As EventArgs)


Handles btnTeQuestion.Click
With Manage_Question_Form
.TopLevel = False
panelCentre.Controls.Add(Manage_Question_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnTeDashboard_Click(sender As Object, e As EventArgs)


Handles btnTeDashboard.Click
Teacher_Dashboard_Form.Refresh()

With Teacher_Dashboard_Form
142
.TopLevel = False
panelCentre.Controls.Add(Teacher_Dashboard_Form)
.BringToFront()
.Show()
End With
End Sub

Private Sub btnAdSettings_Click(sender As Object, e As EventArgs)


Handles btnAdSettings.Click
With Setting_Form
.TopLevel = False
panelCentre.Controls.Add(Setting_Form)
.BringToFront()
.Show()
End With
End Sub

End Class

View_Result_Form.vb
Imports System.Data.SqlClient
Imports System.Data

Public Class View_Result_Form


Dim RegNo, MaxRegNo, MinRegNo As Integer
Dim TotalMarks, MarksObtain As Integer
Dim Percentage As Double
Dim Attempt, Skipped, Correct, Wrong As Integer

Public Function MaxRegNoValue()


connection_close()
connection_open()
qry = "SELECT MAX(RegNo) AS MaxRegNo FROM Result
WHERE Class = '" & cmbViewResultClass.Text & "'
AND Stream = '" & cmbViewResultCourse.Text & "'
AND Subject = '" & cmbViewResultSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Return dr.Item("MaxRegNo")
End Function

143
Public Function MinRegNoValue()
connection_close()
connection_open()
qry = "SELECT MIN(RegNo) AS MinRegNo FROM Result
WHERE Class = '" & cmbViewResultClass.Text & "'
AND Stream = '" & cmbViewResultCourse.Text & "'
AND Subject = '" & cmbViewResultSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Return dr.Item("MinRegNo")
End Function

Public Sub StudentImageNameShow()


Try
connection_close()
connection_open()
qry = "SELECT * FROM Students
WHERE RegNo = '" & RegNo & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
pictureStudent.Image =
Image.FromFile(dr.Item("Picture").ToString)
lblViewResultName.Text = dr.Item("Name").ToString
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Function MinAnsValue()


Try
connection_close()
connection_open()
qry = "select min(QuesNo) as MinQNo from AnswerSheet
where RegNo = '" & txtViewResultRegNo.Text & "'
and Subject = '" & cmbViewResultSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
144
End Try
Return dr.Item("MinQNo")
End Function

Public Function MaxAnsValue()


Try
connection_close()
connection_open()
qry = "select max(QuesNo) as MaxQNo from AnswerSheet
where RegNo = '" & txtViewResultRegNo.Text & "'
and Subject = '" & cmbViewResultSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("MaxQNo")
End Function

Public Function CountCorrectAns()


Try
connection_close()
connection_open()
qry = "select count(QuesNo) as Correct from AnswerSheet
where RegNo = '" & txtViewResultRegNo.Text & "'
and Subject = '" & cmbViewResultSubject.Text & "'
and Answer = GivenAnswer"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("Correct")
End Function

Public Function CountWrongAns()


Try
connection_close()
connection_open()
qry = "select count(QuesNo) as Wrong from AnswerSheet
where RegNo = '" & txtViewResultRegNo.Text & "'
and Subject = '" & cmbViewResultSubject.Text & "'
and Answer <> GivenAnswer"
cmd = New SqlCommand(qry, cnn)
145
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("Wrong")
End Function

Private Sub btnViewResultPrevious_Click(sender As Object, e As


EventArgs) Handles btnViewResultPrevious.Click
If RegNo <= MinRegNo Then

Else
RegNo -= 1
End If
txtViewResultRegNo.Text = RegNo
CheckStudent()
End Sub

Private Sub btnViewResultNext_Click(sender As Object, e As EventArgs)


Handles btnViewResultNext.Click
If RegNo >= MaxRegNo Then

Else
RegNo += 1
End If
txtViewResultRegNo.Text = RegNo
CheckStudent()
End Sub

Private Sub btnClearAll_Click(sender As Object, e As EventArgs)


Handles btnClearAll.Click
txtViewResultRegNo.Clear()
cmbViewResultClass.Text = ""
cmbViewResultCourse.Text = ""
cmbViewResultSubject.Text = ""
pnlResult.Visible = False
lblResultNotFound.Visible = False
End Sub

Public Function CountSkippedQues()


Try
connection_close()
connection_open()
qry = "select count(QuesNo) as Skipped from AnswerSheet
where RegNo = '" & txtViewResultRegNo.Text & "'
146
and Subject = '" & cmbViewResultSubject.Text & "'
and GivenAnswer = ''"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("Skipped")
End Function

Public Function CountAttemptedQues()


Try
connection_close()
connection_open()
qry = "select count(QuesNo) as Attempt from AnswerSheet
where RegNo = '" & txtViewResultRegNo.Text & "'
and Subject = '" & cmbViewResultSubject.Text & "'
and GivenAnswer <> ''"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
dr.Read()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return dr.Item("Attempt")
End Function

Public Sub CalculateResult()


Percentage = (TotalMarks * MarksObtain) / 100
lblPercentage.Text = Percentage & " % "

Correct = CountCorrectAns()
Wrong = CountWrongAns()
Skipped = CountSkippedQues()
Attempt = CountAttemptedQues()

lblCorrectAns.Text = Correct.ToString
lblWrongAns.Text = Wrong.ToString
lblQuesSkipped.Text = Skipped.ToString
lblQuesAttempted.Text = Attempt.ToString
End Sub
Public Sub ShowResult()
Try

147
connection_close()
connection_open()
qry = "SELECT * FROM Result
WHERE RegNo = '" & RegNo & "'
AND Class = '" & cmbViewResultClass.Text & "'
AND Stream = '" & cmbViewResultCourse.Text & "'
AND Subject = '" & cmbViewResultSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
'lblViewResultRegNo.Text = dr.GetString(1).ToString()
'RegNo = dr.Item("RegNo")

lblViewResultClass.Text = dr.GetString(2).ToString()
lblViewResultStream.Text = dr.GetString(3).ToString()
lblViewResultSubject.Text = dr.GetString(4).ToString()
lblViewResultTotalQues.Text =
dr.Item("TotalQues").ToString()

lblViewResultTotalMarks.Text =
dr.Item("TotalMarks").ToString()
TotalMarks = dr.Item("TotalMarks")

lblViewResultMarksScore.Text =
dr.Item("MarksObtain").ToString()
MarksObtain = dr.Item("MarksObtain")

StudentImageNameShow()

CalculateResult()
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub CheckStudent()


connection_close()
connection_open()
Try
qry = "SELECT * FROM Result
WHERE RegNo = '" & RegNo & "'
AND Class = '" & cmbViewResultClass.Text & "'
148
AND Stream = '" & cmbViewResultCourse.Text & "'
AND Subject = '" & cmbViewResultSubject.Text & "'"
cmd = New SqlCommand(qry, cnn)
dr = cmd.ExecuteReader
If dr.Read = True Then
lblResultNotFound.Visible = False
pnlResult.Visible = True
MaxRegNo = MaxRegNoValue()
MinRegNo = MinRegNoValue()
RegNo = txtViewResultRegNo.Text
ShowResult()
Else
pnlResult.Visible = False
lblResultNotFound.Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

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


btnSearch.Click
Try
If cmbViewResultClass.Text = "" Or cmbViewResultCourse.Text =
"" Or cmbViewResultSubject.Text = "" Or txtViewResultRegNo.Text = "" Then
MsgBox("Please Enter Search Detail",
MsgBoxStyle.Critical)
Else
RegNo = txtViewResultRegNo.Text
CheckStudent()
End If
Catch ex As Exception
MsgBox("Invalid Inputs.", MsgBoxStyle.Critical)
End Try
End Sub

End Class

149
Limitations of the project:-

• Machine dependent.

• Need to install Visual basic 2019, SQL server 2019, Microsoft SQL
Server management studio 2018 for running this software.

Future scope of the project:-

• In the future student can also be able to upload and download report.

• Mail acknowledgement receipt to the student after fee payment.

• We can run the entire system in any operating system and also we have an
android application of this entire system.

• We will also see the entire system more interactive and also be able to give
statistics data.

150

You might also like