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

    Private Sub affichage()
        OrganismesDataGridView.Rows.Clear()
        Dim orgs = OrganismesTableAdapter.GetData
        For r = 0 To orgs.Rows.Count - 1
            OrganismesDataGridView.Rows.Add()
        Next
        For r = 0 To orgs.Rows.Count - 1
            OrganismesDataGridView.Item(Column_Nom.Index, r).Value = orgs(r).Nom
            OrganismesDataGridView.Item(Column_Info.Index, r).Value = orgs(r).Info
            OrganismesDataGridView.Item(Column_Enc.Index, r).Value = orgs(r).Type_Encaissement
            OrganismesDataGridView.Item(Residence.Index, r).Value = orgs(r).Residence
        Next
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim org As String = ""
        MyInptBox.my_showdialog("Nom de l'organisme ?", VarType(org), 100, "")
        org = MyInptBox.result
        Dim naissance As String = ""
        Dim Info As String = ""
        MyInptBox.my_showdialog("Informations complémentaires ?", VarType(Info), 100, "")
        Info = MyInptBox.result
        Dim Type_encaissement As Boolean = False
        MyMsg_Box.Presentation("Officine ?", "Permettre l'encaissement pour cet organisme ?", True, "Oui", True, "Non", False, "")
        If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
            Type_encaissement = True
        End If
        Dim Residence As Boolean = False
        MyMsg_Box.Presentation("Officine ?", "Cet organisme est une résidence ?", True, "Oui", True, "Non", False, "")
        If MyMsg_Box.ShowDialog = Windows.Forms.DialogResult.Yes Then
            Residence = True
        End If
        Me.OrganismesTableAdapter.Insert(org, Info, Type_encaissement, Residence)
        affichage()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If Not OrganismesDataGridView.CurrentRow Is Nothing Then
            If OrganismesDataGridView.CurrentRow.Index >= 0 Then
                OrganismesTableAdapter.DeleteBy_Nom(OrganismesDataGridView.Item(Column_Nom.Index, OrganismesDataGridView.CurrentRow.Index).Value)
                affichage()
            End If
        End If
    End Sub

    Private Sub Organismes_Autres_Gestion_Load(sender As Object, e As EventArgs) Handles Me.Load
        affichage()
    End Sub
End Class