' 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.Xml
Public Class Import_Produit_From_Vidal

    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then
            TextBox1_Validated(Nothing, Nothing)
        End If
    End Sub


    Private Sub TextBox1_Validated(sender As Object, e As EventArgs) Handles TextBox1.Validated
        recherche(TextBox1.Text)
    End Sub

    Private Sub recherche(ByVal strg_recherche As String)
        Label1.Text = "RECHERCHE EN COURS..."
        Application.DoEvents()
        DataGridView1.Rows.Clear()

        Dim Vidal_PackService As New Vidal_PackService.PackService
        Vidal_PackService.Timeout = 60000 '3000

        Dim searchByCip = Vidal_PackService.searchByCip(strg_recherche)

        Dim strg_recherche_tab() As String
        ReDim strg_recherche_tab(0)
        strg_recherche_tab(0) = strg_recherche
        Dim searchByCodes = Vidal_PackService.searchByCodes(strg_recherche_tab)

        Dim searchByName = Vidal_PackService.searchByName(strg_recherche)

        If Not searchByCip Is Nothing Then
            DataGridView1.Rows.Add()
            DataGridView1.Item(Désignation.Index, 0).Value = searchByCip.name
            DataGridView1.Item(CIP.Index, 0).Value = searchByCip.cip13
            DataGridView1.Item(Code.Index, 0).Value = searchByCip.ean
            DataGridView1.Item(Vidal_ID.Index, 0).Value = searchByCip.id
            DataGridView1.Item(Vidal_ProductID.Index, 0).Value = searchByCip.productId

        ElseIf Not searchByCodes Is Nothing And searchByCodes.Count > 0 Then
            For Each item In searchByCodes
                DataGridView1.Rows.Add()
            Next
            Dim index = 0
            For Each item In searchByCodes
                DataGridView1.Item(Désignation.Index, index).Value = item.name
                DataGridView1.Item(CIP.Index, index).Value = item.cip13
                DataGridView1.Item(Code.Index, index).Value = item.ean
                DataGridView1.Item(Vidal_ID.Index, index).Value = item.id
                DataGridView1.Item(Vidal_ProductID.Index, index).Value = item.productId
                index = index + 1
            Next

        ElseIf Not searchByName Is Nothing And searchByName.Count > 0 Then
            For Each item In searchByName
                DataGridView1.Rows.Add()
            Next
            Dim index = 0
            For Each item In searchByName
                DataGridView1.Item(Désignation.Index, index).Value = item.name
                DataGridView1.Item(CIP.Index, index).Value = item.cip13
                DataGridView1.Item(Code.Index, index).Value = item.ean
                DataGridView1.Item(Vidal_ID.Index, index).Value = item.id
                DataGridView1.Item(Vidal_ProductID.Index, index).Value = item.productId
                index = index + 1
            Next
        End If
        Label1.Text = "Rechercher :"
        If DataGridView1.Rows.Count > 0 Then
            DataGridView1.Focus()
        Else
            If IsNumeric(TextBox1.Text) Then
                Dim doc = VIDAL_Rest.Search_by_code(TextBox1.Text, "")
                If Not doc Is Nothing Then
                    Dim id As String = ""
                    Dim CIP As String = ""
                    Dim CIP13 As String = ""
                    Dim ean As String = ""
                    Dim name As String = ""
                    Dim refundRate As String = ""
                    Dim LPP As String = ""
                    Dim dose As String = ""
                    Dim galenicForm As String = ""
                    Dim liste As String = ""
                    Dim prestation As String = ""
                    Dim LPP_Type_Service As String = ""
                    Dim publicPrice, vatRate, refundingBase As Decimal
                    Dim Lpp_Quantité As Integer = 0
                    Dim LPP_kit = False
                    Dim root As XmlNode = doc.DocumentElement
                    Dim nsmgr As New XmlNamespaceManager(doc.NameTable)
                    nsmgr.AddNamespace("bk", "http://www.w3.org/2005/Atom")
                    Dim nsmgr2 As New XmlNamespaceManager(doc.NameTable)
                    nsmgr2.AddNamespace("bk2", "http://api.vidal.net/-/spec/vidal-api/1.0/")
                    Dim entries As XmlNodeList = root.SelectNodes("descendant::bk:entry", nsmgr)
                    For Each entry As XmlNode In entries
                        For Each child_node As XmlNode In entry.ChildNodes
                            Select Case child_node.Name
                                Case "vidal:id"
                                    id = child_node.InnerText
                                Case "vidal:cip"
                                    CIP = child_node.InnerText
                                Case "vidal:cip13"
                                    CIP13 = child_node.InnerText
                                Case "vidal:ean"
                                    ean = child_node.InnerText
                                Case "vidal:name"
                                    name = child_node.InnerText
                                Case "vidal:publicPrice"
                                    publicPrice = CDec(Replace(child_node.InnerText, ".", ","))
                                Case "vidal:vatRate "
                                    vatRate = CDec(Replace(child_node.InnerText, ".", ","))
                                Case "vidal:refundRate"
                                    refundRate = child_node.InnerText
                                Case "vidal:dose"
                                    dose = child_node.InnerText
                                Case "vidal:galenicForm"
                                    galenicForm = child_node.InnerText
                                Case "vidal:list "
                                    liste = child_node.InnerText
                                Case "vidal:list"
                                    liste = child_node.InnerText
                                Case "vidal:actCode"
                                    prestation = child_node.Attributes("name").Value

                                Case "vidal:refundingBase"
                                    refundingBase = CDec(Replace(child_node.InnerText, ".", ","))

                            End Select
                        Next
                        If refundRate = "LPPR" Then
                            Dim lppr_doc = VIDAL_Rest.LPPR_by_codeVidal(id)
                            If Not lppr_doc Is Nothing Then
                                Dim lppr_root As XmlNode = lppr_doc.DocumentElement
                                Dim lppr_nsmgr As New XmlNamespaceManager(lppr_doc.NameTable)
                                lppr_nsmgr.AddNamespace("bk", "http://www.w3.org/2005/Atom")
                                Dim lppr_nsmgr2 As New XmlNamespaceManager(lppr_doc.NameTable)
                                lppr_nsmgr2.AddNamespace("bk2", "http://api.vidal.net/-/spec/vidal-api/1.0/")
                                Dim lppr_entries As XmlNodeList = lppr_root.SelectNodes("descendant::bk:entry", lppr_nsmgr)
                                Dim lppr_structs As New List(Of VIDAL_Rest.lppr_struct)
                                For Each lppr_entry As XmlNode In lppr_entries
                                    If lppr_entry.Attributes("vidal:categories").Value.ToString = "LPPR" Then
                                        Dim my_lppr_struct As New VIDAL_Rest.lppr_struct
                                        For Each child_node As XmlNode In entry.ChildNodes

                                            Select Case child_node.Name
                                                Case "vidal:code"
                                                    my_lppr_struct.codelpp = child_node.InnerText
                                                Case "vidal:refundBase"
                                                    my_lppr_struct.prixlpp = child_node.InnerText
                                                Case "vidal:act"
                                                    my_lppr_struct.Prestation = child_node.Attributes("name").Value
                                                Case "vidal:service"
                                                    Select Case child_node.InnerText
                                                        Case "BUYING"
                                                            my_lppr_struct.Type_prestation = "A"
                                                        Case "DELIVERY"
                                                            my_lppr_struct.Type_prestation = "V"
                                                        Case "MAINTENANCE"
                                                            my_lppr_struct.Type_prestation = "E"
                                                        Case "RENTING"
                                                            my_lppr_struct.Type_prestation = "L"
                                                        Case "REPAIR"
                                                            my_lppr_struct.Type_prestation = "R"
                                                        Case "SERVICE"
                                                            my_lppr_struct.Type_prestation = "S"
                                                        Case Else
                                                            my_lppr_struct.Type_prestation = "P"
                                                    End Select
                                                Case "vidal:name"
                                                    my_lppr_struct.Libellé = child_node.InnerText
                                                Case "vidal:coef"
                                                    my_lppr_struct.coef = child_node.InnerText
                                            End Select
                                        Next
                                        lppr_structs.Add(my_lppr_struct)
                                    End If
                                Next
                                If lppr_structs.Count = 1 Then
                                    LPP = lppr_structs(0).codelpp
                                    Lpp_Quantité = CInt(lppr_structs(0).coef)
                                    LPP_Type_Service = lppr_structs(0).Type_prestation
                                ElseIf lppr_structs.Count > 1 Then
                                    LPP_kit = True
                                    COMPTOIR_MAIN.KitsTableAdapter.Delete_by_Désignation(name)
                                    For Each item In lppr_structs
                                        COMPTOIR_MAIN.KitsTableAdapter.Insert("", name, item.codelpp, item.coef)
                                        Lpp_Quantité = 1
                                    Next
                                End If
                            End If
                        End If
                    Next
                    If refundingBase > 0 And refundingBase <> publicPrice Then
                        BDD.BDM_TFRTableAdapter.Insert(CIP13, refundingBase, Now)
                    End If
                    'BDD.ProduitsTableAdapter.Insert(CIP,CIP13,ean,name,publicPrice.ToString,vatRate .ToString,0,LPP,dose,galenicForm,"01/01/1901 00:00:00",False,liste,prestation,refundingBase.ToString,"", Lpp_Quantité, _
                    '                                LPP_Type_Service,100,


                End If
            End If
        End If
        Application.DoEvents()
    End Sub

    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Select Case e.ColumnIndex
            Case Info.Index
                Dim psi As New ProcessStartInfo("http://vidal.fr/rest/redirect-product/id:" & DataGridView1.Item(Vidal_ProductID.Index, DataGridView1.CurrentRow.Index).Value)
                psi.WindowStyle = ProcessWindowStyle.Maximized
                Process.Start(psi)

            Case Importer.Index
                import()

        End Select
    End Sub

    Private Sub import()
        Label1.Text = "Importation en cours"
        Application.DoEvents()
        If COMPTOIR_MAIN.ProduitsTableAdapter.GetDataByInfo("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", _
                                                                    DataGridView1.Item(CIP.Index, DataGridView1.CurrentRow.Index).Value, _
                                                                    DataGridView1.Item(Désignation.Index, DataGridView1.CurrentRow.Index).Value).Rows.Count > 0 Then
            MyMsg_Box.Presentation("Officine", "Produit Existant dans la base: " & COMPTOIR_MAIN.ProduitsTableAdapter.GetDataByInfo("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", DataGridView1.Item(CIP.Index, DataGridView1.CurrentRow.Index).Value, DataGridView1.Item(Désignation.Index, DataGridView1.CurrentRow.Index).Value).Item(0).Designation & " " & COMPTOIR_MAIN.ProduitsTableAdapter.GetDataByInfo("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", DataGridView1.Item(CIP.Index, DataGridView1.CurrentRow.Index).Value, DataGridView1.Item(Désignation.Index, DataGridView1.CurrentRow.Index).Value).Item(0).EAN13 & " " & COMPTOIR_MAIN.ProduitsTableAdapter.GetDataByInfo("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", DataGridView1.Item(CIP.Index, DataGridView1.CurrentRow.Index).Value, DataGridView1.Item(Désignation.Index, DataGridView1.CurrentRow.Index).Value).Item(0).CAB, False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Exit Sub

        Else
            Dim Vidal_PackService As New Vidal_PackService.PackService

            Vidal_PackService.Timeout = 60000 '3000
            Dim pack = Vidal_PackService.searchById(DataGridView1.Item(Vidal_ID.Index, DataGridView1.CurrentRow.Index).Value)

            If Not pack Is Nothing Then
                Dim tva As Single
                If Not pack.vatRateValue Is Nothing Then
                    tva = pack.vatRateValue
                Else
                    MyMsg_Box.Presentation("Officine", "Pas de données TVA dans Vidal pour " & pack.name & " " & pack.cip13 & " " & pack.ean, False, "", False, "", True, "OK")
                    MyMsg_Box.ShowDialog()
                End If
                Dim contenance As String = ""
                If Not pack.dose Is Nothing Then If Not pack.dose.ToString = "True" Then If Not pack.dose.ToString = "False" Then contenance = pack.dose
                Dim Unitecontenance As String = ""
                If Not pack.doseUnit Is Nothing Then If Not pack.doseUnit.ToString = "True" Then If Not pack.doseUnit.ToString = "False" Then Unitecontenance = pack.doseUnit
                Dim Assimilestupefiant As String
                If pack.narcoticPrescription = True Then Assimilestupefiant = "1"
                Dim prestation As String = ""
                If Not pack.actCode Is Nothing Then If Not pack.actCode.ToString = "True" Then If Not pack.actCode.ToString = "False" Then prestation = pack.actCode.ToString
                Dim liste As String = ""
                If Not pack.listValue Is Nothing Then If Not pack.listValue.ToString = "True" Then If Not pack.listValue.ToString = "False" Then liste = pack.listValue.ToString
                Dim Prestation_actCodeValue As String = ""
                If Not pack.actCodeValue Is Nothing Then If Not pack.actCodeValue.ToString = "True" Then If Not pack.actCodeValue.ToString = "False" Then Prestation_actCodeValue = pack.actCodeValue.ToString
                Dim CIS As String = ""
                If Not pack.cis Is Nothing Then If Not pack.cis.ToString = "True" Then If Not pack.cis.ToString = "False" Then If Not pack.cis.ToString = "False" Then CIS = pack.cis.ToString
                Dim communityAgrement As Boolean = pack.communityAgrement
                Dim dispensationPlace As String = pack.dispensationPlace.ToString
                Dim drugInSport As Boolean = pack.drugInSport
                Dim maxPrescriptionDuration As String = ""
                If Not pack.maxPrescriptionDuration Is Nothing Then If Not pack.maxPrescriptionDuration.ToString = "True" Then If Not pack.maxPrescriptionDuration.ToString = "False" _
                    Then maxPrescriptionDuration = pack.maxPrescriptionDuration.ToString
                Dim prescriptionName As String = pack.prescriptionName
                Dim offMarketDate As Date
                If Not pack.offMarketDate Is Nothing Then offMarketDate = pack.offMarketDate
                Dim onFreeAccess As Boolean = pack.onFreeAccess
                Dim onMarketDate As Date
                If Not pack.onMarketDate Is Nothing Then onMarketDate = pack.onMarketDate
                Dim otc As Boolean = pack.otc
                Dim Vidal_ProductID As String = pack.productId
                Dim withoutPrescr As Boolean = pack.withoutPrescr
                Dim Vidal_LpprService As New Vidal_LpprService.LpprService
                Vidal_LpprService.Timeout = 60000 '3000
                Dim lpp = Vidal_LpprService.searchByPackId(pack.id)
                Dim est_un_kit As Boolean = False
                Dim Type_prestation As String = ""
                If Not lpp Is Nothing And lpp.Count > 0 Then
                    If lpp.Count > 1 Then est_un_kit = True
                    For Each item In lpp
                        If COMPTOIR_MAIN.LPPTableAdapter.GetData_CodeLPP_Date(item.code, Format(Now, "yyyyMMdd")).Rows.Count = 0 Then
                            Dim Age_maximal As String = ""
                            If Not item.ageMax Is Nothing Then If Not item.ageMax.ToString = "True" Then If Not item.ageMax.ToString = "False" Then Age_maximal = item.ageMax.ToString
                            Dim Montant_maximal As String = ""
                            If Not item.salePriceLimit Is Nothing Then If Not item.salePriceLimit.ToString = "True" Then If Not item.salePriceLimit.ToString = "False" Then Montant_maximal = (item.salePriceLimit * 100).ToString
                            Dim Quantité_maximale As String = ""
                            If Not item.amountMax Is Nothing Then If Not item.amountMax.ToString = "True" Then If Not item.amountMax.ToString = "False" Then Quantité_maximale = item.amountMax.ToString
                            Select Case item.service.Value
                                Case officine.Vidal_LpprService.LpprServiceType.BUYING
                                    Type_prestation = "A"
                                Case officine.Vidal_LpprService.LpprServiceType.DELIVERY
                                    Type_prestation = "V"
                                Case officine.Vidal_LpprService.LpprServiceType.MAINTENANCE
                                    Type_prestation = "E"
                                Case officine.Vidal_LpprService.LpprServiceType.RENTING
                                    Type_prestation = "L"
                                Case officine.Vidal_LpprService.LpprServiceType.REPAIR
                                    Type_prestation = "R"
                                Case officine.Vidal_LpprService.LpprServiceType.SERVICE
                                    Type_prestation = "S"
                                Case Else
                                    Type_prestation = "P"
                            End Select
                            COMPTOIR_MAIN.LPPTableAdapter.Insert(item.code, (item.refundBase * 100).ToString, "99999999", "00010101", False, item.actCode.ToString, Age_maximal, "", "", False, False, item.name, Montant_maximal, "", "", Quantité_maximale, "", Type_prestation)
                        End If

                        If est_un_kit = True Then
                            COMPTOIR_MAIN.KitsTableAdapter.Insert("", pack.name, item.code, My_LPPR_get_Coef(pack.id, item.code))
                        End If
                    Next

                End If
                '
                Dim CAB As String = pack.cip13
                If Not pack.ean Is Nothing Then
                    If Not pack.ean.ToString = "True" And Not pack.ean.ToString = "False" Then
                        CAB = pack.ean.ToString
                    End If
                End If

                Dim prod_lpp As String = ""
                Dim LPP_Quantité As Decimal = 0
                If est_un_kit = False And Not lpp Is Nothing And lpp.Length > 0 Then
                    prod_lpp = lpp.ElementAt(0).code
                    LPP_Quantité = My_LPPR_get_Coef(pack.id, prod_lpp)
                End If
                If LPP_Quantité = 0 Then
                    LPP_Quantité = 1
                End If

                If pack.cip Is Nothing Then pack.cip = ""
                If pack.cip13 Is Nothing Then pack.cip13 = ""
                If pack.publicPrice Is Nothing Then
                    Dim prx As Decimal = 0
                    MyInptBox.my_showdialog(pack.name.ToString & vbCrLf & vbCrLf & "PRIX DE V€NTE TTC?", VarType(prx), 100, "")
                    pack.publicPrice = (MyInptBox.result).ToString
                End If


                If pack.cip13 <> "" Then 'au revoir cip7
                    pack.cip = ""
                End If
                Dim conditionnement_trimestriel As Boolean = False
                Dim prest As New List(Of String) From {"PH1", "PH2", "PH4", "PH7"}
                If prest.Contains(pack.actCode.ToString) Then
                    MyMsg_Box.Presentation("Officine ?", pack.name & vbCrLf & "S'agit-il d'un conditionement trimestriel?", True, "OUI", True, "NON", False, "")
                    If MyMsg_Box.ShowDialog() = Windows.Forms.DialogResult.Yes Then
                        conditionnement_trimestriel = True
                    End If
                End If
                Dim codePharma_ml As String = pack.cip13
                If CAB <> "" Then
                    codePharma_ml = CAB
                End If
                COMPTOIR_MAIN.ProduitsTableAdapter.Insert(pack.cip.ToString, pack.cip13.ToString, CAB, pack.name.ToString, pack.publicPrice.ToString, tva.ToString, 0, prod_lpp, contenance, Unitecontenance, _
                                       Now, False, liste, prestation, "", "", LPP_Quantité, Type_prestation, 100, conditionnement_trimestriel, 0, CIS, Prestation_actCodeValue, "", pack.id, communityAgrement, _
                                    dispensationPlace, drugInSport, maxPrescriptionDuration, offMarketDate, onFreeAccess, onMarketDate, otc, _
                                    prescriptionName, pack.productId, withoutPrescr, "", False, False, 0, 0, "", "", est_un_kit, False, False, codePharma_ml, "", 0, True, True, False, New Date(3000, 1, 1))
                BDD.Historique_ActionsTableAdapter.Insert(current_User.ID, Now, "Importation produit", pack.name.ToString & " " & pack.cip13.ToString & " " & CAB)
                MyMsg_Box.Presentation("Officine !", "Importation terminée", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
                Me.Close()
            End If

        End If

    End Sub
    Public Function My_LPPR_get_Coef(ByVal pack_id As System.Nullable(Of Integer), ByVal Code_Lpp As String) As Integer
        Try
            Dim toto() As System.Nullable(Of Integer)
            ReDim toto(0)
            toto(0) = pack_id
            Dim Vidal_LpprService2 As New Vidal_LpprService.LpprService
            Dim decomp = Vidal_LpprService2.decompositionPackByPackIds(toto)
            If decomp.Count > 0 Then
                Dim list_ = decomp(0).lppCompositionsList
                For n = 0 To list_.Count - 1
                    If list_(n).lppr.code = Code_Lpp Then
                        Return list_(n).nbLppr
                    End If
                Next
            End If
            Return (VIDAL_Rest.LPPR_get_Coef(pack_id, Code_Lpp))
        Catch ex As Exception
            Return 0
        End Try
    End Function

    Public Sub import_LPP_from_vidal(ByVal codeLPP As String) 'importation de code LPP absents de la base lpp. utilisé en complément de l'importation de LPPTOT

        If COMPTOIR_MAIN.LPPTableAdapter.GetData_CodeLPP_Date(codeLPP, Format(Now, "yyyyMMdd")).Rows.Count = 0 Then
            Dim Vidal_LpprService As New Vidal_LpprService.LpprService
            Vidal_LpprService.Timeout = 60000 '3000
            Dim lppr = Vidal_LpprService.searchByCode(codeLPP)

            If Not lppr Is Nothing Then
                If lppr.Count > 0 Then
                    Dim Type_prestation As String
                    Select Case lppr(0).service.Value
                        Case officine.Vidal_LpprService.LpprServiceType.BUYING
                            Type_prestation = "A"
                        Case officine.Vidal_LpprService.LpprServiceType.DELIVERY
                            Type_prestation = "V"
                        Case officine.Vidal_LpprService.LpprServiceType.MAINTENANCE
                            Type_prestation = "E"
                        Case officine.Vidal_LpprService.LpprServiceType.RENTING
                            Type_prestation = "L"
                        Case officine.Vidal_LpprService.LpprServiceType.REPAIR
                            Type_prestation = "R"
                        Case officine.Vidal_LpprService.LpprServiceType.SERVICE
                            Type_prestation = "S"
                        Case Else
                            Type_prestation = "P"
                    End Select
                    COMPTOIR_MAIN.LPPTableAdapter.Insert(lppr(0).code, (lppr(0).refundBase * 100).ToString, "99999999", "00010101", False, lppr(0).actCode.ToString, "200", "", "", False, False, _
                                                          lppr(0).name, "", "", "", "", (lppr(0).refundBase * 100).ToString, Type_prestation)
                Else
                    MyMsg_Box.Presentation("Officine", "CODE LPP " & codeLPP & " INCONNU", False, "", False, "", True, "OK")
                    MyMsg_Box.ShowDialog()
                End If
            Else
                MyMsg_Box.Presentation("Officine", "CODE LPP " & codeLPP & " INCONNU", False, "", False, "", True, "OK")
                MyMsg_Box.ShowDialog()
            End If
        End If


    End Sub
    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub DataGridView1_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
        If e.ColumnIndex = Importer.Index And e.RowIndex <> -1 Then
            e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentForeground)
            e.Graphics.DrawImage(officine.My.Resources.validate2, e.CellBounds)
            e.Handled = True
        ElseIf e.ColumnIndex = Info.Index And e.RowIndex <> -1 Then
            e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentForeground)
            e.Graphics.DrawImage(officine.My.Resources.magnifying_glass2, e.CellBounds)
            e.Handled = True
        End If
    End Sub
End Class