' 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 Création_produits_hors_nomenclature

  
    Private Sub Insert_Button_Click(sender As Object, e As EventArgs) Handles Insert_Button.Click
        If Importer(CIPTextBox.Text, CABTextBox.Text, DesignationTextBox.Text, PrixventeTTCTextBox.Text, TVATextBox.Text, NomExploitantTextBox.Text, CInt(StockTextBox.Text), CInt(En_commandeTextBox.Text)) = True Then
            Me.Close()
        End If
    End Sub
    Public Function Importer(ByVal CIP As String, ByVal CAB As String, ByVal Designation As String, Prixvente_TTC As Decimal, ByVal TVA As Decimal, ByVal nom_Exploitant As String, ByVal Stock As Integer, ByVal En_commande As Integer) As Boolean
        If ((CIP.Length <> 7 And CIP.Length <> 13) Or Not IsNumeric(CIP)) And CIP.Length <> 0 Then
            MyMsg_Box.Presentation("Officine", "Le code CIP doit contenir 7 ou 13 caractères numériques." & vbCrLf & "IMPORTATION IMPOSSIBLE", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Return False
        End If
        If Me.ProduitsTableAdapter.GetDataByCIP_or_EAN13_or_CAB(CIP).Rows.Count > 0 Then
            MyMsg_Box.Presentation("Officine", "Code CIP réservé:" & vbCrLf & Me.ProduitsTableAdapter.GetDataByCIP_or_EAN13_or_CAB(CIP).Item(0).Designation & vbCrLf & "IMPORTATION IMPOSSIBLE", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Return False
        End If
        If Me.ProduitsTableAdapter.GetDataByCIP_or_EAN13_or_CAB(CAB).Rows.Count > 0 Then
            MyMsg_Box.Presentation("Officine", "Code CAB réservé:" & vbCrLf & Me.ProduitsTableAdapter.GetDataByCIP_or_EAN13_or_CAB(CAB).Item(0).Designation & vbCrLf & "IMPORTATION IMPOSSIBLE", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Return False
        End If
        If Me.ProduitsTableAdapter.GetDataByInfo("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", Designation).Rows.Count > 0 Then
            MyMsg_Box.Presentation("Officine", "Désignation réservée:" & vbCrLf & Designation & vbCrLf & "IMPORTATION IMPOSSIBLE", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Return False
        End If
        If Not IsNumeric(Stock) Then
            MyMsg_Box.Presentation("Officine", "STOCK" & vbCrLf & "IMPORTATION IMPOSSIBLE", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Return False
        End If
        If Not IsNumeric(En_commande) Then
            MyMsg_Box.Presentation("Officine", "En COMMANDE" & vbCrLf & "IMPORTATION IMPOSSIBLE", False, "", False, "", True, "OK")
            MyMsg_Box.ShowDialog()
            Return False
        End If
        If CIP.Length = 7 Then
            Me.ProduitsTableAdapter.Insert(CIP, "", CAB, Designation, Prixvente_TTC.ToString, TVA.ToString, Stock, "", "", "", Now, "", "", "", "", "", 0, "", 100, False, En_commande, "", "", "", 0, False, _
                                      "", False, "", Now, True, Now, False, "", 0, True, nom_Exploitant, False, False, 0, 0, "", "", False, True, False, "", "", 0, True, True, False, New Date(3000, 1, 1))
        Else
            Me.ProduitsTableAdapter.Insert("", CIP, CAB, Designation, Prixvente_TTC.ToString, TVA.ToString, Stock, "", "", "", Now, "", "", "", "", "", 0, "", 100, False, En_commande, "", "", "", 0, False, _
                                      "", False, "", Now, True, Now, False, "", 0, True, nom_Exploitant, False, False, 0, 0, "", "", False, True, False, "", "", 0, True, True, False, New Date(3000, 1, 1))
        End If

       
        Return True
    End Function


End Class