예제 #1
0
class Aplicacion:
    

    def __init__(self):
        #*************************************************************************
        #Crea un objeto TK
        #*************************************************************************
        self.raiz = Tk()
        self.raiz.title ("Mantenimiento de Personas")
        self.raiz.geometry('900x600') 

        #*************************************************************************
        #crea el menu de la pantalla
        #*************************************************************************
        menubar = Menu(self.raiz)
        self.raiz.config(menu=menubar)

        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Acerca de..")
        filemenu.add_separator()
        filemenu.add_command(label="Salir", command=self.raiz.quit)

        mantmenu = Menu(menubar, tearoff=0)
        mantmenu.add_command(label="Personas")
        mantmenu.add_command(label="Teléfonos")
        mantmenu.add_command(label="Direcciones")

        menubar.add_cascade(label="Archivo", menu=filemenu)
        menubar.add_cascade(label="Mantenimiento", menu=mantmenu)

        #*************************************************************************
        #crea un objeto tipo fuenta
        #*************************************************************************
        self.fuente = font.Font(weight="bold")

        #*************************************************************************
        #se crean atributos de la clase
        #*************************************************************************
        self.t_gustos = Gustos.Gustos() #se crea el objeto de dominio para guardar la información
        self.insertando = True
        
        #*************************************************************************
        #se crean los campos de la pantalla
        #*************************************************************************

        #Se coloca un label del titulo
        self.lb_tituloPantalla = Label(self.raiz, text = "MANTENIMIENTO DE GUSTOS", font = self.fuente)
        self.lb_tituloPantalla.place(x = 320, y = 20) #colocar por medio de espacion en pixeles de la parte superior de la pantalla considerando un eje x y un eje y
        
        #coloca en el formulario el campo y el label de idNombre Gustos
        self.lb_cedula = Label(self.raiz, text = "id Nombre Gustos:")
        self.lb_cedula.place(x = 240, y = 60)
        self.txt_cedula = Entry(self.raiz, textvariable=self.t_gustos.idNombreGustos, justify="right")
        self.txt_cedula.place(x = 370, y = 60)

        #coloca en el formulario el campo y el label de descripcion gustos
        self.lb_nombre = Label(self.raiz, text = "Descripcion de los Gustos:")
        self.lb_nombre.place(x = 240, y = 90)
        self.txt_nombre = Entry(self.raiz, textvariable=self.t_gustos.descripcionGustos, justify="right", width=30)
        self.txt_nombre.place(x = 370, y = 90)

        #coloca en el formulario el campo y el label de idUsuario _TGustos
        self.lb_apellido1 = Label(self.raiz, text = "id Usuario_TGustos:")
        self.lb_apellido1.place(x = 240, y = 120)
        self.txt_apellido1 = Entry(self.raiz, textvariable=self.t_gustos.idUsuario_TGustos, justify="right", width=30)
        self.txt_apellido1.place(x = 370, y = 120)


        #coloca en el formulario el campo y el label de nombre gustos
        self.lb_apellido2 = Label(self.raiz, text = "Nombre gustos:")
        self.lb_apellido2.place(x = 240, y = 150)
        self.txt_apellido2 = Entry(self.raiz, textvariable=self.t_gustos.nombreGustos, justify="right", width=30)
        self.txt_apellido2.place(x = 370, y = 150)

        #coloca los botones enviar y borrar
        self.bt_borrar = Button(self.raiz, text="Limpiar", width=15, command = self.limpiarInformacion)
        self.bt_borrar.place(x = 370, y = 330)

        self.bt_enviar = Button(self.raiz, text="Enviar", width=15, command = self.enviarInformacion)
        self.bt_enviar.place(x = 510, y = 330)

        #Se coloca un label del informacion
        self.lb_tituloPantalla = Label(self.raiz, text = "INFORMACIÓN INCLUIDA", font = self.fuente)
        self.lb_tituloPantalla.place(x = 350, y = 360) #colocar por medio de espacion en pixeles de la parte superior de la pantalla considerando un eje x y un eje y

        #*************************************************************************
        #tabla con informacion
        #*************************************************************************
        
        self.sheet = Sheet(self.raiz,
                           page_up_down_select_row = True,
                           #empty_vertical = 0,
                           column_width = 120,
                           startup_select = (0,1,"rows"),
                           #row_height = "4",
                           #default_row_index = "numbers",
                           #default_header = "both",
                           #empty_horizontal = 0,
                           #show_vertical_grid = False,
                           #show_horizontal_grid = False,
                           #auto_resize_default_row_index = False,
                           #header_height = "3",
                           #row_index_width = 100,
                           #align = "center",
                           #header_align = "w",
                            #row_index_align = "w",
                            #data = [[f"Row {r}, Column {c}\nnewline1\nnewline2" for c in range(50)] for r in range(1000)], #to set sheet data at startup
                            headers = ['idNombreGustos', 'nombreGstos', 'DescripcionGustos','idUsuario','nombreGustos'],
                            #row_index = [f"Row {r}\nnewline1\nnewline2" for r in range(2000)],
                            #set_all_heights_and_widths = True, #to fit all cell sizes to text at start up
                            #headers = 0, #to set headers as first row at startup
                            #headers = [f"Column {c}\nnewline1\nnewline2" for c in range(30)],
                           #theme = "light green",
                            #row_index = 0, #to set row_index as first column at startup
                            #total_rows = 2000, #if you want to set empty sheet dimensions at startup
                            #total_columns = 30, #if you want to set empty sheet dimensions at startup
                            height = 195, #height and width arguments are optional
                            width = 720 #For full startup arguments see DOCUMENTATION.md
                            )
        #self.sheet.hide("row_index")
        #self.sheet.hide("header")
        #self.sheet.hide("top_left")
        self.sheet.enable_bindings(("single_select", #"single_select" or "toggle_select"
                                        
                                         "column_select",
                                         "row_select",
                                         "column_width_resize",
                                         "double_click_column_resize",
                                         #"row_width_resize",
                                         #"column_height_resize",
                                         "arrowkeys",
                                         "row_height_resize",
                                         "double_click_row_resize",
                                         "right_click_popup_menu",
                                         "rc_select",
                                         "rc_insert_column",
                                         "rc_delete_column",
                                         "rc_insert_row",
                                         "rc_delete_row"))
        #self.sheet.disable_bindings() #uses the same strings
        #self.sheet.enable_bindings()

        self.sheet.place(x = 20, y = 390)
        
        #coloca los botones cargar y eliminar
        self.bt_cargar = Button(self.raiz, text="Cargar", width=15, command = self.cargarInformacion)
        self.bt_cargar.place(x = 750, y = 385)

        self.bt_eliminar = Button(self.raiz, text="Eliminar", width=15, command = self.eliminarInformacion)
        self.bt_eliminar.place(x = 750, y = 425)
        
        self.cargarTodaInformacion()


        #*************************************************************************
        #se inicial el main loop de la pantalla
        #*************************************************************************
        self.raiz.mainloop()


    #*************************************************************************
    #Metodo para consultar la información de la base de datos para 
    #cargarla en la tabla
    #*************************************************************************
    def cargarTodaInformacion(self):
        try:
            self.gustosBo = GustosBO.GustosBO() #se crea un objeto de logica de negocio
            resultado = self.gustosBo.consultar()

            self.sheet.set_sheet_data(resultado)
        except Exception as e: 
            msg.showerror("Error",  str(e)) #si se genera algun tipo de error muestra un mensache con dicho error

    #*************************************************************************
    #Metodo para cargar informacion
    #*************************************************************************
    def cargarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            idNombreGustos = (self.sheet.get_cell_data(datoSeleccionado[0],0))
            self.t_gustos.idNombreGustos.set(idNombreGustos)
            self.gustosBo = GustosBO.GustosBO() #se crea un objeto de logica de negocio
            self.gustosBo.consultarGustos(self.t_gustos) #se envia a consultar
            self.insertando = False
            msg.showinfo("Acción: Consultar el gusto", "La información del gusto ha sido consultada correctamente") # Se muestra el mensaje de que todo esta correcto
            
        except Exception as e: 
            msg.showerror("Error",  str(e)) #si se genera algun tipo de error muestra un mensache con dicho error

    #*************************************************************************
    #Metodo para cargar eliminar la informacion
    #*************************************************************************
    def eliminarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            idNombreGustos = (self.sheet.get_cell_data(datoSeleccionado[0],0))
            gusto = (self.sheet.get_cell_data(datoSeleccionado[0],1))

            resultado = msg.askquestion("Eliminar",  "¿Desear eliminar a "+gusto+" de la base de datos?")
            if resultado == "yes":
                self.t_gustos.idNombreGustos.set(idNombreGustos)
                self.gustosBo = GustosBO.GustosBO()  #se crea un objeto de logica de negocio
                self.gustosBo.eliminar(self.t_gustos) #se envia a consultar
                self.cargarTodaInformacion()
                self.t_gustos.limpiar()
        except Exception as e: 
            msg.showerror("Error",  str(e)) #si se genera algun tipo de error muestra un mensache con dicho error


    #*************************************************************************
    #Metodo para enviar la información a la base de datos
    #*************************************************************************
    def enviarInformacion(self):
        try:
            self.gustosBo = GustosBO.GustosBO() #se crea un objeto de logica de negocio
            if(self.insertando == True):
                self.gustosBo.guardar(self.t_gustos)
            else:
                self.gustosBo.modificar(self.t_gustos)
            
            self.cargarTodaInformacion()
            self.t_gustos.limpiar() #se limpia el formulario

            if(self.insertando == True):
                msg.showinfo("Acción: Agregar el gusto", "La información de los gustos ha sido incluida correctamente") # Se muestra el mensaje de que todo esta correcto
            else:
                msg.showinfo("Acción: Agregar modificar", "La información de los gustos ha sido modificada correctamente") # Se muestra el mensaje de que todo esta correcto
        except Exception as e: 
            msg.showerror("Error",  str(e)) #si se genera algun tipo de error muestra un mensache con dicho error

    #*************************************************************************
    #Metodo para limpiar el formulario
    #*************************************************************************
    def limpiarInformacion(self):
        self.t_gustos.limpiar() #llama al metodo de la clase gustos para limpiar los atritudos de la clase
        self.insertando = True
        msg.showinfo("Acción del sistema", "La información del formulario ha sido eliminada correctamente") # muestra un mensaje indicando que se limpio el formulario


    #*************************************************************************
    #Metodo para mostrar un contro tipo datepicker
    #*************************************************************************
    def mostrarDatePicker(self):
        self.top = Toplevel(self.raiz)
        self.cal = Calendar(self.top, font="Arial 14", selectmode='day', locale='en_US',
                   cursor="hand", year=2019, month=6, day=16)
        self.cal.pack(fill="both", expand=True)
        ttk.Button(self.top, text="Seleccionar").pack()
class Aplicacion:
    

    def __init__(self):
        self.raiz = Tk()
        self.raiz.title ("Mantenimiento de Administración")
        self.raiz.geometry('900x600') 
        menubar = Menu(self.raiz)
        self.raiz.config(menu=menubar)
        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Acerca de..")
        filemenu.add_separator()
        filemenu.add_command(label="Salir", command=self.raiz.quit)
        mantmenu = Menu(menubar, tearoff=0)
        mantmenu.add_command(label="Clientes", command=self.mostrar_mant_telefonos)
        mantmenu.add_command(label="Servidor")
        menubar.add_cascade(label="Archivo", menu=filemenu)
        menubar.add_cascade(label="Mantenimiento", menu=mantmenu)
        self.fuente = font.Font(weight="bold")
        self.persona = Persona.Persona() 
        self.insertando = True
        self.lb_tituloPantalla = Label(self.raiz, text = "MANTENIMIENTO DE ADMINISTRACIÓN", font = self.fuente)
        self.lb_tituloPantalla.place(x = 320, y = 20)
        self.lb_cedula = Label(self.raiz, text = "Cedula:")
        self.lb_cedula.place(x = 240, y = 60)
        self.txt_cedula = Entry(self.raiz, textvariable=self.persona.cedula, justify="right")
        self.txt_cedula.place(x = 370, y = 60)
        self.lb_nombre = Label(self.raiz, text = "Nombre:")
        self.lb_nombre.place(x = 240, y = 90)
        self.txt_nombre = Entry(self.raiz, textvariable=self.persona.nombre, justify="right", width=30)
        self.txt_nombre.place(x = 370, y = 90)
        self.lb_apellido1 = Label(self.raiz, text = "Primer apellido:")
        self.lb_apellido1.place(x = 240, y = 120)
        self.txt_apellido1 = Entry(self.raiz, textvariable=self.persona.apellido1, justify="right", width=30)
        self.txt_apellido1.place(x = 370, y = 120)
        self.lb_apellido2 = Label(self.raiz, text = "Segundo apellido:")
        self.lb_apellido2.place(x = 240, y = 150)
        self.txt_apellido2 = Entry(self.raiz, textvariable=self.persona.apellido2, justify="right", width=30)
        self.txt_apellido2.place(x = 370, y = 150)
        self.lb_fec_nacimiento = Label(self.raiz, text = "Fecha nacimiento:")
        self.lb_fec_nacimiento.place(x = 240, y = 180)
        self.txt_fechaNacimiento = Entry(self.raiz, textvariable=self.persona.fecNacimiento, justify="right", width=30, state="readonly")
        self.txt_fechaNacimiento.place(x = 370, y = 180)
        self.bt_mostrarCalendario = Button(self.raiz, text="...", width=3, command = self.mostrarDatePicker)
        self.bt_mostrarCalendario.place(x = 650, y = 180)
        self.lb_sexo = Label(self.raiz, text = "Sexo:")
        self.lb_sexo.place(x = 240, y = 210)
        self.radio_sexoM = Radiobutton(self.raiz, text="Masculino", variable=self.persona.sexo,   value=1)
        self.radio_sexoF = Radiobutton(self.raiz, text="Femenino", variable=self.persona.sexo,   value=2)
        self.radio_sexoM.place(x = 370, y = 210)
        self.radio_sexoF.place(x = 490, y = 210)
        self.persona.sexo.set(1)
        self.lb_observaciones = Label(self.raiz, text = "Observaciones:")
        self.lb_observaciones.place(x = 240, y = 250)
        self.txt_observaciones = Entry(self.raiz, textvariable=self.persona.observaciones, justify="right", width=30)
        self.txt_observaciones.place(x = 370, y = 250)
        self.bt_borrar = Button(self.raiz, text="Limpiar", width=15, command = self.limpiarInformacion)
        self.bt_borrar.place(x = 370, y = 310)
        self.bt_enviar = Button(self.raiz, text="Enviar", width=15, command = self.enviarInformacion)
        self.bt_enviar.place(x = 510, y = 310)
        self.bt_modificar = Button(self.raiz, text="Modificar", width=15, command = self.enviarInformacion)
        self.bt_modificar.place(x = 650, y = 310)
        self.lb_tituloPantalla = Label(self.raiz, text = "INFORMACIÓN INCLUIDA", font = self.fuente)
        self.lb_tituloPantalla.place(x = 350, y = 355)
        self.lb_bloquear=Button(self.raiz,text="Bloquear",width=15,command=self.bloquear)
        self.lb_bloquear.place(x=650,y=330)
        self.desbloquear=Button(self.raiz,text="Desbloquear",width=15,command=self.desbloquear)
        self.lb_desbloquear.place(x=650,y=340)
        self.lb_iniciar_tiempo=Button(self.raiz,text="Iniciar tiempo",width=15,command=self.iniciar_tiempo)
        self.lb_iniciar_tiempo.place(x=650,y=350)
        self.lb_detener_tiempo=Button(self.raiz,text="Detener tiempo",width=15,command=self.detener_tiempo)
        self.lb_bloquear.place(x=650,y=360)
        self.lb_enviar_mensaje=Button(self.raiz,text="Enviar",width=15,command=self.enviarInformacion)
        self.lb_enviar_mensaje.place(x=650,y=370)
        self.sheet = Sheet(self.raiz,
                            page_up_down_select_row = True,
                            column_width = 120,
                            startup_select = (0,1,"rows"),
                            headers = ['Cédula', 'Nombre', 'Primer Ape.', 'Segundo Ape.', 'Fec. Nacimiento', 'Sexo'],
                            height = 195, 
                            width = 720 
                            )
        
        self.sheet.enable_bindings(("single_select", 
                                    "column_select",
                                    "row_select",
                                    "column_width_resize",
                                    "double_click_column_resize",
                                    #"row_width_resize",
                                    #"column_height_resize",
                                    "arrowkeys",
                                    "row_height_resize",
                                    "double_click_row_resize",
                                    "right_click_popup_menu",
                                    "rc_select",
                                    "rc_insert_column",
                                    "rc_delete_column",
                                    "rc_insert_row",
                                    "rc_delete_row"))
        self.sheet.place(x = 20, y = 390)
        self.bt_cargar = Button(self.raiz, text="Cargar", width=15, command = self.cargarInformacion)
        self.bt_cargar.place(x = 750, y = 385)
        self.bt_eliminar = Button(self.raiz, text="Eliminar", width=15, command = self.eliminarInformacion)
        self.bt_eliminar.place(x = 750, y = 425)
        self.cargarTodaInformacion()
        self.raiz.mainloop()
    def mostrar_mant_telefonos(self):
        mant_telefonos.MantTelefonos(self.raiz)
    def cargarTodaInformacion(self):
        try:
            self.personaBo = PersonoBO.PersonaBO() 
            resultado = self.personaBo.consultar()

            self.sheet.set_sheet_data(resultado)
        except Exception as e: 
            msg.showerror("Error",  str(e))
    def cargarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            cedula = (self.sheet.get_cell_data(datoSeleccionado[0],0))
            self.persona.cedula.set(cedula)
            self.personaBo = PersonoBO.PersonaBO() 
            self.personaBo.consultarPersona(self.persona) 
            self.insertando = False
            msg.showinfo("Acción: Consultar persona", "La información de la persona ha sido consultada correctamente")
        except Exception as e: 
            msg.showerror("Error",  str(e))
    def eliminarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            cedula = (self.sheet.get_cell_data(datoSeleccionado[0],0))
            nombre = (self.sheet.get_cell_data(datoSeleccionado[0],1))
            resultado = msg.askquestion("Eliminar",  "¿Desear eliminar a "+nombre+" de la base de datos?")
            if resultado == "yes":
                self.persona.cedula.set(cedula)
                self.personaBo = PersonoBO.PersonaBO()
                self.personaBo.eliminar(self.persona) 
                self.cargarTodaInformacion()
                self.persona.limpiar()
        except Exception as e: 
            msg.showerror("Error",  str(e))
    def printTxt(self, texto):
        print(texto)
    def enviarInformacion(self):
        try:
            self.personaBo = PersonoBO.PersonaBO() 
            if(self.insertando == True):
                self.personaBo.guardar(self.persona)
            else:
                self.personaBo.modificar(self.persona)
            self.cargarTodaInformacion()
            self.persona.limpiar() 
            if(self.insertando == True):
                msg.showinfo("Acción: Agregar persona", "La información de la persona ha sido incluida correctamente")
            else:
                msg.showinfo("Acción: Agregar modificar", "La información de la persona ha sido modificada correctamente") 
            self.insertando = True
        except Exception as e: 
            msg.showerror("Error",  str(e))
    def limpiarInformacion(self):
        self.persona.limpiar() 
        self.insertando = True
        msg.showinfo("Acción del sistema", "La información del formulario ha sido eliminada correctamente")
    def mostrarDatePicker(self):
        self.top = Toplevel(self.raiz)
        self.cal = Calendar(self.top, font="Arial 14", selectmode='day', locale='en_US',
                   cursor="hand", year=2019, month=6, day=16)
        self.cal.pack(fill="both", expand=True)
        ttk.Button(self.top, text="Seleccionar", command = self.seleccionarFecha).pack()
    def seleccionarFecha(self):
        self.persona.fecNacimiento.set(self.cal.selection_get())
예제 #3
0
class Directorio_F:
    def __init__(self):
        #Pantalla
        self.raiz = Tk()
        self.raiz.title("Mantenimiento de Factura")
        self.raiz.geometry('600x730')

        #Barra menu
        menubar = Menu(self.raiz)
        self.raiz.config(menu=menubar)

        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Salir", command=self.raiz.quit)

        mantmenu = Menu(menubar, tearoff=0)
        mantmenu.add_command(label="Clientes", command=self.abrir_C)
        mantmenu.add_command(label="Articulos", command=self.abrir_A)
        mantmenu.add_command(label="Proveedores", command=self.abrir_p)
        mantmenu.add_command(label="Conexion", command=self.abrir_R)

        menubar.add_cascade(label="Archivo", menu=filemenu)
        menubar.add_cascade(label="Mantenimiento", menu=mantmenu)

        #Objeto Factura
        self.fuente = font.Font(weight="bold")
        self.factura = Factura.Factura()
        self.insertando = True

        #Titulo
        self.lb_tituloPantalla = Label(self.raiz,
                                       text="MANTENIMIENTO DE FACTURA",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=190, y=20)

        #Formulario

        #ID factura
        self.lb_cedula = Label(self.raiz, text="ID factura:")
        self.lb_cedula.place(x=150, y=60)
        self.txt_cedula = Entry(self.raiz,
                                textvariable=self.factura.PK_N_FACTURA,
                                justify="right")
        self.txt_cedula.place(x=300, y=60)

        #Cedula
        self.lb_nombre = Label(self.raiz, text="Cedula:")
        self.lb_nombre.place(x=150, y=90)
        self.txt_nombre = Entry(self.raiz,
                                textvariable=self.factura.FK_CEDULA,
                                justify="right")
        self.txt_nombre.place(x=300, y=90)

        #Tiempo
        self.lb_apellido2 = Label(self.raiz, text="Tiempo utilizado")
        self.lb_apellido2.place(x=150, y=120)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.factura.TIEMPO_USO,
                                   justify="right",
                                   width=30)
        self.txt_apellido2.place(x=300, y=120)

        #Monto
        self.lb_apellido2 = Label(self.raiz, text="Monto Total:")
        self.lb_apellido2.place(x=150, y=150)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.factura.MONTO,
                                   justify="right",
                                   width=30)
        self.txt_apellido2.place(x=300, y=150)

        #Articulos asociados
        self.lb_apellido2 = Label(self.raiz, text="ID Articulo asociado:")
        self.lb_apellido2.place(x=150, y=180)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.factura.FK_ID_ART,
                                   justify="right")
        self.txt_apellido2.place(x=300, y=180)

        #Asociado

        #Se coloca un label del informacion
        self.lb_tituloPantalla = Label(self.raiz,
                                       text="INFORMACIÓN ASOCIADA",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=200, y=270)

        #Nombre-cedula
        self.lb_apellido2 = Label(self.raiz, text="Nombre asociado:")
        self.lb_apellido2.place(x=150, y=310)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.factura.CLIENTE,
                                   justify="right",
                                   state="readonly",
                                   width=30)
        self.txt_apellido2.place(x=300, y=310)

        #Primer Apellido-cedula
        self.lb_apellido2 = Label(self.raiz, text="1.ª Apellido asociado:")
        self.lb_apellido2.place(x=150, y=340)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.factura.APELLIDO_1,
                                   justify="right",
                                   state="readonly",
                                   width=30)
        self.txt_apellido2.place(x=300, y=340)

        #Segundo Apellido-cedula
        self.lb_apellido2 = Label(self.raiz, text="2.ª Apellido asociado:")
        self.lb_apellido2.place(x=150, y=370)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.factura.APELLIDO_2,
                                   justify="right",
                                   state="readonly",
                                   width=30)
        self.txt_apellido2.place(x=300, y=370)

        #Nombre-articulo
        self.lb_apellido2 = Label(self.raiz, text="Nombre Articulo:")
        self.lb_apellido2.place(x=150, y=400)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.factura.ARTICULO,
                                   justify="right",
                                   state="readonly",
                                   width=30)
        self.txt_apellido2.place(x=300, y=400)

        #Botones

        #Boton Limpiar
        self.bt_borrar = Button(self.raiz,
                                text="Limpiar",
                                width=15,
                                command=self.limpiarInformacion)
        self.bt_borrar.place(x=190, y=220)

        #Boton Enviar
        self.bt_enviar = Button(self.raiz,
                                text="Enviar",
                                width=15,
                                command=self.enviarInformacion)
        self.bt_enviar.place(x=310, y=220)

        #Boton Cargar
        self.bt_borrar = Button(self.raiz,
                                text="Cargar",
                                width=15,
                                command=self.cargarInformacion)
        self.bt_borrar.place(x=430, y=220)

        #Boton Eliminar
        self.bt_enviar = Button(self.raiz,
                                text="Eliminar",
                                width=15,
                                command=self.eliminarInformacion)
        self.bt_enviar.place(x=550, y=220)

        self.bt_reporte = Button(self.raiz,
                                 text="Reporte",
                                 width=15,
                                 command=self.generarPDFListado)
        self.bt_reporte.place(x=670, y=220)

        #Se coloca un label del informacion
        self.lb_tituloPantalla = Label(self.raiz,
                                       text="INFORMACIÓN INCLUIDA",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=200, y=440)

        self.sheet = Sheet(self.raiz,
                           page_up_down_select_row=True,
                           column_width=120,
                           startup_select=(0, 1, "rows"),
                           headers=[
                               'Factura', 'Cedula', 'Tiempo uso', 'Monto',
                               'ID articulo'
                           ],
                           height=170,
                           width=560)

        self.sheet.enable_bindings(
            ("single_select", "column_select", "row_select",
             "column_width_resize", "double_click_column_resize", "arrowkeys",
             "row_height_resize", "double_click_row_resize",
             "right_click_popup_menu", "rc_select", "rc_insert_column",
             "rc_delete_column", "rc_insert_row", "rc_delete_row"))

        self.sheet.place(x=20, y=480)

        self.cargarTodaInformacion()

        self.raiz.mainloop()

    def generarPDFListado(self):
        try:
            #Crea un objeto para la creación del PDF
            nombreArchivo = "ListadoPersonas.pdf"
            rep = reportPDF.Canvas(nombreArchivo)

            #Agrega el tipo de fuente Arial
            registerFont(TTFont('Arial', 'ARIAL.ttf'))

            #Crea el texto en donde se incluye la información
            textobject = rep.beginText()
            # Coloca el titulo
            textobject.setFont('Arial', 16)
            textobject.setTextOrigin(10, 800)
            textobject.setFillColor(colors.darkorange)
            textobject.textLine(text='LISTA DE FACTURA')
            #Escribe el titulo en el reportes
            rep.drawText(textobject)

            #consultar la informacion de la base de datos
            self.facturaBo = FacturaBO.FacturaBO(
            )  #se crea un objeto de logica de negocio
            informacion = self.facturaBo.consultar()
            #agrega los titulos de la tabla en la información consultada
            titulos = [
                "Factura", "Cedula", "Tiempo uso", "Monto", "ID articulo"
            ]
            informacion.insert(0, titulos)
            #crea el objeto tabla  para mostrar la información
            t = Table(informacion)
            #Le coloca el color tanto al borde de la tabla como de las celdas
            t.setStyle(
                TableStyle([("BOX", (0, 0), (-1, -1), 0.25, colors.black),
                            ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black)
                            ]))

            #para cambiar el color de las fichas de hace un ciclo según la cantidad de datos
            #que devuelve la base de datos
            data_len = len(informacion)
            for each in range(data_len):
                if each % 2 == 0:
                    bg_color = colors.whitesmoke
                else:
                    bg_color = colors.lightgrey

                if each == 0:  #Le aplica un estilo diferente a la tabla
                    t.setStyle(
                        TableStyle([('BACKGROUND', (0, each), (-1, each),
                                     colors.orange)]))
                else:
                    t.setStyle(
                        TableStyle([('BACKGROUND', (0, each), (-1, each),
                                     bg_color)]))

            #acomoda la tabla según el espacio requerido
            aW = 840
            aH = 780
            w, h = t.wrap(aW, aH)
            t.drawOn(rep, 10, aH - h)

            #Guarda el archivo
            rep.save()
            #Abre el archivo desde comandos, puede variar en MacOs es open
            #subprocess.Popen("open '%s'" % nombreArchivo, shell=True)
            subprocess.Popen(nombreArchivo, shell=True)  #Windows
        except IOError:
            msg.showerror("Error", "El archivo ya se encuentra abierto")

    #Limpiar
    def limpiarInformacion(self):
        self.factura.limpiar()
        msg.showinfo(
            "Acción del sistema",
            "La información del formulario ha sido eliminada correctamente")

    #envia la info
    def enviarInformacion(self):
        try:
            self.facturaBo = FacturaBO.FacturaBO(
            )  #se crea un objeto de logica de negocio
            if (self.insertando == True):
                self.facturaBo.guardar(self.factura)
            else:
                self.facturaBo.modificar(self.factura)

            self.cargarTodaInformacion()
            self.insertando = True
            self.factura.limpiar()  #se limpia el formulario

            if (self.insertando == True):
                msg.showinfo(
                    "Acción: Agregar factura",
                    "La información de la factura ha sido incluida correctamente"
                )  # Se muestra el mensaje de que todo esta correcto
            else:
                msg.showinfo(
                    "Acción: Modificar factura",
                    "La información de la factura ha sido modificada correctamente"
                )  # Se muestra el mensaje de que todo esta correcto
        except Exception as e:
            msg.showerror(
                "Error", str(e)
            )  #si se genera algun tipo de error muestra un mensache con dicho error

    #eliminar la info
    def eliminarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            factura = (self.sheet.get_cell_data(datoSeleccionado[0], 0))

            resultado = msg.askquestion(
                "Eliminar",
                "¿Desear eliminar a " + factura + " de la base de datos?")
            if resultado == "yes":
                self.factura.PK_N_FACTURA.set(factura)
                self.facturaBo = FacturaBO.FacturaBO()
                self.facturaBo.eliminar(self.factura)
                self.cargarTodaInformacion()
                self.factura.limpiar()
        except Exception as e:
            msg.showerror("Error", str(e))

    #cargar toda la info
    def cargarTodaInformacion(self):
        try:
            self.facturaBo = FacturaBO.FacturaBO()
            resultado = self.facturaBo.consultar()

            self.sheet.set_sheet_data(resultado)
        except Exception as e:
            msg.showerror("Error", str(e))

    #selecionado
    def cargarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            numero = (self.sheet.get_cell_data(datoSeleccionado[0], 0))

            self.factura.PK_N_FACTURA.set(numero)
            self.facturaBo = FacturaBO.FacturaBO()
            self.facturaBo.consultarFactura(self.factura)
            self.insertando = False
            msg.showinfo(
                "Acción: Consultar factura",
                "La información de la factura ha sido consultada correctamente"
            )

        except Exception as e:
            msg.showerror("Error", str(e))

    #abrir
    def abrir_C(self):
        from mant_Cliente import Directorio_C
        self.raiz.destroy()
        Directorio_C()

    def abrir_A(self):
        from mant_Articulos import Directorio_A
        self.raiz.destroy()
        Directorio_A()

    def abrir_p(self):
        from mant_Proveedor import Directorio_P
        self.raiz.destroy()
        Directorio_P()

    def abrir_R(self):
        from mant_RelacionAP import Conexion_AP
        self.raiz.destroy()
        Conexion_AP()
예제 #4
0
class MantTelefono():
    def __init__(self, parent):
        self.parent = parent

        self.raiz = Toplevel(self.parent)
        self.raiz.title("Mantenimiento de Telefonos")
        self.raiz.geometry('900x510')

        menubar = Menu(self.raiz)
        self.raiz.config(menu=menubar)

        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Acerca de..")
        filemenu.add_separator()
        filemenu.add_command(label="Salir", command=self.raiz.quit)

        mantmenu = Menu(menubar, tearoff=0)
        mantmenu.add_command(label="Personas",
                             command=self.mostrar_mant_personas)
        mantmenu.add_command(label="Direcciones")

        menubar.add_cascade(label="Archivo", menu=filemenu)
        menubar.add_cascade(label="Mantenimiento", menu=mantmenu)

        self.fuente = font.Font(weight="bold")

        self.telefono = Telefono.Telefono()
        self.insertando = True
        self.nombreCliente = StringVar()

        self.Cliente = Cliente.Cliente()

        self.lb_tituloPantalla = Label(self.raiz,
                                       text="MANTENIMIENTO DE TELEFONOS",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=320, y=20)

        self.lb_cedula = Label(self.raiz, text="Cedula:")
        self.lb_cedula.place(x=240, y=60)
        self.txt_cedula = Entry(self.raiz,
                                textvariable=self.telefono.cedula,
                                justify="right",
                                width=12)
        self.txt_cedula.place(x=370, y=60)

        self.bt_consultar = Button(self.raiz,
                                   text="Consultar",
                                   width=15,
                                   command=self.consultarNombre)
        self.bt_consultar.place(x=512, y=60)

        self.lb_nombre = Label(self.raiz, text="Nombre:")
        self.lb_nombre.place(x=240, y=90)
        self.txt_nombre = Entry(self.raiz,
                                textvariable=self.nombrePersona,
                                justify="right",
                                width=30)
        self.txt_nombre.place(x=370, y=90)

        self.lb_telefono = Label(self.raiz, text="Telefono:")
        self.lb_telefono.place(x=240, y=120)
        self.txt_telefono = Entry(self.raiz,
                                  textvariable=self.telefono.telefono,
                                  justify="right",
                                  width=30)
        self.txt_telefono.place(x=370, y=120)

        self.lb_descripcion = Label(self.raiz, text="Descripción:")
        self.lb_descripcion.place(x=240, y=150)
        self.txt_descripcion = Entry(self.raiz,
                                     textvariable=self.telefono.descripcion,
                                     justify="right",
                                     width=30)
        self.txt_descripcion.place(x=370, y=150)

        self.bt_borrar = Button(self.raiz,
                                text="Limpiar",
                                width=15,
                                command=self.limpiarInformacion)
        self.bt_borrar.place(x=370, y=180)

        self.bt_enviar = Button(self.raiz,
                                text="Enviar",
                                width=15,
                                command=self.enviarInformacion)
        self.bt_enviar.place(x=510, y=180)

        self.lb_tituloPantalla = Label(self.raiz,
                                       text="INFORMACIÓN INCLUIDA",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=350, y=230)
        self.sheet = Sheet(
            self.raiz,
            page_up_down_select_row=True,
            column_width=120,
            startup_select=(0, 1, "rows"),
            headers=['Cédula', 'Nombre', 'Telefono', 'Descripción'],
            height=195,
            width=720)

        self.sheet.enable_bindings(
            ("single_select", "column_select", "row_select",
             "column_width_resize", "double_click_column_resize", "arrowkeys",
             "row_height_resize", "double_click_row_resize",
             "right_click_popup_menu", "rc_select", "rc_insert_column",
             "rc_delete_column", "rc_insert_row", "rc_delete_row"))
        self.sheet.place(x=20, y=260)

        self.bt_cargar = Button(self.raiz,
                                text="Cargar",
                                width=15,
                                command=self.cargarInformacion)
        self.bt_cargar.place(x=750, y=255)

        self.bt_eliminar = Button(self.raiz,
                                  text="Eliminar",
                                  width=15,
                                  command=self.eliminarInformacion)
        self.bt_eliminar.place(x=750, y=295)

        self.cargarTodaInformacion()

        self.parent.withdraw()

        self.raiz.protocol("WM_DELETE_WINDOW", self.on_closing)

    def enviarInformacion(self):
        try:
            self.telefonoBo = TelefonoBO.TelefonoBO()
            if (self.insertando == True):
                self.telefonoBo.guardar(self.telefono)
            else:
                self.telefonoBo.modificar(self.telefono)

            self.cargarTodaInformacion()
            self.telefono.limpiar()
            self.nombreCliente.set("")

            if (self.insertando == True):
                msg.showinfo(
                    "Acción: Agregar teléfono",
                    "La información del teléfono ha sido incluida correctamente"
                )
            else:
                msg.showinfo(
                    "Acción: Modificar teléfono",
                    "La información del teléfono ha sido modificada correctamente"
                )

            self.insertando = True

        except Exception as e:
            msg.showerror("Error", str(e))

    def limpiarInformacion(self):
        self.telefono.limpiar()
        self.nombreCliente.set("")
        self.insertando = True
        msg.showinfo(
            "Acción del sistema",
            "La información del formulario ha sido eliminada correctamente")

    def consultarNombre(self):
        try:
            self.ClienteBo = PersonoBO.ClienteBO()
            self.Cliente.cedula.set(self.telefono.cedula.get())
            self.ClienteBo.consultarCliente(self.Cliente)
            if self.Cliente.nombre.get() == "":
                self.nombreCliente = "No existe el Cliente "
            else:
                self.nombreCliente.set(self.Cliente.nombre.get() + " " +
                                       self.Cliente.apellido1.get() + " " +
                                       self.Cliente.apellido2.get())

        except Exception as e:
            msg.showerror("Error", str(e))

    def cargarTodaInformacion(self):
        try:
            self.telefonoBo = TelefonoBO.TelefonoBO()
            resultado = self.telefonoBo.consultar()

            self.sheet.set_sheet_data(resultado)
        except Exception as e:
            msg.showerror("Error", str(e))

    def cargarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            telefono = (self.sheet.get_cell_data(datoSeleccionado[0], 2))
            self.telefono.telefono.set(telefono)
            self.telefonoBo = TelefonoBO.TelefonoBO()
            self.telefonoBo.consultarTelefono(self.telefono)
            self.consultarNombre()
            self.insertando = False
            msg.showinfo(
                "Acción: Consultar teléfono",
                "La información del teléfono ha sido consultada correctamente")

        except Exception as e:
            msg.showerror("Error", str(e))

    def eliminarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            telefono = (self.sheet.get_cell_data(datoSeleccionado[0], 2))
            nombre = (self.sheet.get_cell_data(datoSeleccionado[0], 1))

            resultado = msg.askquestion(
                "Eliminar", "¿Desear eliminar el telefono " + telefono +
                " de " + nombre + " de la base de datos?")
            if resultado == "yes":
                self.telefono.telefono.set(telefono)
                self.telefonoBo = TelefonoBO.TelefonoBO()
                self.telefonoBo.eliminar(self.telefono)
                self.cargarTodaInformacion()
                self.telefono.limpiar()
                self.nombreCliente.set("")

        except Exception as e:
            msg.showerror("Error", str(e))

    def mostrar_mant_cliente(self):
        self.parent.deiconify()
        self.raiz.destroy()

    def on_closing(self):
        self.parent.destroy()
예제 #5
0
class Directorio_C:
    def __init__(self):

        #Pantalla
        self.raiz = Tk()
        self.raiz.title("Mantenimiento de Clientes")
        self.raiz.geometry('600x630')

        #Barra menu
        menubar = Menu(self.raiz)
        self.raiz.config(menu=menubar)

        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Salir", command=self.raiz.quit)

        mantmenu = Menu(menubar, tearoff=0)
        mantmenu.add_command(label="Facturas", command=self.abrir_F)
        mantmenu.add_command(label="Articulos", command=self.abrir_A)
        mantmenu.add_command(label="Proveedores", command=self.abrir_p)
        mantmenu.add_command(label="Conexion", command=self.abrir_R)

        menubar.add_cascade(label="Archivo", menu=filemenu)
        menubar.add_cascade(label="Mantenimiento", menu=mantmenu)

        #Objecto cliente
        self.fuente = font.Font(weight="bold")
        self.cliente = Cliente.Cliente()
        self.insertando = True

        #Titulo
        self.lb_tituloPantalla = Label(self.raiz,
                                       text="MANTENIMIENTO DE CLIENTES",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=180, y=20)

        #Formulario

        #Cedula
        self.lb_cedula = Label(self.raiz, text="Cedula:")
        self.lb_cedula.place(x=100, y=60)
        self.txt_cedula = Entry(self.raiz,
                                textvariable=self.cliente.PK_CEDULA,
                                justify="right")
        self.txt_cedula.place(x=230, y=60)

        #Nombre
        self.lb_nombre = Label(self.raiz, text="Nombre:")
        self.lb_nombre.place(x=100, y=90)
        self.txt_nombre = Entry(self.raiz,
                                textvariable=self.cliente.NOMBRE_C,
                                justify="right",
                                width=30)
        self.txt_nombre.place(x=230, y=90)

        #Apellido 1
        self.lb_apellido1 = Label(self.raiz, text="Primer apellido:")
        self.lb_apellido1.place(x=100, y=120)
        self.txt_apellido1 = Entry(self.raiz,
                                   textvariable=self.cliente.APELLIDO_1,
                                   justify="right",
                                   width=30)
        self.txt_apellido1.place(x=230, y=120)

        #Apellido 2
        self.lb_apellido2 = Label(self.raiz, text="Segundo apellido:")
        self.lb_apellido2.place(x=100, y=150)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.cliente.APELLIDO_2,
                                   justify="right",
                                   width=30)
        self.txt_apellido2.place(x=230, y=150)

        #Fecha nacimiento
        self.lb_fec_nacimiento = Label(self.raiz, text="Fecha nacimiento:")
        self.lb_fec_nacimiento.place(x=100, y=180)
        self.txt_fechaNacimiento = Entry(
            self.raiz,
            textvariable=self.cliente.FECHA_NACIMIENTO,
            justify="right",
            width=30,
            state="readonly")
        self.txt_fechaNacimiento.place(x=230, y=180)
        self.bt_mostrarCalendario = Button(self.raiz,
                                           text="...",
                                           width=3,
                                           command=self.mostrarDatePicker)
        self.bt_mostrarCalendario.place(x=510, y=180)

        #Direccion
        self.lb_direccion = Label(self.raiz, text="Direccion:")
        self.lb_direccion.place(x=100, y=210)
        self.txt_direccion = Entry(self.raiz,
                                   textvariable=self.cliente.DIRECCION,
                                   justify="right",
                                   width=30)
        self.txt_direccion.place(x=230, y=210)

        #Observaciones
        self.lb_observaciones = Label(self.raiz, text="Observaciones:")
        self.lb_observaciones.place(x=100, y=240)
        self.txt_observaciones = Entry(self.raiz,
                                       textvariable=self.cliente.OBSERVACIONES,
                                       justify="right",
                                       width=30)
        self.txt_observaciones.place(x=230, y=240)

        #Telefono 1
        self.lb_telefono_1 = Label(self.raiz, text="Telefono Principal:")
        self.lb_telefono_1.place(x=100, y=270)
        self.txt_telefono_1 = Entry(self.raiz,
                                    textvariable=self.cliente.TELEFONO_1,
                                    justify="right",
                                    width=30)
        self.txt_telefono_1.place(x=230, y=270)

        #Telefono 2
        self.lb_telefono_2 = Label(self.raiz, text="Telefono segundario:")
        self.lb_telefono_2.place(x=100, y=300)
        self.txt_telefono_2 = Entry(self.raiz,
                                    textvariable=self.cliente.TELEFONO_2,
                                    justify="right",
                                    width=30)
        self.txt_telefono_2.place(x=230, y=300)

        #Boton Limpiar
        self.bt_borrar = Button(self.raiz,
                                text="Limpiar",
                                width=15,
                                command=self.limpiarInformacion)
        self.bt_borrar.place(x=70, y=340)

        #Boton Enviar
        self.bt_enviar = Button(self.raiz,
                                text="Enviar",
                                width=15,
                                command=self.enviarInformacion)
        self.bt_enviar.place(x=190, y=340)

        #Boton Cargar
        self.bt_borrar = Button(self.raiz,
                                text="Cargar",
                                width=15,
                                command=self.cargarInformacion)
        self.bt_borrar.place(x=310, y=340)

        #Boton Eliminar
        self.bt_enviar = Button(self.raiz,
                                text="Eliminar",
                                width=15,
                                command=self.eliminarInformacion)
        self.bt_enviar.place(x=430, y=340)

        self.bt_reporte = Button(self.raiz,
                                 text="Reporte",
                                 width=15,
                                 command=self.generarPDFListado)
        self.bt_reporte.place(x=550, y=340)

        #label del informacion
        self.lb_tituloPantalla = Label(self.raiz,
                                       text="INFORMACIÓN INCLUIDA",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=190, y=400)

        #cuadro excel
        self.sheet = Sheet(self.raiz,
                           page_up_down_select_row=True,
                           column_width=120,
                           startup_select=(0, 1, "rows"),
                           headers=[
                               'Cédula', 'Nombre', 'Primer Ape.',
                               'Segundo Ape.', 'Fec. Nacimiento', 'Direccion',
                               'Observaciones', 'Telefono 1', 'Telefono 2'
                           ],
                           height=170,
                           width=560)

        self.sheet.enable_bindings(
            ("single_select", "column_select", "row_select",
             "column_width_resize", "double_click_column_resize", "arrowkeys",
             "row_height_resize", "double_click_row_resize",
             "right_click_popup_menu", "rc_select", "rc_insert_column",
             "rc_delete_column", "rc_insert_row", "rc_delete_row"))

        self.sheet.place(x=20, y=440)

        #toda informacion
        self.cargarTodaInformacion()

        #cierre de raiz
        self.raiz.mainloop()

    def generarPDFListado(self):
        try:
            #Crea un objeto para la creación del PDF
            nombreArchivo = "ListadoPersonas.pdf"
            rep = reportPDF.Canvas(nombreArchivo)

            #Agrega el tipo de fuente Arial
            registerFont(TTFont('Arial', 'ARIAL.ttf'))

            #Crea el texto en donde se incluye la información
            textobject = rep.beginText()
            # Coloca el titulo
            textobject.setFont('Arial', 16)
            textobject.setTextOrigin(10, 800)
            textobject.setFillColor(colors.darkorange)
            textobject.textLine(text='LISTA DE CLIENTES')
            #Escribe el titulo en el reportes
            rep.drawText(textobject)

            #consultar la informacion de la base de datos
            self.clienteBo = ClienteBO.ClienteBO(
            )  #se crea un objeto de logica de negocio
            informacion = self.clienteBo.consultar()
            #agrega los titulos de la tabla en la información consultada
            titulos = [
                "Cédula", "Nombre", "Primer Ape.", "Segundo Ape.",
                "Fec. Nacimiento", "Direccion", "Observaciones", "Telefono 1",
                "Telefono 2"
            ]
            informacion.insert(0, titulos)
            #crea el objeto tabla  para mostrar la información
            t = Table(informacion)
            #Le coloca el color tanto al borde de la tabla como de las celdas
            t.setStyle(
                TableStyle([("BOX", (0, 0), (-1, -1), 0.25, colors.black),
                            ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black)
                            ]))

            #para cambiar el color de las fichas de hace un ciclo según la cantidad de datos
            #que devuelve la base de datos
            data_len = len(informacion)
            for each in range(data_len):
                if each % 2 == 0:
                    bg_color = colors.whitesmoke
                else:
                    bg_color = colors.lightgrey

                if each == 0:  #Le aplica un estilo diferente a la tabla
                    t.setStyle(
                        TableStyle([('BACKGROUND', (0, each), (-1, each),
                                     colors.orange)]))
                else:
                    t.setStyle(
                        TableStyle([('BACKGROUND', (0, each), (-1, each),
                                     bg_color)]))

            #acomoda la tabla según el espacio requerido
            aW = 840
            aH = 780
            w, h = t.wrap(aW, aH)
            t.drawOn(rep, 10, aH - h)

            #Guarda el archivo
            rep.save()
            #Abre el archivo desde comandos, puede variar en MacOs es open
            #subprocess.Popen("open '%s'" % nombreArchivo, shell=True)
            subprocess.Popen(nombreArchivo, shell=True)  #Windows
        except IOError:
            msg.showerror("Error", "El archivo ya se encuentra abierto")

    #calendario
    def mostrarDatePicker(self):
        #ventana segundaria
        self.top = Toplevel(self.raiz)
        self.cal = Calendar(self.top,
                            font="Arial 14",
                            selectmode='day',
                            locale='en_US',
                            cursor="hand1",
                            year=2019,
                            month=6,
                            day=16)
        self.cal.pack(fill="both", expand=True)
        ttk.Button(self.top, text="Seleccionar",
                   command=self.seleccionarFecha).pack()

    #Selecciona la fecha
    def seleccionarFecha(self):
        self.cliente.FECHA_NACIMIENTO.set(self.cal.selection_get())
        self.top.destroy()

    #Limpiar
    def limpiarInformacion(self):
        self.cliente.limpiar()
        msg.showinfo(
            "Acción del sistema",
            "La información del formulario ha sido eliminada correctamente")

    #envia la info
    def enviarInformacion(self):
        try:
            self.clienteBo = ClienteBO.ClienteBO()
            if (self.insertando == True):
                self.clienteBo.guardar(self.cliente)
            else:
                self.clienteBo.modificar(self.cliente)

            self.cargarTodaInformacion()
            self.insertando = True
            self.cliente.limpiar()

            if (self.insertando == True):
                msg.showinfo(
                    "Acción: Agregar cliente",
                    "La información del cliente ha sido incluida correctamente"
                )
            else:
                msg.showinfo(
                    "Acción: modificar cliente",
                    "La información del cliente ha sido modificada correctamente"
                )
        except Exception as e:
            msg.showerror("Error", str(e))

    #eliminar la info
    def eliminarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            cedula = (self.sheet.get_cell_data(datoSeleccionado[0], 0))
            nombre = (self.sheet.get_cell_data(datoSeleccionado[0], 1))

            resultado = msg.askquestion(
                "Eliminar",
                "¿Desear eliminar a " + nombre + " de la base de datos?")
            if resultado == "yes":
                self.cliente.PK_CEDULA.set(cedula)
                self.clienteBo = ClienteBO.ClienteBO()
                self.clienteBo.eliminar(self.cliente)
                self.cliente.limpiar()
        except Exception as e:
            msg.showerror("Error", str(e))

        self.cargarTodaInformacion(
        )  #refrescar la pagina especialmente para llaves foraneas relacionales

    #cargar toda la info
    def cargarTodaInformacion(self):
        try:
            self.clienteBo = ClienteBO.ClienteBO()
            resultado = self.clienteBo.consultar()

            self.sheet.set_sheet_data(resultado)
        except Exception as e:
            msg.showerror("Error", str(e))

    #selecionado
    def cargarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            cedula = (self.sheet.get_cell_data(datoSeleccionado[0], 0))
            self.cliente.PK_CEDULA.set(cedula)
            self.clienteBo = ClienteBO.ClienteBO()
            self.clienteBo.consultarCliente(self.cliente)
            self.insertando = False
            msg.showinfo(
                "Acción: Consultar cliente",
                "La información del cliente ha sido consultada correctamente")

        except Exception as e:
            msg.showerror("Error", str(e))

    #abrir
    def abrir_F(self):
        from mant_Factura import Directorio_F
        self.raiz.destroy()
        Directorio_F()

    def abrir_A(self):
        from mant_Articulos import Directorio_A
        self.raiz.destroy()
        Directorio_A()

    def abrir_p(self):
        from mant_Proveedor import Directorio_P
        self.raiz.destroy()
        Directorio_P()

    def abrir_R(self):
        from mant_RelacionAP import Conexion_AP
        self.raiz.destroy()
        Conexion_AP()
예제 #6
0
class Directorio_A:
    def __init__(self):
        #Pantalla
        self.raiz = Tk()
        self.raiz.title("Mantenimiento de Articulos")
        self.raiz.geometry('680x520')

        #Barra menu
        menubar = Menu(self.raiz)
        self.raiz.config(menu=menubar)

        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Salir", command=self.raiz.quit)

        mantmenu = Menu(menubar, tearoff=0)
        mantmenu.add_command(label="Proveedor", command=self.abrir_P)
        mantmenu.add_command(label="Clientes", command=self.abrir_C)
        mantmenu.add_command(label="Facturas", command=self.abrir_F)
        mantmenu.add_command(label="Conexion", command=self.abrir_R)

        menubar.add_cascade(label="Archivo", menu=filemenu)
        menubar.add_cascade(label="Mantenimiento", menu=mantmenu)

        #Objecto Articulo
        self.fuente = font.Font(weight="bold")
        self.articulo = Articulos.Articulo()
        self.insertando = True

        #Titulo
        self.lb_tituloPantalla = Label(self.raiz,
                                       text="MANTENIMIENTO DE ARTICULOS",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=180, y=20)

        #Formulario

        #ID articulo
        self.lb_cedula = Label(self.raiz, text="ID articulo:")
        self.lb_cedula.place(x=100, y=60)
        self.txt_cedula = Entry(self.raiz,
                                textvariable=self.articulo.PK_ID_ART,
                                justify="right")
        self.txt_cedula.place(x=230, y=60)

        #Nombre
        self.lb_nombre = Label(self.raiz, text="nombre del articulo:")
        self.lb_nombre.place(x=100, y=90)
        self.txt_nombre = Entry(self.raiz,
                                textvariable=self.articulo.NOMBRE,
                                justify="right",
                                width=30)
        self.txt_nombre.place(x=230, y=90)

        #Cantidad existente
        self.lb_apellido1 = Label(self.raiz, text="Cantidad existente:")
        self.lb_apellido1.place(x=100, y=120)
        self.txt_apellido1 = Entry(self.raiz,
                                   textvariable=self.articulo.CANT_EXI,
                                   justify="right")
        self.txt_apellido1.place(x=230, y=120)

        #descripcion
        self.lb_apellido2 = Label(self.raiz, text="Descripcion:")
        self.lb_apellido2.place(x=100, y=150)
        self.txt_apellido2 = Entry(self.raiz,
                                   textvariable=self.articulo.DESCRIPCION,
                                   justify="right",
                                   width=30)
        self.txt_apellido2.place(x=230, y=150)

        #Precio unitario
        self.lb_apellido1 = Label(self.raiz, text="Precio unitario:")
        self.lb_apellido1.place(x=100, y=180)
        self.txt_apellido1 = Entry(self.raiz,
                                   textvariable=self.articulo.PRECIO_UN,
                                   justify="right")
        self.txt_apellido1.place(x=230, y=180)

        #Boton Limpiar
        self.bt_borrar = Button(self.raiz, text="Limpiar", width=15)
        self.bt_borrar.place(x=70, y=220)

        #Boton Enviar
        self.bt_enviar = Button(self.raiz,
                                text="Enviar",
                                width=15,
                                command=self.enviarInformacion)
        self.bt_enviar.place(x=190, y=220)

        #Boton Cargar
        self.bt_borrar = Button(self.raiz,
                                text="Cargar",
                                width=15,
                                command=self.cargarInformacion)
        self.bt_borrar.place(x=310, y=220)

        #Boton Eliminar
        self.bt_enviar = Button(self.raiz,
                                text="Eliminar",
                                width=15,
                                command=self.eliminarInformacion)
        self.bt_enviar.place(x=430, y=220)

        self.bt_reporte = Button(self.raiz,
                                 text="Reporte",
                                 width=15,
                                 command=self.generarPDFListado)
        self.bt_reporte.place(x=550, y=340)

        #Se coloca un label del informacion
        self.lb_tituloPantalla = Label(self.raiz,
                                       text="INFORMACIÓN INCLUIDA",
                                       font=self.fuente)
        self.lb_tituloPantalla.place(x=190, y=275)

        self.sheet = Sheet(self.raiz,
                           page_up_down_select_row=True,
                           column_width=120,
                           startup_select=(0, 1, "rows"),
                           headers=[
                               'ID articulo', 'Nombre', 'Cantidad',
                               'Descripcion', 'Preio Unitario'
                           ],
                           height=170,
                           width=560)

        #hoja excel
        self.sheet.enable_bindings(
            ("single_select", "column_select", "row_select",
             "column_width_resize", "double_click_column_resize", "arrowkeys",
             "row_height_resize", "double_click_row_resize",
             "right_click_popup_menu", "rc_select", "rc_insert_column",
             "rc_delete_column", "rc_insert_row", "rc_delete_row"))

        self.sheet.place(x=20, y=310)

        #toda informacion
        self.cargarTodaInformacion()

        self.raiz.mainloop()

    def generarPDFListado(self):
        try:
            #Crea un objeto para la creación del PDF
            nombreArchivo = "ListadoArticulos.pdf"
            rep = reportPDF.Canvas(nombreArchivo)

            #Agrega el tipo de fuente Arial
            registerFont(TTFont('Arial', 'ARIAL.ttf'))

            #Crea el texto en donde se incluye la información
            textobject = rep.beginText()
            # Coloca el titulo
            textobject.setFont('Arial', 16)
            textobject.setTextOrigin(10, 800)
            textobject.setFillColor(colors.darkorange)
            textobject.textLine(text='LISTA DE ARTICULOS')
            #Escribe el titulo en el reportes
            rep.drawText(textobject)

            #consultar la informacion de la base de datos
            self.articuloBo = ArticuloBO.ArticuloBO(
            )  #se crea un objeto de logica de negocio
            informacion = self.articuloBo.consultar()
            #agrega los titulos de la tabla en la información consultada
            titulos = [
                "ID articulo", "Nombre del articulo", "Descripcion",
                "Cant.Existente", "Precio Unitario"
            ]
            informacion.insert(0, titulos)
            #crea el objeto tabla  para mostrar la información
            t = Table(informacion)
            #Le coloca el color tanto al borde de la tabla como de las celdas
            t.setStyle(
                TableStyle([("BOX", (0, 0), (-1, -1), 0.25, colors.black),
                            ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black)
                            ]))

            #para cambiar el color de las fichas de hace un ciclo según la cantidad de datos
            #que devuelve la base de datos
            data_len = len(informacion)
            for each in range(data_len):
                if each % 2 == 0:
                    bg_color = colors.whitesmoke
                else:
                    bg_color = colors.lightgrey

                if each == 0:  #Le aplica un estilo diferente a la tabla
                    t.setStyle(
                        TableStyle([('BACKGROUND', (0, each), (-1, each),
                                     colors.orange)]))
                else:
                    t.setStyle(
                        TableStyle([('BACKGROUND', (0, each), (-1, each),
                                     bg_color)]))

            #acomoda la tabla según el espacio requerido
            aW = 840
            aH = 780
            w, h = t.wrap(aW, aH)
            t.drawOn(rep, 10, aH - h)

            #Guarda el archivo
            rep.save()
            #Abre el archivo desde comandos, puede variar en MacOs es open
            #subprocess.Popen("open '%s'" % nombreArchivo, shell=True)
            subprocess.Popen(nombreArchivo, shell=True)  #Windows
        except IOError:
            msg.showerror("Error", "El archivo ya se encuentra abierto")

    #Limpiar
    def limpiarInformacion(self):
        self.articulo.limpiar()
        msg.showinfo(
            "Acción del sistema",
            "La información del formulario ha sido eliminada correctamente")

    #envia la info
    def enviarInformacion(self):
        try:
            self.articuloBo = ArticuloBO.ArticuloBO()
            if (self.insertando == True):
                self.articuloBo.guardar(self.articulo)
            else:
                self.articuloBo.modificar(self.articulo)

            self.cargarTodaInformacion()
            self.insertando = True
            self.articulo.limpiar()

            if (self.insertando == True):
                msg.showinfo(
                    "Acción: Agregar articulo",
                    "La información del articulo ha sido incluida correctamente"
                )
            else:
                msg.showinfo(
                    "Acción: modificar articulo",
                    "La información del articulo ha sido modificada correctamente"
                )
        except Exception as e:
            msg.showerror("Error", str(e))

    #eliminar la info
    def eliminarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            idarticulo = (self.sheet.get_cell_data(datoSeleccionado[0], 0))
            nombre = (self.sheet.get_cell_data(datoSeleccionado[0], 1))

            resultado = msg.askquestion(
                "Eliminar",
                "¿Desear eliminar a " + nombre + " de la base de datos?")
            if resultado == "yes":
                self.articulo.PK_ID_ART.set(idarticulo)
                self.articuloBo = ArticuloBO.ArticuloBO()
                self.articuloBo.eliminar(self.articulo)
                self.cargarTodaInformacion()
                self.articulo.limpiar()
        except Exception as e:
            msg.showerror("Error", str(e))

    #cargar toda la info
    def cargarTodaInformacion(self):
        try:
            self.articuloBo = ArticuloBO.ArticuloBO()
            resultado = self.articuloBo.consultar()

            self.sheet.set_sheet_data(resultado)
        except Exception as e:
            msg.showerror("Error", str(e))

    #selecionado
    def cargarInformacion(self):
        try:
            datoSeleccionado = self.sheet.get_currently_selected()
            idarticulo = (self.sheet.get_cell_data(datoSeleccionado[0], 0))
            self.articulo.PK_ID_ART.set(idarticulo)
            self.articuloBo = ArticuloBO.ArticuloBO()
            self.articuloBo.consultarArticulo(self.articulo)
            self.insertando = False
            msg.showinfo(
                "Acción: Consultar proveedor",
                "La información del proveedor ha sido consultada correctamente"
            )

        except Exception as e:
            msg.showerror("Error", str(e))

    #abrir
    def abrir_P(self):
        from mant_Proveedor import Directorio_P
        self.raiz.destroy()
        Directorio_P()

    def abrir_C(self):
        from mant_Clientes import Directorio_C
        self.raiz.destroy()
        Directorio_C()

    def abrir_F(self):
        from mant_Factura import Directorio_F
        self.raiz.destroy()
        Directorio_F()

    def abrir_R(self):
        from mant_RelacionAP import Conexion_AP
        self.raiz.destroy()
        Conexion_AP()

        self.raiz.mainloop()