This commit is contained in:
sidya82
2015-02-05 01:21:43 +01:00
parent 2a1099c450
commit b7b6a84643
22 changed files with 460 additions and 316 deletions

View File

@@ -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) + "]"