-
Notifications
You must be signed in to change notification settings - Fork 0
/
managerGUI.py
302 lines (265 loc) · 6.94 KB
/
managerGUI.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import sqlite3
from contextlib import closing
from tkinter import *
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
#inicio da interface gráfica
menuInicial = Tk()
def pesquisar():
nome = str(nomeDoCliente.get())
telefone = str(telefoneDoCliente.get())
if nome != '':
with sqlite3.connect("cadastro.db") as conexao:
with closing(conexao.cursor()) as cursor:
cursor.execute(f'select * from cadastro where nome = ?',(nome,))
x = 0
while True:
resultado = cursor.fetchone()
if resultado is None:
if x == 0:
messagebox.showwarning("Aviso!",'Cadastro não encontrado!')
break
codigo = resultado[0]
nome = resultado[1]
telefone = resultado[2]
cidade = resultado[3]
x += 1
resposta(codigo,nome,telefone,cidade)
elif telefone != '':
with sqlite3.connect("cadastro.db") as conexao:
with closing(conexao.cursor()) as cursor:
cursor.execute(f'select * from cadastro where telefone = ?',(telefone,))
x = 0
while True:
resultado = cursor.fetchone()
if resultado is None:
if x == 0:
messagebox.showwarning("Aviso!",'Cadastro não encontrado!')
break
codigo = resultado[0]
nome = resultado[1]
telefone = resultado[2]
cidade = resultado[3]
x += 1
resposta(codigo,nome,telefone,cidade)
nomeDoCliente.delete(0, 'end')
telefoneDoCliente.delete(0, 'end')
cidadeDoCliente.delete(0, 'end')
def incluir ():
nome = str(nomeDoCliente.get())
telefone = str(telefoneDoCliente.get())
cidade = str(cidadeDoCliente.get())
with sqlite3.connect("cadastro.db") as conexao:
with closing(conexao.cursor()) as cursor:
cursor.execute("insert into cadastro (nome, telefone, cidade) values (?,?,?)",(nome,telefone,cidade))
conexao.commit()
messagebox.showinfo("Cadastro de clientes",'Cadastro realizado.')
nomeDoCliente.delete(0, 'end')
telefoneDoCliente.delete(0, 'end')
cidadeDoCliente.delete(0, 'end')
def editar ():
nome = str(nomeDoCliente.get())
telefone = str(telefoneDoCliente.get())
cidade = str(cidadeDoCliente.get())
with sqlite3.connect("cadastro.db") as conexao:
with closing(conexao.cursor()) as cursor:
cursor.execute('select * from cadastro where nome = ?', (nome,))
x = 0
while True:
resultado = cursor.fetchone()
if resultado is None:
if x == 0:
messagebox.showwarning("Aviso!",'Cadastro não encontrado!')
break
x += 1
if resultado:
cursor.execute(f'update cadastro set telefone = {telefone} where nome = ?',(nome,))
if cursor.rowcount == 1:
conexao.commit()
messagebox.showinfo("Cadastro de clientes",'Cadastro atualizado com sucesso.')
break
else:
conexao.rollback()
messagebox.showwarning("Aviso!",'Alteração cadastral não realizada.')
nomeDoCliente.delete(0, 'end')
telefoneDoCliente.delete(0, 'end')
cidadeDoCliente.delete(0, 'end')
nomeDoCliente.focus()
def desativar ():
nome = str(nomeDoCliente.get())
with sqlite3.connect("cadastro.db") as conexao:
with closing(conexao.cursor()) as cursor:
cursor.execute("delete from cadastro where nome = ?",(nome,))
if cursor.rowcount == 1:
conexao.commit()
messagebox.showinfo("Cadastro de clientes",'Cadastro removido com sucesso.')
else:
conexao.rollback()
messagebox.showwarning("Aviso!",'Alteração cadastral não realizada.')
nomeDoCliente.delete(0, 'end')
telefoneDoCliente.delete(0, 'end')
cidadeDoCliente.delete(0, 'end')
def sair ():
menuInicial.destroy()
def resposta(codigo,nome,telefone,cidade):
resposta = tk.Toplevel(menuInicial)
resposta.title("Cliente: " + nome)
resposta.resizable(True, False)
resposta.iconbitmap("imagens/icon.ico")
#dimensões da janela e posicionamento
largura = 300
altura = 120
larguraScreen = menuInicial.winfo_screenwidth() #resolução do sistema
alturaScreen = menuInicial.winfo_screenheight() #resolução do sistema
posx = int(larguraScreen/2 - largura/2) #posicionamento da janela
posy = int(alturaScreen/2 - altura/2) #posicionamento da janela
resposta.geometry(f"{largura}x{altura}+{posx}+{posy}")
label10 = Label(
resposta,
text='Código: ' + str(codigo),
font="Times 15",
width=25,
anchor=CENTER
).pack()
label11 = Label(
resposta,
text='Nome: ' + nome,
font="Times 15",
width=25,
anchor=CENTER
).pack()
label12 = Label(
resposta,
text='Telefone: ' + telefone,
font="Times 15",
width=25,
anchor=CENTER
).pack()
label13 = Label(
resposta,
text='Cidade: ' + cidade,
font="Times 15",
width=25,
anchor=CENTER
).pack()
#configuração da interface básica
menuInicial.title("Cadastro de clientes")
menuInicial.resizable(False, False)
menuInicial.iconbitmap("imagens/icon.ico")
#dimensões da janela e posicionamento
largura = 500
altura = 600
larguraScreen = menuInicial.winfo_screenwidth() #resolução do sistema
alturaScreen = menuInicial.winfo_screenheight() #resolução do sistema
posx = int(larguraScreen/2 - largura/2) #posicionamento da janela
posy = int(alturaScreen/2 - altura/2) #posicionamento da janela
menuInicial.geometry(f"{largura}x{altura}+{posx}+{posy}")
#label
label0 = Label(
menuInicial,
text="Cadastro de clientes",
font="Times 25 bold",
bd=3,
relief="raised",
width=20,
height=2,
).place(x = 50, y = 20)
label1 = Label(
menuInicial,
text="Nome do cliente",
font="Times 15 bold",
width=15,
anchor=CENTER
).place(x=10,y=150)
label2 = Label(
menuInicial,
text="Telefone",
font="Times 15 bold",
width=15,
anchor=CENTER
).place(x=10,y=190)
label3 = Label(
menuInicial,
text="Cidade",
font="Times 15 bold",
width=15,
anchor=CENTER
).place(x= 10,y=230)
label4 = Label(
menuInicial,
text="Projeto realizado por Luiz Renato Miranda Ferreira",
font="Times 10",
width=60,
anchor=CENTER
).place(x= 50,y=550)
label5 = Label(
menuInicial,
text="Concorrência a vaga de estágio na empresa Cândido Empresarial",
font="Times 10",
width=60,
anchor=CENTER
).place(x= 50,y=570)
#entry
nomeDoCliente = Entry(
menuInicial,
width=25,
bg='white',
font="Times 15"
)
nomeDoCliente.place(x=200,y=150)
telefoneDoCliente = Entry(
menuInicial,
width=25,
bg='white',
font='Times 15'
)
telefoneDoCliente.place(x=200,y=190)
cidadeDoCliente = ttk.Combobox(
menuInicial,
width=23,
font='Times 15',
values=[
"Uberaba",
"Uberlândia",
"Araxá"])
cidadeDoCliente.place(x=200,y=230)
label3 = Label(menuInicial, text="Cidade")
#botões
btn1 = Button(
menuInicial,
text="Pesquisar",
width=25,
font="Times 15",
command=pesquisar
).place(x=115,y=290)
btn2 = Button(
menuInicial,
text="Incluir",
width=25,
font="Times 15",
command=incluir
).place(x=115,y=340)
btn3 = Button(
menuInicial,
text="Editar",
width=25,
font="Times 15",
command=editar
).place(x=115,y=390)
btn4 = Button(
menuInicial,
text="Desativar",
width=25,
font="Times 15",
command=desativar
).place(x=115,y=440)
btn5 = Button(
menuInicial,
text="Sair",
width=25,
font="Times 15",
command=sair
).place(x=115,y=490)
nomeDoCliente.focus()
menuInicial.mainloop()