lunes, 7 de octubre de 2019

Aplicacion en Mongo venta Boletos

from Tkinter import *
import tkMessageBox
from tkMessageBox import *
from pymongo import MongoClient
from Tkinter import OptionMenu
from datetime import datetime
global total, boletos, area, fecha
#VENTANA CON BANNERS
ventana = Tk()
ventana.title("Venta de Boletos")
ventana = Canvas(width = 500, height = 630, bg = 'black')
ventana.pack(expand = YES, fill = BOTH)
banner1 = PhotoImage(file = 'C:/programas/21p.gif')
ventana.create_image(10, 10, image = banner1, anchor = NW)
banner2 = PhotoImage(file = 'C:/programas/21pb.gif')
ventana.create_image(5, 520, image = banner2, anchor = NW)
#AREA A ESCOGER
var = StringVar(ventana)
var.set("Eliga un area")
etiqueta_area = Label(ventana, text='Area: ',background="yellow3",foreground="black",font=('Arial',10)).place(x=120, y=250)
ent_area = OptionMenu(ventana, var, "Pista General", "Segundo Piso", "Tercer Piso")
ent_area.config(background="yellow3",foreground="black")
ent_area.place(x=290, y=250)
#CANTIDAD DE BOELTOS
et1 = Label(ventana, text="Cantidad de boletos",background="yellow3",foreground="black",font=('Arial',10)).place(x=80, y=320)
arr1 = [1, 2, 3, 4, 5, 6, 7]
cantidad = StringVar()
s1 = Spinbox(ventana, textvariable=cantidad, values=arr1,background="yellow3",foreground="black").place(x=280, y=320)
#MOSTRAR MAPA DEL EVENTO
def mostrarmapa():
mapa= Toplevel()
mapa.title("Mapa del Evento")
map = PhotoImage(file='C:/programas/mapa.gif')
mostrar = Label(mapa, image=map)
mostrar.pack()
mapa.mainloop()
#CALCULAR TOTAL A PAGAR
def comprar():
area = str(var.get())
boletos = int(cantidad.get())
fecha = datetime.now()
if area=="Pista General" and boletos<=4:
total=boletos*1900
area=1900
tkMessageBox.showinfo("Total", cantidad.get()+" boletos para Pista General, su total es de: " + str(total))
print area
print boletos
print total
print fecha
elif area=="Pista General" and boletos>4:
showerror("Error", "No se permite adquirir mas de 4 boletos para esta area")
elif area=="Segundo Piso" and boletos>0:
total = boletos * 1500
area=1500
tkMessageBox.showinfo("Total", cantidad.get()+" boletos para Segundo Piso, su total es de: " + str(total))
print area
print boletos
print total
print fecha
elif area=="Tercer Piso" and boletos>0:
total = boletos * 1200
area=1200
tkMessageBox.showinfo("Total", cantidad.get()+" boletos para Tercer Piso, su total es de: " + str(total))
print area
print boletos
print total
print fecha
conexion(area, boletos, total, fecha)
def conexion(area, boletos, total, fecha):
client = MongoClient('localhost', 27017)
db = client['Boletos']
document = {'Precio de Area': area, 'Cantidad de Boletos': boletos, 'Total a Pagar': total, 'Fecha de Compra': fecha}
_id = db['Boletos_Comprados'].insert(document)
def infoboletos():
datos = Toplevel(bg = 'black')
datos.title("Boletos Vendidos")
datos.geometry('520x400')
banner = PhotoImage(file='C:/programas/21pb.gif')
mostrar = Label(datos, image=banner, background="black")
mostrar.place(x=10,y=0)
et1 = Label(datos, text="Informacion de Boletos Vendidos", background="yellow3", foreground="black",font=('Arial',19)).place(x=70, y=130)
b4 = Button(datos, text='Datos de Boletos Comprados', background="yellow3", foreground="black", command=boletoscomprados,font=('Arial', 10)).place(x=170, y=200)
b5 = Button(datos, text='Numero de Boletos Comprados', background="yellow3", foreground="black", command=contarboletoscomprados,font=('Arial', 10)).place(x=160, y=250)
b6 = Button(datos, text='Boletos Comprados por Area', background="yellow3", foreground="black",command=boletoscompradosarea, font=('Arial', 10)).place(x=170, y=300)
datos.mainloop()
def boletoscomprados():
client = MongoClient('localhost', 27017)
db = client['Boletos']
coleccion = db['Boletos_Comprados'].find()
for x in coleccion:
print (x)
print " "
def contarboletoscomprados():
client = MongoClient('localhost', 27017)
db = client['Boletos']
coleccion = db['Boletos_Comprados']
print ('Candtidad de Boeltos Comprados: ', db['Boletos_Comprados'].count_documents({}))
print " "
def boletoscompradosarea():
client = MongoClient('localhost', 27017)
db = client['Boletos']
coleccion = db['Boletos_Comprados']
for datos in coleccion.aggregate([{"$unwind": "$Precio de Area"},{"$group":{"_id":"$Precio de Area","count":{"$sum":1}}}]):
print("%s: %d" % (datos["_id"],datos["count"]))
print " "
#BOTONES
b1=Button(ventana, text='Mostrar mapa',background="yellow3",foreground="black", command=mostrarmapa,font=('Arial',10)).place(x=170, y=400)
b2=Button(ventana, text='Pagar', background="yellow3",foreground="black", command=comprar,font=('Arial',10)).place(x=275, y=400)
b3=Button(ventana, text='Informacion de Boletos Comprados', background="yellow3",foreground="black", command=infoboletos,font=('Arial',10)).place(x=140, y=450)
ventana.mainloop()

No hay comentarios:

Publicar un comentario