diff --git a/lib/models/responsavel_model.dart b/lib/models/responsavel_model.dart index cee2d5e..e49a114 100644 --- a/lib/models/responsavel_model.dart +++ b/lib/models/responsavel_model.dart @@ -1,25 +1,19 @@ class ResponsavelModel{ - String nomeAluno; - String raAluno; - String escola; - String serie; - String turma; - String nomeResponsavel; - String parentesco; - String cpf; - String senha; - String dataCadastro; + String CD_ALUNO; + String NOME; + String PARENTESCO; + String CPF; + String SENHA; + String DATA_CADASTRO; + String CONDICAO; ResponsavelModel({ - required this.nomeAluno, - required this.raAluno, - required this.escola, - required this.serie, - required this.turma, - required this.nomeResponsavel, - required this.parentesco, - required this.cpf, - required this.senha, - required this.dataCadastro, + required this.CD_ALUNO, + required this.NOME, + required this.PARENTESCO, + required this.CPF, + required this.SENHA, + required this.DATA_CADASTRO, + required this.CONDICAO }); } \ No newline at end of file diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 5cdcf0a..bed06ff 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -47,7 +47,7 @@ class _HomeScreenState extends State { }); }else{ List list = map; - print(list); + // print(list); if(list.length != 0){ for(int i =0; list.length>i;i++){ String data = list[i]['DT_NASCIMENTO']??''; diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart index a57e52e..c853ae5 100644 --- a/lib/screens/login_screen.dart +++ b/lib/screens/login_screen.dart @@ -64,7 +64,7 @@ class _LoginScreenState extends State { // print(MainControllers().encrypt(inputSenha.text,map['SENHA'])); if(MainControllers().encrypt(inputSenha.text,map['SENHA']) == map['SENHA']){ showSnackBar(context, 'Acesso validado', Colors.green); - Navigator.push( + Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => HomeScreen()), ); @@ -79,20 +79,6 @@ class _LoginScreenState extends State { }); } - paisBanco()async{ - final url = 'http://localhost:8000/pais'; - // print(url); - final response = await http.get(Uri.parse(url)); - var map = json.decode(response.body); - print(map); - } - - @override - void initState() { - super.initState(); - paisBanco(); - } - @override Widget build(BuildContext context) { double height = MediaQuery.of(context).size.height; diff --git a/lib/screens/responsible_register_screen.dart b/lib/screens/responsible_register_screen.dart index b160410..5e4e4c9 100644 --- a/lib/screens/responsible_register_screen.dart +++ b/lib/screens/responsible_register_screen.dart @@ -36,53 +36,78 @@ class _ResponsibleRegisterScreenState extends State { var inputCpf = TextEditingController(); var inputSenha = TextEditingController(); var inputData = TextEditingController(); + bool carregando = true; + + inserirDB()async{ + final url = 'http://localhost:8000/inserirpais'; + final response = await http.post( + Uri.parse(url), + body:{ + 'CD_ALUNO' : widget.alunoModel.dados['CD_ALUNO'], + 'CPF': inputCpf.text, + 'NOME' : inputNome.text, + 'SENHA' : inputSenha.text, + 'PARENTESCO' : inputParentesco.text, + 'DATA_CADASTRO' : DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()), + 'CONDICAO' : editando?'EDITADO':'NOVO' + } + ); + print(response.body); + if(response.body == 'cadastrado com sucesso' || response.body == 'editado com sucesso'){ + editando? + showSnackBar(context, 'Responsável alterado!', Colors.green): + showSnackBar(context, 'Responsável adicionado!', Colors.green); + + if(editando && indice!=null){ + responsaveis[indice!] = ResponsavelModel( + CD_ALUNO: widget.alunoModel.dados['CD_ALUNO'], + NOME: inputNome.text, + PARENTESCO: inputParentesco.text, + CPF: inputCpf.text, + SENHA: inputSenha.text, + DATA_CADASTRO: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()), + CONDICAO: '' + ); + }else{ + responsaveis.add( + ResponsavelModel( + CD_ALUNO: widget.alunoModel.dados['CD_ALUNO'], + NOME: inputNome.text.toUpperCase(), + PARENTESCO: inputParentesco.text.toUpperCase(), + CPF: inputCpf.text, + SENHA: inputSenha.text.toUpperCase(), + DATA_CADASTRO: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()), + CONDICAO: '' + ) + ); + } + inputNome.clear(); + inputParentesco.clear(); + inputCpf.clear(); + inputSenha.clear(); + showRegister = false; + editando = false; + indice = null; + inputData.clear(); + paisBanco(); + setState((){}); + + }else{ + carregando = false; + setState((){}); + showSnackBar(context, 'Erro ao fazer o registro, verifique os dados do usuário', Colors.red); + } + } salvarResponsavel() { if(inputNome.text.isNotEmpty && inputNome.text.contains(' ')){ if(inputParentesco.text.isNotEmpty){ if(inputCpf.text.isNotEmpty && GetUtils.isCpf(inputCpf.text)){ if(inputSenha.text.isNotEmpty && inputSenha.text.length > 5){ - if(editando && indice!=null){ - responsaveis[indice!] = ResponsavelModel( - nomeAluno: widget.alunoModel.nome, - raAluno: widget.alunoModel.ra, - escola: widget.alunoModel.escola, - serie: widget.alunoModel.serie, - turma: widget.alunoModel.turma, - nomeResponsavel: inputNome.text, - parentesco: inputParentesco.text, - cpf: inputCpf.text, - senha: inputSenha.text, - dataCadastro: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()) - ); - }else{ - responsaveis.add( - ResponsavelModel( - nomeAluno: widget.alunoModel.nome.toUpperCase(), - raAluno: widget.alunoModel.ra.toUpperCase(), - escola: widget.alunoModel.escola.toUpperCase(), - serie: widget.alunoModel.serie.toUpperCase(), - turma: widget.alunoModel.turma.toUpperCase(), - nomeResponsavel: inputNome.text.toUpperCase(), - parentesco: inputParentesco.text.toUpperCase(), - cpf: inputCpf.text, - senha: inputSenha.text.toUpperCase(), - dataCadastro: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()) - ) - ); - } - editando? - showSnackBar(context, 'Responsável alterado!', Colors.green): - showSnackBar(context, 'Responsável adicionado!', Colors.green); - inputNome.clear(); - inputParentesco.clear(); - inputCpf.clear(); - inputSenha.clear(); - showRegister = false; - editando = false; - indice = null; - inputData.clear(); - setState((){}); + setState(() { + carregando = true; + }); + inserirDB(); }else{ showSnackBar(context, 'Insira o uma senha com o mínimo de 6 caracteres', Colors.red); } @@ -97,53 +122,107 @@ class _ResponsibleRegisterScreenState extends State { } } - carregaPais(){ + carregaPais(var map){ + responsaveis.clear(); + List list = map; if(widget.alunoModel.dados['NO_PAI']!=''){ responsaveis.add( ResponsavelModel( - nomeAluno: widget.alunoModel.nome.toUpperCase(), - raAluno: widget.alunoModel.ra.toUpperCase(), - escola: widget.alunoModel.escola.toUpperCase(), - serie: widget.alunoModel.serie.toUpperCase(), - turma: widget.alunoModel.turma.toUpperCase(), - nomeResponsavel: widget.alunoModel.dados['NO_PAI'], - parentesco: 'PAI', - cpf: '', - senha: '', - dataCadastro: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()) + CD_ALUNO: widget.alunoModel.dados['CD_ALUNO'], + NOME: widget.alunoModel.dados['NO_PAI'], + PARENTESCO: 'PAI', + CPF: '', + SENHA: '', + DATA_CADASTRO: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()), + CONDICAO: '' ) ); } if(widget.alunoModel.dados['NO_MAE']!=''){ responsaveis.add( ResponsavelModel( - nomeAluno: widget.alunoModel.nome.toUpperCase(), - raAluno: widget.alunoModel.ra.toUpperCase(), - escola: widget.alunoModel.escola.toUpperCase(), - serie: widget.alunoModel.serie.toUpperCase(), - turma: widget.alunoModel.turma.toUpperCase(), - nomeResponsavel: widget.alunoModel.dados['NO_MAE'], - parentesco: 'MAE', - cpf: '', - senha: '', - dataCadastro: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()) + CD_ALUNO: widget.alunoModel.dados['CD_ALUNO'], + NOME: widget.alunoModel.dados['NO_MAE'], + PARENTESCO: 'MAE', + CPF: '', + SENHA: '', + DATA_CADASTRO: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()), + CONDICAO: '' ) ); } + //fazer if comparando os parentescos para não duplicar e não falta pais + for(int i = 0; list.length>i;i++){ + if(list[i]['PARENTESCO'].toString().toUpperCase()=='PAI'){ + responsaveis[0]= + ResponsavelModel( + CD_ALUNO: list[i]['CD_ALUNO']??'', + NOME: list[i]['NOME']??'', + PARENTESCO: list[i]['PARENTESCO']??'', + CPF: list[i]['CPF']??'', + SENHA: list[i]['SENHA']??'', + DATA_CADASTRO: list[i]['DATA_CADASTRO']??'', + CONDICAO: list[i]['CONDICAO']??'' + ); + }else if (list[i]['PARENTESCO'].toString().toUpperCase()=='MAE' ||list[i]['PARENTESCO'].toString().toUpperCase()=='MÃE'){ + responsaveis[1]= + ResponsavelModel( + CD_ALUNO: list[i]['CD_ALUNO']??'', + NOME: list[i]['NOME'].toString().toUpperCase()??'', + PARENTESCO: list[i]['PARENTESCO'].toString().toUpperCase()??'', + CPF: list[i]['CPF'].toString().toUpperCase()??'', + SENHA: list[i]['SENHA'].toString().toUpperCase()??'', + DATA_CADASTRO: list[i]['DATA_CADASTRO'].toString().toUpperCase()??'', + CONDICAO: list[i]['CONDICAO']??'' + ); + }else{ + responsaveis.add( + ResponsavelModel( + CD_ALUNO: list[i]['CD_ALUNO']??'', + NOME: list[i]['NOME'].toString().toUpperCase()??'', + PARENTESCO: list[i]['PARENTESCO'].toString().toUpperCase()??'', + CPF: list[i]['CPF'].toString().toUpperCase()??'', + SENHA: list[i]['SENHA'].toString().toUpperCase()??'', + DATA_CADASTRO: list[i]['DATA_CADASTRO'].toString().toUpperCase()??'', + CONDICAO: list[i]['CONDICAO']??'' + ) + ); + } + } + carregando = false; + setState(() {}); } paisBanco()async{ - final url = 'http://localhost:8000/pais'; - // print(url); + final url = 'http://localhost:8000/pais?CD_ALUNO=${widget.alunoModel.dados['CD_ALUNO']}'; + print(url); final response = await http.get(Uri.parse(url)); var map = json.decode(response.body); print(map); + carregaPais(map); + } + + excluirResponsavel(int index, String cpf)async{ + Navigator.pop(context); + setState(() { + carregando = true; + }); + final url = 'http://localhost:8000/deleta?CPF=$cpf'; + print(url); + final response = await http.get(Uri.parse(url)); + print(response.body); + if(response.body == 'deletado com sucesso'){ + responsaveis.removeAt(index); + carregando = false; + setState(() {}); + showSnackBar(context, 'Responsável deletado!', Colors.green); + } } @override void initState() { super.initState(); - carregaPais(); + paisBanco(); } @override @@ -164,7 +243,16 @@ class _ResponsibleRegisterScreenState extends State { ), backgroundColor: PaletteColors.grey, ), - body: Padding( + body: carregando?Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CircularProgressIndicator(), + SizedBox(width: 20,), + TextCustom(text: 'AGUARDE ...') + ], + ), + ):Padding( padding: const EdgeInsets.all(30.0), child: Column( children: [ @@ -208,7 +296,7 @@ class _ResponsibleRegisterScreenState extends State { padding: EdgeInsets.all(10), color: Colors.black54, child: TextCustom( - text: 'Novo responsável', + text: editando?'Editar responsável':'Novo responsável', color: Colors.white, textAlign: TextAlign.center, ), @@ -241,6 +329,7 @@ class _ResponsibleRegisterScreenState extends State { width: width>900? width * 0.18:width*0.4, child: InputText( controller: inputCpf, + enable: !editando, title: 'CPF', width: width * 0.18, colorBorder: PaletteColors.white, @@ -315,7 +404,7 @@ class _ResponsibleRegisterScreenState extends State { showRegister?Container():Container( alignment: Alignment.centerLeft, width: width, - height: height*0.3, + height: height*0.4, child: ListView.separated( itemCount: responsaveis.length, separatorBuilder: (context,index){ @@ -326,19 +415,49 @@ class _ResponsibleRegisterScreenState extends State { responsavelModel: responsaveis[index], onTapEdit: (){ showRegister = true; - editando = true; + if(responsaveis[index].CONDICAO == 'NOVO' || responsaveis[index].CONDICAO == 'EDITADO'){ + editando = true; + } indice = index; - inputNome.text = responsaveis[index].nomeResponsavel; - inputParentesco.text = responsaveis[index].parentesco; - inputCpf.text = responsaveis[index].cpf; - inputSenha.text = responsaveis[index].senha; - inputData.text = responsaveis[index].dataCadastro; + inputNome.text = responsaveis[index].NOME; + inputParentesco.text = responsaveis[index].PARENTESCO; + inputCpf.text = responsaveis[index].CPF; + inputSenha.text = responsaveis[index].SENHA; + inputData.text = responsaveis[index].DATA_CADASTRO; setState(() {}); }, onTapDelete: (){ - responsaveis.removeAt(index); - setState(() {}); - showSnackBar(context, 'Responsável deletado!', Colors.green); + + showDialog( + context: context, + builder: (BuildContext context){ + return AlertDialog( + title: TextCustom(text: 'Excluir Responsável'), + content: TextCustom(text:'Deseja realmente excluir esse responsável?',), + actions: [ + ButtonCustom( + onPressed:()=>Navigator.pop(context), + text: 'NÃO', + widthCustom: 0.1, + heightCustom: 0.05, + colorText: Colors.white, + colorBorder: PaletteColors.bgColor, + colorButton: PaletteColors.bgColor, + size: 15, + ), + ButtonCustom( + onPressed:()=>excluirResponsavel(index, responsaveis[index].CPF), + text: 'SIM', + widthCustom: 0.1, + heightCustom: 0.05, + colorText: Colors.white, + colorBorder: PaletteColors.primaryColor, + colorButton: PaletteColors.primaryColor, + size: 15, + ), + ], + ); + }); }, ); } diff --git a/lib/widgets/dados_responsaveis_container.dart b/lib/widgets/dados_responsaveis_container.dart index 8723c73..9214ff1 100644 --- a/lib/widgets/dados_responsaveis_container.dart +++ b/lib/widgets/dados_responsaveis_container.dart @@ -36,8 +36,8 @@ class DadosResponsaveisContainer extends StatelessWidget { padding: EdgeInsets.symmetric(vertical: 10,horizontal: 5), child: Row( children: [ - CaixaTextoContainer(texto: responsavelModel.nomeResponsavel,titulo: 'Nome',widthCustom: 0.15), - CaixaTextoContainer(texto: responsavelModel.parentesco,titulo: 'Parentesco',widthCustom: 0.1,), + CaixaTextoContainer(texto: responsavelModel.NOME,titulo: 'Nome',widthCustom: 0.15), + CaixaTextoContainer(texto: responsavelModel.PARENTESCO,titulo: 'Parentesco',widthCustom: 0.1,), ], ), ),