' 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/>.
Public Class Produits_PCB

    Private Sub Produits_PCB_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        Dim fournisseurs = Commandes_PharmaML.CommandesTableAdapter.Select_distinct_fournisseur
        For r = 0 To fournisseurs.Rows.Count - 1
            FournisseurMyCombobox.Items.Add(fournisseurs.Item(r).Fournisseur)
        Next
       affiche_liste
    End Sub

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Select Case e.ColumnIndex
            Case suppr.Index
                Try
                    BDD.PCBTableAdapter.DeleteQuery(DataGridView1.Item(FournisseurDataGridViewTextBoxColumn.Index, e.RowIndex).Value, DataGridView1.Item(ProduitDataGridViewTextBoxColumn.Index, e.RowIndex).Value)
                    affiche_liste()
                Catch ex As Exception

                End Try

        End Select
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            If BDD.PCBTableAdapter.GetDataBy_Fournisseur_Produit(FournisseurMyCombobox.Text, Produit_CodeLabel.Text).Rows.Count > 0 Then
                BDD.PCBTableAdapter.DeleteQuery(FournisseurMyCombobox.Text, Produit_CodeLabel.Text)
            End If
            BDD.PCBTableAdapter.Insert(FournisseurMyCombobox.Text, Produit_CodeLabel.Text, CInt(PCBTextBox.Text))
            affiche_liste()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
    Private Sub affiche_liste()
        DataGridView1.DataSource = BDD.PCBTableAdapter.GetDataBy_Produit(Produit_CodeLabel.Text)
        For r = 0 To DataGridView1.RowCount - 1
            DataGridView1.Item(suppr.Index, r).Value = "suppr"
        Next
    End Sub
End Class