|
- <%
- Class PurpleEnvelopeReportHelper_Class
-
- Public Function FormatElectionLabel(ByVal rawValue)
- FormatElectionLabel = Trim(rawValue & "")
- If Len(FormatElectionLabel) = 0 Then Exit Function
-
- On Error Resume Next
- dim parsedDate : parsedDate = CDate(rawValue)
- If Err.Number = 0 Then
- FormatElectionLabel = MonthName(Month(parsedDate), True) & "-" & CStr(Year(parsedDate))
- Else
- Err.Clear
- End If
- On Error GoTo 0
- End Function
-
- Public Function SortPrecinctColorRows(ByVal rs)
- dim list : set list = new LinkedList_Class
- If rs.EOF Then
- set SortPrecinctColorRows = list
- Exit Function
- End If
-
- dim items()
- dim itemCount : itemCount = -1
- Do Until rs.EOF
- itemCount = itemCount + 1
- ReDim Preserve items(itemCount)
-
- dim row : set row = new PrecinctColorRow_ViewModel_Class
- row.PRECINCT = rs("PRECINCT")
- If IsNull(rs("ColorId")) Then
- row.ColorId = ""
- Else
- row.ColorId = rs("ColorId")
- End If
- Set items(itemCount) = row
- rs.MoveNext
- Loop
-
- SortPrecinctItems items
-
- dim i
- For i = 0 To UBound(items)
- list.Push items(i)
- Next
-
- set SortPrecinctColorRows = list
- End Function
-
- Public Function SortPrecinctBallotRangeRows(ByVal rs)
- dim list : set list = new LinkedList_Class
- If rs.EOF Then
- set SortPrecinctBallotRangeRows = list
- Exit Function
- End If
-
- dim items()
- dim itemCount : itemCount = -1
- Do Until rs.EOF
- itemCount = itemCount + 1
- ReDim Preserve items(itemCount)
-
- dim row : set row = new PrecinctBallotRangeRow_ViewModel_Class
- row.PRECINCT = rs("PRECINCT")
- row.LowBallotNumber = rs("LowBallotNumber")
- row.HighBallotNumber = rs("HighBallotNumber")
- Set items(itemCount) = row
- rs.MoveNext
- Loop
-
- SortPrecinctItems items
-
- dim i
- For i = 0 To UBound(items)
- list.Push items(i)
- Next
-
- set SortPrecinctBallotRangeRows = list
- End Function
-
- Private Sub SortPrecinctItems(ByRef items)
- If Not IsArray(items) Then Exit Sub
-
- dim i, j
- For i = 0 To UBound(items) - 1
- For j = i + 1 To UBound(items)
- If PrecinctSortsBefore(items(j).PRECINCT, items(i).PRECINCT) Then
- dim temp : set temp = items(i)
- Set items(i) = items(j)
- Set items(j) = temp
- End If
- Next
- Next
- End Sub
-
- Private Function PrecinctSortsBefore(ByVal leftPrecinct, ByVal rightPrecinct)
- dim leftType, leftNumber, leftSuffix, leftNormalized
- dim rightType, rightNumber, rightSuffix, rightNormalized
-
- ParsePrecinctSortParts leftPrecinct, leftType, leftNumber, leftSuffix, leftNormalized
- ParsePrecinctSortParts rightPrecinct, rightType, rightNumber, rightSuffix, rightNormalized
-
- If leftType <> rightType Then
- PrecinctSortsBefore = (leftType < rightType)
- Exit Function
- End If
-
- If leftType = 0 Then
- If leftNumber <> rightNumber Then
- PrecinctSortsBefore = (leftNumber < rightNumber)
- Exit Function
- End If
-
- If leftSuffix <> rightSuffix Then
- PrecinctSortsBefore = (leftSuffix < rightSuffix)
- Exit Function
- End If
- End If
-
- If leftNormalized <> rightNormalized Then
- PrecinctSortsBefore = (leftNormalized < rightNormalized)
- Else
- PrecinctSortsBefore = (UCase(Trim(leftPrecinct & "")) < UCase(Trim(rightPrecinct & "")))
- End If
- End Function
-
- Private Sub ParsePrecinctSortParts(ByVal precinct, ByRef precinctType, ByRef numericPart, ByRef suffixPart, ByRef normalizedText)
- dim rawPrecinct : rawPrecinct = Trim(precinct & "")
- dim leadingDigits : leadingDigits = ""
- dim i, currentChar
-
- For i = 1 To Len(rawPrecinct)
- currentChar = Mid(rawPrecinct, i, 1)
- If currentChar >= "0" And currentChar <= "9" Then
- leadingDigits = leadingDigits & currentChar
- Else
- Exit For
- End If
- Next
-
- If Len(leadingDigits) > 0 Then
- precinctType = 0
- numericPart = CLng(leadingDigits)
- suffixPart = UCase(Trim(Mid(rawPrecinct, Len(leadingDigits) + 1)))
- normalizedText = CStr(numericPart) & "|" & suffixPart
- Else
- precinctType = 1
- numericPart = 0
- suffixPart = UCase(rawPrecinct)
- normalizedText = suffixPart
- End If
- End Sub
- End Class
-
- dim PurpleEnvelopeReportHelper__Singleton
- Function PurpleEnvelopeReportHelper()
- If IsEmpty(PurpleEnvelopeReportHelper__Singleton) Then
- set PurpleEnvelopeReportHelper__Singleton = new PurpleEnvelopeReportHelper_Class
- End If
- set PurpleEnvelopeReportHelper = PurpleEnvelopeReportHelper__Singleton
- End Function
- %>
|