Esempio n. 1
0
    def on_buttonModificar_clicked(self, widget):
        """Merodo para modificar los datos de un cliente.

                    :param widget: Widget
                    :return: No devuelve ningún parámetro.
                    """
        dni = self.comboAux
        nombre = self.entryNombre2.get_text()
        apellidos = self.entryApellidos2.get_text()
        if (self.sexoH2.get_active()):
            sexo = "H"
        else:
            sexo = "M"

        direccion = self.entryDireccion2.get_text()
        telefono = self.entryTelefono2.get_text()
        vaidacionTelf = self.validoTelf(telefono)
        if (vaidacionTelf):
            SQLiteMetodos.updateTablaClientes(dni, nombre, apellidos, sexo,
                                              direccion, telefono)
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                                       Gtk.ButtonsType.OK,
                                       "Cliente Modificado Correctamente")
            dialog.run()
            dialog.destroy()
        else:
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.WARNING,
                                       Gtk.ButtonsType.OK,
                                       "Introduce un nuevo teléfono válido")
            dialog.run()
            dialog.destroy()
Esempio n. 2
0
    def __init__(self):
        """
        Inicializa la ventana con la interfaz.
        """
        # Interfaz Principal
        Gtk.Window.__init__(self, title="Proyecto interfaces")
        #
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_border_width(10)
        self.set_default_size(250, 300)
        self.set_resizable(False)
        self.box = Gtk.Box(spacing=10)
        self.box.set_orientation(Gtk.Orientation.VERTICAL)
        self.add(self.box)
        self.button1 = Gtk.Button(label="Gestión de clientes")
        self.button1.connect("clicked", self.on_button1_clicked)
        self.box.pack_start(self.button1, True, True, 0)
        self.button2 = Gtk.Button(label=" Gestión Productos")
        self.button2.connect("clicked", self.on_button2_clicked)
        self.box.pack_start(self.button2, True, True, 0)
        self.button4 = Gtk.Button(label="Albaranes")
        self.button4.connect("clicked", self.on_button4_clicked)
        self.box.pack_start(self.button4, True, True, 0)
        self.button6 = Gtk.Button(label="Salir")
        self.button6.connect("clicked", self.on_button6_clicked)
        self.box.pack_start(self.button6, True, True, 0)
        self.connect("destroy", Gtk.main_quit)
        # Estilo de la interfaz con css
        css = '''

            button { 
            background:  #abd6f5;
            padding: 5px 5px;
            font-size: 15px;
            text-decoration: none;
            outline: none;
            color: #fff;
            border-style: hidden;
            border-radius: 5px;
            }
            label {
            font: 20px Courier-bold;
            }
                    '''
        cssProvider = Gtk.CssProvider()
        cssProvider.load_from_data(bytes(css.encode()))
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        styleContext.add_provider_for_screen(screen, cssProvider,
                                             Gtk.STYLE_PROVIDER_PRIORITY_USER)

        # Creacion de las tablas en la base de datos.
        SQLiteMetodos.main()
        self.show_all()
    def on_buttonEliminar_clicked(self, widget):
        """Metodo para eliminar un cliente.

                :param widget: Widget
                :return: No devuelve ningún parámetro.

        """
        SQLiteMetodos.deleteTablaClientes(self.comboAux2)
        self.cargar_dni_cliente()
        dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Cliente Eliminado Correctamente")
        dialog.run()
        dialog.destroy()
    def on_changed(self, selection):
        """Método que captura la señal selection en el TreeView y carga los productos del cliente seleccionado.

            :param selection: Si se ha seleccionado algo en el TreeView.
            :return: No devuelve ningún parámetro.

        """
        (self.model, self.iter) = selection.get_selected()
        self.productosP.clear()
        productos = SQLiteMetodos.selectTablaProductos(
            self.model[self.iter][0])
        for producto in productos:
            self.productosP.append([
                producto[0], producto[1], producto[2],
                str(producto[3]) + " €/ud", producto[4]
            ])

        self.modeloP.clear()
        for elemento in self.productosP:
            self.modeloP.append(elemento)

        if (self.auxiliar):
            for i in range(len(self.columnasP)):
                celda = Gtk.CellRendererText()
                self.columnaP = Gtk.TreeViewColumn(self.columnasP[i],
                                                   celda,
                                                   text=i)
                self.vistaP.append_column(self.columnaP)
                self.auxiliar = False
Esempio n. 5
0
    def on_buttonLista_clicked(self, widget):
        """
        Metodo que crea un pdf con una tabla de lista de clientes.
            :param widget: Widget butón.

        """
        data = []
        data.append(
            ["Dni", "Nombre", "Apellidos", "Sexo", "Direccion", "Telefono"])
        clientes = SQLiteMetodos.selectTablaClientes()
        for cliente in clientes:
            data.append([
                cliente[0], cliente[1], cliente[2], cliente[3], cliente[4],
                cliente[5]
            ])
        # Creacion pedf
        fileName = 'listaClientes.pdf'
        current_work_directory = os.getcwd(
        )  # Return a string representing the current working directory.
        print("Current work directory: {}".format(current_work_directory))
        abs_work_directory = os.path.abspath(current_work_directory)
        print(os.pathsep)
        print()
        pdf = SimpleDocTemplate(current_work_directory + "/" + fileName,
                                pagesize=letter)
        # Creación de la tabla
        table = Table(data)
        elementos = []
        elementos.append(table)

        # Añadiendo style a la tabla
        style = TableStyle([
            ('BACKGROUND', (0, 0), (-1, 0), colors.lightslategray),
            ('BACKGROUND', (0, 1), (-1, -1), colors.beige),
            ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
            ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
            ('FONTNAME', (0, 0), (-1, 0), 'Courier-Bold'),
            ('FONTSIZE', (0, 0), (-1, 0), 14),
            ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
        ])
        table.setStyle(style)
        # Alternar color de las filas
        rowNumb = len(data)
        for i in range(1, rowNumb):
            if i % 2 == 0:
                bc = colors.lightgreen
            else:
                bc = colors.lightskyblue
            ts = TableStyle([('BACKGROUND', (0, i), (-1, i), bc)])
            table.setStyle(ts)

        # Añadimos bordes a la tabla
        ts2 = TableStyle([
            ('BOX', (0, 0), (-1, -1), 2, colors.black),
            ('LINEBEFORE', (0, 0), (-1, rowNumb), 2, colors.black),
            ('LINEABOVE', (0, 0), (-1, rowNumb), 2, colors.black)
        ])
        table.setStyle(ts2)
        pdf.build(elementos)
        wb.open_new(current_work_directory + "/" + fileName)
Esempio n. 6
0
    def cargar_dni_cliente(self):
        """
        Metodo que carga los dni de los clientes existentes en los comboBox de modificar y eliminar.

        """
        self.entryDni.clear()
        datos = SQLiteMetodos.selectTablaClientesDni2()
        for clientes in datos:
            self.entryDni.append([clientes[0]])
Esempio n. 7
0
    def cargar_dni_cliente(self):
        """Metodo que carga los dni de los clientes existentes en los comboBox de modificar y eliminar.

        :param: No recibe ningún parámetro.
        :return: No devuelve ningún parámetro.

        """
        self.entryDni.clear()
        datos = SQLiteMetodos.selectTablaClientesDni2()
        for clientes in datos:
            self.entryDni.append([clientes[0]])
Esempio n. 8
0
    def on_buttonAñadir_clicked(self, widget):
        """Metodo para añadir un nuevo cliente dados sus datos.

            :param widget: Widget
            :return: No devuelve ningún parámetro.

            """
        dni = self.entryDni.get_text()
        validacion = self.validoDNI(dni)
        if (self.sexoH.get_active()):
            sexo = "H"
        else:
            sexo = "M"
        direccion = self.entryDireccion.get_text()
        telefono = self.entryTelefono.get_text()
        nombre = self.entryNombre.get_text()
        apellidos = self.entryApellidos.get_text()
        vaidacionTelf = self.validoTelf(telefono)

        if (validacion and vaidacionTelf):
            SQLiteMetodos.insertTablaClientes(dni, nombre, apellidos, sexo,
                                              direccion, telefono)
            self.cargar_dni_cliente()
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                                       Gtk.ButtonsType.OK,
                                       "Cliente Añadido Correctamente")
            dialog.run()
            dialog.destroy()
        elif (validacion == False):
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.WARNING,
                                       Gtk.ButtonsType.OK,
                                       "Introduce un dni válido")
            dialog.run()
            dialog.destroy()

        else:
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.WARNING,
                                       Gtk.ButtonsType.OK,
                                       "Introduce un teléfono válido")
            dialog.run()
            dialog.destroy()
Esempio n. 9
0
    def on_buttonAñadir_clicked(self, button):
        """Metodo que recoge la señal "clicked" del boton y añada un nuevo producto asignado a un cliente.

            :param button: GtkButton.
            :return: No devuelve ningún parámetro.
        """
        try:
            id = int(self.entryId.get_text())
            dni = self.aux
            nombre = self.entryNombre.get_text()
            precio = float(self.entryPrecio.get_text())
            cantidad = int(self.entryCantidad.get_text())
            SQLiteMetodos.insertTablaProductos(id, dni, nombre, precio, cantidad)
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK,
                                       "Producto añadido correctamente")
            dialog.run()
            dialog.destroy()
        except ValueError as verr:
            print("Introduzca valores coherentes")
        except Exception as ex:
            print("Otro Error")
Esempio n. 10
0
    def on_comboModificar_changed(self, combo):
        """Metodo que recoge la señar del combo "changed" para cargar los datos del cliente a modificar.

                :param combo: GtkCombo
                :return: No devuelve ningún parámetro.

        """
        tree_iter = combo.get_active_iter()
        if tree_iter != None:
            model = combo.get_model()
            dniCliente = model[tree_iter][0]
            self.comboAux = dniCliente

            datos = SQLiteMetodos.selectTablaClientesDni(dniCliente)
            for clientes in datos:
                self.entryNombre2.set_text(clientes[1])
                self.entryApellidos2.set_text(clientes[2])
                self.entryDireccion2.set_text(clientes[4])
                self.entryTelefono2.set_text(clientes[5])
    def __init__(self):
        """
        Inicializa la ventana de Albaranes con la interfaz.

        """
        # Interfaz Principal
        Gtk.Window.__init__(self, title="Albaranes")
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_border_width(10)
        self.set_default_size(300, 300)
        self.set_resizable(False)
        self.connect("destroy", Gtk.main_quit)

        self.boxPrincipal = Gtk.Box(spacing=20)
        self.boxPrincipal.set_orientation(Gtk.Orientation.VERTICAL)
        self.add(self.boxPrincipal)
        """TABLA CLIENTES"""
        self.columnasC = [
            "Dni", "Nombre", "Apellidos", "Sexo", "Direccion", "Telefono"
        ]
        self.modeloC = Gtk.ListStore(str, str, str, str, str, str)
        self.clientes = []
        self.vista = Gtk.TreeView(model=self.modeloC)
        self.vista.get_selection().connect("changed", self.on_changed)

        self.labelClientes = Gtk.Label("Clientes")
        """TABLA PRODUCTOS"""
        self.columnasP = ["Id", "Dni", "Nombre", "Precio", "Cantidad"]
        self.modeloP = Gtk.ListStore(int, str, str, str, int)
        self.productosP = []
        self.vistaP = Gtk.TreeView(model=self.modeloP)
        self.vistaP.get_selection().connect("changed", self.on_changedP)
        self.auxiliar = True
        self.labelProductos = Gtk.Label("Productos")

        self.boxPrincipal.add(self.labelClientes)
        self.boxPrincipal.add(self.vista)
        self.boxPrincipal.add(self.labelProductos)
        self.boxPrincipal.add(self.vistaP)

        self.boxAux = Gtk.Box(spacing=20)
        self.boxAux.set_orientation(Gtk.Orientation.HORIZONTAL)
        self.boxPrincipal.add(self.boxAux)

        self.buttonVolver = Gtk.Button(label="Volver")
        self.buttonVolver.connect("clicked", self.on_buttonVolver_clicked)
        self.boxAux.pack_start(self.buttonVolver, True, True, 0)
        self.buttonFactura = Gtk.Button(label="Factura")
        self.buttonFactura.connect("clicked", self.on_buttonFactura_clicked)
        self.boxAux.pack_start(self.buttonFactura, True, True, 0)
        self.buttonLista = Gtk.Button(label="Lista Clientes")
        self.buttonLista.connect("clicked", self.on_buttonLista_clicked)
        self.boxAux.pack_start(self.buttonLista, True, True, 0)

        clientes = SQLiteMetodos.selectTablaClientes()
        for cliente in clientes:
            self.clientes.append([
                cliente[0], cliente[1], cliente[2], cliente[3], cliente[4],
                cliente[5]
            ])

        for elemento in self.clientes:
            self.modeloC.append(elemento)

        for i in range(len(self.columnasC)):
            celda = Gtk.CellRendererText()
            self.columna = Gtk.TreeViewColumn(self.columnasC[i], celda, text=i)
            self.vista.append_column(self.columna)
        self.show_all()
    def on_buttonFactura_clicked(self, widget):
        """Metodo que crea una factura del cliente seeccionado en el treeview.

           :param widget: Widget botón.
           :return: No devuelve ningún parámetro.

        """
        # DATOS CLIENTE SELECCIONADO
        current_work_directory = os.getcwd(
        )  # Return a string representing the current working directory.
        dataC = []
        clientes = SQLiteMetodos.selectTablaClientesDni(
            self.model[self.iter][0])
        for cliente in clientes:
            dataC.append(['Datos Cliente ', '', '', '', ''])
            dataC.append(['Dni: ', cliente[0], '', '', ''])
            dataC.append(['Nombre: ', cliente[1], '', '', ''])
            dataC.append(['Apellidos: ', cliente[2], '', '', ''])
            dataC.append(['Sexo: ', cliente[3], '', '', ''])
            dataC.append(['Direccion: ', cliente[4], '', '', ''])
            dataC.append(['Teléfono: ', cliente[5], '', '', ''])
            dataC.append(['', '', '', '', ''])

            # PRODUCTOS DEL CLIENTE SELECCIONADO
            precioTotal = 0.0
            dataP = []
            productos = SQLiteMetodos.selectTablaProductos(
                self.model[self.iter][0])
            # Productos que pertenecen al cliente seleccionado
        try:
            dataP.append(["Id Producto", "Nombre", "Precio", "Cantidad"])
            for producto in productos:
                dataP.append([
                    producto[0], producto[2],
                    str(producto[3]) + " €/ud", producto[4]
                ])
                precioTotal = precioTotal + (producto[3] * producto[4])

            dataP.append(['', '', 'PRECIO TOTAL:', str(precioTotal) + " €"])
            rowNumb = len(dataP)

            # GENERAR PDF
            fileName = 'Factura' + dataC[1][1] + '.pdf'
            pdf = SimpleDocTemplate(current_work_directory + "/" + fileName,
                                    pagesize=letter)
            # DATOS CLIENTE

            table = Table(dataC, colWidths=80, rowHeights=30)
            table.setStyle(
                TableStyle([
                    ('TEXTCOLOR', (0, 0), (0, -1), colors.darkgreen),
                    ('ALIGN', (0, 0), (0, -1), 'LEFT'),
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                ]))

            # DATOS PRODUCTOS CLIENTE
            table2 = Table(dataP, colWidths=80, rowHeights=30)
            table2.getSpaceBefore()
            table2.setStyle(
                TableStyle([
                    ('TEXTCOLOR', (0, 0), (3, 0), colors.darkgreen),
                    ('TEXTCOLOR', (0, rowNumb - 1), (3, rowNumb - 1),
                     colors.darkred), ('ALIGN', (0, 0), (0, -1), 'LEFT'),
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('BOX', (0, 0), (-1, rowNumb - 2), 1, colors.black),
                    ('INNERGRID', (0, 0), (-1, rowNumb - 2), 0.5, colors.grey)
                ]))

            # Creación de las dtabla
            elementos = []
            elementos.append(table)
            elementos.append(table2)
            pdf.build(elementos)
            wb.open_new(current_work_directory + "/" + fileName)

        except IndexError as e:
            print('No hay productos para generar la factura.')