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:
@@ -9,7 +9,7 @@ abstract interface class IDb {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -65,10 +65,10 @@ class ExcursionDBHelper implements IDb{
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateMainEntry(Map<String, String> excursion) async {
|
||||
Future<int> updateMainEntry(Map<String, String> excursion) async {
|
||||
var excursionDBClient = await dB;
|
||||
|
||||
await excursionDBClient
|
||||
return await excursionDBClient
|
||||
.update('excursion', excursion, where: "ID = ?", whereArgs: [excursion['ID']]);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,10 +64,10 @@ class PlaceDBHelper implements IDb{
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateMainEntry(Map<String, String> place) async {
|
||||
Future<int> updateMainEntry(Map<String, String> place) async {
|
||||
var placeDBClient = await dB;
|
||||
|
||||
await placeDBClient
|
||||
return await placeDBClient
|
||||
.update('place', place, where: "ID = ?", whereArgs: [place['ID']]);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -360,6 +360,7 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
context,
|
||||
getFieldsText(),
|
||||
false,
|
||||
DatabasesEnum.excursion
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'package:fforte/screens/sharedMethods/save_main_entry.dart';
|
||||
import 'package:flutter/material.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
|
||||
static Future<void> showTemplateDialog(BuildContext context,
|
||||
Map<String, String> saveData, bool update) async {
|
||||
@@ -36,7 +36,7 @@ class DialogHelper {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return showDialog(
|
||||
@@ -62,12 +62,12 @@ class DialogHelper {
|
||||
|
||||
if (errorCode != 201 && context.mounted) {
|
||||
showServerErrorDialog(
|
||||
context, saveData, isTemplate);
|
||||
context, saveData, isTemplate, dbType);
|
||||
} else {
|
||||
if (context.mounted) Navigator.pop(context);
|
||||
// saveData(true);
|
||||
SaveMainEntryMethod.saveEntry(
|
||||
entryData: saveData, isTemplate: isTemplate);
|
||||
entryData: saveData, isTemplate: isTemplate, dbType: dbType);
|
||||
if (context.mounted) showSuccessDialog(context);
|
||||
}
|
||||
},
|
||||
@@ -86,7 +86,7 @@ class DialogHelper {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return showDialog(
|
||||
@@ -126,15 +126,16 @@ class DialogHelper {
|
||||
|
||||
if (errorCode != 201 || !context.mounted) {
|
||||
SaveMainEntryMethod.saveEntry(
|
||||
entryData: saveData, isTemplate: isTemplate);
|
||||
entryData: saveData, isTemplate: isTemplate, dbType: dbType);
|
||||
if (context.mounted) {
|
||||
DialogHelper.showServerErrorDialog(
|
||||
context, saveData, isTemplate);
|
||||
AddEntriesDialogHelper.showServerErrorDialog(
|
||||
context, saveData, isTemplate, dbType);
|
||||
}
|
||||
} else {
|
||||
SaveMainEntryMethod.saveEntry(
|
||||
entryData: saveData,
|
||||
isTemplate: isTemplate,
|
||||
dbType: dbType,
|
||||
sent: true);
|
||||
showSuccessDialog(context);
|
||||
}
|
||||
@@ -148,7 +149,7 @@ class DialogHelper {
|
||||
|
||||
try {
|
||||
SaveMainEntryMethod.saveEntry(
|
||||
entryData: saveData, isTemplate: isTemplate);
|
||||
entryData: saveData, isTemplate: isTemplate, dbType: dbType);
|
||||
SaveFileMethod.saveFile(
|
||||
saveData,
|
||||
AppLocalizations.of(context)!.savefilefailed,
|
||||
@@ -165,7 +166,7 @@ class DialogHelper {
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
SaveMainEntryMethod.saveEntry(
|
||||
entryData: saveData, isTemplate: isTemplate);
|
||||
entryData: saveData, isTemplate: isTemplate, dbType: dbType);
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context, '/home', (route) => false);
|
||||
},
|
||||
|
||||
@@ -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';
|
||||
|
||||
class SaveMainEntryMethod {
|
||||
static void saveEntry(
|
||||
{required Map<String, String> entryData,
|
||||
required bool isTemplate,
|
||||
bool sent = false}) async {
|
||||
var placeDB = PlaceDBHelper();
|
||||
static void saveEntry({
|
||||
required Map<String, String> entryData,
|
||||
required bool isTemplate,
|
||||
required DatabasesEnum dbType,
|
||||
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
|
||||
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) {
|
||||
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"]!);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user