document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. Imports System.Data.OleDb
  2. Public Class Form4
  3.     Public cn As New OleDb.OleDbConnection
  4.     Public cmd As New OleDb.OleDbCommand
  5.     Public da As OleDbDataAdapter
  6.     Public dr As OleDbDataReader
  7.     Public ds As DataSet = New DataSet
  8.     Public sql As String = Nothing
  9.     Public ConString As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Settings.AppDB)
  10.     \'//---------------------------------------------------------------------------------------//\'
  11.     Public Sub myCn()
  12.         If cn.State = ConnectionState.Open Then cn.Close()
  13.         cn.ConnectionString = ConString
  14.         cn.Open()
  15.     End Sub
  16.     \'//---------------------------------------------------------------------------------------//\'
  17.     Private Sub Form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  18.         \'TODO: This line of code loads data into the \'AddEditDeleteLogInDataSet.tblLoginHistory\' table. You can move, or remove it, as needed.
  19.         Me.tblLoginHistoryTableAdapter.Fill(Me.AddEditDeleteLogInDataSet.tblLoginHistory)
  20.        
  21.         myCn()
  22.         LoadLname()
  23.         ListViewLog()
  24.     End Sub
  25.     \'//---------------------------------------------------------------------------------------//\'
  26.     Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click
  27.         If TextBox3.Text = "" Or TextBox4.Text = "" Then Exit Sub
  28.         Dim xSQL As New System.Text.StringBuilder
  29.         xSQL.AppendLine("SELECT Uname,Pword")
  30.         xSQL.AppendLine("FROM tblAdmin WHERE")
  31.         xSQL.AppendLine("Uname=@name AND")
  32.         xSQL.AppendLine("Pword=@word")
  33.         Try
  34.             Using cn As New OleDbConnection(ConString)
  35.                 cn.Open()
  36.                 Dim cmd As New OleDbCommand(xSQL.ToString, cn)
  37.                 cmd.Parameters.AddWithValue("@name", TextBox3.Text)
  38.                 cmd.Parameters.AddWithValue("@word", TextBox4.Text)
  39.                 dr = cmd.ExecuteReader
  40.                 If dr.HasRows Then
  41.                     MsgBox("Sucessful!", MsgBoxStyle.Information)
  42.                     LogHistory()
  43.                     TextBox3.Text = ""
  44.                     TextBox4.Text = ""
  45.                     ListViewLog()
  46.                     LoadLname()
  47.                 Else
  48.                     MsgBox("Invalid Username or Password!", MsgBoxStyle.Exclamation)
  49.                 End If
  50.                 dr.Close()
  51.             End Using
  52.         Catch ex As Exception
  53.             MessageBox.Show("ERROR:" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  54.         End Try
  55.     End Sub
  56.     \'//---------------------------------------------------------------------------------------//\'
  57.     Private Function LoadLname()
  58.         Try
  59.             Using cn As OleDbConnection = New OleDbConnection(ConString)
  60.                 Dim xSQL As New System.Text.StringBuilder
  61.                 xSQL.AppendLine("SELECT * FROM tblLoginHistory")
  62.                 xSQL.AppendLine("ORDER BY")
  63.                 xSQL.AppendLine("ID DESC")
  64.  
  65.  
  66.                 Dim cmd As New OleDbCommand(xSQL.ToString, cn)
  67.                 Dim da As New OleDbDataAdapter
  68.                 da.SelectCommand = cmd
  69.                 ds = New DataSet
  70.                 da.Fill(ds, "Uname")
  71.  
  72.  
  73.                 Dim LastName As New AutoCompleteStringCollection
  74.                 Dim i As Integer
  75.                 For i = 0 To ds.Tables(0).Rows.Count - 1
  76.                     LastName.Add(ds.Tables(0).Rows(i)("Uname").ToString())
  77.                 Next
  78.                 TextBox3.AutoCompleteSource = AutoCompleteSource.CustomSource
  79.                 TextBox3.AutoCompleteCustomSource = LastName
  80.                 TextBox3.AutoCompleteMode = AutoCompleteMode.Suggest
  81.             End Using
  82.         Catch ex As Exception
  83.             MessageBox.Show("ERROR:" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  84.         End Try
  85.         Return ds
  86.     End Function
  87.     \'//---------------------------------------------------------------------------------------//\'
  88.     Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
  89.         If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
  90.             TextBox4.Text = ""
  91.             e.Handled = False
  92.         End If
  93.     End Sub
  94.     \'//---------------------------------------------------------------------------------------//\'
  95.     Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  96.         Try
  97.             Dim xSQL As New System.Text.StringBuilder
  98.             xSQL.AppendLine("SELECT Uname,Pword")
  99.             xSQL.AppendLine("FROM tblLoginHistory")
  100.             xSQL.AppendLine("WHERE Uname = \'" & TextBox3.Text.Trim & "\' ")
  101.             Using cn As New OleDbConnection(ConString)
  102.                 cn.Open()
  103.                 Dim cmd As New OleDb.OleDbCommand(xSQL.ToString, cn)
  104.                 dr = cmd.ExecuteReader
  105.                 If dr.HasRows = True Then
  106.                     While dr.Read()
  107.                         TextBox4.Text = (dr("Pword").ToString)
  108.                     End While
  109.                 End If
  110.                 cmd.Dispose()
  111.                 \'dr.Close()
  112.             End Using
  113.         Catch ex As Exception
  114.             MessageBox.Show("ERROR:" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  115.         End Try
  116.     End Sub
  117.     \'//---------------------------------------------------------------------------------------//\'
  118.     Private Function LogHistory()
  119.         Try
  120.             Dim xSQL As New System.Text.StringBuilder
  121.             xSQL.AppendLine("INSERT INTO tblLoginHistory")
  122.             xSQL.AppendLine("(Uname,Pword,Dtoday)")
  123.             xSQL.AppendLine("VALUES")
  124.             xSQL.AppendLine("(@name,@word,@today)")
  125.             Using cn As New OleDbConnection(ConString)
  126.                 cn.Open()
  127.                 Dim cmd As New OleDbCommand(xSQL.ToString, cn)
  128.                 cmd.Parameters.AddWithValue("@name", TextBox3.Text)
  129.                 cmd.Parameters.AddWithValue("@word", TextBox4.Text)
  130.                 cmd.Parameters.AddWithValue("@date", DateTimePicker1.Text.Trim)
  131.                 cmd.ExecuteNonQuery()
  132.                 ListViewLog()
  133.             End Using
  134.             Return True
  135.         Catch ex As Exception
  136.             MessageBox.Show("ERROR:" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  137.             Return False
  138.         End Try
  139.     End Function
  140.     \'//---------------------------------------------------------------------------------------//\'
  141.     Private Function ListViewLog()
  142.         Try
  143.             ListView2.Items.Clear()
  144.             Dim xSQL As New System.Text.StringBuilder
  145.             xSQL.AppendLine("SELECT ID,Uname,Pword,Dtoday")
  146.             xSQL.AppendLine("FROM tblLoginHistory")
  147.             xSQL.AppendLine("ORDER BY ID")
  148.  
  149.  
  150.             Using cn As New OleDbConnection(ConString)
  151.                 cn.Open()
  152.                 Dim cmd As New OleDb.OleDbCommand(xSQL.ToString, cn)
  153.                 dr = cmd.ExecuteReader
  154.                 While dr.Read
  155.                     Dim lv1 As New ListViewItem(dr.Item("ID").ToString.Trim)
  156.                     lv1.SubItems.Add(dr.Item("Uname").ToString.Trim)
  157.                     lv1.SubItems.Add(dr.Item("Pword").ToString.Trim)
  158.                     lv1.SubItems.Add(dr.Item("Dtoday").ToString.Trim)
  159.                     lv1.SubItems.Add("------------")
  160.                     ListView2.Items.Add(lv1)
  161.                 End While
  162.             End Using
  163.             cmd.Dispose()
  164.             dr.Close()
  165.             Return True
  166.         Catch ex As Exception
  167.             MessageBox.Show("ERROR:" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  168.             Return False
  169.         End Try
  170.     End Function
  171.     \'//---------------------------------------------------------------------------------------//\'
  172.     Private Sub btnLogHistory_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogHistory.Click
  173.         Me.ReportViewer2.RefreshReport()
  174.     End Sub
  175. End Class
');