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

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

        If CheckBox_Actes.Checked = True Then
            COMPTOIR_MAIN.ActesTableAdapter.RAZ()
            COMPTOIR_MAIN.ActesTableAdapter.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, 0, False, "")
        End If

        If CheckBox_AR_P.Checked = True Then
            Teletransmission_MAIN.AR_PTableAdapter.RAZ()
            Teletransmission_MAIN.AR_PTableAdapter.Insert(0, "init", "init", "init", "init")
        End If

        If CheckBox_ARL.Checked = True Then
            Teletransmission_MAIN.ARLTableAdapter.RAZ()
            Teletransmission_MAIN.ARLTableAdapter.Insert("init", Nothing, Nothing, Nothing, 0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "arl", "arl")
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "arl\Traités", "arl")
        End If

        If CheckBox_Encaissements.Checked = True Then
            VenteForm.EncaissementsTableAdapter.RAZ()
            VenteForm.EncaissementsTableAdapter.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, 0)
        End If

        If CheckBox_FacturesSV.Checked = True Then
            COMPTOIR_MAIN.Facture_DétailCodeCIPTableAdapter1.RAZ()
            COMPTOIR_MAIN.Facture_DétailLppTableAdapter1.RAZ()
            COMPTOIR_MAIN.Facture_LigneFactureTableAdapter1.RAZ()
            COMPTOIR_MAIN.FacturesTableAdapter.RAZ()
            COMPTOIR_MAIN.FacturesTableAdapter.Insert(0, "init", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, 0, True, True, False)
            suppr_fichiers(Mid(Config.Repertoires_RepertoireFactures, 1, Config.Repertoires_RepertoireFactures.Length - 1), "fse")
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "Traitées", "fse")
            suppr_fichiers(Mid(Config.Repertoires_RepertoireFactures, 1, Config.Repertoires_RepertoireFactures.Length - 1), "dre")
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "Traitées", "dre")
        End If

        If CheckBox_FacturesVD.Checked = True Then
            COMPTOIR_MAIN.Facture_VenteDirecteTableAdapter1.RAZ()
            COMPTOIR_MAIN.Facture_VenteDirecteTableAdapter1.Insert(0, "init", Nothing, Nothing, Nothing, Nothing)
        End If

        If CheckBox_FichiersSV.Checked = True Then
            Teletransmission_MAIN.FichiersSVTableAdapter1.RAZ()
            Teletransmission_MAIN.FichiersSVTableAdapter1.Insert(0, "init", "init", 0, 0, 0)
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "Fichiers", "*")
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "Fichiers\Transmis", "gz")
        End If

        If CheckBox_Lots.Checked = True Then
            Teletransmission_MAIN.LotsTableAdapter.RAZ()
            Teletransmission_MAIN.LotsTableAdapter.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, 0, Nothing, Nothing)
            Teletransmission_MAIN.LotsTableAdapter.Insert(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, "AA@", "@AA@", Nothing, Nothing, Nothing)
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "Lots", "*")
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "Lots\traités", "*")
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "Lots\transmis", "*")
        End If

        If CheckBox_RSP.Checked = True Then
            Teletransmission_MAIN.RSP_LIGNE_REJETTableAdapter.RAZ()
            Teletransmission_MAIN.RSP_LIGNE_REJETTableAdapter.Insert(0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
            Teletransmission_MAIN.RSP_PaiementsTableAdapter.RAZ()
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "RSP", "*")
            suppr_fichiers(Config.Repertoires_RepertoireFactures & "RSP\Traités", "*")
        End If

        If CheckBox_Service_Rejet.Checked = True Then
            Teletransmission_MAIN.Service_RejetTableAdapter.RAZ()
            Teletransmission_MAIN.Service_RejetTableAdapter.Insert(0, "init", "init", "init", "init", "init", 0)
        End If

        If CheckBox_SMTP.Checked = True Then
            Teletransmission_MAIN.SmtpTableAdapter1.RAZ()
            Teletransmission_MAIN.SmtpTableAdapter1.Insert(0, 0, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        End If
        For Each obj In Me.Controls
            obj.Visible = False
            Label1.Text = "DONNEES SUPPRIMEES"
            Label1.Visible = True
        Next
    End Sub

    Private Sub suppr_fichiers(ByVal chemin As String, ByVal extension As String)
        Dim file As String
        file = Dir(chemin + "\*." + extension)
        While file <> ""
            My.Computer.FileSystem.DeleteFile(chemin + "\" + file)
            file = Dir()
        End While
    End Sub
End Class