class ModificarUsuario(wx.Frame): def __init__(self, frame_father, id_user): super(ModificarUsuario, self).__init__() self.xml = xrc.XmlResource('../View/modificar_cuenta_usuario.xml') self.frame = self.xml.LoadFrame(None, 'Frame_Modificar_Cuenta_Usuario') self.panel = xrc.XRCCTRL(self.frame, 'ModificarCuenta_Panel') self.nombre = xrc.XRCCTRL(self.panel, 'Textctrl_Nombre') self.apellido = xrc.XRCCTRL(self.panel, 'Textctrl_Apellido') self.username = xrc.XRCCTRL(self.panel, 'Textctrl_Username') self.foto = xrc.XRCCTRL(self.panel, 'Filepicker_Foto') self.id_user = id_user self.frame_father = frame_father self.user_controller = UserController() self.button_modificar = xrc.XRCCTRL(self.panel, 'wxID_OK') self.button_cancelar = xrc.XRCCTRL(self.panel, 'wxID_CANCEL') self.frame.SetIcon(wx.Icon("../view/System_Images/icon.png")) self.frame.Bind(wx.EVT_BUTTON, self.modificar_usuario, self.button_modificar) self.frame.Bind(wx.EVT_BUTTON, self.cancelar, self.button_cancelar) self.cargar_datos_usuario() self.frame.Show() def cargar_datos_usuario(self): usuario = self.user_controller.get_user(self.id_user) self.nombre.SetValue(usuario.nombre) self.apellido.SetValue(usuario.apellido) self.username.SetValue(usuario.nombre_usuario) self.password = usuario.contrasena def modificar_usuario(self, evt): nombre = self.nombre.GetValue() apellido = self.apellido.GetValue() username = self.username.GetValue() foto = self.foto.GetPath() if nombre and apellido and username: data = { 'nombre': nombre, 'apellido': apellido, 'username': username, 'password': self.password, "imagen": foto } if self.user_controller.edit_user(self.id_user, data): wx.MessageBox('El Usuario se modifico exitosamente', 'Information', wx.OK | wx.ICON_INFORMATION) self.frame_father.load_data_listctrl_user() self.cargar_datos_usuario() else: wx.MessageBox('Todos los campos son obligatorios', 'Error', wx.OK | wx.ICON_ERROR) def cancelar(self, evt): self.frame.Close()
class ModificFrame(wx.Frame): def __init__(self, frame_father=None, id_user=None): super(ModificFrame, self).__init__() self.res = xrc.XmlResource('../view/modific.xrc') self.frame = self.res.LoadFrame(None, 'ModificFrame') self.panel = xrc.XRCCTRL(self.frame, 'InicioModific') self.user_controller = UserController() self.id_user = id_user self.first_name = xrc.XRCCTRL(self.panel, 'textModFirstName') self.last_name = xrc.XRCCTRL(self.panel, 'textModLastName') self.username = xrc.XRCCTRL(self.panel, 'textModUsername') self.password = xrc.XRCCTRL(self.panel, 'textModPassword') self.button_save = xrc.XRCCTRL(self.panel, 'wxID_OK') self.button_cancel = xrc.XRCCTRL(self.panel, 'wxID_CANCEL') self.frame.Bind(wx.EVT_BUTTON, self.close_frame, self.button_cancel) self.frame.Bind(wx.EVT_BUTTON, self.update_user, self.button_save) self.frame.Show() if frame_father is not None: self.frame_father = frame_father if self.id_user is not None: self.load_data_user() def update_user(self, evt): first_name = self.first_name.GetValue() last_name = self.last_name.GetValue() username = self.username.GetValue() password = self.password.GetValue() if first_name and last_name and username and password: if self.id_user is not None: data = { 'first_name': first_name, 'last_name': last_name, 'username': username, 'password': password } self.user_controller.edit_user(self.id_user, data) wx.MessageBox('The user has been update successfully', 'Information', wx.OK | wx.ICON_INFORMATION) self.load_data_user() else: self.user_controller.create_user(first_name, last_name, username, password) self.frame_father.load_data_listctrl_user() else: wx.MessageBox('Fields not entered', 'Error', wx.OK | wx.ICON_ERROR) self.frame_father.load_data_listctrl_user() def close_frame(self, evt): self.frame.Close() def load_data_user(self): user = self.user_controller.get_user(self.id_user) self.first_name.SetValue(user.first_name) self.last_name.SetValue(user.last_name) self.username.SetValue(user.username) self.password.SetValue(user.password)
class RegistroFrame(wx.Frame): def __init__(self, frame_father=None, id_user=None): super(RegistroFrame, self).__init__() self.res = xrc.XmlResource('../view/registro.xrc') self.user_controller = UserController() self.id_user = id_user self.frame = self.res.LoadFrame(None, 'RegistroFrame') self.panel = xrc.XRCCTRL(self.frame, 'InicioRegistro') self.first_name = xrc.XRCCTRL(self.panel, 'textCtrlFirstName') self.last_name = xrc.XRCCTRL(self.panel, 'textCtrlLastname') self.username = xrc.XRCCTRL(self.panel, 'textCtrlUsername') self.password = xrc.XRCCTRL(self.panel, 'textCtrlPassword') self.button_save = xrc.XRCCTRL(self.panel, 'wxID_OK') self.button_cancel = xrc.XRCCTRL(self.panel, 'wxID_CANCEL') self.frame.Bind(wx.EVT_BUTTON, self.close_frame, self.button_cancel) self.frame.Bind(wx.EVT_BUTTON, self.create_user, self.button_save) self.frame_father = frame_father if self.id_user is not None: self.load_data_user() self.frame.Show() def close_frame(self, evt): self.frame.Close() def create_user(self, evt): first_name = self.first_name.GetValue() last_name = self.last_name.GetValue() username = self.username.GetValue() password = self.password.GetValue() search_data = self.user_controller.search_username(username) if first_name and last_name and username and password: if self.id_user is not None: data = { 'first_name': first_name, 'last_name': last_name, 'username': username, 'password': password } self.user_controller.edit_user(self.id_user, data) self.load_data_user() else: if search_data is None: self.user_controller.create_user(first_name, last_name, username, password) wx.MessageBox('The user has been created successfully', 'Information', wx.OK | wx.ICON_INFORMATION) self.clear_fields() else: wx.MessageBox( 'The username already exist in the database.', 'Error', wx.OK | wx.ICON_ERROR) if not self.frame_father is None: self.frame_father.load_data_listctrl_user() else: wx.MessageBox('Fields not entered', 'Error', wx.OK | wx.ICON_ERROR) def clear_fields(self): self.first_name.Clear() self.last_name.Clear() self.username.Clear() self.password.Clear() def load_data_user(self): user = self.user_controller.get_user(self.id_user) self.first_name.SetValue(user.first_name) self.last_name.SetValue(user.last_name) self.username.SetValue(user.username) self.password.SetValue(user.password)