Exemple #1
0
        private void btnBuscarProfessor_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBuscarProfessor.Text))
            {
                professor = new Professor
                {
                    CPF = txtBuscarProfessor.Text
                };

                professor = ProfessorDAO.BuscarProfessorPorCPF(professor);

                if (professor != null)
                {
                    //Mostrar os dados
                    txtNomeProfessor.Text        = professor.Nome;
                    txtCPFProfessor.Text         = professor.CPF.ToString();
                    dateNascimentoProfessor.Text = professor.dataNasc.ToString();
                    HabilitarCampos(true);
                }
                else
                {
                    MessageBox.Show("Esse aluno não existe!", "Escola WPF",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Favor preencher o nome!", "Escola WPF",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        }     // https://profdouglasbarcelos.github.io/

        private void btnGravarTurma_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtNomeTurma.Text))
            {
                //gravar no banco.
                turma = new Turma()
                {
                    NomeTurma = txtNomeTurma.Text,
                };
                // Relacionamento criado
                Professor professor = new Professor()
                {
                    CPF = Convert.ToString(cbxNomeProfessor.SelectedValue)
                };

                professor         = ProfessorDAO.BuscarProfessorPorCPF(professor);
                turma.IdProfessor = professor.Id;

                if (TurmaDAO.CadastrarTurma(turma))
                {
                    LimparCampos();
                    MessageBox.Show("Turma cadastrado com sucesso!", "Escola WPF",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Essa turma já está Cadastrada!", "Escola WPF",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Favor preencher o nome!", "Escola WPF",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }