Você está na página 1de 10

Code for Login

Imports System.Data.SqlClient
Imports System.String
Imports System.Windows.Forms
Imports System.Data
Public Class Login
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles OK.Click
Dim con As New SqlConnection("Data Source=LAAB1;Initial Catalog=LMS;Integrated
Security=True")
Dim cmd As SqlCommand
cmd = New SqlCommand("SELECT * FROM Login WHERE UseName = '" &
UsernameTextBox.Text & "' AND Password = '" & PasswordTextBox.Text & "' ", con)
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
' 'If the record can be queried or found, Pass verification and open another form.
If (sdr.Read() = True) Then
Dim Library As New Main_Form
Library.Show()
Me.Hide()
Else
MsgBox("Invalid username or password:Try Again!!", MsgBoxStyle.OkCancel,
"Message :")
End If
Me.Hide()

End Sub

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


Handles Cancel.Click
Me.Close()
End Sub
End Class
Code for report

Imports CrystalDecisions.CrystalReports.Engine
Public Class repor
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnShow.Click
Dim cryRpt As New ReportDocument
cryRpt.Load("C:\Documents and Settings\user\My Documents\Visual Studio
2008\Projects\HRS\HRS\Hrs_report.rpt")
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
End Class
Code for datagridview

Imports System.Data.SqlClient
Public Class view
Dim connectionString As String = "Data Source=LAAB1;Initial Catalog=MAN;Integrated
Security=True"
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim sql As String
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dv As DataView
'Dim Drd As SqlDataReader

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


Handles bntview.Click
sql = "Select * from hrs"
cnn = New SqlConnection(connectionString)
Try
cnn.Open()
cmd = New SqlCommand(sql, cnn)
adapter.SelectCommand = cmd
adapter.Fill(ds, "Create DataView")
adapter.Dispose()
cmd.Dispose()
cnn.Close()
dv = ds.Tables(0).DefaultView
DataGridView1.DataSource = dv
Catch ex As Exception
MsgBox(" Can not open coonection")
End Try
End Sub
End Class
Code for different operations and navigations

Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports System.Data
Public Class HRS
Dim connectionString As String = "Data Source=LAAB1;Initial Catalog=MAN;Integrated
Security=True" 'Declare and setup the Connection string
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim sql As String
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dv As DataView
Dim Drd As SqlDataReader 'Declaring the DataReader object
Dim Dst = New DataSet
Dim CurrentRow As Integer
Dim dt As New DataTable
Dim check As Integer
Private Sub ShowData(ByVal CurrentRow)
Try
TextBox1.Text = Dst.Tables("hrs").Rows(CurrentRow)("ID")
TextBox2.Text = Dst.Tables("hrs").Rows(CurrentRow)("Fname")
TextBox3.Text = Dst.Tables("hrs").Rows(CurrentRow)("Gender")
TextBox4.Text = Dst.Tables("hrs").Rows(CurrentRow)("Address")
Catch ex As Exception
End Try
End Sub
Private Sub HRS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
cnn = New SqlConnection(connectionString)
CurrentRow = 0
cnn.Open()
adapter = New SqlDataAdapter("SELECT * FROM hrs ORDER BY ID", cnn)
adapter.Fill(Dst, "hrs")
ShowData(CurrentRow)
cnn.Close()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnAdd.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = ""
Then
MsgBox("The record is not completed", MsgBoxStyle.OkOnly)
Else
If MsgBox("Are you sure to save the record with ID : " & TextBox1.Text & " ?",
MsgBoxStyle.OkCancel, "Input confirm") = MsgBoxResult.Cancel Then
' do nothing
Else
Try
cnn.Open()
cmd = cnn.CreateCommand
cmd.CommandText = "SELECT * FROM hrs WHERE ID='" & TextBox1.Text & " '
"
adapter.SelectCommand = cmd
adapter.Fill(ds, "hrs")
dt = ds.Tables("hrs")
If (dt.Rows.Count > 0) Then
MsgBox("The ID " & TextBox1.Text & " is already in database",
MsgBoxStyle.OkOnly, "Message :")
Else
cmd = cnn.CreateCommand
cmd.CommandText = "INSERT INTO hrs(ID, Fname, Gender,Address)
VALUES('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" &
TextBox4.Text & "')"
check = cmd.ExecuteReader.RecordsAffected()
If check > 0 Then
MsgBox("The record With ID " & TextBox1.Text & " succesfully added",
MsgBoxStyle.OkOnly, "Message :")
Else
MsgBox("The record ID " & TextBox1.Text & " Failure to added",
MsgBoxStyle.OkOnly, "Message :")
End If
cnn.Close()
End If
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly,
"Connection Error !!")
End Try
End If
End If
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnClose.Click
cnn.Close()
Me.Close()
End Sub
Private Sub btnDelate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnDelate.Click
If TextBox1.Text <> "" Then
If MsgBox("Are you sure to delete the record with ID : " & TextBox1.Text & " ?",
MsgBoxStyle.OkCancel, "Delete confirm") = MsgBoxResult.Cancel Then
' do nothing
Else
Try
cnn.Open()
cmd = cnn.CreateCommand
cmd.CommandText = "DELETE FROM hrs WHERE ID ='" & TextBox1.Text & "'"
check = cmd.ExecuteReader.RecordsAffected
If check > 0 Then
MsgBox("The record with ID " & TextBox1.Text & " Succesfully Deleted",
MsgBoxStyle.OkOnly, "Info Delete Student")
Else
MsgBox("The record with ID " & TextBox1.Text & " Failure To Delete",
MsgBoxStyle.OkOnly, "Info Delete Student")
End If
cnn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly,
"Connection Error !!")
End Try
End If
Else
MsgBox("Fill ID of the record on ID textbox which record to delete!!",
MsgBoxStyle.OkOnly, "Info Data")
End If
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnUpdate.Click
If TextBox1.Text = "" Then
MessageBox.Show("Please fill all data!!", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Else
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text =
"" Then
MsgBox("hrs Data is not completed", MsgBoxStyle.OkOnly)
Else
If MsgBox("Are you sure to edit hrs data with ID : " & TextBox1.Text & " ?",
MsgBoxStyle.OkCancel, "Edit confirm") = MsgBoxResult.Cancel Then
' do nothing
Else
Try
cnn.Open()
cmd = cnn.CreateCommand
cmd.CommandText = "UPDATE hrs SET Fname ='" & TextBox2.Text & "', Sex=
'" & TextBox3.Text & "' , Address='" & TextBox4.Text & "' WHERE ID ='" & TextBox1.Text &
"'"
check = cmd.ExecuteReader.RecordsAffected
If check > 0 Then
MsgBox("hrs With ID " & TextBox1.Text & " Succesfully Edited",
MsgBoxStyle.OkOnly, "Info Update Data hrs ")
Else
MsgBox("hrs With ID " & TextBox1.Text & " Failure To Edit",
MsgBoxStyle.OkOnly, "Info Update Data hrs ")
End If
cnn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly,
"Connection Error !!")
End Try
End If
End If
End If

End Sub
Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnView.Click
sql = "Select * from hrs"
cnn = New SqlConnection(connectionString)
Try
cnn.Open()
cmd = New SqlCommand(sql, cnn)
adapter.SelectCommand = cmd
adapter.Fill(Dst, "Create DataView")
adapter.Dispose()
cmd.Dispose()
cnn.Close()
dv = Dst.Tables(0).DefaultView
DataGridView1.DataSource = dv
Catch ex As Exception
MsgBox(" Can not open coonection")
End Try
view.Show()
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnSearch.Click
sql = "SELECT * FROM hrs where ID='" & TextBox1.Text & "'" 'Declare and build a
query string
cnn = New SqlConnection(connectionString) 'Instantiate the connection object
cmd = New SqlCommand(sql, cnn) 'Instantiate the command object
cnn.Open()
Drd = cmd.ExecuteReader 'Creating a DataReader object by using the ExecuteReader()
method of the Command object.
If TextBox1.Text = "" Then
MsgBox("Please enter the ID to search!!")
Else
If (Drd.Read = True) Then
TextBox1.Text = Drd(0)
TextBox2.Text = Drd(1)
TextBox3.Text = Drd(2)
TextBox4.Text = Drd(3)
Else
MsgBox("There is no record by the give ID!")
End If
End If
End Sub

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


Handles btnFirst.Click
CurrentRow = 0
ShowData(CurrentRow)
End Sub

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


Handles btnNext.Click
If CurrentRow = Dst.Tables("hrs").Rows.Count - 1 Then
MsgBox("Last Record is Reached!!!")
Else
CurrentRow = CurrentRow + 1
ShowData(CurrentRow)
End If
End Sub

Private Sub btnPrrevious_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnPrrevious.Click
If CurrentRow <> 0 Then
CurrentRow = CurrentRow - 1
ShowData(CurrentRow)
Else
MsgBox("First Record is Reached!!!")
End If
End Sub

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


Handles btnLast.Click
CurrentRow = Dst.Tables("hrs").Rows.Count - 1
ShowData(CurrentRow)
End Sub

End Class

Você também pode gostar