-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
286 lines (252 loc) · 10.1 KB
/
main.py
File metadata and controls
286 lines (252 loc) · 10.1 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
from os import access
from PySide2.QtWidgets import (
QApplication,
QMainWindow,
QWidget,
QMessageBox,
QTreeWidgetItem,
)
from models.os import Os
from ui_login import Ui_Form
from OS_SIMAP_beta import Ui_MainWindow
import sys
from models.database import DataBase
from models.users import Users
from datetime import datetime
class Login(QWidget, Ui_Form):
def __init__(self) -> None:
super(Login, self).__init__()
self.tentativas = 0
self.setupUi(self)
self.setWindowTitle("Login do Sistema")
self.btn_login.clicked.connect(self.checkLogin)
self.db_instance = DataBase()
def checkLogin(self):
db_conn = self.db_instance.create_connection()
autenticado = Users(db_conn).check_user(
self.txt_login.text().upper(), self.txt_password.text()
)
if autenticado.lower() == "administrador" or autenticado.lower() == "user":
self.w = MainWindow(autenticado.lower())
self.w.show()
self.close()
else:
if self.tentativas < 3:
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Erro ao acessar")
msg.setText(
f"Login ou Senha inválidos \n \n Tentativa: {self.tentativas +1} de 3"
)
msg.exec_()
self.tentativas += 1
if self.tentativas == 3:
self.db_instance.close_connection(db_conn)
sys.exit(0)
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, user):
super(MainWindow, self).__init__()
self.setupUi(self)
self.setWindowTitle("Sistema de Manutenção Patrimonial de TI")
self.db_instance = DataBase()
if user.lower() == "user":
self.btn_pg_cadastro.setVisible(False)
# self.btn_editar.setVisible(False)
self.btn_excluir.setVisible(False)
self.btn_gerar.blockSignals(True)
# *****************PÁGINAS DO SISTEMA******************
self.btn_home.clicked.connect(lambda: self.Pages.setCurrentWidget(self.pg_home))
self.btn_pg_cadastro.clicked.connect(
lambda: self.Pages.setCurrentWidget(self.pg_cadastro)
)
self.btn_gerar.clicked.connect(lambda: self.Pages.setCurrentWidget(self.pg_os))
self.btn_consultar_os.clicked.connect(
lambda: self.Pages.setCurrentWidget(self.pg_consultar)
)
self.btn_cadastrar.clicked.connect(self.subscribe_user)
self.btn_gravar.clicked.connect(self.save_os)
# self.btn_editar.clicked.connect(self.edit_os)
self.btn_excluir.clicked.connect(self.remove_os)
self.btn_consultar.clicked.connect(self.list_os)
self.btn_sair.clicked.connect(lambda: self.Pages.setCurrentWidget(self.pg_home))
# self.treeWidget.itemClicked.connect(self.onItemClicked)
def subscribe_user(self):
if self.txt_senha.text() != self.txt_senha_2.text():
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Erro de senha")
msg.setText("Senhas não são iguais.")
msg.exec()
return None()
nome = self.txt_nome.text()
user = self.txt_usuario.text()
password = self.txt_senha.text()
access = self.cb_perfil.currentText()
db_conn = self.db_instance.create_connection()
Users(db_conn).insert_user(nome, user, password, access)
self.db_instance.close_connection(db_conn)
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Cadastro de usuário")
msg.setText("Cadastro realizado com sucesso!")
msg.exec()
self.txt_nome.setText("")
self.txt_usuario.setText("")
self.txt_senha.setText("")
self.txt_senha_2.setText("")
def save_os(self):
num_os = self.txt_num_os.text()
status = "Fechada" if self.cb_close.isChecked() else "Aberta"
dt_os = self.dt_emissao.date().toPython()
hr_os = self.dt_horario.time().toPython()
dt_end = self.dt_fechamento.dateTime()
customer = self.txt_solicitante.text()
technical_manager = self.txt_responsavel.text()
service_type = self.cb_tipo.currentText()
service_start_dt = self.dt_inicio.dateTime()
service_end_dt = self.dt_termino.dateTime()
service_description = self.plainTextEdit.toPlainText()
equip_number = self.txt_num_patrimonio.text()
equip_description = self.txt_equipamento.text()
equip_model = self.txt_modelo.text()
equip_brand = self.txt_marca.text()
equip_props = self.txt_acessorios.text()
equip_defect = self.plainTextEdit_4.toPlainText()
equip_obs = self.plainTextEdit_3.toPlainText()
parts_used = self.plainTextEdit_2.toPlainText()
part_type = self.txt_tipo.text()
part_qtd = self.sb_qtde.text()
part_price = self.txt_preco.text()
part_total = self.txt_valor.text()
# formatting date to save in database
dt_hr_os = str(dt_os) + " " + str(hr_os)
if dt_end:
dt_end = dt_end.toPython()
if service_start_dt:
service_start_dt = service_start_dt.toPython()
if service_end_dt:
service_end_dt = service_end_dt.toPython()
os_data = (
status,
dt_hr_os,
dt_end,
customer,
technical_manager,
service_start_dt,
service_end_dt,
service_description,
service_type,
equip_number,
equip_brand,
equip_description,
equip_model,
equip_props,
equip_defect,
equip_obs,
parts_used,
part_type,
part_qtd,
part_price,
part_total,
int(num_os),
)
# Aqui precisa checar se o num_os já existe, caso existir será feito um update senão um create
db_conn = self.db_instance.create_connection()
created_id = Os(db_conn).insert_os(os_data)
self.db_instance.close_connection(db_conn)
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Nova Ordem de serviço")
if created_id[0]:
msg.setText(
"Ordem de serviço: {} inserida com sucesso!".format(created_id[1])
)
else:
msg.setText("Não foi possível inserir nova Ordem de serviço!")
msg.exec()
def list_os(self):
# Get data from form
num_os = self.txt_num_os_consulta.text()
equip_inventory = self.txt_num_patrimonio_consulta.text()
equip_description = self.txt_equipamento_consulta.text()
customer = self.txt_solicitante_consulta.text()
status = self.cb_status_consulta.currentText()
dt_os_start = self.dt_periodo_consulta.date()
dt_os_end = self.dateEdit_2.date()
# validate data
num_os = num_os if num_os else None
equip_inventory = equip_inventory if equip_inventory else None
equip_description = equip_description if equip_description else None
customer = customer if customer else None
status = status if status else None
if dt_os_start:
dt_os_start = str(dt_os_start.toPython()) + " 00:00:00"
else:
dt_os_start = None
if dt_os_end:
dt_os_end = str(dt_os_end.toPython()) + " 23:59:59"
else:
dt_os_end = None
# Open db connection
db_conn = self.db_instance.create_connection()
# Call method to fetch all OS by filter options
os_list = Os(db_conn).get_all_os(
id=num_os,
equip_inventory_number=equip_inventory,
equip_name=equip_description,
customer=customer,
status=status,
dt_start=dt_os_start,
dt_end=dt_os_end,
)
self.db_instance.close_connection(db_conn)
# First clear current table then list filtered items
self.treeWidget.clear()
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Consultar Ordens de serviço")
if len(os_list) > 0:
msg.setText("Busca realizada com sucesso!")
else:
msg.setText("Nenhuma ordem de serviço encontrada!")
msg.exec()
items = []
for os in os_list:
os_dt = os["created_at"]
os_dt = datetime.strptime(os_dt, "%Y-%m-%d %H:%M:%S")
os_dt = os_dt.strftime("%d/%m/%Y")
item = QTreeWidgetItem(
[
str(os["id"]),
os["customer"],
os["equip_inventory_number"],
os["equip_name"],
os_dt,
os["status"],
str(os["part_total"]),
]
)
items.append(item)
self.treeWidget.insertTopLevelItems(0, items)
def remove_os(self):
selected_os = self.treeWidget.currentItem()
os_num = selected_os.text(0)
if os_num:
db_conn = self.db_instance.create_connection()
result = Os(db_conn).delete_os(os_num)
self.db_instance.close_connection(db_conn)
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Remover Ordem de serviço")
if result:
msg.setText("Ordem de serviço removida com sucesso!")
else:
msg.setText("Não foi possível remover esta ordem de serviço!")
msg.exec()
self.list_os()
if __name__ == "__main__":
DataBase().main()
app = QApplication(sys.argv)
window = Login()
window.show()
app.exec_()