// Objetivo: Classe p/ guardar eletrônicos // Nome // Cliente (outra classe) // Descrição do problema // Observações // Data da Entrada // Data da Saída // Foto(s) do aparelho import 'dbhandler.dart'; class Repair{ int id, status; final int eq_id; final repair; Repair(this.eq_id,this.repair); final dbHandler dbh = dbHandler.instance; Map toJson() =>{ 'eq_id': eq_id, 'repair': repair }; Repair.fromView(Map jsona) : id = jsona['repair_id'], eq_id = jsona['id'], repair = jsona['repair']; Repair.fromJson(Map jsona) : eq_id = jsona['eq_id'], repair = jsona['repair']; int SaveToDB() { Future t = dbh.insert(this.toJson(), "repair"); t.then((int value) { this.id = value; status = 1; },onError: (object){ status = 0; }); } Future LoadFromDB(int num) async { dbh.queryByID("repair", num).then((List> value){ return Repair.fromJson(value[0]); } ); } UpdateDB(int num) { dbh.update(this.toJson(), num, "repair").then((value){ status = 1; },onError: (object){ status = 0; }); } RemoveDB(int num) { dbh.delete(num, "repair").then((value){ status = 1; }, onError: (object){ status = 0; }); } } class Equipment { int id, status; final int client_id; final String name, problem, observation; final DateTime dateInput; DateTime dateExit; List images = []; int isDelivered = 0; Equipment(this.client_id, this.name, this.problem, this.observation, this.dateInput); final dbHandler dbh = dbHandler.instance; Map toJson() => { 'client_id': client_id, 'name': name, 'problem': problem, 'observation': observation, 'dateInput': dateInput.toString(), 'dateExit': dateExit.toString(), 'images': images.toString(), 'isDelivered': isDelivered }; Equipment.fromJson(Map jsona) : id = jsona['id'], client_id = jsona['client_id'], name = jsona['name'], problem = jsona['problem'], observation = jsona['observation'], dateInput = DateTime.tryParse(jsona['dateInput']), dateExit = DateTime.tryParse(jsona['dateExit']), images = jsona['images'].toString().substring(1,jsona['images'].length-1).split(',').toList(), isDelivered = int.tryParse(jsona['isDelivered'].toString()); void AddImage(String image) { images.add(image); } void AddImageAsRange(List imageL) { images.addAll(imageL); } void EquipmentLeave(DateTime time) { dateExit = time; isDelivered = 1; } int SaveToDB() { Future t = dbh.insert(this.toJson(), "equipment"); t.then((int value) { this.id = value; status = 1; }, onError: (value) { status = 0; }); } Future LoadFromDB(int num) async { dbh.queryByID("equipment", num).then((List> value){ return Equipment.fromJson(value[0]); } ); } UpdateDB(int num) { dbh.update(this.toJson(), num, "equipment").then((value){ status = 1; },onError: (object){ status = 0; }); } RemoveDB(int num) { dbh.delete(num, "equipment").then((value){ status = 1; }, onError: (object){ status = 0; }); } }