class CrearCuentaUsuario(wx.Frame):
    def __init__(self, *args, **kw):
        super(CrearCuentaUsuario, self).__init__(*args, **kw)
        self.xml = xrc.XmlResource('../View/crear_cuenta_usuario.xml')
        self.frame = self.xml.LoadFrame(None, 'CrearCuenta_Frame')
        self.panel = xrc.XRCCTRL(self.frame, 'CrearCuenta_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.password = xrc.XRCCTRL(self.panel, 'Textctrl_Password')
        self.foto = xrc.XRCCTRL(self.panel, 'Filepicker_Foto')
        self.button_crear = 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.crear_usuario, self.button_crear)
        self.frame.Bind(wx.EVT_BUTTON, self.cerrar_frame, self.button_cancelar)
        self.user_controller = UserController()
        self.frame.Show()

    def crear_usuario(self, evt):

        nombre = self.nombre.GetValue()
        apellido = self.apellido.GetValue()
        username = self.username.GetValue()
        password = self.password.GetValue()
        foto = self.foto.GetPath()

        if foto == "":
            foto = None

        if nombre and apellido and username and password:

            if self.user_controller.buscar_usuario(username) == False:
                if self.user_controller.create_user(nombre, apellido, username,
                                                    password, foto):
                    wx.MessageBox('El usuario se creo con exito',
                                  'Information', wx.OK | wx.ICON_INFORMATION)
                    self.limpiar_campos()
            else:
                msg = "El nombre de usuario %s" % username + " ya existe ingrese otro diferente"
                wx.MessageBox(msg, 'Error', wx.OK | wx.ICON_ERROR)
                self.limpiar_usuario()

        else:
            wx.MessageBox(
                'Todos los campos excepto la foto deben ser completados',
                'Error', wx.OK | wx.ICON_ERROR)

    def limpiar_usuario(self):
        self.username.Clear()

    def limpiar_campos(self):
        self.nombre.Clear()
        self.apellido.Clear()
        self.username.Clear()
        self.password.Clear()

    def cerrar_frame(self, evt):
        self.frame.Close()
예제 #2
0
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)
예제 #3
0
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)