\o/
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self,id, nom=None, prenom=None, adresse=None, typeAbonnement=None):
|
||||
def __init__(self, id, nom=None, prenom=None, adresse=None, typeAbonnement=None):
|
||||
if id is None:
|
||||
self.__nom = nom
|
||||
self.__prenom = prenom
|
||||
@ -15,9 +17,9 @@ class Client:
|
||||
while True:
|
||||
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
|
||||
range(random.randint(1, 10)))
|
||||
try :
|
||||
try:
|
||||
Client(id)
|
||||
except IndexError :
|
||||
except IndexError:
|
||||
break
|
||||
self.__id = id
|
||||
c = connexionBDD()
|
||||
@ -26,9 +28,9 @@ class Client:
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM client WHERE idClient='"+str(id)+"'")
|
||||
r = c.execute("SELECT * FROM client WHERE idClient='" + str(id) + "'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
if row is None:
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__id = id
|
||||
@ -49,7 +51,7 @@ class Client:
|
||||
|
||||
def desabo(self):
|
||||
c = connexionBDD()
|
||||
c.execute("DELETE FROM client WHERE idClient ='"+str(id)+"'")
|
||||
c.execute("DELETE FROM client WHERE idClient ='" + str(id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
|
||||
@ -66,7 +68,7 @@ class Client:
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def adr(self,nom, prenom, adresse, typeAbonnement):
|
||||
def adr(self):
|
||||
return self.__adresse
|
||||
|
||||
@property
|
||||
@ -76,10 +78,12 @@ class Client:
|
||||
def __str__(self):
|
||||
return "[Client :" \
|
||||
" id = " + str(self.__id) + ", " \
|
||||
" prenom = " + str(self.__prenom) + ", " \
|
||||
" nom = " + str(self.__nom) + ", " \
|
||||
" adresse = " + str(self.__adresse) + ", " \
|
||||
" typeAbonnement = " + str(self.__typeAbonnement) + "]"
|
||||
" prenom = " + str(self.__prenom) + ", " \
|
||||
" nom = " + str(self.__nom) + ", " \
|
||||
" adresse = " + str(
|
||||
self.__adresse) + ", " \
|
||||
" typeAbonnement = " + str(self.__typeAbonnement) + "]"
|
||||
|
||||
|
||||
class TypeAbonnement:
|
||||
ABONNE = 0
|
||||
|
148
src/m/Parking.py
148
src/m/Parking.py
@ -1,36 +1,38 @@
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from src.m.Voiture import Voiture
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
|
||||
from src.m.Voiture import Voiture
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
from src.m.Voiture import Voiture
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
|
||||
class Parking:
|
||||
parkings = []
|
||||
|
||||
@staticmethod
|
||||
def get(id):
|
||||
if len(Parking.parkings) == 0 :
|
||||
if len(Parking.parkings) == 0:
|
||||
Parking.getAllActif()
|
||||
for p in Parking.parkings :
|
||||
if p.id == id :
|
||||
for p in Parking.parkings:
|
||||
if p.id == id:
|
||||
return p
|
||||
|
||||
@staticmethod
|
||||
def getAllActif():
|
||||
if len(Parking.parkings) == 0 :
|
||||
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 :
|
||||
for row in rows:
|
||||
Parking(row["idParking"], row["nom"], None)
|
||||
return Parking.parkings
|
||||
|
||||
@ -38,7 +40,7 @@ class Parking:
|
||||
def remove(parking):
|
||||
Parking.parkings.remove(parking)
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE parking SET actif = 0 WHERE idParking='"+str(parking.id)+"'")
|
||||
c.execute("UPDATE parking SET actif = 0 WHERE idParking='" + str(parking.id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
@staticmethod
|
||||
@ -48,17 +50,22 @@ class Parking:
|
||||
|
||||
def __init__(self, id, nom=None, listeTypePlace=None):
|
||||
self.__nom = nom
|
||||
if id is None :
|
||||
if id is None:
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO parking (nom) VALUES ('"+str(self.__nom)+"')", ())
|
||||
c.execute("INSERT INTO parking (nom) VALUES ('" + str(self.__nom) + "')", ())
|
||||
self.__id = c.lastId()
|
||||
#Crea des places
|
||||
# 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 :
|
||||
placeParNiveau = {}
|
||||
for typePlace in listeTypePlace:
|
||||
try:
|
||||
i = placeParNiveau[typePlace.niveau]
|
||||
except KeyError:
|
||||
i = 0
|
||||
placeParNiveau[typePlace.niveau] = i + typePlace.nombre
|
||||
for i in range(placeParNiveau[typePlace.niveau]):
|
||||
Place(None, self, typePlace, i, True, False)
|
||||
else:
|
||||
self.__id = id
|
||||
self.parkings.append(self)
|
||||
|
||||
@ -91,24 +98,23 @@ class Parking:
|
||||
return Place.placeValide(self.__id, voiture)
|
||||
|
||||
def addPlaceSuperAbo(self, parking):
|
||||
return Place(None, parking, None, None, None, True)
|
||||
return Place(None, parking, None, None, False, True)
|
||||
|
||||
def __str__(self):
|
||||
return "[Parking : nom = " + self.__nom +"]"
|
||||
return "[Parking : nom = " + self.__nom + "]"
|
||||
|
||||
|
||||
class Place:
|
||||
def __init__(self, id=None, parking=None, typePlace=None, numero=None, niveau=None,estLibre=True, estSuperAbo=False):
|
||||
if id is None :
|
||||
def __init__(self, id=None, parking=None, typePlace=None, numero=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
|
||||
if self.__typePlace is None:
|
||||
t = "NULL"
|
||||
else :
|
||||
else:
|
||||
t = self.__typePlace.id
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO place (idParking, idTypePlace, numero, estLibre, estSuperAbo) "
|
||||
@ -117,16 +123,16 @@ class Place:
|
||||
self.__numero, int(self.__estLibre), int(self.__estSuperAbo)))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else :
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM place WHERE idPlace='"+str(id)+"'")
|
||||
r = c.execute("SELECT * FROM place WHERE idPlace='" + str(id) + "'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
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.__numero = row["numero"]
|
||||
self.__estLibre = row["estLibre"]
|
||||
self.__estSuperAbo = row["estSuperAbo"]
|
||||
self.__id = id
|
||||
@ -135,6 +141,7 @@ class Place:
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
|
||||
def prendre(self):
|
||||
"""
|
||||
Rend la place indisponible
|
||||
@ -145,7 +152,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):
|
||||
@ -157,17 +164,22 @@ class Place:
|
||||
raise Exception("Impossible de liberer une place vide")
|
||||
self.__estLibre = True
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE place SET estLibre = 1 WHERE idPlace ='"+str(self.__id)+"'")
|
||||
c.execute(
|
||||
"UPDATE place SET estLibre = 1, fin ='" + str(time.time()) + "' WHERE idPlace ='" + str(self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
@property
|
||||
def identification(self):
|
||||
return TypePlace(self.__typePlace).niveau + ":" + self.__numero
|
||||
return str(chr(self.__typePlace.niveau + ord('A')) + ":" + str(self.__numero))
|
||||
|
||||
@property
|
||||
def estlibre(self):
|
||||
return self.__estLibre
|
||||
|
||||
@property
|
||||
def typePlace(self):
|
||||
return self.__typePlace
|
||||
|
||||
@staticmethod
|
||||
def nbPlaceParking(idParking):
|
||||
c = connexionBDD()
|
||||
@ -179,7 +191,7 @@ class Place:
|
||||
@staticmethod
|
||||
def nbPlaceLibreParking(idParking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = "+str(idParking)+" AND estLibre = 1")
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = " + str(idParking) + " AND estLibre = 1")
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
@ -187,7 +199,7 @@ class Place:
|
||||
@staticmethod
|
||||
def nbSuperAbo(idParking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = "+str(idParking)+" AND estSuperAbo = 1")
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = " + str(idParking) + " AND estSuperAbo = 1")
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
@ -198,31 +210,29 @@ class Place:
|
||||
r = c.execute("SELECT * FROM place WHERE idParking= ? AND estLibre = 1 "
|
||||
"AND idTypePlace =(SELECT idTypePlace FROM typePlace "
|
||||
"WHERE hauteur>? AND longueur>? ORDER BY longueur) ",
|
||||
(str(idPArking),str(voiture.hauteur),str(voiture.longueur)))
|
||||
(str(idPArking), str(voiture.hauteur), str(voiture.longueur)))
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
if row is None :
|
||||
if row is None:
|
||||
return None
|
||||
else :
|
||||
return Place(row["idPlace"],row["idParking"], row["idTypePlace"],
|
||||
else:
|
||||
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) + "," \
|
||||
"numero = " + str(self.__numero) + "," \
|
||||
"estLibre = " + str(self.__estLibre) + "," \
|
||||
"estSuperAbo = " + str(self.__estSuperAbo) + "]" \
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"typePlace = " + str(self.__typePlace) + "," \
|
||||
"numero = " + str(
|
||||
self.__numero) + "," \
|
||||
"estLibre = " + str(self.__estLibre) + "," \
|
||||
"estSuperAbo = " + str(self.__estSuperAbo) + "]" \
|
||||
\
|
||||
\
|
||||
class TypePlace:
|
||||
def __init__(self, id ,longueur=None, hauteur=None, nombre=None, prix=None, niveau=None):
|
||||
if id is None :
|
||||
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
|
||||
@ -230,14 +240,14 @@ class TypePlace:
|
||||
self.__niveau = niveau
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO typePlace (longueur,hauteur,nombre, prix, niveau) VALUES (?,?,?,?,?)",
|
||||
(self.__longueur, self.__hauteur, self.__nombre,self.__prix, self.__niveau))
|
||||
(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)+"'")
|
||||
r = c.execute("SELECT * FROM typePlace WHERE idTypePlace='" + str(id) + "'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
if row is None:
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__longueur = row["longueur"]
|
||||
@ -274,11 +284,13 @@ class TypePlace:
|
||||
def __str__(self):
|
||||
return "[TypePlace : " \
|
||||
"id = " + str(self.__id) + "," \
|
||||
"longueur = " + str(self.__longueur) + "," \
|
||||
"hauteur = " + str(self.__hauteur) + "," \
|
||||
"nombre = " + str(self.__nombre) + "," \
|
||||
"prix = " + str(self.__prix) + "," \
|
||||
"niveau = " + str(self.__niveau) + "]"
|
||||
"longueur = " + str(self.__longueur) + "," \
|
||||
"hauteur = " + str(
|
||||
self.__hauteur) + "," \
|
||||
"nombre = " + str(self.__nombre) + "," \
|
||||
"prix = " + str(self.__prix) + "," \
|
||||
"niveau = " + str(
|
||||
self.__niveau) + "]"
|
||||
|
||||
|
||||
class Placement:
|
||||
@ -289,14 +301,14 @@ class Placement:
|
||||
:param place: Place
|
||||
:return:
|
||||
"""
|
||||
if id is None :
|
||||
if id is None:
|
||||
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
|
||||
range(random.randint(1, 10)))
|
||||
range(random.randint(1, 10)))
|
||||
try:
|
||||
Placement(id)
|
||||
except IndexError:
|
||||
@ -308,9 +320,9 @@ class Placement:
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM placement WHERE idPlacement='"+str(id)+"'")
|
||||
r = c.execute("SELECT * FROM placement WHERE idPlacement='" + str(id) + "'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
if row is None:
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__voiture = Voiture(row["idVoiture"])
|
||||
@ -327,16 +339,22 @@ class Placement:
|
||||
def place(self):
|
||||
return self.__place
|
||||
|
||||
@property
|
||||
def voiture(self):
|
||||
return self.__voiture
|
||||
|
||||
def end(self):
|
||||
self.__fin = time.time()
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE placement SET fin='"+str(self.__fin)+"' WHERE idPlacement='"+str(id)+"'")
|
||||
c.execute("UPDATE placement SET fin='" + str(self.__fin) + "' WHERE idPlacement='" + str(id) + "'")
|
||||
c.seDeconnecter()
|
||||
self.__place.liberer()
|
||||
|
||||
def __str__(self):
|
||||
return "[Placement : " \
|
||||
"id = " + str(self.__id) +"," \
|
||||
"Voiture = " + str(self.__voiture) +"," \
|
||||
"Place = " + str(self.__place) +"," \
|
||||
"Debut = " + str(self.__debut) +"," \
|
||||
"Fin = " + str(self.__fin) +"]"
|
||||
"id = " + str(self.__id) + "," \
|
||||
"Voiture = " + str(self.__voiture) + "," \
|
||||
"Place = " + str(self.__place) + "," \
|
||||
"Debut = " + str(
|
||||
self.__debut) + "," \
|
||||
"Fin = " + str(self.__fin) + "]"
|
@ -1,29 +1,45 @@
|
||||
import time
|
||||
|
||||
from src.m.Client import Client
|
||||
from src.m.Parking import Placement
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class Service:
|
||||
@staticmethod
|
||||
def getAllEnCours(parking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM service WHERE dateRealisation is NULL "
|
||||
"AND idPlacement IN (SELECT idPlacement FROM PLACEMENT WHERE "
|
||||
"idPlace IN (SELECT idPlace FROM Place WHERE idParking = '"+str(parking.id)+"'))")
|
||||
"idPlace IN (SELECT idPlace FROM Place WHERE idParking = '" + str(parking.id) + "'))")
|
||||
rows = r.fetchall()
|
||||
c.seDeconnecter()
|
||||
l =[]
|
||||
l = []
|
||||
for row in rows:
|
||||
l.append(Service(row["idService"], Client(row["idClient"]), Placement(row["idPlacement"]),
|
||||
row["typeService"], row["dateDemande"], row["dateService"], row["dateRealisation"]))
|
||||
row["typeService"], row["dateDemande"], row["dateService"], row["dateRealisation"]))
|
||||
print("l = " + str(l))
|
||||
return l
|
||||
|
||||
def __init__(self, id, client= None, placement= None, typeService= None,
|
||||
dateService = None, dateDemande = time.time(), dateRealisation = None):
|
||||
if id is None :
|
||||
@staticmethod
|
||||
def getAllServicePlacement(placement):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM service WHERE idPlacement ='" + str(placement.id) + "'")
|
||||
rows = r.fetchall()
|
||||
c.seDeconnecter()
|
||||
l = []
|
||||
for row in rows:
|
||||
l.append(Service(row["idService"], Client(row["idClient"]), Placement(row["idPlacement"]),
|
||||
row["typeService"], row["dateDemande"], row["dateService"], row["dateRealisation"]))
|
||||
print("l = " + str(l))
|
||||
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
|
||||
@ -32,14 +48,15 @@ class Service:
|
||||
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)))
|
||||
(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)+"'")
|
||||
r = c.execute("SELECT * FROM service WHERE idService='" + str(id) + "'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
if row is None:
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__id = id
|
||||
@ -56,17 +73,41 @@ class Service:
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def typeService(self) :
|
||||
def typeService(self):
|
||||
return self.__typeService
|
||||
|
||||
@property
|
||||
def placement(self):
|
||||
return self.__placement
|
||||
|
||||
@property
|
||||
def info(self):
|
||||
str = "Place : " + self.__placement.place.identification + "Imma : " + self.__placement.voiture.immatriculation
|
||||
if self.typeService == TypeService.LIVRAISON:
|
||||
str += "Date : " + self.__dateService
|
||||
return str
|
||||
|
||||
@property
|
||||
def estRealise(self):
|
||||
return self.__dateRealisation is None or self.__dateRealisation == "NULL"
|
||||
|
||||
def doService(self):
|
||||
self.__dateRealisation = time.time()
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE service SET dateRealisation = '" + str(self.__dateRealisation) + "' WHERE idService='" + str(
|
||||
self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
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) +"]"
|
||||
"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:
|
||||
|
@ -1,33 +1,47 @@
|
||||
from src.m.Client import Client
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class Voiture:
|
||||
def __init__(self, id, idClient=None, longueur=None, hauteur=None, imma=None, estDansParking=False):
|
||||
if id is None :
|
||||
self.__idClient = idClient
|
||||
def __init__(self, id, client=None, longueur=None, hauteur=None, imma=None):
|
||||
if id is None:
|
||||
if client is None:
|
||||
self.__client = "NULL"
|
||||
cl = "NULL"
|
||||
else:
|
||||
self.__client = client
|
||||
cl = self.__client.id
|
||||
self.__longueur = longueur
|
||||
self.__hauteur = hauteur
|
||||
self.__imma = imma
|
||||
self.__estDansParking = estDansParking
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO voiture (longueur, hauteur, imma, estDansParking) VALUES (?,?,?,?)",
|
||||
(self.__longueur, self.__hauteur, self.__imma, int(self.__estDansParking)))
|
||||
c.execute("INSERT INTO voiture (idClient,longueur, hauteur, imma) VALUES (?,?,?,?)",
|
||||
(cl, self.__longueur, self.__hauteur, self.__imma))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM voiture WHERE idVoiture='"+str(id)+"'")
|
||||
r = c.execute("SELECT * FROM voiture WHERE idVoiture='" + str(id) + "'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
if row is None:
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
self.__id = id
|
||||
self.__idClient = row["idClient"]
|
||||
try:
|
||||
self.__client = Client(row["idClient"])
|
||||
except IndexError:
|
||||
self.__client = "NULL"
|
||||
self.__longueur = row["longueur"]
|
||||
self.__hauteur = row["hauteur"]
|
||||
self.__imma = row["imma"]
|
||||
self.__estDansParking = row["estDansParking"]
|
||||
|
||||
def setClient(self, client):
|
||||
self.__client = client
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE voiture SET idClient = '" + str(client.id) + "' WHERE idVoiture='" + str(self.id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
|
||||
@property
|
||||
@ -47,13 +61,14 @@ class Voiture:
|
||||
return self.__imma
|
||||
|
||||
@property
|
||||
def estDansParking(self):
|
||||
return self.__estDansParking == True
|
||||
def client(self):
|
||||
return self.__client
|
||||
|
||||
def __str__(self):
|
||||
return "[Voiture :" \
|
||||
" id = " + str(self.__id) + ", " \
|
||||
" longueur = " + str(self.__longueur) + ", " \
|
||||
" hauteur = " + str(self.__hauteur) + ", " \
|
||||
" imma = " + str(self.__imma) + ", " \
|
||||
" estDansParking = " + str(self.__estDansParking)+"]"
|
||||
" client = " + str(self.__client) + ", " \
|
||||
" longueur = " + str(
|
||||
self.__longueur) + ", " \
|
||||
" hauteur = " + str(self.__hauteur) + ", " \
|
||||
" imma = " + str(self.__imma) + "]"
|
@ -4,9 +4,11 @@ __author__ = 'sidya'
|
||||
|
||||
import sqlite3
|
||||
|
||||
|
||||
class connexionBDD:
|
||||
__chemin = "m/BDDprojetPython.sq3"
|
||||
__sql = "m/table.sql"
|
||||
|
||||
def __init__(self):
|
||||
try:
|
||||
with open(self.__chemin):
|
||||
@ -21,9 +23,9 @@ class connexionBDD:
|
||||
self.__cur = self.__conn.cursor()
|
||||
|
||||
|
||||
def execute(self, req, param = ()):
|
||||
def execute(self, req, param=()):
|
||||
r = None
|
||||
#try:
|
||||
# try:
|
||||
r = self.__cur.execute(req, param)
|
||||
self.__conn.commit()
|
||||
"""except Exception as e:
|
||||
@ -39,7 +41,7 @@ class connexionBDD:
|
||||
|
||||
def initialisationBDD(self):
|
||||
with open(self.__sql) as f:
|
||||
sql = f.read()
|
||||
sql = f.read()
|
||||
self.__conn.executescript(sql)
|
||||
self.__conn.commit()
|
||||
|
||||
|
@ -59,8 +59,7 @@ CREATE TABLE voiture (
|
||||
idClient VARCHAR(10),
|
||||
hauteur INTEGER,
|
||||
longueur INTEGER,
|
||||
imma VARCHAR(10),
|
||||
estDansParking INTEGER(1)
|
||||
imma VARCHAR(10)
|
||||
);
|
||||
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
from src.m.Parking import Parking, TypePlace, Place
|
||||
|
||||
class TestClient :
|
||||
class TestClient:
|
||||
def TestClient(self):
|
||||
pass
|
@ -4,9 +4,10 @@ from nose.tools import assert_equal
|
||||
|
||||
from src.m.Parking import Parking, TypePlace, Place
|
||||
|
||||
class TestParking :
|
||||
|
||||
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)])
|
||||
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")
|
||||
@ -15,18 +16,19 @@ class TestParking :
|
||||
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)
|
||||
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])
|
||||
t1 = TypePlace(None, 220, 200, 4, 2.5, 1)
|
||||
parking = Parking(None, "test", [t1])
|
||||
|
||||
p = Place(None,parking,t1,2,1)
|
||||
p = Place(None, parking, t1, 2, 1)
|
||||
|
||||
assert_equal(p.estlibre, True, "La place devrait etre libre")
|
||||
|
||||
@ -36,7 +38,7 @@ class TestPlace :
|
||||
try:
|
||||
p.prendre()
|
||||
assert_equal(True, False, "Une place prise ne peut pas a nouveau prise")
|
||||
except Exception :
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
p.liberer()
|
||||
@ -45,18 +47,18 @@ class TestPlace :
|
||||
try:
|
||||
p.liberer()
|
||||
assert_equal(True, False, "Une place libre ne peut pas a nouveau liberée")
|
||||
except Exception :
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
class TestTypePlace :
|
||||
class TestTypePlace:
|
||||
def TestTypePlace(self):
|
||||
#Creation
|
||||
t = TypePlace(None,220,200,4,2.5,1)
|
||||
# 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.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
|
||||
|
||||
@ -64,11 +66,11 @@ class TestTypePlace :
|
||||
try:
|
||||
t = TypePlace("aaaa")
|
||||
assert_equal(True, False, "Un id invalide pour une type de place doit lever une exection")
|
||||
except IndexError :
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
#Recuperer un TypePlace existant
|
||||
try:
|
||||
t = TypePlace(id)
|
||||
except IndexError :
|
||||
except IndexError:
|
||||
assert_equal(True, False, "Un id valide pour une type de place ne doit pas lever une exection")
|
@ -1,10 +1,6 @@
|
||||
from src.m.Service import Service
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
|
||||
class TestService :
|
||||
class TestService:
|
||||
def TestService(self):
|
||||
pass
|
@ -5,24 +5,23 @@ __author__ = 'sidya'
|
||||
from nose.tools import assert_equal
|
||||
|
||||
|
||||
|
||||
class TestVoiture :
|
||||
class TestVoiture:
|
||||
def TestVoiture(self):
|
||||
v = Voiture(None,None,120,100,"IMMA")
|
||||
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
|
||||
# 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 :
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
#Recuperer un Voiture existant
|
||||
try:
|
||||
t = Voiture(id)
|
||||
except IndexError :
|
||||
except IndexError:
|
||||
assert_equal(True, False, "Un id valide pour une voiture ne doit pas lever une exection")
|
Reference in New Issue
Block a user