LucasPy

qr code generator

May 22nd, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.34 KB | Software | 0 0
  1. import sqlite3
  2. import random
  3. import qrcode
  4. import string
  5. import datetime
  6. import tkinter as tk
  7. import customtkinter as ctk
  8. from PIL import ImageTk, Image
  9. from customtkinter.windows import *
  10.  
  11. conn = sqlite3.connect('bancomain.db')
  12. cursor = conn.cursor()
  13.  
  14. cursor.execute("CREATE TABLE IF NOT EXISTS codigosV (id integer PRIMARY KEY AUTOINCREMENT, codigoValido VARCHAR(8), dataHora VARCHAR(17), nomeVendedor VARCHAR(50), nomeCliente VARCHAR(50), emailCliente VARCHAR(50), numeroCliente VARCHAR(11), valor VARCHAR (10))")
  15.  
  16. print('banco de dados ok')
  17.  
  18.  
  19.  
  20. def botaomain1():
  21.     def focus_top():
  22.         top.lift()
  23.         root.after(500, focus_top)
  24.     top = ctk.CTkToplevel(root)
  25.     top.title('Gerar QrCode')
  26.     top.attributes('-topmost', True)
  27.     top.resizable(False, False)
  28.  
  29.     screen_width = top.winfo_screenwidth()
  30.     screen_height = top.winfo_screenheight()
  31.     x = (screen_width // 2) - (700 // 2)
  32.     y = (screen_height // 2) - (900 // 2)
  33.     top.geometry(f"700x900+{x}+{y}")
  34.  
  35. def botaomain2():
  36.     def focus_top():
  37.         top.lift()
  38.         root.after(500, focus_top)
  39.     top = ctk.CTkToplevel(root)
  40.     top.title('Buscar QrCode')
  41.     top.attributes('-topmost', True)
  42.     top.resizable(False, False)
  43.  
  44.     screen_width = top.winfo_screenwidth()
  45.     screen_height = top.winfo_screenheight()
  46.     x = (screen_width // 2) - (700 // 2)
  47.     y = (screen_height // 2) - (900 // 2)
  48.     top.geometry(f"700x900+{x}+{y}")
  49. def botaomain3():
  50.     def focus_top():
  51.         top.lift()
  52.         root.after(500, focus_top)
  53.  
  54.     def botaocompra():
  55.         global codigo_entry, valor_entry, valor_entry2
  56.         top = ctk.CTkToplevel(root)
  57.         top.title('Compra / Depósito')
  58.         top.attributes('-topmost', True)
  59.         top.resizable(False, False)
  60.  
  61.         screen_width = top.winfo_screenwidth()
  62.         screen_height = top.winfo_screenheight()
  63.         x = (screen_width // 2) - (700 // 2)
  64.         y = (screen_height // 2) - (900 // 2)
  65.         top.geometry(f"700x900+{x}+{y}")
  66.  
  67.         valor_label = ctk.CTkLabel(top, text="Valor:", font=('arial', 18))
  68.         valor_label.place(x=90, y=410)
  69.         valor_entry = ctk.CTkEntry(top, font=('arial', 18), width=80, height=50)
  70.         valor_entry.place(x=140, y=400)
  71.  
  72.         botaocompra_top = ctk.CTkButton(top, text="Compra", width=100, height=50, font=('arial', 22),command=compra)
  73.         botaocompra_top.place(x=230, y=400)
  74.  
  75.         valor_label2 = ctk.CTkLabel(top, text="Valor:", font=('arial', 18))
  76.         valor_label2.place(x=90, y=510)
  77.         valor_entry2 = ctk.CTkEntry(top, font=('arial', 18), width=80, height=50)
  78.         valor_entry2.place(x=140, y=500)
  79.  
  80.         botaodeposito_top = ctk.CTkButton(top, text="Depósito", width=100, height=50, font=('arial', 22),command=deposito)
  81.         botaodeposito_top.place(x=230, y=500)
  82.  
  83.         codigo_label = ctk.CTkLabel(top, text="Código:", font=('arial', 18))
  84.         codigo_label.place(x=75, y=160)
  85.         codigo_entry = ctk.CTkEntry(top, font=('arial', 18), width=80, height=50)
  86.         codigo_entry.place(x=140, y=150)
  87.  
  88.         botaobusca_top = ctk.CTkButton(top, text="Buscar", width=100, height=50, font=('arial', 22),command=verificarcodigo)
  89.         botaobusca_top.place(x=230, y=150)
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.     def botaomain3():
  97.         def focus_top():
  98.             top.lift()
  99.             root.after(500, focus_top)
  100.  
  101.         focus_top()
  102.         botaocompra()
  103.  
  104.     top = ctk.CTkToplevel(root)
  105.     top.title('Compra / Depósito')
  106.     top.attributes('-topmost', True)
  107.     top.resizable(False, False)
  108.  
  109.     screen_width = top.winfo_screenwidth()
  110.     screen_height = top.winfo_screenheight()
  111.     x = (screen_width // 2) - (700 // 2)
  112.     y = (screen_height // 2) - (900 // 2)
  113.     top.geometry(f"700x900+{x}+{y}")
  114.  
  115.     botaocompra_main = ctk.CTkButton(root, text="Compra / Depósito", width=300, height=50, command=botaocompra,font=('arial', 22))
  116.     botaocompra_main.place(x=200, y=600)
  117.  
  118.  
  119. ctk.set_appearance_mode("dark")
  120.  
  121. root = ctk.CTk ()
  122. root.title("beta")
  123. root.resizable(False, False)
  124.  
  125. screen_width = root.winfo_screenwidth()
  126. screen_height = root.winfo_screenheight()
  127.  
  128. x = (screen_width // 2) - (700 // 2)
  129. y = (screen_height // 2) - (900 // 2)
  130.  
  131. root.geometry(f"700x900+{x}+{y}")
  132.  
  133. botaomain1 = ctk.CTkButton(root, text="Gerar QrCode", width=300, height=50, command=botaomain1,font=('arial', 22))
  134. botaomain1.place(x=200, y=200)
  135.  
  136. botaomain2 = ctk.CTkButton(root, text="Buscar QrCode", width=300, height=50, command=botaomain2,font=('arial', 22))
  137. botaomain2.place(x=200, y=400)
  138.  
  139. botaomain3 = ctk.CTkButton(root, text="Compra / Depósito", width=300, height=50, command=botaomain3,font=('arial', 22))
  140. botaomain3.place(x=200, y=600)
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149. def informacoes():
  150.     #coleta informacoes como horas, valor nome e etc
  151.     data = datetime.datetime.now()
  152.     dataSimples = data.strftime('%d/%m/%Y %H:%M')
  153.     print(dataSimples)
  154.  
  155.     vendedor = input('vendedor: ')
  156.     cliente = input('cliente: ')
  157.  
  158.     while True:
  159.         email = input('email: ')
  160.         if "@gmail.com" in email:
  161.             print('email OK')
  162.             break
  163.         else:
  164.             print("E-mail inválido. Por favor, insira um e-mail válido com '@gmail.com'.")
  165.             continue  # Solicita novamente a entrada do usuário
  166.  
  167.     while True:
  168.         numeroTel = input('numero Tel: ')
  169.         if numeroTel.isdigit():
  170.             print("Número válido.")
  171.             break
  172.         else:
  173.             print("Número inválido. Por favor, insira apenas números.")
  174.             continue
  175.  
  176.     valor = input('valor: ')
  177.     QRcode = 1
  178.     code = 8
  179.  
  180.     for x in range(QRcode):
  181.         CodigoFinal = (''.join(random.choice(string.ascii_letters + string.digits) for _ in range(code)))
  182.  
  183.         print(CodigoFinal)
  184.  
  185.     cursor.execute("SELECT * FROM codigosV WHERE codigoValido=?", (CodigoFinal,))
  186.     row = cursor.fetchone()
  187.     if row is not None:
  188.         print('codigo ja existe tente novamente')
  189.     else:
  190.         img = qrcode.make(CodigoFinal)
  191.         img.save("Codigo de teste .png")  # Salva a imagem do QRCode em um arquivo
  192.  
  193.         cursor.execute("INSERT INTO codigosV (codigoValido, dataHora, nomeVendedor, nomeCliente, emailCliente, numeroCliente, valor) VALUES (?, ?, ?, ?, ?, ?, ?)", (CodigoFinal, dataSimples, vendedor, cliente, email, numeroTel, valor))
  194.  
  195.  
  196.     conn.commit()  # Confirma a transação no banco de dados
  197.  
  198. def verificarcodigo():
  199.     global bcValor,buscarCodigo
  200.     buscarCodigo = codigo_entry.get()
  201.     cursor.execute("SELECT nomeCliente, valor FROM codigosV WHERE codigoValido=?", (buscarCodigo,))
  202.     row = cursor.fetchone()
  203.     if row is not None:
  204.         print("Código encontrado")
  205.         nomeCliente = row[0]
  206.         bcValor = row[1]
  207.         print("Nome do cliente:", nomeCliente)
  208.         print("Valor: R$", bcValor)
  209.         codigo_entry.delete(0,'end')
  210.     else:
  211.         print("Código não encontrado.")
  212.  
  213. def compra():
  214.     '''buscarCodigo = valor_entry.get()
  215.    cursor.execute("SELECT nomeCliente, valor FROM codigosV WHERE codigoValido=?", (buscarCodigo,))
  216.    row = cursor.fetchone()
  217.    if row is not None:
  218.        print("Código encontrado")
  219.        nomeCliente = row[0]
  220.        bcValor = row[1]
  221.        print("Nome do cliente:", nomeCliente)
  222.        print("Valor: R$", bcValor)
  223.    else:
  224.        print("Código não encontrado.")
  225.        return'''
  226.     global bcValor,buscarCodigo
  227.     descontarValor = valor_entry.get()
  228.     bcValor = bcValor.replace(',', '.')
  229.     descontarValor = descontarValor.replace(',', '.')
  230.     valorDescontado = (float(bcValor) - float(descontarValor))
  231.     if valorDescontado <= float('0'):
  232.         print(f'nao há saldo o suficiente, saldo atual:{bcValor}')
  233.     else:
  234.         print("Valor após desconto: R$", valorDescontado)
  235.         cursor.execute("UPDATE codigosV SET valor=? WHERE codigoValido=?", (valorDescontado, buscarCodigo))
  236.         valor_entry.delete(0,'end')
  237.         conn.commit()
  238.  
  239. def deposito():
  240.     '''buscarCodigo = inputCodigo
  241.    cursor.execute("SELECT nomeCliente, valor FROM codigosV WHERE codigoValido=?", (buscarCodigo,))
  242.    row = cursor.fetchone()
  243.    if row is not None:
  244.        print("Código encontrado")
  245.        nomeCliente = row[0]
  246.        bcValor = row[1]
  247.        print("Nome do cliente:", nomeCliente)
  248.        print("Valor: R$", bcValor)
  249.    else:
  250.        print("Código não encontrado.")
  251.        return'''
  252.     global bcValor,buscarCodigo
  253.     depositarValor = valor_entry2.get()
  254.     bcValor = bcValor.replace(',', '.')
  255.     depositarValor = depositarValor.replace(',', '.')
  256.     valorDepositado = (float(bcValor) + float(depositarValor))
  257.     cursor.execute("UPDATE codigosV SET valor=? WHERE codigoValido=?", (valorDepositado, buscarCodigo))
  258.     print('valor após depóstio',valorDepositado)
  259.     valor_entry2.delete(0, 'end')
  260.     conn.commit()
  261.  
  262. '''def main():
  263.    mainPage = input('compra[1]\ndeposito[2]')
  264.    if mainPage == '1':
  265.        compra()
  266.    if mainPage == '2':
  267.        deposito()'''
  268.  
  269. '''while True:
  270.    menu = input ('gerar giftcard [1]\nverificar codigo[2]\nsistema[3]')
  271.    if menu == '1':
  272.        informacoes()
  273.    if menu == '2':
  274.        verificarcodigo()
  275.    if menu == '3':
  276.        main()
  277.    if menu == 'sair':
  278.        break'''
  279.  
  280.  
  281. root.mainloop()
  282.  
  283. '''cursor.execute("SELECT * FROM codigosV")
  284.  
  285. resultados = cursor.fetchall()
  286.  
  287. for row in resultados:
  288.    print(row)'''
  289.  
  290. conn.close()  # Fecha a conexão com o banco de dados
Tags: qrcode
Add Comment
Please, Sign In to add comment