first commit
This commit is contained in:
23
connection.py
Normal file
23
connection.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import mysql.connector
|
||||||
|
from mysql.connector import Error
|
||||||
|
|
||||||
|
def create_connection(host_name, user_name, user_password, db_name,port):
|
||||||
|
connection = None
|
||||||
|
try:
|
||||||
|
connection = mysql.connector.connect(
|
||||||
|
host=host_name,
|
||||||
|
user=user_name,
|
||||||
|
password=user_password,
|
||||||
|
database=db_name,
|
||||||
|
port=port,
|
||||||
|
ssl_disabled=True
|
||||||
|
)
|
||||||
|
print("Connessione al database riuscita!")
|
||||||
|
except Error as e:
|
||||||
|
print(f"Errore: {e}")
|
||||||
|
return connection
|
||||||
|
|
||||||
|
def close_connection(connection):
|
||||||
|
if connection is not None and connection.is_connected():
|
||||||
|
connection.close()
|
||||||
|
print("Connessione al database chiusa.")
|
||||||
27
search.py
Normal file
27
search.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import mysql.connector
|
||||||
|
import math
|
||||||
|
import xlsxwriter
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import filedialog,messagebox
|
||||||
|
from datetime import datetime
|
||||||
|
from mysql.connector import Error
|
||||||
|
|
||||||
|
def search_article(connection,codice,listino):
|
||||||
|
cursor_1 = connection.cursor()
|
||||||
|
cursor_2 = connection.cursor()
|
||||||
|
query = "SELECT codice FROM art WHERE codice = %s"
|
||||||
|
cursor_1.execute(query,(codice))
|
||||||
|
result_1 = cursor.fetchone()
|
||||||
|
|
||||||
|
if result_1: ## se l'articolo esiste creco per codice listino
|
||||||
|
query_lsv = "SELECT TLV_CODICE FROM lsv WHERE ART_CODICE = %s AND TLV_CODICE = %s"
|
||||||
|
cursor_2.execute(query_lsv,(codice,listino))
|
||||||
|
result_2 = cursor_2.fetchone()
|
||||||
|
|
||||||
|
if result_2: ## se il codice listino è stato trovato
|
||||||
|
return True ## esistono sia articolo che codice listino
|
||||||
|
else:
|
||||||
|
return False ## articlo esiste ma non esiste il codice listino
|
||||||
|
else:
|
||||||
|
return False ## l'articolo non esiste
|
||||||
Reference in New Issue
Block a user