This commit is contained in:
sidya82 2015-01-14 00:39:12 +01:00
parent 640640cab0
commit bf06106e04
35 changed files with 647 additions and 645 deletions

View File

@ -1,39 +1,16 @@
import sqlite3 import sqlite3
from src.c.Main import Main from src.c.Main import Main
from src.m.connexionBDD import connexionBDD
__author__ = 'sidya' __author__ = 'sidya'
class connexionBDD:
def __init__(self):
try:
self.__conn = sqlite3.connect("BD.sql3")
self.__cur = self.__conn.cursor()
except Exception as e:
pass # later
def seDeconnecter(self):
self.__cur.close()
self.__conn.close()
def execute(self, req):
try:
r = self.__cur.execute(req)
self.__conn.commit()
except Exception as e:
pass # later
return r
def lastId(self):
return self.__cur.lastrowid
conn = connexionBDD
if __name__ == "__main__": if __name__ == "__main__":
c = connexionBDD()
c.initialisationBDD()
c.seDeconnecter()
# lancement du controleur principal # lancement du controleur principal
main = Main() main = Main()

View File

@ -1 +0,0 @@
__author__ = 'sidya'

View File

@ -1,9 +1,11 @@
from PyQt4 import QtGui from PyQt4 import QtGui
from src.c.SelectService import SelectService
from src.c.Teleporteur import Teleporteur from src.c.Teleporteur import Teleporteur
from src.m.Placement import Placement from src.m.Parking import Placement
from src.m.Client import Client from src.m.Client import Client
from src.m.TypeAbonnement import TypeAbonnement from src.m.Service import Service
from src.m.Client import TypeAbonnement
from src.v.Camera import Camera from src.v.Camera import Camera
from src.v.MyQWidget import MyQWidget from src.v.MyQWidget import MyQWidget
from src.v.Ui_Borne import Ui_Borne from src.v.Ui_Borne import Ui_Borne
@ -39,7 +41,8 @@ class Borne:
# Validator # Validator
self.__ui.nomParking = parking.nom self.__ui.label_aff.setText("Dream park")
self.__ui.nomParking.setText(parking.nom)
self.nonVoiture() self.nonVoiture()
self.showWindow() self.showWindow()
@ -94,13 +97,15 @@ class Borne:
TypeAbonnement.SUPER_ABONNE) TypeAbonnement.SUPER_ABONNE)
self.__ui.label_aff.setText("Mise a jour de votre abonnement effectué") self.__ui.label_aff.setText("Mise a jour de votre abonnement effectué")
else: else:
if self.__ui.checkBox.isEnabled(): if self.__ui.checkBox.isChecked():
self.__c = Client(self.__ui.nomLineEdit, self.__c = Client(None,
self.__ui.nomLineEdit,
self.__ui.prenomLineEdit, self.__ui.prenomLineEdit,
"", "",
TypeAbonnement.SUPER_ABONNE) TypeAbonnement.SUPER_ABONNE)
else: else:
self.__c = Client(self.__ui.nomLineEdit, self.__c = Client(None,
self.__ui.nomLineEdit,
self.__ui.prenomLineEdit, self.__ui.prenomLineEdit,
"", "",
TypeAbonnement.ABONNE) TypeAbonnement.ABONNE)
@ -114,13 +119,26 @@ class Borne:
:return: :return:
""" """
if self.__c is None: if self.__c is None:
id = Teleporteur.teleporterVoiture(self.v_actuel, self.__parking.recherchePlace(self.v_actuel)) p = self.__parking.recherchePlace(self.v_actuel)
self.__ui.label_aff.setText("Votre num ticket est : " + id) if p is None :
self.__ui.label_aff.setText("Aucun Place disponible")
else :
id = Teleporteur.teleporterVoiture(self.v_actuel, p)
self.__ui.label_aff.setText("Votre num ticket est : " + str(id))
self.nonVoiture()
else: else:
if self.__c.abonnement != TypeAbonnement.SUPER_ABONNE: if self.__c.abonnement != TypeAbonnement.SUPER_ABONNE:
Teleporteur.teleporterVoiture(self.v_actuel, self.__parking.recherchePlace(self.v_actuel)) p = self.__parking.recherchePlace(self.v_actuel)
if p is None :
self.__ui.label_aff.setText("Aucun Place disponible")
else :
id = Teleporteur.teleporterVoiture(self.v_actuel, self.__parking.recherchePlace(self.v_actuel))
self.__w.hide()
self.__child = SelectService(self.__main)
self.__ui.label_aff.setText("Votre num ticket est : " + str(id))
self.nonVoiture()
else: else:
Teleporteur.teleporterVoirureSuperAbonne(self.v_actuel) Teleporteur.teleporterVoitureSuperAbonne(self.v_actuel)
def recuperer(self): def recuperer(self):
@ -128,12 +146,13 @@ class Borne:
Essaie de recuperer une voiture avec le numero de ticket (lineedit) Essaie de recuperer une voiture avec le numero de ticket (lineedit)
:return: :return:
""" """
p = Placement.get(self.__ui.numeroTicketLineEdit.text()) try :
if p is None: p = Placement.get(self.__ui.numeroTicketLineEdit.text())
self.__ui.label_aff.setText("Mauvais numero de ticket")
else:
Teleporteur.teleporterVersSortie(p) Teleporteur.teleporterVersSortie(p)
self.__ui.label_aff.setText("Bonne journée") self.__ui.label_aff.setText("Bonne journée")
except IndexError:
self.__ui.label_aff.setText("Mauvais numero de ticket")
def showWindow(self): def showWindow(self):

View File

@ -1,7 +1,6 @@
from PyQt4 import QtGui from PyQt4 import QtGui
from src.m.Parking import Parking from src.m.Parking import Parking, TypePlace
from src.m.ListeTypePlace import ListeTypePlace
from src.v.MyQWidget import MyQWidget from src.v.MyQWidget import MyQWidget
from src.v.Ui_CreaParking import Ui_CreaParking from src.v.Ui_CreaParking import Ui_CreaParking
@ -13,7 +12,6 @@ class CreaParking:
""" """
Controleur de cretion de parking Controleur de cretion de parking
""" """
def __init__(self, main): def __init__(self, main):
self._main = main self._main = main
self._main.activity("Debut Creation Parking", self._main.lvl.INFO) self._main.activity("Debut Creation Parking", self._main.lvl.INFO)
@ -76,14 +74,12 @@ class CreaParking:
:return: :return:
""" """
# try: # try:
l = ListeTypePlace() l = []
for i in range(0, self._ui.tableWidget.rowCount()): for i in range(0, self._ui.tableWidget.rowCount()):
l.add(int(self._ui.tableWidget.item(i, 0).text()), int(self._ui.tableWidget.item(i, 1).text()), l.append(TypePlace(None,int(self._ui.tableWidget.item(i, 0).text()), int(self._ui.tableWidget.item(i, 1).text()),
int(self._ui.tableWidget.item(i, 2).text())) int(self._ui.tableWidget.item(i, 2).text())))
self._main.addParking(Parking( p = Parking(self._ui.lineEdit_nom.text(),l)
l, self._main.activity("Ajout:" + str(p), self._main.lvl.INFO)
self._ui.lineEdit_nom.text()))
self._main.activity("Ajout Parking : detail", self._main.lvl.INFO)
self._w.hide() self._w.hide()
self._main.showWindow() self._main.showWindow()
#except Exception as e: #except Exception as e:

View File

@ -7,6 +7,7 @@ from src.c.DetailsPlaces import DetailsPlaces
from src.c.log.log import Log from src.c.log.log import Log
from src.c.log.log import lvl from src.c.log.log import lvl
from src.c.CreaParking import CreaParking from src.c.CreaParking import CreaParking
from src.m.Parking import Parking
from src.v.MyQMainWindow import MyQMainWindow from src.v.MyQMainWindow import MyQMainWindow
from src.v.Ui_MainWindow import Ui_MainWindow from src.v.Ui_MainWindow import Ui_MainWindow
@ -19,9 +20,6 @@ class Main:
self.lvl = lvl() # Public : Acces au constante self.lvl = lvl() # Public : Acces au constante
self.__log = Log() self.__log = Log()
# Parking
self.__parkings = []
app = QtGui.QApplication(sys.argv) app = QtGui.QApplication(sys.argv)
self.__view = MyQMainWindow() self.__view = MyQMainWindow()
@ -68,7 +66,7 @@ class Main:
def majListeParking(self): def majListeParking(self):
self.__ui.comboBox.clear() self.__ui.comboBox.clear()
self.__ui.comboBox.addItem("Selectionner un parking") self.__ui.comboBox.addItem("Selectionner un parking")
for p in self.__parkings: for p in Parking.getAll():
self.__ui.comboBox.addItem(p.nom) self.__ui.comboBox.addItem(p.nom)
def selectParking(self): def selectParking(self):
@ -77,25 +75,19 @@ class Main:
self.__ui.placesDispo.clear() self.__ui.placesDispo.clear()
self.__ui.placesSuperAbo.clear() self.__ui.placesSuperAbo.clear()
if self.__ui.comboBox.count() > 1: if self.__ui.comboBox.count() > 1:
print(self.__ui.comboBox.count()) p = Parking.getAll()
self.__ui.nom.setText(self.__parkings[self.__ui.comboBox.currentIndex() - 1].nom) self.__ui.nom.setText(p[self.__ui.comboBox.currentIndex() - 1].nom)
self.__ui.placesParNiveau.setText(str(self.__parkings[self.__ui.comboBox.currentIndex() - 1].nbPlaces)) self.__ui.placesParNiveau.setText(str(p[self.__ui.comboBox.currentIndex() - 1].nbPlaces))
self.__ui.placesDispo.setText( self.__ui.placesDispo.setText(
str(self.__parkings[self.__ui.comboBox.currentIndex() - 1].nbPlacesLibresParking)) str(p[self.__ui.comboBox.currentIndex() - 1].nbPlacesLibresParking))
self.__ui.placesSuperAbo.setText("lol") self.__ui.placesSuperAbo.setText(str(p[self.__ui.comboBox.currentIndex() - 1].nbSuperAbo))
def creerParking(self): def creerParking(self):
self.__view.hide() self.__view.hide()
self.__widgetCourant = CreaParking(self) self.__widgetCourant = CreaParking(self)
def addParking(self, parking):
self.__parkings.append(parking)
def modifParking(self):
if self.__ui.comboBox.currentIndex() != 0:
self.__view.hide()
self.__widgetCourant = ModifParking(self, self.__parkings[self.__ui.comboBox.currentIndex() - 1])
def rmParking(self): def rmParking(self):
if self.__ui.comboBox.currentIndex() != 0: if self.__ui.comboBox.currentIndex() != 0:
@ -113,12 +105,12 @@ class Main:
def detailsPlacesParking(self): def detailsPlacesParking(self):
if self.__ui.comboBox.currentIndex() != 0: if self.__ui.comboBox.currentIndex() != 0:
self.__view.hide() self.__view.hide()
self.__widgetCourant = DetailsPlaces(self, self.__parkings[self.__ui.comboBox.currentIndex() - 1]) self.__widgetCourant = DetailsPlaces(self, Parking.getAll()[self.__ui.comboBox.currentIndex() - 1])
def afficherBorne(self): def afficherBorne(self):
if self.__ui.comboBox.currentIndex() != 0: if self.__ui.comboBox.currentIndex() != 0:
self.__view.hide() self.__view.hide()
self.__widgetCourant = Borne(self, self.__parkings[self.__ui.comboBox.currentIndex() - 1]) self.__widgetCourant = Borne(self, Parking.getAll()[self.__ui.comboBox.currentIndex() - 1])
def showWindow(self): def showWindow(self):

55
src/c/SelectService.py Normal file
View File

@ -0,0 +1,55 @@
from PyQt4 import QtGui
from src.v.MyQWidget import MyQWidget
from src.v.Ui_Service import Ui_Service
__author__ = 'sidya'
class SelectService:
"""
Controleur de cretion de parking
"""
def __init__(self, main):
self.__main = main
self.__main.activity("Choix Service", self.__main.lvl.INFO)
self._w = MyQWidget(self.__main)
self.__ui = Ui_Service()
self.__ui.setupUi(self._w)
# connect
self.__ui.btn_valider.clicked.connect(self.valider)
# Validator
self.showWindow()
def valider(self):
"""
Gestion validation de formulaire de choix de service
:return:
"""
def showWindow(self):
"""
Gestion affichage vue Creation de Parking
:return:
"""
self._w.show()
self.__child = None # supprime l'eventuel widget enfant
self._w.focusWidget() # reprend le focus sur la fenetre
def error(self):
"""
Qdialog message erreur
:return:
"""
QtGui.QMessageBox.warning(self._w,
"Erreur ...",
"Erreur lors du choix de service ...")
self._w.hide()
self.__main.showWindow()

View File

@ -1,18 +1,18 @@
from src.m.Placement import Placement from src.m.Parking import Placement
__author__ = 'sidya' __author__ = 'sidya'
class Teleporteur: class Teleporteur:
@classmethod @staticmethod
def teleporterVoiture(self, voiture, place): def teleporterVoiture(voiture, place):
p = Placement(voiture, place) p = Placement(None,voiture, place,None,None)
return p.id return p.id
@classmethod @staticmethod
def teleporterVoitureSuperAbonne(self, voiture): def teleporterVoitureSuperAbonne(voiture):
pass pass
@classmethod @staticmethod
def teleporterVersSortie(self, placement): def teleporterVersSortie(placement):
placement.end() placement.end()

View File

@ -1,13 +0,0 @@
from src.m.connexionBDD import connexionBDD
class Abonnement:
def __init__(self, libelle, prix, estPackGar):
self.libelle = libelle
self.prix = prix
self.estPackGar = estPackGar
def addContrat(self, contrat):
connexion = connexionBDD()
# indId= connexion.cur.execute("SELECT abonnement.idAbonnement FROM abonnement WHERE libelle = ? AND prix = ? AND estPackGar=?;"(self.libelle, self.prix, self.estPackGar))
# idAbonnement = int(''.join(map(str,indId)))

View File

@ -1,26 +1,45 @@
import random import random
import sqlite3
import string import string
from src.m.connexionBDD import connexionBDD
__author__ = 'sidya' __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"]))
class Client():
clients = []
def __init__(self, nom, prenom, adresse, typeAbonnement): def __init__(self,id, nom, prenom, adresse, typeAbonnement):
while True:
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
range(random.randint(1, 10)))
if Client.get(id) is None:
break
self.__id = id
self.__nom = nom self.__nom = nom
self.__prenom = prenom self.__prenom = prenom
self.__typeAbonnement = typeAbonnement self.__typeAbonnement = typeAbonnement
self.__adresse = adresse self.__adresse = adresse
self.clients.append(self)
if id is None:
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)
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:
self.__id = id
@property @property
def prenom(self): def prenom(self):
@ -42,46 +61,14 @@ class Client():
def abonnement(self): def abonnement(self):
return self.__typeAbonnement return self.__typeAbonnement
@staticmethod
def get(id):
for client in Client.clients:
if client.id == id:
return client
return None
@staticmethod
def loadAll(connection):
with connection:
connection.row_factory = sqlite3.Row
cur = connection.cursor()
cur.execute("SELECT * FROM Client")
rows = cur.fetchall()
for row in rows:
Client(row["num"], row["nom"], row["prenom"], row["adr"], int(row["abo"]))
connection.close()
@staticmethod
def saveAll(connection):
cur = connection.cursor()
# reset table Client
cur.execute("DROP TABLE IF EXISTS Client")
cur.execute(
"""create table Client (num varchar(10) PRIMARY KEY, nom varchar(30), prenom varchar(30), adr varchar(50), abo int(1))""")
# insert clients
for c in Client.tous:
cur.execute("insert into Client values (?, ?, ?, ?, ?)", (c.id, c.nom, c.prenom, c.adr, c.abonnement))
connection.commit()
connection.close()
def maj(self, nom, prenom, adresse, typeAbonnement):
self.__nom = nom
self.__prenom = prenom
self.__typeAbonnement = typeAbonnement
self.__adresse = adresse
def __str__(self): def __str__(self):
return "( " + self.__id + ", " + self.__nom + ", " + self.__prenom + ", " + self.__adresse + ", " + str( return "[Client :" \
self.__typeAbonnement) + " )" " 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

View File

@ -1,26 +0,0 @@
__author__ = 'sidya'
class connexionBDD:
def __init__(self):
try:
self.__conn = sqlite3.connect("BD.sql3")
self.__cur = self.__conn.cursor()
except Exception as e:
pass # later
def seDeconnecter(self):
self.__cur.close()
self.__conn.close()
def execute(self, req):
try:
r = self.__cur.execute(req)
self.__conn.commit()
except Exception as e:
pass # later
return r
def lastId(self):
return self.__cur.lastrowid

View File

@ -1,23 +0,0 @@
from src.m.connexionBDD import connexionBDD
class Contrat:
def __init__(self, dateDebut, dateFin):
self.dateDebut = dateDebut
self.dateFin = dateFin
def enregistrerContrat(self):
connection = connexionBDD()
connection.cur.execute("INSERT INTO contrat (idContrat,dateDebut,dateFin, estEncours) VALUES (NULL,?,?,1);",
( self.dateDebut, self.dateFin, 1))
connection.seDeconnecter()
def rompreContrat(self, idCLient):
connection = connexionBDD()
indContrat = connection.cur.execute(
"SELECT Contrat.idContrat FROM contrat where idClient =? AND dateDebut = ? AND dateFin=? ;"(idCLient,
self.dateDebut,
self.dateFin))
idContrat = int(''.join(map(str, indContrat)))
connection.cur.execute("Update contrat where idContrat=? set estEnCours =0;", ( idContrat))
connection.seDeconnecter()

View File

@ -1,19 +0,0 @@
from src.m.Service import Service
from src.m.connexionBDD import connexionBDD
class Entretien(Service):
def __init__(self, jourService, moisService, anneeService, jourDemande, moisDemande, anneeDemande, rapport,
categorie, idClient):
super(Service, self).__init__(self, jourService, moisService, anneeService, jourDemande, moisDemande,
anneeDemande, rapport, categorie)
self.categorie = 2
self.etat = 0
self.idService = self.enregistrerService(self, idClient, self.categorie, self.etat)
def effectuerEntretien(self):
self.etat = 1
connexion = connexionBDD()
connexion.cur.execute("UPDATE service SET etat= 1 WHERE idService = ?", (self.idService))
connexion.seDeconnecter()

View File

@ -1,26 +0,0 @@
from src.m.TypePlace import TypePlace
__author__ = 'sidya'
class ListeTypePlace:
"""
Classe qui permet de définir une liste de type de place par niveau pour la création d'un parking
"""
def __init__(self):
self.l = []
def add(self, h, l, nb):
self.l.append(TypePlace(h, l, nb))
@property
def nbPlaceTotal(self):
i = 0
for t in self.l:
i += t.nb
return i
@property
def liste(self):
return self.l

View File

@ -1,29 +0,0 @@
import calendar
from src.m.Service import Service
from src.m.connexionBDD import connexionBDD
class Livraison(Service):
def __init__(self, jourService, moisService, anneeService, jourDemande, moisDemande, anneeDemande, rapport,
categorie, idClient):
super(Service, self).__init__(self, jourService, moisService, anneeService, jourDemande, moisDemande,
anneeDemande, rapport, categorie)
self.categorie = 3
self.etat = 0
# 3.Obtenir l'idVoiturier: en recherchant celui qui est disponible le jour en question
self.idService = self.enregistrerService(self, idClient, self.categorie, self.etat)
jour = calendar.weekday(self.dateService._day, self.dateService._month, self.dateService._year)
connexion = connexionBDD()
indiceVoiturier = connexion.cur.execute(
"SELECT voiturier.idVoiturier FROM voiturier WHERE voiturier.joursDisponible = ?; ", (jour))
idVoiturier = int(''.join(map(str, indiceVoiturier)))
connexion.cur.execute("UPDATE service SET idVoiturier= ? WHERE idService = ?", (idVoiturier, self.idService))
connexion.seDeconnecter()
def effectuerLivraison(self):
self.etat = 1
connexion = connexionBDD()
connexion.cur.execute("UPDATE service SET etat= 1 WHERE idService = ?", (self.idService))
connexion.seDeconnecter()

View File

@ -1,18 +0,0 @@
from src.m.Service import Service
from src.m.connexionBDD import connexionBDD
class Maintenance(Service):
def __init__(self, jourService, moisService, anneeService, jourDemande, moisDemande, anneeDemande, rapport,
categorie, idClient):
super(Service, self).__init__(self, jourService, moisService, anneeService, jourDemande, moisDemande,
anneeDemande, rapport, categorie)
self.categorie = 1
self.etat = 0
self.idService = self.enregistrerService(self, idClient, self.categorie, self.etat)
def effectuerMaintenance(self):
self.etat = 1
connexion = connexionBDD()
connexion.cur.execute("UPDATE service SET etat= 1 WHERE idService = ?", (self.idService))

View File

@ -1,30 +1,44 @@
from src.m.Place import Place import random
import string
import datetime
from src.m.Voiture import Voiture
from src.m.connexionBDD import connexionBDD
__author__ = 'sidya' __author__ = 'sidya'
class Parking: class Parking:
""" parkings = []
Definie un parking
"""
def __init__(self, typePlaces, nom): @staticmethod
""" def get(id):
Creer objet parking for p in Parking.parkings :
:param typePlaces: ListeTypePlace if p.id == id :
:param nom: str return p
:return:
""" @staticmethod
self.__typePlaces = typePlaces def getAll():
return Parking.parkings
def __init__(self, nom, listeTypePlace):
self.__nom = nom self.__nom = nom
self.__prix = 10 c = connexionBDD()
self.__Places = {} c.execute("INSERT INTO parking (nom) VALUES ('"+str(self.__nom)+"')", ())
l = [] self.__id = c.lastId()
for t in typePlaces.liste:
for i in range(0, t.nb):
l.append(Place(i + 1, 1, t.longueur, t.hauteur))
self.__Places = l
#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
self.parkings.append(self)
@property
def id(self):
return self.__id
@property @property
def nom(self): def nom(self):
@ -32,16 +46,15 @@ class Parking:
@property @property
def nbPlaces(self): def nbPlaces(self):
return self.__typePlaces.nbPlaceTotal return Place.nbPlaceParking(self.__id)
@property @property
def nbPlacesLibresParking(self): def nbPlacesLibresParking(self):
i = 0 return Place.nbPlaceLibreParking(self.__id)
for p in self.__Places:
if p.estLibre: @property
i += 1 def nbSuperAbo(self):
return i return Place.nbSuperAbo(self.__id)
def recherchePlace(self, voiture): def recherchePlace(self, voiture):
""" """
@ -49,17 +62,240 @@ class Parking:
:param voiture: Voiture :param voiture: Voiture
:return: Place :return: Place
""" """
place = None return Place.placeValide(self.__id, voiture)
for p in self.__Places:
if p.estLibre and p.dimValide(voiture.getHauteur, voiture.getLongueur):
pass
place = p
break
return place
def addAbonnement(self, Abonnement):
pass
def __str__(self): def __str__(self):
return "Parking : niveau : " + str(self.__nbNiveaux) 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
if id is None :
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)))
self.__id = c.lastId()
c.seDeconnecter()
else :
self.__id = id
def prendre(self):
"""
Rend la place indisponible
:param Placement:
:return:
"""
if (self.__estLibre == False):
raise Exception("Place déjà prise")
self.__estLibre = False
c = connexionBDD()
c.execute("UPDATE place SET estLibre = 0 WHERE idPlace = ?", (str(self.__id)))
c.seDeconnecter()
def liberer(self):
"""
Libere une place non dispo
:return:
"""
if (self.__estLibre == True):
raise Exception("Impossible de liberer une place vide")
self.__estLibre = False
c = connexionBDD()
c.execute("UPDATE place SET estLibre = 1 WHERE idPlace = ?", (str(self.__id)))
c.seDeconnecter()
@staticmethod
def nbPlaceParking(idParking):
c = connexionBDD()
print("lol")
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ?", (str(idParking)))
row = r.fetchone()
c.seDeconnecter()
return row[0]
@staticmethod
def nbPlaceLibreParking(idParking):
c = connexionBDD()
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ? AND estLibre = 1", (str(idParking)))
row = r.fetchone()
c.seDeconnecter()
return row[0]
@staticmethod
def nbSuperAbo(idParking):
c = connexionBDD()
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ? AND estSuperAbo = 1", (str(idParking)))
row = r.fetchone()
c.seDeconnecter()
return row[0]
@staticmethod
def placeValide(idPArking, voiture):
c = connexionBDD()
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)))
row = r.fetchone()
c.seDeconnecter()
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"]))
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
if id is None :
c = connexionBDD()
c.execute("INSERT INTO typePlace (longueur,hauteur,nombre) VALUES (?,?,?)",
(self.__longueur, self.__hauteur, self.__nombre))
self.__id = c.lastId()
c.seDeconnecter()
else:
self.__id = id
@property
def id(self):
return self.__id
@property
def longueur(self):
return self.__longueur
@property
def hauteur(self):
return self.__hauteur
@property
def nombre(self):
return self.__nombre
def __str__(self):
return "[TypePlace : " \
"id = " + str(self.__id) + "," \
"longueur = " + str(self.__longueur) + "," \
"hauteur = " + str(self.hauteur) + "," \
"nombre = " + str(self.nombre) + "]"
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):
"""
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.__fin = None
while True:
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
range(random.randint(1, 10)))
try:
Placement.get(id)
except IndexError:
break
c = connexionBDD()
c.execute("INSERT INTO placement (idPlacement,idVoiture,idPlace, debut, fin) VALUES (?,?,?,?,?)",
(str(id), str(self.__voiture.id), str(self.__place.id), str(self.__debut), "NULL"))
self.__id = id
c.seDeconnecter()
else:
self.__id = id
self.__debut = debut
self.__fin = fin
@property
def id(self):
return self.__id
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)

View File

@ -1,79 +0,0 @@
__author__ = 'sidya'
class Place:
"""
Representation d'une place
"""
def __init__(self, numero, niveau, longueur, hauteur):
"""
Creer une place.
Les dimensions doivent etre données en cm (longueur, hauteur)
:param numero: int
:param niveau: int
:param longueur: int
:param hauteur: int
:return:
"""
self.__numero = numero
self.__niveau = niveau
self.__longueur = longueur
self.__hauteur = hauteur
self.__estLibre = True
self.__estSuperAbo = False
self.__Placement = None
@property
def estLibre(self):
return self.__estLibre
@property
def estReserver(self):
return self.__estSuperAbo
def dimValide(self, h, l):
"""
Retourn si un element de hauteur (cm) h et de longueur(cm) l passe dans la place
:param h: int
:param l: int
:return: bool
"""
return h < self.__hauteur and l < self.__longueur
def superAbo(self):
"""
Renvoit si la place est une place superAbo
:return: bool
"""
if (self.__estSuperAbo == True):
raise Exception("Place déjà reservé")
self.__estSuperAbo = True
def prendre(self):
"""
Rend la place indisponible
:param Placement:
:return:
"""
if (self.__estLibre == False):
raise Exception("Place déjà prise")
self.__estLibre = False
def liberer(self):
"""
Libere une place non dispo
:return:
"""
if (self.__estLibre == True):
raise Exception("Impossible de liberer une place vide")
self.__estLibre = True

View File

@ -1,53 +0,0 @@
import datetime
import random
import string
__author__ = 'sidya'
class Placement:
placements = []
def __init__(self, voiture, place):
"""
Creer un placement
:param voiture: Voiture
:param place: Place
:return:
"""
while True:
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
range(random.randint(1, 10)))
if Placement.get(id) is None:
break
self.__id = id
self.__voiture = voiture
self.__place = place
self.__debut = datetime.datetime
self.__fin = None
place.prendre()
self.placements.append(self)
def end(self):
self.__fin = datetime.datetime
self.__place.liberer()
@property
def id(self):
return self.__id
@staticmethod
def get(id):
"""
Recupere le Placement d'id id
:param id: str
:return: Placement or None
"""
for p in Placement.placements:
if p.__id == id:
return p
return None
@property
def estEnCours(self):
return datetime.datetime < self.__fin

View File

@ -1,49 +1,4 @@
import calendar __author__ = 'sidya'
import datetime
from src.m.connexionBDD import connexionBDD
class Service: class Service:
def __init__(self, jourService, moisService, anneeService, jourDemande, moisDemande, anneeDemande, rapport): pass
try:
dateService = datetime.date(anneeService, moisService, jourService)
self.dateService = dateService
except:
# Si la date n'est pas un nombre ou bien si ceux ci sont abérrents
print("la date de service n\'est pas correcte")
try:
dateDemande = datetime.date(anneeDemande, moisDemande, jourDemande)
self.dateDemande = dateDemande
except:
print("la date de service n\'est pas correcte")
self.rapport = rapport
def enregistrerService(self, idClient, categorie, etat):
try:
connection = connexionBDD()
# 1.obtenir id service (fonction max de sqlite ne marche pas bien...elle ne prend en compte que le premier chiffre. Ex: max(56,9)= 9... )
connection.cur.execute("SELECT count(service.idSercice) FROM service;")
# entrée dans la base de donnée
indiceidSer = connection.cur.execute("SELECT count(service.idService) FROM service;")
idService = int(''.join(map(str, indiceidSer))) + 1
#2. obtenir l'idClient: définir une variable globale lors de l'execution du "jeu"
#3.Obtenir l'idVoiturier: en recherchant celui qui est disponible le jour en question
jour = calendar.weekday(self.dateService._day, self.dateService._month, self.dateService._year)
indiceVoiturier = connection.cur.execute(
"SELECT voiturier.idVoiturier FROM voiturier WHERE voiturier.joursDisponible = ?; ", (jour))
idVoiturier = int(''.join(map(str, indiceVoiturier)))
connection.cur.execute(
"INSERT INTO service (idService,dateService,dateDemande,rapport,idClient,idVoiturier,idService, idVoiturier, categorie, etat) VALUES (?,?,?,?,?,?,?,?,?,?);",
(idService, self.dateService, self.dateDemande, self.rapport, idClient, idVoiturier, idService,
categorie, etat))
connection.seDeconnecter()
return idService
except Exception as e:
print
str(e)
pass

View File

@ -1,6 +0,0 @@
__author__ = 'sidya'
class TypeAbonnement:
ABONNE = 0
SUPER_ABONNE = 1

View File

@ -1,24 +0,0 @@
__author__ = 'sidya'
class TypePlace:
"""
Classe qui permet de définir un type de place
"""
def __init__(self, h, l, nb):
self.__hauteur = h
self.__longueur = l
self.__nb = nb
@property
def hauteur(self):
return self.__hauteur
@property
def longueur(self):
return self.__longueur
@property
def nb(self):
return self.__nb

View File

@ -1,26 +1,57 @@
class Voiture(): from src.m.connexionBDD import connexionBDD
def __init__(self, longueur, hauteur, imma):
self._hauteur = hauteur __author__ = 'sidya'
self._longueur = longueur
self._immatriculation = imma class Voiture:
self._estDansParking = False @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
if id is None :
c = connexionBDD()
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:
self.__id = id
@property @property
def getHauteur(self): def id(self):
return self._hauteur return self.__id
@property @property
def getLongueur(self): def hauteur(self):
return self._longueur return self.__hauteur
@property @property
def getImmatriculation(self): def longueur(self):
return self._immatriculation return self.__longueur
@property
def immatriculation(self):
return self.__immatriculation
@property @property
def estDansParking(self): def estDansParking(self):
return self._estDansParking == True return self.__estDansParking == True
# def addPlacement(self, placement):
def __str__(self):
return "[Voiture :" \
" longueur = " +self.__longueur + ", " \
" hauteur = " +self.__hauteur + ", " \
" imma = " +self.__imma + ", " \
" estDansParking = " +self.__estDansParking + "]"

View File

@ -1,28 +0,0 @@
import time
from src.m.connexionBDD import connexionBDD
class Voiturier:
def __init__(self, id, nom, prenom):
self.numero = id
self.nom = nom
self.prenom = prenom
def enregistrerVoiturier(self, nom, prenom, dateEmbauche):
connexion = connexionBDD()
# entrée dans la base de donnée
indiceidVoiturier = connexion.cur.execute("SELECT count(voiturier.idVoiturier) FROM voiturier;") + 1
idVoiturier = int(''.join(map(str, indiceidVoiturier))) + 1
connexion.cur.execute("INSERT INTO voiturier (idVoiturier,nom, prenom, dateEmbauche) VALUES (?,?,?,?);",
(self.idVoiturier, nom, prenom, dateEmbauche))
connexion.seDeconnecter()
def livrerVoiture(self):
dateJour = time.strptime()
connexion = connexionBDD()
indiceLivraison = connexion.cur.execute("SELECT count(voiturier.idVoiturier) FROM voiturier;")
idLivraison = int(''.join(map(str, indiceLivraison))) + 1
connexion.cur.execute("INSERT INTO livraison (idLivraison,dateLivraison, idVoiturier) VALUES (?,?,?,?);",
(idLivraison, dateJour, self.idVoiturier))
connexion.seDeconnecter()

View File

@ -1,12 +1,32 @@
import sqlite3 __author__ = 'sidya'
import sqlite3
class connexionBDD: class connexionBDD:
def __init__(self): def __init__(self):
self.chemin = "BDDprojetPython.sq3" self.__chemin = "m/BDDprojetPython.sq3"
self.conn = sqlite3.connect(self.chemin) self.__conn = sqlite3.connect(self.__chemin)
self.cur = self.conn.cursor() 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): def seDeconnecter(self):
self.cur.close() self.__cur.close()
self.conn.close() self.__conn.close()
def initialisationBDD(self):
with open("m/table.sql") as f:
sql = f.read()
self.__conn.executescript(sql)
self.__conn.commit()

View File

@ -1,27 +1,75 @@
DROP TABLE IF EXISTS service;
DROP TABLE IF EXISTS contrat;
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 ( CREATE TABLE parking (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, idParking INTEGER PRIMARY KEY ,
nom VARCHAR(30), nom VARCHAR(30)
); );
CREATE TABLE place (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
idParking INT UNSIGNED FOREIGN KEY,
idType INT UNSIGNED FOREIGN KEY,
niveau INT UNSIGNED,
numero INT UNSIGNED
);
CREATE TABLE typePlace ( CREATE TABLE typePlace (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, idTypePlace INTEGER PRIMARY KEY ,
longueur INT UNSIGNED, longueur INTEGER ,
hauteur INT UNSIGNED, hauteur INTEGER ,
largeur INT UNSIGNED, nombre INTEGER
estLibre INT(1),
estSuperAbo int(1)
); );
CREATE TABLE place (
idPlace INTEGER PRIMARY KEY ,
idParking INTEGER ,
idTypePlace INTEGER ,
niveau INTEGER ,
numero INTEGER ,
estLibre INTEGER(1),
estSuperAbo INTEGER(1),
FOREIGN KEY (idParking) REFERENCES parking(id),
FOREIGN KEY (idTypePlace) REFERENCES typePlace(id)
);
CREATE TABLE voiture (
idVoiture INTEGER PRIMARY KEY ,
hauteur INTEGER ,
longueur INTEGER ,
imma VARCHAR(10),
estDansParking INTEGER(1)
);
CREATE TABLE placement ( 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)
);
CREATE TABLE client (
idClient VARCHAR(10) PRIMARY KEY ,
nom VARCHAR(20),
prenom VARCHAR(20),
adresse VARCHAR(50),
typeAbonnement INTEGER
);
CREATE TABLE service (
idService INTEGER PRIMARY KEY ,
idClient VARCHAR(10),
dateDemande DATE,
dateService DATE,
dateRealisation DATE,
rapport VARCHAR(255),
FOREIGN KEY (idClient) REFERENCES client(id)
); );

View File

@ -1,16 +0,0 @@
__author__ = 'sidya'
from nose.tools import assert_equal
from src.m.Parking import Parking
class TestParking:
def recherchePlace(self):
"""
Test d'attribution des places
"""
p = Parking()
assert_equal()

View File

@ -1,5 +0,0 @@
__author__ = 'sidya'
class TestPlace:
pass

View File

@ -1 +0,0 @@
__author__ = 'sidya'

View File

View File

@ -1,14 +0,0 @@
__author__ = 'nadiel'
class testClient:
# def testsAbonner:
def testnouvelleVoiture(self):
assert ()
#v = Voiture()
#def testTailleMax(self):
# c = Camera()
# assert (c.capturerHauteur()>1.5)

View File

@ -1,5 +0,0 @@
from src.m.placement import Placement
class testPlacement:
def test_init(self):
newPlacement = Placement()

View File

@ -1,7 +0,0 @@
class testService:
"""Fonction qui vérifie si la date insérée cest dans un format correcte (année est égale à l'année courante, 01≤jour≤31 et 01≤mois≤12); renvoie une erreur sinon"""
def testFormatDate(self, jourInsere, moisInsere, anneeInsere):

View File

@ -12,5 +12,5 @@ class Camera:
def donnerVoiture(self): def donnerVoiture(self):
v = Voiture(random.randint(150, 300), random.randint(100, 200), ''.join( v = Voiture(random.randint(150, 300), random.randint(100, 200), ''.join(
random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
range(random.randint(1, 10)))) range(random.randint(1, 10))),False)
return v return v

View File

@ -18,4 +18,5 @@ class MyQWidget(QtGui.QWidget):
if result == QtGui.QMessageBox.Yes: if result == QtGui.QMessageBox.Yes:
event.accept() event.accept()
self.__main.showWindow() self.__main.showWindow()
self.w = QtGui.QWidget

78
src/v/Ui_Service.py Normal file
View File

@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'service.ui'
#
# Created: Mon Jan 12 17:07:46 2015
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Service(object):
def setupUi(self, Service):
Service.setObjectName(_fromUtf8("Service"))
Service.resize(469, 221)
self.btn_valider = QtGui.QPushButton(Service)
self.btn_valider.setGeometry(QtCore.QRect(260, 180, 87, 27))
self.btn_valider.setObjectName(_fromUtf8("btn_valider"))
self.dateTimeEdit = QtGui.QDateTimeEdit(Service)
self.dateTimeEdit.setGeometry(QtCore.QRect(330, 60, 121, 23))
self.dateTimeEdit.setObjectName(_fromUtf8("dateTimeEdit"))
self.btn_annuler = QtGui.QPushButton(Service)
self.btn_annuler.setGeometry(QtCore.QRect(120, 180, 87, 27))
self.btn_annuler.setObjectName(_fromUtf8("btn_annuler"))
self.formLayoutWidget = QtGui.QWidget(Service)
self.formLayoutWidget.setGeometry(QtCore.QRect(160, 60, 160, 41))
self.formLayoutWidget.setObjectName(_fromUtf8("formLayoutWidget"))
self.formLayout = QtGui.QFormLayout(self.formLayoutWidget)
self.formLayout.setMargin(0)
self.formLayout.setObjectName(_fromUtf8("formLayout"))
self.lieuLabel = QtGui.QLabel(self.formLayoutWidget)
self.lieuLabel.setObjectName(_fromUtf8("lieuLabel"))
self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.lieuLabel)
self.lieuLineEdit = QtGui.QLineEdit(self.formLayoutWidget)
self.lieuLineEdit.setObjectName(_fromUtf8("lieuLineEdit"))
self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.lieuLineEdit)
self.widget = QtGui.QWidget(Service)
self.widget.setGeometry(QtCore.QRect(50, 50, 109, 121))
self.widget.setObjectName(_fromUtf8("widget"))
self.verticalLayout = QtGui.QVBoxLayout(self.widget)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.checkBox_Livraison = QtGui.QCheckBox(self.widget)
self.checkBox_Livraison.setObjectName(_fromUtf8("checkBox_Livraison"))
self.verticalLayout.addWidget(self.checkBox_Livraison)
self.checkBox_Maintenance = QtGui.QCheckBox(self.widget)
self.checkBox_Maintenance.setObjectName(_fromUtf8("checkBox_Maintenance"))
self.verticalLayout.addWidget(self.checkBox_Maintenance)
self.checkBox_Entretien = QtGui.QCheckBox(self.widget)
self.checkBox_Entretien.setObjectName(_fromUtf8("checkBox_Entretien"))
self.verticalLayout.addWidget(self.checkBox_Entretien)
self.retranslateUi(Service)
QtCore.QMetaObject.connectSlotsByName(Service)
def retranslateUi(self, Service):
Service.setWindowTitle(_translate("Service", "Form", None))
self.btn_valider.setText(_translate("Service", "Valider", None))
self.btn_annuler.setText(_translate("Service", "Annuler", None))
self.lieuLabel.setText(_translate("Service", "Lieu", None))
self.checkBox_Livraison.setText(_translate("Service", "Livraison", None))
self.checkBox_Maintenance.setText(_translate("Service", "Maintenance", None))
self.checkBox_Entretien.setText(_translate("Service", "Entretien", None))