Imports System.IO
Imports System.Windows.Forms


Public Class DialogKartica

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        ' Uvozi izbrano datoteko v aktivni projekt
        Dim delovnaMapa = My.Application.Info.DirectoryPath.ToString + "\" + My.Settings.ProjektMapa.ToString + "\"
        Dim izbran As ListView.SelectedListViewItemCollection = Me.ListViewGsiJob.SelectedItems
        Dim item As ListViewItem
        Dim ime As String = ""
        Dim mapa As String = ""
        Dim datdatum As String = ""

        For Each item In izbran
            ime = item.SubItems(0).Text
            mapa = item.SubItems(1).Text
            datdatum = My.Computer.FileSystem.GetFileInfo(mapa).LastWriteTime
            Dim fileUvoz = mapa
            Dim fileIme = ime
            Dim fileIzvoz = delovnaMapa + fileIme
            My.Computer.FileSystem.CopyFile(fileUvoz, fileIzvoz, True)
            Form1.datJob = fileIzvoz
        Next

        Form1.NaloziGsiJob()

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub DialogKartica_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For Each drive In IO.DriveInfo.GetDrives
            'get all removable and fixed drives
            If drive.DriveType = IO.DriveType.Removable And drive.IsReady = True Then
                'add all found drives into the combobox
                cbPgon.Items.Add(drive)
            End If
        Next
    End Sub

    Private Sub cbPgon_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbPgon.SelectedIndexChanged
        Dim delovnaMapa = cbPgon.Text + "GSI"
        ListViewGsiJob.Clear()
        If My.Computer.FileSystem.DirectoryExists(delovnaMapa) Then
            Dim ix As Integer = 0
            Dim datotekeJobi = My.Computer.FileSystem.GetFiles(delovnaMapa, FileIO.SearchOption.SearchTopLevelOnly, "*.GSI")
            For Each datJob In datotekeJobi
                Dim datdatum = My.Computer.FileSystem.GetFileInfo(datJob).LastWriteTime
                ListViewGsiJob.Items.Add(Path.GetFileName(datJob).ToString, 1).SubItems.Add(Path.GetFullPath(datJob))
                ListViewGsiJob.Items.Item(ix).ToolTipText = datdatum.ToString
                ix = ix + 1
            Next
        End If

    End Sub

    Private Sub ListViewGsiJob_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListViewGsiJob.SelectedIndexChanged
        Dim izbran As ListView.SelectedListViewItemCollection = Me.ListViewGsiJob.SelectedItems
        Dim item As ListViewItem
        Dim ime As String = ""
        Dim mapa As String = ""
        Dim datdatum As String = ""
        For Each item In izbran
            ime = item.SubItems(0).Text
            mapa = item.SubItems(1).Text
            datdatum = My.Computer.FileSystem.GetFileInfo(mapa).LastWriteTime
        Next

        Label3.Text = "Datum zapisa: " + datdatum.ToString
        Label4.Text = "Datoteka: " + mapa.ToString
    End Sub
End Class
