-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (62 loc) · 2.26 KB
/
main.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
from PyQt6.QtWidgets import QApplication, QMainWindow
from PyQt6 import uic
from PyQt6 import QtCore
from PyQt6.QtCore import Qt
import sys
import sqlite3
class TableModel(QtCore.QAbstractTableModel):
def __init__(self, data):
super(TableModel, self).__init__()
self._data = data
def data(self, index, role):
if role == Qt.ItemDataRole.DisplayRole:
return self._data[index.row()][index.column()]
def rowCount(self, index):
return len(self._data)
def columnCount(self, index):
return len(self._data[0])
class Ui(QMainWindow):
def __init__(self, database):
super(Ui, self).__init__()
self.formvendas = uic.loadUi('formVendas.ui', self)
self.conn = sqlite3.connect(database)
self.cursor = self.conn.cursor()
self.setFixedSize(307, 230)
self.btnEnviar.clicked.connect(self.enviar)
self.btnConsul.clicked.connect(self.consultar)
self.btnLimp.clicked.connect(self.limpar)
self.lista = uic.loadUi('formLista.ui')
self.lista.btnExcluir.clicked.connect(self.excluir)
self.table = self.lista.TableVendas
self.formvendas.show()
def enviar(self):
prod = self.lineProd.text()
prec = self.linePreco.text()
vend = self.lineName.text()
env = 'INSERT INTO Vendas (Produto, Preco, Vendedor) VALUES (?, ?, ?)'
self.cursor.execute(env, (prod, prec, vend))
self.conn.commit()
self.statusBar.showMessage('Dados enviados!', 5000)
self.lineProd.setText('')
self.linePreco.setText('')
self.lineName.setText('')
def consultar(self):
self.cursor.execute('SELECT * FROM Vendas')
data = self.cursor.fetchall()
self.model = TableModel(data)
self.table.setModel(self.model)
self.lista.show()
def limpar(self):
self.lineProd.setText('')
self.linePreco.setText('')
self.lineName.setText('')
def excluir(self):
self.lista.close()
iden = self.lista.lineExcl.text()
line = f'DELETE FROM Vendas WHERE id = {iden}'
self.cursor.execute(line)
self.conn.commit()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Ui('database.db')
app.exec()