' 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 DETAIL_Ligne_Vente
    Public Mystring As String
    Public Numéro_Prestation_SV As Integer

    Private Sub DETAIL_Ligne_Vente_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        COMPTOIR_MAIN.DP_Poso(COMPTOIR_MAIN.Vente.CurrentRow.Index) = DP_Poso_TextBox.Text
        COMPTOIR_MAIN.DP_Rect(COMPTOIR_MAIN.Vente.CurrentRow.Index) = DP_Rect_TextBox.Text
        Try
            Dim Numéro_Prestation_SV = 0
            For r = 0 To COMPTOIR_MAIN.Vente.RowCount - 1
                If UCase(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value) <> "VENTE DIRECTE" Then
                    Numéro_Prestation_SV = Numéro_Prestation_SV + 1
                    COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_G1740C7.Index, r).Value = CurrentFactureVitale.G1740C7(Numéro_Prestation_SV)
                End If
            Next

        Catch ex As Exception

        End Try

    End Sub





    Private Sub DETAIL_Ligne_Vente_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If COMPTOIR_MAIN.GrouperLPPToolStripMenuItem.Checked = False Then
            For r = 0 To COMPTOIR_MAIN.Vente.CurrentRow.Index
                If UCase(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value) <> "VENTE DIRECTE" Then
                    Numéro_Prestation_SV = Numéro_Prestation_SV + 1
                End If
            Next

        Else
            '-------------------------------------------------------------------------------------------------------------------------------
            'un truc ultra compliqué pour gérer quand les LPP sont regroupés. Ce truc ne gère pas le nombre maxi (10) de LPP regroupés
            Dim index_ligne As Integer = COMPTOIR_MAIN.Vente.CurrentRow.Index
            If Me.CodePrestationsTableAdapter1.GetDataBy_CodeActe(COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString).Item(0).TypeNomenclature = "LPP" Then
                For r = 0 To COMPTOIR_MAIN.Vente.CurrentRow.Index - 1
                    If UCase(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value) <> "VENTE DIRECTE" And _
                        COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, r).Value.ToString = COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString Then
                        index_ligne = r
                        Exit For
                    End If
                Next
            End If

            For r = 0 To index_ligne
                If UCase(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteType.Index, r).Value) <> "VENTE DIRECTE" Then
                    Numéro_Prestation_SV = Numéro_Prestation_SV + 1
                    If Me.CodePrestationsTableAdapter1.GetDataBy_CodeActe(COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, r).Value.ToString).Item(0).TypeNomenclature = "LPP" Then
                        For r2 = 0 To r - 1
                            If COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, r).Value.ToString = COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, r2).Value.ToString Then
                                Numéro_Prestation_SV = Numéro_Prestation_SV - 1
                                Exit For
                            End If
                        Next
                    End If
                End If
            Next
            '-------------------------------------------------------------------------------------------------------------------------------
        End If

        'Label1.Text = Mystring
        For i = 0 To CurrentFactureVitale.PEC.Montants_Actes.Length - 1
            If CurrentFactureVitale.PEC.Montants_Actes(i).Num_Acte = Numéro_Prestation_SV Then
                PEC_TextBox.Text = CurrentFactureVitale.PEC.Montants_Actes(i).Montant.ToString
            End If
        Next
        For i = 0 To CurrentFactureVitale.G1840.Length - 1
            If CurrentFactureVitale.G1840(i).G1840C1 = Numéro_Prestation_SV Then
                If CurrentFactureVitale.G1840(i).G1840C3 <> "" Then
                    Entente_préalable_DateTimePicker.Value = Convert.ToDateTime(Mid(CurrentFactureVitale.G1840(i).G1840C3, 7, 2) + "/" + Mid(CurrentFactureVitale.G1840(i).G1840C3, 5, 2) + "/" + Mid(CurrentFactureVitale.G1840(i).G1840C3, 1, 4))
                End If
                For j = 0 To Entente_préalable_ComboBox.Items.Count - 1
                    If Mid(Entente_préalable_ComboBox.Items.Item(j).ToString, 1, 1) = CurrentFactureVitale.G1840(i).G1840C2 Then
                        Entente_préalable_ComboBox.SelectedIndex = j
                        Entente_préalable_ComboBox.Text = Entente_préalable_ComboBox.Items.Item(j).ToString
                        Exit For
                    End If
                Next
                Exit For
            End If
        Next
        'If CurrentFactureVitale.G1740C7.Length > 1 Then
        '    Subtitution_ComboBox.Text = CurrentFactureVitale.G1740C7(Numéro_Prestation_SV)
        'End If

        For i = 0 To CurrentFactureVitale.Forçage_Part_AMO.Length - 1
            If CurrentFactureVitale.Forçage_Part_AMO(i).Num_Acte = Numéro_Prestation_SV Then
                Forçage_Part_AMO_TextBox.Text = CurrentFactureVitale.Forçage_Part_AMO(i).Montant.ToString
            End If
        Next

        If CurrentFactureVitale.G1741.Length > 1 Then
            For i = 0 To CurrentFactureVitale.G1741.Length - 1
                If CurrentFactureVitale.G1741(i).G1741C1 = Numéro_Prestation_SV Then
                    Prest_Det_Lot_CodeCIP_DataGridView.Rows.Add()
                End If
            Next
            For i = 0 To CurrentFactureVitale.G1741.Length - 1
                If CurrentFactureVitale.G1741(i).G1741C1 = Numéro_Prestation_SV Then
                    Dim rang_du_lot As Integer = CurrentFactureVitale.G1741(i).G1741C2
                    Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C3.Index, rang_du_lot - 1).Value = CurrentFactureVitale.G1741(i).G1741C3
                    Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C4.Index, rang_du_lot - 1).Value = CurrentFactureVitale.G1741(i).G1741C4
                    Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C5.Index, rang_du_lot - 1).Value = CurrentFactureVitale.G1741(i).G1741C5
                    Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C6.Index, rang_du_lot - 1).Value = CurrentFactureVitale.G1741(i).G1741C6
                End If
            Next
        End If

        Dim tauxamo As Integer
        'If CurrentFactureVitale.TabLigneFacture(Numéro_Prestation_SV).G1610C7 = "N" Or CurrentFactureVitale.TabLigneFacture(Numéro_Prestation_SV).G1610C7 = "G" Then
        tauxamo = 0
        'Else
        If Not COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteType.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value Is Nothing Then
            If COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteType.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString <> "" Then
                Select Case COMPTOIR_MAIN.NatureAssurance_Button.Text
                    Case "MATERNITE", "ACCIDENT DU TRAVAIL", "PREVENTION", "SMG"
                        tauxamo = 100
                    Case Else
                        If COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteType.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString = "ALD" Or COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteType.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString = "PREV" Or COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteType.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString = "SP" Then
                            tauxamo = 100
                        Else
                            If Val(COMPTOIR_MAIN.Renouvellement_TextBox.Text) = 0 Or CurrentBenéficiaire.G101C10 = "04" Then
                                tauxamo = COMPTOIR_MAIN.CalculTauxAMO(COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString, CurrentBenéficiaire.G101C10, COMPTOIR_MAIN.CodeSituation(COMPTOIR_MAIN.Date_Droits_AMO()))
                            Else
                                If (COMPTOIR_MAIN.CalculTauxAMO(COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString, CurrentBenéficiaire.G101C10, COMPTOIR_MAIN.CodeSituation(COMPTOIR_MAIN.Date_Droits_AMO())) < COMPTOIR_MAIN.CalculTauxAMO(COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString, CurrentBenéficiaire.G101C10, COMPTOIR_MAIN.CodeSituation(COMPTOIR_MAIN.DateExecution.Value))) Then
                                    CurrentFactureVitale.Renouvellement_Date_Droits_AMO_est_date_éxécution = True
                                    tauxamo = COMPTOIR_MAIN.CalculTauxAMO(COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString, CurrentBenéficiaire.G101C10, COMPTOIR_MAIN.CodeSituation(COMPTOIR_MAIN.DateExecution.Value))
                                Else
                                    CurrentFactureVitale.Renouvellement_Date_Droits_AMO_est_date_éxécution = False
                                    tauxamo = COMPTOIR_MAIN.CalculTauxAMO(COMPTOIR_MAIN.Vente(COMPTOIR_MAIN.VenteCodeActe.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value.ToString, CurrentBenéficiaire.G101C10, COMPTOIR_MAIN.CodeSituation(COMPTOIR_MAIN.Date_Droits_AMO()))
                                End If
                            End If
                        End If
                End Select
            End If
        End If

        TauxAMO_Label.Text = "Taux AMO: " + tauxamo.ToString + "%"

        If CurrentFactureVitale.Non_Rembousable_CheckBox.Length > Numéro_Prestation_SV Then
            If CurrentFactureVitale.Non_Rembousable_CheckBox(Numéro_Prestation_SV) = True Then
                Non_Rembousable_CheckBox.Checked = True
            End If
        End If

        DP_Poso_TextBox.Text = COMPTOIR_MAIN.DP_Poso(COMPTOIR_MAIN.Vente.CurrentRow.Index)
        DP_Rect_TextBox.Text = COMPTOIR_MAIN.DP_Rect(COMPTOIR_MAIN.Vente.CurrentRow.Index)

        Dim fournisseurs = Commandes_PharmaML.FournisseurTableAdapter.GetData_OrderByNom
        For r = 0 To fournisseurs.Rows.Count - 1
            If fournisseurs.Item(r).URL <> "" Then
                Fournisseurs_ComboBox.Items.Add(fournisseurs.Item(r).Nom)
            End If
        Next

        If CurrentBenéficiaire.G101C8 <> "" Then
            Reserver_Produit_Button.Visible = True
        End If
    End Sub

    Private Sub PEC_TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PEC_TextBox.TextChanged

        '______________________________________
        If PEC_TextBox.Text = "" Then
            For i = 0 To CurrentFactureVitale.PEC.Montants_Actes.Length - 1
                If CurrentFactureVitale.PEC.Montants_Actes(i).Num_Acte = Numéro_Prestation_SV Then
                    CurrentFactureVitale.PEC.Montants_Actes(i).Montant = Nothing
                    CurrentFactureVitale.PEC.Montants_Actes(i).Num_Acte = Nothing
                End If
            Next
            '______________________________________
        ElseIf Not IsNumeric(PEC_TextBox.Text) Then
            PEC_TextBox.Text = ""
            Beep()
            Exit Sub
            '______________________________________
        Else
            ReDim Preserve CurrentFactureVitale.PEC.Montants_Actes(COMPTOIR_MAIN.Vente.RowCount)
            CurrentFactureVitale.PEC.Montants_Actes(Numéro_Prestation_SV).Montant = Val(PEC_TextBox.Text)
            CurrentFactureVitale.PEC.Montants_Actes(Numéro_Prestation_SV).Num_Acte = Numéro_Prestation_SV
            CurrentFactureVitale.PEC.MontantGlobal = Nothing
            COMPTOIR_MAIN.MontantGlobalPriseEnchargeToolStripTextBox.Text = ""
        End If
    End Sub

    Private Sub Entente_préalable_ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Entente_préalable_ComboBox.SelectedIndexChanged
        ReDim Preserve CurrentFactureVitale.G1840(COMPTOIR_MAIN.Vente.RowCount)
        If Entente_préalable_ComboBox.Text = "" Then
            For i = 0 To CurrentFactureVitale.G1840.Length - 1
                If CurrentFactureVitale.G1840(i).G1840C1 = Numéro_Prestation_SV Then
                    CurrentFactureVitale.G1840(i).G1840C2 = ""
                    CurrentFactureVitale.G1840(i).G1840C3 = ""
                    Exit Sub
                End If
            Next
        Else
            CurrentFactureVitale.G1840(COMPTOIR_MAIN.Vente.CurrentRow.Index + 1).G1840C1 = Numéro_Prestation_SV
            CurrentFactureVitale.G1840(COMPTOIR_MAIN.Vente.CurrentRow.Index + 1).G1840C2 = Mid(Entente_préalable_ComboBox.Text, 1, 1)
            CurrentFactureVitale.G1840(COMPTOIR_MAIN.Vente.CurrentRow.Index + 1).G1840C3 = Format(Entente_préalable_DateTimePicker.Value, "yyyyMMdd") + "0000"
        End If
    End Sub

    Private Sub Entente_préalable_DateTimePicker_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Entente_préalable_DateTimePicker.ValueChanged
        ReDim Preserve CurrentFactureVitale.G1840(COMPTOIR_MAIN.Vente.RowCount)
        CurrentFactureVitale.G1840(Numéro_Prestation_SV).G1840C3 = Format(Entente_préalable_DateTimePicker.Value, "yyyyMMdd") + "0000"
    End Sub

    'Private Sub Subtitution_ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Subtitution_ComboBox.SelectedIndexChanged
    '    ReDim Preserve CurrentFactureVitale.G1740C7(COMPTOIR_MAIN.Vente.RowCount)
    '    CurrentFactureVitale.G1740C7(Numéro_Prestation_SV) = Subtitution_ComboBox.Text
    'End Sub

    Private Sub Forçage_Part_AMO_TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Forçage_Part_AMO_TextBox.TextChanged
        '______________________________________
        If Forçage_Part_AMO_TextBox.Text = "" Then
            For i = 0 To CurrentFactureVitale.Forçage_Part_AMO.Length - 1
                If CurrentFactureVitale.Forçage_Part_AMO(i).Num_Acte = Numéro_Prestation_SV Then
                    CurrentFactureVitale.Forçage_Part_AMO(i).Montant = Nothing
                    CurrentFactureVitale.Forçage_Part_AMO(i).Num_Acte = Nothing
                End If
            Next
            '______________________________________
        ElseIf Not IsNumeric(Forçage_Part_AMO_TextBox.Text) Then
            Forçage_Part_AMO_TextBox.Text = ""
            Beep()
            Exit Sub
            '______________________________________
        Else
            ReDim Preserve CurrentFactureVitale.Forçage_Part_AMO(COMPTOIR_MAIN.Vente.RowCount)
            CurrentFactureVitale.Forçage_Part_AMO(Numéro_Prestation_SV).Montant = Val(Forçage_Part_AMO_TextBox.Text)
            CurrentFactureVitale.Forçage_Part_AMO(Numéro_Prestation_SV).Num_Acte = Numéro_Prestation_SV
        End If
    End Sub


    Private Sub Prest_Det_Lot_CodeCIP_DataGridView_CellValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Prest_Det_Lot_CodeCIP_DataGridView.CellValidated
        If Prest_Det_Lot_CodeCIP_DataGridView.CurrentCell.Value = "" Then
            Exit Sub
        End If
        ReDim Preserve CurrentFactureVitale.G1741((COMPTOIR_MAIN.Vente.RowCount - 1) * 30)
        Dim found As Boolean = False
        Dim indice_libre_G1740 As Integer = 0
        For i = 0 To CurrentFactureVitale.G1741.Length - 1
            If CurrentFactureVitale.G1741(i).G1741C1 = Numéro_Prestation_SV And CurrentFactureVitale.G1741(i).G1741C2 = Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index + 1 Then
                CurrentFactureVitale.G1741(i).G1741C3 = Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C3.Index, Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index).Value
                CurrentFactureVitale.G1741(i).G1741C4 = Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C4.Index, Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index).Value
                CurrentFactureVitale.G1741(i).G1741C5 = Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C5.Index, Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index).Value
                CurrentFactureVitale.G1741(i).G1741C6 = Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C6.Index, Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index).Value
                found = True
            End If
            If Val(CurrentFactureVitale.G1741(i).G1741C1) = 0 Then
                indice_libre_G1740 = i
            End If
        Next
        If found = False Then
            CurrentFactureVitale.G1741(indice_libre_G1740).G1741C1 = Numéro_Prestation_SV
            CurrentFactureVitale.G1741(indice_libre_G1740).G1741C2 = Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index + 1
            CurrentFactureVitale.G1741(indice_libre_G1740).G1741C3 = Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C3.Index, Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index).Value
            CurrentFactureVitale.G1741(indice_libre_G1740).G1741C4 = Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C4.Index, Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index).Value
            CurrentFactureVitale.G1741(indice_libre_G1740).G1741C5 = Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C5.Index, Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index).Value
            CurrentFactureVitale.G1741(indice_libre_G1740).G1741C6 = Prest_Det_Lot_CodeCIP_DataGridView.Item(G1741C6.Index, Prest_Det_Lot_CodeCIP_DataGridView.CurrentRow.Index).Value
        End If


    End Sub


    Private Sub Prest_Det_Lot_CodeCIP_DataGridView_RowsRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsRemovedEventArgs) Handles Prest_Det_Lot_CodeCIP_DataGridView.RowsRemoved
        For j = 0 To CurrentFactureVitale.G1741.Length - 1
            If CurrentFactureVitale.G1741(j).G1741C1 = Numéro_Prestation_SV Then
                CurrentFactureVitale.G1741(j).G1741C1 = 0
                CurrentFactureVitale.G1741(j).G1741C2 = Nothing
                CurrentFactureVitale.G1741(j).G1741C3 = Nothing
                CurrentFactureVitale.G1741(j).G1741C4 = Nothing
                CurrentFactureVitale.G1741(j).G1741C5 = Nothing
                CurrentFactureVitale.G1741(j).G1741C6 = Nothing
            End If
        Next
        While Prest_Det_Lot_CodeCIP_DataGridView.RowCount > 1
            Prest_Det_Lot_CodeCIP_DataGridView.Rows.RemoveAt(0)
        End While
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Me.Dispose()
        Me.Close()
    End Sub

    Private Sub TVA_ComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TVA_ComboBox.SelectedIndexChanged
        COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteTVA.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value = TVA_ComboBox.Text
    End Sub

    Private Sub Non_Rembousable_CheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles Non_Rembousable_CheckBox.CheckedChanged
        If Non_Rembousable_CheckBox.Checked = True Then
            ReDim Preserve CurrentFactureVitale.Non_Rembousable_CheckBox(COMPTOIR_MAIN.Vente.RowCount)
            CurrentFactureVitale.Non_Rembousable_CheckBox(Numéro_Prestation_SV) = True
        Else
            CurrentFactureVitale.Non_Rembousable_CheckBox(Numéro_Prestation_SV) = False
        End If
    End Sub

    Private Sub VIDAL_Button_Click(sender As Object, e As EventArgs) Handles VIDAL_Button.Click
        'Process.Start("http://vidal.fr/rest/redirect-product/id:" & COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_Vidal_ProductID.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value)

        Dim psi As New ProcessStartInfo("http://vidal.fr/rest/redirect-product/id:" & COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_Vidal_ProductID.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value)

        psi.WindowStyle = ProcessWindowStyle.Maximized


        Process.Start(psi)

        Me.Close()

    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked

        Produits.Visible = True
        'Dim my_produit As New Produits
        If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value <> "" Then
            Produits.Recherche_TextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
        ElseIf COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value <> "" Then
            Produits.Recherche_TextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
        ElseIf COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value <> "" Then
            Produits.Recherche_TextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
        End If
        'Produits.Visible = True
        Produits.Recherche_TextBox_Validated(Nothing, Nothing)
        'Me.WindowState = FormWindowState.Minimized
        ''Produits()
        ''my_produit.ShowDialog()
        Me.Close()
        Produits.BringToFront()
        Produits.WindowState = FormWindowState.Maximized


    End Sub

    Private Sub CommandeLinkLabel_Click(sender As Object, e As EventArgs) Handles CommandeLinkLabel.Click
        'Me.Hide()

        Commandes_PharmaML.Recherche_TextBox.Text = Designation_Label.Text
        Commandes_PharmaML.Visible = True
        Commandes_PharmaML.TopMost = True
        Commandes_PharmaML.Focus()
        Commandes_PharmaML.Recherche_TextBox.Focus()
        Commandes_PharmaML.SelectNextControl(Commandes_PharmaML.Recherche_TextBox, True, True, True, True)
        Commandes_PharmaML.Recherche_DataGridView.Rows(0).Selected = True
        Commandes_PharmaML.Recherche_DataGridView_CellClick(Commandes_PharmaML.Recherche_DataGridView, New DataGridViewCellEventArgs(0, 0))
        'commandes_.BringToFront()
        Me.Close()
    End Sub

    Private Sub Disp_LinkLabel_Click(sender As Object, e As EventArgs) Handles Disp_LinkLabel.Click, Fournisseurs_ComboBox.SelectedIndexChanged
        If Fournisseurs_ComboBox.SelectedItem Is Nothing Then
            MyMsg_Box.Presentation("Officine !", "Fournisseur?", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Exit Sub
        End If


        Commandes_PharmaML.Info_Produit(COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                     COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                     COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                     Fournisseurs_ComboBox.SelectedItem.ToString, COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_Code_PharmaML.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, 1)
    End Sub






    Private Sub Reserver_Produit_Button_Click(sender As Object, e As EventArgs) Handles Reserver_Produit_Button.Click

        Dim Quantité_Reservée As Integer = 0
        Dim Date_reservation = Now
        Dim Date_delivrance_prévue = Now

        If BDD.Produits_ReservésTableAdapter.GetData_ligne(CurrentBenéficiaire.Num, COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                            COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                             COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                              COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value).Rows.Count > 0 Then
            MyMsg_Box.Presentation("Officine ?", "Produit déja réservé pour ce patient." & vbCrLf & vbCrLf & "Que voulez vous faire?", True, "Poursuivre", True, "Annuler", True, "Suppr reservation")
            Select Case MyMsg_Box.ShowDialog
                Case Windows.Forms.DialogResult.Yes
                    Dim reserv_data = BDD.Produits_ReservésTableAdapter.GetData_ligne(CurrentBenéficiaire.Num, COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                            COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                             COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                              COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value).Item(0)
                    Dim my_reserv As New Reservation_Produit
                    my_reserv.Patient_NIRTextBox.Text = CurrentBenéficiaire.G101C8
                    my_reserv.Patient_DateNaissTextBox.Text = CurrentBenéficiaire.G104C12
                    my_reserv.Patient_RangNaissTextBox.Text = CurrentBenéficiaire.G104C13
                    my_reserv.Patient_QualitéTextBox.Text = CurrentBenéficiaire.G104C14
                    my_reserv.Produit_DésignationTextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
                    my_reserv.Produit_CIPTextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
                    my_reserv.Produit_EAN13TextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
                    my_reserv.Produit_CABTextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
                    my_reserv.Quantité_ReservéeTextBox.Text = reserv_data.Quantité_Reservée.ToString
                    my_reserv.Date_reservationDateTimePicker.Value = reserv_data.Date_reservation
                    my_reserv.Date_delivrance_prévueDateTimePicker.Value = reserv_data.Date_delivrance_prévue
                    Me.Visible = False
                    my_reserv.ShowDialog()
                    Me.Visible = True
                Case Windows.Forms.DialogResult.No
                    Exit Sub
                Case Windows.Forms.DialogResult.Cancel
                    BDD.Produits_ReservésTableAdapter.Delete_ligne(CurrentBenéficiaire.Num, COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                            COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                             COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value, _
                                                              COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value)
            End Select

        Else
            Dim my_reserv As New Reservation_Produit
            my_reserv.Patient_NIRTextBox.Text = CurrentBenéficiaire.G101C8
            my_reserv.Patient_DateNaissTextBox.Text = CurrentBenéficiaire.G104C12
            my_reserv.Patient_RangNaissTextBox.Text = CurrentBenéficiaire.G104C13
            my_reserv.Patient_QualitéTextBox.Text = CurrentBenéficiaire.G104C14
            my_reserv.Produit_DésignationTextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteDésignation.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
            my_reserv.Produit_CIPTextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
            my_reserv.Produit_EAN13TextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
            my_reserv.Produit_CABTextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
            my_reserv.Quantité_ReservéeTextBox.Text = COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteQuantité.Index, COMPTOIR_MAIN.Vente.CurrentRow.Index).Value
            my_reserv.Date_reservationDateTimePicker.Value = Now
            my_reserv.Date_delivrance_prévueDateTimePicker.Value = Now
            Me.Visible = False
            my_reserv.ShowDialog()
            Me.Visible = True

        End If




    End Sub

   
End Class