-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdadosCliente.py
223 lines (187 loc) · 8.97 KB
/
dadosCliente.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
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
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'dadosCliente.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
### Imports sistema ###
import mysql.connector
import pandas as pd
### Arquivo variaveis de controle ###
import variaveisControle
### Variáveis de conexão com o banco de dados ###
host = variaveisControle.host
user = variaveisControle.user
password = variaveisControle.password
database = variaveisControle.database
class Ui_formDadosCliente(object):
def setupUi(self, formDadosCliente):
formDadosCliente.setObjectName("formDadosCliente")
formDadosCliente.resize(454, 273)
self.lb_nome = QtWidgets.QLabel(formDadosCliente)
self.lb_nome.setGeometry(QtCore.QRect(20, 40, 61, 31))
self.lb_nome.setObjectName("lb_nome")
self.txt_nome = QtWidgets.QLineEdit(formDadosCliente)
self.txt_nome.setGeometry(QtCore.QRect(100, 40, 331, 31))
self.txt_nome.setText("")
self.txt_nome.setObjectName("txt_nome")
self.lb_telefone = QtWidgets.QLabel(formDadosCliente)
self.lb_telefone.setGeometry(QtCore.QRect(20, 80, 71, 31))
self.lb_telefone.setObjectName("lb_telefone")
self.txt_telefone = QtWidgets.QLineEdit(formDadosCliente)
self.txt_telefone.setGeometry(QtCore.QRect(100, 80, 331, 31))
self.txt_telefone.setText("")
self.txt_telefone.setObjectName("txt_telefone")
self.lb_cidade = QtWidgets.QLabel(formDadosCliente)
self.lb_cidade.setGeometry(QtCore.QRect(20, 120, 61, 31))
self.lb_cidade.setObjectName("lb_cidade")
self.txt_cidade = QtWidgets.QLineEdit(formDadosCliente)
self.txt_cidade.setGeometry(QtCore.QRect(100, 120, 331, 31))
self.txt_cidade.setText("")
self.txt_cidade.setObjectName("txt_cidade")
self.bt_cancelar = QtWidgets.QPushButton(formDadosCliente)
self.bt_cancelar.setGeometry(QtCore.QRect(150, 180, 101, 51))
self.bt_cancelar.setStyleSheet("image: url(:/icon_cancelar/icons/cancelar.png);\n"
"background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 255, 255, 0));")
self.bt_cancelar.setText("")
self.bt_cancelar.setObjectName("bt_cancelar")
self.bt_cadastrar = QtWidgets.QPushButton(formDadosCliente)
self.bt_cadastrar.setGeometry(QtCore.QRect(260, 180, 101, 51))
self.bt_cadastrar.setStyleSheet("image: url(:/icon_cadastrar/icons/cadastrar.png);\n"
"background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgba(255, 255, 255, 0));")
self.bt_cadastrar.setText("")
self.bt_cadastrar.setObjectName("bt_cadastrar")
self.retranslateUi(formDadosCliente)
QtCore.QMetaObject.connectSlotsByName(formDadosCliente)
def retranslateUi(self, formDadosCliente):
_translate = QtCore.QCoreApplication.translate
formDadosCliente.setWindowTitle(_translate("formDadosCliente", "Form"))
self.lb_nome.setText(_translate("formDadosCliente", "Nome:"))
self.lb_telefone.setText(_translate("formDadosCliente", "Telefone:"))
self.lb_cidade.setText(_translate("formDadosCliente", "Cidade:"))
self.bt_cancelar.setToolTip(_translate("formDadosCliente", "<html><head/><body><p><img src=\":/icon_cliente/icons/cliente.png\"/></p></body></html>"))
self.bt_cadastrar.setToolTip(_translate("formDadosCliente", "<html><head/><body><p><img src=\":/icon_cliente/icons/cliente.png\"/></p></body></html>"))
### Botoes sistema ###
self.bt_cancelar.clicked.connect(lambda: self.sairTela(formDadosCliente))
if variaveisControle.tipoTelaDadosCliente == 'incluir':
self.bt_cadastrar.clicked.connect(self.cadastrarCliente)
if variaveisControle.tipoTelaDadosCliente == 'alterar':
self.bt_cadastrar.clicked.connect(self.alterarCliente)
### Condicoes da tela ###
## Tipos form tela ##
if variaveisControle.tipoTelaDadosCliente == 'incluir':
print('dadosCliente: ', variaveisControle.tipoTelaDadosCliente)
self.txt_nome.setEnabled(True)
self.txt_telefone.setEnabled(True)
self.txt_cidade.setEnabled(True)
self.bt_cadastrar.setEnabled(True)
elif variaveisControle.tipoTelaDadosCliente == 'consultar':
print('dadosCliente: ', variaveisControle.tipoTelaDadosCliente)
self.txt_nome.setEnabled(False)
self.txt_telefone.setEnabled(False)
self.txt_cidade.setEnabled(False)
self.bt_cadastrar.setEnabled(False)
# Conexao com o banco de dados #
mydb = mysql.connector.connect(
host = host,
user = user,
password = password,
database = database
)
mycursor = mydb.cursor()
consultaSQL = "SELECT * FROM cliente WHERE idCliente = '" + variaveisControle.idConsulta + "'"
mycursor.execute(consultaSQL)
myresult = mycursor.fetchall()
mycursor.close()
# Converte resultado BD para DataFrame #
df = pd.DataFrame(myresult, columns = ['ID', 'Nome', 'Telefone', 'Cidade'])
nomeCliente = df['Nome'][0]
telefoneCliente = df['Telefone'][0]
cidadeCliente = df['Cidade'][0]
# Seta variaveis na tela do sistema #
self.txt_nome.setText(nomeCliente)
self.txt_telefone.setText(telefoneCliente)
self.txt_cidade.setText(cidadeCliente)
elif variaveisControle.tipoTelaDadosCliente == 'alterar':
print('dadosCliente: ', variaveisControle.tipoTelaDadosCliente)
self.txt_nome.setEnabled(True)
self.txt_telefone.setEnabled(True)
self.txt_cidade.setEnabled(True)
self.bt_cadastrar.setEnabled(True)
# Conexao com o banco de dados #
mydb = mysql.connector.connect(
host = host,
user = user,
password = password,
database = database
)
mycursor = mydb.cursor()
consultaSQL = "SELECT * FROM cliente WHERE idCliente = '" + variaveisControle.idConsulta + "'"
mycursor.execute(consultaSQL)
myresult = mycursor.fetchall()
mycursor.close()
# Converte resultado BD para DataFrame #
df = pd.DataFrame(myresult, columns = ['ID', 'Nome', 'Telefone', 'Cidade'])
nomeCliente = df['Nome'][0]
telefoneCliente = df['Telefone'][0]
cidadeCliente = df['Cidade'][0]
# Seta variaveis na tela do sistema #
self.txt_nome.setText(nomeCliente)
self.txt_telefone.setText(telefoneCliente)
self.txt_cidade.setText(cidadeCliente)
### FUNCOES SISTEMA ###
## Sair formDadosCliente ##
def sairTela(self, formDadosCliente):
variaveisControle.tipoTelaDadosCliente == ''
formDadosCliente.close()
## CADASTRAR CLIENTE ##
def cadastrarCliente(self):
nomeCliente = self.txt_nome.text()
telefoneCliente = self.txt_telefone.text()
cidadeCliente = self.txt_cidade.text()
mydb = mysql.connector.connect(
host = host,
user = user,
password = password,
database = database
)
mycursor = mydb.cursor()
sql = "INSERT INTO cliente (Nome, Telefone, Cidade) values (%s, %s, %s)"
val = (nomeCliente, telefoneCliente, cidadeCliente)
mycursor.execute(sql,val)
mydb.commit()
print(mycursor.rowcount, 'record(s) insert')
mycursor.close()
self.txt_nome.setText("")
self.txt_telefone.setText("")
self.txt_cidade.setText("")
## ALTERAR CLIENTE ##
def alterarCliente(self):
nomeCliente = self.txt_nome.text()
telefoneCliente = self.txt_telefone.text()
cidadeCliente = self.txt_cidade.text()
mydb = mysql.connector.connect(
host = host,
user = user,
password = password,
database = database
)
mycursor = mydb.cursor()
sql = "UPDATE cliente SET Nome = '" + nomeCliente + "', Telefone = '" + telefoneCliente + "', Cidade = '" + cidadeCliente + "' WHERE idCliente = '" + variaveisControle.idConsulta + "'"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, 'record(s) altered')
mycursor.close()
### Icons do Sistema ###
import icon_cadastrar
import icon_cancelar
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
formDadosCliente = QtWidgets.QWidget()
ui = Ui_formDadosCliente()
ui.setupUi(formDadosCliente)
formDadosCliente.show()
sys.exit(app.exec_())