From a04cdfa77c66aa09c0f0a014c0a903b2abf9eb6a Mon Sep 17 00:00:00 2001 From: Reginaldo Date: Fri, 30 Jun 2023 12:54:57 -0300 Subject: [PATCH] =?UTF-8?q?inserido=20acesso=20dos=20usu=C3=A1rios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/aluno_model.dart | 4 +- lib/models/login_model.dart | 16 +- lib/screens/home_screen.dart | 183 ++++++++++++------- lib/screens/login_screen.dart | 58 ++++-- lib/screens/responsible_register_screen.dart | 3 + lib/widgets/item_acesso.dart | 54 ++++++ 6 files changed, 235 insertions(+), 83 deletions(-) create mode 100644 lib/widgets/item_acesso.dart diff --git a/lib/models/aluno_model.dart b/lib/models/aluno_model.dart index 8b77643..be10bfc 100644 --- a/lib/models/aluno_model.dart +++ b/lib/models/aluno_model.dart @@ -6,6 +6,7 @@ class AlunoModel{ String serie; String turma; String cidade; + String login; var dados; AlunoModel({ @@ -16,6 +17,7 @@ class AlunoModel{ required this.serie, required this.turma, required this.dados, - required this.cidade + required this.cidade, + required this.login, }); } \ No newline at end of file diff --git a/lib/models/login_model.dart b/lib/models/login_model.dart index e5cffc3..88c8e7f 100644 --- a/lib/models/login_model.dart +++ b/lib/models/login_model.dart @@ -1,9 +1,17 @@ class LoginModel{ - String login; - bool check; + bool CHECK; + String ID_USUARIO; + String DATA; + String CADASTRADO_POR; + String CIDADE; + String STATUS; LoginModel({ - required this.login, - required this.check, + required this.CHECK, + required this.ID_USUARIO, + required this.DATA, + required this.CADASTRADO_POR, + required this.CIDADE, + required this.STATUS }); } \ No newline at end of file diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index d913ebb..d3d640b 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:educa_controle_acesso/utils/colors.dart'; import 'package:educa_controle_acesso/widgets/input_text.dart'; +import 'package:educa_controle_acesso/widgets/item_acesso.dart'; import 'package:educa_controle_acesso/widgets/text_custom.dart'; import 'package:flutter/material.dart'; import '../models/aluno_model.dart'; @@ -33,6 +34,8 @@ class _HomeScreenState extends State { bool buscandoDados = false; bool showEscola = false; + String mensagem = 'BUSCANDO DADOS ...'; + carregarAlunos()async{ resultadoPesquisa.clear(); alunos.clear(); @@ -70,7 +73,8 @@ class _HomeScreenState extends State { serie: list[i]['DESC_SERIE'], turma: list[i]['TURMA'], dados: list[i], - cidade: widget.dados[0] + cidade: widget.dados[0], + login: widget.dados[1] ) ); resultadoPesquisa.add(alunos[i]); @@ -81,60 +85,61 @@ class _HomeScreenState extends State { setState(() { buscandoDados = false; }); - // pesquisarAluno(); } } - // pesquisa(){ - // pesquisarAluno(); - // } - - // pesquisarAluno()async{ - // resultadoPesquisa =[]; - // if(inputPesquisa.text.isNotEmpty){ - // for (int i =0;alunos.length>i;i++) { - // String nome = alunos[i].nome.toUpperCase(); - // String data = alunos[i].data_nasc.toUpperCase(); - // String ra = alunos[i].ra.toUpperCase(); - // - // if(nome.contains(inputPesquisa.text.toUpperCase()) || - // data.contains(inputPesquisa.text.toUpperCase()) || - // ra.contains(inputPesquisa.text.toUpperCase()) - // ){ - // if(resultadoPesquisa.length<10){ - // resultadoPesquisa.add(alunos[i]); - // } - // } - // } - // }else{ - // if(alunos.length<10){ - // for(int i = 0;ii;i++){ - logins.add(LoginModel(login: list[i]['NO_USERNAME'],check: false)); + if(list.length != 0 ){ + for(int i=0;list.length>i;i++){ + logins.add( + LoginModel( + ID_USUARIO: list[i]['ID_USUARIO'], + CHECK:list[i]['CONDICAO']=='1'?true: false, + STATUS: 'CADASTRADO', + CADASTRADO_POR:list[i]['CADASTRADO_POR'], + CIDADE: list[i]['CIDADE'], + DATA: list[i]['DATA'] + ) + ); + } + setState(() { + buscandoDados = false; + }); + }else{ + getAcessosBasePrincipal(); } + } + getAcessosBasePrincipal()async{ + logins.clear(); + setState(() { + buscandoDados = true; + }); + final url = 'http://192.168.18.2:8000/acesso_base?LOGIN=${inputPesquisa.text.toUpperCase()}&CIDADE=${widget.dados[0]}'; + print(url); + final response = await http.get(Uri.parse(url)); + var map = json.decode(response.body); + print(map); + List list = map; + if(list.length!=0){ + for(int i=0;list.length>i;i++){ + if(list[i]['NO_USERNAME']!='ADMIN'){ + logins.add(LoginModel(ID_USUARIO: list[i]['NO_USERNAME'],CHECK: false,STATUS: 'NOVO',CIDADE: widget.dados[0],CADASTRADO_POR: 'NÃO CADASTRADO',DATA: '00/00/0000')); + } + } + }else{ + showSnackBar(context, 'NENHUM USUÁRIO ENCONTRADO!', Colors.red); + } setState(() { buscandoDados = false; }); @@ -146,17 +151,16 @@ class _HomeScreenState extends State { Uri.parse(url), body:{ 'DATA' : DateTime.now().toString(), - 'CONDICAO': logins[index].check?"1":"2", + 'CONDICAO': logins[index].CHECK?"1":"2", 'CADASTRADO_POR': widget.dados[1].toString().toUpperCase(), - 'ID_USUARIO' : logins[index].login, + 'ID_USUARIO' : logins[index].ID_USUARIO, 'CIDADE': widget.dados[0], - 'NOVO' : 'NAO' + 'NOVO' : logins[index].STATUS == 'NOVO'? 'SIM':'NAO' } ); - print(response.body); - if(response.body == 'cadastrado com sucesso' || response.body == 'editado com sucesso'){ - showSnackBar(context, '${response.body}!', Colors.green); - } + // print(response.body); + showSnackBar(context, '${response.body.toUpperCase()}!', Colors.green); + logins[index].STATUS == 'NAO'; buscandoDados = false; setState(() {}); } @@ -174,11 +178,14 @@ class _HomeScreenState extends State { Container( child: Image.asset("assets/images/logoEduca.png",width:width * 0.08,height: height * 0.12) ), - TextCustom(text: '- PESQUISAR ALUNO',color: Colors.white,), + TextCustom(text: showEscola?'- PESQUISAR USUÁRIOS':'- PESQUISAR ESTUDANTES',color: Colors.white,), Spacer(), widget.dados[1].toString().toUpperCase()=='ADMIN'?ButtonCustom( - onPressed: ()=>setState(()=>showEscola?showEscola=false:showEscola=true), - text: showEscola?'Acesso Pais':'Acesso Escola', + onPressed: (){ + inputPesquisa.clear(); + setState(()=>showEscola?showEscola=false:showEscola=true); + }, + text: showEscola?'Cadastrar Pais':'Cadastrar Usuários', size: 15, widthCustom: 0.1, heightCustom: 0.05, @@ -187,7 +194,8 @@ class _HomeScreenState extends State { colorBorder: PaletteColors.white ):Container(), SizedBox(width: width * 0.02), - TextCustom(text: widget.dados[0]==null?'':widget.dados[0],color: Colors.white,) + TextCustom(text: widget.dados[0]==null?'':widget.dados[0],color: Colors.white,), + TextCustom(text:widget.dados[1]==null?'':' - '+widget.dados[1].toString().toUpperCase(),color: Colors.white,), ], ), backgroundColor: PaletteColors.grey, @@ -198,7 +206,7 @@ class _HomeScreenState extends State { children: [ CircularProgressIndicator(), SizedBox(width: 20,), - TextCustom(text: 'BUSCANDO DADOS...') + TextCustom(text: mensagem) ], ), ):Padding( @@ -232,7 +240,8 @@ class _HomeScreenState extends State { setState(() { buscandoDados = true; }); - getAcessos(); + // getAcessosBasePrincipal(); + getAcessosMariaDB(); }else{ showSnackBar(context, 'Digite alguma informação para pesquisar', Colors.red); } @@ -256,24 +265,64 @@ class _HomeScreenState extends State { ) ), Container( + margin: EdgeInsets.symmetric(vertical: 20), padding: EdgeInsets.symmetric(horizontal: width>900?width*0.1:width*0.05), - height: height*0.2, + width: width, + alignment: Alignment.center, + child: Row( + children: [ + SizedBox(width: 30,), + Container( + width: width*0.1, + child: TextCustom(text: 'USUÁRIO',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,), + ), + Container( + width: width*0.1, + child: TextCustom(text: 'DATA DO CADASTRO',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,), + ), + Container( + width: width*0.1, + child: TextCustom(text: 'CADASTRADO POR',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,), + ), + Container( + width: width*0.1, + child: TextCustom(text: 'BASE',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,), + ), + ], + ), + ), + Container( + padding: EdgeInsets.symmetric(horizontal: width>900?width*0.1:width*0.05), + height: height*0.7, child: ListView.builder( itemCount: logins.length, itemBuilder: (context,index){ - return Row( - children: [ - Checkbox( - value: logins[index].check, - onChanged: (v){ - buscandoDados = true; - setState(()=>logins[index].check=v!); - inserirAcessos(index); - } - ), - TextCustom(text: logins[index].login), - ], + return ItemAcesso( + check: logins[index].CHECK, + ID_USUARIO: logins[index].ID_USUARIO, + CADASTRADO_POR: logins[index].CADASTRADO_POR, + CIDADE: logins[index].CIDADE, + DATA: logins[index].DATA, + onChanged: (v){ + buscandoDados = true; + mensagem = 'SALVANDO DADOS ...'; + setState(()=>logins[index].CHECK=v!); + inserirAcessos(index); + } ); + // return Row( + // children: [ + // Checkbox( + // value: logins[index].CHECK, + // onChanged: (v){ + // buscandoDados = true; + // setState(()=>logins[index].CHECK=v!); + // inserirAcessos(index); + // } + // ), + // TextCustom(text: logins[index].ID_USUARIO), + // ], + // ); }, ), ) diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart index 50e98e0..2270d04 100644 --- a/lib/screens/login_screen.dart +++ b/lib/screens/login_screen.dart @@ -24,7 +24,7 @@ class _LoginScreenState extends State { final inputLogin = TextEditingController(text: 'admin'); final inputSenha = TextEditingController(text: 'las1594@@'); final inputCodigo = TextEditingController(text: 'e003'); - bool loading = false; + bool carregando = false; List listCodigo = []; carregarLista(){ @@ -39,9 +39,13 @@ class _LoginScreenState extends State { if(inputCodigo.text.isNotEmpty){ if(listCodigo.contains(inputCodigo.text.toUpperCase())){ setState(() { - loading = true; + carregando = true; }); - conectAPI(); + if(inputLogin.text.toUpperCase() == 'ADMIN'){ + conectAPI(); + }else{ + getAcessosMariaDB(); + } }else{ showSnackBar(context, 'Código inválido', Colors.red); } @@ -56,6 +60,38 @@ class _LoginScreenState extends State { } } + getAcessosMariaDB()async{ + String cidade = ''; + for(int i =0; Cidades().listCidades.length>i;i++){ + if(Cidades().listCidades[i].codigo == inputCodigo.text.toUpperCase()){ + cidade = Cidades().listCidades[i].cidadeQuery.toUpperCase(); + } + } + final url = 'http://192.168.18.2:8000/acesso_maria?LOGIN=${inputLogin.text.toUpperCase()}&CIDADE=$cidade'; + print(url); + final response = await http.get(Uri.parse(url)); + var map = json.decode(response.body); + print(map); + List list = map; + if(list.length != 0 ){ + for(int i=0;list.length>i;i++){ + if(list[i]['ID_USUARIO']==inputLogin.text.toUpperCase() &&list[i]['CONDICAO']=='1'){ + conectAPI(); + }else{ + setState(() { + carregando = false; + }); + showSnackBar(context, 'Login seu acesso não está liberado!', Colors.red); + } + } + }else{ + setState(() { + carregando = false; + }); + showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red); + } + } + conectAPI()async{ String cidade = ''; @@ -71,7 +107,7 @@ class _LoginScreenState extends State { var map = json.decode(response.body); // print(map); if(map==false){ - showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red); + showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red); }else{ if(map['NO_USERNAME']==map['SENHA']){ if(map['NO_USERNAME']==inputLogin.text.toUpperCase() && map['SENHA']==inputSenha.text.toUpperCase()){ @@ -79,7 +115,7 @@ class _LoginScreenState extends State { List dados = [cidade,inputLogin.text]; Navigator.pushNamed(context, '/home',arguments: dados); }else{ - showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red); + showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red); } }else{ if(MainControllers().encrypt(inputSenha.text,map['SENHA']) == map['SENHA']){ @@ -87,12 +123,12 @@ class _LoginScreenState extends State { List dados = [cidade,inputLogin.text]; Navigator.pushNamed(context, '/home',arguments: dados); }else{ - showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red); + showSnackBar(context, 'Login não cadastrado e/ou senha incorreta e/ou Código incorreto', Colors.red); } } } setState(() { - loading = false; + carregando = false; }); } @@ -116,7 +152,7 @@ class _LoginScreenState extends State { Container( child: Image.asset("assets/images/logoEduca.png",width:width * 0.15,height: height * 0.12) ), - loading?Container():Container( + carregando?Container():Container( width: width>900? width * 0.18:width*0.5, child: InputText( inputFormatters: [], @@ -127,7 +163,7 @@ class _LoginScreenState extends State { ), ), SizedBox(height: height * 0.02), - loading?Container():Container( + carregando?Container():Container( width: width>900? width * 0.18:width*0.5, child: InputText( inputFormatters: [], @@ -139,7 +175,7 @@ class _LoginScreenState extends State { ), ), SizedBox(height: height * 0.02), - loading?Container():Container( + carregando?Container():Container( width: width>900? width * 0.18:width*0.5, child: InputText( inputFormatters: [], @@ -150,7 +186,7 @@ class _LoginScreenState extends State { ), ), SizedBox(height: height * 0.02), - loading?Row( + carregando?Row( mainAxisAlignment: MainAxisAlignment.center, children: [ CircularProgressIndicator(), diff --git a/lib/screens/responsible_register_screen.dart b/lib/screens/responsible_register_screen.dart index b66f748..091b0ea 100644 --- a/lib/screens/responsible_register_screen.dart +++ b/lib/screens/responsible_register_screen.dart @@ -243,6 +243,9 @@ class _ResponsibleRegisterScreenState extends State { child: Image.asset("assets/images/logoEduca.png",width:width * 0.08,height: height * 0.12) ), TextCustom(text: '- Cadastrar Responsável',color: Colors.white,), + Spacer(), + TextCustom(text: widget.alunoModel.cidade,color: Colors.white,), + TextCustom(text:' - '+ widget.alunoModel.login.toUpperCase(),color: Colors.white,), ], ), backgroundColor: PaletteColors.grey, diff --git a/lib/widgets/item_acesso.dart b/lib/widgets/item_acesso.dart new file mode 100644 index 0000000..8ecd825 --- /dev/null +++ b/lib/widgets/item_acesso.dart @@ -0,0 +1,54 @@ +import 'package:educa_controle_acesso/widgets/text_custom.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class ItemAcesso extends StatelessWidget { + bool check; + String ID_USUARIO; + String DATA; + String CADASTRADO_POR; + String CIDADE; + var onChanged; + + ItemAcesso({ + required this.check, + required this.ID_USUARIO, + required this.DATA, + required this.CADASTRADO_POR, + required this.CIDADE, + required this.onChanged +}); + + @override + Widget build(BuildContext context) { + + double width = MediaQuery.of(context).size.width; + + String formataData = DATA == '00/00/0000'?'00/00/0000': DateFormat('dd/MM/yyyy hh:mm').format(DateTime.parse(DATA)); + + return Row( + children: [ + Checkbox( + value: check, + onChanged:onChanged + ), + Container( + width: width*0.1, + child: TextCustom(text: ID_USUARIO) + ), + Container( + width: width*0.1, + child: TextCustom(text: formataData) + ), + Container( + width: width*0.1, + child: TextCustom(text: CADASTRADO_POR) + ), + Container( + width: width*0.1, + child: TextCustom(text: CIDADE) + ), + ], + ); + } +}