update for routing
This commit is contained in:
@ -66,17 +66,22 @@ class DatabaseHelper{
|
||||
return destList;
|
||||
}
|
||||
|
||||
Future<int> deleteDestination(int location_id) async {
|
||||
Future<int> deleteDestination(int location_id) async {
|
||||
Database db = await instance.database;
|
||||
var dest = await db.delete('destination', where: "location_id = ${location_id}");
|
||||
int ret = dest > 0 ? dest : -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Future<void> deleteAllDestinations() async {
|
||||
Database db = await instance.database;
|
||||
await db.delete('destination');
|
||||
}
|
||||
|
||||
Future<bool>isAlreadyAvailable(int location_id) async{
|
||||
Database db = await instance.database;
|
||||
var dest = await db.delete('destination', where: "location_id = ${location_id}");
|
||||
return dest > 0 ? true : false;
|
||||
var dest = await db.query('destination', where: "location_id = ${location_id}");
|
||||
return dest.length > 0 ? true : false;
|
||||
}
|
||||
|
||||
Future<int> insertDestination(Destination dest) async {
|
||||
@ -108,6 +113,42 @@ class DatabaseHelper{
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updateOrder(Destination d, int dir)async {
|
||||
Database db = await instance.database;
|
||||
var target = await db.query('destination', where: "list_order = ${d.list_order! + dir}");
|
||||
var dest = await db.query('destination', where: "location_id = ${d.location_id}");
|
||||
if(target.isNotEmpty){
|
||||
|
||||
List<Destination> target_indb = target.isNotEmpty
|
||||
? target.map((e) => Destination.fromMap(e)).toList() : [];
|
||||
|
||||
List<Destination> dest_indb = dest.isNotEmpty
|
||||
? dest.map((e) => Destination.fromMap(e)).toList() : [];
|
||||
|
||||
Map<String, dynamic> row_target = {
|
||||
"list_order": d.list_order
|
||||
};
|
||||
|
||||
Map<String, dynamic> row_des = {
|
||||
"list_order": dest_indb[0].list_order
|
||||
};
|
||||
|
||||
await db.update(
|
||||
"destination",
|
||||
row_target,
|
||||
where: 'location_id = ?',
|
||||
whereArgs: [target_indb[0]!.location_id]
|
||||
);
|
||||
|
||||
await db.update(
|
||||
"destination",
|
||||
row_des,
|
||||
where: 'location_id = ?',
|
||||
whereArgs: [dest_indb[0]!.location_id]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Future<int?> getPending() async{
|
||||
// Database db = await instance.database;
|
||||
// return await Sqflite.firstIntValue(await db.rawQuery("SELECT COUNT(*) FROM incidents"));
|
||||
|
||||
Reference in New Issue
Block a user