' 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 Convention

    Private Sub Convention_Table_ConventionsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Convention_Table_ConventionsBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Convention_Table_ConventionsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.PharmaDataSet)

    End Sub

    Private Sub Convention_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_Conventions'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
        Me.Convention_Table_ConventionsTableAdapter.Fill(Me.PharmaDataSet.Convention_Table_Conventions)

    End Sub

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

                For i = 0 To 20
                    tab_data(i) = Mid(line, 1, InStr(line, ";") - 1)
                    line = Mid(line, InStr(line, ";") + 1)
                Next
                tab_data(21) = line
                Me.Convention_Table_ConventionsTableAdapter.Insert(tab_data(0), tab_data(1), tab_data(2), tab_data(3), tab_data(4), tab_data(5), tab_data(6), _
                                                                   tab_data(7), tab_data(8), tab_data(9), tab_data(10), tab_data(11), tab_data(12), _
                                                                   tab_data(13), tab_data(14), tab_data(15), tab_data(16), tab_data(17), tab_data(18), _
                                                                   tab_data(19), tab_data(20), tab_data(21))

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