diff --git a/lib/screens/registers_citizen/register_citizen_screen.dart b/lib/screens/registers_citizen/register_citizen_screen.dart index b83b77b..3244dfe 100644 --- a/lib/screens/registers_citizen/register_citizen_screen.dart +++ b/lib/screens/registers_citizen/register_citizen_screen.dart @@ -103,6 +103,7 @@ class _RegisterCitizenScreenState extends State { bool enableBlocked = false; bool checkBoxNumber = false; String date = 'Data de Nascimento'; + String dateDB = ''; List cityDB = []; List ibgeDB = []; List streetDB = []; @@ -116,6 +117,7 @@ class _RegisterCitizenScreenState extends State { String idTipo=''; bool showCheckError = false; bool showTab = false; + String errorTopo = 'Existem campos obrigatórios não preenchidos.'; escolherprazoInicio(BuildContext context,String type) async { var pickDate = await showDatePicker( @@ -126,6 +128,7 @@ class _RegisterCitizenScreenState extends State { if (pickDate != null) { setState(() { if(type == 'birth'){ + dateDB = '${pickDate.year}-${pickDate.month<10?'0':''}${pickDate.month}-${pickDate.day<10?'0':''}${pickDate.day}'; date = formatData(year: pickDate.year, month: pickDate.month, day: pickDate.day); } if(type == 'rg'){ @@ -295,32 +298,33 @@ class _RegisterCitizenScreenState extends State { selectDeficiency==null || selectClassification==null || selectCountry==null || - selectVillage==null || - selectStreet==null || date == 'Data de Nascimento'|| cityBirthController.text.isEmpty || messageDDDController.text.isEmpty || messageController.text.isEmpty || checkMother || checkFather || - checkClassification + checkClassification|| + (selectMaritalStatus == 'CASADO(A)' && spouseController.text.isEmpty) ){ + print('erro'); setState(() { showCheckError = true; }); }else{ - showCheckError = false; + print('passou'); saveCitizen(); } } saveCitizen()async{ + Map row = { 'CD_USUARIO_SUS' : '0', 'NOME_CIDADAO' : nameController.text, 'NOME_SOCIAL' : nameSocialController.text, 'SEXO' : selectGender, - 'DT_NASCIMENTO' : date, + 'DT_NASCIMENTO' : dateDB, 'ID_ESTADO_CIVIL' : '', 'ID_ESTADO_CIVIL' : '', 'NOME_CONJUGE' : spouseController.text, @@ -362,7 +366,7 @@ class _RegisterCitizenScreenState extends State { 'EMAIL' : emailController.text, 'OBSERVACOES' : observationController.text, 'CPF' : CPFController.text, - 'CNS' : CNSController.text, + 'CNS' : checkCNS == 'ok'&& CNSController.text.isNotEmpty?CNSController.text:'999999999999999', 'TITULO_ELEITOR' : voterController.text, 'RG_NUMERO' : RGController.text, 'RG_COMPLEMENTO' : RGComplementController.text, @@ -396,7 +400,27 @@ class _RegisterCitizenScreenState extends State { 'SINCRONIZADO' : '', }; await DbSqliteSync().insertCidadaos(row,'update').then((value){ - print('novo usuário foi salvo'); + if(checkCNS != 'ok' || CNSController.text.isEmpty){ + AlertDialogDefault().alert( + context, + 'Aviso', + 'CNS Inválido!', + 'OK' + ); + setState(() { + errorTopo = 'O usuário foi cadastrado sem um CNS válido!'; + }); + }else{ + setState(() { + showCheckError = false; + }); + } + AlertDialogDefault().alert( + context, + 'Aviso', + 'Cidadão cadastrado com sucesso!', + 'OK' + ); setState(() { showTab = true; }); @@ -443,7 +467,7 @@ class _RegisterCitizenScreenState extends State { child: Row( children: [ Icon(Icons.warning,color: Colors.red,), - TextDefault(text: 'Existem campos obrigatórios não preenchidos.',color: ColorPalette.red,fontSize: 15,) + TextDefault(text: errorTopo,color: ColorPalette.red,fontSize: 15,) ], ), ),