-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetor.py
173 lines (128 loc) · 5.69 KB
/
setor.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
from tkinter.constants import BOTH, END, LEFT, RIGHT, Y
import banco
import tkinter as tk
from tkinter import ttk, Label, Button, Entry, Menu, Toplevel, Scrollbar,Listbox,Frame
from functools import partial
import pandas as pd
from pandastable import Table
''' MÉTODOS IMPLEMENTADOS:
- CadastroSetor() #Tela Cadastro
- ConsultaSetor() #Tela Consulta
- FuncaoButtonCadastro() #Botao tela Cadastro
- FuncaoButtonConsulta() #Botao tela Consulta
- checkfill() #Verifica se campos vazio
TABELA
codSetor SERIAL NOT NULL,
codCoordenador INTEGER,
nomeSetor VARCHAR(20)
'''
""" LISTA CORREÇÃO:
-> Precisa ser inserido coluna "CARGO" na TABELA [Pessoa] para cadastrar um novo setor
"""
#####################################################################
############################ CADASTRO SETOR #########################
#####################################################################
def CadastroSetor():
Setor = tk.Tk()
style = ttk.Style(Setor)
style.theme_use('clam')
Setor.geometry('800x600')
Setor.title('Cadastro de Setores')
lblCodigo = ttk.Label(Setor, text='Codigo do setor:')
lblCodigo.grid(column=0, row=0)
txtCodigo = ttk.Entry(Setor, width=30)
txtCodigo.grid(column=1, row=0)
lblNomeSetor = ttk.Label(Setor, text='Setor:')
lblNomeSetor.grid(column=0, row=1)
txtNomeSetor = ttk.Entry(Setor, width=30)
txtNomeSetor.grid(column=1, row=1)
lblCodigoCoordenador = ttk.Label(Setor, text='Código Coordenador:')
lblCodigoCoordenador.grid(column=0, row=2)
txtCodigoCoordenador = ttk.Entry(Setor, width=30)
txtCodigoCoordenador.grid(column=1, row=2)
labelResult = ttk.Label(Setor)
labelResult.grid(row=4, column=1)
btnIncluir = ttk.Button(Setor, text='Incluir', command = partial(FuncaoButtonCadastro,
txtCodigo,
txtNomeSetor,
txtCodigoCoordenador, labelResult))
btnIncluir.grid(column=1, row=3)
####################################################################################
############################ CONSULTA SETOR #########################################
####################################################################################
# Ajeitar
def ConsultaSetor():
Setor = tk.Tk()
style = ttk.Style(Setor)
style.theme_use('clam')
Setor.geometry('800x600')
Setor.title('Consulte Setores')
lblCodigo = ttk.Label(Setor, text='Codigo do setor:')
lblCodigo.grid(column=0, row=0)
txtCodigo = ttk.Entry(Setor, width=30)
txtCodigo.grid(column=1, row=0)
lblNomeSetor = ttk.Label(Setor, text='Setor:')
lblNomeSetor.grid(column=0, row=1)
txtNomeSetor = ttk.Entry(Setor, width=30)
txtNomeSetor.grid(column=1, row=1)
labelResult = ttk.Label(Setor)
labelResult.grid(row=4, column=1)
btnIncluir = ttk.Button(Setor, text='Consultar', command = partial(FuncaoButtonConsulta, txtCodigo, txtNomeSetor,labelResult))
btnIncluir.grid(column=1, row=3)
####################################################################################
############################ FUNÇÃO BOTÃO CADASTRO ##################################
####################################################################################
def FuncaoButtonCadastro(codigoSetor, setor, codcoord, labelResult):
if checkfill(codigoSetor, setor, codcoord):
labelResult.config(text="Nome ou Cargo ou Email não foi preenchido. Favor verificar")
else:
resultado = banco.salvarsetor(codigoSetor.get(), setor.get(), codcoord.get(), labelResult)
if resultado:
labelResult.config(text = "Setor cadastrado com sucesso!")
else:
labelResult.config(text = "O setor ja existe!")
####################################################################################
############################# FUNÇÃO BOTÃO CONSULTA #################################
####################################################################################
def FuncaoButtonConsulta(codigoSetor, setor, labelResult):
setores = banco.ConsultaSetor(codigoSetor.get(), setor.get(), labelResult)
colunas = getColumnName()
listaSetores = []
print(setores)
for i in range(0,len(setores)):
listaSetores.append(list(setores[i]))
df = pd.DataFrame(listaSetores, columns=colunas)
if setores != None:
root = tk.Tk()
style = ttk.Style(root)
style.theme_use('clam')
root.geometry('800x600')
root.title("Lista de Setores")
f = Frame(root)
f.pack(fill=BOTH,expand=1)
pt = Table(f, dataframe=df)
pt.show()
# scrollbar = ttk.Scrollbar(root)
# scrollbar.pack(side = RIGHT, fill=Y)
# ListaSetor = ttk.Listbox(root, yscrollcommand = scrollbar.set, width = 60)
# for linha in range(0,len(setores)):
# ListaSetor.insert(END, setores[linha])
# ListaSetor.pack(side = LEFT, fill = BOTH)
# scrollbar.config(command= ListaSetor.yview)
# labelResult.config(text = "Retorno Consulta")
# if setores != None:
# for setor in setores:
# print(setor)
else:
labelResult.config(text = "Setor não encontrado")
def checkfill(codigo, setor, codcoord):
return codigo.get()=='' or codcoord.get()=='' or setor.get==''
def getColumnName():
COLUMN_NAME = banco.QueryColumnSetor()
colunas_tabela = []
if COLUMN_NAME != None:
for i in COLUMN_NAME:
colunas_tabela.append(i[3])
return colunas_tabela
else:
return []