From e029c20ae9496466285ca5d377a7d975a5094bcc Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 4 May 2021 14:06:08 +0200 Subject: [PATCH] Customize Msgbox title, handle minDate when file not found, show filename in msgbox --- Global_Indexer/ClassFolderWatcher.vb | 18 +------- Global_Indexer/ClassIndexFunctions.vb | 33 +++++++++++++- Global_Indexer/frmStart.vb | 65 ++------------------------- 3 files changed, 35 insertions(+), 81 deletions(-) diff --git a/Global_Indexer/ClassFolderWatcher.vb b/Global_Indexer/ClassFolderWatcher.vb index 61ee841..a9d3bae 100644 --- a/Global_Indexer/ClassFolderWatcher.vb +++ b/Global_Indexer/ClassFolderWatcher.vb @@ -194,25 +194,9 @@ Public Class ClassFolderWatcher 'Die Datei übergeben LOGGER.Info(">> OnCreated-File:" & e.FullPath) - Dim oFileExists As Date = ClassIndexFunctions.FileExistsinDropTable(e.FullPath) - - If IsNothing(oFileExists) Then + If ClassIndexFunctions.CheckDuplicateFiles(e.FullPath, "FolderWatch/Scan") Then ClassFilehandle.Decide_FileHandle(e.FullPath, oHandleType) - Else - Dim oResult As DialogResult - Dim oDate As String = oFileExists.ToString("d") - - If USER_LANGUAGE = "de-DE" Then - oResult = MsgBox($"Die Datei wurde bereits am [{oDate}] verarbeitet. Wollen Sie die gleiche Datei noch einmal verarbeiten?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "GLOBIX - FolderWatch") - Else - oResult = MsgBox($"This file has already been processed at [{oDate}]. Do you want to process the same file again?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "GLOBIX - FolderWatch") - End If - - If oResult = DialogResult.Yes Then - ClassFilehandle.Decide_FileHandle(e.FullPath, oHandleType) - End If End If - Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in folder_watch_Created") End Try diff --git a/Global_Indexer/ClassIndexFunctions.vb b/Global_Indexer/ClassIndexFunctions.vb index a1a0b35..8d4987e 100644 --- a/Global_Indexer/ClassIndexFunctions.vb +++ b/Global_Indexer/ClassIndexFunctions.vb @@ -1,5 +1,7 @@ -Public Class ClassIndexFunctions - Public Shared Function FileExistsinDropTable(Filename As String) As DateTime +Imports System.IO + +Public Class ClassIndexFunctions + Public Shared Function FileExistsinDropTable(Filename As String) As Date Dim oSQL As String Dim oHash As String @@ -45,4 +47,31 @@ Return Nothing End Try End Function + + Public Shared Function CheckDuplicateFiles(Filepath As String, ModuleTitle As String) + Dim oFileInfo As New FileInfo(Filepath) + Dim oFilename As String = oFileInfo.Name + Dim oFileExists As Date = FileExistsinDropTable(Filepath) + + If oFileExists.Equals(Date.MinValue) Then + Return True + Else + Dim oResult As DialogResult + Dim oDate As String = oFileExists.ToString("d") + Dim oBoxTitle = $"GLOBIX - {ModuleTitle}" + Dim oBoxOptions = MsgBoxStyle.Question Or MsgBoxStyle.YesNo + + If USER_LANGUAGE = "de-DE" Then + oResult = MsgBox($"Die Datei [{oFilename}] wurde bereits am [{oDate}] verarbeitet. Wollen Sie die gleiche Datei noch einmal verarbeiten?", oBoxOptions, oBoxTitle) + Else + oResult = MsgBox($"The file [{oFilename}] has already been processed at [{oDate}]. Do you want to process the same file again?", oBoxOptions, oBoxTitle) + End If + + If oResult = DialogResult.Yes Then + Return True + End If + End If + + Return False + End Function End Class diff --git a/Global_Indexer/frmStart.vb b/Global_Indexer/frmStart.vb index 1c4bcf3..d728067 100644 --- a/Global_Indexer/frmStart.vb +++ b/Global_Indexer/frmStart.vb @@ -168,25 +168,10 @@ Public Class frmStart Dim oLastPipe = oFiledropString.LastIndexOf("|") Dim oHandleType As String = oFiledropString.Substring(0, oLastPipe + 1) Dim oFilename As String = oFiledropString.Substring(oLastPipe + 1) - Dim oFileExists As Date = ClassIndexFunctions.FileExistsinDropTable(oFilename) - If IsNothing(oFileExists) Then + If ClassIndexFunctions.CheckDuplicateFiles(oFilename, "Manuelle Ablage") Then ClassFilehandle.Decide_FileHandle(oFilename, oHandleType) oIndex += 1 - Else - Dim oResult As DialogResult - Dim oDate As String = oFileExists.ToString("d") - - If USER_LANGUAGE = "de-DE" Then - oResult = MsgBox($"Die Datei wurde bereits am [{oDate}] verarbeitet. Wollen Sie die gleiche Datei noch einmal verarbeiten?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "GLOBIX - FolderWatch") - Else - oResult = MsgBox($"This file has already been processed at [{oDate}]. Do you want to process the same file again?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "GLOBIX - FolderWatch") - End If - - If oResult = DialogResult.Yes Then - ClassFilehandle.Decide_FileHandle(oFilename, oHandleType) - oIndex += 1 - End If End If End If Next @@ -373,30 +358,9 @@ Public Class frmStart 'Die Datei übergeben LOGGER.Info(">> Adding file from Scanfolder after startup:" & oFileName) - Dim oFileExists As Date = ClassIndexFunctions.FileExistsinDropTable(oFileName) - - If IsNothing(oFileExists) Then + If ClassIndexFunctions.CheckDuplicateFiles(oFileName, "FolderWatch/Scan") Then ClassFilehandle.Decide_FileHandle(oFileName, oHandleType) - Else - Dim oResult As DialogResult - Dim oDate As String = oFileExists.ToString("d") - - If USER_LANGUAGE = "de-DE" Then - oResult = MsgBox($"Die Datei wurde bereits am [{oDate}] verarbeitet. Wollen Sie die gleiche Datei noch einmal verarbeiten?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "GLOBIX - FolderWatch") - Else - oResult = MsgBox($"This file has already been processed at [{oDate}]. Do you want to process the same file again?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "GLOBIX - FolderWatch") - End If - - If oResult = DialogResult.Yes Then - ClassFilehandle.Decide_FileHandle(oFileName, oHandleType) - End If End If - - 'If ClassIndexFunctions.FileExistsinDropTable(fileName) = False Then - ' ClassFilehandle.Decide_FileHandle(fileName, handleType) - 'Else - ' LOGGER.Info(">> Scanfolder Startup: File already exists:" & fileName) - 'End If Next oFileName Else @@ -430,33 +394,10 @@ Public Class frmStart 'Die Datei übergeben LOGGER.Info(">> Adding file from Folderwatch after startup:" & oFileName) - 'If ClassIndexFunctions.FileExistsinDropTable(fileName) = False Then - ' ClassFilehandle.Decide_FileHandle(fileName, handleType) - 'Else - ' LOGGER.Info(">> Folderwatch Startup: File already exists:" & fileName) - 'End If - - Dim oFileExists As Date = ClassIndexFunctions.FileExistsinDropTable(oFileName) - - If IsNothing(oFileExists) Then + If ClassIndexFunctions.CheckDuplicateFiles(oFileName, "FolderWatch/Scan") Then ClassFilehandle.Decide_FileHandle(oFileName, handleType) - Else - Dim oResult As DialogResult - Dim oDate As String = oFileName.ToString("d") - - If USER_LANGUAGE = "de-DE" Then - oResult = MsgBox($"Die Datei wurde bereits am [{oDate}] verarbeitet. Wollen Sie die gleiche Datei noch einmal verarbeiten?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "GLOBIX - FolderWatch") - Else - oResult = MsgBox($"This file has already been processed at [{oDate}]. Do you want to process the same file again?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "GLOBIX - FolderWatch") - End If - - If oResult = DialogResult.Yes Then - ClassFilehandle.Decide_FileHandle(oFileName, handleType) - End If End If - Next oFileName - Else LOGGER.Info(">> FW_started not started") End If