refonte
This commit is contained in:
@ -6,40 +6,52 @@ from src.m.connexionBDD import connexionBDD
|
||||
__author__ = 'sidya'
|
||||
|
||||
class Client:
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM client WHERE idClient='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
return Client(id, row["nom"],row["prenom"],row["adresse"], bool(row["typeAbonnement"]))
|
||||
|
||||
|
||||
def __init__(self,id, nom, prenom, adresse, typeAbonnement):
|
||||
self.__nom = nom
|
||||
self.__prenom = prenom
|
||||
self.__typeAbonnement = typeAbonnement
|
||||
self.__adresse = adresse
|
||||
|
||||
if id is None:
|
||||
self.__nom = nom
|
||||
self.__prenom = prenom
|
||||
self.__typeAbonnement = typeAbonnement
|
||||
self.__adresse = adresse
|
||||
while True:
|
||||
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
|
||||
range(random.randint(1, 10)))
|
||||
try :
|
||||
Client.get(id)
|
||||
Client(id)
|
||||
except IndexError :
|
||||
break
|
||||
|
||||
self.__id = id
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO client (idClient, nom, prenom, adresse, typeAbonnement) VALUES (?,?,?,?,?)",
|
||||
(str(self.__id), str(self.__nom), str(self.__prenom), "", str(self.__typeAbonnement)))
|
||||
self.__id = id
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM client WHERE idClient='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__id = id
|
||||
self.__nom = row["nom"]
|
||||
self.__prenom = row["prenom"]
|
||||
self.__typeAbonnement = row["typeAbonnement"]
|
||||
self.__adresse = row["adresse"]
|
||||
|
||||
def maj(self, nom, prenom, adresse, typeAbonnement):
|
||||
self.__nom = nom
|
||||
self.__prenom = prenom
|
||||
self.__typeAbonnement = typeAbonnement
|
||||
self.__adresse = adresse
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE client SET nom = ?, prenom = ?, adresse = ?, typeAbonnement = ? WHERE idClient = ?",
|
||||
(str(self.__nom), str(self.__prenom), "", str(self.__typeAbonnement), str(self.__id)))
|
||||
c.seDeconnecter()
|
||||
|
||||
def desabo(self):
|
||||
c = connexionBDD()
|
||||
c.execute("DELETE FROM client WHERE idClient ='"+str(id)+"'")
|
||||
c.seDeconnecter()
|
||||
|
||||
|
||||
@property
|
||||
def prenom(self):
|
||||
@ -54,7 +66,7 @@ class Client:
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def adr(self):
|
||||
def adr(self,nom, prenom, adresse, typeAbonnement):
|
||||
return self.__adresse
|
||||
|
||||
@property
|
||||
|
246
src/m/Parking.py
246
src/m/Parking.py
@ -1,6 +1,6 @@
|
||||
import random
|
||||
import string
|
||||
import datetime
|
||||
import time
|
||||
from src.m.Voiture import Voiture
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
@ -10,30 +10,51 @@ __author__ = 'sidya'
|
||||
|
||||
class Parking:
|
||||
parkings = []
|
||||
|
||||
@staticmethod
|
||||
def get(id):
|
||||
if len(Parking.parkings) == 0 :
|
||||
Parking.getAllActif()
|
||||
for p in Parking.parkings :
|
||||
if p.id == id :
|
||||
return p
|
||||
|
||||
@staticmethod
|
||||
def getAll():
|
||||
def getAllActif():
|
||||
if len(Parking.parkings) == 0 :
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM parking WHERE actif = 1")
|
||||
rows = r.fetchall()
|
||||
c.seDeconnecter()
|
||||
for row in rows :
|
||||
Parking(row["idParking"], row["nom"], None)
|
||||
return Parking.parkings
|
||||
|
||||
|
||||
def __init__(self, nom, listeTypePlace):
|
||||
self.__nom = nom
|
||||
@staticmethod
|
||||
def remove(parking):
|
||||
Parking.parkings.remove(parking)
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO parking (nom) VALUES ('"+str(self.__nom)+"')", ())
|
||||
self.__id = c.lastId()
|
||||
c.execute("UPDATE parking SET actif = 0 WHERE idParking='"+str(parking.id)+"'")
|
||||
c.seDeconnecter()
|
||||
|
||||
#Crea des places
|
||||
n = 0
|
||||
for typePlace in listeTypePlace :
|
||||
for i in range(typePlace.nombre) :
|
||||
print(Place(None,self,typePlace,1,n,True,False))
|
||||
n += 1
|
||||
@staticmethod
|
||||
def removeAllRam():
|
||||
Parking.parkings = []
|
||||
|
||||
|
||||
def __init__(self, id, nom=None, listeTypePlace=None):
|
||||
self.__nom = nom
|
||||
if id is None :
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO parking (nom) VALUES ('"+str(self.__nom)+"')", ())
|
||||
self.__id = c.lastId()
|
||||
#Crea des places
|
||||
n = 0
|
||||
for typePlace in listeTypePlace :
|
||||
for i in range(typePlace.nombre) :
|
||||
print(Place(None,self,typePlace,n,1,True,False))
|
||||
n += 1
|
||||
else :
|
||||
self.__id = id
|
||||
self.parkings.append(self)
|
||||
|
||||
@property
|
||||
@ -64,40 +85,47 @@ class Parking:
|
||||
"""
|
||||
return Place.placeValide(self.__id, voiture)
|
||||
|
||||
def addPlaceSuperAbo(self, parking):
|
||||
return Place(None, parking, None, None, None, True)
|
||||
|
||||
def __str__(self):
|
||||
return "[Parking : nom = " + self.__nom +"]"
|
||||
|
||||
|
||||
class Place:
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM place WHERE idPlace='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
return Place(id,row["idParking"],row["idTypePlace"],row["niveau"],
|
||||
row["numero"],row["estLibre"],row["estSuperAbo"])
|
||||
|
||||
def __init__(self, id, parking, typePlace, niveau, numero, estLibre, estSuperAbo):
|
||||
self.__parking = parking
|
||||
self.__typePlace = typePlace
|
||||
self.__niveau = niveau
|
||||
self.__numero = numero
|
||||
self.__estLibre = estLibre
|
||||
self.__estSuperAbo = estSuperAbo
|
||||
def __init__(self, id=None, parking=None, typePlace=None, numero=None, niveau=None,estLibre=True, estSuperAbo=False):
|
||||
if id is None :
|
||||
self.__parking = parking
|
||||
self.__typePlace = typePlace
|
||||
self.__numero = numero
|
||||
self.__niveau = niveau
|
||||
self.__estLibre = estLibre
|
||||
self.__estSuperAbo = estSuperAbo
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO place (idParking, idTypePlace, niveau, numero, estLibre, estSuperAbo) "
|
||||
"VALUES (?,?,?,?,?,?)",
|
||||
(self.__parking.id, self.__typePlace.id,self.__niveau,
|
||||
self.__numero, self.__estLibre, int(self.__estSuperAbo)))
|
||||
c.execute("INSERT INTO place (idParking, idTypePlace, numero, estLibre, estSuperAbo) "
|
||||
"VALUES (?,?,?,?,?)",
|
||||
(self.__parking.id, self.__typePlace.id,
|
||||
self.__numero, int(self.__estLibre), int(self.__estSuperAbo)))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else :
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM place WHERE idPlace='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__parking = Parking.get(row["idParking"])
|
||||
self.__typePlace = TypePlace(row["idTypePlace"])
|
||||
self.__numero = row["numero"]
|
||||
self.__estLibre = row["estLibre"]
|
||||
self.__estSuperAbo = row["estSuperAbo"]
|
||||
self.__id = id
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
def prendre(self):
|
||||
"""
|
||||
Rend la place indisponible
|
||||
@ -108,7 +136,7 @@ class Place:
|
||||
raise Exception("Place déjà prise")
|
||||
self.__estLibre = False
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE place SET estLibre = 0 WHERE idPlace = ?", (str(self.__id)))
|
||||
c.execute("UPDATE place SET estLibre = 0 WHERE idPlace ='"+str(self.__id)+"'")
|
||||
c.seDeconnecter()
|
||||
|
||||
def liberer(self):
|
||||
@ -118,16 +146,23 @@ class Place:
|
||||
"""
|
||||
if (self.__estLibre == True):
|
||||
raise Exception("Impossible de liberer une place vide")
|
||||
self.__estLibre = False
|
||||
self.__estLibre = True
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE place SET estLibre = 1 WHERE idPlace = ?", (str(self.__id)))
|
||||
c.execute("UPDATE place SET estLibre = 1 WHERE idPlace ='"+str(self.__id)+"'")
|
||||
c.seDeconnecter()
|
||||
|
||||
@property
|
||||
def identification(self):
|
||||
return TypePlace(self.__typePlace).niveau + ":" + self.__numero
|
||||
|
||||
@property
|
||||
def estlibre(self):
|
||||
return self.__estLibre
|
||||
|
||||
@staticmethod
|
||||
def nbPlaceParking(idParking):
|
||||
c = connexionBDD()
|
||||
print("lol")
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ?", (str(idParking)))
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = " + str(idParking))
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
@ -135,7 +170,7 @@ class Place:
|
||||
@staticmethod
|
||||
def nbPlaceLibreParking(idParking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ? AND estLibre = 1", (str(idParking)))
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = "+str(idParking)+" AND estLibre = 1")
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
@ -143,7 +178,7 @@ class Place:
|
||||
@staticmethod
|
||||
def nbSuperAbo(idParking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ? AND estSuperAbo = 1", (str(idParking)))
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = "+str(idParking)+" AND estSuperAbo = 1")
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
@ -160,48 +195,47 @@ class Place:
|
||||
if row is None :
|
||||
return None
|
||||
else :
|
||||
return Place(row["idPlace"],row["idParking"], row["idtypePlace"],
|
||||
row["niveau"], row["numero"], bool(row["estLibre"]), bool(row["estSuperAbo"]))
|
||||
return Place(row["idPlace"],row["idParking"], row["idTypePlace"],
|
||||
row["numero"], bool(row["estLibre"]), bool(row["estSuperAbo"]))
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return "[Place : " \
|
||||
"Parking = " + str(self.__parking) + "," \
|
||||
"typePlace = " + str(self.__typePlace) + "," \
|
||||
"niveau = " + str(self.__niveau) + "," \
|
||||
"numero = " + str(self.__numero) + "," \
|
||||
"estLibre = " + str(self.__estLibre) + "," \
|
||||
"estSuperAbo = " + str(self.__estSuperAbo) + "]" \
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
|
||||
|
||||
|
||||
class TypePlace:
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM typePlace WHERE idTypePlace='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
return TypePlace(id,row["longueur"],row["hauteur"],row["nombre"])
|
||||
|
||||
|
||||
def __init__(self, id ,longueur, hauteur, nombre):
|
||||
self.__longueur = longueur
|
||||
self.__hauteur = hauteur
|
||||
self.__nombre = nombre
|
||||
def __init__(self, id ,longueur=None, hauteur=None, nombre=None, prix=None, niveau=None):
|
||||
if id is None :
|
||||
self.__longueur = longueur
|
||||
self.__hauteur = hauteur
|
||||
self.__nombre = nombre
|
||||
self.__prix = prix
|
||||
self.__niveau = niveau
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO typePlace (longueur,hauteur,nombre) VALUES (?,?,?)",
|
||||
(self.__longueur, self.__hauteur, self.__nombre))
|
||||
c.execute("INSERT INTO typePlace (longueur,hauteur,nombre, prix, niveau) VALUES (?,?,?,?,?)",
|
||||
(self.__longueur, self.__hauteur, self.__nombre,self.__prix, self.__niveau))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM typePlace WHERE idTypePlace='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__longueur = row["longueur"]
|
||||
self.__hauteur = row["hauteur"]
|
||||
self.__nombre = row["nombre"]
|
||||
self.__prix = row["prix"]
|
||||
self.__niveau = row["niveau"]
|
||||
self.__id = id
|
||||
|
||||
@property
|
||||
@ -220,43 +254,36 @@ class TypePlace:
|
||||
def nombre(self):
|
||||
return self.__nombre
|
||||
|
||||
@property
|
||||
def prix(self):
|
||||
return self.__prix
|
||||
|
||||
@property
|
||||
def niveau(self):
|
||||
return self.__niveau
|
||||
|
||||
def __str__(self):
|
||||
return "[TypePlace : " \
|
||||
"id = " + str(self.__id) + "," \
|
||||
"longueur = " + str(self.__longueur) + "," \
|
||||
"hauteur = " + str(self.hauteur) + "," \
|
||||
"nombre = " + str(self.nombre) + "]"
|
||||
"hauteur = " + str(self.__hauteur) + "," \
|
||||
"nombre = " + str(self.__nombre) + "," \
|
||||
"prix = " + str(self.__prix) + "," \
|
||||
"niveau = " + str(self.__niveau) + "]"
|
||||
|
||||
|
||||
class Placement:
|
||||
placementsEnCours = []
|
||||
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM placement WHERE idPlacement='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
print(row["idVoiture"])
|
||||
return Placement(row["idPlacement"], Voiture.get(row["idVoiture"]), Place.get(row["idPlace"]),
|
||||
row["debut"], row["fin"])
|
||||
|
||||
|
||||
def __init__(self,id, voiture, place, debut, fin):
|
||||
def __init__(self, id, voiture=None, place=None, debut=None, fin=None):
|
||||
"""
|
||||
Creer un placement
|
||||
:param voiture: Voiture
|
||||
:param place: Place
|
||||
:return:
|
||||
"""
|
||||
self.__voiture = voiture
|
||||
self.__place = place
|
||||
place.prendre()
|
||||
self.placementsEnCours.append(self)
|
||||
if id is None :
|
||||
self.__debut = datetime.datetime
|
||||
self.__voiture = voiture
|
||||
self.__place = place
|
||||
self.__debut = time.time()
|
||||
self.__fin = None
|
||||
while True:
|
||||
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
|
||||
@ -271,6 +298,14 @@ class Placement:
|
||||
self.__id = id
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM placement WHERE idPlacement='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__voiture = row["voiture"]
|
||||
self.__place = row["place"]
|
||||
self.__id = id
|
||||
self.__debut = debut
|
||||
self.__fin = fin
|
||||
@ -279,23 +314,20 @@ class Placement:
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def place(self):
|
||||
return self.__place
|
||||
|
||||
def end(self):
|
||||
self.__fin = time.time()
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE placement SET fin='"+str(self.__fin)+"' WHERE idPlacement='"+str(id)+"'")
|
||||
c.seDeconnecter()
|
||||
|
||||
def __str__(self):
|
||||
return "[Placement : " \
|
||||
"id = " + self.__id +"," \
|
||||
"Voiture = " + self.__voiture +"," \
|
||||
"Place = " + self.__place +"," \
|
||||
"Debut = " + self.__debut +"," \
|
||||
"Fin = " + self.__fin +"]"
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__" :
|
||||
c = connexionBDD()
|
||||
c.initialisationBDD()
|
||||
c.seDeconnecter()
|
||||
listeTypePlaces = []
|
||||
listeTypePlaces.append(TypePlace(None,200, 300,10))
|
||||
listeTypePlaces.append(TypePlace(None,120, 250,15))
|
||||
p = Parking("test",listeTypePlaces)
|
||||
print (p)
|
||||
"id = " + str(self.__id) +"," \
|
||||
"Voiture = " + str(self.__voiture) +"," \
|
||||
"Place = " + str(self.__place) +"," \
|
||||
"Debut = " + str(self.__debut) +"," \
|
||||
"Fin = " + str(self.__fin) +"]"
|
@ -1,4 +1,74 @@
|
||||
import time
|
||||
from src.m import Client
|
||||
from src.m.Parking import Placement
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
class Service:
|
||||
pass
|
||||
@staticmethod
|
||||
def getAllEnCours(parking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM service WHERE dateRealisation = NULL "
|
||||
"AND idPlacement = (SELECT idPlacement FORM PLACEMENT WHERE "
|
||||
"idPlace = (SELECT idPlace FROM Place WHERE idParking '"+str(parking.id)+"'))")
|
||||
rows = r.fetchall()
|
||||
c.seDeconnecter()
|
||||
l =[]
|
||||
for row in rows:
|
||||
l.append(Service(row["idService"], Client.get(row["idClient"]), Placement.get(row["idPlacement"]),
|
||||
row["typeService"], row["dateDemande"], row["dateService"], row["dateRealisation"]))
|
||||
return l
|
||||
|
||||
def __init__(self, id, client= None, placement= None, typeService= None,
|
||||
dateService = None, dateDemande = time.time(), dateRealisation = None):
|
||||
if id is None :
|
||||
self.__client = client
|
||||
self.__placement = placement
|
||||
self.__typeService = typeService
|
||||
self.__dateDemande = dateDemande
|
||||
self.__dateService = dateService
|
||||
self.__dateRealisation = dateRealisation
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO service (idClient,idPlacement, typeService, dateDemande) VALUES (?,?,?,?)",
|
||||
(str(self.__client.id), str(self.__placement.id), str(self.__typeService), str(self.__dateDemande)))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM service WHERE idService='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__id = id
|
||||
self.__client = row["client"]
|
||||
self.__placement = row["placement"]
|
||||
self.__typeService = row["typeService"]
|
||||
self.__dateDemande = row["dateDemande"]
|
||||
self.__dateService = row["dateService"]
|
||||
self.__dateRealisation = row["dateRealisation"]
|
||||
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def typeService(self) :
|
||||
return self.__typeService
|
||||
|
||||
def __str__(self):
|
||||
return "[Service : " \
|
||||
"id = " + str(self.__id) +"," \
|
||||
"Client = " + str(self.__client) +"," \
|
||||
"TypeService = " + str(self.__typeService) +"," \
|
||||
"DateDemande = " + str(self.__dateDemande) +"," \
|
||||
"DateService = " + str(self.__dateService) +"," \
|
||||
"DateRealisation = " + str(self.__dateRealisation) +"]"
|
||||
|
||||
|
||||
class TypeService:
|
||||
MAINTENANCE = 1
|
||||
ENTRETIEN = 2
|
||||
LIVRAISON = 3
|
@ -3,31 +3,32 @@ from src.m.connexionBDD import connexionBDD
|
||||
__author__ = 'sidya'
|
||||
|
||||
class Voiture:
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM voiture WHERE idVoiture='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
return Voiture(id,row["longueur"],row["hauteur"],row["imma"], bool(row["estDansParking"]))
|
||||
|
||||
|
||||
def __init__(self, longueur, hauteur, imma, estDansParking):
|
||||
self.__longueur = longueur
|
||||
self.__hauteur = hauteur
|
||||
self.__imma = imma
|
||||
self.__estDansParking = estDansParking
|
||||
|
||||
def __init__(self, id, idClient=None, longueur=None, hauteur=None, imma=None, estDansParking=False):
|
||||
if id is None :
|
||||
self.__idClient = idClient
|
||||
self.__longueur = longueur
|
||||
self.__hauteur = hauteur
|
||||
self.__imma = imma
|
||||
self.__estDansParking = estDansParking
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO voiture (longueur,hauteur,imma, estDansParking) VALUES (?,?,?,?)",
|
||||
c.execute("INSERT INTO voiture (longueur, hauteur, imma, estDansParking) VALUES (?,?,?,?)",
|
||||
(self.__longueur, self.__hauteur, self.__imma, int(self.__estDansParking)))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM voiture WHERE idVoiture='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__id = id
|
||||
self.__idClient = row["idClient"]
|
||||
self.__longueur = row["longueur"]
|
||||
self.__hauteur = row["hauteur"]
|
||||
self.__imma = row["imma"]
|
||||
self.__estDansParking = row["estDansParking"]
|
||||
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
@ -43,7 +44,7 @@ class Voiture:
|
||||
|
||||
@property
|
||||
def immatriculation(self):
|
||||
return self.__immatriculation
|
||||
return self.__imma
|
||||
|
||||
@property
|
||||
def estDansParking(self):
|
||||
@ -51,7 +52,8 @@ class Voiture:
|
||||
|
||||
def __str__(self):
|
||||
return "[Voiture :" \
|
||||
" longueur = " +self.__longueur + ", " \
|
||||
" hauteur = " +self.__hauteur + ", " \
|
||||
" imma = " +self.__imma + ", " \
|
||||
" estDansParking = " +self.__estDansParking + "]"
|
||||
" id = " + str(self.__id) + ", " \
|
||||
" longueur = " + str(self.__longueur) + ", " \
|
||||
" hauteur = " + str(self.__hauteur) + ", " \
|
||||
" imma = " + str(self.__imma) + ", " \
|
||||
" estDansParking = " + str(self.__estDansParking)+"]"
|
@ -1,14 +1,26 @@
|
||||
from shutil import copyfile
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
import sqlite3
|
||||
|
||||
class connexionBDD:
|
||||
__chemin = "m/BDDprojetPython.sq3"
|
||||
__sql = "m/table.sql"
|
||||
def __init__(self):
|
||||
self.__chemin = "m/BDDprojetPython.sq3"
|
||||
self.__conn = sqlite3.connect(self.__chemin)
|
||||
try:
|
||||
with open(self.__chemin):
|
||||
pass
|
||||
except IOError:
|
||||
self.__conn = sqlite3.connect(connexionBDD.__chemin)
|
||||
self.__conn.row_factory = sqlite3.Row
|
||||
self.__cur = self.__conn.cursor()
|
||||
self.initialisationBDD()
|
||||
self.__conn = sqlite3.connect(connexionBDD.__chemin)
|
||||
self.__conn.row_factory = sqlite3.Row
|
||||
self.__cur = self.__conn.cursor()
|
||||
|
||||
|
||||
def execute(self, req, param = ()):
|
||||
r = None
|
||||
#try:
|
||||
@ -26,7 +38,15 @@ class connexionBDD:
|
||||
self.__conn.close()
|
||||
|
||||
def initialisationBDD(self):
|
||||
with open("m/table.sql") as f:
|
||||
with open(self.__sql) as f:
|
||||
sql = f.read()
|
||||
self.__conn.executescript(sql)
|
||||
self.__conn.commit()
|
||||
|
||||
@staticmethod
|
||||
def sauver(path):
|
||||
copyfile(connexionBDD.chemin, path)
|
||||
|
||||
@staticmethod
|
||||
def charger(path):
|
||||
copyfile(path, connexionBDD.chemin)
|
||||
|
@ -1,75 +1,77 @@
|
||||
DROP TABLE IF EXISTS service;
|
||||
DROP TABLE IF EXISTS contrat;
|
||||
DROP TABLE IF EXISTS voiture;
|
||||
DROP TABLE IF EXISTS client;
|
||||
DROP TABLE IF EXISTS abonnement;
|
||||
DROP TABLE IF EXISTS placement;
|
||||
DROP TABLE IF EXISTS voiture;
|
||||
DROP TABLE IF EXISTS place;
|
||||
DROP TABLE IF EXISTS parking;
|
||||
DROP TABLE IF EXISTS typePlace;
|
||||
|
||||
|
||||
|
||||
CREATE TABLE parking (
|
||||
idParking INTEGER PRIMARY KEY ,
|
||||
nom VARCHAR(30)
|
||||
);
|
||||
idParking INTEGER PRIMARY KEY,
|
||||
nom VARCHAR(30),
|
||||
actif INTEGER(1) DEFAULT 1
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE typePlace (
|
||||
idTypePlace INTEGER PRIMARY KEY ,
|
||||
longueur INTEGER ,
|
||||
hauteur INTEGER ,
|
||||
nombre INTEGER
|
||||
idTypePlace INTEGER PRIMARY KEY,
|
||||
longueur INTEGER,
|
||||
hauteur INTEGER,
|
||||
nombre INTEGER,
|
||||
prix FLOAT,
|
||||
niveau INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE place (
|
||||
idPlace INTEGER PRIMARY KEY ,
|
||||
idParking INTEGER ,
|
||||
idTypePlace INTEGER ,
|
||||
niveau INTEGER ,
|
||||
numero INTEGER ,
|
||||
idPlace INTEGER PRIMARY KEY,
|
||||
idParking INTEGER,
|
||||
idTypePlace INTEGER,
|
||||
numero INTEGER,
|
||||
estLibre INTEGER(1),
|
||||
estSuperAbo INTEGER(1),
|
||||
FOREIGN KEY (idParking) REFERENCES parking(id),
|
||||
FOREIGN KEY (idTypePlace) REFERENCES typePlace(id)
|
||||
FOREIGN KEY (idParking) REFERENCES parking(idParking),
|
||||
FOREIGN KEY (idTypePlace) REFERENCES typePlace(idTypePlace)
|
||||
);
|
||||
|
||||
CREATE TABLE voiture (
|
||||
idVoiture INTEGER PRIMARY KEY ,
|
||||
hauteur INTEGER ,
|
||||
longueur INTEGER ,
|
||||
imma VARCHAR(10),
|
||||
estDansParking INTEGER(1)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE placement (
|
||||
idPlacement VARCHAR(10) PRIMARY KEY ,
|
||||
idVoiture INTEGER ,
|
||||
idPlace INTEGER ,
|
||||
debut DATE,
|
||||
fin DATE,
|
||||
FOREIGN KEY (idVoiture) REFERENCES voiture(id),
|
||||
FOREIGN KEY (idPlace) REFERENCES place(id)
|
||||
idPlacement VARCHAR(10) PRIMARY KEY,
|
||||
idVoiture INTEGER,
|
||||
idPlace INTEGER,
|
||||
debut TIMESTAMP,
|
||||
fin TIMESTAMP,
|
||||
FOREIGN KEY (idVoiture) REFERENCES voiture(idVoiture),
|
||||
FOREIGN KEY (idPlace) REFERENCES place(idPlace)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE client (
|
||||
idClient VARCHAR(10) PRIMARY KEY ,
|
||||
idClient VARCHAR(10) PRIMARY KEY,
|
||||
nom VARCHAR(20),
|
||||
prenom VARCHAR(20),
|
||||
adresse VARCHAR(50),
|
||||
typeAbonnement INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE voiture (
|
||||
idVoiture INTEGER PRIMARY KEY,
|
||||
idClient VARCHAR(10),
|
||||
hauteur INTEGER,
|
||||
longueur INTEGER,
|
||||
imma VARCHAR(10),
|
||||
estDansParking INTEGER(1)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE service (
|
||||
idService INTEGER PRIMARY KEY ,
|
||||
idService INTEGER PRIMARY KEY,
|
||||
idClient VARCHAR(10),
|
||||
dateDemande DATE,
|
||||
dateService DATE,
|
||||
dateRealisation DATE,
|
||||
rapport VARCHAR(255),
|
||||
FOREIGN KEY (idClient) REFERENCES client(id)
|
||||
idPlacement VARCHAR(10),
|
||||
typeService INTEGER,
|
||||
dateDemande TIMESTAMP,
|
||||
dateService TIMESTAMP,
|
||||
dateRealisation TIMESTAMP
|
||||
FOREIGN KEY (idClient) REFERENCES client(idClient),
|
||||
FOREIGN KEY (idPlacement) REFERENCES placement(idPlacement)
|
||||
);
|
9
src/m/test/TestClient.py
Normal file
9
src/m/test/TestClient.py
Normal file
@ -0,0 +1,9 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
from src.m.Parking import Parking, TypePlace, Place
|
||||
|
||||
class TestClient :
|
||||
def TestClient(self):
|
||||
pass
|
74
src/m/test/TestParking.py
Normal file
74
src/m/test/TestParking.py
Normal file
@ -0,0 +1,74 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
from src.m.Parking import Parking, TypePlace, Place
|
||||
|
||||
class TestParking :
|
||||
def TestParking(self):
|
||||
p = Parking(None,"test",[TypePlace(None,220,200,4,2.5,1),TypePlace(None,200,130,5,2.5,1)])
|
||||
id = p.id
|
||||
assert_equal(p.nbPlacesLibresParking, 9, "Nombre de place libre non valide")
|
||||
assert_equal(p.nbPlaces, 9, "Nombre de place non valide")
|
||||
assert_equal(p.nbSuperAbo, 0, "Nombre de place super abo")
|
||||
|
||||
def TestRecherchePlace(self):
|
||||
pass
|
||||
|
||||
class TestPlace :
|
||||
def TestPlace(self):
|
||||
t1 =TypePlace(None,220,200,4,2.5,1)
|
||||
parking = Parking(None,"test",[t1])
|
||||
|
||||
p = Place(None,parking,t1,2,1)
|
||||
|
||||
def TestPrendreLiberer(self):
|
||||
t1 = TypePlace(None,220,200,4,2.5,1)
|
||||
parking = Parking(None,"test",[t1])
|
||||
|
||||
p = Place(None,parking,t1,2,1)
|
||||
|
||||
assert_equal(p.estlibre, True, "La place devrait etre libre")
|
||||
|
||||
p.prendre()
|
||||
assert_equal(p.estlibre, False, "La place ne devrait ne pas etre libre")
|
||||
|
||||
try:
|
||||
p.prendre()
|
||||
assert_equal(True, False, "Une place prise ne peut pas a nouveau prise")
|
||||
except Exception :
|
||||
pass
|
||||
|
||||
p.liberer()
|
||||
assert_equal(p.estlibre, True, "La place devrait etre libre")
|
||||
|
||||
try:
|
||||
p.liberer()
|
||||
assert_equal(True, False, "Une place libre ne peut pas a nouveau liberée")
|
||||
except Exception :
|
||||
pass
|
||||
|
||||
|
||||
class TestTypePlace :
|
||||
def TestTypePlace(self):
|
||||
#Creation
|
||||
t = TypePlace(None,220,200,4,2.5,1)
|
||||
assert_equal(t.longueur, 220, "Valeur non attendue pour la longueur")
|
||||
assert_equal(t.hauteur, 200,"Valeur non attendue pour la hauteur")
|
||||
assert_equal(t.nombre,4,"Valeur non attendue pour le nombre de place")
|
||||
assert_equal(t.prix, 2.5,"Valeur non attendue pour le prix")
|
||||
assert_equal(t.niveau, 1, "Valeur non attendue pour le niveau")
|
||||
id = t.id
|
||||
|
||||
#Recuperer un TypePlace Non existant
|
||||
try:
|
||||
t = TypePlace("aaaa")
|
||||
assert_equal(True, False, "Un id invalide pour une type de place doit lever une exection")
|
||||
except IndexError :
|
||||
pass
|
||||
|
||||
#Recuperer un TypePlace existant
|
||||
try:
|
||||
t = TypePlace(id)
|
||||
except IndexError :
|
||||
assert_equal(True, False, "Un id valide pour une type de place ne doit pas lever une exection")
|
10
src/m/test/TestService.py
Normal file
10
src/m/test/TestService.py
Normal file
@ -0,0 +1,10 @@
|
||||
from src.m.Service import Service
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
|
||||
class TestService :
|
||||
def TestService(self):
|
||||
pass
|
28
src/m/test/TestVoiture.py
Normal file
28
src/m/test/TestVoiture.py
Normal file
@ -0,0 +1,28 @@
|
||||
from src.m.Voiture import Voiture
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
|
||||
|
||||
class TestVoiture :
|
||||
def TestVoiture(self):
|
||||
v = Voiture(None,None,120,100,"IMMA")
|
||||
assert_equal(v.longueur, 120, "Ne retourne pas la longueur attendue")
|
||||
assert_equal(v.hauteur, 100, "Ne retourne pas la hateur attendue")
|
||||
assert_equal(v.immatriculation, "IMMA", "Ne retourne pas l'immatriculation attendue")
|
||||
id = v.id
|
||||
|
||||
#Recuperer une Voiture Non existant
|
||||
try:
|
||||
t = Voiture("aaaa")
|
||||
assert_equal(True, False, "Un id invalide pour une voiture doit lever une exection")
|
||||
except IndexError :
|
||||
pass
|
||||
|
||||
#Recuperer un Voiture existant
|
||||
try:
|
||||
t = Voiture(id)
|
||||
except IndexError :
|
||||
assert_equal(True, False, "Un id valide pour une voiture ne doit pas lever une exection")
|
1
src/m/test/__init__.py
Normal file
1
src/m/test/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__author__ = 'sidya'
|
Reference in New Issue
Block a user