86 lines
3.4 KiB
VB.net
86 lines
3.4 KiB
VB.net
Imports System.Text
|
|
Imports System.Text.RegularExpressions
|
|
|
|
Module ModuleHelpers
|
|
|
|
''' <summary>
|
|
''' Überprüft einen Wert auf verschiedene Arten von "Null" und gibt einen Standard-Wert zurück, wenn der Wert "Null" ist.
|
|
''' </summary>
|
|
''' <param name="value">Der zu überprüfende Wert</param>
|
|
''' <param name="defaultValue">Der Standard Wert</param>
|
|
''' <returns>value oder wenn dieser "Null" ist, defaultValue</returns>
|
|
Public Function NotNull(Of T)(ByVal value As T, ByVal defaultValue As T) As T
|
|
If IsNothing(value) OrElse String.IsNullOrEmpty(value.ToString) OrElse IsDBNull(value) Then
|
|
Return defaultValue
|
|
Else
|
|
Return value
|
|
End If
|
|
End Function
|
|
Public Function encode_utf8(ByVal str As String) As String
|
|
Try
|
|
'supply True as the construction parameter to indicate
|
|
'that you wanted the class to emit BOM (Byte Order Mark)
|
|
'NOTE: this BOM value is the indicator of a UTF-8 string
|
|
Dim utf8Encoding As New System.Text.UTF8Encoding(True)
|
|
Dim encodedString() As Byte
|
|
encodedString = utf8Encoding.GetBytes(str)
|
|
Return utf8Encoding.GetString(encodedString)
|
|
Catch ex As Exception
|
|
MsgBox("Unexpected error in encode_utf8: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
|
|
End Function
|
|
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
|
|
Try
|
|
Dim bytes() As Byte
|
|
' get unicode string as bytes
|
|
bytes = Encoding.UTF8.GetBytes(strData)
|
|
' return byte data
|
|
Return bytes
|
|
Catch ex As Exception
|
|
MsgBox("Unexpected error in StringAsUtf8Bytes: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
|
|
End Function
|
|
Public Function CheckSpecialSigns(ByVal str As String)
|
|
Try
|
|
Dim pattern As String = "[!""#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\s]"
|
|
Dim matches As MatchCollection = Regex.Matches(str, pattern)
|
|
Return matches.Count
|
|
Catch ex As Exception
|
|
MsgBox("Unexpected error in CheckSpecialSigns: " & ex.Message, MsgBoxStyle.Critical)
|
|
Return 0
|
|
End Try
|
|
End Function
|
|
Public Sub Refresh_RegexTable()
|
|
My.Application.BASE_DATA_DT_REGEX = My.Database.GetDatatable("SELECT * FROM TBGI_FUNCTION_REGEX")
|
|
End Sub
|
|
Public Function FilterDatatable(myDatatable As DataTable, myFilter As String, mycheckColumn As String, pSortString As String, returnDT As Boolean) As Object
|
|
Try
|
|
If myDatatable.Rows.Count = 0 Then
|
|
Return Nothing
|
|
End If
|
|
Dim dv As DataView = myDatatable.DefaultView
|
|
dv.RowFilter = myFilter
|
|
If dv.Count = 1 And returnDT = False Then
|
|
For Each rowView As DataRowView In dv
|
|
Dim row As DataRow = rowView.Row
|
|
Return row.Item(mycheckColumn)
|
|
Next
|
|
Else
|
|
Dim dt_copy As DataTable = New DataTable()
|
|
dt_copy = myDatatable.Select(myFilter, pSortString).CopyToDataTable()
|
|
|
|
Return dt_copy
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox("Unexpected error in FilterDatatable: " + ex.Message, MsgBoxStyle.Critical)
|
|
Return Nothing
|
|
End Try
|
|
|
|
End Function
|
|
|
|
End Module
|