Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 163 lines (128 sloc) 7.036 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 frmListFullDetails
5 Public accConnection As New OleDbConnection
6
7 Private Sub frmListFullDetails_Load(ByVal sender As System.Object, _
8 ByVal e As System.EventArgs) Handles MyBase.Load
9
10 If frmLoginForm.accConnection.State <> ConnectionState.Open Then
11 frmLoginForm.accConnection.Open()
12 End If
13
14 If frmList.cbtxtListOptions.SelectedItem = "Customers" Then
15 Call PopulateCustInfo()
16 ElseIf frmList.cbtxtListOptions.SelectedItem = "Suppliers" Then
17 Call PopulateSuppInfo()
18 ElseIf frmList.cbtxtListOptions.SelectedItem = "Components" Then
19 Call PopulateCompInfo()
20 End If
21 End Sub
22
23 Private Sub PopulateCustInfo()
24
25 accConnection = frmLoginForm.accConnection
26 'Input customer name from the other form and attribute it to CTN.
27 Dim ctn As String = frmList.lbList.SelectedItem 'Customer name.
28 Dim cmdString As String = "SELECT * FROM Customer WHERE cust_name = '" & ctn & "'"
29 Dim accCommand As New OleDbCommand
30 Dim da As New OleDbDataAdapter(cmdString, accConnection)
31 Dim ds As New DataSet
32
33 da.Fill(ds, "Customer")
34
35 Dim dt As DataTable = ds.Tables(0)
36 'Dim dr As DataRow <- This is redundant - it does not do anything.
37
38 'Populate the textboxes in the form with existing customer details.
39 'All the customer data text boxes are read-only to avoid data error:
40 'to edit those, edit the customer details directly, then come back.
41
42 'Populate the customer name textbox with the customer name
43 'from the other form, before getting info from db about others.
44
45 'An example of my variable naming here:
46 'The variable 'txtldcn' = textbox listdetails custname.
47 txtldctn.Text = ctn
48 If ds.Tables(0).Rows.Count <> 0 Then
49 cbldctt.Text = ds.Tables(0).Rows(0).Item("cust_title")
50 txtldctba.Text = ds.Tables(0).Rows(0).Item("cust_billaddress")
51 txtldctbp.Text = ds.Tables(0).Rows(0).Item("cust_billpostcode")
52 txtldctia.Text = ds.Tables(0).Rows(0).Item("cust_instaddress")
53 txtldctip.Text = ds.Tables(0).Rows(0).Item("cust_instpostcode")
54 txtldcthtn.Text = ds.Tables(0).Rows(0).Item("cust_hometelno")
55 txtldctmtn.Text = ds.Tables(0).Rows(0).Item("cust_mobtelno")
56 txtldctea.Text = ds.Tables(0).Rows(0).Item("cust_email")
57 txtldctmpan.Text = ds.Tables(0).Rows(0).Item("cust_mpan")
58 End If
59
60 accCommand.Connection = frmLoginForm.accConnection
61 accCommand.CommandType = CommandType.Text
62 accCommand.CommandText = cmdString
63 End Sub
64
65 Private Sub PopulateSuppInfo()
66
67 accConnection = frmLoginForm.accConnection
68 'Input supplier name from the other form and attribute it to SPN.
69 Dim spn As String = frmList.lbList.SelectedItem 'Supplier name.
70 Dim cmdString As String = "SELECT * FROM Supplier WHERE supp_name = '" & spn & "'"
71 Dim accCommand As New OleDbCommand
72 Dim da As New OleDbDataAdapter(cmdString, accConnection)
73 Dim ds As New DataSet
74
75 da.Fill(ds, "Supplier")
76
77 Dim dt As DataTable = ds.Tables(0)
78 'Dim dr As DataRow <- This is redundant - it does not do anything.
79
80 'Populate the textboxes in the form with existing supplier details.
81 'All the supplier data text boxes are read-only to avoid data error:
82 'to edit those, edit the supplier details directly, then come back.
83
84 'Populate the supplier name textbox with the customer name
85 'from the other form, before getting info from db about others.
86
87 'An example of my variable naming here:
88 'The variable 'txtldspn' = textbox listdetails suppname.
89 txtldspn.Text = spn
90 If ds.Tables(0).Rows.Count <> 0 Then
91 txtldspa.Text = ds.Tables(0).Rows(0).Item("supp_address")
92 txtldspp.Text = ds.Tables(0).Rows(0).Item("supp_postcode")
93 txtldsptn.Text = ds.Tables(0).Rows(0).Item("supp_telno")
94 txtldspc.Text = ds.Tables(0).Rows(0).Item("supp_contactname")
95 End If
96
97 accCommand.Connection = frmLoginForm.accConnection
98 accCommand.CommandType = CommandType.Text
99 accCommand.CommandText = cmdString
100
101 End Sub
102
103 Private Sub PopulateCompInfo()
104
105 accConnection = frmLoginForm.accConnection
106 'Input component name from the other form and attribute it to CPN.
107 Dim cpn As String = frmList.lbList.SelectedItem 'Component name.
108 Dim cmdString As String = "SELECT * FROM Component WHERE comp_name = '" & cpn & "'"
109
110 Dim accCommand As New OleDbCommand
111 Dim da As New OleDbDataAdapter(cmdString, accConnection)
112 Dim ds As New DataSet
113
114 da.Fill(ds, "Component")
115
116 Dim dt As DataTable = ds.Tables(0)
117 'Dim dr As DataRow <- This is redundant - it does not do anything.
118
119 Dim compsupplierval As Integer = 0
120
121 'Check if a supplier is selected. Before this Try/Catch, the
122 'program would crash due to no value at row 0 of the table.
123 Try
124 compsupplierval = ds.Tables(0).Rows(0).Item("comp_supplier")
125 Catch
126 End Try
127 Dim csuppv As Integer = compsupplierval
128 Dim sn As String = "" 'Supplier name, initially blank here.
129
130 'Now call the List form's switching supplier ID function.
131 'No point creating a near identical one if there exists the
132 'ability of reusing code.
133 Call frmList.SwitchSuppIDToName(csuppv, sn)
134
135 'Populate the textboxes in the form with existing component details.
136 'All the component data text boxes are read-only to avoid data error:
137 'to edit those, edit the component details directly, then come back.
138
139 'Populate the component name textbox with the customer name
140 'from the other form, before getting info from db about others.
141
142 'An example of my variable naming here:
143 'The variable 'txtldcpn' = textbox listdetails compname.
144 txtldcpn.Text = cpn
145 If ds.Tables(0).Rows.Count <> 0 Then
146 txtldcpt.Text = ds.Tables(0).Rows(0).Item("comp_type")
147 txtldcpsn.Text = ds.Tables(0).Rows(0).Item("comp_serialno")
148 txtldcppkwp.Text = ds.Tables(0).Rows(0).Item("comp_panelkwp")
149 txtldcpspn.Text = sn
150 End If
151
152 accCommand.Connection = frmLoginForm.accConnection
153 accCommand.CommandType = CommandType.Text
154 accCommand.CommandText = cmdString
155 End Sub
156
157 Private Sub btnClose_Click(ByVal sender As System.Object, _
158 ByVal e As System.EventArgs) Handles btnClose.Click
159 frmList.Show()
160 Me.Close()
161 End Sub
162
163 End Class
Something went wrong with that request. Please try again.