' 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
Imports System.Text
Public Class Correspondance

    Private Sub Convention_Table_correspondanceBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Convention_Table_correspondanceBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Convention_Table_correspondanceBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.PharmaDataSet)

    End Sub

    Private Sub Correspondance_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO : cette ligne de code charge les données dans la table 'PharmaDataSet.Convention_Table_correspondance'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
        Me.Convention_Table_correspondanceTableAdapter.Fill(Me.PharmaDataSet.Convention_Table_correspondance)

    End Sub

    Private Sub Button_Importer_Fichier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Importer_Fichier.Click
        OpenFileDialog1.ShowDialog()
        Using sr As New StreamReader(OpenFileDialog1.FileName, Encoding.Default)
            Dim line As String
            Dim tab_data() As String
            ReDim tab_data(4)
            line = sr.ReadLine
            Do

                For i = 0 To 2
                    tab_data(i) = Mid(line, 1, InStr(line, ";") - 1)
                    line = Mid(line, InStr(line, ";") + 1)
                Next
                tab_data(3) = line
                Me.Convention_Table_correspondanceTableAdapter.Insert(tab_data(2), tab_data(0), tab_data(1), tab_data(3))

                line = sr.ReadLine
            Loop Until line Is Nothing
        End Using

    End Sub
End Class