Permalink
Browse files

Add the VB COMP4 coursework code, for the fun of it.

  • Loading branch information...
0 parents commit 159371fecff395607704486216dc4fc8a82a862c @issyl0 committed Oct 13, 2012
Showing with 1,539 additions and 0 deletions.
  1. +41 −0 frmAdd.vb
  2. +103 −0 frmAddComponent.vb
  3. +123 −0 frmAddCustomer.vb
  4. +71 −0 frmAddSupplier.vb
  5. +170 −0 frmList.vb
  6. +163 −0 frmListFullDetails.vb
  7. +53 −0 frmLoginForm.vb
  8. +50 −0 frmMainMenu.vb
  9. +40 −0 frmRemove.vb
  10. +70 −0 frmRemoveComponent.vb
  11. +68 −0 frmRemoveCustomer.vb
  12. +34 −0 frmRemoveCustomers.vb
  13. +72 −0 frmRemoveSupplier.vb
  14. +73 −0 frmReportInvoice.vb
  15. +86 −0 frmReportLog.vb
  16. +38 −0 frmReportMenu.vb
  17. +72 −0 frmReportQuote.vb
  18. +44 −0 frmReportSurvey.vb
  19. +64 −0 frmSurveyForm.vb
  20. +104 −0 frmSwankyCode.vb
41 frmAdd.vb
@@ -0,0 +1,41 @@
+Public Class frmAdd
+
+ Private Sub frmAdd_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ 'Check if the database connection is breathing.
+ 'If it isn't, resuscitate it. :)
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ 'Populate drop down box.
+ cbtxtAddOptions.Items.Add("Customer")
+ cbtxtAddOptions.Items.Add("Supplier")
+ cbtxtAddOptions.Items.Add("Component")
+ End Sub
+
+ Private Sub btnShow_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnShow.Click
+
+ 'According to the option selected, display the next form and hide
+ 'this one.
+ If cbtxtAddOptions.Text = "Customer" Then
+ Me.Hide()
+ frmAddCustomer.Show()
+ ElseIf cbtxtAddOptions.Text = "Supplier" Then
+ Me.Hide()
+ frmAddSupplier.Show()
+ ElseIf cbtxtAddOptions.Text = "Component" Then
+ Me.Hide()
+ frmAddComponent.Show()
+ End If
+ End Sub
+
+ Private Sub btnClose_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnClose.Click
+ 'Close this window and show the main menu.
+ Me.Close()
+ frmMainMenu.Show()
+ End Sub
+
+End Class
103 frmAddComponent.vb
@@ -0,0 +1,103 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Class frmAddComponent
+ Public accConnection As New OleDbConnection
+
+ Private Sub AddComponent_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ accConnection = frmLoginForm.accConnection
+ Dim strSQL As String = "SELECT supp_name FROM Supplier"
+ Dim da As New OleDbDataAdapter(strSQL, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Supplier")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow
+
+ For Each dr In dt.Rows()
+ 'List supplier names in the box so that the user can select
+ 'the supplier that the component is coming from. Pull this
+ 'from the Supplier table.
+ txtcbCompSupplierName.Items.Add(dr("supp_name"))
+ Next
+
+ txtcbCompSupplierName.SelectedIndex = -1
+
+ End Sub
+
+ Private Sub btnSave_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnSave.Click
+
+ 'This takes the supplier name from the supplier table and gets the
+ 'supplier ID from it, thereby letting it into the Component table.
+
+ Dim suppidvaluecmd As String = "SELECT supp_id FROM Supplier WHERE " _
+ & "supp_name = '" & txtcbCompSupplierName.SelectedItem & "'"
+
+ Dim cmdString As String = "INSERT INTO Component (comp_name, comp_type, comp_serialno," _
+ & " comp_panelkwp, comp_supplier)" _
+ & "VALUES (@comp_name,@comp_type,@comp_serialno," _
+ & "@comp_panelkwp,@comp_supplier)"
+
+ Dim da As New OleDbDataAdapter(suppidvaluecmd, accConnection)
+ Dim ds As New DataSet
+ da.Fill(ds, "Supplier")
+
+ Dim AddSupplierDataAdapter As New OleDbDataAdapter
+ Dim accCommand As New OleDbCommand
+ Dim intInsert As Integer
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+ Dim supplieridvalue As Integer = ds.Tables(0).Rows(0).Item("supp_id")
+ MsgBox(supplieridvalue)
+ Call InsertParameters(accCommand, supplieridvalue)
+ 'Now check if all the textboxes are populated.
+ Try
+ intInsert = accCommand.ExecuteNonQuery()
+ Catch ex As Exception
+ MsgBox("Enter a value in each of the boxes, and make it a valid one!")
+ End Try
+
+ Call frmSwankyCode.CheckAdditions(intInsert, btnSave)
+ End Sub
+
+ Private Sub InsertParameters(ByRef acccmd As OleDbCommand, ByRef siv As Integer)
+
+ acccmd.Parameters.Add("@comp_name", OleDbType.Char).Value = txtComponentName.Text
+ acccmd.Parameters.Add("@comp_type", OleDbType.Char).Value = txtComponentType.Text
+ acccmd.Parameters.Add("@comp_serialno", OleDbType.Char).Value = txtComponentSerialNo.Text
+ acccmd.Parameters.Add("@comp_panelkwp", OleDbType.Numeric).Value = txtComponentPanelkWp.Text
+ 'And now the supplier ID value.
+ acccmd.Parameters.Add("@comp_supplier", OleDbType.Numeric).Value = siv
+
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+
+ If btnSave.Enabled = False Then
+ 'It's all fine and has gone through OK, so don't display a
+ 'message because that would just be annoying, just close this
+ 'and display the previous form.
+ Me.Close()
+ frmAdd.Show()
+ Else
+ 'If it hasn't gone through OK, or nothing has been added,
+ 'then let the user know this so as not to panic them;
+ 'if the user did not mean to click the button, he/she knows.
+ MsgBox("This window will close and these details will not be saved.")
+ Me.Close()
+ frmAdd.Show()
+ End If
+
+ End Sub
+
+End Class
123 frmAddCustomer.vb
@@ -0,0 +1,123 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmAddCustomer
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmAddCustomers_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ 'Populate this list with selected titles.
+ Me.cbCustomerTitle.Items.Add("Mr")
+ Me.cbCustomerTitle.Items.Add("Mrs")
+ Me.cbCustomerTitle.Items.Add("Miss")
+ Me.cbCustomerTitle.Items.Add("Dr")
+
+ 'Add tooltip to lblCustomerName and txtCustomerName field
+ 'so that the user knows to add the name in a uniform way.
+ Me.ttCustomerName.SetToolTip(Me.lblCustomerName, _
+ "Name must be in the format 'Forename <space> Surname'.")
+ Me.ttCustomerName.SetToolTip(Me.txtCustomerName, _
+ "Name must be in the format 'Forename <space> Surname'.")
+ End Sub
+
+ Private Sub btnSave_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnSave.Click
+
+ Dim cmdString As String = "INSERT INTO Customer (cust_title, cust_name, " _
+ & "cust_billaddress, cust_billpostcode, cust_instaddress, " _
+ & "cust_instpostcode, cust_hometelno, cust_mobtelno, " _
+ & "cust_email, cust_mpan) VALUES (@cust_title,@cust_name," _
+ & "@cust_billaddress,@cust_billpostcode,@cust_instaddress," _
+ & "@cust_instpostcode,@cust_hometelno,@cust_mobtelno," _
+ & "@cust_email,@cust_mpan)"
+
+ Dim AddCustomerDataAdapter As New OleDbDataAdapter
+ Dim accCommand As New OleDbCommand
+ Dim intInsert As Integer
+ Dim CustomerForename As String
+
+ CustomerForename = txtCustomerName.Text
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+
+ 'Make the customer bill address be the install address too if
+ 'the user ticks the box.
+ If cbCustomerBillInstallSameAddress.CheckState = 1 Then
+ txtCustomerInstAddress.Text = txtCustomerBillAddress.Text
+ txtCustomerInstPostcode.Text = txtCustomerBillPostcode.Text
+ End If
+
+ Call InsertParameters(accCommand)
+
+ 'Check if there are no empty textboxes. If there aren't, do all
+ 'other checks, and send it through to the database.
+ Try
+ intInsert = accCommand.ExecuteNonQuery()
+ Catch ex As Exception
+ intInsert = 0
+ MsgBox("Enter a value in each of the boxes, and make it a valid one!")
+ End Try
+
+ 'Check if the email textbox contains '@', therefore if it is a
+ 'valid email address.
+ Dim pos As Integer
+ Dim etb As String = txtCustomerEmail.Text 'email textbox
+ Dim atsymbol As String = "@"
+ pos = InStr(etb, atsymbol)
+ If pos = 0 Then
+ MsgBox("Input another email address!")
+ intInsert = 0
+ End If
+
+ Call frmSwankyCode.CheckAdditions(intInsert, btnSave)
+
+ End Sub
+
+ Private Sub InsertParameters(ByRef acccmd As OleDbCommand)
+ acccmd.Parameters.Add("@cust_title", OleDbType.Char).Value = _
+ cbCustomerTitle.SelectedItem
+ acccmd.Parameters.Add("@cust_name", OleDbType.Char).Value = _
+ txtCustomerName.Text
+ acccmd.Parameters.Add("@cust_billaddress", OleDbType.Char).Value = _
+ txtCustomerBillAddress.Text
+ acccmd.Parameters.Add("@cust_billpostcode", OleDbType.Char).Value = _
+ txtCustomerBillPostcode.Text
+ acccmd.Parameters.Add("@cust_instaddress", OleDbType.Char).Value = _
+ txtCustomerInstAddress.Text
+ acccmd.Parameters.Add("@cust_instpostcode", OleDbType.Char).Value = _
+ txtCustomerInstPostcode.Text
+ acccmd.Parameters.Add("@cust_hometelno", OleDbType.Char).Value = _
+ txtCustomerHomeTelNo.Text
+ acccmd.Parameters.Add("@cust_mobtelno", OleDbType.Char).Value = _
+ mtxtCustomerMobTelNo.Text
+ acccmd.Parameters.Add("@cust_email", OleDbType.Char).Value = _
+ txtCustomerEmail.Text
+ acccmd.Parameters.Add("@cust_mpan", OleDbType.Char).Value = _
+ txtCustomerMpanNo.Text
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+
+ If btnSave.Enabled = False Then
+ 'It's all fine and has gone through OK, so don't display a
+ 'message because that would just be annoying, just close this
+ 'and display the previous form.
+ Me.Close()
+ frmAdd.Show()
+ Else
+ 'If it hasn't gone through OK, or nothing has been added,
+ 'then let the user know this so as not to panic them;
+ 'if the user did not mean to click the button, he/she knows.
+ MsgBox("This window will close and these details will not be saved.")
+ Me.Close()
+ frmAdd.Show()
+ End If
+
+ End Sub
+End Class
71 frmAddSupplier.vb
@@ -0,0 +1,71 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmAddSupplier
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmAddSupplier_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+ End Sub
+
+ Private Sub btnSave_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnSave.Click
+
+ Dim cmdString As String = "INSERT INTO Supplier (supp_name, supp_address, supp_postcode, " _
+ & "supp_telno, supp_contactname)" _
+ & "VALUES (@supp_name,@supp_address,@supp_postcode," _
+ & "@supp_telno,@supp_contactname)"
+
+ Dim AddSupplierDataAdapter As New OleDbDataAdapter
+ Dim accCommand As New OleDbCommand
+ Dim intInsert As Integer
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+ Call InsertParameters(accCommand)
+ 'Now check if all the textboxes are populated.
+ Try
+ intInsert = accCommand.ExecuteNonQuery()
+ Catch ex As Exception
+ intInsert = 0
+ MsgBox("Enter a value in each of the boxes, and make it a valid one!")
+ End Try
+
+ Call frmSwankyCode.CheckAdditions(intInsert, btnSave)
+
+ End Sub
+
+ Private Sub InsertParameters(ByRef acccmd As OleDbCommand)
+ acccmd.Parameters.Add("@supp_name", OleDbType.Char).Value = txtSupplierName.Text
+ acccmd.Parameters.Add("@supp_address", OleDbType.Char).Value = txtSupplierAddress.Text
+ acccmd.Parameters.Add("@supp_postcode", OleDbType.Char).Value = txtSupplierPostCode.Text
+ acccmd.Parameters.Add("@supp_telno", OleDbType.Char).Value = mtxtSupplierTelNo.Text
+ acccmd.Parameters.Add("@supp_contactname", OleDbType.Char).Value = txtSupplierContactName.Text
+
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+
+ If btnSave.Enabled = False Then
+ 'It's all fine and has gone through OK, so don't display a
+ 'message because that would just be annoying, just close this
+ 'and display the previous form.
+ Me.Close()
+ frmAdd.Show()
+ Else
+ 'If it hasn't gone through OK, or nothing has been added,
+ 'then let the user know this so as not to panic them;
+ 'if the user did not mean to click the button, he/she knows.
+ MsgBox("This window will close and these details will not be saved.")
+ Me.Close()
+ frmAdd.Show()
+ End If
+
+ End Sub
+
+End Class
170 frmList.vb
@@ -0,0 +1,170 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmList
+ Public accConnection As New OleDbConnection
+
+ 'I think this is a better way of doing the listing [1] - fewer buttons
+ 'just a dropdown list which can be added to without having to create
+ 'another form
+
+ '[1] - compared to the previous separate frmList[Customer|Supplier] etc.
+
+ Private Sub frmList_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+
+ 'Check if db connection is breathing.
+ 'If it isn't, resuscitate it. :)
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ 'Populate the options list box with the following values.
+ cbtxtListOptions.Items.Add("Customers")
+ cbtxtListOptions.Items.Add("Suppliers")
+ cbtxtListOptions.Items.Add("Components")
+ End Sub
+
+ Private Sub btnShow_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnShow.Click
+
+ Dim cmdString As String = "" 'Initially blank.
+ accConnection = frmLoginForm.accConnection
+ Dim ds As New DataSet
+ Dim dr As DataRow
+
+ 'da0, da1, da2
+ 'dt0, dt1, dt2
+ 'Declared within this if statement to make the program recognise
+ 'the change in cmdString and so know where to look.
+ 'Named da<num> and dt<num> to differentiate between different ifs.
+
+ If cbtxtListOptions.Text = "Customers" Then
+ cmdString = "SELECT cust_name FROM Customer"
+ 'Now clear the box if the selection changes.
+ lbList.Items.Clear()
+ Dim da0 As New OleDbDataAdapter(cmdString, accConnection)
+ da0.Fill(ds, "Customer")
+ Dim dt0 As DataTable = ds.Tables(0)
+ For Each dr In dt0.Rows()
+ lbList.Items.Add(dr("cust_name"))
+ Next
+ ElseIf cbtxtListOptions.Text = "Suppliers" Then
+ cmdString = "SELECT supp_name FROM Supplier"
+ 'Now clear the box if the selection changes.
+ lbList.Items.Clear()
+ Dim da1 As New OleDbDataAdapter(cmdString, accConnection)
+ da1.Fill(ds, "Supplier")
+ Dim dt1 As DataTable = ds.Tables(0)
+ For Each dr In dt1.Rows()
+ lbList.Items.Add(dr("supp_name"))
+ Next
+ ElseIf cbtxtListOptions.Text = "Components" Then
+ cmdString = "SELECT comp_name FROM Component"
+ 'Now clear the box if the selection changes.
+ lbList.Items.Clear()
+ Dim da2 As New OleDbDataAdapter(cmdString, accConnection)
+ da2.Fill(ds, "Component")
+ Dim dt2 As DataTable = ds.Tables(0)
+ For Each dr In dt2.Rows()
+ lbList.Items.Add(dr("comp_name"))
+ Next
+ End If
+
+ End Sub
+
+ Private Sub btnShowAssoc_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnShowAssoc.Click
+
+ If cbtxtListOptions.SelectedItem = "Customers" Then
+ MsgBox("No associations to show at this stage.")
+ ElseIf cbtxtListOptions.SelectedItem = "Suppliers" Then
+ MsgBox("No associations to show at this stage.")
+ ElseIf cbtxtListOptions.SelectedItem = "Components" Then
+ 'Show the association between component and supplier: who supplies
+ 'each component.
+ Call AssocCompSupp()
+ End If
+ End Sub
+
+ Private Sub AssocCompSupp()
+
+ 'Variables here:
+ 'sn = supplier name;
+ 'cn = component name.
+
+ accConnection = frmLoginForm.accConnection
+ Dim cn As String = lbList.SelectedItem
+ Dim compsuppliervalcmd As String = "SELECT comp_supplier FROM Component " & _
+ "WHERE comp_name = '" & cn & "'"
+ Dim sn As String = ""
+
+ Dim da As New OleDbDataAdapter(compsuppliervalcmd, accConnection)
+ Dim ds As New DataSet
+ da.Fill(ds, "Component")
+
+ Dim compsupplierval As Integer = 0 'Initially.
+
+ 'Don't let the program crash if it detects that nothing has been
+ 'selected - just display the main form anyway.
+ Try
+ compsupplierval = ds.Tables(0).Rows(0).Item("comp_supplier")
+ Catch
+ End Try
+
+ 'Put the supplier ID value into another variable for ease of
+ 'use within the function just below.
+ Dim csuppv As Integer = compsupplierval
+
+ 'Call the function to switch the supplier ID associated with the
+ 'component in the component table into the actual supplier name.
+ 'Send the suppname variable SN to the function so that it is
+ 'easier to reference here afterwards.
+ Call SwitchSuppIDToName(csuppv, sn)
+
+ 'Make sure that totally blank "is supplied by" don't display
+ 'blank at both ends because the user hasn't selected an item.
+ 'This does not cover lack of data about components' suppliers?
+ If lbList.SelectedIndex = -1 Then
+ MsgBox("Cannot show associations; please select an item from the list.")
+ Else
+ MsgBox(cn & " is supplied by " & sn & ".")
+ End If
+
+ End Sub
+
+ Public Function SwitchSuppIDToName(ByVal csuppval As Integer, _
+ ByRef finalsn As String)
+
+ accConnection = frmLoginForm.accConnection
+ Dim cmdString As String = "SELECT supp_name FROM Supplier WHERE supp_id = " & csuppval & ""
+
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+ da.Fill(ds, "Supplier")
+
+ 'Don't let the program crash if it detects that nothing has been
+ 'selected - just display the main form anyway.
+ Try
+ finalsn = ds.Tables(0).Rows(0).Item("supp_name")
+ Catch
+ End Try
+
+ 'Functions always return a value, so make this one return one.
+ SwitchSuppIDToName = finalsn
+
+ End Function
+
+ Private Sub btnListFullDetails_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnListFullDetails.Click
+ frmListFullDetails.Show()
+ Me.Close()
+ End Sub
+
+ Private Sub btnClose_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnClose.Click
+ 'Close this window and show the main menu.
+ Me.Close()
+ frmMainMenu.Show()
+ End Sub
+End Class
163 frmListFullDetails.vb
@@ -0,0 +1,163 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmListFullDetails
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmListFullDetails_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ If frmList.cbtxtListOptions.SelectedItem = "Customers" Then
+ Call PopulateCustInfo()
+ ElseIf frmList.cbtxtListOptions.SelectedItem = "Suppliers" Then
+ Call PopulateSuppInfo()
+ ElseIf frmList.cbtxtListOptions.SelectedItem = "Components" Then
+ Call PopulateCompInfo()
+ End If
+ End Sub
+
+ Private Sub PopulateCustInfo()
+
+ accConnection = frmLoginForm.accConnection
+ 'Input customer name from the other form and attribute it to CTN.
+ Dim ctn As String = frmList.lbList.SelectedItem 'Customer name.
+ Dim cmdString As String = "SELECT * FROM Customer WHERE cust_name = '" & ctn & "'"
+ Dim accCommand As New OleDbCommand
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+ 'Dim dr As DataRow <- This is redundant - it does not do anything.
+
+ 'Populate the textboxes in the form with existing customer details.
+ 'All the customer data text boxes are read-only to avoid data error:
+ 'to edit those, edit the customer details directly, then come back.
+
+ 'Populate the customer name textbox with the customer name
+ 'from the other form, before getting info from db about others.
+
+ 'An example of my variable naming here:
+ 'The variable 'txtldcn' = textbox listdetails custname.
+ txtldctn.Text = ctn
+ If ds.Tables(0).Rows.Count <> 0 Then
+ cbldctt.Text = ds.Tables(0).Rows(0).Item("cust_title")
+ txtldctba.Text = ds.Tables(0).Rows(0).Item("cust_billaddress")
+ txtldctbp.Text = ds.Tables(0).Rows(0).Item("cust_billpostcode")
+ txtldctia.Text = ds.Tables(0).Rows(0).Item("cust_instaddress")
+ txtldctip.Text = ds.Tables(0).Rows(0).Item("cust_instpostcode")
+ txtldcthtn.Text = ds.Tables(0).Rows(0).Item("cust_hometelno")
+ txtldctmtn.Text = ds.Tables(0).Rows(0).Item("cust_mobtelno")
+ txtldctea.Text = ds.Tables(0).Rows(0).Item("cust_email")
+ txtldctmpan.Text = ds.Tables(0).Rows(0).Item("cust_mpan")
+ End If
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+ End Sub
+
+ Private Sub PopulateSuppInfo()
+
+ accConnection = frmLoginForm.accConnection
+ 'Input supplier name from the other form and attribute it to SPN.
+ Dim spn As String = frmList.lbList.SelectedItem 'Supplier name.
+ Dim cmdString As String = "SELECT * FROM Supplier WHERE supp_name = '" & spn & "'"
+ Dim accCommand As New OleDbCommand
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Supplier")
+
+ Dim dt As DataTable = ds.Tables(0)
+ 'Dim dr As DataRow <- This is redundant - it does not do anything.
+
+ 'Populate the textboxes in the form with existing supplier details.
+ 'All the supplier data text boxes are read-only to avoid data error:
+ 'to edit those, edit the supplier details directly, then come back.
+
+ 'Populate the supplier name textbox with the customer name
+ 'from the other form, before getting info from db about others.
+
+ 'An example of my variable naming here:
+ 'The variable 'txtldspn' = textbox listdetails suppname.
+ txtldspn.Text = spn
+ If ds.Tables(0).Rows.Count <> 0 Then
+ txtldspa.Text = ds.Tables(0).Rows(0).Item("supp_address")
+ txtldspp.Text = ds.Tables(0).Rows(0).Item("supp_postcode")
+ txtldsptn.Text = ds.Tables(0).Rows(0).Item("supp_telno")
+ txtldspc.Text = ds.Tables(0).Rows(0).Item("supp_contactname")
+ End If
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+
+ End Sub
+
+ Private Sub PopulateCompInfo()
+
+ accConnection = frmLoginForm.accConnection
+ 'Input component name from the other form and attribute it to CPN.
+ Dim cpn As String = frmList.lbList.SelectedItem 'Component name.
+ Dim cmdString As String = "SELECT * FROM Component WHERE comp_name = '" & cpn & "'"
+
+ Dim accCommand As New OleDbCommand
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Component")
+
+ Dim dt As DataTable = ds.Tables(0)
+ 'Dim dr As DataRow <- This is redundant - it does not do anything.
+
+ Dim compsupplierval As Integer = 0
+
+ 'Check if a supplier is selected. Before this Try/Catch, the
+ 'program would crash due to no value at row 0 of the table.
+ Try
+ compsupplierval = ds.Tables(0).Rows(0).Item("comp_supplier")
+ Catch
+ End Try
+ Dim csuppv As Integer = compsupplierval
+ Dim sn As String = "" 'Supplier name, initially blank here.
+
+ 'Now call the List form's switching supplier ID function.
+ 'No point creating a near identical one if there exists the
+ 'ability of reusing code.
+ Call frmList.SwitchSuppIDToName(csuppv, sn)
+
+ 'Populate the textboxes in the form with existing component details.
+ 'All the component data text boxes are read-only to avoid data error:
+ 'to edit those, edit the component details directly, then come back.
+
+ 'Populate the component name textbox with the customer name
+ 'from the other form, before getting info from db about others.
+
+ 'An example of my variable naming here:
+ 'The variable 'txtldcpn' = textbox listdetails compname.
+ txtldcpn.Text = cpn
+ If ds.Tables(0).Rows.Count <> 0 Then
+ txtldcpt.Text = ds.Tables(0).Rows(0).Item("comp_type")
+ txtldcpsn.Text = ds.Tables(0).Rows(0).Item("comp_serialno")
+ txtldcppkwp.Text = ds.Tables(0).Rows(0).Item("comp_panelkwp")
+ txtldcpspn.Text = sn
+ End If
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+ End Sub
+
+ Private Sub btnClose_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnClose.Click
+ frmList.Show()
+ Me.Close()
+ End Sub
+
+End Class
53 frmLoginForm.vb
@@ -0,0 +1,53 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmLoginForm
+ Public accConnection As New OleDbConnection
+ Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
+ "Data Source = E:\SFS.mdb"
+
+ Private Sub frmLoginForm_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ accConnection = New OleDbConnection(ConnectionString)
+ End Sub
+
+ Private Sub OK_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles OK.Click
+
+ Dim cmdString As String = "SELECT login_uname, login_pword FROM Login"
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+ Dim u As String = txtUsername.Text
+ Dim p As String = txtPassword.Text
+
+ da.Fill(ds, "Login")
+ Dim dt As DataTable = ds.Tables(0)
+
+ 'The usernames and passwords obtained from the database, to
+ 'compare with the ones the user entered.
+ Dim loginuname As String = ""
+ Dim loginpword As String = ""
+
+ If ds.Tables(0).Rows.Count <> 0 Then
+ loginuname = ds.Tables(0).Rows(0).Item("login_uname")
+ loginpword = ds.Tables(0).Rows(0).Item("login_pword")
+ End If
+
+ If u = loginuname And p = loginpword Then
+ frmMainMenu.Show()
+ Else
+ MsgBox("Incorrect username or password. Try again.")
+ 'Error, then blank the textboxes so that the user doesn't
+ 'have to.
+ txtUsername.Text = ""
+ txtPassword.Text = ""
+ End If
+
+ End Sub
+
+ Private Sub Cancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles Cancel.Click
+ Me.Close()
+ End Sub
+
+End Class
50 frmMainMenu.vb
@@ -0,0 +1,50 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmMainMenu
+ Private Sub frmMainMenu_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ 'Hide the login form from the user when this form is loaded so
+ 'that he/she is not having to close a load of windows when he/she
+ 'quits the program.
+ frmLoginForm.Hide()
+ End Sub
+
+ 'In each of these, according to the buttons clicked, show the correct
+ 'form and close this window.
+ Private Sub btnReport_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnReport.Click
+ Me.Hide()
+ frmReportMenu.Show()
+ End Sub
+
+ Private Sub btnList_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnList.Click
+ Me.Hide()
+ frmList.Show()
+ End Sub
+
+ Private Sub btnAdd_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnAdd.Click
+ Me.Hide()
+ frmAdd.Show()
+ End Sub
+
+ Private Sub btnRemove_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnRemove.Click
+ Me.Hide()
+ frmRemove.Show()
+ End Sub
+
+ Private Sub btnQuit_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnQuit.Click
+ Me.Close()
+ 'Now close the login form that is at present hidden so that the
+ 'program closes and doesn't stay running displaying nothing. Also,
+ 'someone would have already logged in, so displaying the login
+ 'form again would intice people into logging in again, potentially
+ 'messing database stuff up like the closing of connections etc.
+ frmLoginForm.Close()
+ End Sub
+
+End Class
40 frmRemove.vb
@@ -0,0 +1,40 @@
+Public Class frmRemove
+
+ Private Sub frmRemove_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ 'Check if the database connection is breathing.
+ 'If it isn't, resuscitate it. :-)
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ cbtxtRemoveOptions.Items.Add("Customer")
+ cbtxtRemoveOptions.Items.Add("Supplier")
+ cbtxtRemoveOptions.Items.Add("Component")
+ End Sub
+
+ Private Sub btnShow_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnShow.Click
+
+ 'According to the option selected, display the next form and hide
+ 'this one.
+ If cbtxtRemoveOptions.Text = "Customer" Then
+ Me.Hide()
+ frmRemoveCustomer.Show()
+ ElseIf cbtxtRemoveOptions.Text = "Supplier" Then
+ Me.Hide()
+ frmRemoveSupplier.Show()
+ ElseIf cbtxtRemoveOptions.Text = "Component" Then
+ Me.Hide()
+ frmRemoveComponent.Show()
+ End If
+
+ End Sub
+
+ Private Sub btnClose_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnClose.Click
+ 'Close this window and show the main menu.
+ Me.Close()
+ frmMainMenu.Show()
+ End Sub
+End Class
70 frmRemoveComponent.vb
@@ -0,0 +1,70 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Class frmRemoveComponent
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmRemoveComponent_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ 'Check if the database connection is breathing.
+ 'If it isn't, resuscitate it. :-)
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ accConnection = frmLoginForm.accConnection
+ Dim strSQL As String = "SELECT comp_name FROM Component"
+ Dim da As New OleDbDataAdapter(strSQL, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Component")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow
+
+ For Each dr In dt.Rows()
+ 'List component names in the box.
+ txtcbComponentRemove.Items.Add(dr("comp_name"))
+ Next
+
+ txtcbComponentRemove.SelectedIndex = -1
+
+ End Sub
+
+ Private Sub btnRemove_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnRemove.Click
+
+ Dim cmdString As String = "DELETE * FROM Component WHERE comp_name = " & _
+ Me.txtcbComponentRemove.SelectedItem & ""
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+ Dim accCommand As New OleDbCommand
+ Dim intRemove As Integer
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+
+ intRemove = accCommand.ExecuteNonQuery()
+
+ If intRemove = 0 Then
+ MsgBox("Data deletion failed.")
+ 'Else, assume it went through OK.
+ Else
+ btnRemove.Enabled = False
+ End If
+
+ End Sub
+
+ Private Sub RemoveParameters(ByRef acccmd As OleDbCommand)
+ acccmd.Parameters.Add("@comp_name", OleDbType.Char).Value = _
+ txtcbComponentRemove.SelectedItem
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+ Me.Close()
+ frmRemove.Show()
+ End Sub
+
+End Class
68 frmRemoveCustomer.vb
@@ -0,0 +1,68 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmRemoveCustomer
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmRemoveCustomers_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ accConnection = frmLoginForm.accConnection
+ Dim strSQL As String = "SELECT cust_name FROM Customer"
+ Dim da As New OleDbDataAdapter(strSQL, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow
+
+ For Each dr In dt.Rows()
+ txtcbCustomerRemove.Items.Add(dr("cust_name"))
+ Next
+
+ txtcbCustomerRemove.SelectedIndex = -1
+ End Sub
+
+ Private Sub btnRemove_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnRemove.Click
+
+ Dim cmdString As String = "DELETE * FROM Customer WHERE cust_name = '" & _
+ Me.txtcbCustomerRemove.SelectedItem & "'"
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+ Dim accCommand As New OleDbCommand
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+
+ Call RemoveParameters(accCommand)
+ Dim intRemove As Integer
+
+ intRemove = accCommand.ExecuteNonQuery()
+
+ If intRemove = 0 Then
+ MsgBox("Sorry, data deletion failed.")
+ 'Else, assume it went through OK.
+ Else
+ btnRemove.Enabled = False
+ End If
+
+ End Sub
+
+ Private Sub RemoveParameters(ByRef acccmd As OleDbCommand)
+ acccmd.Parameters.Add("@cust_name", OleDbType.Char).Value = _
+ Me.txtcbCustomerRemove.SelectedItem
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+ Me.Close()
+ frmRemove.Show()
+ End Sub
+
+End Class
34 frmRemoveCustomers.vb
@@ -0,0 +1,34 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmRemoveCustomers
+ Public accConnection As New OleDbConnection
+ Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
+ MsgBox("No customers will be removed from the database.")
+ Me.Close()
+ End Sub
+
+ Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
+ 'nothing happens yet
+ Me.Close()
+ End Sub
+
+ Private Sub frmRemoveCustomers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
+ accConnection = frmMainMenu.accConnection
+ Dim strSQL As String = "SELECT cust_surname, cust_forename FROM Customer"
+ Dim da As New OleDbDataAdapter(strSQL, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow
+
+ For Each dr In dt.Rows()
+ txtcbCustomerRemove.Items.Add(dr("cust_surname") + ", " + dr("cust_forename"))
+ Next
+
+ txtcbCustomerRemove.SelectedIndex = -1
+ End Sub
+
+End Class
72 frmRemoveSupplier.vb
@@ -0,0 +1,72 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmRemoveSupplier
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmRemoveSupplier_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+
+ 'Check if db connection is breathing.
+ 'If it isn't, resuscitate it.
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ accConnection = frmLoginForm.accConnection
+ Dim strSQL As String = "SELECT supp_id,supp_name FROM Supplier"
+ Dim da As New OleDbDataAdapter(strSQL, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Supplier")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow
+
+ For Each dr In dt.Rows()
+ 'Populate the box with the supplier names.
+ txtcbSupplierRemove.Items.Add(dr("supp_name"))
+ Next
+
+ txtcbSupplierRemove.SelectedIndex = -1
+
+ End Sub
+
+ Private Sub btnRemove_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnRemove.Click
+
+ Dim RemoveSupplierDataAdapter As New OleDbDataAdapter
+ Dim accCommand As New OleDbCommand
+ Dim cmdString As String = "DELETE * FROM Supplier WHERE supp_name = " & _
+ Me.txtcbSupplierRemove.SelectedItem & ""
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+
+ Call RemoveParameters(accCommand)
+ 'Execute the query to delete the record from the db.
+ Dim intRemove As Integer
+
+ intRemove = accCommand.ExecuteNonQuery()
+
+ If intRemove = 0 Then
+ MsgBox("Data deletion failed.")
+ 'Else, assume it went through OK.
+ Else
+ btnRemove.Enabled = False
+ End If
+
+ End Sub
+
+ Private Sub RemoveParameters(ByRef acccmd As OleDbCommand)
+ acccmd.Parameters.Add("@supp_name", OleDbType.Char).Value = _
+ txtcbSupplierRemove.SelectedItem
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+ Me.Close()
+ frmRemove.Show()
+ End Sub
+End Class
73 frmReportInvoice.vb
@@ -0,0 +1,73 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Class frmReportInvoice
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmReportInvoice_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ accConnection = frmLoginForm.accConnection
+ Dim strSQL As String = "SELECT cust_name FROM Customer"
+ Dim da As New OleDbDataAdapter(strSQL, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow
+
+ For Each dr In dt.Rows()
+ 'List customer names in the box so that the user can select
+ 'a customer to show the invoice of. At least customer details
+ 'will be inserted into the Word document at this stage.
+ txtcbCustNameForInvoice.Items.Add(dr("cust_name"))
+ Next
+
+ txtcbCustNameForInvoice.SelectedIndex = -1
+
+ End Sub
+
+
+ Private Sub btnOK2_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnOK2.Click
+
+ accConnection = frmLoginForm.accConnection
+ 'Input supplier name from the other form and attribute it to CTN.
+ Dim ctn As String = txtcbCustNameForInvoice.SelectedItem
+ Dim cmdString As String = "SELECT * FROM Customer WHERE cust_name = '" & ctn & "'"
+
+ Dim accCommand As New OleDbCommand
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+
+ 'Now create variables to hold the useful address values of the
+ ''* FROM Customer' so they'll be useful later on for the Word
+ 'invoicing stuff.
+ 'aicn, for example, = add invoice cust name
+ Dim aict As String = ds.Tables(0).Rows(0).Item("cust_title")
+ Dim aicn As String = ds.Tables(0).Rows(0).Item("cust_name")
+ 'Billing address and postcode in this case.
+ Dim aica As String = ds.Tables(0).Rows(0).Item("cust_billaddress")
+ Dim aicp As String = ds.Tables(0).Rows(0).Item("cust_billpostcode")
+
+ 'Now for some Word automation magic. Call a procedure to do this
+ 'to save cluttering this OK button's execution with code.
+ Call frmSwankyCode.WordInvoiceAutomationMagic(aict, aicn, aica, aicp)
+
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+ frmReportMenu.Show()
+ Me.Close()
+ End Sub
+End Class
86 frmReportLog.vb
@@ -0,0 +1,86 @@
+Imports Microsoft.Office.Core
+Imports Microsoft.Office.Interop
+Imports Microsoft.Office.Interop.Word
+
+Public Class frmReportLog
+
+ Private Sub frmReportLog_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+
+ 'Drop down menu populated with months up to 12/12.
+ txtcbReportLog.Items.Add("December 2011")
+ txtcbReportLog.Items.Add("January 2012")
+ txtcbReportLog.Items.Add("February 2012")
+ txtcbReportLog.Items.Add("March 2012")
+ txtcbReportLog.Items.Add("April 2012")
+ txtcbReportLog.Items.Add("May 2012")
+ txtcbReportLog.Items.Add("June 2012")
+ txtcbReportLog.Items.Add("July 2012")
+ txtcbReportLog.Items.Add("August 2012")
+ txtcbReportLog.Items.Add("September 2012")
+ txtcbReportLog.Items.Add("October 2012")
+ txtcbReportLog.Items.Add("November 2012")
+ txtcbReportLog.Items.Add("December 2012")
+
+ End Sub
+
+ Private Sub btnOK_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnOK.Click
+ 'On click, open the selected file from the drop down list with
+ 'Microsoft Word.
+
+ Dim ms_word As New Word.Application
+ Dim worddoc As New Word.Document
+
+ 'Make the name shorter purely for ease of typing, despite Visual
+ 'Studio's tab completion.
+ Dim rlsi As String = txtcbReportLog.SelectedItem
+ 'Make worddoc variable shorter purely for ease of typing in these
+ 'stressed times where typing every month and every file to open
+ 'gets tedious and frustrating, but I can't think of a better way
+ 'to add the months. Again, tedious and stressful typing 'worddoc'
+ 'despite Visual Studio's tab completion.
+ Dim wd As Word.Document = worddoc
+
+ If rlsi = "December 2011" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_dec11.docx")
+ ElseIf rlsi = "January 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_jan12.docx")
+ ElseIf rlsi = "February 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_feb12.docx")
+ ElseIf rlsi = "March 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_mar12.docx")
+ ElseIf rlsi = "April 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_apr12.docx")
+ ElseIf rlsi = "May 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_may12.docx")
+ ElseIf rlsi = "June 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_jun12.docx")
+ ElseIf rlsi = "July 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_jul12.docx")
+ ElseIf rlsi = "August 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_aug12.docx")
+ ElseIf rlsi = "September 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_sept12.docx")
+ ElseIf rlsi = "October 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_oct12.docx")
+ ElseIf rlsi = "November 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_nov12.docx")
+ ElseIf rlsi = "December 2012" Then
+ wd = ms_word.Documents.Open("E:\sfsstuff\log_dec12.docx")
+ Else
+ MsgBox("No form was selected.")
+ End If
+
+ 'Let the user see the document when it opens.
+ ms_word.WindowState = Word.WdWindowState.wdWindowStateNormal
+ ms_word.Visible = True
+
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+ Me.Close()
+ frmReportMenu.Show()
+ End Sub
+End Class
38 frmReportMenu.vb
@@ -0,0 +1,38 @@
+Public Class frmReportMenu
+
+ Private Sub btnQuit_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnQuit.Click
+ 'On close, close this window and show the main menu.
+ Me.Close()
+ frmMainMenu.Show()
+ End Sub
+
+ Private Sub btnQuotes_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnQuotes.Click
+ 'Show the quote form to the user, then hide this menu window.
+ frmReportQuote.Show()
+ Me.Hide()
+ End Sub
+
+ Private Sub btnLogs_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnLogs.Click
+ 'Show the log form to the user, then hide this menu window.
+ frmReportLog.Show()
+ Me.Hide()
+ End Sub
+
+ Private Sub btnInvoices_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnInvoices.Click
+ 'Show the invoice form to the user, then hide this menu window.
+ frmReportInvoice.Show()
+ Me.Hide()
+ End Sub
+
+ Private Sub btnSurvey_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnSurvey.Click
+ 'Show the survey form to the user, then hide this menu window.
+ frmReportSurvey.Show()
+ Me.Hide()
+ End Sub
+
+End Class
72 frmReportQuote.vb
@@ -0,0 +1,72 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmReportQuote
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmReportQuote_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ accConnection = frmLoginForm.accConnection
+ Dim strSQL As String = "SELECT cust_name FROM Customer"
+ Dim da As New OleDbDataAdapter(strSQL, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow
+
+ For Each dr In dt.Rows()
+ 'List customer names in the box so that the user can select
+ 'a customer to show the quotation of. At least customer details
+ 'will be inserted into the Word document at this stage.
+ txtcbCustNameForQuotation.Items.Add(dr("cust_name"))
+ Next
+
+ txtcbCustNameForQuotation.SelectedIndex = -1
+
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+ Me.Close()
+ frmReportMenu.Show()
+ End Sub
+
+ Private Sub btnOK2_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnOK2.Click
+
+ accConnection = frmLoginForm.accConnection
+ 'Input customer name from the other form and attribute it to CTN.
+ Dim ctn As String = txtcbCustNameForQuotation.SelectedItem
+ Dim cmdString As String = "SELECT * FROM Customer WHERE cust_name = '" & ctn & "'"
+
+ Dim accCommand As New OleDbCommand
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+
+ 'Now create variables to hold the useful address values of the
+ ''* FROM Customer' so they'll be useful later on for the Word
+ 'quotation stuff.
+ 'aqcn, for example, = add quotation cust name
+ Dim aqct As String = ds.Tables(0).Rows(0).Item("cust_title")
+ Dim aqcn As String = ds.Tables(0).Rows(0).Item("cust_name")
+ 'Billing address and postcode in this case.
+ Dim aqca As String = ds.Tables(0).Rows(0).Item("cust_billaddress")
+ Dim aqcp As String = ds.Tables(0).Rows(0).Item("cust_billpostcode")
+
+ 'Now for some Word automation magic. Call a procedure to do this
+ 'to save cluttering this OK button's execution with code.
+ Call frmSwankyCode.WordQuotationAutomationMagic(aqct, aqcn, aqca, aqcp)
+
+ End Sub
+End Class
44 frmReportSurvey.vb
@@ -0,0 +1,44 @@
+Imports System.Data
+Imports System.Data.OleDb
+
+Public Class frmReportSurvey
+
+ Private Sub frmReportSurvey_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ Dim cmdString As String = "SELECT cust_name FROM Customer"
+ 'check if db connection is breathing
+ 'if it isn't, resuscitate it :)
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+ Dim accConnection As OleDbConnection = frmLoginForm.accConnection
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow
+
+ For Each dr In dt.Rows()
+ txtcbReportSurvey.Items.Add(dr("cust_name"))
+ Next
+
+ txtcbReportSurvey.SelectedIndex = -1
+
+ End Sub
+
+
+ Private Sub btnOK_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnOK.Click
+
+ Dim custname As String = txtcbReportSurvey.SelectedItem
+ frmSurveyForm.Show()
+ End Sub
+
+ Private Sub btnCancel_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnCancel.Click
+ Me.Close()
+ frmReportMenu.Show()
+ End Sub
+End Class
64 frmSurveyForm.vb
@@ -0,0 +1,64 @@
+Imports System.Data
+Imports System.Data.OleDb
+Public Class frmSurveyForm
+
+ Public accConnection As New OleDbConnection
+
+ Private Sub frmSurveyForm_Load(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles MyBase.Load
+ 'All this does, for now, is display the selected customer details.
+ 'In the future, full survey details will be able to be entered by
+ 'the user, however at this moment I cannot implement this due to
+ 'time constraints, so it will be implemented in after-development.
+ 'To show this to the user when he or she hunts around, there
+ 'exists a placeholder text label that states that features are
+ 'coming soon.
+
+ If frmLoginForm.accConnection.State <> ConnectionState.Open Then
+ frmLoginForm.accConnection.Open()
+ End If
+
+ accConnection = frmLoginForm.accConnection
+ 'Input customer name from the other form and attribute it to CN.
+ Dim cn As String = frmReportSurvey.txtcbReportSurvey.SelectedItem
+ Dim cmdString As String = "SELECT * FROM Customer WHERE cust_name = '" & cn & "'"
+ Dim accCommand As New OleDbCommand
+ Dim da As New OleDbDataAdapter(cmdString, accConnection)
+ Dim ds As New DataSet
+
+ da.Fill(ds, "Customer")
+
+ Dim dt As DataTable = ds.Tables(0)
+ Dim dr As DataRow '<- This is redundant.sss
+
+ 'Populate the textboxes in the form with existing customer details.
+ 'All the customer data text boxes are read-only to avoid data error:
+ 'to edit those, edit the customer details directly, then come back.
+
+ 'Populate the customer name textbox with the customer name
+ 'from the other form, before getting info from db about others.
+ txtscn.Text = cn
+ If ds.Tables(0).Rows.Count <> 0 Then
+ cbsct.Text = ds.Tables(0).Rows(0).Item("cust_title")
+ txtscba.Text = ds.Tables(0).Rows(0).Item("cust_billaddress")
+ txtscbp.Text = ds.Tables(0).Rows(0).Item("cust_billpostcode")
+ txtscia.Text = ds.Tables(0).Rows(0).Item("cust_instaddress")
+ txtscip.Text = ds.Tables(0).Rows(0).Item("cust_instpostcode")
+ txtschtn.Text = ds.Tables(0).Rows(0).Item("cust_hometelno")
+ txtscmtn.Text = ds.Tables(0).Rows(0).Item("cust_mobtelno")
+ txtscmpan.Text = ds.Tables(0).Rows(0).Item("cust_mpan")
+ txtscea.Text = ds.Tables(0).Rows(0).Item("cust_email")
+ End If
+
+ accCommand.Connection = frmLoginForm.accConnection
+ accCommand.CommandType = CommandType.Text
+ accCommand.CommandText = cmdString
+
+ End Sub
+
+ Private Sub btnClose_Click(ByVal sender As System.Object, _
+ ByVal e As System.EventArgs) Handles btnClose.Click
+ Me.Close()
+ frmReportSurvey.Show()
+ End Sub
+End Class
104 frmSwankyCode.vb
@@ -0,0 +1,104 @@
+Imports Microsoft.Office.Core
+Imports Microsoft.Office.Interop
+Imports Microsoft.Office.Interop.Word
+
+Public Class frmSwankyCode
+
+ 'This is a form because I couldn't work out how to make it work any
+ 'other way.
+
+ 'This is where all the code goes that is referenced from other subs
+ 'in other forms, to save space and attempt to minimise repetition.
+
+ Public Sub CheckAdditions(ByVal intInsert As Integer, _
+ ByRef btnSave As Button)
+
+ If intInsert = 0 Then
+ MsgBox("Data insertion failed.")
+ Else
+ 'Assume it went through OK and disable the Save button to
+ 'guard against duplication.
+ btnSave.Enabled = False
+ End If
+
+ End Sub
+
+ Public Sub WordInvoiceAutomationMagic(ByVal ict As String, ByVal icn As String, _
+ ByVal ica As String, ByVal icp As String)
+
+ Dim oWord As Word.Application
+ Dim oDoc As Word.Document
+ Dim CustAddressStuff As Word.Paragraph
+ Dim CustInvoiceHeader As Word.Paragraph
+
+ 'Start Word and open the document.
+ 'This is object stuff that I don't understand, but it was found on
+ 'a Microsoft doc, and the other stuff I tried didn't work, so I
+ 'used it.
+ oWord = CreateObject("Word.Application")
+ oWord.Visible = True
+ oDoc = oWord.Documents.Add
+
+ 'Insert the customer billing address stuff.
+ CustAddressStuff = oDoc.Content.Paragraphs.Add
+ CustAddressStuff.Range.Text = ict & " " & icn & Chr(11) & ica _
+ & Chr(11) & icp & Chr(11)
+ CustAddressStuff.Range.ParagraphFormat.Alignment = _
+ Word.WdParagraphAlignment.wdAlignParagraphRight
+ CustAddressStuff.Range.Font.Bold = False
+
+ 'Sort out the spacing afterwards.
+ CustAddressStuff.Format.SpaceAfter = 4
+ CustAddressStuff.Range.InsertParagraphAfter()
+
+ 'Now, after the spacing, the INVOICE header, centred.
+ CustInvoiceHeader = _
+ oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
+ CustInvoiceHeader.Range.Text = "INVOICE"
+ CustInvoiceHeader.Range.ParagraphFormat.Alignment = _
+ Word.WdParagraphAlignment.wdAlignParagraphCenter
+ CustInvoiceHeader.Range.Font.Size = 22
+ CustInvoiceHeader.Range.Font.Bold = True
+
+ End Sub
+
+ Public Sub WordQuotationAutomationMagic(ByVal qct As String, ByVal qcn As String, _
+ ByVal qca As String, ByVal qcp As String)
+
+ Dim oWord As Word.Application
+ Dim oDoc As Word.Document
+ Dim CustAddressStuff As Word.Paragraph
+ Dim CustQuotationHeader As Word.Paragraph
+
+ 'Start Word and open the document.
+ 'This is object stuff that I don't understand, but it was found on
+ 'a Microsoft doc, and the other stuff I tried didn't work, so I
+ 'used it.
+ oWord = CreateObject("Word.Application")
+ oWord.Visible = True
+ oDoc = oWord.Documents.Add
+
+ 'Insert the customer billing address stuff.
+ CustAddressStuff = oDoc.Content.Paragraphs.Add
+ CustAddressStuff.Range.Text = qct & " " & qcn & Chr(11) & qca _
+ & Chr(11) & qcp & Chr(11)
+ CustAddressStuff.Range.ParagraphFormat.Alignment = _
+ Word.WdParagraphAlignment.wdAlignParagraphRight
+ CustAddressStuff.Range.Font.Bold = False
+
+ 'Sort out the spacing afterwards.
+ CustAddressStuff.Format.SpaceAfter = 4
+ CustAddressStuff.Range.InsertParagraphAfter()
+
+ 'Now, after the spacing, the Quotation header, centred.
+ CustQuotationHeader = _
+ oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
+ CustQuotationHeader.Range.Text = "QUOTATION"
+ CustQuotationHeader.Range.ParagraphFormat.Alignment = _
+ Word.WdParagraphAlignment.wdAlignParagraphCenter
+ CustQuotationHeader.Range.Font.Size = 22
+ CustQuotationHeader.Range.Font.Bold = True
+
+ End Sub
+
+End Class

0 comments on commit 159371f

Please sign in to comment.