1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| function creeralim() {
var newid;
//on récupère les valeurs des différents champs
var nom = document.getElementById("nom").value;
var cal = document.getElementById("Calories").value;
var ig = document.getElementById("IG").value;
var prot = document.getElementById("Proteines").value;
var glu = document.getElementById("Glucides").value;
var lip = document.getElementById("Lipides").value;
var fib = document.getElementById("Fibres").value;
var conv = document.getElementById("convers").value;
console.log('1 : la val conv vaut : ' + conv);
var dbPath = Windows.Storage.ApplicationData.current.localFolder.path + '\\aliments.sqlite';
SQLite3JS.openAsync(dbPath)
.then(function (db) {
return db.runAsync('INSERT INTO aliments (Nom, Calories, IG, Proteines, Glucides, Lipides, Fibres) VALUES (?, ?, ?, ?, ?, ?, ?)', [nom, cal, ig, prot, glu, lip, fib])
.then(function () {
newid = db.lastInsertRowId;
console.log('2 avant insert avec conv = ' + conv + 'et newid = ' + newid);
return db.runAsync('INSERT INTO conversion (gr, cl, ID_aliments) VALUES (?, ?, ?)', [100, conv, newid])
})
.then(function () {
db.close();
console.log('3 avant getalim avec newid = ' + newid);
getalim(newid);
});
});
} |