Skip to content

Commit

Permalink
feat: Feito funcionalidade de edição da reunião
Browse files Browse the repository at this point in the history
  • Loading branch information
LiloMarino committed Jan 14, 2024
1 parent 6a5f929 commit 75be144
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
49 changes: 38 additions & 11 deletions Telas/EditarRG/editar.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# This file was generated by the Tkinter Designer by Parth Jadhav
# https://github.com/ParthJadhav/Tkinter-Designer

from datetime import date
from pathlib import Path
from tkinter import Tk, Canvas, Entry, Text, Button, PhotoImage, ttk
from tkcalendar import DateEntry
import tkinter as tk
import sys
from cruds.Presenca import consultar_presencas_pelo_id

from cruds.Reuniao import consultar_reuniao_pelo_id
from cruds.Reuniao import atualizar_reuniao, consultar_reuniao_pelo_id


ASSETS_PATH = Path(__file__).parent / "assets" / "frame0"
Expand Down Expand Up @@ -64,6 +66,8 @@ def criar_canvas():
def criar_input_data():
date_entry = DateEntry(master=frame, font=(FONTE_TELAS, 20))
date_entry.place(x=180.0, y=67.0, width=201.0)
data_reuniao = consultar_reuniao_pelo_id(id_reuniao)
date_entry.set_date(data_reuniao)
return date_entry

def criar_tabela():
Expand All @@ -89,20 +93,26 @@ def criar_scrollbar(frame_tabela, tabela):
tabela.heading("nome", text="Nome")
tabela.heading("curso", text="Curso")
tabela.heading("presente", text="Presente")
tabela.tag_configure("presente",background="pale green")
tabela.tag_configure("ausente",background="light coral")
tabela.tag_configure("presente", background="pale green")
tabela.tag_configure("ausente", background="light coral")
tabela.grid(row=0, column=0, sticky="nsew")
return tabela

def atualizar_tabela():
tabela.delete(*tabela.get_children())
presentes = consultar_reuniao_pelo_id(id_reuniao)
presentes = consultar_presencas_pelo_id(id_reuniao)
for id_usuario, nome, curso, presenca in presentes:
tabela.insert("", tk.END, iid=id_usuario, values=(nome, curso, "Sim" if presenca else "Não"), tags="presente" if presenca else "ausente")

tabela.insert(
"",
tk.END,
iid=id_usuario,
values=(nome, curso, "Sim" if presenca else "Não"),
tags="presente" if presenca else "ausente",
)

def alternar_presenca():
itens_selecionados = tabela.selection()

for item_id in itens_selecionados:
# Obtém os dados do item
valores_atuais = tabela.item(item_id, "values")
Expand All @@ -120,13 +130,29 @@ def alternar_presenca():
tags_atuais.append("presente")

tabela.item(item_id, values=valores_atuais, tags=tags_atuais)

def deletar_rg():
...

def salvar_rg():
...

lista_presencas = []
todos_itens = tabela.get_children()
for item_id in todos_itens:
# Obtém a presença
valores = tabela.item(item_id, "values")
presente = 1 if valores[2] == "Sim" else 0

# Obtém o id do usuário
tabela.focus(item_id)
id_usuario = tabela.focus()
lista_presencas.append((id_usuario, presente))

atualizar_reuniao(id_reuniao, lista_presencas, date_entry.get_date())

def obter_iid_selecionado(event):
iid_selecionado = tabela.focus()
print("IID do item selecionado:", iid_selecionado)

def criar_botoes():
button_salvar = Button(
frame,
Expand Down Expand Up @@ -168,3 +194,4 @@ def criar_botoes():
date_entry = criar_input_data()
tabela = criar_tabela()
frame.bind("<F5>", lambda event: atualizar_tabela())
tabela.bind("<<TreeviewSelect>>", obter_iid_selecionado)
15 changes: 9 additions & 6 deletions cruds/Presenca.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from tkinter import messagebox
from plyer import notification
from plyer import notification
from cruds.Conexao import Conexao


def ler_carteirinha(n_carteirinha, id_reuniao):
resultados = None

Expand Down Expand Up @@ -37,6 +38,7 @@ def ler_carteirinha(n_carteirinha, id_reuniao):
message="Este número de carteirinha não foi encontrado no sistema",
)


def consultar_presencas_pelo_id(id_reuniao: int):
print(f"EXECUTANDO SELECT PRESENCAS -> REUNIAO ID={id_reuniao}")
conn = Conexao.get_conexao()
Expand All @@ -54,20 +56,21 @@ def consultar_presencas_pelo_id(id_reuniao: int):
return resultados
except Exception as e:
messagebox.showerror(title="Erro ao obter reunião", message=e)



def atualizar_presencas(id_reuniao: int, presencas: list):
conn = Conexao.get_conexao()
sql = "UPDATE presencas SET Presente = CASE ID_Usuário "
sql = "UPDATE presenças SET Presente = CASE ID_Usuário " # Atualize a tabela presenças nos seguintes casos
placeholders = []

for id_usuario, presente in presencas:
sql += "WHEN %s THEN %s "
sql += "WHEN %s THEN %s " # Quando o ID do usuário for ... então Presente = ...
placeholders.extend([id_usuario, presente])

sql += "END WHERE ID_Reunioes = %s"
sql += "END WHERE ID_Reuniões = %s" # Onde ID da reunião for ...
placeholders.append(id_reuniao)
try:
with conn.cursor() as cursor:
cursor.execute(sql, placeholders)
except Exception as e:
messagebox.showerror(title="Erro ao atualizar presenças", message=e)
messagebox.showerror(title="Erro ao atualizar presenças", message=e)
4 changes: 2 additions & 2 deletions cruds/Reuniao.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def consultar_reuniao_pelo_id(id: int):
try:
with conn.cursor() as cursor:
cursor.execute(sql, (id,))
resultados = cursor.fetchall()
return resultados
resultados = cursor.fetchone()
return resultados[0]
except Exception as e:
messagebox.showerror(title="Erro ao obter reunião", message=e)

Expand Down

0 comments on commit 75be144

Please sign in to comment.