Browse Source

testing update where exist

master
fabriceBJHost 6 months ago
parent
commit
eb7d02e472
  1. 4
      database/Models/Etudiants.js
  2. 7
      database/database.js
  3. 83
      database/import/Etudiants.js
  4. 4
      src/main/index.js
  5. 30
      src/renderer/src/components/SingleEtudiant.jsx
  6. 2
      src/renderer/src/components/Student.jsx

4
database/Models/Etudiants.js

@ -25,7 +25,7 @@ async function insertEtudiant(
parcours parcours
) { ) {
const query = database.prepare( 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 { try {
@ -150,7 +150,7 @@ async function updateEtudiant(
parcours parcours
) { ) {
const query = database.prepare( 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 { try {

7
database/database.js

@ -86,7 +86,7 @@ const createEtudiantsTableQuery = `
num_inscription TEXT NOT NULL UNIQUE, num_inscription TEXT NOT NULL UNIQUE,
sexe VARCHAR(20) NOT NULL, sexe VARCHAR(20) NOT NULL,
cin VARCHAR(250) DEFAULT NULL, cin VARCHAR(250) DEFAULT NULL,
date_delivrence DEFAULT NULL, date_delivrance DEFAULT NULL,
nationalite DATE NOT NULL, nationalite DATE NOT NULL,
annee_bacc DATE NOT NULL, annee_bacc DATE NOT NULL,
serie VARCHAR(20) NOT NULL, serie VARCHAR(20) NOT NULL,
@ -261,7 +261,10 @@ const createParcourTableQuery = `
CREATE TABLE IF NOT EXISTS parcours ( CREATE TABLE IF NOT EXISTS parcours (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
nom VARCHAR(250) 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() database.prepare(createParcourTableQuery).run()

83
database/import/Etudiants.js

@ -3,7 +3,7 @@ const path = require('path')
const XLSX = require('xlsx') const XLSX = require('xlsx')
const { getCompressedDefaultImage } = require('../function/GetImageDefaault') const { getCompressedDefaultImage } = require('../function/GetImageDefaault')
const { parse } = require('csv-parse/sync') const { parse } = require('csv-parse/sync')
const { insertEtudiant } = require('../Models/Etudiants') const { insertEtudiant, updateEtudiant } = require('../Models/Etudiants')
const { database } = require('../database') const { database } = require('../database')
const { getMentions } = require('../Models/Mentions') const { getMentions } = require('../Models/Mentions')
const dayjs = require('dayjs') const dayjs = require('dayjs')
@ -81,7 +81,6 @@ async function importFileToDatabase(filePath) {
// Vérifier les données en une seule boucle // Vérifier les données en une seule boucle
for (const row of records) { for (const row of records) {
console.log(convertToISODate(row.date_naissance))
if ( if (
!row.nom || !row.nom ||
// !row.prenom || // !row.prenom ||
@ -154,7 +153,7 @@ async function importFileToDatabase(filePath) {
// Si aucune erreur, insérer les données en batch // Si aucune erreur, insérer les données en batch
if (error !== false) { if (error !== false) {
// Utiliser transaction pour éviter une latence si l'insertion dépasse 100 // Utiliser transaction pour éviter une latence si l'insertion dépasse 100
database.transaction(() => { database.transaction(async () => {
for (const row of records) { for (const row of records) {
// Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase) // Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase)
const matchedMention = ListMention.find( const matchedMention = ListMention.find(
@ -167,27 +166,63 @@ async function importFileToDatabase(filePath) {
if (matchedMention) { if (matchedMention) {
row.mention = matchedMention.id row.mention = matchedMention.id
} }
// Insert the student data with the updated mention ID
insertEtudiant( const inscription = database.prepare(
row.nom, 'SELECT id FROM etudiants WHERE num_inscription = ?'
row.prenom, ).get(row.num_inscription)
getCompressedDefaultImage(),
convertToISODate(row.date_naissance), // Check if the student already exists in the database
row.niveau, if (inscription) {
row.annee_scolaire,
getStatusMention(row.code_redoublement), updateEtudiant(
row.num_inscription, row.nom,
row.mention, row.prenom,
row.sexe, getCompressedDefaultImage(),
row.nationaliter, convertToISODate(row.date_naissance),
row.cin, row.niveau,
row.date_de_livraison, row.annee_scolaire,
row.annee_baccalaureat, getStatusMention(row.code_redoublement),
row.serie, row.mention,
row.boursier, row.num_inscription,
row.domaine, inscription.id, // Assuming 'id' is the primary key of the student
row.contact 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
)
}
} }
})() })()
} }

4
src/main/index.js

@ -421,7 +421,7 @@ ipcMain.handle('updateETudiants', async (event, credentials) => {
sexe, sexe,
nationalite, nationalite,
cin, cin,
date_delivrence, date_delivrance,
annee_bacc, annee_bacc,
serie, serie,
boursier, boursier,
@ -444,7 +444,7 @@ ipcMain.handle('updateETudiants', async (event, credentials) => {
sexe, sexe,
nationalite, nationalite,
cin, cin,
date_delivrence, date_delivrance,
annee_bacc, annee_bacc,
serie, serie,
boursier, boursier,

30
src/renderer/src/components/SingleEtudiant.jsx

@ -47,7 +47,7 @@ const SingleEtudiant = () => {
sexe: 'Garçon', sexe: 'Garçon',
nationalite: '', nationalite: '',
cin: '', cin: '',
date_delivrence: '', date_delivrance: '',
annee_bacc: '', annee_bacc: '',
serie: '', serie: '',
boursier: 'oui', boursier: 'oui',
@ -125,7 +125,7 @@ const SingleEtudiant = () => {
sexe: etudiant.sexe, sexe: etudiant.sexe,
nationalite: etudiant.nationalite, nationalite: etudiant.nationalite,
cin: etudiant.cin, cin: etudiant.cin,
date_delivrence: etudiant.date_delivrence, date_delivrance: etudiant.date_delivrance,
annee_bacc: etudiant.annee_bacc, annee_bacc: etudiant.annee_bacc,
serie: etudiant.serie, serie: etudiant.serie,
boursier: etudiant.boursier, boursier: etudiant.boursier,
@ -155,7 +155,7 @@ const SingleEtudiant = () => {
sexe, sexe,
nationalite, nationalite,
cin, cin,
date_delivrence, date_delivrance,
annee_bacc, annee_bacc,
serie, serie,
boursier, boursier,
@ -175,15 +175,17 @@ const SingleEtudiant = () => {
!sexe || !sexe ||
!nationalite || !nationalite ||
!cin || !cin ||
!date_delivrence || !date_delivrance ||
!annee_bacc || !annee_bacc ||
!serie || !serie ||
!boursier || !boursier ||
!domaine || !domaine ||
!contact || !contact
!parcours
) { ) {
setOpen(true) // setOpen(true)
alert('Veuillez remplir tous les champs obligatoires.')
console.log(formData);
return // Prevent submission if validation fails return // Prevent submission if validation fails
} }
@ -716,10 +718,10 @@ const SingleEtudiant = () => {
<TextField <TextField
fullWidth fullWidth
label="Date de delivrance" label="Date de delivrance"
name="date_delivrence" name="date_delivrance"
color="warning" color="warning"
type="date" type="date"
defaultValue={etudiant.date_delivrence} // Controlled component value defaultValue={etudiant.date_delivrance} // Controlled component value
onChange={handleChange} onChange={handleChange}
InputProps={{ InputProps={{
startAdornment: ( startAdornment: (
@ -772,8 +774,8 @@ const SingleEtudiant = () => {
}} }}
> >
{/* Liste des options */} {/* Liste des options */}
<MenuItem value={'Garçon'}>Garçon</MenuItem> <MenuItem value={'M'}>Garçon</MenuItem>
<MenuItem value={'Fille'}>Fille</MenuItem> <MenuItem value={'F'}>Fille</MenuItem>
</TextField> </TextField>
</Grid> </Grid>
<Grid item xs={6}> <Grid item xs={6}>
@ -819,7 +821,7 @@ const SingleEtudiant = () => {
color="warning" color="warning"
defaultValue={etudiant.annee_bacc} // Controlled component value defaultValue={etudiant.annee_bacc} // Controlled component value
onChange={handleChange} onChange={handleChange}
type="date" type="text"
InputProps={{ InputProps={{
startAdornment: ( startAdornment: (
<InputAdornment position="start"> <InputAdornment position="start">
@ -897,8 +899,8 @@ const SingleEtudiant = () => {
} }
}} }}
> >
<MenuItem value={'oui'}>Oui</MenuItem> <MenuItem value={'OUI'}>Oui</MenuItem>
<MenuItem value={'non'}>Non</MenuItem> <MenuItem value={'NON'}>Non</MenuItem>
</TextField> </TextField>
</Grid> </Grid>
<Grid item xs={6}> <Grid item xs={6}>

2
src/renderer/src/components/Student.jsx

@ -325,7 +325,7 @@ const Student = () => {
photos: etudiant.photos, photos: etudiant.photos,
sexe: etudiant.sexe, sexe: etudiant.sexe,
cin: etudiant.cin, cin: etudiant.cin,
date_deli: etudiant.date_delivrence, date_deli: etudiant.date_delivrance,
nation: etudiant.nationalite, nation: etudiant.nationalite,
annee_bacc: etudiant.annee_bacc, annee_bacc: etudiant.annee_bacc,
serie: etudiant.serie, serie: etudiant.serie,

Loading…
Cancel
Save