Skip to content

Instantly share code, notes, and snippets.

@CalvinRodo
Created May 11, 2015 15:42
Show Gist options
  • Save CalvinRodo/d7db07a2668eb4039f88 to your computer and use it in GitHub Desktop.
Save CalvinRodo/d7db07a2668eb4039f88 to your computer and use it in GitHub Desktop.
rewrite assignments.vb
Imports System.Text
Public Class Assignments
'this object will perform our database interaction
Private ReadOnly _sqlbot As New SQLBot
'this will hold our tickets
'this will hold the tech that was selected in the last window
Private _currentTech As Tech
'this will hold the string built by our database query
Private ReadOnly _statement As New StringBuilder
Private Sub Assignments_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'first pull in the tag as an arraylist
Dim source As ArrayList = CType(Me.Tag, ArrayList)
GetCurrentTechInfo(source)
Dim tableOfTickets As DataTable = GetTickets(_currentTech.TechID.ToString, CType(source(0), String))
DisplayTickets(source(3), source(4), CType(source(2), String), CType(source(0), String), tableOfTickets)
End Sub
Private Sub GetCurrentTechInfo(source As ArrayList)
'hold a temp table of tech info
Dim techtable As DataTable
'set the tech into to the table
techtable = _sqlbot.returnDataTable(String.Format("SELECT * from Techs where TechID = {0}", source(1)))
'set the tech
_currentTech = New Tech(CStr(techtable.Rows(0).Item(1)), CStr(techtable.Rows(0).Item(2)), CStr(techtable.Rows(0).Item(3)), CInt(techtable.Rows(0).Item(4)), CInt(techtable.Rows(0).Item(0)))
End Sub
Private Sub DisplayTickets(startDate As Object, endDate As Object, assignee As String, ticketStatus As String, tickets As DataTable)
Dim output As String
'check if the user clicked pending or completed tickets
If tickets.Rows.Count = 0 Then
'check if the table is empty, if not show a genaric message
output = "Agent has no assignments"
Else
'add the first line of the txtbox
_statement.Append(String.Format("Showing tickets from {0} to {1}", CDate(startDate).ToShortDateString, CDate(endDate).ToShortDateString)).AppendLine()
'if not for each of the rows in the table
For Each row As DataRow In tickets.Rows
'add that information to the textbox in the specified order
_statement.Append(String.Format("Ticket ID: {0}", row.Item(0))).AppendLine()
_statement.Append(String.Format("Issue: {0} Reporter: {1} Date Submitted: {2} Severity: {3}", row.Item(1), row.Item(2), _
CDate(row.Item(4)).ToShortDateString, row.Item(5))).AppendLine()
_statement.Append(String.Format("Date Resolved: {0} Resolution {1}", row.Item(8), row.Item(9))).AppendLine()
Next
'set the output variable to the stringbuilder results
output = _statement.ToString
End If
'set the label to the reflect the current tech info
Me.Text = String.Format("{0} work for {1}", ticketStatus, assignee)
'pdate the txtbox
txtAssignments.Text = output
End Sub
Private Function GetTickets(currentTechID As String, ticketStatus As String) As DataTable
If (String.IsNullOrEmpty(ticketStatus)) Then
Return New DataTable()
End If
Dim resolved As String
If ticketStatus Is "Pending" Then
'fill the table with tickets
resolved = "0"
ElseIf ticketStatus Is "Completed" Then
'fill the table with tickets
resolved = "1"
Else
Throw New Exception("Unknown Ticket Status.")
End If
Return _sqlbot.returnDataTable(String.Format("SELECT * FROM Tickets WHERE assignment = {0} and resolved = {1} ORDER BY severity DESC", currentTechID, resolved))
End Function
Private Sub btnEmail_Click(sender As Object, e As EventArgs) Handles btnEmail.Click
'if the user clicks the email button, fill in the email with the subject and all of the assignments reflected in the box.
_currentTech.emailTicket("Your assigmments", _statement.ToString)
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment