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

    Public Désignation As String

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Me.WindowState = FormWindowState.Minimized
        MyMsg_Box.Presentation("Officine ?", "Confirmez Location:" + Chr(10) + "du " + Debut_DateTimePicker.Value.ToShortDateString + Chr(10) + "au " + Fin_DateTimePicker.Value.ToShortDateString & vbCrLf & vbCrLf & "(Attention, la date de début de location doit correspondre à la date d'éxecution)", True, "OUI", True, "NON", False, "")
        If MyMsg_Box.ShowDialog() = Windows.Forms.DialogResult.Yes Then
            COMPTOIR_MAIN.location_lpp_date_debut = Format(Debut_DateTimePicker.Value, "yyyyMMdd") + "0000"
            COMPTOIR_MAIN.location_lpp_date_fin = Format(Fin_DateTimePicker.Value, "yyyyMMdd") + "0000"
            Me.Close()
        End If
        Me.WindowState = FormWindowState.Normal
    End Sub

    Private Sub Lpp_Location_Date_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Désignation_Label.Text = Désignation
    End Sub


    Private Sub PictureBox1_MouseHover(sender As Object, e As EventArgs) Handles PictureBox1.MouseHover
        PictureBox1.BackgroundImage = officine.My.Resources.validate2
    End Sub

    Private Sub PictureBox1_MouseLeave(sender As Object, e As EventArgs) Handles PictureBox1.MouseLeave
        PictureBox1.BackgroundImage = officine.My.Resources.validate
    End Sub

    Private Sub Lpp_Location_Date_Shown(sender As Object, e As EventArgs) Handles Me.Shown

        Debut_DateTimePicker.Value = COMPTOIR_MAIN.DateExecution.Value
        If Facture_Auto.Facturation_auto Then
            Dim data = BDD.ChroniqueTableAdapter.GetDataBy_DateRenouv_TypeOrdo_VitaleNum(Now, CurrentBenéficiaire.Num, "LOCATION")
            If data.Rows.Count > 0 Then
                For r = 0 To data.Rows.Count - 1
                    For s = 0 To COMPTOIR_MAIN.Vente.RowCount - 2
                        If COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteCIP.Index, s).Value = data(r).Produit_CIP And
                            COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.VenteEAN13.Index, s).Value = data(r).Produit_EAN13 And
                            COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Ventecab.Index, s).Value = data(r).Produit_CAB And
                            COMPTOIR_MAIN.Vente.Item(COMPTOIR_MAIN.Vente_produits.Index, s).Value = data(r).Produit_Désignation Then
                            Fin_DateTimePicker.Value = DateAdd(DateInterval.Day, data(r).Intervalle_renouvellement, Debut_DateTimePicker.Value)
                        End If
                    Next
                Next
            End If
        End If

    End Sub
End Class