389 lines
14 KiB
Dart
389 lines
14 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:rkm_educa_prof_app/componentes/item_aluno_nota.dart';
|
|
import '../componentes/appbar_custom.dart';
|
|
import '../componentes/drawer_custom.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import '../componentes/dropdown_disciplina.dart';
|
|
import '../componentes/dropdown_periodo.dart';
|
|
import '../componentes/dropdown_turma.dart';
|
|
import '../componentes/item_subtitulo_texto.dart';
|
|
import '../componentes/snackBars.dart';
|
|
import '../componentes/text_custom.dart';
|
|
import '../controllers/main_controllers.dart';
|
|
import '../modelos/modelo_disciplina.dart';
|
|
import '../modelos/modelo_nota_aluno.dart';
|
|
import '../modelos/modelo_periodo.dart';
|
|
import '../utils/cores.dart';
|
|
import '../utils/dimensoes.dart';
|
|
|
|
class TelaNotas extends StatefulWidget {
|
|
List dados;
|
|
|
|
TelaNotas({
|
|
required this.dados
|
|
});
|
|
|
|
@override
|
|
State<TelaNotas> createState() => _TelaNotasState();
|
|
}
|
|
|
|
class _TelaNotasState extends State<TelaNotas> {
|
|
|
|
List<ModeloDisciplina> disciplinas = [];
|
|
List<ModeloPeriodo> periodos = [];
|
|
List tipoEnsino = [];
|
|
List turmas = [];
|
|
String SIGLA_TIPO_ENSINO = '';
|
|
String? selecionaTurma;
|
|
double hightLine = 40;
|
|
bool edit = false;
|
|
ModeloDisciplina? selecionaDisciplina;
|
|
ModeloPeriodo? selecionaPeriodo;
|
|
int ID_TIPO_ENSINO = 0;
|
|
int CD_DISCIPLINA = 0;
|
|
int CD_SALA = 0;
|
|
String CD_PERIODO = '';
|
|
List<ModeloNotaAluno> alunos = [];
|
|
bool novaNota = false;
|
|
bool SALVANDO = false;
|
|
|
|
buscarDisciplinas()async{
|
|
// print('dados');
|
|
// print(widget.dados);
|
|
final url = '${widget.dados[2]}/buscardisciplinasprof?USUARIO_SISTEMA=${widget.dados[8]}&CIDADE=${widget.dados[0]}&ANO=${DateTime.now().year}';
|
|
// print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
var map = json.decode(response.body);
|
|
// print(map);
|
|
List list = map;
|
|
for(int i = 0; list.length > i; i++){
|
|
tipoEnsino.add(list[i]['CD_TIPO_ENSINO']);
|
|
disciplinas.add(
|
|
ModeloDisciplina(
|
|
CD_ANO_DISCIPLINA: list[i]['CD_ANO_DISCIPLINA'],
|
|
CD_CAD_DIVERSO: list[i]['CD_CAD_DIVERSO'],
|
|
CD_SALA: list[i]['CD_SALA'],
|
|
CD_SERIE: list[i]['CD_SERIE'],
|
|
ANO_ATRIBUICAO: list[i]['ANO_ATRIBUICAO'],
|
|
CD_DISCIPLINA: list[i]['CD_DISCIPLINA'],
|
|
CD_TIPO_ENSINO: list[i]['CD_TIPO_ENSINO'],
|
|
DESCRICAO: list[i]['DESCRICAO'],
|
|
ABREVIATURA: list[i]['ABREVIATURA'],
|
|
TURMA: list[i]['TURMA'].toString().trim(),
|
|
DESC_SERIE: list[i]['DESC_SERIE'].toString().trim(),
|
|
GRAU: list[i]['GRAU'].toString().trim(),
|
|
HR_INICIO: list[i]['HR_INICIO'].toString().trim()
|
|
)
|
|
);
|
|
|
|
turmas.add(
|
|
'${disciplinas[i].GRAU} - ${disciplinas[i].DESC_SERIE} - ${disciplinas[i].TURMA} - ${disciplinas[i].HR_INICIO.toString().trim().toUpperCase()=='07:00:00'?'MANHA':'TARDE'}'
|
|
);
|
|
if(SIGLA_TIPO_ENSINO != disciplinas[i].GRAU.toString().trim().toUpperCase()){
|
|
SIGLA_TIPO_ENSINO = disciplinas[i].GRAU.toString().trim().toUpperCase();
|
|
}
|
|
if(turmas.isNotEmpty){
|
|
List duplicada = turmas.toSet().toList();
|
|
turmas = duplicada;
|
|
}
|
|
}
|
|
setState(() {});
|
|
// print(disciplinas);
|
|
}
|
|
|
|
buscarPediodoNotas()async{
|
|
final url = '${widget.dados[2]}/buscarperiodonotas?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;
|
|
for(int i = 0; list.length > i; i++){
|
|
periodos.add(ModeloPeriodo(PERIODO: list[i]['PERIODO'], NO_PERIODO: list[i]['NO_PERIODO']));
|
|
// print(periodos[i].PERIODO);
|
|
}
|
|
setState(() {});
|
|
}
|
|
|
|
buscarNotasRealizadas()async{
|
|
|
|
final url = '${widget.dados[2]}/buscarnotasrealizadas?CD_SALA=$CD_SALA&CD_DISCIPLINA=$CD_DISCIPLINA&PERIODO=$CD_PERIODO&CIDADE=${widget.dados[0]}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
List map = json.decode(response.body);
|
|
// print(map);
|
|
if(map.isNotEmpty){
|
|
alunos.clear();
|
|
for(int i = 0; map.length > i; i++){
|
|
TextEditingController nota = TextEditingController(text: map[i]['NOTA']=='' || map[i]['NOTA'] == null?'0':map[i]['NOTA']);
|
|
|
|
alunos.add(
|
|
ModeloNotaAluno(
|
|
CD_MATRICULA: map[i]['CD_MATRICULA'],
|
|
CD_DISCIPLINA: CD_DISCIPLINA,
|
|
CD_SALA: CD_SALA,
|
|
PERIODO: CD_PERIODO,
|
|
NOTA: nota,
|
|
CD_ALUNO: map[i]['CD_ALUNO'],
|
|
CD_NOTA: map[i]['CD_NOTA'],
|
|
NR_TURMA: map[i]['NR_TURMA'],
|
|
NO_ALUNO: map[i]['NO_ALUNO'],
|
|
STATUS: map[i]['STATUS'],
|
|
)
|
|
);
|
|
}
|
|
novaNota = false;
|
|
SALVANDO = false;
|
|
edit = false;
|
|
print('alunos : ${alunos.length}');
|
|
}else{
|
|
novaNota = true;
|
|
buscarNovaChamada();
|
|
}
|
|
setState(() {});
|
|
}
|
|
|
|
|
|
buscarNovaChamada()async{
|
|
int ano = DateTime.now().year;
|
|
final url = '${widget.dados[2]}/buscarnovachamada?''CD_SALA=${CD_SALA}&ANO=${ano}&CIDADE=${widget.dados[0]}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
List map = json.decode(response.body);
|
|
print(map);
|
|
if(map.isNotEmpty){
|
|
alunos.clear();
|
|
for(int i = 0; map.length > i; i++){
|
|
TextEditingController nota = TextEditingController(text: map[i]['STATUS']!='MATRICULADO'?'0':'');
|
|
alunos.add(
|
|
ModeloNotaAluno(
|
|
CD_MATRICULA: map[i]['CD_MATRICULA'],
|
|
CD_DISCIPLINA: CD_DISCIPLINA,
|
|
CD_SALA: CD_SALA,
|
|
PERIODO: CD_PERIODO,
|
|
NOTA: nota,
|
|
CD_ALUNO: map[i]['CD_ALUNO'],
|
|
CD_NOTA: 0,
|
|
NR_TURMA: map[i]['NR_TURMA'],
|
|
NO_ALUNO: map[i]['NO_ALUNO'],
|
|
STATUS: map[i]['STATUS'],
|
|
)
|
|
);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'NÃO FOI POSSÍVEL CRIAR UMA NOVA CHAMADA', Colors.red);
|
|
}
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
buscarDisciplinas();
|
|
buscarPediodoNotas();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
appBar: AppBarCustom().appbar(context, 'LANÇAMENTO DE NOTAS'),
|
|
drawer: DrawerCustom(dados: widget.dados,),
|
|
bottomNavigationBar: SALVANDO?Container(width: 0,height: 0,):edit?Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SALVANDO?Container():CircleAvatar(
|
|
backgroundColor: Colors.red,
|
|
child: IconButton(
|
|
icon: Icon(Icons.clear,color: Colors.white,),
|
|
onPressed: (){
|
|
setState(()=>edit=false);
|
|
buscarNotasRealizadas();
|
|
}
|
|
),
|
|
),
|
|
SizedBox(width: 10,),
|
|
SALVANDO?Container():CircleAvatar(
|
|
backgroundColor: PaletaCores.verdeCalendario,
|
|
child: IconButton(
|
|
icon: Icon(Icons.check,color: Colors.white,),
|
|
onPressed: ()async{
|
|
bool aguardandoAlteracao = false;
|
|
int indexAluno = alunos.indexWhere((aluno) => aluno.AVISO != '');
|
|
int indexNota = alunos.indexWhere((aluno) => aluno.NOTA.text == '');
|
|
|
|
print('indexNota');
|
|
print(indexNota);
|
|
print('indexAluno');
|
|
print(indexAluno);
|
|
|
|
if(indexAluno==-1 && indexNota ==-1){
|
|
|
|
setState(()=>SALVANDO = true);
|
|
|
|
if(novaNota){
|
|
aguardandoAlteracao = await MainControllers().salvarNovaNota(alunos, widget.dados);
|
|
}else{
|
|
aguardandoAlteracao = await MainControllers().atualizarNota(alunos, widget.dados);
|
|
}
|
|
|
|
if(aguardandoAlteracao){
|
|
buscarNotasRealizadas();
|
|
showSnackBar(context, 'DADOS SALVOS COM SUCESSO', Colors.green);
|
|
setState(()=>SALVANDO = false);
|
|
setState(()=>edit=false);
|
|
}else{
|
|
setState(()=>SALVANDO = false);
|
|
showSnackBar(context, 'DADOS NÃO FORAM SALVOS', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'VERIFIQUE SE TODAS AS NOTAS FORAM INSERIDAS CORRETAMENTE!', Colors.red);
|
|
}
|
|
}
|
|
)
|
|
),
|
|
],
|
|
),
|
|
):Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
CircleAvatar(
|
|
backgroundColor: Colors.deepOrangeAccent,
|
|
child: IconButton(
|
|
icon: Icon(Icons.edit, color: Colors.white),
|
|
onPressed: ()=> setState(()=>edit=true)
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
body: ListView(
|
|
padding: EdgeInsets.all(20),
|
|
children: [
|
|
ItemSubtituloTexto(titulo:'Escola: ',subtitulo: widget.dados[3]),
|
|
DropdownTurma(
|
|
titulo: 'Turma: ',
|
|
seleciona: selecionaTurma,
|
|
itens: turmas,
|
|
hightLine: hightLine,
|
|
onChanged:edit?null: (value){
|
|
selecionaTurma = value!.toString();
|
|
selecionaDisciplina = null;
|
|
selecionaPeriodo = null;
|
|
int index = turmas.indexOf(selecionaTurma);
|
|
ID_TIPO_ENSINO = tipoEnsino[index];
|
|
alunos.clear();
|
|
setState(() {});
|
|
},
|
|
),
|
|
selecionaTurma==null?Container():DropdownPeriodo(
|
|
titulo: 'Período: ',
|
|
seleciona: selecionaPeriodo,
|
|
hightLine: hightLine,
|
|
itens: periodos.map((value) => DropdownMenuItem<ModeloPeriodo>(
|
|
value: value,
|
|
child: TextCustom(
|
|
text: value.NO_PERIODO,
|
|
size: 12.0,
|
|
color: Colors.black54,
|
|
),
|
|
)
|
|
).toList(),
|
|
onChanged:edit?null: (ModeloPeriodo? value){
|
|
selecionaPeriodo = value;
|
|
selecionaDisciplina = null;
|
|
CD_PERIODO = selecionaPeriodo!.PERIODO.toString().trim();
|
|
alunos.clear();
|
|
setState(() {});
|
|
},
|
|
),
|
|
selecionaTurma==null || selecionaPeriodo== null?Container():
|
|
DropdownDisciplina(
|
|
titulo: 'Disciplina: ',
|
|
seleciona: selecionaDisciplina,
|
|
hightLine: hightLine,
|
|
listDropDown: disciplinas.map((value) => DropdownMenuItem<ModeloDisciplina>(
|
|
value: value,
|
|
child: TextCustom(
|
|
text: value.DESCRICAO,
|
|
size: 12.0,
|
|
color: Colors.black54,
|
|
),
|
|
)
|
|
).toList(),
|
|
onChanged:edit?null: (ModeloDisciplina? value){
|
|
alunos.clear();
|
|
selecionaDisciplina = value;
|
|
print('CD_DISCIPLINA : '+ value!.CD_DISCIPLINA.toString());
|
|
print('CD_SALA : '+ value!.CD_SALA.toString());
|
|
CD_DISCIPLINA = value!.CD_DISCIPLINA;
|
|
CD_SALA = value!.CD_SALA;
|
|
buscarNotasRealizadas();
|
|
setState(() {});
|
|
},
|
|
),
|
|
SALVANDO || alunos.isEmpty?Container():Container(
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 30,
|
|
child: TextCustom(text: 'N°',size: 12.0, fontWeight: FontWeight.bold)),
|
|
TextCustom(text: 'ESTUDANTE',size: 12.0, fontWeight: FontWeight.bold),
|
|
Spacer(),
|
|
TextCustom(text: 'NOTAS',size: 12.0, fontWeight: FontWeight.bold),
|
|
],
|
|
),
|
|
),
|
|
if (SALVANDO || alunos.isEmpty) Container() else Container(
|
|
height: Dimensoes.height*0.6,
|
|
child: ListView.builder(
|
|
itemCount: alunos.length,
|
|
itemBuilder: (context, index){
|
|
return ItemAlunoNota(
|
|
edit: edit,
|
|
aluno: alunos[index],
|
|
onChanged: (value){
|
|
if (value!.isEmpty) {
|
|
alunos[index].AVISO = 'Por favor, digite um valor';
|
|
}else{
|
|
double? nota = double.tryParse(value);
|
|
if (nota == null || nota < 0 || nota > 10) {
|
|
alunos[index].AVISO = 'A nota deve ser um número entre 0 e 10';
|
|
}else{
|
|
alunos[index].AVISO = '';
|
|
alunos[index].STATUS_DADOS = 'ALTERADO';
|
|
}
|
|
}
|
|
setState(() {});
|
|
},
|
|
);
|
|
}
|
|
)
|
|
),
|
|
SALVANDO?Container(
|
|
height: Dimensoes.height*0.55,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircularProgressIndicator(color: Colors.deepOrangeAccent),
|
|
SizedBox(height: 50),
|
|
TextCustom(text: 'Salvando dados dos estudantes.\nAguarde...', fontWeight: FontWeight.bold,maxLines: 2,)
|
|
],
|
|
),
|
|
):Container(),
|
|
],
|
|
)
|
|
);
|
|
}
|
|
}
|