Skip to content
Snippets Groups Projects
Commit 8a8e1760 authored by Bouchaira Neirouz's avatar Bouchaira Neirouz
Browse files

Changes

parent 1bbe05c0
No related branches found
No related tags found
No related merge requests found
......@@ -5,23 +5,24 @@ import sqlite3
import pandas as pd
from datetime import datetime
from faicons import icon_svg as icon
from shiny import reactive
ui.page_opts(title="Bienvenue à la page RH", fillable=True)
with ui.navset_tab():
with ui.nav_panel("Création de compte employé"):
conn = sqlite3.connect('C:/Users/neiro/Documents/GitHub/sgbd-usine/donnees/company.db')
cursor = conn.cursor()
with ui.value_box(showcase=icon("user-plus")):
"Veuillez remplir les informations suivantes pour créer un compte employé"
""
with ui.card():
with ui.layout_columns():
with ui.card(full_screen=True):
ui.h4("Veillez remplir les informations ci-dessous:")
conn = sqlite3.connect('C:/Users/neiro/Documents/GitHub/sgbd-usine/donnees/company.db')
cursor = conn.cursor()
ui.input_text("Nom", "NOM")
ui.input_text("Prénom", "PRENOM")
ui.input_select("type_de_contrat", "Type de contrat", choices=["Journalier", "Production"])
ui.input_text("NOM","Nom")
ui.input_text("PRENOM","Prénom")
ui.input_select("TYPE", "Type de contrat", choices=["Journalier", "Production"])
@render.ui
def journee_ou_production():
conn = sqlite3.connect('C:/Users/neiro/Documents/GitHub/sgbd-usine/donnees/company.db')
......@@ -32,34 +33,34 @@ with ui.nav_panel("Création de compte employé"):
res2= cursor.execute("SELECT * FROM GRILLE_SALAIRE_PROD")
data2 = pd.DataFrame(res2.fetchall(), columns=[x[0] for x in cursor.description])
production = data2['CS_PRODUCTION'].unique().tolist()
type=input.type_de_contrat()
if type== "Journalier":
TYPE=1
typ=input.TYPE()
conn.close()
if typ== "Journalier":
return ui.input_select("CS_JOURNEE","Code salarial journalier", choices=journee)
else:
TYPE=2
return ui.input_select("CS_PRODUCTION","Code salarial de production", choices=production)
ui.input_date("date_debut", "Date de début" )
ui.input_action_button( "create_account","Create Account")
@input.create_account()
def create_account():
ui.input_action_button("action_button", "Créer un compte")
@render.text()
@reactive.event(input.action_button)
def counter():
if int(input.action_button()) == 1:
NOM = input.NOM()
PRENOM = input.PRENOM()
TYPE = 1 if input.type_de_contrat() == "Journalier" else 2
CS_PRODUCTION = input.CS_PRODUCTION if TYPE == 2 else None
CS_JOURNEE = input.CS_JOURNEE if TYPE == 1 else None
TYPE = 1 if input.TYPE() == "Journalier" else 2
CS_JOURNEE = input.CS_JOURNEE() if TYPE == 1 else None
CS_PRODUCTION = input.CS_PRODUCTION() if TYPE == 2 else None
date_debut = input.date_debut()
conn = sqlite3.connect('C:/Users/neiro/Documents/GitHub/sgbd-usine/donnees/company.db')
cursor = conn.cursor()
cursor.execute("""
restest=cursor.execute("""
SELECT NUMERO_EMPLOYE FROM EMPLOYE
WHERE NOM = ? AND PRENOM = ? AND DATE_DEBUT = ?
""", (NOM, PRENOM, date_debut))
existing_employee = cursor.fetchone()
existing_employee = restest.fetchone()
if existing_employee:
if existing_employee is not None:
return f"Cet employé est déjà enregistré avec le numéro employé: {existing_employee[0]}"
else:
cursor.execute("""
......@@ -77,6 +78,8 @@ with ui.nav_panel("Création de compte employé"):
conn.close()
return f"Nouvel employé enregistré!\n\n" + f"Numéro employé: {NUMERO_EMPLOYE}" + f"\nType de contrat: {'Journalier' if TYPE == 1 else 'Production'}" + f"\nNom: {NOM}" + f"\nPrénom: {PRENOM}" + (f"\nCode salarial de production: {CS_PRODUCTION}" if TYPE == 2 else f"\nCode salarial journalier: {CS_JOURNEE}") + f"\nDate du début du contrat: {date_debut}"
elif int(input.action_button())>1:
return "Vous avez déjà créé un compte employé, merci de rafraîchir la page pour en créer un autre."
with ui.nav_panel("Suivi des employés"):
@render.data_frame
......@@ -85,5 +88,6 @@ with ui.nav_panel("Suivi des employés"):
cursor = conn1.cursor()
res= cursor.execute("SELECT * FROM EMPLOYE")
data = pd.DataFrame(res.fetchall(), columns=[x[0] for x in cursor.description])
conn1.close()
return data
......@@ -23,39 +23,27 @@ if page == "suivi_employes":
# Add code for "Suivi Employés" page here
st.write("Page de suivi des employés")
# Connect to the database
conn = sqlite3.connect('donnees\company.db')
with sqlite3.connect('donnees\company.db') as conn:
cursor = conn.cursor()
# Fetch all employee records
cursor.execute("SELECT * FROM EMPLOYE")
employees = cursor.fetchall()
# Convert the employee records to a DataFrame
df = pd.DataFrame(employees, columns=[desc[0] for desc in cursor.description])
# Display the DataFrame with Streamlit
st.dataframe(df)
# Close the connection
conn.close()
st.stop()
# Add a button to navigate to "Suivi Employés" page
if page == "creation_compte_employe":
st.title("Création de compte employé")
# Connect to the database
conn = sqlite3.connect('donnees\company.db')
with sqlite3.connect('donnees\company.db') as conn:
cursor = conn.cursor()
# Get the maximum employee number from the database
cursor.execute("SELECT MAX(NUMERO_EMPLOYE) FROM EMPLOYE")
max_numero_employe = cursor.fetchone()[0]
# Close the connection
conn.close()
# Set the employee number to the next available number
NUMERO_EMPLOYE = max_numero_employe + 1 if max_numero_employe is not None else 1
......@@ -82,10 +70,9 @@ if page == "creation_compte_employe":
# Submit button
if st.button("Create Account"):
# Connect to the database
conn = sqlite3.connect('donnees\company.db')
with sqlite3.connect('donnees\company.db') as conn:
cursor = conn.cursor()
# Insert the new employee record
# Check if the employee already exists
cursor.execute("""
SELECT NUMERO_EMPLOYE FROM EMPLOYE
WHERE NOM = ? AND PRENOM = ? AND DATE_DEBUT = ?
......@@ -96,17 +83,13 @@ if page == "creation_compte_employe":
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))
# Check if the employee already exists
# Commit the transaction and close the connection
# Commit the transaction
conn.commit()
conn.close()
st.write("Nouvel employé enregistré!")
st.write(f"Numéro employé: {NUMERO_EMPLOYE}")
......@@ -118,6 +101,4 @@ if page == "creation_compte_employe":
else:
st.write(f"code salarial journalier: {CS_JOURNEE}")
st.write(f"Date du début du contrat: {date_debut}")
#---------------------------------
st.stop()
\ No newline at end of file
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment