Imports System.IO

Public Class frmFileRename
    Dim oRenameType As String
    Public Sub New(DocID As Int32, oldName As String, pRenameType As String)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        lblType.Text = pRenameType
        lblOldFilename.Text = oldName
        txtNewName.Text = oldName
        oRenameType = pRenameType
    End Sub

    Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
        Dim result As MsgBoxResult
        Dim oMSG = "Wollen Sie die Datei wirklich umbenennen?"
        If USER_LANGUAGE <> "de-DE" Then
            oMSG = "Do You really want to rename the file?"
        End If
        result = MessageBox.Show(oMSG, CAPTION_CONFIRMATION, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = MsgBoxResult.Yes Then
            If oRenameType = "Displayname" Then
                Try
                    ClassFileResult.DocID = ClassWindreamDocGrid.SELECTED_DOC_ID
                    If txtNewName.Text <> "" Then
                        If ClassFileResult.Set_Displayname(txtNewName.Text) Then
                            Me.Close()
                        Else
                            MsgBox("Not succesfull - Check log", MsgBoxStyle.Critical)
                        End If
                    End If
                Catch ex As Exception
                    ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", "Unexpected Error in  Setting Displayname Click: ", ex.Message)
                End Try
            Else
                Dim OldName, NewName, OnlyFilename As String
                OldName = ClassWindreamDocGrid.SELECTED_DOC_PATH
                ' Define file names.
                NewName = txtNewName.Text
                OnlyFilename = NewName
                Dim oFullFilename = ClassHelper.FORMAT_WM_PATH(ClassWindreamDocGrid.SELECTED_DOC_PATH)
                Dim name1 = Path.Combine(Path.GetDirectoryName(oFullFilename), NewName)
                NewName = NewName & Path.GetExtension(oFullFilename)
                OnlyFilename &= Path.GetExtension(oFullFilename)
                ' Rename file.
                LOGGER.Info($"Renaming Old: [{OldName}]")
                LOGGER.Info($"Renaming New: [{NewName}]")
                My.Computer.FileSystem.RenameFile(OldName, NewName)
                LOGGER.Info($"Renaming FileSystem done!")
                Cursor = Cursors.WaitCursor
                Dim oEXEC As String = $"EXEC PRPMO_DOC_CREATE_NEW_DOC {ClassWindreamDocGrid.SELECTED_DOC_ID}, {CURRENT_RECORD_ID},'{USER_USERNAME}'"
                If MYDB_ECM.ExecuteNonQuery(oEXEC) Then
                    Me.Close()
                Else
                    MsgBox("Not succesfull - Check log", MsgBoxStyle.Critical)
                End If
            End If
        End If




    End Sub
End Class