Files
OrganLit/MyGlobals.vb
2026-03-07 19:38:21 -06:00

110 lines
4.1 KiB
VB.net

Imports System.Data.SqlClient
Imports System.IO
Imports System.Xml.Xsl
Imports System.Collections.Generic
Imports System.Windows.Forms
Public Class MyGlobals
Public Shared g_objDatabaseLayer As clsDatabaseLayer
Public Shared g_objCachedObjects As Hashtable
Public Shared g_objObjectTypesCached As New List(Of String)
Public Const COMPOSER_NAME_SIZE As Integer = 60
Public Const PUBLISHER_NAME_SIZE As Integer = 60
Public Const PUBLISHER_STREAMING_ALLOWED_SIZE As Integer = 7
Public Const HYMNAL_NAME_SIZE As Integer = 60
Public Const HYMNAL_ABBREVIATION_SIZE As Integer = 10
Public Const BOOK_TITLE_SIZE As Integer = 120
Public Const HYMN_TUNE_NAME_SIZE As Integer = 60
Public Const HYMN_NAME_SIZE As Integer = 120
Public Const WORK_NAME_SIZE As Integer = 150
Public Const OPUS_INFO_SIZE As Integer = 50
Public Const INSTRUMENTATION_NAME_SIZE As Integer = 60
Public Const COLLECTION_STRING As String = "(Collection)"
Public Const NONE_STRING As String = "(None)"
Public Const PUBLISHER_STREAMING_ALLOWED_UNKNOWN As String = "Unknown"
Public Shared Function GetItemFromHashWithStringKey(ByVal strKeyValue As String, ByVal objHash As Hashtable) As Object
If objHash.ContainsKey(strKeyValue) Then
Return objHash.Item(strKeyValue)
Else
Return Nothing
End If
End Function
Public Shared Sub FlushCachedObjects()
If g_objCachedObjects Is Nothing Then
g_objCachedObjects = New Hashtable
Else
g_objCachedObjects.Clear()
End If
g_objObjectTypesCached.Clear()
End Sub
Public Shared Sub AddCachedObject(ByRef objObject As Object, ByVal strKeyValue As String)
If g_objCachedObjects Is Nothing Then
FlushCachedObjects()
End If
If g_objCachedObjects.ContainsKey(strKeyValue) Then
g_objCachedObjects.Remove(strKeyValue)
End If
g_objCachedObjects.Add(strKeyValue, objObject)
End Sub
Public Shared Sub RemoveCachedObject(ByVal strKeyValue As String)
If g_objCachedObjects Is Nothing Then
FlushCachedObjects()
End If
If g_objCachedObjects.ContainsKey(strKeyValue) Then
g_objCachedObjects.Remove(strKeyValue)
End If
End Sub
Public Shared Function CachedObjectExists(ByVal strKeyValue As String) As Boolean
If g_objCachedObjects Is Nothing Then
FlushCachedObjects()
End If
Return g_objCachedObjects.ContainsKey(strKeyValue)
End Function
Public Shared Function CachedObjectRetrieve(ByVal strKeyValue As String) As Object
If g_objCachedObjects Is Nothing Then
FlushCachedObjects()
End If
Return GetItemFromHashWithStringKey(strKeyValue, g_objCachedObjects)
End Function
Public Shared Function AllowKeypressInNumericTextBox(ByVal sChar As Char) As Boolean
If Not Char.IsDigit(sChar) Then
Select Case Asc(sChar)
Case 8, 3, 24 '8=Backspace,3=ctrlC,24=ctrlX
'Let these through
Case 22 '22=ctrlV
If Clipboard.GetDataObject.GetDataPresent("System.String", True) Then
Dim sClipboardText As String
sClipboardText = Clipboard.GetDataObject.GetData("System.String", True).ToString
Dim sCharInClipboard As Char
For Each sCharInClipboard In sClipboardText
If Not Char.IsDigit(sCharInClipboard) Then
'There is a non-digit in the clipboard - don't allow the paste
Return False
End If
Next
Else
Return False
End If
Case Else
Return False
End Select
End If
Return True
End Function
End Class