-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncionesres.py
139 lines (117 loc) · 4.16 KB
/
funcionesres.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
# coding=utf-8
from datetime import datetime
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import variables, sqlite3, conexion
def clearEntrys():
variables.filares[0].set_text('')
variables.filares[1].set_text('')
variables.filares[2].set_active(-1)
variables.filares[3].set_text('')
variables.filares[4].set_text('')
variables.filares[5].set_text('')
variables.reserva = -1
def ponerListadoEnGUI():
variables.listres.clear()
variables.listhabnum.clear()
clearEntrys()
for registro in listarres():
variables.listres.append(registro)
for registro in listarnumhab():
variables.listhabnum.append(registro)
def listarres():
try:
conexion.cur.execute("select id, cliente, habitacion, checkin, checkout, noches from reservas")
listado = conexion.cur.fetchall()
conexion.connect.commit()
return listado
except sqlite3.OperationalError as e:
print("Error: ", e)
conexion.connect.rollback()
def calcularnoches():
try:
diain = variables.filares[3].get_text()
date_in = datetime.strptime(diain, '%d/%m/%Y').date()
diaout = variables.filares[4].get_text()
date_out = datetime.strptime(diaout, '%d/%m/%Y').date()
noches = (date_out - date_in).days
if noches <= 0:
variables.filares[5].set_text("Inválido")
else:
variables.filares[5].set_text(str(noches))
except Exception:
pass
def listarnumhab():
try:
conexion.cur.execute("select id from habitaciones")
listado = conexion.cur.fetchall()
conexion.connect.commit()
return listado
except sqlite3.OperationalError as e:
print("Error: ", e)
conexion.connect.rollback()
def insertarres(registro):
try:
if fechasdisponibles(registro[1], registro[2], registro[3]):
conexion.cur.execute(
"insert into reservas(cliente, habitacion, checkin, checkout, noches, regimen, parking, "
"personas) values (?,?,?,?,?, 'alojamiento', 'no', 1)", registro)
conexion.connect.commit()
else:
variables.wdialog.connect('delete-event', lambda w, e: w.hide() or True)
variables.lbldialog.set_text('Fechas no disponibles.')
variables.wdialog.show()
except sqlite3.OperationalError as e:
print(e)
conexion.connect.rollback()
def cogerapel(dni):
try:
conexion.cur.execute("select apel from clientes where dni = ?", (dni,))
apel = conexion.cur.fetchone()
conexion.connect.commit()
return apel
except sqlite3.OperationalError as e:
print("Error: ", e)
def eliminar():
try:
conexion.cur.execute("delete from reservas where id = ?", (variables.reserva,))
apel = conexion.cur.fetchone()
conexion.connect.commit()
return apel
except sqlite3.OperationalError as e:
print("Error: ", e)
conexion.connect.rollback()
def modificar(registro):
try:
conexion.cur.execute("update reservas set checkin = ?, checkout = ?, noches = ? "
"where id = ?",
(registro[0], registro[1], registro[2], variables.reserva))
conexion.connect.commit()
except sqlite3.OperationalError as e:
print(e)
conexion.connect.rollback()
def fechasdisponibles(hab, cin, cout):
try:
fa = datetime.strptime(cin, '%d/%m/%Y')
fb = datetime.strptime(cout, '%d/%m/%Y')
for r in reservas_habitacion(hab):
f1 = datetime.strptime(r[0], '%d/%m/%Y')
f2 = datetime.strptime(r[1], '%d/%m/%Y')
if f2 <= fa:
pass
elif f1 >= fb:
pass
else:
return False
return True
except Exception as e:
print(e)
def reservas_habitacion(hab):
try:
conexion.cur.execute("select checkin, checkout from reservas where habitacion = ?", (hab,))
reservas = conexion.cur.fetchall()
conexion.connect.commit()
return reservas
except Exception as e:
print('Detalles: ', e)