-
Notifications
You must be signed in to change notification settings - Fork 0
/
trabalho.py
93 lines (78 loc) · 2.8 KB
/
trabalho.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sqlite3
import sys
from PyQt5.QtCore import QTime
from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget, QMessageBox
from view.trabalhoUi import Ui_Form
class TrabalhoWindow(QWidget, Ui_Form):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setupUi(self)
self.popula_lista()
self.center()
self.btnLim_tim.clicked.connect(self.on_btn_limpar_pressed)
self.btnAdd_hor.clicked.connect(self.on_btn_add_pressed)
self.btnDel_hor.clicked.connect(self.on_btn_del_pressed)
self.listTra.clicked.connect(self.setar_campo)
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def on_btn_limpar_pressed(self):
self.timHor.setTime(QTime(0, 0))
def popula_lista(self):
self.listTra.clear()
db = sqlite3.connect('dbmehsys.db')
cursor = db.cursor()
sql = 'select horario from horarios order by horario'
try:
cursor.execute(sql)
rs = cursor.fetchall()
for i in range(len(rs)):
self.listTra.addItem(rs[i][0])
cursor.close()
db.close()
except Exception as e:
db.close()
QMessageBox.warning(self, 'ERRO!!!', str(e))
def setar_campo(self):
selected = self.listTra.currentItem().text()
hor = int(selected[0:2])
min = int(selected[3:5])
self.timHor.setTime(QTime(hor, min))
def on_btn_add_pressed(self):
db = sqlite3.connect('dbmehsys.db')
cursor = db.cursor()
sql = 'insert into horarios (horario) values (?)'
horario = self.timHor.text()
try:
cursor.execute(sql, [horario])
db.commit()
cursor.close()
db.close()
except Exception as e:
cursor.close()
db.close()
QMessageBox.critical(self, 'ERRO!!!', f'ESTE HORÁRIO JÁ FOI ADICIONADO!\n\n"{str(e)}"')
self.on_btn_limpar_pressed()
self.popula_lista()
def on_btn_del_pressed(self):
db = sqlite3.connect('dbmehsys.db')
cursor = db.cursor()
sql = 'delete from horarios where horario=?'
horario = self.timHor.text()
try:
cursor.execute(sql, [horario])
db.commit()
cursor.close()
except Exception as e:
cursor.close()
db.close()
QMessageBox.critical(self, 'ERRO!!!', f'HORÁRIO NÃO ENCONTRADO NO BANCO DE DADOS!\n\n"{str(e)}"')
self.on_btn_limpar_pressed()
self.popula_lista()
if __name__ == '__main__':
app = QApplication(sys.argv)
trabalho = TrabalhoWindow()
trabalho.show()
app.exec_()