begin cleanup add_cam_main. dont remember if anything more

This commit is contained in:
Nico
2025-05-06 23:54:11 +02:00
parent 6a5dcc64a3
commit 86ffd77888
21 changed files with 925 additions and 1724 deletions

View File

@@ -1,3 +1,4 @@
import 'package:fforte/interfaces/i_db.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
import 'dart:io' as io;
@@ -6,29 +7,32 @@ import 'package:path/path.dart';
// * Gives the complete functionality for the databases
// ! functions may not be named complete correctly
class ExcursionDBHelper {
class ExcursionDBHelper implements IDb{
static Database? _excursionDB;
// checks if the databses are existing and creates them with the initPlaceDatabase function if not
Future<Database> get excursionDB async {
@override
Future<Database> get dB async {
if (_excursionDB != null) {
return _excursionDB!;
}
_excursionDB = await initExcursionDatabase();
_excursionDB = await initDatabases();
return _excursionDB!;
}
// Creates the databases with help from the _onCreateExcursion function
initExcursionDatabase() async {
@override
initDatabases() async {
io.Directory documentsDirectory = await getApplicationCacheDirectory();
String path = join(documentsDirectory.path, 'excursionDB.db');
var excursionDB =
await openDatabase(path, version: 1, onCreate: _onCreateExcursion);
await openDatabase(path, version: 1, onCreate: onCreateDatabases);
return excursionDB;
}
// The function that helps
_onCreateExcursion(Database excursionDB, int version) async {
@override
onCreateDatabases(Database excursionDB, int version) async {
await excursionDB.execute(
'CREATE TABLE excursion (ID INTEGER PRIMARY KEY AUTOINCREMENT, Datum TEXT, Rudel TEXT, Teilnehmer TEXT, Jahr TEXT, Mjahr TEXT, Monat INTEGER, Saison TEXT, Dauer TEXT, BLjahr TEXT, BLand, TEXT, Lkr TEXT, BeiOrt TEXT, Wetter TEXT, Temperat TEXT, RegenVor TEXT, KmAuto TEXT, KmFuss TEXT, KmRad TEXT, KmTotal TEXT, KmAuProf TEXT, KmFuProz TEXT, KmRaProz TEXT, SpGut TEXT, SpSchlecht TEXT, SpurFund TEXT, SpurLang TEXT, SpurTiere Text, SpSicher TEXT, WelpenSp TEXT, WelpenAnz TEXT, WpSicher TEXT, LosungGes TEXT, LosunAnz TEXT, LosunGen TEXT, UrinAnz TEXT, UrinGen TEXT, OestrAnz TEXT, OestrGen TEXT, HaarAnz TEXT, HaarGen TEXT, LosungKm TEXT, GenetiKm TEXT, Hinweise TEXT, Bemerk TEXT, IntKomm TEXT, BimaNr TEXT, BimaName TEXT, BimaNutzer TEXT, BimaAGV TEXT, FallNum INTEGER, MHund TEXT, MLeine TEXT, LogDat TEXT, HinweiseSonstiges TEXT)');
await excursionDB.execute(
@@ -36,8 +40,9 @@ class ExcursionDBHelper {
}
// Function to add a finished entry and return its ID
Future<int> addExcursion(Map<String, dynamic> excursion) async {
var excursionDBClient = await excursionDB;
@override
Future<int> addMainEntry(Map<String, dynamic> excursion) async {
var excursionDBClient = await dB;
final existingID = await excursionDBClient.query(
'excursion',
where: 'ID = ?',
@@ -45,7 +50,7 @@ class ExcursionDBHelper {
);
if (existingID.isNotEmpty) {
updateExcursion(excursion);
updateMainEntry(excursion);
return existingID.first['ID'] as int; // Return existing ID
}
@@ -58,24 +63,27 @@ class ExcursionDBHelper {
return id; // Return the ID of the newly inserted entry
}
Future<void> updateExcursion(Map<String, dynamic> excursion) async {
var excursionDBClient = await excursionDB;
@override
Future<void> updateMainEntry(Map<String, dynamic> excursion) async {
var excursionDBClient = await dB;
await excursionDBClient
.update('excursion', excursion, where: "ID = ?", whereArgs: [excursion['ID']]);
}
// function to update the sent value
@override
Future<void> updateSent(int id) async {
var excursionDBClient = await excursionDB;
var excursionDBClient = await dB;
await excursionDBClient.update('excursion', {'Sent': 1},
where: 'ID = ?', whereArgs: [id]);
}
// same thing as before but with templatews
@override
Future<void> addTemplate(Map<String, dynamic> templates) async {
var excursionDBClient = await excursionDB;
var excursionDBClient = await dB;
final existingCID = await excursionDBClient.query(
'excursionTemplates',
@@ -94,8 +102,9 @@ class ExcursionDBHelper {
}
// Updates a existing template
@override
Future<void> updateTemplate(Map<String, dynamic> template) async {
var excursionDBClient = await excursionDB;
var excursionDBClient = await dB;
await excursionDBClient.update(
'excursionTemplates',
@@ -106,32 +115,37 @@ class ExcursionDBHelper {
}
// get the finished entries from db
Future<List<Map<String, dynamic>>> getExcursionen() async {
var excursionDBClient = await excursionDB;
@override
Future<List<Map<String, dynamic>>> getAllMainEntries() async {
var excursionDBClient = await dB;
return await excursionDBClient.query('excursion');
}
// get the finished templates from db
Future<List<Map<String, dynamic>>> getTemplates() async {
var excursionDBClient = await excursionDB;
@override
Future<List<Map<String, dynamic>>> getAllTemplates() async {
var excursionDBClient = await dB;
return await excursionDBClient.query('excursionTemplates');
}
// deletes all finished entries from the db LOCALLY
Future<void> deleteAllExcursionen() async {
var excursionDBClient = await excursionDB;
@override
Future<void> deleteAllMainEntries() async {
var excursionDBClient = await dB;
await excursionDBClient.delete('excursion');
}
// deletes all templates from the db LOCALLY
@override
Future<void> deleteAllTemplates() async {
var excursionDBClient = await excursionDB;
var excursionDBClient = await dB;
await excursionDBClient.delete('excursionTemplates');
}
// delete specific template
Future<void> deleteTemplate(String id) async {
var excursionDBClient = await excursionDB;
@override
Future<void> deleteTemplateById(String id) async {
var excursionDBClient = await dB;
await excursionDBClient.delete(
'excursionTemplates',
where: 'ID = ?',
@@ -140,8 +154,9 @@ class ExcursionDBHelper {
}
// delete specific excursion
Future<void> deleteExcursion(String id) async {
var excursionDBClient = await excursionDB;
@override
Future<void> deleteMainEntryById(String id) async {
var excursionDBClient = await dB;
await excursionDBClient.delete(
'excursion',
where: 'ID = ?',

View File

@@ -1,42 +0,0 @@
// ignore_for_file: avoid_print
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:shared_preferences/shared_preferences.dart';
class HttpRequest {
int? _errorCode;
int get errorCode => _errorCode ?? 0;
Future<void> httpRequest(String httpData) async {
// print(jsonEncode(place));
final dio = Dio();
final SharedPreferences prefs = await SharedPreferences.getInstance();
dio.options
..connectTimeout = const Duration(seconds: 5)
..receiveTimeout = const Duration(seconds: 5)
..responseType = ResponseType.plain;
Response response = Response(requestOptions: RequestOptions(path: ''), statusCode: 400);
try {
response = await dio.post(prefs.getString('apiAddress') ?? "",
data: jsonEncode(httpData));
// ignore: unused_catch_clause
} on DioException catch (e) {
_errorCode = response.statusCode;
print('is hier. var: $_errorCode');
return;
}
_errorCode = response.statusCode;
print('is hier 2. var: $_errorCode');
}
}

View File

@@ -1,3 +1,4 @@
import 'package:fforte/interfaces/i_db.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
import 'dart:io' as io;
@@ -6,40 +7,42 @@ import 'package:path/path.dart';
// * Gives the complete functionality for the databases
// ! functions may not be named complete correctly
class PlaceDBHelper {
static Database? _placeDB;
class PlaceDBHelper implements IDb{
static Database? _dB;
// checks if the databses are existing and creates them with the initPlaceDatabase function if not
Future<Database> get placeDB async {
if (_placeDB != null) {
return _placeDB!;
@override
Future<Database> get dB async {
if (_dB != null) {
return _dB!;
}
_placeDB = await initPlaceDatabase();
return _placeDB!;
_dB = await initDatabases();
return _dB!;
}
// Creates the databases with help from the _onCreatePlace function
initPlaceDatabase() async {
@override
initDatabases() async {
io.Directory documentsDirectory = await getApplicationCacheDirectory();
String path = join(documentsDirectory.path, 'placeDB.db');
var placeDB =
await openDatabase(path, version: 1, onCreate: _onCreatePlace);
await openDatabase(path, version: 1, onCreate: onCreateDatabases);
return placeDB;
}
// The function that helps
_onCreatePlace(Database placeDB, int version) async {
@override
onCreateDatabases(Database placeDB, int version) async {
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))');
await placeDB.execute(
'CREATE TABLE excursion (ID INTEGER PRIMARY KEY AUTOINCREMENT, Datum TEXT, Rudel TEXT, Teilnehmer TEXT, Jahr TEXT, Mjahr TEXT, Monat INTEGER, Saison TEXT, Dauer TEXT, BLjahr TEXT, BLand, TEXT, Lkr TEXT, BeiOrt TEXT, Wetter TEXT, Temperat TEXT, RegenVor TEXT, KmAuto TEXT, KmFuss TEXT, KmRad TEXT, KmTotal TEXT, KmAuProf TEXT, KmFuProz TEXT, KmRaProz TEXT, SpGut TEXT, SpSchlecht TEXT, SpurFund TEXT, SpurLang TEXT, SpurTiere Text, SpSicher TEXT, WelpenSp TEXT, WelpenAnz TEXT, WpSicher TEXT, LosungGes TEXT, LosunAnz TEXT, LosunGen TEXT, UrinAnz TEXT, UrinGen TEXT, OestrAnz TEXT, OestrGen TEXT, HaarAnz TEXT, HaarGen TEXT, LosungKm TEXT, GenetiKm TEXT, Hinweise TEXT, Bemerk TEXT, IntKomm TEXT, BimaNr TEXT, BimaName TEXT, BimaNutzer TEXT, BimaAGV TEXT, FallNum INTEGER, MHund TEXT, MLeine TEXT, LogDat TEXT)');
}
// Function to add a finished entry and return its ID
Future<int> addPlace(Map<String, dynamic> place) async {
var placeDBClient = await placeDB;
@override
Future<int> addMainEntry(Map<String, dynamic> place) async {
var placeDBClient = await dB;
final existingID = await placeDBClient.query(
'place',
where: 'ID = ?',
@@ -47,7 +50,7 @@ class PlaceDBHelper {
);
if (existingID.isNotEmpty) {
updatePlace(place);
updateMainEntry(place);
return existingID.first['ID'] as int; // Return existing ID
}
@@ -60,24 +63,27 @@ class PlaceDBHelper {
return id; // Return the ID of the newly inserted entry
}
Future<void> updatePlace(Map<String, dynamic> place) async {
var placeDBClient = await placeDB;
@override
Future<void> updateMainEntry(Map<String, dynamic> place) async {
var placeDBClient = await dB;
await placeDBClient
.update('place', place, where: "ID = ?", whereArgs: [place['ID']]);
}
// function to update the sent value
@override
Future<void> updateSent(int id) async {
var placeDBClient = await placeDB;
var placeDBClient = await dB;
await placeDBClient.update('place', {'Sent': 1},
where: 'ID = ?', whereArgs: [id]);
}
// same thing as before but with templatews
@override
Future<void> addTemplate(Map<String, dynamic> templates) async {
var placeDBClient = await placeDB;
var placeDBClient = await dB;
final existingCID = await placeDBClient.query(
'placeTemplates',
@@ -96,8 +102,9 @@ class PlaceDBHelper {
}
// Updates a existing template
@override
Future<void> updateTemplate(Map<String, dynamic> template) async {
var placeDBClient = await placeDB;
var placeDBClient = await dB;
await placeDBClient.update(
'placeTemplates',
@@ -108,32 +115,37 @@ class PlaceDBHelper {
}
// get the finished entries from db
Future<List<Map<String, dynamic>>> getPlace() async {
var placeDBClient = await placeDB;
@override
Future<List<Map<String, dynamic>>> getAllMainEntries() async {
var placeDBClient = await dB;
return await placeDBClient.query('place');
}
// get the finished templates from db
Future<List<Map<String, dynamic>>> getTemplates() async {
var placeDBClient = await placeDB;
@override
Future<List<Map<String, dynamic>>> getAllTemplates() async {
var placeDBClient = await dB;
return await placeDBClient.query('placeTemplates');
}
// deletes all finished entries from the db LOCALLY
Future<void> deleteAllPlaces() async {
var placeDBClient = await placeDB;
@override
Future<void> deleteAllMainEntries() async {
var placeDBClient = await dB;
await placeDBClient.delete('place');
}
// deletes all templates from the db LOCALLY
@override
Future<void> deleteAllTemplates() async {
var placeDBClient = await placeDB;
var placeDBClient = await dB;
await placeDBClient.delete('placeTemplates');
}
// delete specific template
Future<void> deleteTemplate(String id) async {
var placeDBClient = await placeDB;
@override
Future<void> deleteTemplateById(String id) async {
var placeDBClient = await dB;
await placeDBClient.delete(
'placeTemplates',
where: 'ID = ?',
@@ -142,8 +154,9 @@ class PlaceDBHelper {
}
// delete specific place
Future<void> deletePlace(String id) async {
var placeDBClient = await placeDB;
@override
Future<void> deleteMainEntryById(String id) async {
var placeDBClient = await dB;
await placeDBClient.delete(
'place',
where: 'ID = ?',

View File

@@ -1,71 +0,0 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SendFile extends StatefulWidget {
const SendFile({super.key});
@override
State<SendFile> createState() => _SendFileState();
}
class _SendFileState extends State<SendFile> {
File? pickedFile;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
children: [
ElevatedButton(
onPressed: () async {
FilePickerResult? result =
await FilePicker.platform.pickFiles();
if (result != null) {
pickedFile = File(result.files.single.path!);
} else {
pickedFile = File("");
}
},
child: Text(AppLocalizations.of(context)!.pickfile)),
Text(pickedFile.toString()),
ElevatedButton(
onPressed: () async {
final dio = Dio();
final SharedPreferences prefs =
await SharedPreferences.getInstance();
String? fileContent = await pickedFile?.readAsString();
dio.options.responseType = ResponseType.plain;
Response response = Response(
requestOptions: RequestOptions(path: ''), statusCode: 400);
try {
response = await dio.post(prefs.getString('apiAddress') ?? "",
data: jsonEncode(fileContent));
} on DioException catch (e) {
if (e.response?.statusCode == 500) {
/* print('-------------------------');
print('code 500'); */
return;
}
}
if (response.statusCode == 201) {
// print(response.statusCode);
} else {
//print(response.statusCode);
}
},
child: Text(AppLocalizations.of(context)!.sendtoserver))
],
),
);
}
}