diff --git a/database/Models/Etudiants.js b/database/Models/Etudiants.js index af8e672..4d07508 100644 --- a/database/Models/Etudiants.js +++ b/database/Models/Etudiants.js @@ -25,7 +25,7 @@ async function insertEtudiant( parcours ) { const query = database.prepare( - 'INSERT INTO etudiants (nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, status, mention_id, num_inscription, sexe, cin, date_delivrence, nationalite, annee_bacc, serie, boursier, domaine, contact, parcours) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' + 'INSERT INTO etudiants (nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, status, mention_id, num_inscription, sexe, cin, date_delivrance, nationalite, annee_bacc, serie, boursier, domaine, contact, parcours) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' ) try { @@ -150,7 +150,7 @@ async function updateEtudiant( parcours ) { const query = database.prepare( - 'UPDATE etudiants SET nom = ?, prenom = ?, photos = ?, date_de_naissances = ?, niveau = ?, annee_scolaire = ?, status = ?, mention_id = ?, num_inscription = ?, sexe = ?, cin = ?, date_delivrence = ?, nationalite = ?, annee_bacc = ?, serie = ?, boursier = ?, domaine = ?, contact = ?, parcours = ? WHERE id = ?' + 'UPDATE etudiants SET nom = ?, prenom = ?, photos = ?, date_de_naissances = ?, niveau = ?, annee_scolaire = ?, status = ?, mention_id = ?, num_inscription = ?, sexe = ?, cin = ?, date_delivrance = ?, nationalite = ?, annee_bacc = ?, serie = ?, boursier = ?, domaine = ?, contact = ?, parcours = ? WHERE id = ?' ) try { diff --git a/database/database.js b/database/database.js index 348df9c..066120d 100644 --- a/database/database.js +++ b/database/database.js @@ -86,7 +86,7 @@ const createEtudiantsTableQuery = ` num_inscription TEXT NOT NULL UNIQUE, sexe VARCHAR(20) NOT NULL, cin VARCHAR(250) DEFAULT NULL, - date_delivrence DEFAULT NULL, + date_delivrance DEFAULT NULL, nationalite DATE NOT NULL, annee_bacc DATE NOT NULL, serie VARCHAR(20) NOT NULL, @@ -261,7 +261,10 @@ const createParcourTableQuery = ` CREATE TABLE IF NOT EXISTS parcours ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, nom VARCHAR(250) NOT NULL, - uniter VARCHAR(250) NOT NULL + uniter VARCHAR(250) NOT NULL, + mention_id INTEGER DEFAULT NULL, -- Clé étrangère vers mentions + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); ` database.prepare(createParcourTableQuery).run() diff --git a/database/import/Etudiants.js b/database/import/Etudiants.js index c278478..ed9a010 100644 --- a/database/import/Etudiants.js +++ b/database/import/Etudiants.js @@ -3,7 +3,7 @@ const path = require('path') const XLSX = require('xlsx') const { getCompressedDefaultImage } = require('../function/GetImageDefaault') const { parse } = require('csv-parse/sync') -const { insertEtudiant } = require('../Models/Etudiants') +const { insertEtudiant, updateEtudiant } = require('../Models/Etudiants') const { database } = require('../database') const { getMentions } = require('../Models/Mentions') const dayjs = require('dayjs') @@ -81,7 +81,6 @@ async function importFileToDatabase(filePath) { // Vérifier les données en une seule boucle for (const row of records) { - console.log(convertToISODate(row.date_naissance)) if ( !row.nom || // !row.prenom || @@ -154,7 +153,7 @@ async function importFileToDatabase(filePath) { // Si aucune erreur, insérer les données en batch if (error !== false) { // Utiliser transaction pour éviter une latence si l'insertion dépasse 100 - database.transaction(() => { + database.transaction(async () => { for (const row of records) { // Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase) const matchedMention = ListMention.find( @@ -167,27 +166,63 @@ async function importFileToDatabase(filePath) { if (matchedMention) { row.mention = matchedMention.id } - // Insert the student data with the updated mention ID - insertEtudiant( - row.nom, - row.prenom, - getCompressedDefaultImage(), - convertToISODate(row.date_naissance), - row.niveau, - row.annee_scolaire, - getStatusMention(row.code_redoublement), - row.num_inscription, - row.mention, - row.sexe, - row.nationaliter, - row.cin, - row.date_de_livraison, - row.annee_baccalaureat, - row.serie, - row.boursier, - row.domaine, - row.contact - ) + + const inscription = database.prepare( + 'SELECT id FROM etudiants WHERE num_inscription = ?' + ).get(row.num_inscription) + + // Check if the student already exists in the database + if (inscription) { + + updateEtudiant( + row.nom, + row.prenom, + getCompressedDefaultImage(), + convertToISODate(row.date_naissance), + row.niveau, + row.annee_scolaire, + getStatusMention(row.code_redoublement), + row.mention, + row.num_inscription, + inscription.id, // Assuming 'id' is the primary key of the student + row.sexe, + row.nationaliter, + row.cin, + row.date_de_delivrance ? convertToISODate(row.date_de_delivrance) : null, + row.annee_baccalaureat, + row.serie, + row.boursier, + row.domaine, + row.contact, + null + ); + + console.log(inscription) + + } else { + + // Insert the student data with the updated mention ID + insertEtudiant( + row.nom, + row.prenom, + getCompressedDefaultImage(), + convertToISODate(row.date_naissance), + row.niveau, + row.annee_scolaire, + getStatusMention(row.code_redoublement), + row.num_inscription, + row.mention, + row.sexe, + row.nationaliter, + row.cin, + row.date_de_delivrance, + row.annee_baccalaureat, + row.serie, + row.boursier, + row.domaine, + row.contact + ) + } } })() } diff --git a/src/main/index.js b/src/main/index.js index a64c16c..fd67a0b 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -421,7 +421,7 @@ ipcMain.handle('updateETudiants', async (event, credentials) => { sexe, nationalite, cin, - date_delivrence, + date_delivrance, annee_bacc, serie, boursier, @@ -444,7 +444,7 @@ ipcMain.handle('updateETudiants', async (event, credentials) => { sexe, nationalite, cin, - date_delivrence, + date_delivrance, annee_bacc, serie, boursier, diff --git a/src/renderer/src/components/SingleEtudiant.jsx b/src/renderer/src/components/SingleEtudiant.jsx index 3308087..f08e0b2 100644 --- a/src/renderer/src/components/SingleEtudiant.jsx +++ b/src/renderer/src/components/SingleEtudiant.jsx @@ -47,7 +47,7 @@ const SingleEtudiant = () => { sexe: 'Garçon', nationalite: '', cin: '', - date_delivrence: '', + date_delivrance: '', annee_bacc: '', serie: '', boursier: 'oui', @@ -125,7 +125,7 @@ const SingleEtudiant = () => { sexe: etudiant.sexe, nationalite: etudiant.nationalite, cin: etudiant.cin, - date_delivrence: etudiant.date_delivrence, + date_delivrance: etudiant.date_delivrance, annee_bacc: etudiant.annee_bacc, serie: etudiant.serie, boursier: etudiant.boursier, @@ -155,7 +155,7 @@ const SingleEtudiant = () => { sexe, nationalite, cin, - date_delivrence, + date_delivrance, annee_bacc, serie, boursier, @@ -175,15 +175,17 @@ const SingleEtudiant = () => { !sexe || !nationalite || !cin || - !date_delivrence || + !date_delivrance || !annee_bacc || !serie || !boursier || !domaine || - !contact || - !parcours + !contact ) { - setOpen(true) + // setOpen(true) + alert('Veuillez remplir tous les champs obligatoires.') + console.log(formData); + return // Prevent submission if validation fails } @@ -716,10 +718,10 @@ const SingleEtudiant = () => { { }} > {/* Liste des options */} - Garçon - Fille + Garçon + Fille @@ -819,7 +821,7 @@ const SingleEtudiant = () => { color="warning" defaultValue={etudiant.annee_bacc} // Controlled component value onChange={handleChange} - type="date" + type="text" InputProps={{ startAdornment: ( @@ -897,8 +899,8 @@ const SingleEtudiant = () => { } }} > - Oui - Non + Oui + Non diff --git a/src/renderer/src/components/Student.jsx b/src/renderer/src/components/Student.jsx index d663d24..28e8a6c 100644 --- a/src/renderer/src/components/Student.jsx +++ b/src/renderer/src/components/Student.jsx @@ -325,7 +325,7 @@ const Student = () => { photos: etudiant.photos, sexe: etudiant.sexe, cin: etudiant.cin, - date_deli: etudiant.date_delivrence, + date_deli: etudiant.date_delivrance, nation: etudiant.nationalite, annee_bacc: etudiant.annee_bacc, serie: etudiant.serie,