Imports System.IO

Public Class ClassHelper
    Public Shared Function CheckDBNull(input As Object, back_Value As String)
        If IsDBNull(input) Then
            If back_Value = "String" Then
                Return ""
            Else
                Return True
            End If
        Else
            If back_Value = "String" Then
                Return input.ToString
            Else
                Return False
            End If
        End If
    End Function
    Public Shared Function Get_TempFilename()
        'Eine tempfile generieren
        Dim tempFilename = My.Computer.FileSystem.GetTempFileName()
        'Nur den Filenamen ohne Erweiterung
        Dim tempName = Path.GetDirectoryName(tempFilename) & "\" & Path.GetFileNameWithoutExtension(tempFilename)
        'tempfile lsöchen
        If My.Computer.FileSystem.FileExists(tempFilename) Then
            My.Computer.FileSystem.DeleteFile(tempFilename)
        End If
        Return tempName
    End Function
    Public Shared Function CheckFileIsInUse(ByVal filename) As Boolean
        Dim fs As Integer = FreeFile()
        Dim inuse As Boolean = False
        If File.Exists(filename) Then
           Try
                Using f As New IO.FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
                    ' thisFileInUse = False
                End Using
            Catch
                inuse = True
            End Try

            Try
                FileOpen(fs, filename, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
            Catch ex As Exception
                ClassLogger.Add("File " & filename & " inuse or not able to open - message: " & ex.Message, True)
                inuse = True
            Finally
                FileClose(fs)
            End Try
        End If
        Return inuse
    End Function
End Class
