-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaz.py
114 lines (100 loc) · 3.47 KB
/
interfaz.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
import sqlite3
import flet as ft
import matplotlib
import gestion_estacionamiento as ge
def main(page: ft.Page):
matplotlib.use('agg')
conn = sqlite3.connect("database.db")
cursor = conn.cursor()
page.title = "Gestor de Estacionamiento"
page.theme_mode = ft.ThemeMode.DARK
page.padding = 10
nombre_usuario = ft.TextField(label="DNI del Usuario")
tipo_vehiculo = ft.TextField(label="Patente de Vehículo")
id_ticket = ft.TextField(label="Ticket")
mensaje = ft.Text("")
def cambiar_tab(index):
tabs_control.selected_index = index
page.update()
def mostrar_popup(mensaje_popup):
dialog = ft.AlertDialog(
title=ft.Text("Información"),
content=ft.Text(mensaje_popup),
actions=[
ft.TextButton("Cerrar", on_click=lambda _: cerrar_popup(dialog))
],
)
page.dialog = dialog
dialog.open = True
page.update()
def cerrar_popup(dialog):
dialog.open = False
page.update()
def manejar_ingreso(e):
if nombre_usuario.value and tipo_vehiculo.value:
resultado = ge.ingresar_vehiculo(cursor, conn, nombre_usuario.value, f"'{tipo_vehiculo.value}'")
if resultado != -1:
mostrar_popup(f"Vehículo registrado exitosamente. Su número de trámite es: {resultado}")
else:
mostrar_popup("No quedan plazas disponibles.")
nombre_usuario.value = ""
tipo_vehiculo.value = ""
page.update()
else:
mostrar_popup("Por favor, complete ambos campos.")
def manejar_egreso(e):
if id_ticket.value:
resultado = ge.retirar_vehiculo(id_ticket.value, cursor, conn)
if resultado:
mostrar_popup("Vehículo retirado exitosamente.")
else:
mostrar_popup("El ticket no corresponde a una plaza ocupada.")
id_ticket.value = ""
page.update()
else:
mostrar_popup("Por favor, complete el campo del ticket.")
page.appbar = ft.AppBar(
title=ft.Text("Gestor de Estacionamiento"),
center_title=True,
bgcolor=ft.colors.BLUE,
)
tabs_control = ft.Tabs(
tabs=[
ft.Tab(
text="",
content=ft.Column([
ft.Text("Registro de Vehículos", style=ft.TextThemeStyle.HEADLINE_SMALL),
nombre_usuario,
tipo_vehiculo,
ft.ElevatedButton("Registrar Vehículo", on_click=manejar_ingreso),
mensaje,
])
),
ft.Tab(
text="",
content=ft.Column([
ft.Text("Baja de Vehículos", style=ft.TextThemeStyle.HEADLINE_SMALL),
id_ticket,
ft.ElevatedButton("Retirar Vehículo", on_click=manejar_egreso),
mensaje,
])
),
],
selected_index=0,
)
botones = ft.Row(
controls=[
ft.ElevatedButton(
text="Ingresar Vehículo",
on_click=lambda _: cambiar_tab(0),
),
ft.ElevatedButton(
text="Retirar Vehículo",
on_click=lambda _: cambiar_tab(1),
),
],
alignment=ft.MainAxisAlignment.CENTER,
)
page.add(botones, tabs_control)
# Iniciar aplicación
ft.app(target=main)