\o/
This commit is contained in:
132
src/m/Abonnement.py
Normal file
132
src/m/Abonnement.py
Normal file
@@ -0,0 +1,132 @@
|
||||
"""
|
||||
Module qui implémente les classes representants les Abonnements de DreamPark.
|
||||
"""
|
||||
import random
|
||||
import string
|
||||
from src.c.utils.connexionBDD import connexionBDD
|
||||
|
||||
## Représentation d'un Client de DreamPark
|
||||
class Client:
|
||||
##
|
||||
# Contsructeur du Client
|
||||
# @param id Si None : Création du Client dans la bd a l'aide des autres parametres.
|
||||
# Sinon : tentative de récupération du client avec cet id dans la bd
|
||||
# @param nom nom du Client si creation
|
||||
# @param prenom prenom du Client si creation
|
||||
# @param cb cb du Client si creation
|
||||
# @param typeAbonnement typeabonnement du client si creation
|
||||
def __init__(self, id, nom=None, prenom=None, cb=None, typeAbonnement=None):
|
||||
|
||||
if id is None:
|
||||
self.__nom = nom
|
||||
self.__prenom = prenom
|
||||
self.__typeAbonnement = typeAbonnement
|
||||
self.__cb = cb
|
||||
while True:
|
||||
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
|
||||
range(random.randint(1, 10)))
|
||||
try:
|
||||
Client(id)
|
||||
except IndexError:
|
||||
break
|
||||
self.__id = id
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO client (idClient, nom, prenom, cb, typeAbonnement) VALUES (?,?,?,?,?)",
|
||||
(str(self.__id), str(self.__nom), str(self.__prenom), str(self.__cb), str(self.__typeAbonnement)))
|
||||
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.__cb = row["cb"]
|
||||
|
||||
## Mise a jour du Client
|
||||
# @param nom nouveau nom
|
||||
# @param prenom nouveau prenom
|
||||
# @param cb nouveau cb
|
||||
# @param typeAbonnement nouveau TypeAbonnement
|
||||
def maj(self, nom, prenom, cb, typeAbonnement):
|
||||
self.__nom = nom
|
||||
self.__prenom = prenom
|
||||
self.__typeAbonnement = typeAbonnement
|
||||
self.__cb = cb
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE client SET nom = ?, prenom = ?, cb = ?, typeAbonnement = ? WHERE idClient = ?",
|
||||
(str(self.__nom), str(self.__prenom), "", str(self.__typeAbonnement), str(self.__id)))
|
||||
c.seDeconnecter()
|
||||
|
||||
## Desabonne le Client en le supprimant
|
||||
def desabo(self):
|
||||
c = connexionBDD()
|
||||
c.execute("DELETE FROM client WHERE idClient ='" + str(self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
## Propriete : prenom du Client
|
||||
@property
|
||||
def prenom(self):
|
||||
return self.__prenom
|
||||
|
||||
## Propriete : nom du Client
|
||||
@property
|
||||
def nom(self):
|
||||
return self.__nom
|
||||
|
||||
## Propriete : id du Client
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
## Propriete : cb du Client
|
||||
@property
|
||||
def cb(self):
|
||||
return self.__cb
|
||||
|
||||
## Propriete : abonnement du Client
|
||||
@property
|
||||
def abonnement(self):
|
||||
return self.__typeAbonnement
|
||||
|
||||
## Retourne le nombre de super abonné
|
||||
# @return nombre de super abonné
|
||||
@staticmethod
|
||||
def nbSuperAbo():
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT COUNT(*) FROM client WHERE typeAbonnement = " + str(TypeAbonnement.SUPER_ABONNE))
|
||||
nb = r.fetchone()[0]
|
||||
c.seDeconnecter()
|
||||
return nb
|
||||
|
||||
## Retourne le nombre d'abonné
|
||||
# @return nombre d'abonné
|
||||
@staticmethod
|
||||
def nbAbo():
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT COUNT(*) FROM client WHERE typeAbonnement = " + str(TypeAbonnement.ABONNE))
|
||||
nb = r.fetchone()[0]
|
||||
c.seDeconnecter()
|
||||
return nb
|
||||
|
||||
|
||||
|
||||
## Representation du Client en chaine
|
||||
def __str__(self):
|
||||
return "[Client :" \
|
||||
" id = " + str(self.__id) + ", "+\
|
||||
" prenom = " + str(self.__prenom) + ", "+\
|
||||
" nom = " + str(self.__nom) + ", " +\
|
||||
" cb = " + str( self.__cb) + ", " +\
|
||||
" typeAbonnement = " + str(self.__typeAbonnement) + "]"
|
||||
|
||||
## Classe définissant les constantes de TypeAbonnement disponible pour le Client
|
||||
class TypeAbonnement:
|
||||
ABONNE = 0
|
||||
SUPER_ABONNE = 1
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
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):
|
||||
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(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)))
|
||||
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):
|
||||
return self.__prenom
|
||||
|
||||
@property
|
||||
def nom(self):
|
||||
return self.__nom
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def adr(self):
|
||||
return self.__adresse
|
||||
|
||||
@property
|
||||
def abonnement(self):
|
||||
return self.__typeAbonnement
|
||||
|
||||
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) + "]"
|
||||
|
||||
|
||||
class TypeAbonnement:
|
||||
ABONNE = 0
|
||||
SUPER_ABONNE = 1
|
||||
198
src/m/Parking.py
198
src/m/Parking.py
@@ -1,22 +1,22 @@
|
||||
"""
|
||||
Module qui implémente les classes representants un parking de DreamPark.
|
||||
"""
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from src.c.utils.connexionBDD import connexionBDD
|
||||
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'
|
||||
|
||||
|
||||
## Representation d'un parking de DreamPark
|
||||
class Parking:
|
||||
parkings = []
|
||||
|
||||
## Retourne un objet parking correspondant à id
|
||||
# @param id id du Parking a retourner
|
||||
@staticmethod
|
||||
def get(id):
|
||||
if len(Parking.parkings) == 0:
|
||||
@@ -25,6 +25,7 @@ class Parking:
|
||||
if p.id == id:
|
||||
return p
|
||||
|
||||
## Retourne tout les Parking actif present dans la bd
|
||||
@staticmethod
|
||||
def getAllActif():
|
||||
if len(Parking.parkings) == 0:
|
||||
@@ -36,6 +37,8 @@ class Parking:
|
||||
Parking(row["idParking"], row["nom"], None)
|
||||
return Parking.parkings
|
||||
|
||||
## Supprime un parking
|
||||
# @param parking L'objet parking a supprimer
|
||||
@staticmethod
|
||||
def remove(parking):
|
||||
Parking.parkings.remove(parking)
|
||||
@@ -43,11 +46,15 @@ class Parking:
|
||||
c.execute("UPDATE parking SET actif = 0 WHERE idParking='" + str(parking.id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
## Supprime les parkings present dans la mémoire vive (pas dans la bd)
|
||||
@staticmethod
|
||||
def removeAllRam():
|
||||
Parking.parkings = []
|
||||
|
||||
|
||||
## Constructeur du Parking
|
||||
# @param id Si None : Cree un Parking dans la BD Sinon : tentative de récupération du Parking avec cet id dans la bd
|
||||
# @param nom : Si creation nom du parking
|
||||
# @param listeTypePlace : Si creation Liste des TypePlace du parking
|
||||
def __init__(self, id, nom=None, listeTypePlace=None):
|
||||
self.__nom = nom
|
||||
if id is None:
|
||||
@@ -69,43 +76,56 @@ class Parking:
|
||||
self.__id = id
|
||||
self.parkings.append(self)
|
||||
|
||||
## Propriete : id du Parking
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
## propriete : nom du Parking
|
||||
@property
|
||||
def nom(self):
|
||||
return self.__nom
|
||||
|
||||
## propriete : nombre de Place du Parking
|
||||
@property
|
||||
def nbPlaces(self):
|
||||
return Place.nbPlaceParking(self.__id)
|
||||
|
||||
## propriete : nombre de Place libres du Parking
|
||||
@property
|
||||
def nbPlacesLibresParking(self):
|
||||
return Place.nbPlaceLibreParking(self.__id)
|
||||
|
||||
## propriete : nombre de Place super abo
|
||||
@property
|
||||
def nbSuperAbo(self):
|
||||
return Place.nbSuperAbo(self.__id)
|
||||
|
||||
## Recherche une place pour une voiture
|
||||
# @param voiture voiture pour laquel on recherche la place
|
||||
# @return Place Si touvé : Place sinon : None
|
||||
def recherchePlace(self, voiture):
|
||||
"""
|
||||
Permet de rechercher une place valide pour une voiture
|
||||
:param voiture: Voiture
|
||||
:return: Place
|
||||
"""
|
||||
return Place.placeValide(self.__id, voiture)
|
||||
|
||||
def addPlaceSuperAbo(self, parking):
|
||||
return Place(None, parking, None, None, False, True)
|
||||
## Ajout d'une place surmesure pour super abo
|
||||
# @param parking le parking ou il faut ajouter la place
|
||||
def addPlaceSuperAbo(self):
|
||||
return Place(None, self, None, None, False, True)
|
||||
|
||||
## Representation du Parking en chaine
|
||||
def __str__(self):
|
||||
return "[Parking : nom = " + self.__nom + "]"
|
||||
|
||||
|
||||
## Representation d'une place de DreamPark
|
||||
class Place:
|
||||
def __init__(self, id=None, parking=None, typePlace=None, numero=None, estLibre=True, estSuperAbo=False):
|
||||
## Contructeur de Place
|
||||
# @param id Si None : creation de la Place dans la bd Sinon : tentative de récupération de la Place avec cet id dans la bd
|
||||
# @param parking Si creation : le Parking ou est creer la Place
|
||||
# @param typePlace Si creation : le TypePlace de Place
|
||||
# @param numero Si creation : le numero de Place
|
||||
# @param estLibre Si creation : Si la Place est libre ou non
|
||||
# @param estSuperAbo Si creation : Si la Place est superAbo ou non
|
||||
def __init__(self, id, parking=None, typePlace=None, numero=None, estLibre=True, estSuperAbo=False):
|
||||
if id is None:
|
||||
self.__parking = parking
|
||||
self.__typePlace = typePlace
|
||||
@@ -137,17 +157,10 @@ class Place:
|
||||
self.__estSuperAbo = row["estSuperAbo"]
|
||||
self.__id = id
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
|
||||
## Rend la Place la indisponible
|
||||
def prendre(self):
|
||||
"""
|
||||
Rend la place indisponible
|
||||
:param Placement:
|
||||
:return:
|
||||
"""
|
||||
if (self.__estLibre == False):
|
||||
raise Exception("Place déjà prise")
|
||||
self.__estLibre = False
|
||||
@@ -155,31 +168,49 @@ class Place:
|
||||
c.execute("UPDATE place SET estLibre = 0 WHERE idPlace ='" + str(self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
## Rend la Place disponible
|
||||
def liberer(self):
|
||||
"""
|
||||
Libere une place non dispo
|
||||
:return:
|
||||
"""
|
||||
if (self.__estLibre == True):
|
||||
raise Exception("Impossible de liberer une place vide")
|
||||
self.__estLibre = True
|
||||
c = connexionBDD()
|
||||
c.execute(
|
||||
"UPDATE place SET estLibre = 1, fin ='" + str(time.time()) + "' WHERE idPlace ='" + str(self.__id) + "'")
|
||||
c.execute("UPDATE place SET estLibre = 1 WHERE idPlace ='" + str(self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
## Suppression place de la bd
|
||||
def supprimer(self):
|
||||
c = connexionBDD()
|
||||
c.execute("DELETE FROM place idPlace ='" + str(self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
## propriete : id de la Place
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
## propriete : identification etage : numero de la Place
|
||||
@property
|
||||
def identification(self):
|
||||
return str(chr(self.__typePlace.niveau + ord('A')) + ":" + str(self.__numero))
|
||||
|
||||
## propriete : True si la place est Place
|
||||
@property
|
||||
def estlibre(self):
|
||||
return self.__estLibre
|
||||
|
||||
## propriete : typePlace de la Place
|
||||
@property
|
||||
def typePlace(self):
|
||||
return self.__typePlace
|
||||
|
||||
## propriete : typePlace de la Place
|
||||
@property
|
||||
def estSuperAbo(self):
|
||||
return self.__estSuperAbo
|
||||
|
||||
## Retourne les nombre de place du Parking d'id idParking
|
||||
# @param idParking l'id du Parking
|
||||
# @return le nombre de Place
|
||||
@staticmethod
|
||||
def nbPlaceParking(idParking):
|
||||
c = connexionBDD()
|
||||
@@ -188,6 +219,9 @@ class Place:
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
|
||||
## Retourne les nombre de place libre du Parking d'id idParking
|
||||
# @param idParking l'id du Parking
|
||||
# @return le nombre de Place libre
|
||||
@staticmethod
|
||||
def nbPlaceLibreParking(idParking):
|
||||
c = connexionBDD()
|
||||
@@ -196,6 +230,9 @@ class Place:
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
|
||||
## Retourne les nombre de place superAbo du Parking d'id idParking
|
||||
# @param idParking l'id du Parking
|
||||
# @return le nombre de Place superAbo
|
||||
@staticmethod
|
||||
def nbSuperAbo(idParking):
|
||||
c = connexionBDD()
|
||||
@@ -204,6 +241,10 @@ class Place:
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
|
||||
## Retourne si une Place valide pour une Voiture dans un parking
|
||||
# @param idParking id du Parking ou est recherché la place
|
||||
# @param voiture Voiture pour laquelle est recherché la place
|
||||
# @return Si non trouve : None. Sinon : Place une place valide
|
||||
@staticmethod
|
||||
def placeValide(idPArking, voiture):
|
||||
c = connexionBDD()
|
||||
@@ -220,17 +261,25 @@ class Place:
|
||||
row["numero"], bool(row["estLibre"]), bool(row["estSuperAbo"]))
|
||||
|
||||
|
||||
## Representation d'une Place en chaine
|
||||
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) + "]" \
|
||||
\
|
||||
\
|
||||
return "[Place : " +\
|
||||
"Parking = " + str(self.__parking) + ","+\
|
||||
"typePlace = " + str(self.__typePlace) + ","+\
|
||||
"numero = " + str(self.__numero) + ","+\
|
||||
"estLibre = " + str(self.__estLibre) + ","+\
|
||||
"estSuperAbo = " + str(self.__estSuperAbo) + "]"
|
||||
|
||||
|
||||
## Representation d'un TypePlace de DreamPark
|
||||
class TypePlace:
|
||||
## Constructeur de TypePlace
|
||||
# @param id Si None : creation du TypePlace dans la bd Sinon : tentative de récupération du TypePlace avec cet id dans la bd
|
||||
# @param longueur Longueur de la Place en cm
|
||||
# @param hauteur Hauteur de la Place en cm
|
||||
# @param nombre Nombre de Place de ce type
|
||||
# @param prix Le prix pur ce type de Place
|
||||
# @param niveau Le niveau ou se trouve les Place
|
||||
def __init__(self, id, longueur=None, hauteur=None, nombre=None, prix=None, niveau=None):
|
||||
if id is None:
|
||||
self.__longueur = longueur
|
||||
@@ -257,50 +306,53 @@ class TypePlace:
|
||||
self.__niveau = row["niveau"]
|
||||
self.__id = id
|
||||
|
||||
## propriete : id du Typeplace
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
## propriete : longueur du Typeplace
|
||||
@property
|
||||
def longueur(self):
|
||||
return self.__longueur
|
||||
|
||||
## propriete : hauteur du Typeplace
|
||||
@property
|
||||
def hauteur(self):
|
||||
return self.__hauteur
|
||||
|
||||
## propriete : nombre du Typeplace
|
||||
@property
|
||||
def nombre(self):
|
||||
return self.__nombre
|
||||
|
||||
## propriete : prix du Typeplace
|
||||
@property
|
||||
def prix(self):
|
||||
return self.__prix
|
||||
|
||||
## propriete : niveau du Typeplace
|
||||
@property
|
||||
def niveau(self):
|
||||
return self.__niveau
|
||||
|
||||
## Representation du TypePlace en chaine
|
||||
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) + "]"
|
||||
|
||||
"id = " + str(self.__id) + ","+\
|
||||
"longueur = " + str(self.__longueur) + ","+\
|
||||
"hauteur = " + str(self.__hauteur) + ","+\
|
||||
"nombre = " + str(self.__nombre) + "," +\
|
||||
"prix = " + str(self.__prix) + ","+\
|
||||
"niveau = " + str(self.__niveau) + "]"
|
||||
|
||||
## Representation d'un Placement de DreamPark
|
||||
class Placement:
|
||||
def __init__(self, id, voiture=None, place=None, debut=None, fin=None):
|
||||
"""
|
||||
Creer un placement
|
||||
:param voiture: Voiture
|
||||
:param place: Place
|
||||
:return:
|
||||
"""
|
||||
## Constructeur Placement
|
||||
# @param id Si None : creation du Placement dans la bd Sinon : tentative de récupération du Placement avec cet id dans la bd
|
||||
# @param voiture Si creation : Voiture lié au Placement
|
||||
# @param place Si creation : Place lié au Placement
|
||||
def __init__(self, id, voiture=None, place=None):
|
||||
if id is None:
|
||||
self.__voiture = voiture
|
||||
self.__place = place
|
||||
@@ -328,33 +380,47 @@ class Placement:
|
||||
self.__voiture = Voiture(row["idVoiture"])
|
||||
self.__place = Place(row["idPlace"])
|
||||
self.__id = id
|
||||
self.__debut = debut
|
||||
self.__fin = fin
|
||||
self.__debut = row["debut"]
|
||||
self.__fin = row["fin"]
|
||||
|
||||
## Propriete : id du Placement
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
## Propriete : place liée du Placement
|
||||
@property
|
||||
def place(self):
|
||||
return self.__place
|
||||
|
||||
## Propriete : voiture liée du Placement
|
||||
@property
|
||||
def voiture(self):
|
||||
return self.__voiture
|
||||
|
||||
## Retourne la durée moyenne des placement
|
||||
# @return duree moyenne placement
|
||||
@staticmethod
|
||||
def dureeMoyPlacement():
|
||||
c = connexionBDD()
|
||||
r= c.execute("SELECT AVG(FIN - DEBUT) AS duree FROM placement")
|
||||
nb = r.fetchone()[0]
|
||||
c.seDeconnecter()
|
||||
return nb
|
||||
|
||||
## Fin du placement (depart 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(self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
self.__place.liberer()
|
||||
|
||||
## Representation du Placement en chaine
|
||||
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) + "]"
|
||||
104
src/m/Service.py
104
src/m/Service.py
@@ -1,55 +1,65 @@
|
||||
import time
|
||||
|
||||
from src.m.Client import Client
|
||||
from src.c.utils.connexionBDD import connexionBDD
|
||||
from src.m.Abonnement import Client
|
||||
from src.m.Parking import Placement
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
## Representation d'un Service de DreamPack
|
||||
class Service:
|
||||
## Retourne tout les services en cours dans le Parking parking
|
||||
# @param parking Parking dont on veut connaitre les services
|
||||
# @return Liste Service en cours
|
||||
@staticmethod
|
||||
def getAllEnCours(parking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM service WHERE dateRealisation is NULL "
|
||||
r = c.execute("SELECT idService 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) + "'))")
|
||||
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"]))
|
||||
l.append(Service(row["idService"]))
|
||||
print("l = " + str(l))
|
||||
return l
|
||||
|
||||
## Retourne tout les services associé a un Placement
|
||||
# @param parking Parking dont on veut connaitre les services
|
||||
# @return Liste Service associé a un Placement
|
||||
@staticmethod
|
||||
def getAllServicePlacement(placement):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM service WHERE idPlacement ='" + str(placement.id) + "'")
|
||||
r = c.execute("SELECT idService 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"]))
|
||||
l.append(Service(row["idService"]))
|
||||
print("l = " + str(l))
|
||||
return l
|
||||
|
||||
## Contructeur d'un Service
|
||||
# @param id Si None : Cree un Service dans la BD Sinon : tentative de récupération du Service avec cet id dans la bd
|
||||
# @param client Si creation : Client associe au Service
|
||||
# @param placement Si creation : Placement associe au Service
|
||||
# @param typeService Si creation : TypeService du Service
|
||||
# @param dateService Si creation : date ou sera realise le service si necessaire
|
||||
# @param lieu Si creation : lieu ou realise le service si necessaire
|
||||
def __init__(self, id, client=None, placement=None, typeService=None,
|
||||
dateService=None, dateDemande=time.time(), dateRealisation=None):
|
||||
dateService="NULL", lieu =""):
|
||||
if id is None:
|
||||
self.__client = client
|
||||
self.__placement = placement
|
||||
self.__typeService = typeService
|
||||
self.__dateDemande = dateDemande
|
||||
self.__dateDemande = time.time()
|
||||
self.__dateService = dateService
|
||||
self.__dateRealisation = dateRealisation
|
||||
self.__dateRealisation = "NULL"
|
||||
self.__lieu = lieu
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO service (idClient,idPlacement, typeService, dateDemande) VALUES (?,?,?,?)",
|
||||
c.execute("INSERT INTO service (idClient,idPlacement, typeService, dateDemande,dateService,lieu) VALUES (?,?,?,?,?,?)",
|
||||
(str(self.__client.id), str(self.__placement.id), str(self.__typeService),
|
||||
str(self.__dateDemande)))
|
||||
str(self.__dateDemande), str(self.__dateService),str(self.__lieu)))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
@@ -66,31 +76,44 @@ class Service:
|
||||
self.__dateDemande = row["dateDemande"]
|
||||
self.__dateService = row["dateService"]
|
||||
self.__dateRealisation = row["dateRealisation"]
|
||||
self.__lieu = row["lieu"]
|
||||
|
||||
|
||||
## Propriete : id Service
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
## Propriete : TypeService du Service
|
||||
@property
|
||||
def typeService(self):
|
||||
return self.__typeService
|
||||
|
||||
## Propriete : Placement associe au Service
|
||||
@property
|
||||
def placement(self):
|
||||
return self.__placement
|
||||
|
||||
## Propriete : date ou le Service doit etre realisé
|
||||
@property
|
||||
def dateService(self):
|
||||
return self.__dateService
|
||||
|
||||
## Propriete : lieu ou le Service doit etre realisé
|
||||
@property
|
||||
def lieu(self):
|
||||
return self.__lieu
|
||||
|
||||
## Propriete : information interessante pout l'admin pour un Service
|
||||
@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
|
||||
return "Place : " + self.__placement.place.identification + " Imma : " + self.__placement.voiture.immatriculation
|
||||
|
||||
## Propriete : Retour si un service a été réalisé du Service
|
||||
@property
|
||||
def estRealise(self):
|
||||
return self.__dateRealisation is None or self.__dateRealisation == "NULL"
|
||||
return self.__dateRealisation is not None and not self.__dateRealisation == "NULL"
|
||||
|
||||
## Passe le service comme realise
|
||||
def doService(self):
|
||||
self.__dateRealisation = time.time()
|
||||
c = connexionBDD()
|
||||
@@ -98,18 +121,37 @@ class Service:
|
||||
self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
## Passe a un service a un etat de non realisé si le Client recupere sa Voiture avant que le Service est été réalisé
|
||||
def nonRealise(self):
|
||||
self.__dateRealisation = 1
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE service SET dateRealisation = '" + str(self.__dateRealisation) + "' WHERE idService='" + str(
|
||||
self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
## mise a jour de infos de livraison
|
||||
def maj(self, datetime, lieu):
|
||||
self.__dateService = datetime
|
||||
self.__lieu = lieu
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE service SET dateService = '" + str(self.__dateService) +
|
||||
"' , lieu = '" + str(self.__lieu) +
|
||||
"' WHERE idService='" + str(self.__id) + "'")
|
||||
c.seDeconnecter()
|
||||
|
||||
## Representation en chaine d'un Service
|
||||
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) + "," +\
|
||||
"Placement = " + str(self.__placement) + "," +\
|
||||
"TypeService = " + str( self.__typeService) + ","+\
|
||||
"DateDemande = " + str(self.__dateDemande) + ","+\
|
||||
"DateService = " + str( self.__dateService) + "," +\
|
||||
"DateRealisation = " + str(self.__dateRealisation) + \
|
||||
"Lieu = " + str( self.__lieu) +" ]"
|
||||
|
||||
## Classe Representant les différents TypeService
|
||||
class TypeService:
|
||||
MAINTENANCE = 1
|
||||
ENTRETIEN = 2
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
from src.m.Client import Client
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
"""
|
||||
Module qui implémente les classes representants d'une voiture de DreamPark.
|
||||
"""
|
||||
from src.c.utils.connexionBDD import connexionBDD
|
||||
from src.m.Abonnement import Client
|
||||
|
||||
## Representation d'une Voiture de DreamPark
|
||||
class Voiture:
|
||||
## Constucteur Voiture
|
||||
# @param id Si None : Cree une Voiture dans la BD Sinon : tentative de récupération de la Voiture avec cet id dans la bd
|
||||
# @param client Si creation Client qui posséde la Voiture
|
||||
# @param longueur Si creation longueur de la Voiture
|
||||
# @param hauteur Si creation hauteur de la Voiture
|
||||
# @param imma Si creation imma de la Voiture
|
||||
def __init__(self, id, client=None, longueur=None, hauteur=None, imma=None):
|
||||
if id is None:
|
||||
if client is None:
|
||||
@@ -37,38 +44,44 @@ class Voiture:
|
||||
self.__hauteur = row["hauteur"]
|
||||
self.__imma = row["imma"]
|
||||
|
||||
## Met a jour la possesion d'un voiture par un Client
|
||||
# @param client Client qui posséde la voiture
|
||||
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()
|
||||
|
||||
|
||||
## propriete : id Voiture
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
## propriete : hauteur Voiture
|
||||
@property
|
||||
def hauteur(self):
|
||||
return self.__hauteur
|
||||
|
||||
## propriete : longueur Voiture
|
||||
@property
|
||||
def longueur(self):
|
||||
return self.__longueur
|
||||
|
||||
## propriete : immatriculation Voiture
|
||||
@property
|
||||
def immatriculation(self):
|
||||
return self.__imma
|
||||
|
||||
## propriete : Client possedant Voiture
|
||||
@property
|
||||
def client(self):
|
||||
return self.__client
|
||||
|
||||
## Representation d'une Voiture en chaine
|
||||
def __str__(self):
|
||||
return "[Voiture :" \
|
||||
" id = " + str(self.__id) + ", " \
|
||||
" client = " + str(self.__client) + ", " \
|
||||
" longueur = " + str(
|
||||
self.__longueur) + ", " \
|
||||
" hauteur = " + str(self.__hauteur) + ", " \
|
||||
" imma = " + str(self.__imma) + "]"
|
||||
" id = " + str(self.__id) + ", "+\
|
||||
" client = " + str(self.__client) + ", " +\
|
||||
" longueur = " + str(self.__longueur) + ", " +\
|
||||
" hauteur = " + str(self.__hauteur) + ", " +\
|
||||
" imma = " + str(self.__imma) + "]"
|
||||
@@ -1,54 +0,0 @@
|
||||
from shutil import copyfile
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
import sqlite3
|
||||
|
||||
|
||||
class connexionBDD:
|
||||
__chemin = "m/BDDprojetPython.sq3"
|
||||
__sql = "m/table.sql"
|
||||
|
||||
def __init__(self):
|
||||
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:
|
||||
r = self.__cur.execute(req, param)
|
||||
self.__conn.commit()
|
||||
"""except Exception as e:
|
||||
print (e)"""
|
||||
return r
|
||||
|
||||
def lastId(self):
|
||||
return self.__cur.lastrowid
|
||||
|
||||
def seDeconnecter(self):
|
||||
self.__cur.close()
|
||||
self.__conn.close()
|
||||
|
||||
def initialisationBDD(self):
|
||||
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)
|
||||
@@ -50,7 +50,7 @@ CREATE TABLE client (
|
||||
idClient VARCHAR(10) PRIMARY KEY,
|
||||
nom VARCHAR(20),
|
||||
prenom VARCHAR(20),
|
||||
adresse VARCHAR(50),
|
||||
cb VARCHAR(50),
|
||||
typeAbonnement INTEGER
|
||||
);
|
||||
|
||||
@@ -71,6 +71,7 @@ CREATE TABLE service (
|
||||
dateDemande TIMESTAMP,
|
||||
dateService TIMESTAMP DEFAULT NULL,
|
||||
dateRealisation TIMESTAMP DEFAULT NULL,
|
||||
lieu VARCHAR(255),
|
||||
FOREIGN KEY (idClient) REFERENCES client(idClient),
|
||||
FOREIGN KEY (idPlacement) REFERENCES placement(idPlacement)
|
||||
);
|
||||
Reference in New Issue
Block a user