Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 71 lines (57 sloc) 3.028 kb
159371f @issyl0 Add the VB COMP4 coursework code, for the fun of it.
authored
1 Imports System.Data
2 Imports System.Data.OleDb
3
4 Public Class frmAddSupplier
5 Public accConnection As New OleDbConnection
6
7 Private Sub frmAddSupplier_Load(ByVal sender As System.Object, _
8 ByVal e As System.EventArgs) Handles MyBase.Load
9 If frmLoginForm.accConnection.State <> ConnectionState.Open Then
10 frmLoginForm.accConnection.Open()
11 End If
12 End Sub
13
14 Private Sub btnSave_Click(ByVal sender As System.Object, _
15 ByVal e As System.EventArgs) Handles btnSave.Click
16
17 Dim cmdString As String = "INSERT INTO Supplier (supp_name, supp_address, supp_postcode, " _
18 & "supp_telno, supp_contactname)" _
19 & "VALUES (@supp_name,@supp_address,@supp_postcode," _
20 & "@supp_telno,@supp_contactname)"
21
22 Dim AddSupplierDataAdapter As New OleDbDataAdapter
23 Dim accCommand As New OleDbCommand
24 Dim intInsert As Integer
25
26 accCommand.Connection = frmLoginForm.accConnection
27 accCommand.CommandType = CommandType.Text
28 accCommand.CommandText = cmdString
29 Call InsertParameters(accCommand)
30 'Now check if all the textboxes are populated.
31 Try
32 intInsert = accCommand.ExecuteNonQuery()
33 Catch ex As Exception
34 intInsert = 0
35 MsgBox("Enter a value in each of the boxes, and make it a valid one!")
36 End Try
37
38 Call frmSwankyCode.CheckAdditions(intInsert, btnSave)
39
40 End Sub
41
42 Private Sub InsertParameters(ByRef acccmd As OleDbCommand)
43 acccmd.Parameters.Add("@supp_name", OleDbType.Char).Value = txtSupplierName.Text
44 acccmd.Parameters.Add("@supp_address", OleDbType.Char).Value = txtSupplierAddress.Text
45 acccmd.Parameters.Add("@supp_postcode", OleDbType.Char).Value = txtSupplierPostCode.Text
46 acccmd.Parameters.Add("@supp_telno", OleDbType.Char).Value = mtxtSupplierTelNo.Text
47 acccmd.Parameters.Add("@supp_contactname", OleDbType.Char).Value = txtSupplierContactName.Text
48
49 End Sub
50
51 Private Sub btnCancel_Click(ByVal sender As System.Object, _
52 ByVal e As System.EventArgs) Handles btnCancel.Click
53
54 If btnSave.Enabled = False Then
55 'It's all fine and has gone through OK, so don't display a
56 'message because that would just be annoying, just close this
57 'and display the previous form.
58 Me.Close()
59 frmAdd.Show()
60 Else
61 'If it hasn't gone through OK, or nothing has been added,
62 'then let the user know this so as not to panic them;
63 'if the user did not mean to click the button, he/she knows.
64 MsgBox("This window will close and these details will not be saved.")
65 Me.Close()
66 frmAdd.Show()
67 End If
68
69 End Sub
70
71 End Class
Something went wrong with that request. Please try again.