RecordOrganizer/app/DD-Record-Organiser/ModuleHelperMethods.vb
2015-12-09 12:26:22 +01:00

362 lines
11 KiB
VB.net

Module ModuleHelperMethods
Public Enum EnumFormat
[String] = 0
Currency = 1
[Decimal] = 2
End Enum
Public Function BoolToInt(bool As Boolean) As Integer
' Wandelt einen Boolean Wert in einen Int um
Return IIf(bool, 1, 0)
End Function
Public Function IntToBool(int As Integer) As Boolean
If int = 0 Then
Return False
ElseIf int = 1 Then
Return True
Else
Throw New Exception("IntToBool expects an Integer value that is either 0 or 1")
End If
End Function
Public Function ColorToInt(color As Color) As Integer
Return System.Drawing.ColorTranslator.ToWin32(color)
End Function
Public Function IntToColor(int As Integer) As Color
Return System.Drawing.ColorTranslator.FromWin32(int)
End Function
Public Function StrToBool(str As Object) As Boolean
Dim result As Boolean = False
str = TryCast(str, String)
Try
result = Convert.ToBoolean(str)
Catch ex As Exception
result = False
End Try
Return result
End Function
Public Function ByteArrayToBitmap(bytearray() As Byte) As Bitmap
Return New Bitmap(New System.IO.MemoryStream(bytearray))
End Function
Public Function StringToByteArray(ByVal hex As String) As Byte()
Dim NumberChars As Integer = hex.Length
Dim bytes(NumberChars / 2) As Byte
For i As Integer = 0 To NumberChars - 1 Step 2
bytes(i / 2) = Convert.ToByte(hex.Substring(i, 2), 16)
Next
Return bytes
End Function
Public Function BitmapToByteArray(bitmap As Bitmap) As Byte()
Dim bytearray As Byte()
Using stream As New System.IO.MemoryStream
bitmap.Save(stream, bitmap.RawFormat)
bytearray = stream.ToArray()
End Using
Return bytearray
End Function
Public Function IsGroupBox(c As Control)
Return c.GetType().Name = "GroupBox"
End Function
Public Function ParentIsGroupBox(c As Control)
Return c.Parent.GetType().Name = "GroupBox"
End Function
''' <summary>
''' Checks if a property exists on an object
''' </summary>
''' <param name="obj">The Object to check</param>
''' <param name="prop">The Property to check for</param>
''' <returns>True, if prop exists</returns>
Public Function propExists(ByVal obj As Object, ByVal prop As String) As Boolean
Dim type As Type = obj.GetType
Return type.GetProperty(prop) IsNot Nothing
End Function
Public Function propExistsWithType(ByVal obj As Object, ByVal prop As String, returnType As System.Type)
Dim type As Type = obj.GetType
Return type.GetProperty(prop, returnType) IsNot Nothing
End Function
''' <summary>
''' Gets a ControlID from Control Name
''' </summary>
''' <param name="name">Control Name</param>
''' <param name="formid">Current Form ID</param>
''' <returns>Control ID</returns>
Public Function GetControlID_for_Name(name As String, formid As Integer) As Integer
Try
Dim SQL = "SELECT GUID FROM TBPMO_CONTROL WHERE FORM_ID = " & formid & " and NAME = '" & name & "'"
Dim ID As Integer = ClassDatabase.Execute_Scalar(SQL)
If ID > 0 Then
Return ID
Else
Return -1
End If
Catch ex As Exception
MsgBox("Error in GetControlID_for_Name:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Function
Public Function GetControlID_for_RecordID(name As String, recID As Integer) As Integer
Try
Dim SQL = "SELECT CONTROL_ID FROM VWPMO_VALUES WHERE RECORD_ID = " & recID & " and CONTROL_NAME = '" & name & "'"
If LogErrorsOnly = False Then ClassLogger.Add(">> " & SQL, False)
Dim ID As Integer = ClassDatabase.Execute_Scalar(SQL)
If ID > 0 Then
Return ID
Else
If LogErrorsOnly = False Then ClassLogger.Add(">> es konnte keine ID für name geholt werden: " & SQL, False)
Return -1
End If
Catch ex As Exception
MsgBox("Error in GetControlID:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Function
''' <summary>
''' Gets a Control Name from ControlID
''' </summary>
''' <param name="Id">ControlID</param>
''' <param name="formid">Current Form ID</param>
''' <returns>Control Name</returns>
Public Function GetName_for_ControlID(Id As Integer, formid As Integer) As String
Try
Dim SQL = "SELECT NAME FROM TBPMO_CONTROL WHERE FORM_ID = " & formid & " AND GUID = " & Id
Dim Name = ClassDatabase.Execute_Scalar(SQL)
Return Name
Catch ex As Exception
MsgBox("Error in GetName_for_ControlID:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return False
End Try
End Function
Public Sub OpenFormInputFor(FormID As Integer, ScreenID As Integer)
CURRENT_FORM_ID = FormID
CURRENT_SCREEN_ID = ScreenID
Dim frm As New frmFormInput
frm.MdiParent = MAIN_FORM
frm.Show()
frm.BringToFront()
End Sub
Public Sub OpenFormCalendar()
Dim frm As New frmCalendar
frm = frmCalendar.Instance()
If My.Settings.User_Calendar_isChild = True Then
frm.MdiParent = MAIN_FORM
End If
frm.Show()
End Sub
Public Sub OpenFormOverview()
For i = System.Windows.Forms.Application.OpenForms.Count - 1 To 1 Step -1
Dim form As Form = System.Windows.Forms.Application.OpenForms(i)
form.WindowState = FormWindowState.Normal
Next i
Dim frm As New frmForm_Overview
frm = frmForm_Overview.Instance()
frm.MdiParent = MAIN_FORM
frm.Show()
End Sub
Public Sub OpenFormLevelDesigner()
For i = System.Windows.Forms.Application.OpenForms.Count - 1 To 1 Step -1
Dim form As Form = System.Windows.Forms.Application.OpenForms(i)
form.WindowState = FormWindowState.Normal
Next i
Dim frm As New frmLevel_Designer
frm = frmLevel_Designer.Instance
frm.MdiParent = MAIN_FORM
frm.Show()
Dim frm2 As New frmTool_ControlDesigner
frm2 = frmTool_ControlDesigner.Instance
If My.Settings.User_DesignPanels_areChild = True Then
frm2.MdiParent = MAIN_FORM
End If
frm2.Show()
Dim frm3 As New frmTool_ControlProperties
frm3 = frmTool_ControlProperties.Instance
If My.Settings.User_DesignPanels_areChild = True Then
frm3.MdiParent = MAIN_FORM
End If
frm3.Show()
End Sub
Public Sub OpenFormConstructor(id As Integer)
CURRENT_CONSTRUCTOR_ID = id
Dim frm As New frmForm_Constructor()
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.MdiParent = MAIN_FORM
frm.Show()
' frm = frmForm_Constructor.Instance()
End Sub
' TODO: NUR FÜR WINDREAM CON!!!
Public Sub OpenFormConstructorDemo(id As Integer)
Try
CURRENT_CONSTRUCTOR_ID = id
Dim frm As New frmForm_Constructor_Main_2()
' frm = frmForm_Constructor.Instance()
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.MdiParent = MAIN_FORM
frm.Show()
Catch ex As Exception
ClassLogger.Add(ex)
MsgBox("Fehler beim Laden des Formulars, bitte erneut versuchen")
End Try
End Sub
' TODO: NUR FÜR WINDREAM CON!!!
Public Sub OpenTaskmanagement()
Dim frm As New frmTaskmanagement
frm = frmTaskmanagement.Instance()
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Sub OpenDokumentartt()
Dim frm As New frmDokumentart_Konfig
frm = frmDokumentart_Konfig.Instance()
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Sub OpenMenuDesigner()
Dim frm As New frmMenuDesigner
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Sub OpenUserKonfig()
Dim frm As New frmUserKonfig
frm = frmUserKonfig.Instance()
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Sub OpenImageManager()
Dim frm As New frmQuickAccessManager
'frm = frmImageManager.Instance()
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Sub OpenObjecttypeConfig()
Dim frm As New frmObjecttypeConfig
frm = frmObjecttypeConfig.Instance()
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Sub OpenWiedervorlage()
Dim frm As New frmWiedervorlage
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Sub OpenLogRecord()
Dim frm As New frmLogRecord
frm = frmLogRecord.Instance()
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Sub OpenTemplatemanagement()
Dim frm As New frmTemplates
frm.MdiParent = MAIN_FORM
Dim activeChild As Form = MAIN_FORM.ActiveMdiChild
If activeChild IsNot Nothing Then
activeChild.WindowState = FormWindowState.Normal
End If
frm.Show()
End Sub
Public Function ShortGUID() As String
Return Guid.NewGuid().ToString().GetHashCode().ToString("x")
End Function
End Module