added sent and id column again for add_cam_main

id checks if entry already exists. sent says if the entry is already
sent to the db
This commit is contained in:
Nico
2025-05-12 18:18:36 +02:00
parent a5769a7dc0
commit ecafe2df02
7 changed files with 518 additions and 607 deletions

View File

@@ -9,7 +9,7 @@ abstract interface class IDb {
Future<int> addMainEntry(Map<String, String> excursion); Future<int> addMainEntry(Map<String, String> excursion);
Future<void> updateMainEntry(Map<String, String> excursion); Future<int> updateMainEntry(Map<String, String> excursion);
Future<void> updateSent(int id); Future<void> updateSent(int id);

View File

@@ -65,10 +65,10 @@ class ExcursionDBHelper implements IDb{
} }
@override @override
Future<void> updateMainEntry(Map<String, String> excursion) async { Future<int> updateMainEntry(Map<String, String> excursion) async {
var excursionDBClient = await dB; var excursionDBClient = await dB;
await excursionDBClient return await excursionDBClient
.update('excursion', excursion, where: "ID = ?", whereArgs: [excursion['ID']]); .update('excursion', excursion, where: "ID = ?", whereArgs: [excursion['ID']]);
} }

View File

@@ -64,10 +64,10 @@ class PlaceDBHelper implements IDb{
} }
@override @override
Future<void> updateMainEntry(Map<String, String> place) async { Future<int> updateMainEntry(Map<String, String> place) async {
var placeDBClient = await dB; var placeDBClient = await dB;
await placeDBClient return await placeDBClient
.update('place', place, where: "ID = ?", whereArgs: [place['ID']]); .update('place', place, where: "ID = ?", whereArgs: [place['ID']]);
} }

File diff suppressed because it is too large Load Diff

View File

@@ -360,6 +360,7 @@ class _ExcursionMainState extends State<ExcursionMain> {
context, context,
getFieldsText(), getFieldsText(),
false, false,
DatabasesEnum.excursion
); );
} }
} }

View File

@@ -7,7 +7,7 @@ import 'package:fforte/screens/sharedMethods/save_main_entry.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fforte/l10n/app_localizations.dart'; import 'package:fforte/l10n/app_localizations.dart';
class DialogHelper { class AddEntriesDialogHelper {
// Function to show the dialog where the user has to choose if he want to safe his values as a template // Function to show the dialog where the user has to choose if he want to safe his values as a template
static Future<void> showTemplateDialog(BuildContext context, static Future<void> showTemplateDialog(BuildContext context,
Map<String, String> saveData, bool update) async { Map<String, String> saveData, bool update) async {
@@ -36,7 +36,7 @@ class DialogHelper {
} }
static Future<dynamic> showServerErrorDialog( static Future<dynamic> showServerErrorDialog(
BuildContext context, Map<String, String> saveData, bool isTemplate) { BuildContext context, Map<String, String> saveData, bool isTemplate, DatabasesEnum dbType) {
bool isLoading = false; bool isLoading = false;
return showDialog( return showDialog(
@@ -62,12 +62,12 @@ class DialogHelper {
if (errorCode != 201 && context.mounted) { if (errorCode != 201 && context.mounted) {
showServerErrorDialog( showServerErrorDialog(
context, saveData, isTemplate); context, saveData, isTemplate, dbType);
} else { } else {
if (context.mounted) Navigator.pop(context); if (context.mounted) Navigator.pop(context);
// saveData(true); // saveData(true);
SaveMainEntryMethod.saveEntry( SaveMainEntryMethod.saveEntry(
entryData: saveData, isTemplate: isTemplate); entryData: saveData, isTemplate: isTemplate, dbType: dbType);
if (context.mounted) showSuccessDialog(context); if (context.mounted) showSuccessDialog(context);
} }
}, },
@@ -86,7 +86,7 @@ class DialogHelper {
} }
static Future<void> showSaveOptionsDialog(BuildContext context, static Future<void> showSaveOptionsDialog(BuildContext context,
Map<String, String> saveData, bool isTemplate) async { Map<String, String> saveData, bool isTemplate, DatabasesEnum dbType) async {
bool isLoading = false; bool isLoading = false;
return showDialog( return showDialog(
@@ -126,15 +126,16 @@ class DialogHelper {
if (errorCode != 201 || !context.mounted) { if (errorCode != 201 || !context.mounted) {
SaveMainEntryMethod.saveEntry( SaveMainEntryMethod.saveEntry(
entryData: saveData, isTemplate: isTemplate); entryData: saveData, isTemplate: isTemplate, dbType: dbType);
if (context.mounted) { if (context.mounted) {
DialogHelper.showServerErrorDialog( AddEntriesDialogHelper.showServerErrorDialog(
context, saveData, isTemplate); context, saveData, isTemplate, dbType);
} }
} else { } else {
SaveMainEntryMethod.saveEntry( SaveMainEntryMethod.saveEntry(
entryData: saveData, entryData: saveData,
isTemplate: isTemplate, isTemplate: isTemplate,
dbType: dbType,
sent: true); sent: true);
showSuccessDialog(context); showSuccessDialog(context);
} }
@@ -148,7 +149,7 @@ class DialogHelper {
try { try {
SaveMainEntryMethod.saveEntry( SaveMainEntryMethod.saveEntry(
entryData: saveData, isTemplate: isTemplate); entryData: saveData, isTemplate: isTemplate, dbType: dbType);
SaveFileMethod.saveFile( SaveFileMethod.saveFile(
saveData, saveData,
AppLocalizations.of(context)!.savefilefailed, AppLocalizations.of(context)!.savefilefailed,
@@ -165,7 +166,7 @@ class DialogHelper {
TextButton( TextButton(
onPressed: () { onPressed: () {
SaveMainEntryMethod.saveEntry( SaveMainEntryMethod.saveEntry(
entryData: saveData, isTemplate: isTemplate); entryData: saveData, isTemplate: isTemplate, dbType: dbType);
Navigator.pushNamedAndRemoveUntil( Navigator.pushNamedAndRemoveUntil(
context, '/home', (route) => false); context, '/home', (route) => false);
}, },

View File

@@ -1,21 +1,38 @@
import 'package:fforte/enums/databases.dart';
import 'package:fforte/interfaces/i_db.dart';
import 'package:fforte/methods/excursion_db_helper.dart';
import 'package:fforte/methods/place_db_helper.dart'; import 'package:fforte/methods/place_db_helper.dart';
class SaveMainEntryMethod { class SaveMainEntryMethod {
static void saveEntry( static void saveEntry({
{required Map<String, String> entryData, required Map<String, String> entryData,
required bool isTemplate, required bool isTemplate,
bool sent = false}) async { required DatabasesEnum dbType,
var placeDB = PlaceDBHelper(); bool sent = false,
}) async {
IDb? placeDB;
if (dbType == DatabasesEnum.place) {
placeDB = PlaceDBHelper();
} else if (dbType == DatabasesEnum.excursion) {
placeDB = ExcursionDBHelper();
}
int entryId;
// Get the ID of the newly added or updated place // Get the ID of the newly added or updated place
int newPlaceId = await placeDB.addMainEntry(entryData); if (entryData["ID"] == "") {
entryData.remove("ID");
entryId = await placeDB!.addMainEntry(entryData);
} else {
entryId = await placeDB!.updateMainEntry(entryData);
}
if (sent == true) { if (sent == true) {
placeDB.updateSent(newPlaceId); // Update 'Sent' using the correct ID placeDB.updateSent(entryId); // Update 'Sent' using the correct ID
} }
if (isTemplate) { await placeDB.deleteTemplateById(entryData["CID"]!);
await placeDB.deleteTemplateById(entryData["CID"]!);
}
} }
} }