-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cursante.py
225 lines (163 loc) · 8.33 KB
/
Cursante.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
from tkinter import messagebox as mb, StringVar, Toplevel
from tkinter.ttk import Frame, Label, Entry, Button, Combobox
from Form import Form
import sqlite3
class Cursante:
connection = None
modified = False
def create(self, data):
if data[0] and data[1] and data[2] and data[5]:
cur = Cursante.connection.cursor()
sql = """INSERT INTO `Cursante` VALUES
(NULL, ?, ?, ?, ?, ?, ?)"""
try:
cur.execute(sql, data)
Cursante.connection.commit()
self.need_update()
mb.showinfo("Información", "El registro se ha creado con éxito!")
except Exception as e:
mb.showwarning("Ha ocurrido un problema", e)
else:
mb.showwarning("Advertencia!", "Los campos:\n DNI, Nombre, Apellido e Institución\nson obligatorios.")
def delete(self, id_register):
if mb.askyesnocancel("Confimación", "Está seguro que desea eliminar \nlos datos del alumno?"):
cur = Cursante.connection.cursor()
sql = """DELETE FROM `Cursante`
WHERE codigo = ?"""
sql_insc = """DELETE FROM `Inscripto`
WHERE cursante = ?"""
sql_asist = """DELETE FROM `Asistencia`
WHERE inscripto IN (SELECT codigo
FROM `Inscripto`
WHERE cursante = ?)"""
try:
cur.execute(sql_asist, (id_register,))
cur.execute(sql_insc, (id_register,))
cur.execute(sql, (id_register,))
Cursante.connection.commit()
self.need_update()
mb.showinfo("Información", "El registro se ha eliminado con éxito!")
except Exception as e:
mb.showwarning("Ha ocurrido un problema", e)
def update(self, id_register, data):
if data[0] and data[1] and data[2] and data[5]:
if mb.askyesnocancel("Confimación", "Está seguro que desea modificar \nlos datos del alumno?"):
cur = Cursante.connection.cursor()
data.append(id_register)
sql = """UPDATE `Cursante`
SET dni = ?, nombre = ?, apellido = ?, email = ?, telefono = ?, institucion = ?
WHERE codigo = ?"""
try:
cur.execute(sql, data)
Cursante.connection.commit()
self.need_update()
mb.showinfo("Información", "El registro se ha modificado con éxito!")
except Exception as e:
mb.showwarning("Ha ocurrido un problema", e)
else:
mb.showwarning("Advertencia!", "Los campos:\n DNI, Nombre, Apellido e Institución\nson obligatorios.")
@classmethod
def get_all(self):
cur = Cursante.connection.cursor()
sql = """SELECT * FROM `Cursante`"""
try:
cur.execute(sql)
return {"names": [ desc[0] for desc in cur.description], "data":cur.fetchall()}
except Exception as e:
mb.showwarning("Ha ocurrido un problema", e)
@classmethod
def get_register(self, id_register):
cur = Cursante.connection.cursor()
sql = """SELECT * FROM `Cursante` WHERE codigo = ?"""
try:
cur.execute(sql, (id_register,))
return cur.fetchone()
except Exception as e:
mb.showwarning("Ha ocurrido un problema", e)
@classmethod
def need_update(self):
Cursante.modified = True
@classmethod
def is_update(self):
return Cursante.modified
@classmethod
def updated(self):
Cursante.modified = False
class FormCursante(Cursante, Form):
def __init__(self):
Cursante.__init__(self)
Form.__init__(self)
self.id_register = None
self.fieldsFrame = Frame(self.root, relief="groove", padding=(15,15))
self.fieldsFrame.grid(row=0, column=0, padx=10, pady=10)
lbl_dni = Label(self.fieldsFrame, text="DNI: ", width=10)
lbl_dni.grid(row=1, column=0, columnspan=10)
dni = StringVar()
e_dni = Entry(self.fieldsFrame, textvariable=dni, width=40)
e_dni.grid(row=2, column=0, columnspan=40, pady=(0,15))
lbl_name = Label(self.fieldsFrame, text="Nombre: ", width=10)
lbl_name.grid(row=3, column=0, columnspan=10)
name = StringVar()
e_name = Entry(self.fieldsFrame, textvariable=name, width=40)
e_name.grid(row=4, column=0, columnspan=40, pady=(0,15))
lbl_surname = Label(self.fieldsFrame, text="Apellido: ", width=10)
lbl_surname.grid(row=5, column=0, columnspan=10)
surname = StringVar()
e_surname = Entry(self.fieldsFrame, textvariable=surname, width=40)
e_surname.grid(row=6, column=0, columnspan=40, pady=(0,15))
lbl_email = Label(self.fieldsFrame, text="Email: ", width=10)
lbl_email.grid(row=7, column=0, columnspan=10)
email = StringVar()
e_email = Entry(self.fieldsFrame, textvariable=email, width=40)
e_email.grid(row=8, column=0, columnspan=40, pady=(0,15))
lbl_phone = Label(self.fieldsFrame, text="Teléfono: ", width=10)
lbl_phone.grid(row=9, column=0, columnspan=10)
phone = StringVar()
e_phone = Entry(self.fieldsFrame, textvariable=phone, width=40)
e_phone.grid(row=10, column=0, columnspan=40, pady=(0,15))
lbl_institute = Label(self.fieldsFrame, text="Institución: ", width=10)
lbl_institute.grid(row=11, column=0, columnspan=10)
institute = StringVar()
e_institute = Combobox(self.fieldsFrame, textvariable=institute, width=37,
values=("UNTDF", "UTN", "OTRO"), state="readonly")
e_institute.current(0)
e_institute.grid(row=12, column=0, columnspan=40, pady=(0,15))
super().set_fields({"dni":dni, "nombre":name, "apellido":surname,
"email":email, "telefono":phone, "institucion":institute})
dni.trace("w", lambda *args: self.validate_dni(dni, *args))
name.trace("w", lambda *args: self.validate_str(name, *args))
surname.trace("w", lambda *args: self.validate_str(surname, *args))
phone.trace("w", lambda *args: self.validate_phone(phone, *args))
class FormDetailsCursante(FormCursante):
def __init__(self):
FormCursante.__init__(self)
super().set_title("Detalles del alumno")
btn_modify = Button(self.fieldsFrame, text="Modificar",
command=lambda: self.update(self.id_register, self.get_data()))
btn_modify.grid(row=13, column=0, columnspan=20, pady=5)
btn_delete = Button(self.fieldsFrame, text="Eliminar",
command=lambda: (self.delete(self.id_register),
self.hide()))
btn_delete.grid(row=13, column=20, columnspan=20, pady=5)
def show(self, id_register):
self.id_register = id_register
register = self.get_register(id_register)
# Se limpian los campos y se carga la nueva
# info, mediante el llamado a la clase padre 'Form'
self.clean_fields()
self.load_data(register)
super().show()
class FormCreateCursante(FormCursante):
def __init__(self):
FormCursante.__init__(self)
super().set_title("Crear alumno")
lbl_newCursante = Label(self.fieldsFrame, text="Formulario de registro")
lbl_newCursante.grid(row=0, column=0, columnspan=18, pady=(5,10))
btn_createCursante = Button(self.fieldsFrame, text="Registrar",
command=lambda: (self.create(self.get_data()),
self.hide()))
btn_createCursante.grid(row=13, column=0, columnspan=40, pady=5)
def show(self):
# Se limpian los campos llamado a la clase padre 'Form'
self.clean_fields()
super().show()