from AppliDef import *
from EtagProduits import *
from EtagMat import *
from FrmTopLevel import *
from FrmInfoProd import *
from FrmInfoMat import *
from FrmInfoTP import *
from FrmAjoutModifProd import *
from FrmAjoutModifMat import *
from FrmAjoutModifTP import *
from FrmAjoutModifTPPhys import *
from FrmPrepaMat import *
from FrmPrepaProdChim import *
from FrmPrepaSol import *
from FrmConsomProd import *
from FrmTabRecapProd import *
from FrmTabRecapMat import *
from FrmMatHS import *
from FrmCommandProd import *
from FrmCommandMat import *
from FrmPlanningTP import *
from FrmAccueil import *
from FrmTP import *
from FrmDoc import *
from FrmInfoDoc import *
from FrmAjoutModifDoc import *
from FrmAjoutModifFour import *
from FrmParam import *
from FrmFournisseur import *
import sqlite3


class MainAppli(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)

        self.parent = parent
        self.parent.lift()
        self.NAction = 0
        self.BaseEnCours = ''
        self.SX = self.parent.frmwidth
        self.SY = self.parent.frmheight
        self.Nconfig = DeterminAspectRatio()
        self.FrmAccueil = None
        self.EtagProduits = None
        self.EtagMat = None
        self.IndexElt = 0
        self.NEtag = 0
        self.ListBtnActionV = []
        self.InfoAction = False
        self.InfoActionV = False
        self.LegendActionV = None
        self.ListInfoActionV = ['Rechercher', 'Trier', 'Ajouter', 'Modifier', 'Supprimer', '',
                                '', '', '', 'Retour Accueil']
        self.ListInfoAction = ['Produits chimiques', 'Matériel de chimie', 'Travaux pratiques de chimie',
                               'Documentation de chimie', 'Paramètres BDD Chimie', 'Fournisseurs',
                               'Matériel de physique', 'Travaux pratiques de physique', 'Documentation de physique', '',
                               'Paramètres BDD Physique', 'Fournisseurs']
        self.ListCatProduits = ['Fonction', 'Danger', 'Synonyme', 'Lieu de stockage', 'Fournisseur']
        self.ListCatMats = ['Catégorie', 'Lieu de stockage', 'Fournisseur']
        self.ListCatTPs = ['Année scolaire', 'Classe', 'Catégorie']
        self.ListCatDocs = ['Catégorie', 'Mots clés']
        self.ListCatFours = ['Catégorie']
        self.RequeteRecherche = ''
        self.FrmFindData = None
        self.ListRecherch = []
        self.ListCat = []
        self.CatSelected = ''
        self.ListProdCat = []
        self.NCatselected = 0
        self.NSCatselected = 0
        self.DangerSelected = ''
        self.FrmPicto = None
        self.InfoProd = None
        self.Init = True
        self.ListChampsTabProd = "NOMS, UNITMES, FORMDEV, GHS1, GHS2, GHS3, FORMULES, FONCTION, LIEUX, FOURNISSEUR, " \
                                 "SYNO, MM, D, MP, SOLUB, RisqueGHS, PrudGHS, FDS, QSTOCK, QUTIL, REFERENCE, " \
                                 "CONDITIONNEMENT, PRIXHT, QCOM, QCOMANNUL, QenCOM, CAS"
        self.ListChampsTabMat = "NOMS, VISUEL, CATEGORIE, LABOLIEU, LABOQUANT, LABOLIEU2, LABOQUANT2, SALLETPLIEU, " \
                                "SALLETPQUANT, POSTETPLIEU, POSTETPQUANT, SPECTROLIEU, SPECTROQUANT, QSTOCK, QUtil, " \
                                "FOURNISSEUR, REFERENCE, CONDITIONNEMENT, PRIXHT, CARACT1TYPE, CARACT1VAL, " \
                                "CARACT2TYPE, CARACT2VAL, CARACT3TYPE, CARACT3VAL, CARACT4TYPE, CARACT4VAL, NOTICE, " \
                                "DESCRIPT, QCOM, QCOMANNUL, QENCOM"
        self.ListCatLieuSelected = ["LABOLIEU", "LABOLIEU2", "SALLETPLIEU", "POSTETPLIEU", "SPECTROLIEU"]
        self.ListCatLieu = []
        self.ListChampsTabMatPhys = "NOMS, VISUEL, Categorie, LaboLieu, LaboQuant, SalleTPLieu, SalleTPQuant, " \
                                    "ResLieu, ResQuant, QUtil, FOURNISSEUR, REFERENCE, Conditionnement, PRIXHT, " \
                                    "Caract1Type, Caract1Val, Caract2Type, Caract2Val, Caract3Type, Caract3Val, " \
                                    "Caract4Type, Caract4Val, Notice, DESCRIPT, Qcom, Qcomannul, Qencom"
        self.ListCatMatPhysLieuSelected = ["LaboLieu", "SalleTPLieu", "ResLieu"]
        self.ListCatMatPhysLieu = []
        self.ListChampsTabTP = "TITRE, PDF, CLASSE, CAT"
        self.ListChampsTabTP2 = "TITRE, PDF, CLASSE, MATERIEL, QUANTITE, LIEU, CAT"
        self.ListChampsTabTP3 = "TITRE, PDF, CLASSE, PRODUIT, QUANTITE, UNITMES, CAT"
        self.ListChampsTabTP4 = "TITRE, PDF, CLASSE, SOLUTE, SOLVANT, CONCENTRATION, QUANTITE, CAT"
        self.ListChampsTabTP5 = "TITRE, PDF, CLASSE, SOLUTE, CONCENTRATION, SOLUTE2, CONCENTRATION2, QUANTITE, CAT"
        self.ListChampsTabTP6 = "TITRE, PDF, CLASSE, SOLVANT, CONCENTRATION, SOLVANT2, CONCENTRATION2, QUANTITE, CAT"
        self.ListChampsTabTPPhys = "TITRE, PDF, CLASSE, CAT"
        self.ListChampsTabTPPhys2 = "TITRE, PDF, CLASSE, MATERIEL, QUANTITE, LIEU, CAT"
        self.ListChampsTabTPConsomprod = "TITRE, ANNEESCOL, NFLACON, PRODUIT, UTIL, PFLACONAVTP, PFLACONAPTP, " \
                                         "UNITMES, QUANTITE"
        self.ListChampsTabTPSol = "TITRE, ANNEESCOL, DATE, PRODUIT, UTIL, SOLVANT, VPREPA, CONCENTRATION, UNITMES, " \
                                  "QUANTITE"
        self.ListChampsTabBonComProd = "NBON, DATE, FOURNISSEUR, NBRPROD, PRIXTOTCOM, FRAISPORT, PRODUIT, REFERENCE, " \
                                       "COND, PRIXUNIT, QUANTITE, PRIXTOTAL, LIVRAISON, CLOTURE"
        self.ListChampsTabDoc = "Titre, Chemin, RESUME, MOTSCLE, Cat"
        self.ListChampsTabPlanningTP = 'DATE, TYPE, HDEB , HFIN, CLASSE, NGROUPES, TITRE'
        self.ListChampsTabFournisseurs = 'NOM, Adresse1, Adresse2, Codepostal, Tel, Fraisport, Francolimite, Logo, ' \
                                         'Web, Capture, Fax, Email, Contact, Cat'
        self.ListMatCat = None
        self.FrmAjoutProd = None
        self.FrmModifProd = None
        self.ListNomProd = []
        self.OldNAction = 0
        self.ListMats = None
        self.ListProduits = None
        self.LegendAction = None
        self.InfoMat = None
        self.FrmAjoutMat = None
        self.ButtonClic = -1
        self.ListTPs = []
        self.FrmTP = None
        self.InfoTP = None
        self.ListTP = []
        self.ListRecher = []
        self.ListTPCa = []
        self.ListTPCat = []
        self.FrmModifTP = None
        self.FrmAjoutTP = None
        self.FrmModifTPPhys = None
        self.ModifEnCours = False
        self.FrmPrepaProd = None
        self.FrmPrepaMat = None
        self.AnScol = None
        self.FrmPrepaSol = None
        self.FrmConsomProd = None
        self.FrmTabRecapProd = None
        self.FrmAjoutProdRecy = None
        self.FrmTabRecapMat = None
        self.FrmModifMat = None
        self.FrmMatHS = None
        self.FrmCommandProd = None
        self.FrmCommandMat = None
        self.FrmDoc = None
        self.ListDocCat = []
        self.FrmPlanningTP = None
        self.ListDocs = []
        self.InfoDoc = None
        self.ListDocCa = []
        self.FrmAjoutDoc, self.FrmModifDoc = None, None
        self.ListTPinPlanning = []
        self.FrmParam = None
        self.AutoSave, self.AutoLoad, self.MaxSaves = 0, 0, 0
        self.AutoSavePath = ''
        self.DTBPhysPath = ''
        self.DTBChimiePath = ''
        self.DataBasePhys = None
        self.curphys = None
        self.curSave = None
        self.ListParam = []
        self.DataBaseChimie = None
        self.cur = None
        self.NbrElt = 0
        self.Etab = []
        self.Service = ''
        self.AffichEtab, self.AffichService = 0, 0
        self.LieuxStockMatChim = []
        self.LieuxStockMatPhys = []
        self.LogoPath = ''
        self.AffichLogo = 0
        self.ListFours, self.ListFourCa = [], []
        self.FrmFour = None
        self.InfoFour = None
        self.ListFourCat = []
        self.FrmAjoutFour, self.FrmModifFour = None, None
        self.ListClasses = []
        self.CoeffSecuProd = ''
        self.CoeffSecuMat = ''
        self.TVA = ''

        self.DataBaseSave = sqlite3.connect('DTBSave.sq3')
        self.curSave = self.DataBaseSave.cursor()

        FrmMainFond = Image.open('Media/FrmMain/Fond/Fond.jpg')
        self.RatioFondX = float(self.SX) / float(FrmMainFond.size[0])
        self.RatioFondY = float(self.SY) / float(FrmMainFond.size[1])

        self.ImgFrmMain = []
        self.ImgFrmMain = RedimImg(self.SX, self.SY, 'Media/FrmMain/Fond/')
        self.CanvasFrmMain = CanvasApp(self.parent, width=self.SX, height=self.SY)
        self.ImgCanvasFrmMain = self.CanvasFrmMain.create_image(0, 0, anchor=tk.NW, image=self.ImgFrmMain[0])

        self.SizeFont = int(ConfigResolution(self.Nconfig, 'SizeFontMainAppli', self.curSave))

        self.ImgBtnQuit, wsize, hsize, self.CanvasBtnQuit, self.ImgCanvasBtnQuit = CanInWindow(
            'Media/FrmMain/BtnClose/', self.RatioFondX, self.RatioFondY, self.CanvasFrmMain, tk.CENTER,
            int(self.SX * 0.986), int(self.SY * 0.016), 0)
        ChangeCursor(self.CanvasBtnQuit)
        self.CanvasBtnQuit.bind('<Motion>',
                                lambda action: self.CanvasBtnQuit.itemconfig(self.ImgCanvasBtnQuit,
                                                                             image=self.ImgBtnQuit[1]))
        self.CanvasBtnQuit.bind('<ButtonRelease-1>', self.quitter)

        self.ImgLogo, wsize, hsize, self.Canvaslogo, self.ImgCanvaslogo = CanInWindow(
            'Media/FrmMain/Logo/', self.RatioFondX, self.RatioFondX, self.CanvasFrmMain, tk.CENTER,
            int(self.SX * 0.01), int(self.SY * 0.016), 0)

        self.LabelLog = LabelText(self.CanvasFrmMain, '', '#F7F7F7',
                                  font=AppliFont('Helvetica', self.SizeFont, 'normal', 0))
        self.CanvasFrmMain.create_window(int(self.SX * 0.02), int(self.SY * 0.009), anchor=tk.NW,
                                         window=self.LabelLog)

        self.ImgBtnRetour, wsize, hsize, self.CanvasBtnRetour, self.ImgCanvasBtnRetour = CanInWindow(
            'Media/FrmMain/BtnRetour/', self.RatioFondX, self.RatioFondY, self.CanvasFrmMain, tk.CENTER,
            int(self.SX * 0.166), int(self.SY * 0.0926), 0)
        self.CanvasBtnRetour.bind('<ButtonPress-1>', self.ActionBtnRetourPress)
        self.CanvasBtnRetour.bind('<ButtonRelease-1>', self.ActionRetour)

        self.ImgBtnSuiv, wsize, hsize, self.CanvasBtnSuiv, self.ImgCanvasBtnSuiv = CanInWindow(
            'Media/FrmMain/BtnSuiv/', self.RatioFondX, self.RatioFondY, self.CanvasFrmMain, tk.CENTER,
            int(self.SX * 0.99), int(self.SY * 0.093), 2)

        self.ImgBtnRetour2, wsize, hsize, self.CanvasBtnRetour2, self.ImgCanvasBtnRetour2 = CanInWindow(
            'Media/FrmMain/BtnSuiv/', self.RatioFondX, self.RatioFondY, self.CanvasFrmMain, tk.CENTER,
            int(self.SX * 0.98), int(self.SY * 0.093), 2)

        self.CanvasFrmMain.pack()
        self.parent.lift()
        self.lift()

        self.CanvasFrmMain.bind('<Motion>', self.MoveOnCanvas)
        self.CanvasFrmMain.bind('<Button-1>', self.ClicOnCanvas)

        self.ListBtnAction = []
        for i in range(6):
            if i < 4:
                self.ListBtnAction.append(BtnAction(self.CanvasFrmMain, int(self.SX * 0.015) + i * int(self.SX * 0.025),
                                                    int(self.SY * 0.054), self.RatioFondX, self.RatioFondY,
                                                    'Media/FrmMain/BtnAction' + str(i) + '/'))
            elif i == 4:
                self.ListBtnAction.append(BtnAction(self.CanvasFrmMain, int(self.SX * 0.985), int(self.SY * 0.054),
                                                    self.RatioFondX, self.RatioFondY,
                                                    'Media/FrmMain/BtnAction' + str(i) + '/'))
            elif i == 5:
                self.ListBtnAction.append(BtnAction(self.CanvasFrmMain, int(self.SX * 0.96), int(self.SY * 0.054),
                                                    self.RatioFondX, self.RatioFondY,
                                                    'Media/FrmMain/BtnAction' + str(i) + '/'))

            def GestEvt(_, j=i):
                return self.Action(j)

            def GestEvt2(_, j=i):
                return self.MotionBtn(j)

            def GestEvt3(_, j=i):
                return self.PressBtn(j)

            self.ListBtnAction[i].CanvasBtn.bind('<Motion>', GestEvt2)
            self.ListBtnAction[i].CanvasBtn.bind('<ButtonPress-1>', GestEvt3)
            self.ListBtnAction[i].CanvasBtn.bind('<ButtonRelease-1>', GestEvt)

        self.CanvasListBox = CanvasApp(self.CanvasFrmMain, bg='white')
        self.CanvasFrmMain.create_window(int(self.SX * 0.0273), int(self.SY * 0.15), anchor=tk.NW,
                                         window=self.CanvasListBox)
        self.ScrollbarListBoxV = tk.Scrollbar(self.CanvasListBox)
        self.ScrollbarListBoxV.pack(side=tk.RIGHT, fill=tk.Y)
        self.ListBoxProduits = tk.Listbox(self.CanvasListBox, width=int(self.SX * 0.022), height=int(self.SY * 0.05),
                                          activestyle='none')
        self.ListBoxProduits.config(yscrollcommand=self.ScrollbarListBoxV.set)
        self.ScrollbarListBoxV.config(command=self.ListBoxProduits.yview)

        self.ScrollbarListBoxH = tk.Scrollbar(self.CanvasListBox, orient=tk.HORIZONTAL)
        self.ScrollbarListBoxH.pack(side=tk.BOTTOM, fill=tk.X)
        self.ListBoxProduits.config(xscrollcommand=self.ScrollbarListBoxH.set)
        self.ScrollbarListBoxH.config(command=self.ListBoxProduits.xview)

        self.ListBoxProduits.bind('<<ListboxSelect>>', self.OnSelectListBox)
        self.ScrollbarListBoxV.bind('<Button>', self.ClicOnCanvas)
        self.ScrollbarListBoxH.bind('<Button>', self.ClicOnCanvas)
        self.ListBoxProduits.pack()

        self.LegendePanneauG = self.CanvasFrmMain.create_text(int(self.SX * 0.007), int(self.SY * 0.093), text='',
                                                              font=AppliFont('Helvetica', self.SizeFont, 'normal', 0),
                                                              anchor=tk.W)
        self.CanvasFrmMain.addtag_withtag('LegendePanneauG', self.LegendePanneauG)

        self.LegendePanneauD = self.CanvasFrmMain.create_text(int(self.SX * 0.757), int(self.SY * 0.093),
                                                              text='Informations',
                                                              font=AppliFont('Helvetica', self.SizeFont, 'normal', 0),
                                                              anchor=tk.W)
        self.CanvasFrmMain.addtag_withtag('LegendePanneauD', self.LegendePanneauD)

        self.LabelTotal = LabelText(self.CanvasFrmMain, '', '#F7F7F7',
                                    font=AppliFont('Helvetica', self.SizeFont, 'normal', 0))
        self.CanvasFrmMain.create_window(int(self.SX * 0.03), int(self.SY * 0.988), anchor=tk.W,
                                         window=self.LabelTotal)

        self.ImgMenuVFond, self.MVwsize, self.MVhsize, self.CanvasMenuVFond, self.ImgCanvasMenuVFond = CanInWindow(
            'Media/FrmMain/MenuV/Fond/', self.RatioFondX, self.RatioFondY, self.CanvasFrmMain, tk.CENTER,
            int(self.SX * 0.0135), int(self.SY * 0.54), 0)
        self.CanvasMenuVFond.bind('<Motion>', self.MoveOnCanvas)

        self.InitBtnAction()

        self.AfficheMenuV()
        self.CalculAnScol()

        self.ChargeParam()
        self.OpenDTB()

        self.FrmAccueil = FrmAccueil(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)

    def ChargeParam(self):
        self.curSave.execute("select " + "Type , DTBChimie, DTBPhys, AutoSave, AutoLoad, SavePath, MaxSave, "
                                         "Etablissement, Service, AffichEtab, AffichService, MatChimLieux1,"
                                         "MatChimLieux2, MatChimLieux3, MatPhysLieux1, MatPhysLieux2, MatPhysLieux3,"
                                         "Logo, AffichLogo, Adresse, Tel, Email, Classes, CoefSecuProd, CoefSecuMat,"
                                         " TVA" + " from Param order by Type")
        self.ListParam = self.curSave.fetchall()

    def InitParam(self, i):
        self.AutoSave = self.ListParam[i][3]
        self.AutoLoad = self.ListParam[i][4]
        self.AutoSavePath = self.ListParam[i][5]
        self.MaxSaves = self.ListParam[i][6]
        self.Etab = []
        for j in [7, 19, 20, 21]:
            self.Etab.append(self.ListParam[i][j])
        self.Service = self.ListParam[i][8]
        self.AffichEtab = self.ListParam[i][9]
        self.AffichService = self.ListParam[i][10]
        self.LabelLog['text'] = 'GestLab - Gestionnaire de laboratoire'
        if self.Service is not None and self.Service != '' and self.AffichService == 1:
            self.LabelLog['text'] = self.LabelLog['text'] + ' - ' + self.Service
        if self.Etab[0] is not None and self.Etab[0] != '' and self.AffichEtab == 1:
            self.LabelLog['text'] = self.LabelLog['text'] + ' - ' + self.Etab[0]
        self.LieuxStockMatChim = [self.ListParam[i][11], self.ListParam[i][12], self.ListParam[i][13]]
        self.ListCatLieu = [self.ListParam[i][11], self.ListParam[i][11], self.ListParam[i][12], self.ListParam[i][12],
                            self.ListParam[i][13]]
        self.LieuxStockMatPhys = [self.ListParam[i][14], self.ListParam[i][15], self.ListParam[i][16]]
        self.ListCatMatPhysLieu = list(self.LieuxStockMatPhys)
        self.LogoPath = self.ListParam[i][17]
        self.AffichLogo = self.ListParam[i][18]
        self.ListClasses = self.ListParam[i][22].split(',')
        self.ListClasses.sort()
        self.CoeffSecuProd = self.ListParam[i][23]
        self.CoeffSecuMat = self.ListParam[i][24]
        self.TVA = self.ListParam[i][25]

    def OpenDTB(self):
        if len(self.ListParam) == 2 and self.ListParam[1][4] == 1:
            self.InitParam(1)
            if self.ListParam[1][1] != '' and self.ListParam[1][1] is not None:
                if Path(self.ListParam[1][1]).is_file():
                    self.DTBChimiePath = self.ListParam[1][1]
                else:
                    tkMB.showwarning('Attention', "Un problème est survenu lors de l'ouverture de la base de données de"
                                                  " chimie, veuillez vérifier les paramètres!", parent=self.FrmAccueil)
                    self.DTBChimiePath = self.ListParam[0][1]
                    self.InitParam(0)
                if Path(self.ListParam[1][2]).is_file():
                    self.DTBPhysPath = self.ListParam[1][2]
                else:
                    tkMB.showwarning('Attention',
                                     "Un problème est survenu lors de l'ouverture de la base de données de physique, "
                                     "veuillez vérifier les paramètres!", parent=self.FrmAccueil)
                    self.DTBPhysPath = self.ListParam[0][2]
                    self.InitParam(0)
        else:
            if len(self.ListParam) == 2:
                self.InitParam(1)
                if self.ListParam[1][1] != '' and self.ListParam[1][1] is not None:
                    Rep = tkMB.askyesno('Attention', 'Voulez-vous ouvrir la base de données de chimie: "' +
                                        self.ListParam[1][1] + '"', parent=self.FrmAccueil)
                    if Rep:
                        if Path(self.ListParam[1][1]).is_file():
                            self.DTBChimiePath = self.ListParam[1][1]
                        else:
                            tkMB.showwarning('Attention',
                                             "Un problème est survenu lors de l'ouverture de la base de données, "
                                             "veuillez vérifier les paramètres!", parent=self.FrmAccueil)
                            self.DTBChimiePath = self.ListParam[0][1]
                            self.InitParam(0)
                    else:
                        self.DTBChimiePath = self.ListParam[0][1]
                        self.InitParam(0)
                else:
                    self.DTBChimiePath = self.ListParam[0][1]
                    self.InitParam(0)

                if self.ListParam[1][2] != '' and self.ListParam[1][2] is not None:
                    Rep = tkMB.askyesno('Attention', 'Voulez-vous ouvrir la base de données de physique: "' +
                                        self.ListParam[1][2] + '"', parent=self.FrmAccueil)
                    if Rep:
                        if Path(self.ListParam[1][2]).is_file():
                            self.DTBPhysPath = self.ListParam[1][2]
                        else:
                            tkMB.showwarning('Attention',
                                             "Un problème est survenu lors de l'ouverture de la base de données, "
                                             "veuillez vérifier les paramètres!", parent=self.FrmAccueil)
                            self.DTBPhysPath = self.ListParam[0][2]
                            self.InitParam(0)
                    else:
                        self.DTBPhysPath = self.ListParam[0][2]
                        self.InitParam(0)
                else:
                    self.DTBPhysPath = self.ListParam[0][2]
                    self.InitParam(0)
            else:
                self.DTBChimiePath = self.ListParam[0][1]
                self.DTBPhysPath = self.ListParam[0][2]
                self.InitParam(0)

        if self.AutoSave == 1 and self.Init:
            SaveDTBChimie = False
            SaveDTBPhys = False
            TypeDTB = ['Chimie', 'Physique']
            for i in range(2):
                self.curSave.execute("select " + "Date , Heure" + " from Saves WHERE Type = \"" +
                                     TypeDTB[i] + "\"")
                ListSaves = self.curSave.fetchall()
                ListSaves.reverse()
                if len(ListSaves) > 0:
                    self.curSave.execute("select " + "Date" + " from Modif WHERE TypeDTB = \"" +
                                         TypeDTB[i] + "\"order by Date")
                    ListModif = self.curSave.fetchall()
                    for j in range(len(ListModif)):
                        if (datetime.strptime(ListSaves[0][0] + ' ' + ListSaves[0][1], '%d-%m-%Y %H:%M:%S') <
                                datetime.strptime(ListModif[j][0].split('.')[0], '%Y-%m-%d %H:%M:%S')):
                            if i == 0:
                                SaveDTBChimie = True
                            else:
                                SaveDTBPhys = True
                else:
                    if i == 0:
                        SaveDTBChimie = True
                    else:
                        SaveDTBPhys = True
            if SaveDTBChimie:
                self.SaveDTB(self.DTBChimiePath, 'Chimie')
            if SaveDTBPhys:
                self.SaveDTB(self.DTBPhysPath, 'Physique')
        self.DataBaseChimie = sqlite3.connect(self.DTBChimiePath)
        self.cur = self.DataBaseChimie.cursor()
        self.DataBasePhys = sqlite3.connect(self.DTBPhysPath)
        self.curphys = self.DataBasePhys.cursor()

        self.parent.focus_force()
        self.FrmLift()

    def MoveOnCanvas(self, _):
        self.CanvasBtnQuit.itemconfig(self.ImgCanvasBtnQuit, image=self.ImgBtnQuit[0])
        if self.InfoActionV and self.NAction != 102 and self.NAction != 1021 and self.NAction != 1022 and \
                self.NAction != 202 and self.NAction != 2021 and self.NAction != 2022 and self.NAction != 1011 \
                and self.NAction != 2011 and self.NAction != 101 and self.NAction != 201 and self.NAction != 301 \
                and self.NAction != 302 and self.NAction != 3021 and self.NAction != 3022 and self.NAction != 3011 \
                and self.NAction != 401 and self.NAction != 402 and self.NAction != 4021 and self.NAction != 4022 \
                and self.NAction != 4011 and self.NAction != 601 and self.NAction != 602 and self.NAction != 6021 \
                and self.NAction != 6022 and self.NAction != 6011:
            self.CanvasFrmMain.delete(self.LegendActionV)
            self.InfoActionV = False
        elif self.InfoAction:
            self.CanvasFrmMain.delete(self.LegendAction)
            self.InfoAction = False
        if self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 \
                or self.NAction == 1011:
            for i in range(3):
                if not self.InfoProd.MenuOnglets.MenuSelected[i]:
                    self.InfoProd.MenuOnglets.ListCanvasMenu[i].itemconfig(
                        self.InfoProd.MenuOnglets.ListImgMenu[i], image=self.InfoProd.MenuOnglets.ListMenu[i][0])
        elif self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 \
                or self.NAction == 2011:
            for i in range(3):
                if not self.InfoMat.MenuOnglets.MenuSelected[i]:
                    self.InfoMat.MenuOnglets.ListCanvasMenu[i].itemconfig(
                        self.InfoMat.MenuOnglets.ListImgMenu[i], image=self.InfoMat.MenuOnglets.ListMenu[i][0])
        elif (self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 or
              self.NAction == 3011) and self.BaseEnCours == 'CHIMIE':
            for i in range(3):
                if not self.InfoTP.MenuOnglets.MenuSelected[i]:
                    self.InfoTP.MenuOnglets.ListCanvasMenu[i].itemconfig(
                        self.InfoTP.MenuOnglets.ListImgMenu[i], image=self.InfoTP.MenuOnglets.ListMenu[i][0])

    def ClicOnCanvas(self, _):
        self.FrmLift()
        if self.FrmAccueil is not None:
            self.FrmAccueil.lift()
            if self.NAction == 5:
                self.FrmParam.lift()

    def PressBtn(self, j):
        if self.BaseEnCours == 'CHIMIE':
            self.ListBtnAction[j].CanvasBtn.itemconfig(self.ListBtnAction[j].ImgCanvasBtn,
                                                       image=self.ListBtnAction[j].ImgBtn[1])
        elif self.BaseEnCours == 'PHYS':
            if j < 3:
                self.ListBtnAction[j].CanvasBtn.itemconfig(self.ListBtnAction[j].ImgCanvasBtn,
                                                           image=self.ListBtnAction[j].ImgBtn[3])
            elif j == 3:
                self.ListBtnAction[j].CanvasBtn.itemconfig(self.ListBtnAction[j].ImgCanvasBtn,
                                                           image=self.ListBtnAction[j].ImgBtn[2])
            else:
                self.ListBtnAction[j].CanvasBtn.itemconfig(self.ListBtnAction[j].ImgCanvasBtn,
                                                           image=self.ListBtnAction[j].ImgBtn[1])

    def Action(self, j):
        if j == 0:
            if self.BaseEnCours == 'CHIMIE':
                if self.NAction < 10 and self.NAction != 1 and self.NAction != 5:
                    self.Action1()
                else:
                    if self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 \
                            or (self.OldNAction == 1 and self.NAction == 5):
                        self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[0].ImgBtn[1])
                    else:
                        self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[0].ImgBtn[0])
                    self.FrmLift()
                    winsound.PlaySound("*", winsound.SND_ASYNC)
            elif self.BaseEnCours == 'PHYS':
                if self.NAction < 10 and self.NAction != 2 and self.NAction != 5:
                    self.Action2()
                else:
                    if self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 \
                            or (self.OldNAction == 2 and self.NAction == 5):
                        self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[0].ImgBtn[3])
                    else:
                        self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[0].ImgBtn[2])
                    self.FrmLift()
                    winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 1:
            if self.BaseEnCours == 'CHIMIE':
                if self.NAction < 10 and self.NAction != 2 and self.NAction != 5:
                    self.Action2()
                else:
                    if self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 \
                            or (self.OldNAction == 2 and self.NAction == 5):
                        self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[1].ImgBtn[1])
                    else:
                        self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[1].ImgBtn[0])
                    self.FrmLift()
                    winsound.PlaySound("*", winsound.SND_ASYNC)
            elif self.BaseEnCours == 'PHYS':
                if self.NAction < 10 and self.NAction != 3 and self.NAction != 5:
                    self.Action3()
                else:
                    if self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 \
                            or (self.OldNAction == 3 and self.NAction == 5):
                        self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[1].ImgBtn[3])
                    else:
                        self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[1].ImgBtn[2])
                    self.FrmLift()
                    winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 2:
            if self.BaseEnCours == 'CHIMIE':
                if self.NAction < 10 and self.NAction != 3 and self.NAction != 5:
                    self.Action3()
                else:
                    if self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 \
                            or (self.OldNAction == 3 and self.NAction == 5):
                        self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[2].ImgBtn[1])
                    else:
                        self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[2].ImgBtn[0])
                    self.FrmLift()
                    winsound.PlaySound("*", winsound.SND_ASYNC)
            elif self.BaseEnCours == 'PHYS':
                if self.NAction < 10 and self.NAction != 4 and self.NAction != 5:
                    self.Action4()
                else:
                    if self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 \
                            or (self.OldNAction == 4 and self.NAction == 5):
                        self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[2].ImgBtn[3])
                    else:
                        self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[2].ImgBtn[2])
                    self.FrmLift()
                    winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 3:
            if self.BaseEnCours == 'CHIMIE':
                if self.NAction < 10 and self.NAction != 4 and self.NAction != 5:
                    self.Action4()
                else:
                    if self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 \
                            or (self.OldNAction == 4 and self.NAction == 5):
                        self.ListBtnAction[3].CanvasBtn.itemconfig(self.ListBtnAction[3].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[3].ImgBtn[1])
                    else:
                        self.ListBtnAction[3].CanvasBtn.itemconfig(self.ListBtnAction[3].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[3].ImgBtn[0])
                    self.FrmLift()
                    winsound.PlaySound("*", winsound.SND_ASYNC)
            elif self.BaseEnCours == 'PHYS':
                self.FrmLift()

        elif j == 4:
            if self.NAction < 10 and self.NAction != 5:
                self.Action5()
            else:
                if self.NAction != 5:
                    self.ListBtnAction[4].CanvasBtn.itemconfig(self.ListBtnAction[4].ImgCanvasBtn,
                                                               image=self.ListBtnAction[4].ImgBtn[0])
                    winsound.PlaySound("*", winsound.SND_ASYNC)
                else:
                    self.FrmParam.destroy()
                    self.ListBtnAction[4].CanvasBtn.itemconfig(self.ListBtnAction[4].ImgCanvasBtn,
                                                               image=self.ListBtnAction[4].ImgBtn[0])
                    self.NAction = self.OldNAction
                self.FrmLift()

        elif j == 5:
            if self.NAction < 10 and self.NAction != 5 and self.NAction != 6:
                self.Action6()
            else:
                if self.NAction == 6 or 600 < self.NAction < 700 or self.NAction == 6021 or self.NAction == 6022 \
                        or (self.OldNAction == 6 and self.NAction == 5):
                    self.ListBtnAction[5].CanvasBtn.itemconfig(self.ListBtnAction[5].ImgCanvasBtn,
                                                               image=self.ListBtnAction[5].ImgBtn[1])
                else:
                    self.ListBtnAction[5].CanvasBtn.itemconfig(self.ListBtnAction[5].ImgCanvasBtn,
                                                               image=self.ListBtnAction[5].ImgBtn[0])
                self.FrmLift()
                winsound.PlaySound("*", winsound.SND_ASYNC)

    def MotionBtn(self, j):
        if self.InfoAction:
            self.CanvasFrmMain.delete(self.LegendAction)
            self.InfoAction = False
        if self.NAction < 10:
            deb = 0
            if self.BaseEnCours == 'CHIMIE':
                deb = 0
            elif self.BaseEnCours == 'PHYS':
                deb = 6
            self.LegendAction = self.CanvasFrmMain.create_text(int(self.SX * 0.03),
                                                               int(self.SY * 0.128), anchor=tk.W,
                                                               text=self.ListInfoAction[deb + j], fill='black',
                                                               font=AppliFont('Helvetica', self.SizeFont, 'bold', 0))
            self.InfoAction = True

    def AfficheMenuV(self):
        for widget in self.CanvasMenuVFond.winfo_children():
            widget.destroy()
        self.ListBtnActionV = []
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.04),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnActionFind/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.1),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnCat/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.16),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnAjout/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.22),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnModif/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.28),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnSup/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.4),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnSAction1/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.46),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnSAction2/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.52),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnSAction3/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.58),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnSAction4/'))
        self.ListBtnActionV.append(BtnAction(self.CanvasMenuVFond, int(self.MVwsize * 0.5),
                                             int(self.MVhsize * 0.96),
                                             self.RatioFondX, self.RatioFondY, 'Media/FrmMain/MenuV/BtnHome/'))

        self.CacheMenuV()

        for i in range(len(self.ListBtnActionV)):
            def GestEvt(_, j=i):
                return self.ActionV(j)

            def GestEvt2(_, j=i):
                return self.MotionBtnV(j)

            self.ListBtnActionV[i].CanvasBtn.bind('<Motion>', GestEvt2)
            self.ListBtnActionV[i].CanvasBtn.bind('<ButtonRelease-1>', GestEvt)

    def MotionBtnV(self, j):
        if self.NAction != 102 and self.NAction != 1021 and self.NAction != 1022 and self.NAction != 202 and \
                self.NAction != 2021 and self.NAction != 2022 and self.NAction != 101 and self.NAction != 1011 \
                and self.NAction != 201 and self.NAction != 2011 and self.NAction != 302 and self.NAction != 3021 \
                and self.NAction != 3022 and self.NAction != 301 and self.NAction != 3011 and self.NAction != 402 \
                and self.NAction != 4021 and self.NAction != 4022 and self.NAction != 401 and self.NAction != 4011 \
                and self.NAction != 6021 and self.NAction != 6022 and self.NAction != 601 and self.NAction != 6011 \
                and self.NAction != 602:
            if self.InfoActionV:
                self.CanvasFrmMain.delete(self.LegendActionV)
                self.InfoActionV = False
            self.LegendActionV = self.CanvasFrmMain.create_text(int(self.SX * 0.03),
                                                                int(self.SY * 0.128), anchor=tk.W,
                                                                text=self.ListInfoActionV[j], fill='black',
                                                                font=AppliFont('Helvetica', self.SizeFont, 'bold', 0))

            self.InfoActionV = True

    def InitBtnAction(self):
        if self.NAction == 0:
            self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                       image=self.ListBtnAction[0].ImgBtn[4])
            self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                       image=self.ListBtnAction[1].ImgBtn[4])
            self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                       image=self.ListBtnAction[2].ImgBtn[4])
            self.ListBtnAction[3].CanvasBtn.itemconfig(self.ListBtnAction[3].ImgCanvasBtn,
                                                       image=self.ListBtnAction[3].ImgBtn[2])
            self.ListBtnAction[4].CanvasBtn.itemconfig(self.ListBtnAction[4].ImgCanvasBtn,
                                                       image=self.ListBtnAction[4].ImgBtn[2])
            self.ListBtnAction[5].CanvasBtn.itemconfig(self.ListBtnAction[5].ImgCanvasBtn,
                                                       image=self.ListBtnAction[5].ImgBtn[2])
        else:
            for i in range(6):
                if self.BaseEnCours == 'CHIMIE':
                    self.ListBtnAction[i].CanvasBtn.itemconfig(self.ListBtnAction[i].ImgCanvasBtn,
                                                               image=self.ListBtnAction[i].ImgBtn[0])
                    if i == 3:
                        ChangeCursor(self.ListBtnAction[i].CanvasBtn)
                elif self.BaseEnCours == 'PHYS':
                    if i < 4:
                        self.ListBtnAction[i].CanvasBtn.itemconfig(self.ListBtnAction[i].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[i].ImgBtn[2])
                        if i == 3:
                            ChangeCursor2(self.ListBtnAction[i].CanvasBtn)
                    else:
                        self.ListBtnAction[i].CanvasBtn.itemconfig(self.ListBtnAction[i].ImgCanvasBtn,
                                                                   image=self.ListBtnAction[i].ImgBtn[0])

        if self.InfoAction:
            self.CanvasFrmMain.delete(self.LegendAction)
            self.InfoAction = False

    def Action1(self):
        self.CacheMenuV()
        for i in range(5, 8):
            self.ListBtnActionV[i].CanvasBtn.itemconfig(self.ListBtnActionV[i].ImgCanvasBtn,
                                                        image=self.ListBtnActionV[i].ImgBtn[2])
            ChangeCursor(self.ListBtnActionV[i].CanvasBtn)
        self.ListBtnActionV[8].CanvasBtn.itemconfig(self.ListBtnActionV[8].ImgCanvasBtn,
                                                    image=self.ListBtnActionV[8].ImgBtn[0])
        ChangeCursor(self.ListBtnActionV[8].CanvasBtn)
        self.ListBtnActionV[6].CanvasBtn.bind('<ButtonPress-1>',
                                              lambda action: self.ListBtnActionV[6].CanvasBtn.itemconfig(
                                                  self.ListBtnActionV[6].ImgCanvasBtn,
                                                  image=self.ListBtnActionV[6].ImgBtn[3]))
        self.ListBtnActionV[5].CanvasBtn.bind('<ButtonPress-1>',
                                              lambda action: self.ListBtnActionV[5].CanvasBtn.itemconfig(
                                                  self.ListBtnActionV[5].ImgCanvasBtn,
                                                  image=self.ListBtnActionV[5].ImgBtn[3]))
        self.ListBtnActionV[7].CanvasBtn.bind('<ButtonPress-1>',
                                              lambda action: self.ListBtnActionV[7].CanvasBtn.itemconfig(
                                                  self.ListBtnActionV[7].ImgCanvasBtn,
                                                  image=self.ListBtnActionV[7].ImgBtn[3]))
        self.ListBtnActionV[8].CanvasBtn.bind('<ButtonPress-1>',
                                              lambda action: self.ListBtnActionV[8].CanvasBtn.itemconfig(
                                                  self.ListBtnActionV[8].ImgCanvasBtn,
                                                  image=self.ListBtnActionV[8].ImgBtn[1]))
        self.ListInfoActionV[6] = 'Consommations annuelles de produits'
        self.ListInfoActionV[5] = 'Tableau récapitulatif des produits'
        self.ListInfoActionV[7] = 'Produits chimiques à recycler'
        self.ListInfoActionV[8] = 'Commandes produits chimiques'

        if self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 or \
                self.NAction == 2011:
            self.EtagMat.CanvasEtagMat.itemconfig(self.EtagMat.ImgCanvasEtagMat, image=self.EtagMat.ImgEtagMat[1])
            self.EtagMat.destroy()
            self.InfoMat.destroy()

        elif self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 or \
                self.NAction == 3011:
            self.FrmTP.destroy()
            self.InfoTP.destroy()

        elif self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 or \
                self.NAction == 4011:
            self.FrmDoc.destroy()
            self.InfoDoc.destroy()

        elif self.NAction == 6 or 600 < self.NAction < 700 or self.NAction == 6021 or self.NAction == 6022 or \
                self.NAction == 6011:
            self.FrmFour.destroy()
            self.InfoFour.destroy()

        self.NAction = 1
        self.OldNAction = 0
        self.InitBtnAction()
        self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                   image=self.ListBtnAction[0].ImgBtn[1])
        self.ListBtnActionV[5].CanvasBtn.bind('<ButtonPress-1>',
                                              lambda action: self.ListBtnActionV[5].CanvasBtn.itemconfig(
                                                  self.ListBtnActionV[5].ImgCanvasBtn,
                                                  image=self.ListBtnActionV[5].ImgBtn[3]))

        self.cur.execute("select " + self.ListChampsTabProd + " from PRODUITS order by NOMS")
        self.ListProduits = self.cur.fetchall()

        self.Init = True
        self.ChargeListProduits(self.ListProduits)
        self.AffichEtagProduits(self.ListProduits)
        self.AffichInfoProd(0)
        self.MAJInfo()
        self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des produits chimiques")
        self.Init = False

        self.FrmLift()

    def Action2(self):
        self.CacheMenuV()
        self.ListBtnActionV[5].CanvasBtn.itemconfig(self.ListBtnActionV[5].ImgCanvasBtn,
                                                    image=self.ListBtnActionV[5].ImgBtn[2])
        ChangeCursor(self.ListBtnActionV[5].CanvasBtn)
        self.ListBtnActionV[5].CanvasBtn.bind('<ButtonPress-1>',
                                              lambda action: self.ListBtnActionV[5].CanvasBtn.itemconfig(
                                                  self.ListBtnActionV[5].ImgCanvasBtn,
                                                  image=self.ListBtnActionV[5].ImgBtn[3]))
        self.ListInfoActionV[5] = 'Tableau récapitulatif du matériel'

        self.ListBtnActionV[6].CanvasBtn.itemconfig(self.ListBtnActionV[6].ImgCanvasBtn,
                                                    image=self.ListBtnActionV[7].ImgBtn[2])
        ChangeCursor(self.ListBtnActionV[6].CanvasBtn)
        self.ListBtnActionV[6].CanvasBtn.bind('<ButtonPress-1>',
                                              lambda action: self.ListBtnActionV[6].CanvasBtn.itemconfig(
                                                  self.ListBtnActionV[6].ImgCanvasBtn,
                                                  image=self.ListBtnActionV[7].ImgBtn[3]))
        self.ListInfoActionV[6] = 'Matériel HS ou consommables'

        self.ListBtnActionV[7].CanvasBtn.itemconfig(self.ListBtnActionV[7].ImgCanvasBtn,
                                                    image=self.ListBtnActionV[8].ImgBtn[0])
        ChangeCursor(self.ListBtnActionV[7].CanvasBtn)
        self.ListBtnActionV[7].CanvasBtn.bind('<ButtonPress-1>',
                                              lambda action: self.ListBtnActionV[7].CanvasBtn.itemconfig(
                                                  self.ListBtnActionV[7].ImgCanvasBtn,
                                                  image=self.ListBtnActionV[8].ImgBtn[1]))
        self.ListInfoActionV[7] = 'Commandes matériels de chimie'

        if self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 or \
                self.NAction == 1011:
            self.EtagProduits.CanvasEtagProduits.itemconfig(self.EtagProduits.ImgCanvasEtagProduits,
                                                            image=self.EtagProduits.ImgEtagProduits[1])
            self.EtagProduits.destroy()
            self.InfoProd.destroy()

        elif self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 or \
                self.NAction == 3011:
            self.FrmTP.destroy()
            self.InfoTP.destroy()

        elif self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 or \
                self.NAction == 4011:
            self.FrmDoc.destroy()
            self.InfoDoc.destroy()

        elif self.NAction == 6 or 600 < self.NAction < 700 or self.NAction == 6021 or self.NAction == 6022 or \
                self.NAction == 6011:
            self.FrmFour.destroy()
            self.InfoFour.destroy()

        self.ListBoxProduits.delete(0, tk.END)
        self.NAction = 2
        self.OldNAction = 0
        self.InitBtnAction()
        if self.BaseEnCours == 'CHIMIE':

            self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                       image=self.ListBtnAction[1].ImgBtn[1])
            self.cur.execute("select " + self.ListChampsTabMat + " from MATERIEL order by NOMS")
            self.ListMats = self.cur.fetchall()
            self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion du matériel de chimie")
        elif self.BaseEnCours == 'PHYS':
            self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                       image=self.ListBtnAction[0].ImgBtn[3])
            self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                       image=self.ListBtnAction[1].ImgBtn[2])
            self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                       image=self.ListBtnAction[2].ImgBtn[2])
            self.curphys.execute("select " + self.ListChampsTabMatPhys + " from MATERIEL order by NOMS")
            self.ListMats = self.curphys.fetchall()
            self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion du matériel de physique")

        self.Init = True
        self.ChargeListProduits(self.ListMats)
        self.AffichEtagProduits(self.ListMats)
        self.AffichInfoProd(0)
        self.MAJInfo()
        self.Init = False

        self.FrmLift()

    def Action3(self):
        self.CacheMenuV()
        if self.BaseEnCours == "CHIMIE":
            for i in range(5, 8):
                self.ListBtnActionV[i].CanvasBtn.itemconfig(self.ListBtnActionV[i].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[i].ImgBtn[0])
                ChangeCursor(self.ListBtnActionV[i].CanvasBtn)
            self.ListBtnActionV[8].CanvasBtn.itemconfig(self.ListBtnActionV[8].ImgCanvasBtn,
                                                        image=self.ListBtnActionV[8].ImgBtn[2])
            ChangeCursor(self.ListBtnActionV[8].CanvasBtn)
            self.ListBtnActionV[6].CanvasBtn.bind('<ButtonPress-1>',
                                                  lambda action: self.ListBtnActionV[6].CanvasBtn.itemconfig(
                                                      self.ListBtnActionV[6].ImgCanvasBtn,
                                                      image=self.ListBtnActionV[6].ImgBtn[1]))
            self.ListBtnActionV[5].CanvasBtn.bind('<ButtonPress-1>',
                                                  lambda action: self.ListBtnActionV[5].CanvasBtn.itemconfig(
                                                      self.ListBtnActionV[5].ImgCanvasBtn,
                                                      image=self.ListBtnActionV[5].ImgBtn[1]))
            self.ListBtnActionV[7].CanvasBtn.bind('<ButtonPress-1>',
                                                  lambda action: self.ListBtnActionV[7].CanvasBtn.itemconfig(
                                                      self.ListBtnActionV[7].ImgCanvasBtn,
                                                      image=self.ListBtnActionV[7].ImgBtn[1]))
            self.ListBtnActionV[8].CanvasBtn.bind('<ButtonPress-1>',
                                                  lambda action: self.ListBtnActionV[8].CanvasBtn.itemconfig(
                                                      self.ListBtnActionV[8].ImgCanvasBtn,
                                                      image=self.ListBtnActionV[8].ImgBtn[3]))
            self.ListInfoActionV[5] = 'Préparer le matériel'
            self.ListInfoActionV[6] = 'Préparer les produits chimiques'
            self.ListInfoActionV[7] = 'Préparer les solutions'
            self.ListInfoActionV[8] = 'Planning des TPs'

        elif self.BaseEnCours == "PHYS":
            self.ListBtnActionV[5].CanvasBtn.itemconfig(self.ListBtnActionV[5].ImgCanvasBtn,
                                                        image=self.ListBtnActionV[5].ImgBtn[4])
            ChangeCursor(self.ListBtnActionV[5].CanvasBtn)
            self.ListBtnActionV[5].CanvasBtn.bind('<ButtonPress-1>',
                                                  lambda action: self.ListBtnActionV[5].CanvasBtn.itemconfig(
                                                      self.ListBtnActionV[5].ImgCanvasBtn,
                                                      image=self.ListBtnActionV[5].ImgBtn[5]))
            self.ListInfoActionV[5] = 'Préparer le matériel'
            self.ListBtnActionV[6].CanvasBtn.itemconfig(self.ListBtnActionV[6].ImgCanvasBtn,
                                                        image=self.ListBtnActionV[8].ImgBtn[2])
            ChangeCursor(self.ListBtnActionV[6].CanvasBtn)
            self.ListBtnActionV[6].CanvasBtn.bind('<ButtonPress-1>',
                                                  lambda action: self.ListBtnActionV[6].CanvasBtn.itemconfig(
                                                      self.ListBtnActionV[6].ImgCanvasBtn,
                                                      image=self.ListBtnActionV[8].ImgBtn[3]))
            self.ListInfoActionV[6] = 'Planning des TPs'

        if self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 or \
                self.NAction == 2011:
            self.EtagMat.CanvasEtagMat.itemconfig(self.EtagMat.ImgCanvasEtagMat, image=self.EtagMat.ImgEtagMat[1])
            self.EtagMat.destroy()
            self.InfoMat.destroy()

        elif self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 or \
                self.NAction == 1011:
            self.EtagProduits.CanvasEtagProduits.itemconfig(self.EtagProduits.ImgCanvasEtagProduits,
                                                            image=self.EtagProduits.ImgEtagProduits[1])
            self.EtagProduits.destroy()
            self.InfoProd.destroy()

        elif self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 or \
                self.NAction == 4011:
            self.FrmDoc.destroy()
            self.InfoDoc.destroy()

        elif self.NAction == 6 or 600 < self.NAction < 700 or self.NAction == 6021 or self.NAction == 6022 or \
                self.NAction == 6011:
            self.FrmFour.destroy()
            self.InfoFour.destroy()

        self.NAction = 3
        self.OldNAction = 0
        self.InitBtnAction()
        if self.BaseEnCours == 'CHIMIE':
            self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                       image=self.ListBtnAction[2].ImgBtn[1])
            self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des travaux pratiques de chimie")
            self.cur.execute("select " + self.ListChampsTabTP + " from TP order by TITRE")
            self.ListTP = self.cur.fetchall()
        elif self.BaseEnCours == 'PHYS':
            self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                       image=self.ListBtnAction[0].ImgBtn[2])
            self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                       image=self.ListBtnAction[1].ImgBtn[3])
            self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                       image=self.ListBtnAction[2].ImgBtn[2])
            self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des travaux pratiques de physique")
            self.curphys.execute("select " + self.ListChampsTabTP + " from TP order by TITRE")
            self.ListTP = self.curphys.fetchall()

        self.ListTPs = []
        for i in self.ListTP:
            if i not in self.ListTPs:
                self.ListTPs.append(i)
        self.Init = True
        self.ChargeListProduits(self.ListTPs)
        self.AffichEtagProduits(self.ListTPs)
        self.AffichInfoProd(0)
        self.MAJInfo()
        self.Init = False
        self.CanvasFrmMain.delete(self.LegendActionV)
        self.FrmLift()

    def Action4(self):
        self.CacheMenuV()
        if self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 or \
                self.NAction == 2011:
            self.EtagMat.CanvasEtagMat.itemconfig(self.EtagMat.ImgCanvasEtagMat, image=self.EtagMat.ImgEtagMat[1])
            self.EtagMat.destroy()
            self.InfoMat.destroy()

        elif self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 or \
                self.NAction == 1011:
            self.EtagProduits.CanvasEtagProduits.itemconfig(self.EtagProduits.ImgCanvasEtagProduits,
                                                            image=self.EtagProduits.ImgEtagProduits[1])
            self.EtagProduits.destroy()
            self.InfoProd.destroy()

        elif self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 or \
                self.NAction == 3011:
            self.FrmTP.destroy()
            self.InfoTP.destroy()

        elif self.NAction == 6 or 600 < self.NAction < 700 or self.NAction == 6021 or self.NAction == 6022 or \
                self.NAction == 6011:
            self.FrmFour.destroy()
            self.InfoFour.destroy()

        self.NAction = 4
        self.OldNAction = 0
        self.InitBtnAction()

        if self.BaseEnCours == 'CHIMIE':
            self.ListBtnAction[3].CanvasBtn.itemconfig(self.ListBtnAction[3].ImgCanvasBtn,
                                                       image=self.ListBtnAction[3].ImgBtn[1])
            self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion de la documentation de chimie")
            self.cur.execute("select " + self.ListChampsTabDoc + " from Docs order by Titre")
            self.ListDocs = self.cur.fetchall()
        elif self.BaseEnCours == 'PHYS':
            self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                       image=self.ListBtnAction[0].ImgBtn[2])
            self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                       image=self.ListBtnAction[1].ImgBtn[2])
            self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                       image=self.ListBtnAction[2].ImgBtn[3])
            self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion de la documentation de physique")
            self.curphys.execute("select " + self.ListChampsTabDoc + " from Docs order by Titre")
            self.ListDocs = self.curphys.fetchall()

        self.Init = True
        self.ChargeListProduits(self.ListDocs)
        self.AffichEtagProduits(self.ListDocs)
        self.AffichInfoProd(0)
        self.MAJInfo()
        self.Init = False
        self.CanvasFrmMain.delete(self.LegendActionV)
        self.FrmLift()

    def Action5(self):
        self.ListBtnAction[4].CanvasBtn.itemconfig(self.ListBtnAction[4].ImgCanvasBtn,
                                                   image=self.ListBtnAction[4].ImgBtn[1])
        self.FrmLift()
        self.FrmParam = FrmParam(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
        self.OldNAction = self.NAction
        self.NAction = 5

    def Action6(self):
        self.CacheMenuV()
        if self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 or \
                self.NAction == 2011:
            self.EtagMat.CanvasEtagMat.itemconfig(self.EtagMat.ImgCanvasEtagMat, image=self.EtagMat.ImgEtagMat[1])
            self.EtagMat.destroy()
            self.InfoMat.destroy()

        elif self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 or \
                self.NAction == 1011:
            self.EtagProduits.CanvasEtagProduits.itemconfig(self.EtagProduits.ImgCanvasEtagProduits,
                                                            image=self.EtagProduits.ImgEtagProduits[1])
            self.EtagProduits.destroy()
            self.InfoProd.destroy()

        elif self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 or \
                self.NAction == 3011:
            self.FrmTP.destroy()
            self.InfoTP.destroy()

        elif self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 or \
                self.NAction == 4011:
            self.FrmDoc.destroy()
            self.InfoDoc.destroy()

        self.NAction = 6
        self.OldNAction = 0
        self.InitBtnAction()
        self.ListBtnAction[5].CanvasBtn.itemconfig(self.ListBtnAction[5].ImgCanvasBtn,
                                                   image=self.ListBtnAction[5].ImgBtn[1])

        if self.BaseEnCours == 'CHIMIE':
            self.CanvasFrmMain.itemconfigure(
                'LegendePanneauG', text="Gestion des fournisseurs de chimie")
            self.cur.execute("select " + self.ListChampsTabFournisseurs + " from Fournisseurs order by NOM")
            self.ListFours = self.cur.fetchall()
        elif self.BaseEnCours == 'PHYS':
            self.ListBtnAction[0].CanvasBtn.itemconfig(self.ListBtnAction[0].ImgCanvasBtn,
                                                       image=self.ListBtnAction[0].ImgBtn[2])
            self.ListBtnAction[1].CanvasBtn.itemconfig(self.ListBtnAction[1].ImgCanvasBtn,
                                                       image=self.ListBtnAction[1].ImgBtn[2])
            self.ListBtnAction[2].CanvasBtn.itemconfig(self.ListBtnAction[2].ImgCanvasBtn,
                                                       image=self.ListBtnAction[2].ImgBtn[2])
            self.CanvasFrmMain.itemconfigure(
                'LegendePanneauG', text="Gestion des fournisseurs physique")
            self.curphys.execute("select " + self.ListChampsTabFournisseurs + " from Fournisseurs order by NOM")
            self.ListFours = self.curphys.fetchall()

        self.Init = True
        self.ChargeListProduits(self.ListFours)
        self.AffichEtagProduits(self.ListFours)
        self.AffichInfoProd(0)
        self.MAJInfo()
        self.Init = False
        self.CanvasFrmMain.delete(self.LegendActionV)
        self.FrmLift()

    def ActionV(self, j):
        if j < 2 and self.NAction < 10:
            self.ButtonClic = j
        if j < 5 or j == 9:
            self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                        image=self.ListBtnActionV[j].ImgBtn[0])
        if j == 0:
            if self.NAction not in [101, 1011, 102, 1021, 1022, 201, 2011, 202, 2021, 2022, 301, 3011, 302, 3021, 3022,
                                    401, 4011, 402, 4021, 4022, 5, 601, 6011, 602, 6021, 6022] and self.NbrElt > 0:
                self.Recherche()
            elif self.NAction == 101 or self.NAction == 201 or self.NAction == 301 or self.NAction == 401 \
                    or self.NAction == 601:
                self.RetourListeProduits()
                self.CanvasBtnRetour.itemconfig(self.ImgCanvasBtnRetour, image=self.ImgBtnRetour[0])
                ChangeCursor2(self.CanvasBtnRetour)
                self.ButtonClic = -1
            elif self.NAction == 1011 or self.NAction == 2011 or self.NAction == 3011 or self.NAction == 4011 \
                    or self.NAction == 6011:
                self.RetourListeProduits()
                self.Recherche()
            else:
                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 1:
            if self.NAction not in [101, 1011, 102, 1022, 201, 2011, 202, 2022, 301, 3011, 302, 3022,
                                    401, 4011, 402, 4022, 5, 601, 6011, 602, 6022] and self.NbrElt > 0:
                self.ListBtnActionV[1].CanvasBtn.itemconfig(self.ListBtnActionV[1].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[1].ImgBtn[1])
                self.CanvasBtnRetour.itemconfig(self.ImgCanvasBtnRetour, image=self.ImgBtnRetour[1])
                ChangeCursor(self.CanvasBtnRetour)
                ListCat = []
                TextCat = []
                if self.NAction == 1 or self.NAction == 1021:
                    self.NAction = 102
                    ListCat = self.ListCatProduits
                    TextCat = 'Trier les produits par:'
                    self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                     text="Gestion des produits chimiques - Trie")
                elif self.NAction == 2 or self.NAction == 2021:
                    self.NAction = 202
                    ListCat = self.ListCatMats
                    TextCat = 'Trier le matériel par:'
                    if self.BaseEnCours == 'CHIMIE':
                        self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                         text="Gestion du matériel de chimie - Trie")
                    elif self.BaseEnCours == 'PHYS':
                        self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                         text="Gestion du matériel de physique - Trie")
                elif self.NAction == 3 or self.NAction == 3021:
                    self.NAction = 302
                    ListCat = self.ListCatTPs
                    TextCat = 'Trier les TPs par:'
                    if self.BaseEnCours == 'CHIMIE':
                        self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                         text="Gestion des TPs de chimie - Trie")
                    elif self.BaseEnCours == 'PHYS':
                        self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                         text="Gestion des TPs de physique - Trie")
                elif self.NAction == 4 or self.NAction == 4021:
                    self.NAction = 402
                    ListCat = self.ListCatDocs
                    TextCat = 'Trier les documents par:'
                    if self.BaseEnCours == 'CHIMIE':
                        self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                         text="Gestion des documents de chimie - Trie")
                    elif self.BaseEnCours == 'PHYS':
                        self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                         text="Gestion des documents de physique - Trie")

                elif self.NAction == 6 or self.NAction == 6021:
                    self.NAction = 602
                    ListCat = self.ListCatFours
                    TextCat = 'Trier les fournisseurs par:'
                    if self.BaseEnCours == 'CHIMIE':
                        self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                         text="Gestion des fournisseurs de chimie - Trie")
                    elif self.BaseEnCours == 'PHYS':
                        self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                         text="Gestion des fournisseurs de physique - Trie")
                self.ListBoxProduits.delete(0, tk.END)
                for i in range(len(ListCat)):
                    self.ListBoxProduits.insert(tk.END, ListCat[i])
                self.CanvasFrmMain.itemconfig(self.LegendActionV, text=TextCat)

            elif self.NAction == 102 or self.NAction == 202 or self.NAction == 302 or self.NAction == 402 \
                    or self.NAction == 602:
                self.RetourListeProduits()
                self.CanvasBtnRetour.itemconfig(self.ImgCanvasBtnRetour, image=self.ImgBtnRetour[0])
                ChangeCursor2(self.CanvasBtnRetour)
                self.ButtonClic = -1
            elif self.NAction == 1022 or self.NAction == 2022 or self.NAction == 3022 or self.NAction == 4022 \
                    or self.NAction == 6022:
                self.ListBtnActionV[1].CanvasBtn.itemconfig(self.ListBtnActionV[1].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[1].ImgBtn[1])
                if self.NAction == 1022:
                    self.AffichEtagProduits(self.ListProduits)
                    self.AffichListCat(self.NCatselected)
                elif self.NAction == 2022:
                    self.AffichEtagProduits(self.ListMats)
                    self.AffichListCatMat(self.NCatselected)
                elif self.NAction == 3022:
                    self.AffichEtagProduits(self.ListTPs)
                    self.AffichListCatTP(self.NCatselected)
                elif self.NAction == 4022:
                    self.AffichEtagProduits(self.ListDocs)
                    self.AffichListCatDoc(self.NCatselected)
                elif self.NAction == 6022:
                    self.AffichEtagProduits(self.ListFours)
                    self.AffichListCatFour(self.NCatselected)
            else:
                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 2:
            if self.NAction not in [101, 1011, 102, 1021, 1022, 201, 2011, 202, 2021, 2022, 301, 3011, 302, 3021, 3022,
                                    401, 4011, 402, 4021, 4022, 5, 601, 6011, 602, 6021, 6022]:
                if self.NAction == 1:
                    self.NAction = 103
                    self.FrmAjoutProd = FrmAjoutProd(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                elif self.NAction == 2:
                    self.NAction = 203
                    self.FrmAjoutMat = FrmAjoutMat(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                elif self.NAction == 3:
                    self.NAction = 303
                    if self.BaseEnCours == "CHIMIE":
                        self.FrmAjoutTP = FrmAjoutTP(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    elif self.BaseEnCours == "PHYS":
                        self.FrmAjoutTP = FrmAjoutTPPhys(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                elif self.NAction == 4:
                    self.NAction = 403
                    self.FrmAjoutDoc = FrmAjoutDoc(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                elif self.NAction == 6:
                    self.NAction = 603
                    self.FrmAjoutFour = FrmAjoutFour(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                self.CanvasFrmMain.delete(self.LegendActionV)
            else:
                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 3:
            if self.NAction not in [101, 102, 1021, 201, 202, 2021, 301, 302, 3021,
                                    401, 402, 4021, 5, 601, 602, 6021] and self.NbrElt > 0:
                if self.NAction == 1 or self.NAction == 1011 or self.NAction == 1022:
                    self.ModifEnCours = True
                    self.FrmModifProd = FrmAjoutProd(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 104
                elif self.NAction == 2 or self.NAction == 2011 or self.NAction == 2022:
                    self.ModifEnCours = True
                    self.FrmModifMat = FrmAjoutMat(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 204
                elif self.NAction == 3 or self.NAction == 3011 or self.NAction == 3022:
                    self.ModifEnCours = True
                    if self.BaseEnCours == "CHIMIE":
                        self.FrmModifTP = FrmAjoutTP(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    elif self.BaseEnCours == "PHYS":
                        self.FrmModifTPPhys = FrmAjoutTPPhys(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 304
                elif self.NAction == 4 or self.NAction == 4011 or self.NAction == 4022:
                    self.ModifEnCours = True
                    self.FrmModifDoc = FrmAjoutDoc(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 404
                elif self.NAction == 6 or self.NAction == 6011 or self.NAction == 6022:
                    self.ModifEnCours = True
                    self.FrmModifFour = FrmAjoutFour(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 604
                self.CanvasFrmMain.delete(self.LegendActionV)
            else:
                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 4:
            if self.NAction not in [101, 102, 1021, 201, 202, 2021, 301, 302, 3021,
                                    401, 402, 4021, 5, 601, 602, 6021] and self.NbrElt > 0:
                self.SupProd(self.IndexElt)
            else:
                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 5:
            if self.NAction == 1:
                self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[j].ImgBtn[2])
                if self.BaseEnCours == "CHIMIE":
                    self.FrmTabRecapProd = FrmTabRecapProd(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 105
            elif self.NAction == 2:
                self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[j].ImgBtn[2])
                self.FrmTabRecapMat = FrmTabRecapMat(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                self.OldNAction = self.NAction
                self.NAction = 205
            elif (self.NAction == 3 or self.NAction == 3011 or self.NAction == 3022) and self.NbrElt > 0:
                self.ModifEnCours = True
                if self.BaseEnCours == "CHIMIE":
                    self.ListBtnActionV[5].CanvasBtn.itemconfig(self.ListBtnActionV[5].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[5].ImgBtn[0])
                    self.FrmPrepaMat = FrmPrepaMat(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 3051
                elif self.BaseEnCours == "PHYS":
                    self.ListBtnActionV[5].CanvasBtn.itemconfig(self.ListBtnActionV[5].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[5].ImgBtn[4])
                    self.FrmPrepaMat = FrmPrepaMat(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 3051
            elif self.NAction == 5:
                if self.OldNAction == 1 or self.OldNAction == 2:
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[2])
                elif self.OldNAction == 3:
                    if self.BaseEnCours == "CHIMIE":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[j].ImgBtn[0])
                    elif self.BaseEnCours == "PHYS":
                        self.ListBtnActionV[5].CanvasBtn.itemconfig(self.ListBtnActionV[5].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[5].ImgBtn[4])
                winsound.PlaySound("*", winsound.SND_ASYNC)
            else:
                if str(self.NAction)[0] == "1" or str(self.NAction)[0] == "2":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[2])
                elif str(self.NAction)[0] == "3":
                    if self.BaseEnCours == "CHIMIE":
                        self.ListBtnActionV[5].CanvasBtn.itemconfig(self.ListBtnActionV[5].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[5].ImgBtn[0])
                    elif self.BaseEnCours == "PHYS":
                        self.ListBtnActionV[5].CanvasBtn.itemconfig(self.ListBtnActionV[5].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[5].ImgBtn[4])

                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 6:
            if self.NAction == 1:
                self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[j].ImgBtn[2])
                if self.BaseEnCours == "CHIMIE":
                    self.FrmConsomProd = FrmConsomProd(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY,
                                                       'Consom', self)
                    self.OldNAction = self.NAction
                    self.NAction = 106
            elif self.NAction == 2:
                self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[7].ImgBtn[2])
                self.FrmMatHS = FrmMatHS(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                self.OldNAction = self.NAction
                self.NAction = 206
            elif (self.NAction == 3 or self.NAction == 3011 or self.NAction == 3022) and self.NbrElt > 0:
                self.ModifEnCours = True
                if self.BaseEnCours == "CHIMIE":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[0])
                    self.FrmPrepaProd = FrmPrepaProd(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 3052
                if self.BaseEnCours == "PHYS":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[8].ImgBtn[2])
                    self.FrmPlanningTP = FrmPlanningTP(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 306
            elif self.NAction == 5:
                if self.OldNAction == 1:
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[2])
                elif self.OldNAction == 2:
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[7].ImgBtn[2])
                elif self.OldNAction == 3:
                    if self.BaseEnCours == "CHIMIE":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[j].ImgBtn[0])
                    elif self.BaseEnCours == "PHYS":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[8].ImgBtn[2])
                winsound.PlaySound("*", winsound.SND_ASYNC)
            else:
                if str(self.NAction)[0] == "1":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[2])
                elif str(self.NAction)[0] == "2":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[7].ImgBtn[2])
                elif str(self.NAction)[0] == "3":
                    if self.BaseEnCours == "CHIMIE":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[j].ImgBtn[0])
                    elif self.BaseEnCours == "PHYS":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[8].ImgBtn[2])
                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 7:
            if self.NAction == 1:
                self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[j].ImgBtn[2])
                if self.BaseEnCours == "CHIMIE":
                    self.FrmAjoutProdRecy = FrmConsomProd(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY,
                                                          'Recyclage', self)
                    self.OldNAction = self.NAction
                    self.NAction = 107
            elif self.NAction == 2:
                self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[8].ImgBtn[0])
                self.FrmCommandMat = FrmCommandMat(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                self.OldNAction = self.NAction
                self.NAction = 207

            elif (self.NAction == 3 or self.NAction == 3011 or self.NAction == 3022) and self.NbrElt > 0:
                self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[j].ImgBtn[0])
                self.ModifEnCours = True
                if self.BaseEnCours == "CHIMIE":
                    self.FrmPrepaSol = FrmPrepaSol(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 3053
                elif self.BaseEnCours == "PHYS":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[4])

            elif self.NAction == 5:
                if self.OldNAction == 1:
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[2])
                elif self.OldNAction == 2:
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[8].ImgBtn[0])
                elif self.OldNAction == 3:
                    if self.BaseEnCours == "CHIMIE":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[j].ImgBtn[0])
                    elif self.BaseEnCours == "PHYS":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[j].ImgBtn[4])
                winsound.PlaySound("*", winsound.SND_ASYNC)

            else:
                if str(self.NAction)[0] == "1":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[2])
                elif str(self.NAction)[0] == "2":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[8].ImgBtn[0])
                elif str(self.NAction)[0] == "3":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[0])
                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 8:
            if self.NAction == 1:
                self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[j].ImgBtn[0])
                self.FrmCommandProd = FrmCommandProd(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                self.OldNAction = self.NAction
                self.NAction = 108
            elif self.NAction == 3 and self.NbrElt > 0:
                if self.BaseEnCours == "CHIMIE":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[2])
                    self.FrmPlanningTP = FrmPlanningTP(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
                    self.OldNAction = self.NAction
                    self.NAction = 306
                elif self.BaseEnCours == "PHYS":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[4])
            elif self.NAction == 5:
                if self.OldNAction == 1:
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[0])
                elif self.OldNAction == 3:
                    if self.BaseEnCours == "CHIMIE":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[j].ImgBtn[2])
                    elif self.BaseEnCours == "PHYS":
                        self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                    image=self.ListBtnActionV[j].ImgBtn[4])
                winsound.PlaySound("*", winsound.SND_ASYNC)
            else:
                if str(self.NAction)[0] == "1":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[0])
                elif str(self.NAction)[0] == "3":
                    self.ListBtnActionV[j].CanvasBtn.itemconfig(self.ListBtnActionV[j].ImgCanvasBtn,
                                                                image=self.ListBtnActionV[j].ImgBtn[2])
                winsound.PlaySound("*", winsound.SND_ASYNC)

        elif j == 9:
            self.CanvasFrmMain.delete(self.LegendActionV)
            if self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 or \
                    self.NAction == 1011:
                self.EtagProduits.destroy()
                self.InfoProd.destroy()
            elif self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 or \
                    self.NAction == 2011:
                self.EtagMat.destroy()
                self.InfoMat.destroy()
            elif self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 or \
                    self.NAction == 3011:
                self.FrmTP.destroy()
                self.InfoTP.destroy()
            elif self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 or \
                    self.NAction == 4011:
                self.FrmDoc.destroy()
                self.InfoDoc.destroy()
            elif self.NAction == 5:
                self.FrmParam.destroy()

            self.ListBoxProduits.delete(0, tk.END)
            if self.FrmFindData is not None or self.NAction == 102 or self.NAction == 1021 or self.NAction == 1022 \
                    or self.NAction == 202 or self.NAction == 2021 or self.NAction == 2022 \
                    or self.NAction == 302 or self.NAction == 3021 or self.NAction == 3022 \
                    or self.NAction == 402 or self.NAction == 4021 or self.NAction == 4022:
                if self.FrmFindData:
                    self.FrmFindData.destroy()
                    self.FrmFindData = None
                self.CanvasBtnRetour.itemconfig(self.ImgCanvasBtnRetour, image=self.ImgBtnRetour[0])
                ChangeCursor2(self.CanvasBtnRetour)
                self.ListBtnActionV[0].CanvasBtn.itemconfig(self.ListBtnActionV[0].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[0].ImgBtn[0])
                self.ListBtnActionV[1].CanvasBtn.itemconfig(self.ListBtnActionV[1].ImgCanvasBtn,
                                                            image=self.ListBtnActionV[1].ImgBtn[0])
            self.ButtonClic = -1
            self.NAction = 0
            self.FrmAccueil = FrmAccueil(self.CanvasFrmMain, self.RatioFondX, self.RatioFondY, self)
        self.MAJInfo()
        self.FrmLift()

    def ChargeListProduits(self, lp):
        self.ListBoxProduits.delete(0, tk.END)
        self.ListNomProd = []
        for i in range(len(lp)):
            if self.CatSelected == "ANNEE SCOLAIRE" and self.NAction == 3022:
                self.ListBoxProduits.insert(tk.END, lp[i][2] + ' - ' + lp[i][0])
            else:
                self.ListBoxProduits.insert(tk.END, lp[i][0])
            self.ListNomProd.append(lp[i][0])

    def AffichEtagProduits(self, ListProduits):
        if self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 \
                or self.NAction == 1011:
            if self.EtagProduits is not None:
                self.EtagProduits.destroy()
            self.EtagProduits = FrmEtagProduits(self.CanvasFrmMain, ListProduits, self.RatioFondX, self.RatioFondY,
                                                self)
        elif self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 \
                or self.NAction == 2011:
            if self.EtagMat is not None:
                self.EtagMat.destroy()
            self.EtagMat = FrmEtagMat(self.CanvasFrmMain, ListProduits, self.RatioFondX, self.RatioFondY, self)

        elif self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 \
                or self.NAction == 3011:
            if self.FrmTP is not None:
                self.FrmTP.destroy()
            if self.InfoTP is not None:
                self.InfoTP.destroy()
            if len(ListProduits) > 0:
                self.NbrElt = len(ListProduits)
                self.InfoTP = FrmInfosTP(self.CanvasFrmMain, ListProduits[0], self.RatioFondX, self.RatioFondY, self)
            else:
                self.NbrElt = 0
                self.InfoTP = FrmInfosTP(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
            self.FrmTP = FrmTP(self.CanvasFrmMain, ListProduits, self.RatioFondX, self.RatioFondY, self)

        elif self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 \
                or self.NAction == 4011:
            if self.FrmDoc is not None:
                self.FrmDoc.destroy()
            if self.InfoDoc is not None:
                self.InfoDoc.destroy()
            if len(ListProduits) > 0:
                self.NbrElt = len(ListProduits)
                self.InfoDoc = FrmInfosDoc(self.CanvasFrmMain, ListProduits[0], self.RatioFondX, self.RatioFondY, self)
            else:
                self.NbrElt = 0
                self.InfoDoc = FrmInfosDoc(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
            self.FrmDoc = FrmDoc(self.CanvasFrmMain, ListProduits, self.RatioFondX, self.RatioFondY, self)

        elif self.NAction == 6 or 600 < self.NAction < 700 or self.NAction == 6021 or self.NAction == 6022 \
                or self.NAction == 6011:
            if self.FrmFour is not None:
                self.FrmFour.destroy()
            if self.InfoFour is not None:
                self.InfoFour.destroy()
            if len(ListProduits) > 0:
                self.NbrElt = len(ListProduits)
                self.InfoFour = FrmInfosFour(self.CanvasFrmMain, ListProduits[0], self.RatioFondX, self.RatioFondY,
                                             self)
            else:
                self.NbrElt = 0
                self.InfoFour = FrmInfosFour(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
            self.FrmFour = FrmFour(self.CanvasFrmMain, ListProduits, self.RatioFondX, self.RatioFondY, self)

    def MAJInfo(self):
        ch = ''
        Type = ''
        Nbr = ''
        if self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 \
                or self.NAction == 1011:
            Type = ' Produit'
            Nbr = str(len(self.ListProduits))
        elif self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 \
                or self.NAction == 2011:
            Type = ' Matériel'
            Nbr = str(len(self.ListMats))
        elif self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 \
                or self.NAction == 3011:
            Type = ' TP'
            Nbr = str(len(self.ListTPs))
        elif self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 \
                or self.NAction == 4011:
            Type = ' Document'
            Nbr = str(len(self.ListDocs))
        elif self.NAction == 6 or 600 < self.NAction < 700 or self.NAction == 6021 or self.NAction == 6022 \
                or self.NAction == 6011:
            Type = ' Fournisseur'
            Nbr = str(len(self.ListFours))
        if self.NAction == 1 or self.NAction == 1021 or self.NAction == 102 or self.NAction == 2 or \
                self.NAction == 2021 or self.NAction == 202 or self.NAction == 3 or self.NAction == 3021 \
                or self.NAction == 302 or self.NAction == 4 or self.NAction == 4021 or self.NAction == 402 \
                or self.NAction == 6 or self.NAction == 6021 or self.NAction == 602:
            if int(Nbr) > 0:
                ch = 'Total: ' + Nbr + Type
                if int(Nbr) > 1 and self.NAction != 3 and self.NAction != 3021 and self.NAction != 302:
                    ch = ch + 's'
        elif self.NAction == 1011 or self.NAction == 2011 or self.NAction == 3011 or self.NAction == 4011 \
                or self.NAction == 6011:
            if len(self.ListRecherch) >= 0:
                ch = 'Total Recherche "' + self.RequeteRecherche + '": ' + str(len(self.ListRecherch)) + Type
                if len(self.ListRecherch) > 1 and self.NAction != 3011:
                    ch = ch + 's'
                self.AffichInfoAction('Recherche "' + self.RequeteRecherche + '":')
        elif self.NAction == 1022:
            if len(self.ListProdCat) >= 0:
                ch = 'Total Trie par ' + self.RequeteRecherche + ' ' + str(len(self.ListProdCat)) + Type
                if len(self.ListProdCat) > 1:
                    ch = ch + 's'
                self.AffichInfoAction(self.RequeteRecherche)
        elif self.NAction == 2022:
            if len(self.ListMatCat) >= 0:
                ch = 'Total Trie par ' + self.RequeteRecherche + ' ' + str(len(self.ListMatCat)) + Type
                if len(self.ListMatCat) > 1:
                    ch = ch + 's'
                self.AffichInfoAction(self.RequeteRecherche)
        elif self.NAction == 3022:
            if len(self.ListTPCat) >= 0:
                ch = 'Total Trie par ' + self.RequeteRecherche + ' ' + str(len(self.ListTPCat)) + Type
                if len(self.ListTPCat) > 1:
                    ch = ch + 's'
                self.AffichInfoAction(self.RequeteRecherche)
        elif self.NAction == 4022:
            if len(self.ListDocCat) >= 0:
                ch = 'Total Trie par ' + self.RequeteRecherche + ' ' + str(len(self.ListDocCat)) + Type
                if len(self.ListDocCat) > 1:
                    ch = ch + 's'
                self.AffichInfoAction(self.RequeteRecherche)
        elif self.NAction == 6022:
            if len(self.ListFourCat) >= 0:
                ch = 'Total Trie par ' + self.RequeteRecherche + ' ' + str(len(self.ListFourCat)) + Type
                if len(self.ListFourCat) > 1:
                    ch = ch + 's'
                self.AffichInfoAction(self.RequeteRecherche)

        self.LabelTotal.config(text=ch)

    def OnSelectListBox(self, evt):
        if self.NAction != 5:
            try:
                w = evt.widget
                self.IndexElt = int(w.curselection()[0])
                self.SelectProd()
            except:
                pass
        else:
            self.ListBoxProduits.selection_clear(0, tk.END)
            self.ListBoxProduits.selection_set(self.IndexElt)
            self.FrmLift()

    def SelectProd(self):
        if self.NAction == 1 or 100 < self.NAction < 200 or self.NAction == 1021 or self.NAction == 1022 \
                or self.NAction == 1011:
            if self.NAction != 102 and self.NAction != 1021:
                NEtag = CalculNEtag(self.IndexElt + 1, 15)
                self.EtagProduits.DefilProduits.set(NEtag)
                if self.InfoProd.ZoomDanger is not None:
                    self.InfoProd.ZoomDanger.destroy()
                    self.InfoProd.ZoomDanger = None
                if self.InfoProd.ZoomConseil is not None:
                    self.InfoProd.ZoomConseil.destroy()
                    self.InfoProd.ZoomConseil = None
                if self.NEtag == NEtag:
                    self.EtagProduits.SelectProd(self.IndexElt - NEtag * 15)
                else:
                    self.NEtag = NEtag
            elif self.NAction == 102:
                self.NCatselected = self.IndexElt
                self.AffichListCat(self.IndexElt)
            elif self.NAction == 1021:
                self.NSCatselected = self.IndexElt
                self.AffichListProdCat(self.IndexElt)
        elif self.NAction == 2 or 200 < self.NAction < 300 or self.NAction == 2021 or self.NAction == 2022 \
                or self.NAction == 2011:
            if self.NAction != 202 and self.NAction != 2021:
                NEtag = CalculNEtag(self.IndexElt + 1, 12)
                self.EtagMat.DefilMat.set(NEtag)
                if self.NEtag == NEtag:
                    self.EtagMat.SelectMat(self.IndexElt - NEtag * 12)
                else:
                    self.NEtag = NEtag
            elif self.NAction == 202:
                self.NCatselected = self.IndexElt
                self.AffichListCatMat(self.IndexElt)
            elif self.NAction == 2021:
                self.NSCatselected = self.IndexElt
                self.AffichListMatCat(self.IndexElt)
        elif self.NAction == 3 or 300 < self.NAction < 400 or self.NAction == 3021 or self.NAction == 3022 \
                or self.NAction == 3011:
            if self.NAction != 302 and self.NAction != 3021:
                self.FrmTP.AffichPDF(self.IndexElt)
                self.FrmTP.SelectTP(self.IndexElt)
            elif self.NAction == 302:
                self.NCatselected = self.IndexElt
                self.AffichListCatTP(self.IndexElt)
            elif self.NAction == 3021:
                self.NSCatselected = self.IndexElt
                self.AffichListTPCat(self.IndexElt)
        elif self.NAction == 4 or 400 < self.NAction < 500 or self.NAction == 4021 or self.NAction == 4022 \
                or self.NAction == 4011:
            if self.NAction != 402 and self.NAction != 4021:
                self.FrmDoc.AffichPDF(self.IndexElt)
                self.FrmDoc.SelectDoc(self.IndexElt)
            elif self.NAction == 402:
                self.NCatselected = self.IndexElt
                self.AffichListCatDoc(self.IndexElt)
            elif self.NAction == 4021:
                self.NSCatselected = self.IndexElt
                self.AffichListDocCat(self.IndexElt)
        elif self.NAction == 6 or 600 < self.NAction < 700 or self.NAction == 6021 or self.NAction == 6022 \
                or self.NAction == 6011:
            if self.NAction != 602 and self.NAction != 6021:
                self.FrmFour.AffichCaptureWeb(self.IndexElt)
                self.FrmFour.SelectFour(self.IndexElt)
            elif self.NAction == 602:
                self.NCatselected = self.IndexElt
                self.AffichListCatFour(self.IndexElt)
            elif self.NAction == 6021:
                self.NSCatselected = self.IndexElt
                self.AffichListFourCat(self.IndexElt)
        self.FrmLift()

    def Recherche(self):
        self.ListBtnActionV[0].CanvasBtn.itemconfig(self.ListBtnActionV[0].ImgCanvasBtn,
                                                    image=self.ListBtnActionV[0].ImgBtn[1])
        self.CanvasFrmMain.delete(self.LegendActionV)
        if self.NAction == 1:
            self.NAction = 101
            self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des produits chimiques - Recherche")
        elif self.NAction == 2:
            self.NAction = 201
            if self.BaseEnCours == 'CHIMIE':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion du matériel de chimie - Recherche")
            elif self.BaseEnCours == 'PHYS':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion du matériel de physique - Recherche")
        elif self.NAction == 3:
            self.NAction = 301
            if self.BaseEnCours == 'CHIMIE':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                 text="Gestion des TPs de chimie - Recherche")
            elif self.BaseEnCours == 'PHYS':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                 text="Gestion des TPs de physique - Recherche")
        elif self.NAction == 4:
            self.NAction = 401
            if self.BaseEnCours == 'CHIMIE':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                 text="Gestion des documents de chimie - Recherche")
            elif self.BaseEnCours == 'PHYS':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                 text="Gestion des documents de physique - Recherche")

        elif self.NAction == 6:
            self.NAction = 601
            if self.BaseEnCours == 'CHIMIE':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                 text="Gestion des fournisseurs de chimie - Recherche")
            elif self.BaseEnCours == 'PHYS':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG',
                                                 text="Gestion des fournisseurs de physique - Recherche")
        self.FrmFindData = FrmFindData(self.parent, self.RatioFondX, self.RatioFondY, self)

        self.CanvasBtnRetour.itemconfig(self.ImgCanvasBtnRetour, image=self.ImgBtnRetour[1])
        ChangeCursor(self.CanvasBtnRetour)

    def ActionRecherche(self):
        self.ListRecherch = []
        if self.RequeteRecherche != '':
            ch = self.RequeteRecherche
            if self.NAction == 101:
                self.cur.execute('SELECT ' + self.ListChampsTabProd +
                                 ' FROM PRODUITS WHERE NOMS LIKE \"%' + ch + '%\"or FORMULES LIKE ''\"%' + ch +
                                 '%\"or SYNO LIKE ''\"%' + ch + '%\" order by NOMS')
                self.ListRecherch = self.cur.fetchall()
                self.NAction = 1011
            elif self.NAction == 201:
                if self.BaseEnCours == 'CHIMIE':
                    self.cur.execute('SELECT ' + self.ListChampsTabMat +
                                     ' FROM MATERIEL WHERE NOMS LIKE \"%' +
                                     ch + '%\"or CATEGORIE LIKE ''\"%' + ch + '%\" order by NOMS')
                    self.ListRecherch = self.cur.fetchall()
                elif self.BaseEnCours == 'PHYS':
                    self.curphys.execute('SELECT ' + self.ListChampsTabMatPhys +
                                         ' FROM MATERIEL WHERE NOMS LIKE \"%' +
                                         ch + '%\"or Categorie LIKE ''\"%' + ch + '%\" order by NOMS')
                    self.ListRecherch = self.curphys.fetchall()
                self.NAction = 2011
            elif self.NAction == 301:
                if self.BaseEnCours == 'CHIMIE':
                    self.cur.execute('SELECT ' + self.ListChampsTabTP +
                                     ' FROM TP WHERE TITRE LIKE \"%' +
                                     ch + '%\"or CLASSE LIKE ''\"%' + ch + '%\" order by TITRE')
                    self.ListRecher = self.cur.fetchall()
                elif self.BaseEnCours == 'PHYS':
                    self.curphys.execute('SELECT ' + self.ListChampsTabTPPhys +
                                         ' FROM TP WHERE TITRE LIKE \"%' +
                                         ch + '%\"or CLASSE LIKE ''\"%' + ch + '%\" order by TITRE')
                    self.ListRecher = self.curphys.fetchall()
                self.ListRecherch = []
                for i in self.ListRecher:
                    if i not in self.ListRecherch:
                        self.ListRecherch.append(i)
                self.NAction = 3011
            elif self.NAction == 401:
                if self.BaseEnCours == 'CHIMIE':
                    self.cur.execute('SELECT ' + self.ListChampsTabDoc +
                                     ' FROM Docs WHERE TITRE LIKE \"%' +
                                     ch + '%\"or MOTSCLE LIKE ''\"%' + ch + '%\" order by TITRE')
                    self.ListRecher = self.cur.fetchall()
                elif self.BaseEnCours == 'PHYS':
                    self.curphys.execute('SELECT ' + self.ListChampsTabDoc +
                                         ' FROM Docs WHERE TITRE LIKE \"%' +
                                         ch + '%\"or MOTSCLE LIKE ''\"%' + ch + '%\" order by TITRE')
                    self.ListRecher = self.curphys.fetchall()
                self.ListRecherch = []
                for i in self.ListRecher:
                    if i not in self.ListRecherch:
                        self.ListRecherch.append(i)
                self.NAction = 4011
            elif self.NAction == 601:
                if self.BaseEnCours == 'CHIMIE':
                    self.cur.execute('SELECT ' + self.ListChampsTabFournisseurs +
                                     ' FROM Fournisseurs WHERE NOM LIKE \'%' + ch + '%\' order by NOM')
                    self.ListRecher = self.cur.fetchall()
                elif self.BaseEnCours == 'PHYS':
                    self.curphys.execute('SELECT ' + self.ListChampsTabFournisseurs +
                                         ' FROM Fournisseurs WHERE NOM LIKE \'%' + ch + '%\' order by NOM')
                    self.ListRecher = self.curphys.fetchall()
                self.ListRecherch = []
                for i in self.ListRecher:
                    if i not in self.ListRecherch:
                        self.ListRecherch.append(i)
                self.NAction = 6011

            self.CanvasFrmMain.itemconfig(self.LegendActionV, text='Recherche "' + self.RequeteRecherche + '":')
            if len(self.ListRecherch) > 0:
                self.ChargeListProduits(self.ListRecherch)
                self.AffichEtagProduits(self.ListRecherch)
            else:
                self.ChargeListProduits([])
                self.AffichEtagProduits([])
                if self.NAction == 1011:
                    self.InfoProd = FrmInfoProd(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
                elif self.NAction == 2011:
                    self.InfoMat = FrmInfoMat(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
            self.MAJInfo()
            self.FrmLift()

    def AffichListCat(self, j):
        self.ListCat = []
        Cat = ''
        if j == 1:
            self.FrmPicto = FrmPicto(self.parent, self.RatioFondX, self.RatioFondY, self)
            self.FrmPicto.lift()
        else:
            for i in range(len(self.ListProduits)):
                if j == 0:
                    Cat = self.ListProduits[i][7]
                    self.CatSelected = 'FONCTION'
                elif j == 2:
                    Cat = self.ListProduits[i][10]
                    self.CatSelected = 'SYNO'
                elif j == 3:
                    Cat = self.ListProduits[i][8]
                    self.CatSelected = 'LIEUX'
                elif j == 4:
                    Cat = self.ListProduits[i][9]
                    self.CatSelected = 'FOURNISSEUR'
                if Cat not in self.ListCat and Cat != '':
                    self.ListCat.append(Cat)
            self.ListBoxProduits.delete(0, tk.END)
            self.ListCat.sort()
            if self.CatSelected == 'FONCTION' or self.CatSelected == 'FOURNISSEUR':
                self.ListCat.append('SANS')
            for i in range(len(self.ListCat)):
                self.ListBoxProduits.insert(tk.END, self.ListCat[i])
        self.NAction = 1021
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text='Trier les produits par "' +
                                                               self.ListCatProduits[self.NCatselected] + '":')
        self.ListBoxProduits.selection_clear(0, tk.END)

    def AffichListCatMat(self, j):
        self.ListCat = []
        Cat = ''
        for i in range(len(self.ListMats)):
            if j == 0:
                Cat = self.ListMats[i][2]
                self.CatSelected = 'CATEGORIE'
            elif j == 1:
                IndexCat = 3
                self.CatSelected = 'LIEU'
                if self.BaseEnCours == 'CHIMIE':
                    for n in range(5):
                        if self.ListMats[i][IndexCat] is not None and self.ListMats[i][IndexCat] != '':
                            Cat = self.ListCatLieu[n] + " - " + self.ListMats[i][IndexCat]
                        if Cat not in self.ListCat and Cat != '':
                            self.ListCat.append(Cat)
                        IndexCat = IndexCat + 2
                elif self.BaseEnCours == 'PHYS':
                    for n in range(3):
                        if self.ListMats[i][IndexCat] is not None and self.ListMats[i][IndexCat] != '':
                            Cat = self.ListCatMatPhysLieu[n] + " - " + self.ListMats[i][IndexCat]
                        if Cat not in self.ListCat and Cat != '':
                            self.ListCat.append(Cat)
                        IndexCat = IndexCat + 2
            elif j == 2:
                if self.BaseEnCours == 'CHIMIE':
                    Cat = self.ListMats[i][15]
                elif self.BaseEnCours == 'PHYS':
                    Cat = self.ListMats[i][10]
                self.CatSelected = 'FOURNISSEUR'
            if Cat not in self.ListCat and Cat != '':
                self.ListCat.append(Cat)
        self.ListBoxProduits.delete(0, tk.END)
        self.ListCat.sort()
        if self.CatSelected != 'LIEU':
            self.ListCat.append('SANS')
        for i in range(len(self.ListCat)):
            self.ListBoxProduits.insert(tk.END, self.ListCat[i])
        self.NAction = 2021
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text='Trier le matériel par "' +
                                                               self.ListCatMats[self.NCatselected] + '":')
        self.ListBoxProduits.selection_clear(0, tk.END)

    def AffichListCatTP(self, j):
        self.ListCat = []
        if j == 1:
            self.CatSelected = 'CLASSE'
            for i in range(len(self.ListTPs)):
                Cat = self.ListTPs[i][2]
                if Cat not in self.ListCat and Cat != '':
                    self.ListCat.append(Cat)
        elif j == 2:
            self.CatSelected = 'CAT'
            for i in range(len(self.ListTPs)):
                Cat = self.ListTPs[i][3]
                if Cat not in self.ListCat and Cat != '' and Cat is not None:
                    self.ListCat.append(Cat)
        elif j == 0:
            self.CatSelected = 'ANNEE SCOLAIRE'
            if self.BaseEnCours == "CHIMIE":
                self.cur.execute("select " + self.ListChampsTabPlanningTP +
                                 " from PlanningTPChimie WHERE TYPE='TP' order by DATE")
                self.ListTPinPlanning = self.cur.fetchall()
            elif self.BaseEnCours == "PHYS":
                self.curphys.execute("select " + self.ListChampsTabPlanningTP +
                                     " from PlanningTPPhys WHERE TYPE='TP' order by DATE")
                self.ListTPinPlanning = self.curphys.fetchall()
            for i in range(len(self.ListTPinPlanning)):
                Date = self.ListTPinPlanning[i][0].split(' ')
                An = Date[-1]
                Mois = ConvertMois(Date[-2])
                if 8 < Mois <= 12:
                    AnScol = An + '/' + str(int(An) + 1)
                else:
                    AnScol = str(int(An) - 1) + '/' + An
                if AnScol not in self.ListCat:
                    self.ListCat.append(AnScol)

        self.ListBoxProduits.delete(0, tk.END)
        self.ListCat.sort()
        if self.CatSelected == 'ANNEE SCOLAIRE':
            self.ListCat.reverse()
        if self.CatSelected == 'CAT':
            self.ListCat.append('SANS')
        for i in range(len(self.ListCat)):
            self.ListBoxProduits.insert(tk.END, self.ListCat[i])
        self.NAction = 3021
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text='Trier les TPs par "' +
                                                               self.ListCatTPs[self.NCatselected] + '":')
        self.ListBoxProduits.selection_clear(0, tk.END)

    def AffichListCatDoc(self, j):
        self.ListCat = []
        if j == 0:
            self.CatSelected = 'Cat'
            for i in range(len(self.ListDocs)):
                Cat = self.ListDocs[i][4]
                if Cat not in self.ListCat and Cat != '' and Cat is not None:
                    self.ListCat.append(Cat)
        elif j == 1:
            self.CatSelected = 'MOTSCLE'
            for i in range(len(self.ListDocs)):
                if self.ListDocs[i][3] is not None:
                    Cat = self.ListDocs[i][3].split(',')
                    for j in range(len(Cat)):
                        if Cat[j] not in self.ListCat and Cat[j] != '':
                            self.ListCat.append(Cat[j])

        self.ListBoxProduits.delete(0, tk.END)
        self.ListCat.sort()
        for i in range(len(self.ListCat)):
            self.ListBoxProduits.insert(tk.END, self.ListCat[i])
        self.NAction = 4021
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text='Trier les Documents par "' +
                                                               self.ListCatDocs[self.NCatselected] + '":')
        self.ListBoxProduits.selection_clear(0, tk.END)

    def AffichListCatFour(self, j):
        self.ListCat = []
        if j == 0:
            self.CatSelected = 'Cat'
            for i in range(len(self.ListFours)):
                Cat = self.ListFours[i][13]
                if Cat not in self.ListCat and Cat != '':
                    self.ListCat.append(Cat)

        self.ListBoxProduits.delete(0, tk.END)
        self.ListCat.sort()
        for i in range(len(self.ListCat)):
            self.ListBoxProduits.insert(tk.END, self.ListCat[i])
        self.NAction = 6021
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text='Trier les fournisseurs par "' +
                                                               self.ListCatDocs[self.NCatselected] + '":')
        self.ListBoxProduits.selection_clear(0, tk.END)

    def AffichListFourCat(self, j):
        self.ListFourCa = []
        if self.CatSelected == "Cat":
            if self.BaseEnCours == 'CHIMIE':
                self.cur.execute('SELECT ' + self.ListChampsTabFournisseurs +
                                 " FROM Fournisseurs WHERE " + self.CatSelected + "='" + self.ListCat[j] +
                                 "' order by NOM")
                self.ListFourCa = self.cur.fetchall()
            elif self.BaseEnCours == 'PHYS':
                self.curphys.execute('SELECT ' + self.ListChampsTabFournisseurs +
                                     " FROM Fournisseurs WHERE " + self.CatSelected + "='" + self.ListCat[j]
                                     + "' order by NOM")
                self.ListFourCa = self.curphys.fetchall()
        self.ListFourCat = []
        for i in self.ListFourCa:
            if i not in self.ListFourCat:
                self.ListFourCat.append(i)
        self.ListFourCat.sort()
        self.NAction = 6022
        if len(self.ListFourCat) > 0:
            self.ChargeListProduits(self.ListFourCat)
            self.AffichEtagProduits(self.ListFourCat)
        self.RequeteRecherche = self.ListCatFours[self.NCatselected] + ' "' + self.ListCat[j] + '":'
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text=self.RequeteRecherche)
        self.MAJInfo()
        self.FrmLift()

    def AffichListProdCat(self, j):
        self.ListProdCat = []
        if self.ListCat[j] != 'SANS':
            self.cur.execute('SELECT ' + self.ListChampsTabProd +
                             " FROM PRODUITS WHERE " + self.CatSelected + "='" + self.ListCat[j] + "' order by NOMS")
        else:
            self.cur.execute('SELECT ' + self.ListChampsTabProd +
                             " FROM PRODUITS WHERE " + self.CatSelected + "='" + '' + "' order by NOMS")
        self.ListProdCat = self.cur.fetchall()
        self.NAction = 1022
        if len(self.ListProdCat) > 0:
            self.ChargeListProduits(self.ListProdCat)
            self.AffichEtagProduits(self.ListProdCat)
        else:
            self.ChargeListProduits([])
            self.AffichEtagProduits([])
            self.InfoProd = FrmInfoProd(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
        self.RequeteRecherche = self.ListCatProduits[self.NCatselected] + ' "' + self.ListCat[j] + '":'
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text=self.RequeteRecherche)
        self.MAJInfo()
        self.FrmLift()

    def AffichListMatCat(self, j):
        self.ListMatCat = []
        if self.CatSelected != 'LIEU':
            if self.BaseEnCours == 'CHIMIE':
                if self.ListCat[j] != 'SANS':
                    self.cur.execute('SELECT ' + self.ListChampsTabMat +
                                     " FROM MATERIEL WHERE " + self.CatSelected + "='" + self.ListCat[
                                         j] + "' order by NOMS")
                else:
                    self.cur.execute('SELECT ' + self.ListChampsTabMat +
                                     " FROM MATERIEL WHERE " + self.CatSelected + "='" + '' + "' order by NOMS")
                self.ListMatCat = self.cur.fetchall()
            elif self.BaseEnCours == 'PHYS':
                if self.ListCat[j] != 'SANS':
                    self.curphys.execute('SELECT ' + self.ListChampsTabMatPhys +
                                         " FROM MATERIEL WHERE " + self.CatSelected + "='" + self.ListCat[
                                             j] + "' order by NOMS")
                else:
                    self.curphys.execute('SELECT ' + self.ListChampsTabMatPhys +
                                         " FROM MATERIEL WHERE " + self.CatSelected + "='" + '' + "' order by NOMS")

                self.ListMatCat = self.curphys.fetchall()
        else:
            Lieu = self.ListCat[j].split('-')[1].lstrip()
            Salle = self.ListCat[j].split('-')[0].rstrip()
            if self.BaseEnCours == 'CHIMIE':
                IndexLieu = self.ListCatLieu.index(Salle)
                if IndexLieu == 0 or IndexLieu == 2:
                    for i in range(2):
                        self.cur.execute('SELECT ' + self.ListChampsTabMat + " FROM MATERIEL WHERE " +
                                         self.ListCatLieuSelected[IndexLieu + i] + "='" + Lieu + "' order by NOMS")
                        self.ListMatCat.extend(self.cur.fetchall())
                else:
                    self.cur.execute('SELECT ' + self.ListChampsTabMat + " FROM MATERIEL WHERE " +
                                     self.ListCatLieuSelected[IndexLieu] + "='" + Lieu + "' order by NOMS")
                    self.ListMatCat = self.cur.fetchall()
            elif self.BaseEnCours == 'PHYS':
                IndexLieu = self.ListCatMatPhysLieu.index(Salle)
                self.curphys.execute('SELECT ' + self.ListChampsTabMatPhys + " FROM MATERIEL WHERE " +
                                     self.ListCatMatPhysLieuSelected[IndexLieu] + "='" + Lieu + "' order by NOMS")
                self.ListMatCat = self.curphys.fetchall()

        self.NAction = 2022
        if len(self.ListMatCat) > 0:
            self.ChargeListProduits(self.ListMatCat)
            self.AffichEtagProduits(self.ListMatCat)
        else:
            self.ChargeListProduits([])
            self.AffichEtagProduits([])
            self.InfoMat = FrmInfoMat(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
        self.RequeteRecherche = self.ListCatMats[self.NCatselected] + ' "' + self.ListCat[j] + '":'
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text=self.RequeteRecherche)
        self.MAJInfo()
        self.FrmLift()

    def AffichListTPCat(self, j):
        self.ListTPCa = []
        if self.CatSelected == "CLASSE" or self.CatSelected == "CAT":
            if self.BaseEnCours == 'CHIMIE':
                if self.ListCat[j] != 'SANS':
                    self.cur.execute('SELECT ' + self.ListChampsTabTP +
                                     " FROM TP WHERE " + self.CatSelected + "='" + self.ListCat[j] + "' order by TITRE")
                    self.ListTPCa = self.cur.fetchall()
                else:
                    self.cur.execute('SELECT ' + self.ListChampsTabTP + " FROM TP")
                    ListTP = self.cur.fetchall()
                    for i in range(len(ListTP)):
                        if ListTP[i][3] == '' or ListTP[i][3] is None:
                            self.ListTPCa.append(ListTP[i])
            elif self.BaseEnCours == 'PHYS':
                if self.ListCat[j] != 'SANS':
                    self.curphys.execute('SELECT ' + self.ListChampsTabTPPhys +
                                         " FROM TP WHERE " + self.CatSelected + "='" + self.ListCat[
                                             j] + "' order by TITRE")
                    self.ListTPCa = self.curphys.fetchall()
                else:
                    self.curphys.execute('SELECT ' + self.ListChampsTabTPPhys + " FROM TP")
                    ListTP = self.curphys.fetchall()
                    for i in range(len(ListTP)):
                        if ListTP[i][3] == '' or ListTP[i][3] is None:
                            self.ListTPCa.append(ListTP[i])
        elif self.CatSelected == "ANNEE SCOLAIRE":
            for i in range(len(self.ListTPinPlanning)):
                Date = self.ListTPinPlanning[i][0].split(' ')
                An = Date[-1]
                Mois = ConvertMois(Date[-2])
                if 8 < Mois <= 12:
                    AnScol = An + '/' + str(int(An) + 1)
                else:
                    AnScol = str(int(An) - 1) + '/' + An
                if AnScol == self.ListCat[j]:
                    ListTP = ''
                    if self.BaseEnCours == 'CHIMIE':
                        self.cur.execute('SELECT ' + self.ListChampsTabTP +
                                         " FROM TP WHERE " + 'TITRE' + "=\"" + self.ListTPinPlanning[i][6] +
                                         "\" order by TITRE")
                        ListTP = self.cur.fetchall()
                    elif self.BaseEnCours == 'PHYS':
                        self.curphys.execute('SELECT ' + self.ListChampsTabTPPhys +
                                             " FROM TP WHERE " + 'TITRE' + "=\"" + self.ListTPinPlanning[i][6] +
                                             "\" order by TITRE")
                        ListTP = self.curphys.fetchall()
                    for n in ListTP:
                        if n not in self.ListTPCa:
                            self.ListTPCa.append(n)

        self.ListTPCat = []
        for i in self.ListTPCa:
            if i not in self.ListTPCat:
                self.ListTPCat.append(i)
        try:
            self.ListTPCat.sort()
        except:
            pass
        self.NAction = 3022
        if len(self.ListTPCat) > 0:
            self.ChargeListProduits(self.ListTPCat)
            self.AffichEtagProduits(self.ListTPCat)
        else:
            self.ChargeListProduits([])
            self.AffichEtagProduits([])
        self.RequeteRecherche = self.ListCatTPs[self.NCatselected] + ' "' + self.ListCat[j] + '":'
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text=self.RequeteRecherche)
        self.MAJInfo()
        self.FrmLift()

    def AffichListDocCat(self, j):
        self.ListDocCa = []
        if self.CatSelected == "Cat":
            if self.BaseEnCours == 'CHIMIE':
                self.cur.execute('SELECT ' + self.ListChampsTabDoc +
                                 " FROM Docs WHERE " + self.CatSelected + "='" + self.ListCat[j] + "' order by TITRE")
                self.ListDocCa = self.cur.fetchall()
            elif self.BaseEnCours == 'PHYS':
                self.curphys.execute('SELECT ' + self.ListChampsTabDoc +
                                     " FROM Docs WHERE " + self.CatSelected + "='" + self.ListCat[
                                         j] + "' order by TITRE")
                self.ListDocCa = self.curphys.fetchall()
        elif self.CatSelected == "MOTSCLE":
            for i in range(len(self.ListDocs)):
                if self.ListDocs[i][3] is not None:
                    if self.ListCat[j] in self.ListDocs[i][3]:
                        self.ListDocCa.append(self.ListDocs[i])

        self.ListDocCat = []
        for i in self.ListDocCa:
            if i not in self.ListDocCat:
                self.ListDocCat.append(i)
        self.ListDocCat.sort()
        self.NAction = 4022
        if len(self.ListDocCat) > 0:
            self.ChargeListProduits(self.ListDocCat)
            self.AffichEtagProduits(self.ListDocCat)
        else:
            self.ChargeListProduits([])
            self.AffichEtagProduits([])
        self.RequeteRecherche = self.ListCatDocs[self.NCatselected] + ' "' + self.ListCat[j] + '":'
        self.CanvasFrmMain.itemconfig(self.LegendActionV, text=self.RequeteRecherche)
        self.MAJInfo()
        self.FrmLift()

    def AffichInfoProd(self, n):
        if self.NAction == 1:
            if len(self.ListProduits) > 0:
                self.InfoProd = FrmInfoProd(self.CanvasFrmMain, self.ListProduits[n], self.RatioFondX, self.RatioFondY,
                                            self)
                self.NbrElt = len(self.ListProduits)
            else:
                self.InfoProd = FrmInfoProd(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY,
                                            self)
                self.NbrElt = 0
        elif self.NAction == 2:
            if len(self.ListMats) > 0:
                self.InfoMat = FrmInfoMat(self.CanvasFrmMain, self.ListMats[n], self.RatioFondX, self.RatioFondY, self)
                self.NbrElt = len(self.ListMats)
            else:
                self.InfoMat = FrmInfoMat(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
                self.NbrElt = 0

        elif self.NAction == 3:
            if len(self.ListTPs) > 0:
                self.NbrElt = len(self.ListTPs)
            else:
                self.NbrElt = 0

        elif self.NAction == 4:
            if len(self.ListDocs) > 0:
                self.NbrElt = len(self.ListDocs)
            else:
                self.NbrElt = 0

        elif self.NAction == 6:
            if len(self.ListFours) > 0:
                self.NbrElt = len(self.ListFours)
            else:
                self.NbrElt = 0

    def SupProd(self, n):
        NomProd = ''
        if self.NAction == 1:
            NomProd = self.ListProduits[n][0]
        elif self.NAction == 1011 or self.NAction == 2011 or self.NAction == 3011 or self.NAction == 4011 \
                or self.NAction == 6011:
            NomProd = self.ListRecherch[n][0]
        elif self.NAction == 1022:
            NomProd = self.ListProdCat[n][0]
        elif self.NAction == 2:
            NomProd = self.ListMats[n][0]
        elif self.NAction == 2022:
            NomProd = self.ListMatCat[n][0]
        elif self.NAction == 3:
            NomProd = self.ListTPs[n][0]
        elif self.NAction == 3022:
            NomProd = self.ListTPCat[n][0]
        elif self.NAction == 4:
            NomProd = self.ListDocs[n][0]
        elif self.NAction == 4022:
            NomProd = self.ListDocCat[n][0]
        elif self.NAction == 6:
            NomProd = self.ListFours[n][0]
        elif self.NAction == 6022:
            NomProd = self.ListFourCat[n][0]

        Legend = ''
        Champ = ''
        TextAction = ''
        if self.NAction == 1 or self.NAction == 1011 or self.NAction == 1022:
            Legend = 'Supprimer un produit chimique'
            Champ = 'PRODUITS'
            TextAction = 'Suppression - Produit chimique - '
        elif self.NAction == 2 or self.NAction == 2011 or self.NAction == 2022:
            Champ = 'MATERIEL'
            TextAction = 'Suppression - Matériel - '
            if self.BaseEnCours == "CHIMIE":
                Legend = 'Supprimer un matériel de chimie'
            elif self.BaseEnCours == "PHYS":
                Legend = 'Supprimer un matériel de physique'
        elif self.NAction == 3 or self.NAction == 3011 or self.NAction == 3022:
            Champ = 'TP'
            TextAction = 'Suppression - TP - '
            if self.BaseEnCours == "CHIMIE":
                Legend = 'Supprimer un TP de chimie'
            elif self.BaseEnCours == "PHYS":
                Legend = 'Supprimer un TP de physique'
        elif self.NAction == 4 or self.NAction == 4011 or self.NAction == 4022:
            Champ = 'Docs'
            TextAction = 'Suppression - Document - '
            if self.BaseEnCours == "CHIMIE":
                Legend = 'Supprimer un document de chimie'
            elif self.BaseEnCours == "PHYS":
                Legend = 'Supprimer un document de physique'
        elif self.NAction == 6 or self.NAction == 6011 or self.NAction == 6022:
            Champ = 'Fournisseurs'
            TextAction = 'Suppression - Fournisseur - '
            if self.BaseEnCours == "CHIMIE":
                Legend = 'Supprimer un fournisseur de chimie'
            elif self.BaseEnCours == "PHYS":
                Legend = 'Supprimer un fournisseur de physique'

        Rep = tkMB.askyesno(Legend, 'Etes vous sûr de vouloir supprimer "' +
                            NomProd + '" de la base de données ?', parent=self)
        if self.NAction != 3 and self.NAction != 3011 and self.NAction != 3022 and \
                self.NAction != 4 and self.NAction != 4011 and self.NAction != 4022 and \
                self.NAction != 6 and self.NAction != 6011 and self.NAction != 6022:
            SQLRequet = "DELETE FROM " + Champ + " WHERE " + 'NOMS="' + NomProd + '"'
        elif self.NAction == 6 or self.NAction == 6011 or self.NAction == 6022:
            SQLRequet = "DELETE FROM " + Champ + " WHERE " + 'NOM="' + NomProd + '"'
        else:
            SQLRequet = "DELETE FROM " + Champ + " WHERE " + 'TITRE="' + NomProd + '"'
        if Rep:
            path1 = ''
            path2 = ''
            path3 = ''
            path4 = ''
            path5 = ''
            path6 = ''
            path7 = 'Datas/Fournisseurs/Logos/'
            path8 = 'Datas/Fournisseurs/Captures/'
            ind = 0
            if self.BaseEnCours == "CHIMIE":
                self.cur.execute(SQLRequet)
                self.DataBaseChimie.commit()
                self.SaveListModifDTB('Chimie', TextAction + NomProd)
                path1 = 'Datas/VisuelMatChim/'
                path2 = 'Datas/NoticeChim/'
                path3 = 'Datas/DescriptMatChim/'
                path4 = 'Datas/PDFTPChim/'
                path5 = 'Datas/DocsPDFChim/'
                path6 = 'Datas/DescriptDocChim/'
                ind = 27
            elif self.BaseEnCours == "PHYS":
                self.curphys.execute(SQLRequet)
                self.DataBasePhys.commit()
                self.SaveListModifDTB('Physique', TextAction + NomProd)
                path1 = 'Datas/VisuelMatPhys/'
                path2 = 'Datas/NoticePhys/'
                path3 = 'Datas/DescriptMatPhys/'
                path4 = 'Datas/PDFTPPhys/'
                path5 = 'Datas/DocsPDFPhys/'
                path6 = 'Datas/DescriptDocPhys/'
                ind = 22

            if self.NAction == 1:
                if self.ListProduits[n][2] is not None and self.ListProduits[n][2] != '' and \
                        os.path.exists('Datas/FormDev/' + self.ListProduits[n][2]):
                    os.remove('Datas/FormDev/' + self.ListProduits[n][2])
                if self.ListProduits[n][17] is not None and self.ListProduits[n][17] != '' and \
                        os.path.exists('Datas/FDS/' + self.ListProduits[n][17] + '.pdf'):
                    os.remove('Datas/FDS/' + self.ListProduits[n][17] + '.pdf')
            elif self.NAction == 1011:
                if self.ListRecherch[n][2] is not None and self.ListRecherch[n][2] != '' and \
                        os.path.exists('Datas/FormDev/' + self.ListRecherch[n][2]):
                    os.remove('Datas/FormDev/' + self.ListRecherch[n][2])
                if self.ListRecherch[n][17] is not None and self.ListRecherch[n][17] != '' and \
                        os.path.exists('Datas/FDS/' + self.ListRecherch[n][17] + '.pdf'):
                    os.remove('Datas/FDS/' + self.ListRecherch[n][17] + '.pdf')
            elif self.NAction == 1022:
                if self.ListProdCat[n][2] is not None and self.ListProdCat[n][2] != '' and \
                        os.path.exists('Datas/FormDev/' + self.ListProdCat[n][2]):
                    os.remove('Datas/FormDev/' + self.ListProdCat[n][2])
                if self.ListProdCat[n][17] is not None and self.ListProdCat[n][17] != '' and \
                        os.path.exists('Datas/FDS/' + self.ListProdCat[n][17] + '.pdf'):
                    os.remove('Datas/FDS/' + self.ListProdCat[n][17] + '.pdf')
            elif self.NAction == 2:
                if self.ListMats[n][1] is not None and self.ListMats[n][1] != '' and \
                        os.path.exists(path1 + self.ListMats[n][1]):
                    os.remove(path1 + self.ListMats[n][1])
                if self.ListMats[n][ind] is not None and self.ListMats[n][ind] != '' and \
                        os.path.exists(path2 + self.ListMats[n][ind] + '.pdf'):
                    os.remove(path2 + self.ListMats[n][ind] + '.pdf')
                if self.ListMats[n][ind + 1] is not None and self.ListMats[n][ind + 1] != '' and \
                        os.path.exists(path3 + self.ListMats[n][ind + 1] + '.txt'):
                    os.remove(path3 + self.ListMats[n][ind + 1] + '.txt')
            elif self.NAction == 2011:
                if self.ListRecherch[n][1] is not None and self.ListRecherch[n][1] != '' and \
                        os.path.exists(path1 + self.ListRecherch[n][1]):
                    os.remove(path1 + self.ListRecherch[n][1])
                if self.ListRecherch[n][ind] is not None and self.ListRecherch[n][ind] != '' and \
                        os.path.exists(path2 + self.ListRecherch[n][ind] + '.pdf'):
                    os.remove(path2 + self.ListRecherch[n][ind] + '.pdf')
                if self.ListRecherch[n][ind + 1] is not None and self.ListRecherch[n][ind + 1] != '' and \
                        os.path.exists(path3 + self.ListRecherch[n][ind + 1] + '.txt'):
                    os.remove(path3 + self.ListRecherch[n][ind + 1] + '.txt')
            elif self.NAction == 2022:
                if self.ListMatCat[n][1] is not None and self.ListMatCat[n][1] != '' and \
                        os.path.exists(path1 + self.ListMatCat[n][1]):
                    os.remove(path1 + self.ListMatCat[n][1])
                if self.ListMatCat[n][ind] is not None and self.ListMatCat[n][ind] != '' and \
                        os.path.exists(path2 + self.ListMatCat[n][ind] + '.pdf'):
                    os.remove(path2 + self.ListMatCat[n][ind] + '.pdf')
                if self.ListMatCat[n][ind + 1] is not None and self.ListMatCat[n][ind + 1] != '' and \
                        os.path.exists(path3 + self.ListMatCat[n][ind + 1] + '.txt'):
                    os.remove(path3 + self.ListMatCat[n][ind + 1] + '.txt')
            elif self.NAction == 3:
                if self.ListTPs[n][1] is not None and self.ListTPs[n][1] != '' and \
                        os.path.exists(path4 + self.ListTPs[n][1] + '.pdf'):
                    os.remove(path4 + self.ListTPs[n][1] + '.pdf')
            elif self.NAction == 3011:
                if self.ListRecherch[n][1] is not None and self.ListRecherch[n][1] != '' and \
                        os.path.exists(path4 + self.ListRecherch[n][1] + '.pdf'):
                    os.remove(path4 + self.ListRecherch[n][1] + '.pdf')
            elif self.NAction == 3022:
                if self.ListTPCat[n][1] is not None and self.ListTPCat[n][1] != '' and \
                        os.path.exists(path4 + self.ListTPCat[n][1] + '.pdf'):
                    os.remove(path4 + self.ListTPCat[n][1] + '.pdf')
            elif self.NAction == 4:
                if self.ListDocs[n][1] is not None and self.ListDocs[n][1] != '' and \
                        os.path.exists(path5 + self.ListDocs[n][1] + '.pdf'):
                    os.remove(path5 + self.ListDocs[n][1] + '.pdf')
                if self.ListDocs[n][2] is not None and self.ListDocs[n][2] != '' and \
                        os.path.exists(path6 + self.ListDocs[n][2] + '.txt'):
                    os.remove(path6 + self.ListDocs[n][2] + '.txt')
            elif self.NAction == 4011:
                if self.ListRecherch[n][1] is not None and self.ListRecherch[n][1] != '' and \
                        os.path.exists(path5 + self.ListRecherch[n][1] + '.pdf'):
                    os.remove(path5 + self.ListRecherch[n][1] + '.pdf')
                if self.ListRecherch[n][2] is not None and self.ListRecherch[n][2] != '' and \
                        os.path.exists(path6 + self.ListRecherch[n][2] + '.txt'):
                    os.remove(path6 + self.ListRecherch[n][2] + '.txt')
            elif self.NAction == 4022:
                if self.ListDocCat[n][1] is not None and self.ListDocCat[n][1] != '' and \
                        os.path.exists(path5 + self.ListDocCat[n][1] + '.pdf'):
                    os.remove(path5 + self.ListDocCat[n][1] + '.pdf')
                if self.ListDocCat[n][2] is not None and self.ListDocCat[n][2] != '' and \
                        os.path.exists(path6 + self.ListDocCat[n][2] + '.txt'):
                    os.remove(path6 + self.ListDocCat[n][2] + '.txt')
            elif self.NAction == 6:
                if self.ListFours[n][7] is not None and self.ListFours[n][7] != '' and \
                        os.path.exists(path7 + self.ListFours[n][0]):
                    os.remove(path7 + self.ListFours[n][0])
                if self.ListFours[n][9] is not None and self.ListFours[n][9] != '' and \
                        os.path.exists(path8 + self.ListFours[n][0]):
                    os.remove(path8 + self.ListFours[n][0])
            elif self.NAction == 6011:
                if self.ListRecherch[n][7] is not None and self.ListRecherch[n][7] != '' and \
                        os.path.exists(path7 + self.ListRecherch[n][0]):
                    os.remove(path7 + self.ListRecherch[n][0])
                if self.ListRecherch[n][9] is not None and self.ListRecherch[n][9] != '' and \
                        os.path.exists(path8 + self.ListRecherch[n][0]):
                    os.remove(path8 + self.ListRecherch[n][0])
            elif self.NAction == 6022:
                if self.ListFourCat[n][7] is not None and self.ListFourCat[n][7] != '' and \
                        os.path.exists(path7 + self.ListFourCat[n][0]):
                    os.remove(path7 + self.ListFourCat[n][0])
                if self.ListFourCat[n][9] is not None and self.ListFourCat[n][9] != '' and \
                        os.path.exists(path8 + self.ListFourCat[n][0]):
                    os.remove(path8 + self.ListFourCat[n][0])

            if self.NAction == 1 or self.NAction == 1011 or self.NAction == 1022:
                self.cur.execute("select " + self.ListChampsTabProd + " from PRODUITS order by NOMS")
                self.ListProduits = self.cur.fetchall()
            elif self.NAction == 2 or self.NAction == 2011 or self.NAction == 2022:
                if self.BaseEnCours == "CHIMIE":
                    self.cur.execute("select " + self.ListChampsTabMat + " from MATERIEL order by NOMS")
                    self.ListMats = self.cur.fetchall()
                elif self.BaseEnCours == "PHYS":
                    self.curphys.execute("select " + self.ListChampsTabMatPhys + " from MATERIEL order by NOMS")
                    self.ListMats = self.curphys.fetchall()
            elif self.NAction == 3 or self.NAction == 3011 or self.NAction == 3022:
                if self.BaseEnCours == "CHIMIE":
                    self.cur.execute("select " + self.ListChampsTabTP + " from TP order by TITRE")
                    self.ListTP = self.cur.fetchall()
                elif self.BaseEnCours == "PHYS":
                    self.curphys.execute("select " + self.ListChampsTabTPPhys + " from TP order by TITRE")
                    self.ListTP = self.curphys.fetchall()
                self.ListTPs = []
                for i in self.ListTP:
                    if i not in self.ListTPs:
                        self.ListTPs.append(i)
            elif self.NAction == 4 or self.NAction == 4011 or self.NAction == 4022:
                if self.BaseEnCours == "CHIMIE":
                    self.cur.execute("select " + self.ListChampsTabDoc + " from Docs order by TITRE")
                    self.ListDocs = self.cur.fetchall()
                elif self.BaseEnCours == "PHYS":
                    self.curphys.execute("select " + self.ListChampsTabDoc + " from Docs order by TITRE")
                    self.ListDocs = self.curphys.fetchall()
            elif self.NAction == 6 or self.NAction == 6011 or self.NAction == 6022:
                if self.BaseEnCours == "CHIMIE":
                    self.cur.execute("select " + self.ListChampsTabFournisseurs + " from Fournisseurs order by NOM")
                    self.ListFours = self.cur.fetchall()
                elif self.BaseEnCours == "PHYS":
                    self.curphys.execute("select " + self.ListChampsTabFournisseurs + " from Fournisseurs order by NOM")
                    self.ListFours = self.curphys.fetchall()

            if self.NAction == 1:
                self.ChargeListProduits(self.ListProduits)
                self.AffichEtagProduits(self.ListProduits)
                self.CanvasFrmMain.delete(self.LegendActionV)
            elif self.NAction == 1011:
                self.NAction = 101
                self.ActionRecherche()
                if len(self.ListRecherch) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.InfoProd = FrmInfoProd(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
                    self.MAJInfo()
            elif self.NAction == 1022:
                self.AffichListProdCat(self.NSCatselected)
                if len(self.ListProdCat) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.InfoProd = FrmInfoProd(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
                    self.MAJInfo()

            elif self.NAction == 2:
                self.ChargeListProduits(self.ListMats)
                self.AffichEtagProduits(self.ListMats)
                self.CanvasFrmMain.delete(self.LegendActionV)
            elif self.NAction == 2011:
                self.NAction = 201
                self.ActionRecherche()
                if len(self.ListRecherch) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.InfoMat = FrmInfoMat(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
                    self.MAJInfo()
            elif self.NAction == 2022:
                self.AffichListMatCat(self.NSCatselected)
                if len(self.ListMatCat) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.InfoMat = FrmInfoMat(self.CanvasFrmMain, [], self.RatioFondX, self.RatioFondY, self)
                    self.MAJInfo()

            elif self.NAction == 3:
                self.ChargeListProduits(self.ListTPs)
                self.AffichEtagProduits(self.ListTPs)
                self.CanvasFrmMain.delete(self.LegendActionV)
            elif self.NAction == 3011:
                self.NAction = 301
                self.ActionRecherche()
                if len(self.ListRecherch) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.MAJInfo()
            elif self.NAction == 3022:
                self.AffichListTPCat(self.NSCatselected)
                if len(self.ListTPCat) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.MAJInfo()

            elif self.NAction == 4:
                self.ChargeListProduits(self.ListDocs)
                self.AffichEtagProduits(self.ListDocs)
                self.CanvasFrmMain.delete(self.LegendActionV)
            elif self.NAction == 4011:
                self.NAction = 401
                self.ActionRecherche()
                if len(self.ListRecherch) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.MAJInfo()
            elif self.NAction == 4022:
                self.AffichListDocCat(self.NSCatselected)
                if len(self.ListDocCat) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.MAJInfo()

            elif self.NAction == 6:
                self.ChargeListProduits(self.ListFours)
                self.AffichEtagProduits(self.ListFours)
                self.CanvasFrmMain.delete(self.LegendActionV)
            elif self.NAction == 6011:
                self.NAction = 601
                self.ActionRecherche()
                if len(self.ListRecherch) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.MAJInfo()
            elif self.NAction == 6022:
                self.AffichListFourCat(self.NSCatselected)
                if len(self.ListFourCat) == 0:
                    self.ListBoxProduits.delete(0, tk.END)
                    self.AffichEtagProduits([])
                    self.MAJInfo()

    def RetourListeProduits(self):
        if self.NAction == 102 or self.NAction == 101 or self.NAction == 1011:
            self.NAction = 1
            self.ChargeListProduits(self.ListProduits)
            self.EtagProduits.destroy()
            self.AffichEtagProduits(self.ListProduits)
            self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des produits chimiques")
        elif self.NAction == 202 or self.NAction == 201 or self.NAction == 2011:
            self.NAction = 2
            self.ChargeListProduits(self.ListMats)
            self.EtagMat.destroy()
            self.AffichEtagProduits(self.ListMats)
            if self.BaseEnCours == 'CHIMIE':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion du matériel de chimie")
            elif self.BaseEnCours == 'PHYS':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion du matériel de physique")
        elif self.NAction == 302 or self.NAction == 301 or self.NAction == 3011:
            self.NAction = 3
            self.ChargeListProduits(self.ListTPs)
            self.FrmTP.destroy()
            self.AffichEtagProduits(self.ListTPs)
            if self.BaseEnCours == 'CHIMIE':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des travaux pratiques de chimie")
            elif self.BaseEnCours == 'PHYS':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des travaux pratiques de physique")
        elif self.NAction == 402 or self.NAction == 401 or self.NAction == 4011:
            self.NAction = 4
            self.ChargeListProduits(self.ListDocs)
            self.FrmDoc.destroy()
            self.AffichEtagProduits(self.ListDocs)
            if self.BaseEnCours == 'CHIMIE':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion de la documentation de chimie")
            elif self.BaseEnCours == 'PHYS':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion de la documentation de physique")
        elif self.NAction == 602 or self.NAction == 601 or self.NAction == 6011:
            self.NAction = 6
            self.ChargeListProduits(self.ListFours)
            self.FrmFour.destroy()
            self.AffichEtagProduits(self.ListFours)
            if self.BaseEnCours == 'CHIMIE':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des fournisseurs de chimie")
            elif self.BaseEnCours == 'PHYS':
                self.CanvasFrmMain.itemconfigure('LegendePanneauG', text="Gestion des fournisseurs de physique")
        self.CanvasFrmMain.delete(self.LegendActionV)
        self.OldNAction = 0

    def AffichInfoAction(self, text):
        if self.InfoActionV:
            self.CanvasFrmMain.delete(self.LegendActionV)
            self.InfoActionV = False
        self.LegendActionV = self.CanvasFrmMain.create_text(int(self.SX * 0.03),
                                                            int(self.SY * 0.128), anchor=tk.W,
                                                            text=text, fill='black',
                                                            font=AppliFont('Helvetica', self.SizeFont, 'bold',
                                                                           0))
        self.InfoActionV = True

    def ActionRetour(self, _):
        if self.ButtonClic >= 0:
            self.CanvasBtnRetour.itemconfig(self.ImgCanvasBtnRetour, image=self.ImgBtnRetour[1])
            self.ActionV(self.ButtonClic)

    def ActionBtnRetourPress(self, _):
        if self.ButtonClic >= 0:
            self.CanvasBtnRetour.itemconfig(self.ImgCanvasBtnRetour, image=self.ImgBtnRetour[2])
        else:
            self.FrmLift()

    def CacheMenuV(self):
        for i in range(5, 9):
            self.ListBtnActionV[i].CanvasBtn.itemconfig(self.ListBtnActionV[i].ImgCanvasBtn,
                                                        image=self.ListBtnActionV[i].ImgBtn[
                                                            len(self.ListBtnActionV[i].ImgBtn) - 1])
            self.ListInfoActionV[i] = ''
            ChangeCursor2(self.ListBtnActionV[i].CanvasBtn)
            self.ListBtnActionV[i].CanvasBtn.bind(
                '<ButtonPress-1>', lambda action: self.ListBtnActionV[i].CanvasBtn.itemconfig(
                    self.ListBtnActionV[i].ImgCanvasBtn, image=self.ListBtnActionV[i].ImgBtn[len(
                        self.ListBtnActionV[i].ImgBtn) - 1]))

    def FrmLift(self):
        self.parent.lift()
        self.lift()
        if self.NAction == 1 or self.NAction == 101 or self.NAction == 102 or self.NAction == 1021 or \
                self.NAction == 1022 or self.NAction == 1011:
            self.EtagProduits.lift()
            self.InfoProd.lift()
            if self.InfoProd.FDSZoom is not None and self.InfoProd.ZoomActif:
                self.InfoProd.FDSZoom.lift()
            if self.InfoProd.ZoomDanger is not None and self.InfoProd.ZoomActif:
                self.InfoProd.ZoomDanger.lift()
            if self.InfoProd.ZoomConseil is not None and self.InfoProd.ZoomActif:
                self.InfoProd.ZoomConseil.lift()
            if self.NAction == 101:
                self.FrmFindData.lift()
        elif self.NAction == 2 or self.NAction == 201 or self.NAction == 202 or self.NAction == 2021 or \
                self.NAction == 2022 or self.NAction == 2011:
            self.EtagMat.lift()
            self.InfoMat.lift()
            if self.InfoMat.PDFZoom is not None and self.InfoMat.ZoomActif:
                self.InfoMat.PDFZoom.lift()
            if self.NAction == 201:
                self.FrmFindData.lift()
        elif self.NAction == 3 or self.NAction == 301 or self.NAction == 302 or self.NAction == 3021 or \
                self.NAction == 3022 or self.NAction == 3011:
            self.FrmTP.lift()
            if self.FrmTP.DocZoom is not None and self.FrmTP.ZoomActif:
                self.FrmTP.DocZoom.lift()
            if self.InfoTP is not None:
                self.InfoTP.lift()
                if self.InfoTP.TabZoom is not None and self.InfoTP.ZoomActif:
                    self.InfoTP.TabZoom.lift()
            if self.NAction == 301:
                self.FrmFindData.lift()
        elif self.NAction == 4 or self.NAction == 401 or self.NAction == 402 or self.NAction == 4021 or \
                self.NAction == 4022 or self.NAction == 4011:
            self.FrmDoc.lift()
            if self.FrmDoc.DocZoom is not None and self.FrmDoc.ZoomActif:
                self.FrmDoc.DocZoom.lift()
            if self.InfoDoc is not None:
                self.InfoDoc.lift()
            if self.NAction == 401:
                self.FrmFindData.lift()
        elif self.NAction == 6 or self.NAction == 601 or self.NAction == 602 or self.NAction == 6021 or \
                self.NAction == 6022 or self.NAction == 6011:
            if self.FrmFour is not None:
                self.FrmFour.lift()
                if self.InfoFour is not None:
                    self.InfoFour.lift()
        elif self.NAction == 5:
            if self.OldNAction == 1:
                self.EtagProduits.lift()
                self.InfoProd.lift()
                if self.InfoProd.FDSZoom is not None and self.InfoProd.ZoomActif:
                    self.InfoProd.FDSZoom.lift()
                if self.InfoProd.ZoomDanger is not None and self.InfoProd.ZoomActif:
                    self.InfoProd.ZoomDanger.lift()
                if self.InfoProd.ZoomConseil is not None and self.InfoProd.ZoomActif:
                    self.InfoProd.ZoomConseil.lift()
            elif self.OldNAction == 2:
                self.EtagMat.lift()
                self.InfoMat.lift()
                if self.InfoMat.PDFZoom is not None and self.InfoMat.ZoomActif:
                    self.InfoMat.PDFZoom.lift()
            elif self.OldNAction == 3:
                self.FrmTP.lift()
                if self.FrmTP.DocZoom is not None and self.FrmTP.ZoomActif:
                    self.FrmTP.DocZoom.lift()
                if self.InfoTP is not None:
                    self.InfoTP.lift()
                    if self.InfoTP.TabZoom is not None and self.InfoTP.ZoomActif:
                        self.InfoTP.TabZoom.lift()
            elif self.OldNAction == 4:
                self.FrmDoc.lift()
                if self.FrmDoc.DocZoom is not None and self.FrmDoc.ZoomActif:
                    self.FrmDoc.DocZoom.lift()
                if self.InfoDoc is not None:
                    self.InfoDoc.lift()
            self.FrmParam.lift()
        elif self.NAction == 103:
            self.FrmAjoutProd.lift()
            if self.FrmAjoutProd.FrmModifFour is not None:
                self.FrmAjoutProd.FrmModifFour.lift()
        elif self.NAction == 104:
            self.FrmModifProd.lift()
            if self.FrmModifProd.FrmModifFour is not None:
                self.FrmModifProd.FrmModifFour.lift()
        elif self.NAction == 105:
            self.FrmTabRecapProd.lift()
        elif self.NAction == 106:
            self.FrmConsomProd.lift()
            if self.FrmConsomProd.FrmAjoutConsomProd is not None:
                self.FrmConsomProd.FrmAjoutConsomProd.lift()
        elif self.NAction == 107:
            self.FrmAjoutProdRecy.lift()
            if self.FrmAjoutProdRecy.FrmAjoutConsomProd is not None:
                self.FrmAjoutProdRecy.FrmAjoutConsomProd.lift()
        elif self.NAction == 108:
            self.FrmCommandProd.lift()
            if self.FrmCommandProd.FrmAjoutProdACom is not None:
                self.FrmCommandProd.FrmAjoutProdACom.lift()
        elif self.NAction == 203:
            self.FrmAjoutMat.lift()
        elif self.NAction == 204:
            self.FrmModifMat.lift()
        elif self.NAction == 205:
            self.FrmTabRecapMat.lift()
        elif self.NAction == 206:
            self.FrmMatHS.lift()
            if self.FrmMatHS.FrmAjoutMatHS is not None:
                self.FrmMatHS.FrmAjoutMatHS.lift()
        elif self.NAction == 207:
            self.FrmCommandMat.lift()
            if self.FrmCommandMat.FrmAjoutMatACom is not None:
                self.FrmCommandMat.FrmAjoutMatACom.lift()
        elif self.NAction == 303:
            self.FrmAjoutTP.lift()
        elif self.NAction == 304:
            if self.BaseEnCours == "CHIMIE":
                self.FrmModifTP.lift()
                if self.FrmModifTP.FrmVisuPDF is not None:
                    self.FrmModifTP.FrmVisuPDF.lift()
            elif self.BaseEnCours == "PHYS":
                self.FrmModifTPPhys.lift()
        elif self.NAction == 3051:
            self.FrmPrepaMat.lift()
        elif self.NAction == 3052:
            self.FrmPrepaProd.lift()
            if self.FrmPrepaProd.FrmImprimEtiqProd is not None:
                self.FrmPrepaProd.FrmImprimEtiqProd.lift()
            if self.FrmPrepaProd.TabRecap is not None:
                self.FrmPrepaProd.TabRecap.lift()
        elif self.NAction == 3053:
            self.FrmPrepaSol.lift()
            if self.FrmPrepaSol.FrmImprimEtiqSol is not None:
                self.FrmPrepaSol.FrmImprimEtiqSol.lift()
            if self.FrmPrepaSol.TabRecap is not None:
                self.FrmPrepaSol.TabRecap.lift()
        elif self.NAction == 306:
            self.FrmPlanningTP.lift()
            self.FrmPlanningTP.FrmAgenda.lift()
        elif self.NAction == 403:
            self.FrmAjoutDoc.lift()
        elif self.NAction == 404:
            self.FrmModifDoc.lift()
        elif self.NAction == 603:
            self.FrmAjoutFour.lift()
        elif self.NAction == 604:
            self.FrmModifFour.lift()
        elif self.NAction == 0:
            if self.FrmAccueil is not None:
                self.FrmAccueil.lift()

    def CalculAnScol(self):
        Date = datetime.now()
        Mois = Date.date().month
        if 8 < Mois <= 12:
            self.AnScol = str(Date.date().year) + '/' + str(Date.date().year + 1)
        else:
            self.AnScol = str(Date.date().year - 1) + '/' + str(Date.date().year)

    def SaveDTB(self, DTB, Type):
        Date = datetime.now()
        FileSaveName = ModifString(DTB.split('/')[-1].split('.')[0] + str(Date)) + '.sq3'
        shutil.copy(DTB, self.AutoSavePath + '/' + FileSaveName)
        data = [(str(Date.date().day) + '-' + str(Date.date().month) + '-' + str(Date.date().year),
                 str(Date.strftime("%H:%M:%S")), self.AutoSavePath + '/' + FileSaveName, Type)]
        self.curSave.execute("INSERT INTO Saves(" + "Date , Heure, File, Type" + ") VALUES(?,?,?,?)", data[0])
        self.DataBaseSave.commit()

        self.curSave.execute("select " + "File" + " from Saves WHERE Type = \"" + Type + "\"")
        ListSaves = self.curSave.fetchall()
        if len(ListSaves) > self.MaxSaves:
            for i in range(len(ListSaves) - self.MaxSaves):
                SQLRequet = "DELETE FROM Saves WHERE File='" + ListSaves[i][0] + "'"
                self.curSave.execute(SQLRequet)
                if os.path.exists(ListSaves[i][0]):
                    os.remove(ListSaves[i][0])
            self.DataBaseSave.commit()

        self.curSave.execute("select " + "Date , Heure" + " from Saves WHERE Type = \"" + Type + "\"")
        ListSaves = self.curSave.fetchall()
        if len(ListSaves) > 0:
            self.curSave.execute("select " + "Date" + " from Modif WHERE TypeDTB = \"" + Type + "\"order by Date")
            ListModif = self.curSave.fetchall()
            ListModifSup = []
            for j in range(len(ListModif)):
                if (datetime.strptime(ListSaves[0][0] + ' ' + ListSaves[0][1], '%d-%m-%Y %H:%M:%S') >
                        datetime.strptime(ListModif[j][0].split('.')[0], '%Y-%m-%d %H:%M:%S')):
                    ListModifSup.append(ListModif[j][0])
            for n in range(len(ListModifSup) - 2):
                self.curSave.execute("DELETE FROM Modif WHERE date='" + ListModifSup[n] + "' AND TypeDTB = \"" +
                                     Type + "\"")
            self.DataBaseSave.commit()

    def SaveListModifDTB(self, TypeDTB, Action):
        data = [(str(datetime.now()), TypeDTB, Action)]
        self.curSave.execute("INSERT INTO Modif(" + "Date , TypeDTB, Action" + ") VALUES(?,?,?)", data[0])
        self.DataBaseSave.commit()

    def CloseDTB(self):
        self.cur.close()
        self.DataBaseChimie.close()
        self.curphys.close()
        self.DataBasePhys.close()

    def quitter(self, _):
        self.CloseDTB()
        self.curSave.close()
        self.DataBaseSave.close()
        self.parent.destroy()
        sys.exit()


if __name__ == '__main__':
    FrmMain = FrmMainApp("")
    Appli = MainAppli(FrmMain)
    FrmMain.mainloop()
