コード例 #1
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);
                }
            }
        }