Gestion de Stock et de Commandes

Bonjour,

Je développe en ce moment même une application de gestion.

Gestion de Stock et de Commandes

  • Pouvoir gérer ses stock et ses commandes en toute facilité
  • Etre intuitive et facile d'utilisation
  • Faciliter la vie de l'utilisateur

Cette application doit :

  • Ce gérer entièrement depuis des boites de dialogues
  • Utilisable sur toute les versions de Calc
  • Etre esthétique
  • Etre utilisable même pour un novice de Calc


Dans ce cours, je parlerez :

  • de mon avancement
  • des techniques employés pour les codes
  • des problèmes rencontrés pendant la création
  • l'explication des codes et du Open Office Basic
  • et en bonus : certains bouts de code adapté aux VBA pour ceux qui veulent tester peuvent essayer

Je métrerais un fichier assez souvent qui montre l'avancement du projet.


Désolé pour les yeux sensibles aux fautes d'orthographe

Jour 1 :

Pour commencer, voici le fichier sans les macros et boites de dialogues

La première problématique est de réfléchir au actions de l'applications.

  • Insertion de produit dans la feuille produits
  • Gestion des produits
  • Insertion de commande dans la feuille commandes
  • Gestion des commandes

Insertion de produit

Un schéma pour commencer:

s 1 ins d

Pour la boite de dialogue d'insertion, il faut des champs pour :

  • La référence
  • Le nom
  • Les dimensions
  • Le poids
  • Le prix
  • Le fournisseur
  • Le stock lors de l'enregistrement
  • Un commentaire (facultatif)

Un aperçu de la boite de dialogue

image

Le code:

L'ouverture de la boite de dialogue

Dim oDialogue As Object

Sub Ins_p

    oDialogue.endExecute()
    oDialogue=CreateUnoDialog(DialogLibraries.Standard.ins_p)
    oDialogue.execute()

End Sub
Excel - VBA

Crée un userform au nom de ins_p

Puis entre ses lignes de codes

Dim oDialogue As Object

Sub Ouverture

    ins_p.Show

End Sub

Puis nous avons besoin de vérifier les champs puis insérer si Oui ou envoyer un message qui va être sous forme d'un texte en rouge marqué dans le champ ou il a problème.

Dim Doc As Object

Sub Inserer_produits

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Dim Row As Object

    Sheet = Doc.Sheets(1)
    Row = Sheet.getCellByPosition(10, 0)

    'Vérification champ par champ

    With oDialogue
        If .getControl("reference").Text = "" Then
        With .getControl("reference")
                .Text = "Vous n'avez pas complété ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("nom").Text = "" Then
            With .getControl("nom")
                .Text = "Vous n'avez pas complété ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("ComboBox1").Text = "" Then
            With .getControl("ComboBox1")
                .Text = "Vous n'avez pas complété ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("L").Text = "" OR not(IsNumeric(.getControl("L").Text)) Then
            With .getControl("L")
                .Text = "Vous n'avez pas complété (bien) ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("l").Text = "" OR not(IsNumeric(.getControl("l").Text)) Then
            With .getControl("l")
                .Text = "Vous n'avez pas complété (bien) ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("H").Text = "" OR not(IsNumeric(.getControl("H").Text)) Then
            With .getControl("H")
                .Text = "Vous n'avez pas complété (bien) ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("poids").Text = "" OR not(IsNumeric(.getControl("poids").Text)) Then
            With .getControl("poids")
                .Text = "Vous n'avez pas complété (bien) ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("prix").Text = "" OR not(IsNumeric(.getControl("prix").Text)) Then
            With .getControl("prix")
                .Text = "Vous n'avez pas complété (bien) ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("adresse").Text = "" Then
            With .getControl("adresse")
                .Text = "Vous n'avez pas complété ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        ElseIf .getControl("stock").Text = "" OR not(IsNumeric(.getControl("stock").Text)) Then
            With .getControl("stock")
                .Text = "Vous n'avez pas complété (bien) ce champ"
                .Model.TextColor = RGB(255, 0, 0)
            End With
        Else
            'Insertion dans la feuille
            Sheet.getCellByPosition(1,Row.value).value = .getControl("reference").Text
            Sheet.getCellByPosition(2,Row.value).String = .getControl("nom").Text
            Sheet.getCellByPosition(3,Row.value).String = .getControl("L").Text + " x " + .getControl("l").Text + " x " + .getControl("H").Text + " " + .getControl("ComboBox1").Text
            Sheet.getCellByPosition(4,Row.value).String = .getControl("poids").Text
            Sheet.getCellByPosition(5,Row.value).value = .getControl("prix").Text
            Sheet.getCellByPosition(6,Row.value).String = .getControl("adresse").Text
            Sheet.getCellByPosition(7,Row.value).value = .getControl("stock").Text
            If .getControl("commentaire").Text <> "" Then
                Sheet.getCellByPosition(9,Row.value-1).String = .getControl("commentaire").Text
            EndIf

            .endExecute()
        EndIf
    End With

End Sub
Excel - VBA

Le code adapté à VBA

Sub Bouton_envoi_insertion_prosuits_Click()

    Dim Row As Object
    Row = Sheets("produits").Range("K1").Value
    Row = Row + 1

    If reference.Value = "" Then
        With reference
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf nom.Value = "" Then
        With nom
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf ComboBox1.Value = "" Then
        With ComboBox1
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf L.Value = "" OR not(IsNumeric(L.Value)) Then
        With L
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf l.Value = "" OR not(IsNumeric(l.Value)) Then
        With l
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf H.Value = "" OR not(IsNumeric(H.Value)) Then
        With H
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf poids.Value = "" OR not(IsNumeric(poids.Value)) Then
        With prix
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf prix.Value = "" OR not(IsNumeric(prix.Value)) Then
        With prix
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf adresse.Value = "" Then 'Champ fournisseur
        With adresse
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    ElseIf stock.Value = "" OR not(IsNumeric(stock.Value)) Then
        With stock
            .Value = "Vous n'avez pas complété ce champ"
            .BackColor = RGB(255, 0, 0)
        End With
    Else
        With Sheets("produits")
            .Cells(Row, 2).Value = reference.Value
            .Cells(Row, 3).Value = nom.Value
            .Cells(Row, 4).Value = L.Value & " x " & l.Value & " x " & H.Value & " " & ComboBox1.Value
            .Cells(Row, 5).Value = poids.Value
            .Cells(Row, 6).Value = prix.Value
            .Cells(Row, 7).Value = fournisseur.Value
            .Cells(Row, 8).Value = stock.Value
        End With
        If commentaire.Value <> "" Then
            Sheets("produits").Cells(Row, 10).Value = commentaire.Value
            Me.Unload
        EndIf
    EndIf

End Sub

Bonne Nuit

Gestion de produit

Un schéma des actions sur les produits pour commencer (comme toujours ) :

s 2 ges d

Nous entrons dans une partie plus complexe pour les macros (finis de rire ):

Déjà la boite de dialogue

image
  • La X est la fonctionnalité de suppression
  • Le bouton Modif est de la modification.
  • Le + est la fonctionnalité d'insertion.
  • Le bouton MàJ mets à jour le champ de liste, le gros défaut que j'ai trouvé à Calc est cette impossibilité de mettre à jour comme titre_de_l_userform_Initialize() en VBA.
  • Et un bouton qui permet de voir les informations de la sélection active de la liste

Commençons par le commencement:

Sub Ges_p

    oDialogue.endExecute()
    oDialogue=CreateUnoDialog(DialogLibraries.Standard.ges_p)
    oDialogue.execute()

End Sub
Excel - VBA

Crée un userform au nom de ins_p

Puis entre ses lignes de codes

Sub Ges_p()

    ges_p.Show

End Sub

Puis la mise à jour

Sub maj_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)
    max = Sheet.getCellByPosition(10,0).Value-2

    oDialogue.getControl("choix").removeItems(0, oDialogue.getControl("choix").ItemCount) 

    For I = 0 To max
        oDialogue.getControl("choix").addItem(Sheet.getCellByPosition(2,I+1).String, I)
    Next

End Sub
Excel - VBA
Sub maj_p_Click()

    max = Sheets("produits").Cells(1,11).Value-2

    Me.choix.Clear

    For I = 0 To max
        Me.choix.AddItem Sheets("produits").Cells(I+2,2).Value, I)
    Next For

End Sub

Pour continuer, la fonctionnalité de suppression

Sub suppr_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    If oDialogue.getControl("choix").ItemCount > 0 Then
                'Fonction de définition de I
        For I=0 To 1000
            If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
                Exit For
            EndIf
        Next

        If MsgBox("Etes vous sur de vouloir supprimer ce produits de la base de données", 20) = 6 Then
            Sheet.getCellByPosition(1, I).String = ""
            Sheet.getCellByPosition(2, I).String = ""
            Sheet.getCellByPosition(3, I).String = ""
            Sheet.getCellByPosition(4, I).String = ""
            Sheet.getCellByPosition(5, I).String = ""
            Sheet.getCellByPosition(6, I).String = ""
            Sheet.getCellByPosition(7, I).String = ""
            Sheet.getCellByPosition(9, I).String = ""
            MsgBox "Le produit a bien été supprimmé"

            Ges_p
        EndIf
    Else
        MsgBox "Vous n'avez pas mis à jour la liste"&chr(10)&chr(10)&"Utilisez le bouton MàJ", 48
    EndIf

End Sub
Excel - VBA
Sub suppr_p_Click()

    Dim I As Long

    If Me.choix.height > 0 Then
        For I=0 To 1000
            If Me.choix.caption = Sheets("produits").Cells(I+1,3).Value Then
                Exit For
            EndIf
        Next For

        If MsgBox("Etes vous sur de vouloir supprimer ce produits de la base de données", 20) = 6 Then
            Sheets("produits").Cells(I, 2).Value = ""
            Sheets("produits").Cells(I, 3).Value = ""
            Sheets("produits").Cells(I, 4).Value = ""
            Sheets("produits").Cells(I, 5).Value = ""
            Sheets("produits").Cells(I, 6).Value = ""
            Sheets("produits").Cells(I, 7).Value = ""
            Sheets("produits").Cells(I, 8).Value = ""
            Sheets("produits").Cells(I, 10).Value = ""
            MsgBox "Le produit a bien été supprimmé"

            Ges_p
        EndIf
    Else
            MsgBox "Vous n'avez pas mis à jour la liste"&chr(10)&chr(10)&"Utilisez le bouton MàJ", 48
    EndIf

End Sub

La suite dans les prochains jours...

Bonne Nuit (pour de bon cette fois)

Jour 2 :

Les informations de la sélection active de la liste

image

Voici le code d'ouverture de la boite de dialogue infos

Dim oDialogue_infos As Object

Sub inf_p

    If oDialogue.getControl("choix").ItemCount > 0 Then
        oDialogue_infos=CreateUnoDialog(DialogLibraries.Standard.infos)
        oDialogue_infos.execute()
    Else
        MsgBox "Vous n'avez pas mis à jour la liste"&chr(10)&chr(10)&"Utilisez le bouton MàJ", 48
    EndIf

End Sub

Vous remarquerez qu'une seconde variable de boite de dialogue est crée, cela permet de toujours gardé la boite de dialogue de gestion ouverte.

Puis la macro d'insertion des valeurs dans la boite de dialogue

Sub maj_inf_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    For I=0 To 1000
        If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
            Exit For
        EndIf
    Next

    With oDialogue_infos
        .getControl("reference").Text = Sheet.getCellByPosition(1, I).String
        .getControl("nom").Text = Sheet.getCellByPosition(2, I).String
        .getControl("taille").Text = Sheet.getCellByPosition(3, I).String
        .getControl("poids").Text = Sheet.getCellByPosition(4, I).String
        .getControl("prix").Text = Sheet.getCellByPosition(5, I).String
        .getControl("fournisseur").Text = Sheet.getCellByPosition(6, I).String
        .getControl("stock").Text = Sheet.getCellByPosition(7, I).String
        .getControl("actuelle").Text = Sheet.getCellByPosition(8, I).String
        .getControl("commentaire").Text = Sheet.getCellByPosition(9, I).String
    End With

End Sub

Et la macro qui permet de voir en complet le commentaire

Sub complet_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    For I=0 To 1000
        If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
            Exit For
        EndIf
    Next

    If Sheet.getCellByPosition(9, I).String <> "" Then
        MsgBox(prompt:=Sheet.getCellByPosition(9, I).String)
    EndIf

End Sub

Voilà pour l'instant, la suite plus tard...

Jour 3 :

Modification de produit

image

Le code d'ouverture

Sub mod_p

    If oDialogue.getControl("choix").ItemCount > 0 Then
        oDialogue_infos=CreateUnoDialog(DialogLibraries.Standard.mod_p)
        oDialogue_infos.execute()
    Else
        MsgBox "Vous n'avez pas mis à jour la liste"&chr(10)&chr(10)&"Utilisez le bouton MàJ", 48
    EndIf

End Sub

Comme pour les informations, une seconde variable de boite de dialogue permet de consulter les 2 en même temps.

Mise à jour des valeurs

Sub mod_maj_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    For I=0 To 1000
        If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
            Exit For
        EndIf
    Next

    With oDialogue_infos
        .getControl("reference").Text = Sheet.getCellByPosition(1, I).String
        .getControl("nom").Text = Sheet.getCellByPosition(2, I).String
        .getControl("dimensions").Text = Sheet.getCellByPosition(3, I).String
        .getControl("poids").Text = Sheet.getCellByPosition(4, I).String
        .getControl("prix").Text = Sheet.getCellByPosition(5, I).String
        .getControl("fournisseur").Text = Sheet.getCellByPosition(6, I).String
        .getControl("stock").Text = Sheet.getCellByPosition(7, I).String
        .getControl("commentaire").Text = Sheet.getCellByPosition(9, I).String
    End With

End Sub

Et l'insertion des valeurs

Sub mod_maj_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    For I=0 To 1000
        If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
            Exit For
        EndIf
    Next

    oDialogue_infos.getControl("reference").Text = Sheet.getCellByPosition(1, I).String
    oDialogue_infos.getControl("nom").Text = Sheet.getCellByPosition(2, I).String
    oDialogue_infos.getControl("dimensions").Text = Sheet.getCellByPosition(3, I).String
    oDialogue_infos.getControl("poids").Text = Sheet.getCellByPosition(4, I).String
    oDialogue_infos.getControl("prix").Text = Sheet.getCellByPosition(5, I).String
    oDialogue_infos.getControl("fournisseur").Text = Sheet.getCellByPosition(6, I).String
    oDialogue_infos.getControl("stock").Text = Sheet.getCellByPosition(7, I).String
    oDialogue_infos.getControl("commentaire").Text = Sheet.getCellByPosition(9, I).String

End Sub

Et l'insertion des valeurs

Sub mod_ins_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    If oDialogue.getControl("reference").Text = "" Then
        With oDialogue.getControl("reference")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("nom").Text = "" Then
        With oDialogue.getControl("nom")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("dimensions").Text = "" Then
        With oDialogue.getControl("dimensions")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("poids").Text = "" OR not(IsNumeric(oDialogue.getControl("poids").Text)) Then
        With oDialogue.getControl("poids")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("prix").Text = "" OR not(IsNumeric(oDialogue.getControl("prix").Text)) Then
        With oDialogue.getControl("prix")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("adresse").Text = "" Then
        With oDialogue.getControl("adresse")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("stock").Text = "" OR not(IsNumeric(oDialogue.getControl("stock").Text)) Then
        With oDialogue.getControl("stock")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    Else

        Dim I As Long

        For I=0 To 1000
            If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
                Exit For
            EndIf
        Next

        With Sheet
            .getCellByPosition(1,I).value = oDialogue_infos.getControl("reference").Text
            .getCellByPosition(2,I).String = oDialogue_infos.getControl("nom").Text
            .getCellByPosition(3,I).String = oDialogue_infos.getControl("dimensions").Text
            .getCellByPosition(4,I).String = oDialogue_infos.getControl("poids").Text
            .getCellByPosition(5,I).value = oDialogue_infos.getControl("prix").Text
            .getCellByPosition(6,I).String = oDialogue_infos.getControl("fournisseur").Text
            .getCellByPosition(7,I).value = oDialogue_infos.getControl("stock").Text
            .getCellByPosition(9,I).String = oDialogue_infos.getControl("commentaire").Text
        End With

        oDialogue_infos.endExecute()
    EndIf

End Sub
Code actuel
REM  *****  BASIC  *****

Dim oDialogue As Object
Dim oDialogue_infos As Object
Dim Doc As Object

Sub Ouverture

    oDialogue=CreateUnoDialog(DialogLibraries.Standard.menu)
    oDialogue.execute()

End Sub

'Insertion

Sub Ins_p

    oDialogue.endExecute()
    oDialogue=CreateUnoDialog(DialogLibraries.Standard.ins_p)
    oDialogue.execute()

End Sub

Sub Inserer_produits

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Dim Row As Object

    Sheet = Doc.Sheets(1)
    Row = Sheet.getCellByPosition(10, 0)

    'Vérification champ par champ

    If oDialogue.getControl("reference").Text = "" Then
        With oDialogue.getControl("reference")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("nom").Text = "" Then
        With oDialogue.getControl("nom")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("ComboBox1").Text = "" Then
        With oDialogue.getControl("ComboBox1")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("L").Text = "" OR not(IsNumeric(oDialogue.getControl("L").Text)) Then
        With oDialogue.getControl("L")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("l").Text = "" OR not(IsNumeric(oDialogue.getControl("l").Text)) Then
        With oDialogue.getControl("l")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("H").Text = "" OR not(IsNumeric(oDialogue.getControl("H").Text)) Then
        With oDialogue.getControl("H")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("poids").Text = "" OR not(IsNumeric(oDialogue.getControl("poids").Text)) Then
        With oDialogue.getControl("poids")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("prix").Text = "" OR not(IsNumeric(oDialogue.getControl("prix").Text)) Then
        With oDialogue.getControl("prix")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("adresse").Text = "" Then
        With oDialogue.getControl("adresse")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("stock").Text = "" OR not(IsNumeric(oDialogue.getControl("stock").Text)) Then
        With oDialogue.getControl("stock")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    Else
        'Insertion dans la feuille
        Sheet.getCellByPosition(1,Row.value).value = oDialogue.getControl("reference").Text
        Sheet.getCellByPosition(2,Row.value).String = oDialogue.getControl("nom").Text
        Sheet.getCellByPosition(3,Row.value).String = oDialogue.getControl("L").Text + " x " + oDialogue.getControl("l").Text + " x " + oDialogue.getControl("H").Text + " " + oDialogue.getControl("ComboBox1").Text
        Sheet.getCellByPosition(4,Row.value).String = oDialogue.getControl("poids").Text
        Sheet.getCellByPosition(5,Row.value).value = oDialogue.getControl("prix").Text
        Sheet.getCellByPosition(6,Row.value).String = oDialogue.getControl("adresse").Text
        Sheet.getCellByPosition(7,Row.value).value = oDialogue.getControl("stock").Text
        If oDialogue.getControl("commentaire").Text <> "" Then
            Sheet.getCellByPosition(9,Row.value-1).String = oDialogue.getControl("commentaire").Text
        EndIf

        oDialogue.endExecute()
    EndIf

End Sub

'Gestion produits

Sub Ges_p

    oDialogue.endExecute()
    oDialogue=CreateUnoDialog(DialogLibraries.Standard.ges_p)
    oDialogue.execute()

End Sub

Sub maj_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)
    max = Sheet.getCellByPosition(10,0).Value-2

    oDialogue.getControl("choix").removeItems(0, oDialogue.getControl("choix").ItemCount) 

    For I = 0 To max
        oDialogue.getControl("choix").addItem(Sheet.getCellByPosition(2,I+1).String, I)
    Next

End Sub

Sub inf_p

    If oDialogue.getControl("choix").ItemCount > 0 Then
        oDialogue_infos=CreateUnoDialog(DialogLibraries.Standard.infos)
        oDialogue_infos.execute()
    Else
        MsgBox "Vous n'avez pas mis à jour la liste"&chr(10)&chr(10)&"Utilisez le bouton MàJ", 48
    EndIf

End Sub

Sub maj_inf_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    For I=0 To 1000
        If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
            Exit For
        EndIf
    Next

    oDialogue_infos.getControl("reference").Text = Sheet.getCellByPosition(1, I).String
    oDialogue_infos.getControl("nom").Text = Sheet.getCellByPosition(2, I).String
    oDialogue_infos.getControl("taille").Text = Sheet.getCellByPosition(3, I).String
    oDialogue_infos.getControl("poids").Text = Sheet.getCellByPosition(4, I).String
    oDialogue_infos.getControl("prix").Text = Sheet.getCellByPosition(5, I).String
    oDialogue_infos.getControl("fournisseur").Text = Sheet.getCellByPosition(6, I).String
    oDialogue_infos.getControl("stock").Text = Sheet.getCellByPosition(7, I).String
    oDialogue_infos.getControl("actuelle").Text = Sheet.getCellByPosition(8, I).String
    oDialogue_infos.getControl("commentaire").Text = Sheet.getCellByPosition(9, I).String

End Sub

Sub complet_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    For I=0 To 1000
        If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
            Exit For
        EndIf
    Next

    If Sheet.getCellByPosition(9, I).String <> "" Then
        MsgBox(prompt:=Sheet.getCellByPosition(9, I).String)
    EndIf

End Sub

Sub suppr_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    If oDialogue.getControl("choix").ItemCount > 0 Then
        For I=0 To 1000
            If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
                Exit For
            EndIf
        Next

        If MsgBox("Etes vous sur de vouloir supprimer ce produits de la base de données", 20) = 6 Then
            Sheet.getCellByPosition(1, I).String = ""
            Sheet.getCellByPosition(2, I).String = ""
            Sheet.getCellByPosition(3, I).String = ""
            Sheet.getCellByPosition(4, I).String = ""
            Sheet.getCellByPosition(5, I).String = ""
            Sheet.getCellByPosition(6, I).String = ""
            Sheet.getCellByPosition(7, I).String = ""
            Sheet.getCellByPosition(9, I).String = ""
            MsgBox "Le produit a bien été supprimmé"

            Ges_p
        EndIf
    Else
        MsgBox "Vous n'avez pas mis à jour la liste"&chr(10)&chr(10)&"Utilisez le bouton MàJ", 48
    EndIf

End Sub

Sub mod_p

    If oDialogue.getControl("choix").ItemCount > 0 Then
        oDialogue_infos=CreateUnoDialog(DialogLibraries.Standard.mod_p)
        oDialogue_infos.execute()
    Else
        MsgBox "Vous n'avez pas mis à jour la liste"&chr(10)&chr(10)&"Utilisez le bouton MàJ", 48
    EndIf

End Sub

Sub mod_maj_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    Dim I As Long

    For I=0 To 1000
        If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
            Exit For
        EndIf
    Next

    With oDialogue_infos
        .getControl("reference").Text = Sheet.getCellByPosition(1, I).String
        .getControl("nom").Text = Sheet.getCellByPosition(2, I).String
        .getControl("dimensions").Text = Sheet.getCellByPosition(3, I).String
        .getControl("poids").Text = Sheet.getCellByPosition(4, I).String
        .getControl("prix").Text = Sheet.getCellByPosition(5, I).String
        .getControl("fournisseur").Text = Sheet.getCellByPosition(6, I).String
        .getControl("stock").Text = Sheet.getCellByPosition(7, I).String
        .getControl("commentaire").Text = Sheet.getCellByPosition(9, I).String
    End With

End Sub

Sub mod_ins_p

    Doc = StarDesktop.CurrentComponent

    Dim Sheet As Object
    Sheet = Doc.Sheets(1)

    If oDialogue.getControl("reference").Text = "" Then
        With oDialogue.getControl("reference")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("nom").Text = "" Then
        With oDialogue.getControl("nom")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("dimensions").Text = "" Then
        With oDialogue.getControl("dimensions")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("poids").Text = "" OR not(IsNumeric(oDialogue.getControl("poids").Text)) Then
        With oDialogue.getControl("poids")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("prix").Text = "" OR not(IsNumeric(oDialogue.getControl("prix").Text)) Then
        With oDialogue.getControl("prix")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("adresse").Text = "" Then
        With oDialogue.getControl("adresse")
            .Text = "Vous n'avez pas complété ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    ElseIf oDialogue.getControl("stock").Text = "" OR not(IsNumeric(oDialogue.getControl("stock").Text)) Then
        With oDialogue.getControl("stock")
            .Text = "Vous n'avez pas complété (bien) ce champ"
            .Model.TextColor = RGB(255, 0, 0)
        End With
    Else

        Dim I As Long

        For I=0 To 1000
            If oDialogue.getControl("choix").selectedItem = Sheet.getCellByPosition(2,I).String Then
                Exit For
            EndIf
        Next

        With Sheet
            .getCellByPosition(1,I).value = oDialogue_infos.getControl("reference").Text
            .getCellByPosition(2,I).String = oDialogue_infos.getControl("nom").Text
            .getCellByPosition(3,I).String = oDialogue_infos.getControl("dimensions").Text
            .getCellByPosition(4,I).String = oDialogue_infos.getControl("poids").Text
            .getCellByPosition(5,I).value = oDialogue_infos.getControl("prix").Text
            .getCellByPosition(6,I).String = oDialogue_infos.getControl("fournisseur").Text
            .getCellByPosition(7,I).value = oDialogue_infos.getControl("stock").Text
            .getCellByPosition(9,I).String = oDialogue_infos.getControl("commentaire").Text
        End With

        oDialogue_infos.endExecute()
    EndIf

End Sub

Bonne Journée

Rechercher des sujets similaires à "gestion stock commandes"