Exemplo n.º 1
0
        private void btnCadastrarProfessor_Click(object sender, EventArgs e)
        {
            if (tbProfessor.Text != null && tbProfessor.Text != "")
            {
                Professor professor = new Professor(Convert.ToDateTime(dtNascimentoProfessor.Text), tbProfessor.Text);

                ProfessorRepositorio professorRepositorio = new ProfessorRepositorio();

                string matricula = professorRepositorio.cadastraProfessor(professor);

                if (matricula != null && matricula != "")
                {
                    if (formAreaPesquisa != null && formAreaPesquisa.listaSelecionada != null && formAreaPesquisa.listaSelecionada.Count > 0)
                    {
                        ProfessorAreaPesquisaRepositorio professorAreaPesquisaRepositorio = new ProfessorAreaPesquisaRepositorio();
                        professorAreaPesquisaRepositorio.ligaProfessorAreaPesquisa(matricula, formAreaPesquisa.listaSelecionada);
                    }

                    if (formCurso != null && formCurso.listaSelecionada != null && formCurso.listaSelecionada.Count > 0)
                    {
                        ProfessorCursoRepositorio professorCursoRepositorio = new ProfessorCursoRepositorio();
                        professorCursoRepositorio.ligaProfessorCurso(matricula, formCurso.listaSelecionada);
                    }
                }
                btnBuscarProfessor_Click(null, null);
                MessageBox.Show("Professor cadastrado com sucesso");
            }
            else
            {
                MessageBox.Show("Os dados para cadastro de um professor estão incompletos. Por favor preencha todos os campos e tente novamente.");
            }
        }
Exemplo n.º 2
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (dtvProfessor != null)
            {
                DataGridViewSelectedCellCollection selectedCells = dtvProfessor.SelectedCells;

                if (selectedCells.Count != 3)
                {
                    return;
                }
                string matricula = selectedCells[0].FormattedValue.ToString();

                string nome = selectedCells[1].FormattedValue.ToString();

                string dataNascimento = selectedCells[2].FormattedValue.ToString();

                Professor professor = new Professor(Convert.ToInt32(matricula), Convert.ToDateTime(dataNascimento), nome);

                if (matricula != null && matricula != "")
                {
                    if (formAreaPesquisa != null && formAreaPesquisa.listaSelecionada != null && formAreaPesquisa.listaSelecionada.Count > 0)
                    {
                        ProfessorAreaPesquisaRepositorio professorAreaPesquisaRepositorio = new ProfessorAreaPesquisaRepositorio();
                        professorAreaPesquisaRepositorio.ligaProfessorAreaPesquisa(matricula, formAreaPesquisa.listaSelecionada);
                    }

                    if (formCurso != null && formCurso.listaSelecionada != null && formCurso.listaSelecionada.Count > 0)
                    {
                        ProfessorCursoRepositorio professorCursoRepositorio = new ProfessorCursoRepositorio();
                        professorCursoRepositorio.ligaProfessorCurso(matricula, formCurso.listaSelecionada);
                    }
                }

                ProfessorRepositorio professorRepositorio = new ProfessorRepositorio();

                if (professorRepositorio.editaProfessor(professor) == 1)
                {
                    MessageBox.Show("Os dados do professor foram alterados com sucesso!");
                    tbProfessor.Text = nome;
                    btnBuscarProfessor_Click(sender, e);
                }
            }
        }