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

    Public ordos As PharmaDataSet.OrdoDataTable
    Public chroniques As PharmaDataSet.ChroniqueDataTable


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        If Ordos_DataGridView.SelectedRows Is Nothing Then
            Exit Sub
        End If
        If Chroniques_DataGridView.SelectedRows Is Nothing Then
            Exit Sub
        End If
        ' MsgBox(CInt(Ordos_DataGridView.Item(Id_Ordo.Index, Ordos_DataGridView.SelectedRows.Item(0).Index).Value))
        For Each myrow As DataGridViewRow In Chroniques_DataGridView.SelectedRows
            '     MsgBox(myrow.Index.ToString)

            BDD.ChroniqueTableAdapter.Update_IdOrdo_By_VitaleNum_Produit(CInt(Ordos_DataGridView.Item(Id_Ordo.Index, Ordos_DataGridView.SelectedRows.Item(0).Index).Value), _
                                                                         CurrentBenéficiaire.Num, _
                                                                         Chroniques_DataGridView.Item(Produit_Désignation.Index, myrow.Index).Value, _
                                                                           Chroniques_DataGridView.Item(Produit_CIP.Index, myrow.Index).Value, _
                                                                             Chroniques_DataGridView.Item(Produit_EAN13.Index, myrow.Index).Value, _
                                                                               Chroniques_DataGridView.Item(Produit_CAB.Index, myrow.Index).Value)



        Next
        affichage()

    End Sub

    Public Sub affichage()
        ordos = BDD.OrdoTableAdapter.GetDataBy_VitaleNum(CurrentBenéficiaire.Num)
        chroniques = BDD.ChroniqueTableAdapter.GetDataBy_Vitale_Num_List(CurrentBenéficiaire.Num)
        Ordos_DataGridView.Rows.Clear()
        For r = 0 To ordos.Rows.Count - 1
            Ordos_DataGridView.Rows.Add()
        Next
        For r = 0 To ordos.Rows.Count - 1
            If ordos(r).Prescr_NumID <> "" Or ordos(r).Prescr_NumRPPS <> "" Then
                Try
                    Ordos_DataGridView.Item(Prescripteur.Index, r).Value = BDD.PrescripteursTableAdapter.GetDataBy_Numidentification_NumRPPS(ordos(r).Prescr_NumID, ordos(r).Prescr_NumRPPS).Item(0).NomPrénom
                Catch ex As Exception
                    Ordos_DataGridView.Item(Prescripteur.Index, r).Value = "ERREUR: prescripteur inconnu"
                End Try
            End If
            Ordos_DataGridView.Item(Date_prescr.Index, r).Value = ordos(r).Ordo_Date_Prescr.ToShortDateString
            Ordos_DataGridView.Item(Id_Ordo.Index, r).Value = ordos(r).Id_Ordo
            Ordos_DataGridView.Item(Type.Index, r).Value = ordos(r).Type
        Next

        Chroniques_DataGridView.Rows.Clear()
        For r = 0 To chroniques.Rows.Count - 1
            Chroniques_DataGridView.Rows.Add()
        Next
        For r = 0 To chroniques.Rows.Count - 1
            Chroniques_DataGridView.Item(Chronique_Id_Ordo.Index, r).Value = chroniques(r).Id_Ordo
            Chroniques_DataGridView.Item(Produit_Désignation.Index, r).Value = chroniques(r).Produit_Désignation
            Chroniques_DataGridView.Item(Produit_CIP.Index, r).Value = chroniques(r).Produit_CIP
            Chroniques_DataGridView.Item(Produit_EAN13.Index, r).Value = chroniques(r).Produit_EAN13
            Chroniques_DataGridView.Item(Produit_CAB.Index, r).Value = chroniques(r).Produit_CAB
        Next
    End Sub

    Private Sub Chronique_Selection_Ordo_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    

        affichage()
    End Sub
End Class