' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Imports System.IO
Public Class ReTransmission_Lot

    Private Sub LotsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.LotsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.PharmaDataSet)

    End Sub



    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'TODO : cette ligne de code charge les données dans la table 'PharmaDataSet.Lots'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
        Me.LotsTableAdapter.FillByEtat_and_NombreTransmission(Me.PharmaDataSet.Lots, ComboBox1.Text, 1)
    End Sub

    Private Sub LotsDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles LotsDataGridView.CellContentClick

        Select Case LotsDataGridView.CurrentCellAddress.X

            Case BoutonColumn.Index
                Dim cheminsource As String = ""
                Dim file As String = LotsDataGridView.Item(DataGridViewTextBoxColumnRéférence.Index, LotsDataGridView.CurrentRow.Index).Value.ToString
                If Dir("C:\Factures\Lots\transmis\" + file + ".lotFSE") <> "" Then
                    cheminsource = "C:\Factures\Lots\transmis\"
                Else
                    If Dir("C:\Factures\Lots\traités\" + file + ".lotFSE") <> "" Then
                        cheminsource = "C:\Factures\Lots\traités\"
                    End If
                End If
                If cheminsource = "" Then
                    MsgBox("LE FICHIER CORRESPONDANT A CE LOT EST MANQUANT", MsgBoxStyle.Critical)
                    Exit Sub
                End If
                If MsgBox("VOULEZ VOUS REMETTRE LE LOT " + file + " A DISPOSITION POUR TRANSMISSION?", 36) = MsgBoxResult.Yes Then
                    My.Computer.FileSystem.MoveFile(cheminsource + file + ".lotFSE", "C:\Factures\Lots\" + file + ".lotFSE")
                    Me.LotsTableAdapter.Update_Etat("A TRANSMETTRE", Val(file), Nothing)
                End If

        End Select


    End Sub
End Class