1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| class Form(QWidget, Ui_Form):
def __init__(self, parent = None, bdd = None):
QWidget.__init__(self, parent)
self.setupUi(self)
self.actuCombo()
self.bdd = bdd
def actuCombo(self):
self.cbSalon.clear()
self.cbSalon.addItems(self.bdd.ListeSalon())
@pyqtSlot()
def on_BtSalon_clicked(self):
liste = [self.cbSalon.currentText(), self.dtDebut.date(), self.dtFin.date(), self.EditVilleSalon.text(), self.EditBudget.text(),
self.EditDescriptif.text(), self.EditIntervenant.text(), self.EditInteret.text()]
if self.BtSalon.text() == "Créer un nouveau salon":
self.cbSalon.setEditable(True)
self.BtSalon.setText("Enregistrer les modifications")
elif self.BtSalon.text() == "Enregistrer les modifications":
self.bdd.WriteTableSalon(liste)
class Salon():
def __init__(self, bdd):
self.bdd = bdd
def CreateTableSalon(self):
query = QtSql.QSqlQuery()
query.exec_('''create table if not exists salon (
id INTEGER PRIMARY KEY NOT NULL,
salon VARCHAR(45) NOT NULL ,
dtDebut VARCHAR(45) NULL ,
dtFin VARCHAR(45) NULL ,
ville VARCHAR(5) NULL ,
budget VARCHAR(45) NULL ,
descriptif VARCHAR(45) NULL ,
intervenant VARCHAR(45) NULL ,
interet VARCHAR(45) NULL )''')
query.finish()
self.bdd.commit()
#print (query.lastError().text())
def WriteTableSalon(self, liste):
model = QtSql.QSqlTableModel()
model.setTable('salon')
model.select()
model.insertRows(0, 1)
a = 0
while a <= 7:
model.setData(model.index(0, a+1), liste[a])
a+=1
model.submitAll()
def ListeSalon(self):
liste = [""]
model = QtSql.QSqlTableModel()
model.setTable("salon")
model.select()
nb_row = model.rowCount()
a = 0
while a < nb_row:
record = model.record(a)
salon = record.value("salon")
liste.append(salon)
a +=1
liste.sort()
return liste
Form(self.Form, self.bddSalon)
Form.show() |
Partager