fixed delete in view_app. Also some other things but i forgot everything
This commit is contained in:
@@ -36,23 +36,23 @@ class PlaceDBHelper implements IDb{
|
||||
await placeDB.execute(
|
||||
'CREATE TABLE place (ID INTEGER PRIMARY KEY AUTOINCREMENT, CID TEXT, Standort TEXT, Rudel TEXT, Datum DATE, Adresse1 TEXT, Adresse2 TEXT, Adresse3 TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, OrtInfo TEXT, Status TEXT, FFTyp TEXT, FotoFilm TEXT, MEZ TEXT, Platzung TEXT, KSchloNr TEXT, KontDat DATE, Betreuung TEXT, AbbauDat DATE, Auftrag TEXT, KontAbsp TEXT, SonstBem TEXT, FKontakt1 TEXT, FKontakt2 TEXT, FKontakt3 TEXT, KTage1 INTEGER, KTage2 INTEGER, ProtoAm DATE, IntKomm TEXT, DECLNG DECIMALS(4,8), DECLAT DECIMALS(4,8), Sent INTEGER DEFAULT 0)');
|
||||
await placeDB.execute(
|
||||
'CREATE TABLE placeTemplates (ID INTEGER PRIMARY KEY AUTOINCREMENT, CID TEXT, Standort TEXT, Rudel TEXT, Datum DATE, Adresse1 TEXT, Adresse2 TEXT, Adresse3 TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, OrtInfo TEXT, Status TEXT, FFTyp TEXT, FotoFilm TEXT, MEZ TEXT, Platzung TEXT, KSchloNr TEXT, KontDat DATE, Betreuung TEXT, AbbauDat DATE, Auftrag TEXT, KontAbsp TEXT, SonstBem TEXT, FKontakt1 TEXT, FKontakt2 TEXT, FKontakt3 TEXT, KTage1 INTEGER, KTage2 INTEGER, ProtoAm DATE, IntKomm TEXT, DECLNG DECIMALS(4,8), DECLAT DECIMALS(4,8))');
|
||||
'CREATE TABLE placeTemplates (ID INTEGER PRIMARY KEY AUTOINCREMENT, CID TEXT, Standort TEXT, Rudel TEXT, Datum DATE, Adresse1 TEXT, Adresse2 TEXT, Adresse3 TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, OrtInfo TEXT, Status TEXT, FFTyp TEXT, FotoFilm TEXT, MEZ TEXT, Platzung TEXT, KSchloNr TEXT, KontDat DATE, Betreuung TEXT, AbbauDat DATE, Auftrag TEXT, KontAbsp TEXT, SonstBem TEXT, FKontakt1 TEXT, FKontakt2 TEXT, FKontakt3 TEXT, KTage1 INTEGER, KTage2 INTEGER, ProtoAm DATE, IntKomm TEXT, DECLNG DECIMALS(4,8), DECLAT DECIMALS(4,8))');
|
||||
}
|
||||
|
||||
// Function to add a finished entry and return its ID
|
||||
@override
|
||||
Future<int> addMainEntry(Map<String, String> place) async {
|
||||
var placeDBClient = await dB;
|
||||
final existingID = await placeDBClient.query(
|
||||
'place',
|
||||
where: 'ID = ?',
|
||||
whereArgs: [place['ID']],
|
||||
);
|
||||
|
||||
if (existingID.isNotEmpty) {
|
||||
updateMainEntry(place);
|
||||
return existingID.first['ID'] as int; // Return existing ID
|
||||
}
|
||||
// final existingID = await placeDBClient.query(
|
||||
// 'place',
|
||||
// where: 'ID = ?',
|
||||
// whereArgs: [place['ID']],
|
||||
// );
|
||||
//
|
||||
// if (existingID.isNotEmpty) {
|
||||
// updateMainEntry(place);
|
||||
// return existingID.first['ID'] as int; // Return existing ID
|
||||
// }
|
||||
|
||||
int id = await placeDBClient.insert(
|
||||
'place',
|
||||
|
||||
@@ -23,7 +23,6 @@ import 'widgets/status.dart';
|
||||
|
||||
class AddCamMain extends StatefulWidget {
|
||||
final bool isTemplate;
|
||||
final bool isFinished;
|
||||
final bool isSent;
|
||||
final Map<String, dynamic>? existingData;
|
||||
|
||||
@@ -31,7 +30,6 @@ class AddCamMain extends StatefulWidget {
|
||||
super.key,
|
||||
this.isTemplate = false,
|
||||
this.existingData,
|
||||
this.isFinished = false,
|
||||
this.isSent = false,
|
||||
});
|
||||
|
||||
@@ -148,6 +146,8 @@ class _AddCamMainState extends State<AddCamMain> {
|
||||
// select initial werte
|
||||
rmap["MEZ"]!["controller"]!.text = selectedMEZ;
|
||||
rmap["Status"]!["controller"]!.text = selectedStatus;
|
||||
rmap["DECLAT"]!["controller"]!.text = currentPosition.latitude.toString();
|
||||
rmap["DECLNG"]!["controller"]!.text = currentPosition.longitude.toString();
|
||||
|
||||
// If a template is edited this fills in the existing values
|
||||
if (widget.existingData?.isNotEmpty ?? false) {
|
||||
@@ -286,8 +286,8 @@ class _AddCamMainState extends State<AddCamMain> {
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Text(currentPosition.latitude.toString()),
|
||||
Text(currentPosition.longitude.toString()),
|
||||
Text(rmap["DECLAT"]!["controller"]!.text),
|
||||
Text(rmap["DECLNG"]!["controller"]!.text),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
|
||||
@@ -4,6 +4,19 @@ import 'package:fforte/methods/excursion_db_helper.dart';
|
||||
import 'package:fforte/methods/place_db_helper.dart';
|
||||
|
||||
class DeleteTemplates {
|
||||
|
||||
static void deleteSingle(DatabasesEnum dbType, String id) {
|
||||
IDb? db;
|
||||
|
||||
if (dbType == DatabasesEnum.place) {
|
||||
db = PlaceDBHelper();
|
||||
} else if (dbType == DatabasesEnum.excursion) {
|
||||
db = ExcursionDBHelper();
|
||||
}
|
||||
|
||||
db!.deleteTemplateById(id);
|
||||
}
|
||||
|
||||
static void deleteAll(DatabasesEnum dbType) {
|
||||
IDb? db;
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ class SaveMainEntryMethod {
|
||||
placeDB = ExcursionDBHelper();
|
||||
}
|
||||
|
||||
int entryId;
|
||||
if (isTemplate) placeDB!.deleteTemplateById(entryData["ID"]!);
|
||||
|
||||
// Get the ID of the newly added or updated place
|
||||
if (entryData["ID"] == "") {
|
||||
int entryId;
|
||||
if (isTemplate || entryData["ID"] == "") {
|
||||
entryData.remove("ID");
|
||||
entryId = await placeDB!.addMainEntry(entryData);
|
||||
} else {
|
||||
|
||||
@@ -14,6 +14,9 @@ void saveTemplate(Map<String, String> templateData, DatabasesEnum dbType,
|
||||
return;
|
||||
}
|
||||
|
||||
templateData.remove("Sent");
|
||||
templateData.remove("ID");
|
||||
|
||||
if (update) {
|
||||
await dbHelper.updateTemplate(templateData);
|
||||
} else {
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:fforte/screens/addCam/add_cam_main.dart';
|
||||
import 'package:fforte/methods/place_db_helper.dart';
|
||||
import 'package:fforte/screens/helper/view_entries_dialog_helper.dart';
|
||||
import 'package:fforte/screens/sharedMethods/delete_main_entries.dart';
|
||||
import 'package:fforte/screens/sharedMethods/delete_templates.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fforte/l10n/app_localizations.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
@@ -25,11 +26,11 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
late Future<List<Map<String, dynamic>>> mainEntries;
|
||||
late Future<List<Map<String, dynamic>>> templates;
|
||||
late List<Marker> markers;
|
||||
IDb? db;
|
||||
|
||||
// loads the entries
|
||||
@override
|
||||
void initState() {
|
||||
IDb? db;
|
||||
super.initState();
|
||||
if (widget.dbType == DatabasesEnum.place) {
|
||||
db = PlaceDBHelper();
|
||||
@@ -37,8 +38,12 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
db = ExcursionDBHelper();
|
||||
}
|
||||
|
||||
reloadAllEntries();
|
||||
}
|
||||
|
||||
Future<void> reloadAllEntries() async {
|
||||
mainEntries = db!.getAllMainEntries();
|
||||
templates = db.getAllTemplates();
|
||||
templates = db!.getAllTemplates();
|
||||
}
|
||||
|
||||
// The widet tree with taps to differentiate between templates and finished entries
|
||||
@@ -89,24 +94,24 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline),
|
||||
AppLocalizations.of(context)!.placedata),
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
AppLocalizations.of(context)!.placedata,
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline),
|
||||
AppLocalizations.of(context)!.sent),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
AppLocalizations.of(context)!.sent,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -128,6 +133,9 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
widget.dbType,
|
||||
place['ID'.toString()],
|
||||
);
|
||||
setState(() {
|
||||
reloadAllEntries();
|
||||
});
|
||||
},
|
||||
backgroundColor: Colors.red,
|
||||
foregroundColor: Colors.white,
|
||||
@@ -158,7 +166,6 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
place['Sent'] == 1
|
||||
? true
|
||||
: false,
|
||||
isFinished: true,
|
||||
existingData: place,
|
||||
),
|
||||
),
|
||||
@@ -203,23 +210,47 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
itemBuilder: (context, index) {
|
||||
Map<String, dynamic> templates =
|
||||
snapshot.data![index];
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
(context) => AddCamMain(
|
||||
isTemplate: true,
|
||||
isFinished: false,
|
||||
existingData: templates,
|
||||
),
|
||||
return Slidable(
|
||||
startActionPane: ActionPane(
|
||||
motion: const ScrollMotion(),
|
||||
children: [
|
||||
SlidableAction(
|
||||
onPressed: (context) {
|
||||
DeleteTemplates.deleteSingle(
|
||||
widget.dbType,
|
||||
templates['ID'].toString(),
|
||||
);
|
||||
setState(() {
|
||||
reloadAllEntries();
|
||||
});
|
||||
},
|
||||
backgroundColor: Colors.red,
|
||||
foregroundColor: Colors.white,
|
||||
icon: Icons.delete,
|
||||
label:
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
)!.justdelete,
|
||||
),
|
||||
);
|
||||
},
|
||||
title: Text('Place ${index + 1}'),
|
||||
subtitle: Text(
|
||||
'ID: ${templates['CID']} DATUM: ${templates['Datum']} RUDEL: ${templates['Rudel']} STATUS: ${templates['Status']}',
|
||||
],
|
||||
),
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
(context) => AddCamMain(
|
||||
isTemplate: true,
|
||||
existingData: templates,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
title: Text('Place ${index + 1}'),
|
||||
subtitle: Text(
|
||||
'ID: ${templates['CID']} DATUM: ${templates['Datum']} RUDEL: ${templates['Rudel']} STATUS: ${templates['Status']}',
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -241,29 +272,31 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
} else if (snapshot.hasError) {
|
||||
return Text("Error ${snapshot.error}");
|
||||
} else {
|
||||
markers =
|
||||
snapshot.data!.map((e) {
|
||||
return Marker(
|
||||
width: 80.0,
|
||||
height: 80.0,
|
||||
point: LatLng(
|
||||
double.parse(e['DECLAT'].toString()),
|
||||
double.parse(e['DECLNG'].toString()),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.location_on,
|
||||
color: Colors.red,
|
||||
),
|
||||
Text(
|
||||
"ID: ${e['ID'].toString()}",
|
||||
style: const TextStyle(color: Colors.black),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
if (snapshot.data != null) {
|
||||
markers =
|
||||
snapshot.data!.map((e) {
|
||||
return Marker(
|
||||
width: 80.0,
|
||||
height: 80.0,
|
||||
point: LatLng(
|
||||
double.parse(e['DECLAT'].toString()),
|
||||
double.parse(e['DECLNG'].toString()),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.location_on,
|
||||
color: Colors.red,
|
||||
),
|
||||
Text(
|
||||
"ID: ${e['ID'].toString()}",
|
||||
style: const TextStyle(color: Colors.black),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
return FlutterMap(
|
||||
options: MapOptions(
|
||||
initialCenter:
|
||||
|
||||
Reference in New Issue
Block a user