' 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 Encaissements_edition
    Public num As Decimal
    Private Sub EncaissementsBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles EncaissementsBindingNavigatorSaveItem.Click
        MyMsg_Box.Presentation("Officine", "Confirmer modification de l'encaissement.", True, "OUI", True, "NON", False, "")
        If MyMsg_Box.ShowDialog() = MsgBoxResult.No Then
            Exit Sub
        End If
        Try
            Dim toto = CDec(Replace(ValeurTextBox.Text, ".", ","))
        Catch ex As Exception
            MyMsg_Box.Presentation("Officine", "Valeur erronnée.", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Exit Sub
        End Try
        Me.Validate()
        Me.EncaissementsBindingSource.EndEdit()
        Dim encaissement=BDD.EncaissementsTableAdapter.GetDataBy_Num(num).Item(0)
        BDD.Historique_ActionsTableAdapter.Insert(current_User.ID, Now, "Modification Encaissement", num.ToString & "  Type:" & encaissement.Type & "->" & TypeTextBox.Text & _
                                                  "  Valeur:" & encaissement.Valeur.ToString & "->" & ValeurTextBox.Text & _
                                                   "  Encaissement_sur_Crédit_Type:" & encaissement.Encaissement_sur_Crédit_Type.ToString & "->" & Encaissement_sur_Crédit_TypeTextBox.Text)


        Me.EncaissementsTableAdapter.Update_Type_Valeur_By_Num(TypeTextBox.Text, CDec(Replace(ValeurTextBox.Text, ".", ",")), num)
        Me.EncaissementsTableAdapter.Update_Encaissement_sur_Crédit_Type(Encaissement_sur_Crédit_TypeTextBox.Text, num)

        Me.Close()

    End Sub

    Private Sub Encaissements_edition_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: cette ligne de code charge les données dans la table 'PharmaDataSet.Encaissements'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
        Me.EncaissementsTableAdapter.FillBy_Num(Me.PharmaDataSet.Encaissements, num)

    End Sub


    Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
        MyMsg_Box.Presentation("Officine", "Confirmer suppression de l'encaissement.", True, "OUI", True, "NON", False, "")
        If MyMsg_Box.ShowDialog() = MsgBoxResult.No Then
            Exit Sub
        End If
        Me.EncaissementsTableAdapter.DeleteByNum(num)
        Me.Close()
    End Sub
End Class