Advertisement
Guest User

Untitled

a guest
May 11th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 11.38 KB | None | 0 0
  1. Public Class Form1
  2.     Dim KeyAscii As Integer
  3.     'Public CustomerID As String
  4.     Dim LogAd As Integer = 0
  5.  
  6.     Function Checkbox_false()
  7.         chbAdmin.Checked = False
  8.     End Function
  9.  
  10.  
  11.  
  12.     'If txtUser.Text = "AdHughes" And txtPass.Text = "A1b2C3" Then
  13.     '    'txtUser.Text = "Admin"
  14.     '    'txtPass.Text = "Password"
  15.     '    'MsgBox(txtUser.Text)    'showing the value in the text box under admin
  16.     '    'MsgBox(txtPass.Text)
  17.     '    LogAd = 1
  18.     '    CustomerID = txtUser.Text
  19.     '    Database_cus()
  20.     '    Database_cus1()
  21.     '    'LogAd = 0
  22.     '    'Form2.Show()
  23.     '    'Me.Hide()
  24.     'Else
  25.     '    txtUser.Text = ""
  26.     '    txtPass.Text = ""
  27.     'End If
  28.  
  29.  
  30.  
  31.  
  32.     Function Login_check()
  33.         'Do Until txtUser.Text = "" And txtPass.Text = ""
  34.         If txtUser.Text <> "" And txtPass.Text = "" Then    'checking if the password is missing by seeing if the value is = nothing
  35.             MsgBox("Your details are incorrect!",
  36.                            MsgBoxStyle.Exclamation)
  37.         ElseIf txtUser.Text = "" And txtPass.Text <> "" Then    'checking if the username is missing by seeing if the value is = nothing
  38.             MsgBox("You are missing a Username",
  39.                            MsgBoxStyle.Exclamation)
  40.             'Return False
  41.         ElseIf txtUser.Text = "" And txtPass.Text = "" Then
  42.             MsgBox("You are missing all details",
  43.                            MsgBoxStyle.Exclamation)
  44.         End If
  45.             'Loop
  46.     End Function
  47.  
  48.     Function Database_cus()                                                                                                                  'Database check 1
  49.  
  50.         If LogAd = 0 Then
  51.             If txtUser.Text = "AdHughes" Then
  52.                 txtUser.Text = ""               'When the program starts all of the data is reset and the fields are cleared_
  53.                 txtPass.Text = ""                   'this is more so nessasary when the user logs out of the system so that_
  54.                 chbAdmin.Checked = False                'all data is cleared for security
  55.             End If
  56.         End If
  57.  
  58.         Dim con As New OleDb.OleDbConnection
  59.         Dim dbProvider As String
  60.         Dim dbSource As String
  61.         Dim ds As New DataSet
  62.         Dim da As OleDb.OleDbDataAdapter
  63.         Dim sql As String
  64.         Dim recordCount As Integer
  65.         Dim userID As String
  66.         Dim password As String
  67.  
  68.         userID = txtUser.Text
  69.         password = txtPass.Text
  70.         'User = txtUser.Text    'makes the username disapear when enter is clicked
  71.         dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
  72.         ' dbSource = "Data Source = E:\PrototypeofProduct\Prototype of Product\bin\Debug\LoginDatabase.mdb"     'creating a link to the database tables to check the username and password records
  73.         '    dbSource = "Data Source = .\LoginDatabase.mdb"     'creating a link to the database tables to check the username and password records
  74.         con.ConnectionString = dbProvider & PublicVariables.ConnString
  75.  
  76.  
  77.         con.Open()
  78.  
  79.  
  80.         sql = "SELECT * FROM CustomerID WHERE CustomerID = '" & userID & "' AND CustomerPassword = '" & password & "'"      'using the database to then select the necessary fields to read_
  81.         da = New OleDb.OleDbDataAdapter(sql, con)                                                                                ' from to check the username to password
  82.         da.Fill(ds, "CustomerID")
  83.         recordCount = ds.Tables("CustomerID").Rows.Count
  84.  
  85.         Login_check()       'calling a previous function
  86.  
  87.  
  88.         If recordCount = 0 Then
  89.             con.Close()
  90.             Return False
  91.         Else
  92.             con.Close()
  93.             Return True
  94.         End If
  95.  
  96.         If CustomerID = 0 Then
  97.             'MsgBox("memes")
  98.         End If
  99.     End Function
  100.  
  101.     Function Database_cus1()                                                                                                                        'Database check 2
  102.  
  103.         '    If LogAd = 0 Then
  104.         '        If txtUser.Text = "Admin" Then
  105.         '            txtUser.Text = ""               'When the program starts all of the data is reset and the fields are cleared_
  106.         '            txtPass.Text = ""                   'this is more so nessasary when the user logs out of the system so that_
  107.         '            chbAdmin.Checked = False                'all data is cleared for security
  108.         '        End If
  109.         '    End If
  110.  
  111.         '    Dim con As New OleDb.OleDbConnection
  112.         '    Dim dbProvider As String
  113.         '    Dim dbSource As String
  114.         '    Dim ds As New DataSet
  115.         '    Dim da As OleDb.OleDbDataAdapter
  116.         '    Dim sql As String
  117.         '    Dim recordCount As Integer
  118.         '    Dim userID As String
  119.         '    Dim password As String
  120.  
  121.         '    userID = txtUser.Text
  122.         '    password = txtPass.Text
  123.         '    'User = txtUser.Text    'makes the username disapear when enter is clicked
  124.         '    dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
  125.         '    dbSource = "Data Source = E:\PrototypeofProduct\Prototype of Product\bin\Debug\LoginDatabase.mdb"     'creating a link to the database tables to check the username and password records
  126.         '    con.ConnectionString = dbProvider & dbSource
  127.  
  128.         '    con.Open()
  129.  
  130.         '    sql = "SELECT * FROM EmailID WHERE EmployeeID = '" & userID & "' AND Employee_Pass = '" & password & "'"      'using the database to then select the necessary fields to read_
  131.         '    da = New OleDb.OleDbDataAdapter(sql, con)                                                                                ' from to check the username to password
  132.         '    da.Fill(ds, "CustomerID")
  133.         '    recordCount = ds.Tables("CustomerID").Rows.Count
  134.  
  135.         '    Login_check()       'calling a previous function
  136.  
  137.         '    If recordCount = 0 Then
  138.         '        con.Close()
  139.         '        Return False
  140.         '    Else
  141.         '        con.Close()
  142.         '        Return True
  143.         '    End If
  144.  
  145.     End Function
  146.  
  147.     Public Sub Button1_Click(sender As Object, e As EventArgs) Handles btnLog.Click
  148.         MsgBox("Login  details are incorrect!")
  149.         If txtUser.Text = "AdHughes" And txtPass.Text = "A1b2C3" Then
  150.             Login_check()
  151.             'txtUser.Text = "Admin"
  152.             'txtPass.Text = "Password"
  153.             'MsgBox(txtUser.Text)    'showing the value in the text box under admin
  154.             'MsgBox(txtPass.Text)
  155.             LogAd = 1
  156.             CustomerID = txtUser.Text
  157.             Database_cus()
  158.             'LogAd = 0
  159.             'Form2.Show()
  160.             'Me.Hide()
  161.             'Else
  162.             '    txtUser.Text = ""
  163.             '    txtPass.Text = ""
  164.         End If
  165.  
  166.  
  167.  
  168.         Login_check()
  169.         If Database_cus() = True Then   'using a function to make the code shorter and reusable via recalling it
  170.  
  171.             'Login_check()
  172.  
  173.             CustomerID = txtUser.Text   'v-- design aspect that allows me to check that the system has read the entered detail correctly
  174.             'MsgBox(CustomerID)      'checking that the value has been entered into the variable
  175.             txtPass.Clear()     'need to clear the text boxes to make sure that no data over rides the current user
  176.             txtUser.Clear()
  177.             Me.Hide()           'closing the 'login' form_  'note; This system was bad due to it just hiding the old form so now__
  178.             Checkbox_false()
  179.             Form2.Show()        'to then open the second form       'it is closed to allow for more efficient running of the program
  180.             'Me.Close()
  181.  
  182.  
  183.         ElseIf Logad = 1 Then   'making use of the variable in two instances to ensure that the program doesnt just open the second form on activation of the first  use of the variable_
  184.             'ElseIf Database_cus1() = True Then
  185.  
  186.             CustomerID = txtUser.Text   'v-- design aspect that allows me to check that the system has read the entered detail correctly
  187.             'MsgBox(CustomerID)      'checking that the value has been entered into the variable
  188.             txtPass.Clear()     'need to clear the text boxes to make sure that no data over rides the current user
  189.             txtUser.Clear()
  190.             Me.Hide()           'closing the 'login' form_  'note; This system was bad due to it just hiding the old form so now__
  191.             Checkbox_false()
  192.             Form2.Show()        'to then open the second form       'it is closed to allow for more efficient running of the program
  193.             'Me.Close()
  194.  
  195.  
  196.             'If txtUser.Text = "Admin" And txtPass.Text = "Password" Then  'the 'login' button must be pressed to load the next form, before the activation of the 'admin' check box loaded_
  197.             '    Me.Hide()                                                   'the Next form automatically
  198.             '    Form2.Show()
  199.             'End If
  200.         End If
  201.     End Sub
  202.  
  203.     Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles btnClose1.Click
  204.         Dim message = MsgBox("Are you sure?", MsgBoxStyle.YesNo)
  205.         If message = MsgBoxResult.Yes = True Then
  206.             Me.Close()
  207.         End If
  208.     End Sub
  209.  
  210.     Private Sub EnterClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
  211.         If e.KeyCode.Equals(Keys.Enter) Then
  212.         End If
  213.     End Sub
  214.  
  215.  
  216.     Private Sub txtPass_KeyPress(KeyCode As Integer, Shift As Integer)      'my attempt at trying to make the enter key being pressed click a certain button to allow for a faster login attempt
  217.         'If KeyAscii = 13 Then      
  218.         '    btnLog.Focus()
  219.         'End If
  220.     End Sub
  221.  
  222.     Private Sub txtPass_KeyDown(sender As Object, e As KeyEventArgs) Handles txtPass.KeyDown    '//
  223.         If e.KeyCode = Keys.Enter Then
  224.             Database_cus()
  225.             'Database_cus1()
  226.         End If
  227.     End Sub
  228.  
  229.     Private Sub txtUser_KeyDown(sender As Object, e As KeyEventArgs) Handles txtUser.KeyDown    '//
  230.         If e.KeyCode = Keys.Enter Then
  231.             Database_cus()
  232.             'Database_cus1()
  233.         End If
  234.     End Sub
  235.  
  236.     Private Sub chbAdmin_CheckedChanged(sender As Object, e As EventArgs) Handles chbAdmin.CheckedChanged
  237.         'If chbAdmin.Checked = True Then
  238.         '    txtUser.Text = "Admin"
  239.         '    txtPass.Text = "Password"
  240.         '    'MsgBox(txtUser.Text)    'showing the value in the text box under admin
  241.         '    'MsgBox(txtPass.Text)
  242.         '    LogAd = 1
  243.         '    CustomerID = txtUser.Text
  244.         '    Database_cus()
  245.         '    Database_cus1()
  246.         '    'LogAd = 0
  247.         '    'Form2.Show()
  248.         '    'Me.Hide()
  249.         'Else
  250.         '    txtUser.Text = ""
  251.         '    txtPass.Text = ""
  252.         'End If
  253.  
  254.         If chbAdmin.Checked = True Then
  255.             txtUser.Text = "AdHughes"
  256.             txtPass.Text = "A1b2C3"
  257.         Else
  258.             txtUser.Text = ""
  259.             txtPass.Text = ""
  260.         End If
  261.  
  262.  
  263.     End Sub
  264.  
  265.     Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
  266.         If CheckBox1.Checked = True Then
  267.             txtUser.Text = "Jhughes"
  268.             txtPass.Text = "12345"
  269.         Else
  270.             txtUser.Text = ""
  271.             txtPass.Text = ""
  272.         End If
  273.     End Sub
  274.  
  275.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  276.         'chbAdmin.Checked = False
  277.         CheckBox1.Hide()
  278.     End Sub
  279.  
  280. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement