Attribute VB_Name = "CommandModule"
Option Explicit

Public Sub ShowStockEntreeForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    StockEntreeForm.Show
    Do
        DoEvents
    Loop Until StockEntreeForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowStockSortieForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    StockSortieForm.Show
    Do
        DoEvents
    Loop Until StockSortieForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowFinanceForm(Optional ByVal Hwnd As Long = 0, Optional ByVal vVersement As MYVERSEMENT = mv_Versement)
    EnableWindow Hwnd, 0
    If vVersement = mv_Versement Then
        FinanceForm.InfoTxt(3).Enabled = True
        FinanceForm.InfoTxt(4).Enabled = False
    Else
        FinanceForm.InfoTxt(3).Enabled = False
        FinanceForm.InfoTxt(4).Enabled = True
    End If
    FinanceForm.Show
    Do
        DoEvents
    Loop Until FinanceForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowRégulationChoixForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    RégulationChoixForm.Show
    Do
        DoEvents
    Loop Until RégulationChoixForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowRégulationEntréeForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    RegulationEntréeForm.Show
    Do
        DoEvents
    Loop Until RegulationEntréeForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowRégulationSortieForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    RégulationSortieForm.Show
    Do
        DoEvents
    Loop Until RégulationSortieForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowMouvementFinanceForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    MouvementFinanceForm.Show
    Do
        DoEvents
    Loop Until MouvementFinanceForm.Visible = False
    Unload MouvementFinanceForm
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowMouvementStockForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    MouvementStockForm.Show
    Do
        DoEvents
    Loop Until MouvementStockForm.Visible = False
    Unload MouvementStockForm
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowMemoForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    MemoForm.Show
    Do
        DoEvents
    Loop Until MemoForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowSécuritéForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    
    If MyActiveConnexionType = ct_Employee Then
        GiveMessage "Vous n'avez pas assez de priviliège pour accéder à cette ressource!", M_Ok
        EnableWindow Hwnd, 1
        Exit Sub
    End If
    
    SécuritéForm.Show
    Do
        DoEvents
    Loop Until SécuritéForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Function GetCatégorie(Optional ByVal Hwnd As Long = 0) As MYCATEGORIE
    Dim NForm As New CategorieForm
    EnableWindow Hwnd, 0
    
    NForm.Show
    Do
        DoEvents
    Loop Until NForm.Visible = False
    GetCatégorie.mc_Catégorie = NForm.MyCatégorie
    GetCatégorie.mc_Désignation = NForm.MyDésignation
    Unload NForm
    
    EnableWindow Hwnd, 1
End Function

Public Sub NewSecurity(Optional ByVal Hwnd As Long = 0)
    Dim NForm As New NewUserForm
    EnableWindow Hwnd, 0
    
    NForm.Show
    Do
        DoEvents
    Loop Until NForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Function IsHaveConnexion() As Boolean
    Dim NForm As New LoginForm
    Dim rs As New ADODB.Recordset
    
    rs.Open "Sécurité", cn, 1, 2
    If rs.EOF Then
        IsHaveConnexion = True
        MyActiveConnexionType = ct_Administrator
        MyActiveUser = "monier"
        Exit Function
    End If
    
    NForm.Show
    Do
        DoEvents
    Loop Until NForm.Visible = False
    
    IsHaveConnexion = NForm.Authentified
End Function

Public Sub ModifySecurity(ByVal sUser As String, ByVal sPassword As String, ByVal sCompte As String, Optional ByVal Hwnd As Long = 0)
    Dim NForm As New NewUserForm
    EnableWindow Hwnd, 0
    
    NForm.MyUser = sUser
    NForm.MyPassword = sPassword
    NForm.MyCompte = sCompte
    NForm.Show
    Do
        DoEvents
    Loop Until NForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Sub ShowSettingsForm(Optional ByVal Hwnd As Long = 0)
    EnableWindow Hwnd, 0
    
    If MyActiveConnexionType = ct_Employee Then
        GiveMessage "Vous n'avez pas assez de priviliège pour accéder à cette ressource!", M_Ok
        EnableWindow Hwnd, 1
        Exit Sub
    End If
    
    SettingsForm.Show
    Do
        DoEvents
    Loop Until SettingsForm.Visible = False
    EnableWindow Hwnd, 1
End Sub

Public Function GetDatabaseFileName(Optional ByVal Hwnd As Long = 0) As String
    Dim NForm As New FileNameForm
    EnableWindow Hwnd, 0
    NForm.Show
    Do
        DoEvents
    Loop Until NForm.Visible = False
    GetDatabaseFileName = NForm.MyFileName
    EnableWindow Hwnd, 1
End Function

Public Function ShowAbout()
    AboutForm.Show
End Function
