This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
L3GestionParking/src/m/Service.py

157 lines
6.1 KiB
Python
Raw Normal View History

2015-02-04 13:20:39 +00:00
import time
2015-02-05 00:21:43 +00:00
2015-02-07 22:59:01 +00:00
from src.c.utils.connexionBDD import connexionBDD
from src.m.Abonnement import Client
2015-02-04 13:20:39 +00:00
from src.m.Parking import Placement
2015-01-12 15:46:50 +00:00
2015-02-05 00:21:43 +00:00
2015-02-07 22:59:01 +00:00
## Representation d'un Service de DreamPack
2015-01-10 15:11:11 +00:00
class Service:
2015-02-07 22:59:01 +00:00
## Retourne tout les services en cours dans le Parking parking
# @param parking Parking dont on veut connaitre les services
# @return Liste Service en cours
2015-02-04 13:20:39 +00:00
@staticmethod
def getAllEnCours(parking):
c = connexionBDD()
2015-02-07 22:59:01 +00:00
r = c.execute("SELECT idService FROM service WHERE dateRealisation is NULL "
2015-02-04 14:33:15 +00:00
"AND idPlacement IN (SELECT idPlacement FROM PLACEMENT WHERE "
2015-02-05 00:21:43 +00:00
"idPlace IN (SELECT idPlace FROM Place WHERE idParking = '" + str(parking.id) + "'))")
2015-02-04 13:20:39 +00:00
rows = r.fetchall()
c.seDeconnecter()
2015-02-05 00:21:43 +00:00
l = []
2015-02-04 13:20:39 +00:00
for row in rows:
2015-02-07 22:59:01 +00:00
l.append(Service(row["idService"]))
2015-02-04 13:20:39 +00:00
return l
2015-02-07 22:59:01 +00:00
## Retourne tout les services associé a un Placement
# @param parking Parking dont on veut connaitre les services
# @return Liste Service associé a un Placement
2015-02-05 00:21:43 +00:00
@staticmethod
def getAllServicePlacement(placement):
c = connexionBDD()
2015-02-07 22:59:01 +00:00
r = c.execute("SELECT idService FROM service WHERE idPlacement ='" + str(placement.id) + "'")
2015-02-05 00:21:43 +00:00
rows = r.fetchall()
c.seDeconnecter()
l = []
for row in rows:
2015-02-07 22:59:01 +00:00
l.append(Service(row["idService"]))
2015-02-05 00:21:43 +00:00
print("l = " + str(l))
return l
2015-02-07 22:59:01 +00:00
## 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
2015-02-05 00:21:43 +00:00
def __init__(self, id, client=None, placement=None, typeService=None,
2015-02-07 22:59:01 +00:00
dateService="NULL", lieu =""):
2015-02-05 00:21:43 +00:00
if id is None:
2015-02-04 13:20:39 +00:00
self.__client = client
self.__placement = placement
self.__typeService = typeService
2015-02-07 22:59:01 +00:00
self.__dateDemande = time.time()
2015-02-04 13:20:39 +00:00
self.__dateService = dateService
2015-02-07 22:59:01 +00:00
self.__dateRealisation = "NULL"
self.__lieu = lieu
2015-02-04 13:20:39 +00:00
c = connexionBDD()
2015-02-07 22:59:01 +00:00
c.execute("INSERT INTO service (idClient,idPlacement, typeService, dateDemande,dateService,lieu) VALUES (?,?,?,?,?,?)",
2015-02-05 00:21:43 +00:00
(str(self.__client.id), str(self.__placement.id), str(self.__typeService),
2015-02-07 22:59:01 +00:00
str(self.__dateDemande), str(self.__dateService),str(self.__lieu)))
2015-02-04 13:20:39 +00:00
self.__id = c.lastId()
c.seDeconnecter()
else:
c = connexionBDD()
2015-02-05 00:21:43 +00:00
r = c.execute("SELECT * FROM service WHERE idService='" + str(id) + "'")
2015-02-04 13:20:39 +00:00
row = r.fetchone()
2015-02-05 00:21:43 +00:00
if row is None:
2015-02-04 13:20:39 +00:00
raise IndexError("Invalid id")
c.seDeconnecter()
self.__id = id
2015-02-04 14:33:15 +00:00
self.__client = Client(row["idClient"])
self.__placement = Placement(row["idPlacement"])
2015-02-04 13:20:39 +00:00
self.__typeService = row["typeService"]
self.__dateDemande = row["dateDemande"]
self.__dateService = row["dateService"]
self.__dateRealisation = row["dateRealisation"]
2015-02-07 22:59:01 +00:00
self.__lieu = row["lieu"]
2015-02-04 13:20:39 +00:00
2015-02-07 22:59:01 +00:00
## Propriete : id Service
2015-02-04 13:20:39 +00:00
@property
def id(self):
return self.__id
2015-02-07 22:59:01 +00:00
## Propriete : TypeService du Service
2015-02-04 13:20:39 +00:00
@property
2015-02-05 00:21:43 +00:00
def typeService(self):
2015-02-04 13:20:39 +00:00
return self.__typeService
2015-02-07 22:59:01 +00:00
## Propriete : Placement associe au Service
2015-02-05 00:21:43 +00:00
@property
def placement(self):
return self.__placement
2015-02-07 22:59:01 +00:00
## 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
2015-02-05 00:21:43 +00:00
@property
def info(self):
2015-02-07 22:59:01 +00:00
return "Place : " + self.__placement.place.identification + " Imma : " + self.__placement.voiture.immatriculation
2015-02-05 00:21:43 +00:00
2015-02-07 22:59:01 +00:00
## Propriete : Retour si un service a été réalisé du Service
2015-02-05 00:21:43 +00:00
@property
def estRealise(self):
2015-02-07 22:59:01 +00:00
return self.__dateRealisation is not None and not self.__dateRealisation == "NULL"
2015-02-05 00:21:43 +00:00
2015-02-07 22:59:01 +00:00
## Passe le service comme realise
2015-02-05 00:21:43 +00:00
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()
2015-02-07 22:59:01 +00:00
## 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()
2015-02-04 13:20:39 +00:00
2015-02-07 22:59:01 +00:00
## 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()
2015-02-04 13:20:39 +00:00
2015-02-07 22:59:01 +00:00
## Representation en chaine d'un Service
def __str__(self):
return "[Service : " \
"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
2015-02-04 13:20:39 +00:00
class TypeService:
MAINTENANCE = 1
ENTRETIEN = 2
LIVRAISON = 3