' 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
Public Class PDA_Main


    Public Vitale_Num As Integer




    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Select Case e.ColumnIndex
            Case Patient.Index
                Recherche_Patient_TextBox.Text = DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value
                affichage()
            Case Organisme.Index
                Recherche_Organisme_MyCombobox.Text = DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value
                affichage()
            Case Produit.Index
                Recherche_Produit_TextBox.Text = DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value
                affichage()
        End Select
    End Sub

    Private Sub affichage()
        Bandeau_info_bas_show("Création Liste ...")
        Try

       
        DataGridView1.Rows.Clear()
        Dim Recherche_Patient_string = ""

        Dim Recherche_Produit_string = ""
        If Recherche_Patient_TextBox.Text <> "" Then
            Recherche_Patient_string = "%" & Replace(Recherche_Patient_TextBox.Text, " ", "%") & "%"
        End If

        If Recherche_Produit_TextBox.Text <> "" Then
            Recherche_Produit_string = "%" & Replace(Recherche_Produit_TextBox.Text, " ", "%") & "%"
        End If

        Dim chroniques As New PharmaDataSet.ChroniqueDataTable
        Dim plans_poso As New PharmaDataSet.Plan_PosoDataTable


        If Vitale_Num = 0 Then
            Dim Chronique_Periode As Integer = 0
            Try
                Chronique_Periode = CInt(Chronique_Periode_MyCombobox.Text)
            Catch ex As Exception
            End Try

            chroniques = BDD.ChroniqueTableAdapter.GetData_affichage_total(Recherche_Produit_string, Chronique_Periode, Recherche_Patient_string, Recherche_Organisme_MyCombobox.Text)
            plans_poso = BDD.Plan_PosoTableAdapter.GetData_affichage_total(DateTimePicker1.Value, DateTimePicker2.Value, Recherche_Produit_string, Chronique_Periode, Recherche_Patient_string, Recherche_Organisme_MyCombobox.Text)
        Else

            chroniques = BDD.ChroniqueTableAdapter.GetDataBy_Vitale_Num_List(Vitale_Num)
            plans_poso = BDD.Plan_PosoTableAdapter.GetDataBy_Vitale_Num(Vitale_Num)

        End If
            For r = 0 To chroniques.Rows.Count - 1

                Dim liste_date = liste_date_medicament(chroniques(r))


                For d = 0 To liste_date.Count - 1

                    If add_the_date(chroniques(r), liste_date(d)) Then
                        If chroniques(r).Poso_MATIN > 0 Then
                            DataGridView1.Rows.Add()
                        End If
                        If chroniques(r).Poso_MIDI > 0 Then
                            DataGridView1.Rows.Add()
                        End If
                        If chroniques(r).Poso_SOIR > 0 Then
                            DataGridView1.Rows.Add()
                        End If
                        If chroniques(r).Poso_COUCHER > 0 Then
                            DataGridView1.Rows.Add()
                        End If
                        If chroniques(r).Poso_BESOIN > 0 Then
                            DataGridView1.Rows.Add()
                        End If
                    End If
                Next
            Next
        For r = 0 To plans_poso.Rows.Count - 1
            DataGridView1.Rows.Add()
        Next
        For r = 0 To DataGridView1.Rows.Count - 1
            DataGridView1.Item(GO.Index, r).Value = True
        Next
        Dim index = 0
            For r = 0 To chroniques.Rows.Count - 1
                Dim vitale = BDD.VitaleTableAdapter.GetDataBy_Num(chroniques(r).Vitale_Num).Item(0)
                Dim liste_date = liste_date_medicament(chroniques(r))
                'MsgBox(vitale.G104C1 & vbCrLf & chroniques(r).Produit_Désignation & vbCrLf & vbCrLf & "liste_date.Count  " & liste_date.Count.ToString)

                For d = 0 To liste_date.Count - 1
                    If add_the_date(chroniques(r), liste_date(d)) Then
                        If chroniques(r).Poso_MATIN > 0 Then
                            DataGridView1.Item(VitaleNum.Index, index).Value = chroniques(r).Vitale_Num
                            DataGridView1.Item(Patient.Index, index).Value = vitale.G104C1 & " " & vitale.G104C3
                            DataGridView1.Item(Organisme.Index, index).Value = vitale.Organisme
                            DataGridView1.Item(Produit.Index, index).Value = chroniques(r).Produit_Désignation
                            DataGridView1.Item(CIP.Index, index).Value = chroniques(r).Produit_CIP
                            DataGridView1.Item(EAN13.Index, index).Value = chroniques(r).Produit_EAN13
                            DataGridView1.Item(CAB.Index, index).Value = chroniques(r).Produit_CAB
                            DataGridView1.Item(Date_.Index, index).Value = liste_date(d)
                            DataGridView1.Item(Poso.Index, index).Value = chroniques(r).Poso_MATIN
                            DataGridView1.Item(heure.Index, index).Value = "0800"
                            DataGridView1.Item(Prescr_num.Index, index).Value = chroniques(r).Prescr_IDinterne
                            DataGridView1.Item(PDA_Num.Index, index).Value = chroniques(r).PDA_Num
                            If chroniques(r).PDA_Num <> 0 Then
                                Try
                                    DataGridView1.Item(PDA_dernier.Index, index).Value = BDD.PDATableAdapter.GetDataBy_Num(chroniques(r).PDA_Num).Item(0)._Date
                                Catch ex As Exception
                                End Try
                            End If
                            index = index + 1
                        End If
                        If chroniques(r).Poso_MIDI > 0 Then
                            DataGridView1.Item(VitaleNum.Index, index).Value = chroniques(r).Vitale_Num
                            DataGridView1.Item(Patient.Index, index).Value = vitale.G104C1 & " " & vitale.G104C3
                            DataGridView1.Item(Organisme.Index, index).Value = vitale.Organisme
                            DataGridView1.Item(Produit.Index, index).Value = chroniques(r).Produit_Désignation
                            DataGridView1.Item(CIP.Index, index).Value = chroniques(r).Produit_CIP
                            DataGridView1.Item(EAN13.Index, index).Value = chroniques(r).Produit_EAN13
                            DataGridView1.Item(CAB.Index, index).Value = chroniques(r).Produit_CAB
                            DataGridView1.Item(Date_.Index, index).Value = liste_date(d)
                            DataGridView1.Item(Poso.Index, index).Value = chroniques(r).Poso_MIDI
                            DataGridView1.Item(heure.Index, index).Value = "1200"
                            DataGridView1.Item(Prescr_num.Index, index).Value = chroniques(r).Prescr_IDinterne
                            DataGridView1.Item(PDA_Num.Index, index).Value = chroniques(r).PDA_Num
                            If chroniques(r).PDA_Num <> 0 Then
                                Try
                                    DataGridView1.Item(PDA_dernier.Index, index).Value = BDD.PDATableAdapter.GetDataBy_Num(chroniques(r).PDA_Num).Item(0)._Date
                                Catch ex As Exception
                                End Try
                            End If
                            index = index + 1
                        End If
                        If chroniques(r).Poso_SOIR > 0 Then
                            DataGridView1.Item(VitaleNum.Index, index).Value = chroniques(r).Vitale_Num
                            DataGridView1.Item(Patient.Index, index).Value = vitale.G104C1 & " " & vitale.G104C3
                            DataGridView1.Item(Organisme.Index, index).Value = vitale.Organisme
                            DataGridView1.Item(Produit.Index, index).Value = chroniques(r).Produit_Désignation
                            DataGridView1.Item(CIP.Index, index).Value = chroniques(r).Produit_CIP
                            DataGridView1.Item(EAN13.Index, index).Value = chroniques(r).Produit_EAN13
                            DataGridView1.Item(CAB.Index, index).Value = chroniques(r).Produit_CAB
                            DataGridView1.Item(Date_.Index, index).Value = liste_date(d)
                            DataGridView1.Item(Poso.Index, index).Value = chroniques(r).Poso_SOIR
                            DataGridView1.Item(heure.Index, index).Value = "1900"
                            DataGridView1.Item(Prescr_num.Index, index).Value = chroniques(r).Prescr_IDinterne
                            DataGridView1.Item(PDA_Num.Index, index).Value = chroniques(r).PDA_Num
                            If chroniques(r).PDA_Num <> 0 Then
                                Try
                                    DataGridView1.Item(PDA_dernier.Index, index).Value = BDD.PDATableAdapter.GetDataBy_Num(chroniques(r).PDA_Num).Item(0)._Date
                                Catch ex As Exception
                                End Try
                            End If
                            index = index + 1
                        End If
                        If chroniques(r).Poso_COUCHER > 0 Then
                            DataGridView1.Item(VitaleNum.Index, index).Value = chroniques(r).Vitale_Num
                            DataGridView1.Item(Patient.Index, index).Value = vitale.G104C1 & " " & vitale.G104C3
                            DataGridView1.Item(Organisme.Index, index).Value = vitale.Organisme
                            DataGridView1.Item(Produit.Index, index).Value = chroniques(r).Produit_Désignation
                            DataGridView1.Item(CIP.Index, index).Value = chroniques(r).Produit_CIP
                            DataGridView1.Item(EAN13.Index, index).Value = chroniques(r).Produit_EAN13
                            DataGridView1.Item(CAB.Index, index).Value = chroniques(r).Produit_CAB
                            DataGridView1.Item(Date_.Index, index).Value = liste_date(d)
                            DataGridView1.Item(Poso.Index, index).Value = chroniques(r).Poso_COUCHER
                            DataGridView1.Item(heure.Index, index).Value = "2100"
                            DataGridView1.Item(Prescr_num.Index, index).Value = chroniques(r).Prescr_IDinterne
                            DataGridView1.Item(PDA_Num.Index, index).Value = chroniques(r).PDA_Num
                            If chroniques(r).PDA_Num <> 0 Then
                                DataGridView1.Item(PDA_dernier.Index, index).Value = BDD.PDATableAdapter.GetDataBy_Num(chroniques(r).PDA_Num).Item(0)._Date
                            End If
                            index = index + 1
                        End If
                        If chroniques(r).Poso_BESOIN > 0 Then
                            DataGridView1.Item(VitaleNum.Index, index).Value = chroniques(r).Vitale_Num
                            DataGridView1.Item(Patient.Index, index).Value = vitale.G104C1 & " " & vitale.G104C3
                            DataGridView1.Item(Organisme.Index, index).Value = vitale.Organisme
                            DataGridView1.Item(Produit.Index, index).Value = chroniques(r).Produit_Désignation
                            DataGridView1.Item(CIP.Index, index).Value = chroniques(r).Produit_CIP
                            DataGridView1.Item(EAN13.Index, index).Value = chroniques(r).Produit_EAN13
                            DataGridView1.Item(CAB.Index, index).Value = chroniques(r).Produit_CAB
                            DataGridView1.Item(Date_.Index, index).Value = liste_date(d)
                            DataGridView1.Item(Poso.Index, index).Value = chroniques(r).Poso_BESOIN
                            DataGridView1.Item(heure.Index, index).Value = "1000"
                            DataGridView1.Item(Prescr_num.Index, index).Value = chroniques(r).Prescr_IDinterne
                            DataGridView1.Item(PDA_Num.Index, index).Value = chroniques(r).PDA_Num
                            If chroniques(r).PDA_Num <> 0 Then
                                Try
                                    DataGridView1.Item(PDA_dernier.Index, index).Value = BDD.PDATableAdapter.GetDataBy_Num(chroniques(r).PDA_Num).Item(0)._Date
                                Catch ex As Exception
                                End Try
                            End If
                            index = index + 1
                        End If

                    End If

                Next
            Next
        For r = 0 To plans_poso.Rows.Count - 1
            DataGridView1.Item(VitaleNum.Index, r + index).Value = plans_poso(r).Vitale_Num
            Dim vitale = BDD.VitaleTableAdapter.GetDataBy_Num(plans_poso(r).Vitale_Num).Item(0)
            DataGridView1.Item(Patient.Index, r + index).Value = vitale.G104C1 & " " & vitale.G104C3
            DataGridView1.Item(Organisme.Index, r + index).Value = vitale.Organisme
            DataGridView1.Item(Produit.Index, r + index).Value = plans_poso(r).Produit_Désignation
            DataGridView1.Item(CIP.Index, r + index).Value = plans_poso(r).Produit_CIP
            DataGridView1.Item(EAN13.Index, r + index).Value = plans_poso(r).Produit_EAN13
            DataGridView1.Item(CAB.Index, r + index).Value = plans_poso(r).Produit_CAB
            DataGridView1.Item(Date_.Index, r + index).Value = plans_poso(r)._Date
            DataGridView1.Item(Poso.Index, r + index).Value = plans_poso(r).Poso
            DataGridView1.Item(heure.Index, r + index).Value = plans_poso(r).heure
            DataGridView1.Item(Prescr_num.Index, r + index).Value = plans_poso(r).Prescr_IDinterne
            DataGridView1.Item(PDA_Num.Index, index).Value = plans_poso(r).PDA_Num
            If plans_poso(r).PDA_Num <> 0 Then
                DataGridView1.Item(PDA_dernier.Index, r + index).Value = BDD.PDATableAdapter.GetDataBy_Num(plans_poso(r).PDA_Num).Item(0)._Date
            End If
        Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Bandeau_info_bas_hide()
    End Sub

    Private Sub affichage_histo()
        Dim histo = BDD.PDATableAdapter.GetData_last(50)
        DataGridView2.Rows.Clear()
        For r = 0 To histo.Rows.Count - 1
            DataGridView2.Rows.Add()
        Next
        For r = 0 To histo.Rows.Count - 1
            DataGridView2.Item(Num.Index, r).Value = histo(r).Num
            DataGridView2.Item(Date__.Index, r).Value = histo(r)._Date
            DataGridView2.Item(Opérateur.Index, r).Value = histo(r).Opérateur
            DataGridView2.Item(Date_Debut.Index, r).Value = histo(r).Date_Debut
            DataGridView2.Item(Dtae_Fin.Index, r).Value = histo(r).Date_Fin
            DataGridView2.Item(modifier.Index, r).Value = "modifier"
            DataGridView2.Item(Supprimer.Index, r).Value = "supprimer"
        Next



    End Sub
    Private Function add_the_date(ByVal chronique_item As PharmaDataSet.ChroniqueRow, ByVal date_ As Date) As Boolean

        If chronique_item.Poso_Jours_liste = "1111111" And chronique_item.Poso_Interval_jour = 1 And chronique_item.Poso_Interval_dénominateur = 1 Then
            Return True
        ElseIf chronique_item.Poso_Jours_liste <> "1111111" Then
            If (date_.DayOfWeek = DayOfWeek.Monday And Mid(chronique_item.Poso_Jours_liste, 1, 1) = "1") _
                Or (date_.DayOfWeek = DayOfWeek.Tuesday And Mid(chronique_item.Poso_Jours_liste, 2, 1) = "1") _
                Or (date_.DayOfWeek = DayOfWeek.Wednesday And Mid(chronique_item.Poso_Jours_liste, 3, 1) = "1") _
                Or (date_.DayOfWeek = DayOfWeek.Thursday And Mid(chronique_item.Poso_Jours_liste, 4, 1) = "1") _
                Or (date_.DayOfWeek = DayOfWeek.Friday And Mid(chronique_item.Poso_Jours_liste, 5, 1) = "1") _
                Or (date_.DayOfWeek = DayOfWeek.Saturday And Mid(chronique_item.Poso_Jours_liste, 6, 1) = "1") _
                Or (date_.DayOfWeek = DayOfWeek.Sunday And Mid(chronique_item.Poso_Jours_liste, 7, 1) = "1") Then
                Return True
            End If
        Else
            Dim ecartjours = Math.Abs(DateDiff(DateInterval.Day, chronique_item.Date_dernière_delivrance, date_))
            ecartjours = ecartjours Mod chronique_item.Poso_Interval_dénominateur
            If ecartjours < chronique_item.Poso_Interval_jour Then
                Return True
            End If
        End If
        Return False
    End Function

    Private Function liste_date_medicament(ByVal chronique_item As PharmaDataSet.ChroniqueRow) As List(Of Date)
        Dim liste_date As New List(Of Date)
        If chronique_item.chronique = True Then
            Dim date_debut = DateTimePicker1.Value
            While date_debut <= DateTimePicker2.Value
                liste_date.Add(date_debut)
                date_debut = date_debut.AddDays(1)
            End While
            Return liste_date
        End If
        Return liste_date

    End Function

    Private Sub OK_Button_Click(sender As Object, e As EventArgs) Handles OK_Button.Click
        affichage()
    End Sub

 
    Private Sub PDA_Main_Load(sender As Object, e As EventArgs) Handles Me.Load

        DataGridView1.Columns(Date_.Index).DefaultCellStyle.Format = "dd/MM/yyyy"
        DateTimePicker1.Value = New System.DateTime(Now.Year, Now.Month, Now.Day, 0, 0, 1)
        Dim fin = DateAdd(DateInterval.Day, 7, DateTimePicker1.Value)
        fin = DateAdd(DateInterval.Second, 10, fin)
        DateTimePicker2.Value = fin
        If Vitale_Num <> 0 Then
            affichage()
            Recherche_Patient_TextBox.Enabled = False
            Recherche_Organisme_MyCombobox.Enabled = False
        End If
        affichage_histo()

        Dim période = BDD.Chronique_PériodeTableAdapter.GetData
        Chronique_Periode_MyCombobox.Items.Clear()
        Chronique_Periode_MyCombobox.Buttons_color_list = New List(Of String)
        For r = 0 To période.Rows.Count - 1
            Chronique_Periode_MyCombobox.Items.Add(période.Item(r).Id)
            Chronique_Periode_MyCombobox.Buttons_color_list.Add(période.Item(r).Color_hex)
        Next
        Dim organismes = BDD.OrganismesTableAdapter.GetData_OrderByNom
        Recherche_Organisme_MyCombobox.Items.Clear()
        For r = 0 To organismes.Rows.Count - 1
            Recherche_Organisme_MyCombobox.Items.Add(organismes.Item(r).Nom)
        Next
    End Sub


    Private Sub Go_Button_Click(sender As Object, e As EventArgs) Handles Go_Button.Click
        If DataGridView1.Rows.Count = 0 Then Exit Sub

        Dim gogo = False
        For r = 0 To DataGridView1.Rows.Count - 1
            If DataGridView1.Item(GO.Index, r).Value = True Then
                gogo = True
                Exit For
            End If
        Next
        If gogo = True Then
            Dim Num_PDA = BDD.PDATableAdapter.Select_Max_Num + 1
            Dim num_ligne = 1
            BDD.PDATableAdapter.Insert(Num_PDA, Now, current_User.ID, DateTimePicker1.Value, DateTimePicker2.Value)
            For r = 0 To DataGridView1.Rows.Count - 1
                If DataGridView1.Item(GO.Index, r).Value = True Then
                    BDD.PDA_LignesTableAdapter.Insert(Num_PDA, num_ligne, DataGridView1.Item(VitaleNum.Index, r).Value, DataGridView1.Item(CIP.Index, r).Value, _
                                                      DataGridView1.Item(EAN13.Index, r).Value, DataGridView1.Item(EAN13.Index, r).Value, DataGridView1.Item(Produit.Index, r).Value, _
                                                      DataGridView1.Item(Date_.Index, r).Value, "", "", Now, DataGridView1.Item(Prescr_num.Index, r).Value, _
                                                      DataGridView1.Item(Poso.Index, r).Value, DataGridView1.Item(heure.Index, r).Value)
                    num_ligne = num_ligne + 1
                    BDD.ChroniqueTableAdapter.Update_PDA_Num(Num_PDA, DataGridView1.Item(Produit.Index, r).Value, DataGridView1.Item(CIP.Index, r).Value, DataGridView1.Item(EAN13.Index, r).Value, _
                                                             DataGridView1.Item(EAN13.Index, r).Value, DataGridView1.Item(VitaleNum.Index, r).Value)
                    BDD.Plan_PosoTableAdapter.Update_PDA_Num(Num_PDA, DataGridView1.Item(Produit.Index, r).Value, DataGridView1.Item(CIP.Index, r).Value, DataGridView1.Item(EAN13.Index, r).Value, _
                                                             DataGridView1.Item(EAN13.Index, r).Value, DataGridView1.Item(VitaleNum.Index, r).Value)
                End If
            Next
            GO_ROBOT(Num_PDA)
        End If

        affichage()
    End Sub

    Private Sub Recherche_Patient_TextBox_TextChanged(sender As Object, e As EventArgs) Handles Recherche_Patient_TextBox.TextChanged

    End Sub

    Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick
        Select Case e.ColumnIndex
            Case modifier.Index
                Dim my_detail As New PDA_Détail
                my_detail.num_PDA = DataGridView2.Item(Num.Index, e.RowIndex).Value
                Me.Hide()
                my_detail.ShowDialog()
                Me.Show()
            Case Supprimer.Index
                MyMsg_Box.Presentation("Officine ?", "La suppression est définitive, poursuivre ?", True, "Oui", True, "Non", False, "")
                If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
                    BDD.PDA_LignesTableAdapter.Delete_by_NumPDA(DataGridView2.Item(Num.Index, e.RowIndex).Value)
                    BDD.PDATableAdapter.Delete_by_Num(DataGridView2.Item(Num.Index, e.RowIndex).Value)
                    affichage_histo()
                End If
        End Select
    End Sub

    Public Sub GO_ROBOT(ByVal Num_PDA As Integer)
        Bandeau_info_bas_show("Communication avec Synmed ...")
        Dim ListProd_for_NumOrdo As New List(Of String)

        Try
            Dim data = BDD.PDA_LignesTableAdapter.GetDataBy_Num_PDA(Num_PDA)
            Dim nomfichier = Num_PDA.ToString & "_" & Format(Now, ("yyyyMMdd"))
            Dim sw As New StreamWriter(Application.StartupPath & "\" & nomfichier, True, System.Text.Encoding.Default)
            For r = 0 To data.Rows.Count - 1
                Dim vitale = BDD.VitaleTableAdapter.GetDataBy_Num(data(r).Vitale_Num).Item(0)
                Dim prescr = ""
                Try
                    prescr = BDD.PrescripteursTableAdapter.GetPrescripteurDataByIDinterne(data(r).Prescr_num).Item(0).NomPrénom
                Catch ex As Exception
                End Try
                Dim num_ordo As Integer
                If Not ListProd_for_NumOrdo.Contains(data(r).Prod_EAN13 & data(r).Vitale_Num.ToString) Then
                    ListProd_for_NumOrdo.Add(data(r).Prod_EAN13 & data(r).Vitale_Num.ToString)
                End If
                For rr = 0 To ListProd_for_NumOrdo.Count - 1
                    If ListProd_for_NumOrdo(rr) = data(r).Prod_EAN13 & data(r).Vitale_Num.ToString Then
                        num_ordo = rr + 1
                        Exit For
                    End If
                Next

                Dim poso As String = ""
                If data(r).Poso Mod 1 = 0 Then
                    poso = CInt(data(r).Poso.ToString)
                ElseIf data(r).Poso Mod 1 = (0.5) Then
                    poso = "-2" & (data(r).Poso - (0.5)) * 2 + 1.ToString
                ElseIf data(r).Poso Mod 1 = (0.33) Then
                    poso = "-3" & (data(r).Poso - (0.33)) * 3 + 1.ToString
                ElseIf data(r).Poso Mod 1 = (0.66) Then
                    poso = "-3" & (data(r).Poso - (0.66)) * 3 + 2.ToString
                ElseIf data(r).Poso Mod 1 = (0.25) Then
                    poso = "-4" & (data(r).Poso - (0.25)) * 4 + 1.ToString
                ElseIf data(r).Poso Mod 1 = (0.75) Then
                    poso = "-4" & (data(r).Poso - (0.75)) * 4 + 3.ToString
                End If

                Dim etage = ""
                Dim chambre = ""
                Dim lit = ""
                Try
                    Dim PDA_InfoCompl = BDD.PDA_InfoComplTableAdapter.GetDataBy_VitaleNum(data(r).Vitale_Num)
                    If PDA_InfoCompl.Rows.Count > 0 Then
                        etage = PDA_InfoCompl(0).Etage
                        chambre = PDA_InfoCompl(0).Chambre
                        lit = PDA_InfoCompl(0).Lit
                    End If
                Catch ex As Exception

                End Try
            

                'NOM DE L'ETABLISSEMENT,A VOTRE,,666,2,julien misiak,,,,,,,,plus 2 ui si besoin,,,,X,N,1
                Dim line = Format(data(r)._Date, "ddMMyyyy") & "," & data(r).heure & "," & data(r).Prod_EAN13 & "," & poso & "," & num_ordo.ToString & "," & "," & vitale.G104C1 & " " & vitale.G104C3 & "," & _
                "," & vitale.Adresse & "," & vitale.Téléphone & "," & "," & vitale.Organisme_de_residence & "," & etage & "," & chambre & "," & lit & "," & prescr & "," & "," & "," & "," & "," & "," & "," & "," & "," & _
                "," & "," & "," & "," & "," & data(r).Vitale_Num.ToString

                sw.WriteLine(line)
            Next
            sw.Close()
            MyMsg_Box.Presentation("PDA", "Le fichier pour le robot est enregistré" & vbCrLf & vbCrLf & nomfichier, False, "", False, "", True, "Ok")
            MyMsg_Box.ShowDialog()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Bandeau_info_bas_hide()
    End Sub
End Class