diff --git a/code_interface/streamlit_app.py b/code_interface/streamlit_app.py index de8f9b810490fcc26df164f3e94b3a2661db5da7..bb25231d530716b10542e58f3273a50058cce6c4 100644 --- a/code_interface/streamlit_app.py +++ b/code_interface/streamlit_app.py @@ -14,7 +14,7 @@ with tab1: # Add code for "Suivi Employés" page here st.write("Page de suivi des employés") # Connect to the database - with sqlite3.connect(r'donnees\company.db') as conn: # Use raw string + with sqlite3.connect(r'C:\Users\neiro\Documents\+\GitHub\sgbd-usine\donnees\company.db') as conn: # Use raw string cursor = conn.cursor() # Fetch all employee records cursor.execute("SELECT * FROM EMPLOYE") @@ -24,14 +24,15 @@ with tab1: # Display the DataFrame with Streamlit st.dataframe(df) st.stop() + conn.close() with tab2: st.title("Création de compte employé") print("Page de création de compte employé") conn= sqlite3.connect(r'C:\Users\neiro\Documents\+\GitHub\sgbd-usine\donnees\company.db') cursor = conn.cursor() - cursor.execute("SELECT MAX(NUMERO_EMPLOYE) FROM EMPLOYE") - max_numero_employe = cursor.fetchone()[0] + cursor.execute("SELECT MAX(NUMERO_EMPLOYE) FROM EMPLOYE") + max_numero_employe = cursor.fetchone()[0] # Set the employee number to the next available number NUMERO_EMPLOYE = max_numero_employe + 1 if max_numero_employe is not None else 1 @@ -59,26 +60,25 @@ with tab2: # Submit button if st.button("Create Account"): # Connect to the database - with sqlite3.connect('donnees\company.db') as conn: - cursor = conn.cursor() + conn=sqlite3.connect(r'C:\Users\neiro\Documents\+\GitHub\sgbd-usine\donnees\company.db') # Check if the employee already exists - cursor.execute(""" - SELECT NUMERO_EMPLOYE FROM EMPLOYE - WHERE NOM = ? AND PRENOM = ? AND DATE_DEBUT = ? - """, (NOM, PRENOM, date_debut)) - existing_employee = cursor.fetchone() + cursor.execute(""" + SELECT NUMERO_EMPLOYE FROM EMPLOYE + WHERE NOM = ? AND PRENOM = ? AND DATE_DEBUT = ? + """, (NOM, PRENOM, date_debut)) + existing_employee = cursor.fetchone() - if existing_employee: - st.write(f"Cet employé est déjà enregistré avec le numéro employé: {existing_employee[0]}") - st.stop() + if existing_employee: + st.write(f"Cet employé est déjà enregistré avec le numéro employé: {existing_employee[0]}") + st.stop() - # Insert the new employee record - cursor.execute(""" - INSERT INTO EMPLOYE (NUMERO_EMPLOYE, TYPE, NOM, PRENOM, CS_PRODUCTION, CS_JOURNEE, DATE_DEBUT) - VALUES (?, ?, ?, ?, ?, ?, ?) - """, (NUMERO_EMPLOYE, TYPE, NOM, PRENOM, CS_PRODUCTION if CS_PRODUCTION is not None else None, CS_JOURNEE if CS_JOURNEE is not None else None, date_debut)) - # Commit the transaction - conn.commit() + # Insert the new employee record + cursor.execute(""" + INSERT INTO EMPLOYE (NUMERO_EMPLOYE, TYPE, NOM, PRENOM, CS_PRODUCTION, CS_JOURNEE, DATE_DEBUT) + VALUES (?, ?, ?, ?, ?, ?, ?) + """, (NUMERO_EMPLOYE, TYPE, NOM, PRENOM, CS_PRODUCTION if CS_PRODUCTION is not None else None, CS_JOURNEE if CS_JOURNEE is not None else None, date_debut)) + # Commit the transaction + conn.commit() st.write("Nouvel employé enregistré!") st.write(f"Numéro employé: {NUMERO_EMPLOYE}")