8848fffjjfj

EmployeeMenu

May 8th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 23.42 KB | None | 0 0
  1. Public Class EmployeeMenu
  2.  
  3.     Private Sub btnLogout_Click(sender As Object, e As EventArgs) Handles btnLogout.Click
  4.         con.Close()
  5.         Me.Close()
  6.         FormLogin.Show()
  7.         FormLogin.Refresh()
  8.     End Sub
  9.  
  10.     Private Sub cmbSTTitles_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbSTTitles.SelectedIndexChanged
  11.         txtTitle.Clear()
  12.  
  13.         If cmbSTTitles.Text = "Other" Then
  14.             txtTitle.Enabled = True     'show and enable custom title text box when other is selected
  15.             txtTitle.Visible = True
  16.         Else
  17.             txtTitle.Visible = False    'hide and disable custom title text box when other isn't selected
  18.             txtTitle.Enabled = False
  19.         End If
  20.     End Sub
  21.  
  22.     Private Sub EmployeeMenu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  23.  
  24.         Me.CenterToScreen() 'Opens form in the centre of the screen
  25.         Dim TotalTickets As String
  26.  
  27.         Dim sql As String
  28.         sql = "SELECT COUNT(*) FROM tblSubmitted_Ticket_Details WHERE Employee_ID = '" & UserIDDatabase & "'" 'Counts number of tickets send to display "x number Of tickets have been sent"
  29.         db.connect()
  30.         ds = db.sqlTotalTickets(sql)
  31.  
  32.         db.Close()
  33.  
  34.         TotalTickets = (ds.Tables("TotalTickets").Rows(0).Item(0))
  35.         lblOverviewAmountSent.Text = TotalTickets & " tickets have been sent in total"
  36.  
  37.         LoadSentTickets()
  38.         lstSentTicketsBubbleSort()  'Bubble sort algorithm to sort lstSentTickets listview by most recent date
  39.         LoadLastTicket()
  40.         LoadTicketReplies()
  41.         lstTicketRepliesBubbleSort()    'Bubble sort algorithm to sort lstTicketReplies listview by most recent date
  42.         con.Close()
  43.  
  44.     End Sub
  45.     'Below are the functions to display the sent tickets, last ticket sent, and the ticket replies from the access tables into
  46.     'three different listview controls. I have put this into a function so that I can recall it without typing out the
  47.     'whole code again, making the code more efficient and being more time efficient for me: the programmer
  48.  
  49.     Public Function LoadSentTickets()
  50.         Dim recordCount As Integer
  51.         Dim XCounter As Integer = 0
  52.  
  53.         Dim sql As String = "SELECT Ticket_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, Ticket_Solved FROM tblSubmitted_Ticket_Details ORDER BY Ticket_Date ASC" 'Function to load data into listview ordered by the time
  54.         db.connect()
  55.         ds = db.sqltblSubmitted_Ticket_Details(sql)
  56.         db.Close()
  57.  
  58.         recordCount = ds.Tables("tblSubmitted_Ticket_Details").Rows.Count
  59.         lstSentTickets.Items.Clear()
  60.         Do Until XCounter = recordCount
  61.             lstSentTickets.Items.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(0))
  62.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(1))
  63.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(2))
  64.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(3))
  65.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(4))
  66.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(5))
  67.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(6))
  68.             XCounter = XCounter + 1
  69.         Loop
  70.  
  71.         Return lstSentTickets.Text
  72.     End Function
  73.     Public Function LoadLastTicket()
  74.         Dim recordCount As Integer
  75.         Dim XCounter As Integer = 0
  76.  
  77.         Dim sql As String = "SELECT Ticket_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, Ticket_Solved FROM " _
  78.         & "tblSubmitted_Ticket_Details WHERE Employee_ID = '" & UserIDDatabase & "' ORDER BY Ticket_Date DESC" 'Function to load data into listview ordered by the time
  79.         db.connect()
  80.         ds = db.sqltblSubmitted_Ticket_Details(sql)
  81.         db.Close()
  82.  
  83.         recordCount = ds.Tables("tblSubmitted_Ticket_Details").Rows.Count
  84.         If (ds.Tables("tblSubmitted_Ticket_Details").Rows.Count) = 0 Then
  85.  
  86.         Else
  87.             lstLastTicket.Items.Clear()
  88.             'Do Until XCounter = recordCount
  89.             lstLastTicket.Items.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(0))
  90.             lstLastTicket.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(1))
  91.             lstLastTicket.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(2))
  92.             lstLastTicket.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(3))
  93.             lstLastTicket.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(4))
  94.             lstLastTicket.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(5))
  95.             lstLastTicket.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(6))
  96.             XCounter = XCounter + 1
  97.             ' Loop 'No loop = no more than 1 record showing
  98.         End If
  99.  
  100.         Return lstLastTicket.Text
  101.     End Function
  102.     Public Function LoadTicketReplies()
  103.  
  104.         Dim recordCount As Integer
  105.         Dim XCounter As Integer = 0
  106.  
  107.  
  108.         Dim sql As String = "SELECT Reply_ID, TechSupport_ID, Reply_Description, Reply_Date FROM tblTicket_Reply_Details " _
  109.         & "WHERE tblTicket_Reply_Details.Employee_ID = '" & UserIDDatabase & "'"
  110.  
  111.         db.connect()
  112.         ds = db.sqlDetails(sql)
  113.         db.Close()
  114.  
  115.         '#Region "Add items to listview loop"
  116.         recordCount = ds.Tables("Details").Rows.Count
  117.         lstTicketReplies.Items.Clear()
  118.         Do Until XCounter = recordCount
  119.             lstTicketReplies.Items.Add(ds.Tables("Details").Rows(XCounter).Item(0))
  120.             lstTicketReplies.Items(XCounter).SubItems.Add(ds.Tables("Details").Rows(XCounter).Item(1))
  121.             lstTicketReplies.Items(XCounter).SubItems.Add(ds.Tables("Details").Rows(XCounter).Item(2))
  122.             lstTicketReplies.Items(XCounter).SubItems.Add(ds.Tables("Details").Rows(XCounter).Item(3))
  123.  
  124.             XCounter = XCounter + 1
  125.         Loop
  126.         '#End Region
  127.  
  128.         Return lstTicketReplies
  129.     End Function
  130.  
  131.     Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
  132.         '#Region "Control Variables"
  133.         Dim Title, TitleOther, ComputerID, Department, DepartmentOther, Desc, SystemDate, TicketDeadline As String
  134.         Dim NullDate As Date
  135.         NullDate = #12/31/9999 11:59:59#
  136.         Title = cmbSTTitles.Text
  137.         TitleOther = txtTitle.Text
  138.         Desc = txtSTDescription.Text
  139.         SystemDate = lblSTDate.Text
  140.         TicketDeadline = dtpDeadline.Value.ToString
  141.         Department = cmbDepartment.Text
  142.         DepartmentOther = txtDepartmentOther.Text
  143.         'Declaring the controls on the submit ticket screen (variables)
  144.         '#End Region
  145.  
  146.         '#Region "PRESENCE CHECKS FOR ALL POSSIBLE COMBINATIONS WITH SQLs"
  147.  
  148.         'if the combobox is "Other" then use the sql to include the custom text box instead of the combo box
  149.         'but if the combolist isn't "other" or "" then it is everything else in there, so if all of the other text is filled in, the sql
  150.         'without the custom text box is used as the items in the combobox is recognised as anything that isn't "other" and ""
  151.  
  152.  
  153.         If cmbSTTitles.Text = "" Or cmbDepartment.Text = "" Or txtSTDescription.Text = "" Or dtpDeadline.Value < SystemDate Then
  154.             MsgBox("You haven't filled in all of the required fields, please recheck your submission.") 'If something hasn't been filled in, tell the user and do not send a ticket
  155.         ElseIf cmbSTTitles.Text = "Other" And (txtTitle.Text = "" Or txtSTDescription.Text = "" Or dtpDeadline.Value < SystemDate) Then
  156.             MsgBox("You haven't filled in all of the required fields, please recheck your submission.")
  157.         ElseIf cmbDepartment.Text = "Other" And (txtSTDescription.Text = "" Or dtpDeadline.Value < SystemDate) Then
  158.             MsgBox("You haven't filled in all of the required fields, please recheck your submission.")
  159.         ElseIf cmbSTTitles.Text = "Other" And cmbDepartment.Text = "Other" And (txtTitle.Text = "" Or txtDepartmentOther.Text = "" Or txtSTDescription.Text = "") Then
  160.             MsgBox("You haven't filled in all of the required fields, please recheck your submission.")
  161.         ElseIf cmbSTTitles.Text = "Other" And cmbDepartment.Text = "Other" Then
  162.  
  163.  
  164.             Dim sql As String
  165.             sql = "SELECT Computer_ID FROM tblEmployee_Details WHERE Employee_ID = '" & UserIDDatabase & "'"
  166.             db.connect()
  167.             ds = db.sqlComputerID(sql)
  168.             db.Close()
  169.  
  170.             ComputerID = (ds.Tables("ComputerID").Rows(0).Item(0))    'Navigates to value in ds array and stores it as a string variable
  171.  
  172.             Dim sql2 As String
  173.             sql2 = "INSERT INTO tblSubmitted_Ticket_Details (Employee_ID, Computer_ID, Ticket_Title, Department, Ticket_Description, Ticket_Date, Ticket_Deadline, " _
  174.             & "Ticket_SolveDate) VALUES ('" & UserIDDatabase & "','" & ComputerID & "','" & TitleOther & " ',' " & DepartmentOther & " ',' " & Desc & "','" & SystemDate & "','" & TicketDeadline & "','" & NullDate & "')"
  175.             db.connect()
  176.             ds = db.sqltblSubmitted_Ticket_DetailsSql2(sql2)
  177.             db.Close()
  178.  
  179.             MsgBox("Ticket sent successfully!")
  180.             tabOverview.Show()  'Automatically navigates back to the homescreen
  181.             ClearSendTicketFields() 'Delete the text in the fields so nothing is in them
  182.  
  183.         ElseIf cmbSTTitles.Text = "Other" Then
  184.             Dim sql As String
  185.             sql = "SELECT Computer_ID FROM tblEmployee_Details WHERE Employee_ID = '" & UserIDDatabase & "'"
  186.             db.connect()
  187.             ds = db.sqlComputerID(sql)
  188.             db.Close()
  189.  
  190.             ComputerID = (ds.Tables("ComputerID").Rows(0).Item(0))    'Navigates to value in ds array and stores it as a string variable
  191.  
  192.             Dim sql2 As String
  193.             sql2 = "INSERT INTO tblSubmitted_Ticket_Details (Employee_ID, Computer_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, " _
  194.             & "Ticket_SolveDate) VALUES ('" & UserIDDatabase & "','" & ComputerID & "','" & Department & "','" & TitleOther & "','" & Desc & "','" & SystemDate & "','" & TicketDeadline & "','" & NullDate & "')"
  195.             db.connect()
  196.             ds = db.sqltblSubmitted_Ticket_DetailsSql2(sql2)
  197.             db.Close()
  198.  
  199.             MsgBox("Ticket sent successfully!")
  200.             tabOverview.Show()  'Automatically navigates back to the homescreen
  201.             ClearSendTicketFields() 'Delete the text in the fields so nothing is in them
  202.  
  203.         ElseIf cmbDepartment.Text = "Other" Then
  204.             Dim sql As String
  205.             sql = "SELECT Computer_ID FROM tblEmployee_Details WHERE Employee_ID = '" & UserIDDatabase & "'"
  206.             db.connect()
  207.             ds = db.sqlComputerID(sql)
  208.             db.Close()
  209.             ComputerID = (ds.Tables("ComputerID").Rows(0).Item(0))    'Navigates to value in ds array and stores it as a string variable
  210.  
  211.             Dim sql2 As String
  212.             sql2 = "INSERT INTO tblSubmitted_Ticket_Details (Employee_ID, Computer_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, " _
  213.             & "Ticket_SolveDate) VALUES ('" & UserIDDatabase & "','" & ComputerID & "','" & DepartmentOther & "','" & Title & " ',' " & Desc & "','" & SystemDate & "','" & TicketDeadline & "','" & NullDate & "')"
  214.             db.connect()
  215.             ds = db.sqltblSubmitted_Ticket_DetailsSql2(sql2)
  216.             db.Close()
  217.  
  218.             MsgBox("Ticket sent successfully!")
  219.             tabOverview.Show()  'Automatically navigates back to the homescreen
  220.             ClearSendTicketFields() 'Delete the text in the fields so nothing is in them
  221.  
  222.         Else
  223.  
  224.             Dim sql As String
  225.             sql = "SELECT Computer_ID FROM tblEmployee_Details WHERE Employee_ID = '" & UserIDDatabase & "'"
  226.             db.connect()
  227.             ds = db.sqlComputerID(sql)
  228.             db.Close()
  229.  
  230.             ComputerID = (ds.Tables("ComputerID").Rows(0).Item(0))    'Navigates to value in ds array and stores it as a string variable
  231.  
  232.             Dim sql2 As String
  233.             sql2 = "INSERT INTO tblSubmitted_Ticket_Details (Employee_ID, Computer_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, " _
  234.             & "Ticket_SolveDate) VALUES ('" & UserIDDatabase & "','" & ComputerID & "','" & Department & "','" & Title & "','" & Desc & "','" & SystemDate & "','" & TicketDeadline & "','" & NullDate & "')"
  235.             db.connect()
  236.             ds = db.sqltblSubmitted_Ticket_DetailsSql2(sql2)
  237.             db.Close()
  238.  
  239.             MsgBox("Ticket sent successfully!")
  240.             tabOverview.Show()  'Automatically navigates back to the homescreen
  241.             ClearSendTicketFields() 'Delete the text in the fields so nothing is in them
  242.  
  243.         End If
  244.         '#End Region
  245.  
  246.         LoadSentTickets()
  247.         lstSentTicketsBubbleSort()
  248.         LoadLastTicket()
  249.         con.Close()
  250.  
  251.     End Sub
  252.  
  253.     Private Sub tmrDate_Tick(sender As Object, e As EventArgs) Handles tmrDate.Tick
  254.         lblSTDate.Text = Format(Now, "dd/MM/yyyy HH:mm") 'Shows current system date - updates once per second
  255.         lblOverviewDate.Text = "The current date is " & Format(Now, "dd/MM/yyyy HH:mm:ss") 'Shows current system date along with "the current time is" - updates once per second
  256.     End Sub
  257.  
  258.     Private Sub btnLoadReplies_Click(sender As Object, e As EventArgs)
  259.         LoadSentTickets()
  260.         lstSentTicketsBubbleSort()
  261.     End Sub
  262.  
  263.     Private Sub cmbDepartment_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbDepartment.SelectedIndexChanged
  264.         txtDepartmentOther.Clear()
  265.  
  266.         If cmbDepartment.Text = "Other" Then
  267.             txtDepartmentOther.Enabled = True
  268.             txtDepartmentOther.Visible = True
  269.         Else                                  'Department combobox will only be visible when "Other" is selected from "Area of business/department"
  270.             txtDepartmentOther.Enabled = False
  271.             txtDepartmentOther.Visible = False
  272.         End If
  273.     End Sub
  274.  
  275.     Private Sub btnMyTicketSearch_Click(sender As Object, e As EventArgs) Handles btnMyTicketSearch.Click
  276.         SearchSentTickets()
  277.     End Sub
  278.  
  279.     Private Sub txtTicketSearchOther_TextChanged(sender As Object, e As EventArgs) Handles txtTicketSearchOther.TextChanged
  280.         SearchSentTickets()
  281.     End Sub
  282.  
  283.     Private Sub cmbTicketSearch_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbTicketSearch.SelectedIndexChanged
  284.         txtTicketSearchOther.Clear()
  285.  
  286.         Dim TicketSearch As String = cmbTicketSearch.Text
  287.         Dim TicketSearchOther As String = txtTicketSearchOther.Text
  288.  
  289.         If cmbTicketSearch.Text = "Other" Then
  290.             txtTicketSearchOther.Enabled = True
  291.             txtTicketSearchOther.Visible = True
  292.         Else
  293.             txtTicketSearchOther.Enabled = False
  294.             txtTicketSearchOther.Visible = False
  295.         End If
  296.         SearchSentTickets()
  297.     End Sub
  298.  
  299.     Private Sub btnRefreshReplies_Click(sender As Object, e As EventArgs) Handles btnRefreshReplies.Click
  300.         LoadTicketReplies()
  301.         lstTicketRepliesBubbleSort()
  302.     End Sub
  303.  
  304.     'Functions to be recalled so code is more efficient and not repeated
  305.     Function SearchSentTickets()
  306.  
  307.         Dim sql As String
  308.         Dim recordCount As Integer
  309.         Dim XCounter As Integer = 0
  310.         Dim TicketSearch As String = cmbTicketSearch.Text
  311.         Dim TicketSearchOther As String = txtTicketSearchOther.Text
  312.  
  313.  
  314.         If cmbTicketSearch.Text = "Other" Then
  315.  
  316.             sql = "SELECT Ticket_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, Ticket_Solved FROM tblSubmitted_Ticket_Details WHERE Ticket_Title LIKE '%" & TicketSearchOther & "%' ORDER BY Ticket_Date ASC"
  317.         ElseIf cmbTicketSearch.Text = "All" Then
  318.             sql = "SELECT Ticket_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, Ticket_Solved FROM tblSubmitted_Ticket_Details ORDER BY Ticket_Date ASC"
  319.         Else
  320.             sql = "SELECT Ticket_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, Ticket_Solved FROM tblSubmitted_Ticket_Details WHERE Ticket_Title LIKE '%" & TicketSearch & "%' ORDER BY Ticket_Date ASC"
  321.         End If
  322.  
  323.         'listview will load records from the text in the combobox but if 'other' is selected in the combo box it will search by the textbox instead
  324.         If cmbTicketSearch.Text = "" Then
  325.             sql = "SELECT Ticket_ID, Department, Ticket_Title, Ticket_Description, Ticket_Date, Ticket_Deadline, Ticket_Solved FROM tblSubmitted_Ticket_Details ORDER BY Ticket_Date ASC"
  326.         End If
  327.         db.connect()
  328.         ds = db.sqltblSubmitted_Ticket_Details(sql)
  329.         db.Close()
  330.  
  331.         'If nothing is typed in, then the listview will load all records from the table
  332.         '#Region "Add items to list view loop"
  333.  
  334.         recordCount = ds.Tables("tblSubmitted_Ticket_Details").Rows.Count
  335.         lstSentTickets.Items.Clear()
  336.         Do Until XCounter = recordCount
  337.             lstSentTickets.Items.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(0))
  338.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(1))
  339.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(2))
  340.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(3))
  341.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(4))
  342.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(5))
  343.             lstSentTickets.Items(XCounter).SubItems.Add(ds.Tables("tblSubmitted_Ticket_Details").Rows(XCounter).Item(6))
  344.             XCounter = XCounter + 1
  345.         Loop
  346.         '#End Region
  347.         con.Close() 'Closes the connection
  348.         lstSentTicketsBubbleSort()  'After the items are re-added to the listview, sort them again using this bubble sort algorithm
  349.  
  350.         Return lstSentTickets
  351.     End Function
  352.  
  353.     Function lstSentTicketsBubbleSort()
  354.         'Bubble sort algorithm to sort listview by newest date first
  355.         Dim Sorted As Boolean = False
  356.  
  357.         Do While Sorted = False 'While the list is not sorted
  358.             Sorted = True 'The list is sorted until otherwise stated
  359.  
  360.             For ItemPosition As Integer = 0 To lstSentTickets.Items.Count - 2 'Go through each item in listv
  361.  
  362.                 If CDate(lstSentTickets.Items(ItemPosition).SubItems(4).Text) < CDate(lstSentTickets.Items(ItemPosition + 1).SubItems(4).Text) Then 'If first item is smaller than next item
  363.  
  364.                     Dim tempName As String = lstSentTickets.Items(ItemPosition + 1).Text 'Set the placeholder to hold the current item
  365.                     Dim tempSubItems(3) 'Create an array for the sub items sub item. 5 instead of 6 as array starts at 0
  366.                     For SubItem As Integer = 1 To 4 'For each sub item in the current item
  367.                         tempSubItems(SubItem - 1) = lstSentTickets.Items(ItemPosition + 1).SubItems(SubItem).Text 'Set the array entry to be equal to that of its corresponding subitem
  368.                     Next
  369.  
  370.                     lstSentTickets.Items(ItemPosition + 1).Text = lstSentTickets.Items(ItemPosition).Text 'Set the current item text as equal to the next item
  371.                     For SubItem As Integer = 1 To 4 'For each sub item in the current item
  372.                         lstSentTickets.Items(ItemPosition + 1).SubItems(SubItem).Text = lstSentTickets.Items(ItemPosition).SubItems(SubItem).Text 'Set the array entry to be equal to that of its corresponding subitem
  373.                     Next
  374.  
  375.                     lstSentTickets.Items(ItemPosition).Text = tempName 'Set the next item to be the placeholder (what the old value was)
  376.                     For SubItem As Integer = 1 To 4 'For each subitem in the temporary subitems array
  377.                         lstSentTickets.Items(ItemPosition).SubItems(SubItem).Text = tempSubItems(SubItem - 1) 'Set the array entry to be equal to that of its corresponding temporary subitem
  378.                     Next
  379.                     'This rotates / swaps the two values
  380.                     Sorted = False 'Show that the list was not sorted and another check needs to be performed
  381.                 End If
  382.             Next
  383.         Loop
  384.         Return lstSentTickets
  385.     End Function
  386.  
  387.     Function lstTicketRepliesBubbleSort()
  388.         'Bubble sort algorithm to sort listview by newest date first
  389.         Dim Sorted As Boolean = False
  390.  
  391.         Do While Sorted = False 'While the list is not sorted
  392.             Sorted = True 'The list is sorted until otherwise stated
  393.  
  394.             For ItemPosition As Integer = 0 To lstTicketReplies.Items.Count - 2 'Go through each item in listv
  395.  
  396.                 If CDate(lstTicketReplies.Items(ItemPosition).SubItems(3).Text) < CDate(lstTicketReplies.Items(ItemPosition + 1).SubItems(3).Text) Then 'If first item is smaller than next item
  397.  
  398.                     Dim tempName As String = lstTicketReplies.Items(ItemPosition + 1).Text 'Set the placeholder to hold the current item
  399.                     Dim tempSubItems(3) 'Create an array for the sub items sub item. 5 instead of 6 as array starts at 0
  400.                     For SubItem As Integer = 1 To 3 'For each sub item in the current item
  401.                         tempSubItems(SubItem - 1) = lstTicketReplies.Items(ItemPosition + 1).SubItems(SubItem).Text 'Set the array entry to be equal to that of its corresponding subitem
  402.                     Next
  403.  
  404.                     lstTicketReplies.Items(ItemPosition + 1).Text = lstTicketReplies.Items(ItemPosition).Text 'Set the current item text as equal to the next item
  405.                     For SubItem As Integer = 1 To 3 'For each sub item in the current item
  406.                         lstTicketReplies.Items(ItemPosition + 1).SubItems(SubItem).Text = lstTicketReplies.Items(ItemPosition).SubItems(SubItem).Text 'Set the array entry to be equal to that of its corresponding subitem
  407.                     Next
  408.  
  409.                     lstTicketReplies.Items(ItemPosition).Text = tempName 'Set the next item to be the placeholder (what the old value was)
  410.                     For SubItem As Integer = 1 To 3 'For each subitem in the temporary subitems array
  411.                         lstTicketReplies.Items(ItemPosition).SubItems(SubItem).Text = tempSubItems(SubItem - 1) 'Set the array entry to be equal to that of its corresponding temporary subitem
  412.                     Next
  413.                     'This rotates / swaps the two values
  414.                     Sorted = False 'Show that the list was not sorted and another check needs to be performed
  415.                 End If
  416.             Next
  417.         Loop
  418.         Return lstTicketReplies
  419.     End Function
  420.  
  421.     Function ClearSendTicketFields()
  422.         txtDepartmentOther.Clear()
  423.         cmbSTTitles.SelectedIndex = 0
  424.         txtTitle.Clear()
  425.         txtSTDescription.Clear()
  426.         Return TechSupportMenu
  427.     End Function
  428.  
  429. End Class
Add Comment
Please, Sign In to add comment