Imports System.IO
Imports System.Windows.Forms
Imports System.Windows.Forms.ListViewItem


Public Class DialogJobOdpri

    Dim mapa As String
    Dim datime As String
    Dim datmapa As String
    Dim datdatum As String

    Private Sub DialogJobOdpri_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        mapa = My.Settings.ProjektMapa.ToString
        Dim delovnaMapa = My.Application.Info.DirectoryPath.ToString + "\" + mapa.ToString
        Dim datotekeJobi = My.Computer.FileSystem.GetFiles(delovnaMapa, FileIO.SearchOption.SearchTopLevelOnly, "*.GSI")
        Dim i As Integer = 0
        ListView1.Clear()

        For Each datJob In datotekeJobi
            ListView1.Items.Add(Path.GetFileName(datJob).ToString).SubItems.Add(Path.GetFullPath(datJob))
            ListView1.Items.Item(i).ImageIndex = 0
            i = i + 1
        Next
        LabelMapa.Text = mapa.ToString
    End Sub

    Private Sub NaloziJob()
        Form1.datJob = datmapa
        Form1.NaloziGsiJob()
    End Sub

    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        Dim izbran As ListView.SelectedListViewItemCollection = Me.ListView1.SelectedItems
        Dim item As ListViewItem

        For Each item In izbran
            datime = item.SubItems(0).Text
            datmapa = item.SubItems(1).Text
        Next

        datdatum = My.Computer.FileSystem.GetFileInfo(datmapa).LastWriteTime

        If LabelDatoteka.Text = "" Then
            OK_Button.Enabled = False
        Else
            OK_Button.Enabled = True
        End If

        LabelDatoteka.Text = datime.ToString
        LabelDatum.Text = datdatum.ToString

    End Sub

    Private Sub ListView1_Selected_DoubleClick(sender As Object, e As EventArgs) Handles ListView1.DoubleClick
        NaloziJob()
        Me.Close()
    End Sub

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        NaloziJob()
        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 ButtonUvozi_Click(sender As Object, e As EventArgs) Handles ButtonUvozi.Click
        Form1.UvoziGsiJob()
        Me.Close()

    End Sub
End Class
