testing update where exist
This commit is contained in:
parent
1af4aebf27
commit
eb7d02e472
@ -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 {
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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 = () => {
|
||||
<TextField
|
||||
fullWidth
|
||||
label="Date de delivrance"
|
||||
name="date_delivrence"
|
||||
name="date_delivrance"
|
||||
color="warning"
|
||||
type="date"
|
||||
defaultValue={etudiant.date_delivrence} // Controlled component value
|
||||
defaultValue={etudiant.date_delivrance} // Controlled component value
|
||||
onChange={handleChange}
|
||||
InputProps={{
|
||||
startAdornment: (
|
||||
@ -772,8 +774,8 @@ const SingleEtudiant = () => {
|
||||
}}
|
||||
>
|
||||
{/* Liste des options */}
|
||||
<MenuItem value={'Garçon'}>Garçon</MenuItem>
|
||||
<MenuItem value={'Fille'}>Fille</MenuItem>
|
||||
<MenuItem value={'M'}>Garçon</MenuItem>
|
||||
<MenuItem value={'F'}>Fille</MenuItem>
|
||||
</TextField>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
@ -819,7 +821,7 @@ const SingleEtudiant = () => {
|
||||
color="warning"
|
||||
defaultValue={etudiant.annee_bacc} // Controlled component value
|
||||
onChange={handleChange}
|
||||
type="date"
|
||||
type="text"
|
||||
InputProps={{
|
||||
startAdornment: (
|
||||
<InputAdornment position="start">
|
||||
@ -897,8 +899,8 @@ const SingleEtudiant = () => {
|
||||
}
|
||||
}}
|
||||
>
|
||||
<MenuItem value={'oui'}>Oui</MenuItem>
|
||||
<MenuItem value={'non'}>Non</MenuItem>
|
||||
<MenuItem value={'OUI'}>Oui</MenuItem>
|
||||
<MenuItem value={'NON'}>Non</MenuItem>
|
||||
</TextField>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user