daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Apr 27th, 2016 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Runtime.InteropServices
  2. Imports MySql.Data.MySqlClient
  3. Public Class Fault
  4.     Dim MySqlConn As MySqlConnection
  5.     Dim myCommand As MySqlCommand
  6.     Dim myAdapter As MySqlDataAdapter
  7.     Dim myData As DataTable
  8.     Dim SQL As String
  9.     Dim connectionString = "server=localhost; userid=root; database=database;"
  10.  
  11.     Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
  12.         MySqlConn = New MySqlConnection()
  13.  
  14.         MySqlConn.ConnectionString = connectionString
  15.  
  16.         Try
  17.             MySqlConn.Open()
  18.             MessageBox.Show("Connected to database!")
  19.         Catch ex As Exception
  20.             MsgBox(ex.ToString())
  21.         End Try
  22.     End Sub
  23.  
  24.     Private Sub btnReturnAll_Click(sender As Object, e As EventArgs) Handles btnReturnAll.Click
  25.         myAdapter = New MySqlDataAdapter
  26.         myCommand = New MySqlCommand
  27.         myData = New DataTable
  28.  
  29.         SQL = "Select * FROM database.fault"
  30.  
  31.         myCommand.Connection = MySqlConn
  32.         myCommand.CommandText = SQL
  33.  
  34.         myAdapter.SelectCommand = myCommand
  35.         myAdapter.Fill(myData)
  36.  
  37.         mainDataGrid.DataSource = myData
  38.     End Sub
  39.  
  40.     Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
  41.         Dim SQL As String = "INSERT INTO database.fault (FaultID, TechnicianID, ComponentID, FaultDesc, DateLogged, FaultUrgency, Resolution, CompletionDate) Values (?,?,?,?,?,?,?,?)"
  42.  
  43.         MySqlConn = New MySqlConnection()
  44.         MySqlConn.ConnectionString() = connectionString
  45.         MySqlConn.Open()
  46.  
  47.         myCommand = New MySqlCommand()
  48.  
  49.         myCommand.CommandText = SQL
  50.         myCommand.Parameters.AddWithValue("FaultID", txtFaultID.Text)
  51.         myCommand.Parameters.AddWithValue("TechnicianID", txtTechID.Text)
  52.         myCommand.Parameters.AddWithValue("ComponentID", txtCompID.Text)
  53.         myCommand.Parameters.AddWithValue("FaultDesc", txtfaultDesc.Text)
  54.         myCommand.Parameters.AddWithValue("DateLogged", txtDateLogged.Text)
  55.         myCommand.Parameters.AddWithValue("FaultUrgency", txtFaultUrgency.Text)
  56.         myCommand.Parameters.AddWithValue("Resolution", txtResolution.Text)
  57.         myCommand.Parameters.AddWithValue("CompletionDate", TxtCompDate.Text)
  58.  
  59.         myCommand.Connection = MySqlConn
  60.  
  61.         If txtFaultID.Text = Nothing Then
  62.             MessageBox.Show("Error... A field was not correclty filled in!")
  63.         End If
  64.  
  65.         If txtTechID.Text = Nothing Then
  66.             MessageBox.Show("Error... A field was not correclty filled in!")
  67.         End If
  68.  
  69.         If txtCompID.Text = Nothing Then
  70.             MessageBox.Show("Error... A field was not correclty filled in!")
  71.         End If
  72.  
  73.         If txtfaultDesc.Text = Nothing Then
  74.             MessageBox.Show("Error... A field was not correclty filled in!")
  75.         End If
  76.  
  77.         If txtDateLogged.Text = Nothing Then
  78.             MessageBox.Show("Error... A field was not correclty filled in!")
  79.         Else
  80.             myCommand.ExecuteNonQuery()
  81.         End If
  82.  
  83.         If txtFaultUrgency.Text = Nothing Then
  84.             MessageBox.Show("Error... A field was not correclty filled in!")
  85.         End If
  86.  
  87.         If txtResolution.Text = Nothing Then
  88.             MessageBox.Show("Error... A field was not correclty filled in!")
  89.         End If
  90.  
  91.         If TxtCompDate.Text = Nothing Then
  92.             MessageBox.Show("Error... A field was not correclty filled in!")
  93.         End If
  94.  
  95.     End Sub
  96.  
  97.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  98.         txtFaultID.Clear()
  99.         txtTechID.Clear()
  100.         txtCompID.Clear()
  101.         txtfaultDesc.Clear()
  102.         txtDateLogged.Clear()
  103.         txtFaultUrgency.Clear()
  104.         txtResolution.Clear()
  105.         TxtCompDate.Clear()
  106.     End Sub
  107.     <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
  108.     Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer,
  109.                                         ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
  110.     End Function
  111.  
  112.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  113.  
  114.         SendMessage(Me.txtFaultID.Handle, &H1501, 0, "ID of Fault")
  115.         SendMessage(Me.txtTechID.Handle, &H1501, 0, "Technicians ID Number")
  116.         SendMessage(Me.txtCompID.Handle, &H1501, 0, "Components ID Number")
  117.         SendMessage(Me.txtfaultDesc.Handle, &H1501, 0, "Description of Fault")
  118.         SendMessage(Me.txtDateLogged.Handle, &H1501, 0, "Date of log (DD/MM/YYYY")
  119.         SendMessage(Me.txtFaultUrgency.Handle, &H1501, 0, "Urgency? High, low etc")
  120.         SendMessage(Me.txtResolution.Handle, &H1501, 0, "Resolved? How?")
  121.         SendMessage(Me.TxtCompDate.Handle, &H1501, 0, "DD/MM/YYYY")
  122.     End Sub
  123.  
  124.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  125.         mainDataGrid.DataSource = Nothing
  126.         mainDataGrid.Rows.Clear()
  127.         MySqlConn.Close()
  128.         MessageBox.Show("You have been disconnected from the database")
  129.     End Sub
  130.  
  131.  
  132.  
  133.     Private Sub TechnicianToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles TechnicianToolStripMenuItem1.Click
  134.         Me.Hide()
  135.         Technician.Show()
  136.     End Sub
  137.  
  138.     Private Sub RetrieveTechnicianIDToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RetrieveTechnicianIDToolStripMenuItem.Click
  139.         myAdapter = New MySqlDataAdapter
  140.         myCommand = New MySqlCommand
  141.         myData = New DataTable
  142.  
  143.         SQL = "Select technicianid FROM database.technician"
  144.  
  145.         myCommand.Connection = MySqlConn
  146.         myCommand.CommandText = SQL
  147.  
  148.         myAdapter.SelectCommand = myCommand
  149.         myAdapter.Fill(myData)
  150.  
  151.         mainDataGrid.DataSource = myData
  152.     End Sub
  153.  
  154.     Private Sub RetrieveAllWithFaultPriorityHighToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RetrieveAllWithFaultPriorityHighToolStripMenuItem.Click
  155.         myAdapter = New MySqlDataAdapter
  156.         myCommand = New MySqlCommand
  157.         myData = New DataTable
  158.  
  159.         SQL = "SELECT Technician.TechnicianID, Fault.FaultUrgency FROM Technician, Fault WHERE FaultUrgency='high'"
  160.  
  161.         myCommand.Connection = MySqlConn
  162.         myCommand.CommandText = SQL
  163.  
  164.         myAdapter.SelectCommand = myCommand
  165.         myAdapter.Fill(myData)
  166.  
  167.         mainDataGrid.DataSource = myData
  168.     End Sub
  169.  
  170.     Private Sub MultipleTableQuery1ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MultipleTableQuery1ToolStripMenuItem.Click
  171.         myAdapter = New MySqlDataAdapter
  172.         myCommand = New MySqlCommand
  173.         myData = New DataTable
  174.  
  175.         SQL = "SELECT Component.ComponentID, Fault.DateLogged FROM Component, Fault"
  176.  
  177.         myCommand.Connection = MySqlConn
  178.         myCommand.CommandText = SQL
  179.  
  180.         myAdapter.SelectCommand = myCommand
  181.         myAdapter.Fill(myData)
  182.  
  183.         mainDataGrid.DataSource = myData
  184.     End Sub
  185.  
  186.     Private Sub MultipleTableQuery2ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MultipleTableQuery2ToolStripMenuItem.Click
  187.         myAdapter = New MySqlDataAdapter
  188.         myCommand = New MySqlCommand
  189.         myData = New DataTable
  190.  
  191.         SQL = "SELECT Technician.TechnicianEmail, Fault.FaultDesc, Fault.Resolution FROM Technician, Fault"
  192.  
  193.         myCommand.Connection = MySqlConn
  194.         myCommand.CommandText = SQL
  195.  
  196.         myAdapter.SelectCommand = myCommand
  197.         myAdapter.Fill(myData)
  198.  
  199.         mainDataGrid.DataSource = myData
  200.     End Sub
  201. End Class
  202. Public Class Login
  203.     Dim MySqlConn As MySqlConnection
  204.     Dim myCommand As MySqlCommand
  205.     Dim myAdapter As MySqlDataAdapter
  206.     Dim myData As DataTable
  207.     Dim connectionString = "server=localhost; userid=root; database=database;"
  208.     <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
  209.     Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer,
  210.                                         ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
  211.     End Function
  212.  
  213.     Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  214.  
  215.  
  216.         Dim IPAddress As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
  217.         Label2.Text = "" & IPAddress.AddressList(0).ToString()
  218.         Label1.Text = Date.Now
  219.  
  220.         MySqlConn = New MySqlConnection()
  221.  
  222.         MySqlConn.ConnectionString = connectionString
  223.  
  224.         Try
  225.             MySqlConn.Open()
  226.         Catch ex As Exception
  227.             MsgBox(ex.ToString())
  228.         End Try
  229.  
  230.         SendMessage(Me.TextBox1.Handle, &H1501, 0, "Username")
  231.         SendMessage(Me.TextBox2.Handle, &H1501, 0, "Password")
  232.     End Sub
  233.  
  234.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  235.         MySqlConn = New MySqlConnection()
  236.         MySqlConn.ConnectionString = connectionString
  237.         Dim Reader As MySqlDataReader
  238.  
  239.  
  240.         Dim LogData As String = "INSERT INTO database.log (username, ipaddress, date) Values (?,?,?)"
  241.         MySqlConn.Open()
  242.         myCommand = New MySqlCommand()
  243.  
  244.         myCommand.CommandText = LogData
  245.         myCommand.Parameters.AddWithValue("username", TextBox1.Text)
  246.         myCommand.Parameters.AddWithValue("ipaddress", Label2.Text)
  247.         myCommand.Parameters.AddWithValue("date", Label1.Text)
  248.         myCommand.Connection = MySqlConn
  249.         myCommand.ExecuteNonQuery()
  250.  
  251.  
  252.         Try
  253.             Dim Query As String
  254.             Query = "select * from database.logins where username='" & TextBox1.Text & " ' and password ='" & TextBox2.Text & "'"
  255.             myCommand = New MySqlCommand(Query, MySqlConn)
  256.             Reader = myCommand.ExecuteReader
  257.  
  258.             Dim Count As Integer
  259.             Count = 0
  260.             While Reader.Read
  261.                 Count = Count + 1
  262.             End While
  263.  
  264.             If Count = 1 Then
  265.                 MessageBox.Show("Connection Successful")
  266.                 Me.Hide()
  267.                 Fault.Show()
  268.             ElseIf Count > 1 Then
  269.                 MessageBox.Show("Connection is duplicated")
  270.             Else
  271.                 MessageBox.Show("Connection unsuccessful")
  272.  
  273.             End If
  274.  
  275.             MySqlConn.Close()
  276.  
  277.         Catch ex As Exception
  278.             MsgBox(ex.ToString())
  279.         Finally
  280.             MySqlConn.Dispose()
  281.         End Try
  282.     End Sub
  283. End Class
  284. Imports System.Runtime.InteropServices
  285. Imports MySql.Data.MySqlClient
  286. Public Class Technician
  287.     Dim MySqlConn As MySqlConnection
  288.     Dim myCommand As MySqlCommand
  289.     Dim myAdapter As MySqlDataAdapter
  290.     Dim myData As DataTable
  291.     Dim SQL As String
  292.     Dim connectionString = "server=localhost; userid=root; database=database;"
  293.     Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
  294.         MySqlConn = New MySqlConnection()
  295.  
  296.         MySqlConn.ConnectionString = connectionString
  297.  
  298.         Try
  299.             MySqlConn.Open()
  300.             MessageBox.Show("Connected to database!")
  301.         Catch ex As Exception
  302.             MsgBox(ex.ToString())
  303.         End Try
  304.     End Sub
  305.     Private Sub btnReturnAll_Click(sender As Object, e As EventArgs) Handles btnReturnAll.Click
  306.         myAdapter = New MySqlDataAdapter
  307.         myCommand = New MySqlCommand
  308.         myData = New DataTable
  309.  
  310.         SQL = "Select * FROM database.technician"
  311.  
  312.         myCommand.Connection = MySqlConn
  313.         myCommand.CommandText = SQL
  314.  
  315.         myAdapter.SelectCommand = myCommand
  316.         myAdapter.Fill(myData)
  317.  
  318.         mainDataGrid.DataSource = myData
  319.     End Sub
  320.     Private Sub btnDisconnect_Click(sender As Object, e As EventArgs) Handles btnDisconnect.Click
  321.         mainDataGrid.DataSource = Nothing
  322.         mainDataGrid.Rows.Clear()
  323.         MySqlConn.Close()
  324.         MessageBox.Show("You have been disconnected from the database")
  325.     End Sub
  326.  
  327.     Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
  328.         Dim SQL As String = "INSERT INTO database.technician (TechnicianID, TechnicianFirstName, TechnicianLastName, TechnicianTel, TechnicianEmail) Values (?,?,?,?,?)"
  329.  
  330.         MySqlConn = New MySqlConnection()
  331.         MySqlConn.ConnectionString() = connectionString
  332.         MySqlConn.Open()
  333.  
  334.         myCommand = New MySqlCommand()
  335.  
  336.         myCommand.CommandText = SQL
  337.         myCommand.Parameters.AddWithValue("TechnicianID", txtTechID.Text)
  338.         myCommand.Parameters.AddWithValue("TechnicianFirstName", txtTechFirstName.Text)
  339.         myCommand.Parameters.AddWithValue("TechnicianLastName", txtTechLastName.Text)
  340.         myCommand.Parameters.AddWithValue("TechnicianTel", txtTechTel.Text)
  341.         myCommand.Parameters.AddWithValue("TechnicianEmail", txtTechEmail.Text)
  342.  
  343.         myCommand.Connection = MySqlConn
  344.  
  345.         If txtTechID.Text = Nothing Then
  346.             MessageBox.Show("Error... A field was not correclty filled in!")
  347.         Else
  348.             myCommand.ExecuteNonQuery()
  349.         End If
  350.  
  351.         If txtTechFirstName.Text = Nothing Then
  352.             MessageBox.Show("Error... A field was not correclty filled in!")
  353.         End If
  354.  
  355.         If txtTechLastName.Text = Nothing Then
  356.             MessageBox.Show("Error... A field was not correclty filled in!")
  357.         End If
  358.  
  359.         If txtTechTel.Text = Nothing Then
  360.             MessageBox.Show("Error... A field was not correclty filled in!")
  361.         End If
  362.  
  363.         If txtTechEmail.Text = Nothing Then
  364.             MessageBox.Show("Error... A field was not correclty filled in!")
  365.         End If
  366.     End Sub
  367.  
  368.     Private Sub btnClearFields_Click(sender As Object, e As EventArgs) Handles btnClearFields.Click
  369.         txtTechID.Clear()
  370.         txtTechFirstName.Clear()
  371.         txtTechLastName.Clear()
  372.         txtTechTel.Clear()
  373.         txtTechEmail.Clear()
  374.     End Sub
  375.  
  376.  
  377.     Private Sub FaultToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FaultToolStripMenuItem.Click
  378.         Me.Hide()
  379.         Fault.Show()
  380.     End Sub
  381.  
  382.  
  383.     Private Sub RetrieveTechnicianIDToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RetrieveTechnicianIDToolStripMenuItem.Click
  384.         myAdapter = New MySqlDataAdapter
  385.         myCommand = New MySqlCommand
  386.         myData = New DataTable
  387.  
  388.         SQL = "Select technicianid FROM database.technician"
  389.  
  390.         myCommand.Connection = MySqlConn
  391.         myCommand.CommandText = SQL
  392.  
  393.         myAdapter.SelectCommand = myCommand
  394.         myAdapter.Fill(myData)
  395.  
  396.         mainDataGrid.DataSource = myData
  397.     End Sub
  398. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top