Пример #1
0
        public FrmMenuAcaoAluno(Aluno aluno, string acao)
        {
            InitializeComponent();

            AlunoNegocios alunoNegocios = new AlunoNegocios();

            if (acao == "Inserir Aluno")
            {
                this.Text = "Inserir Aluno";
            }
            else if (acao == "Alterar Aluno")
            {
                this.Text = "Alterar Aluno";
                textBoxAcaoAlunoID.Text = aluno.AlunoID.ToString();
                textBoxAcaoAlunoNome.Text = aluno.AlunoNome;
                textBoxAcaoAlunoMatricula.Text = aluno.AlunoMatricula;
                maskedTextBoxAcaoAlunoTelefone.Text = aluno.AlunoTelefone;
                textBoxAcaoAlunoCursoID.Text = aluno.AlunoCursoID.ToString();
                textBoxAcaoAlunoCursoNome.Text = aluno.AlunoCursoNome;
                textBoxAcaoAlunoUnidade.Text = aluno.AlunoUnidadeNome;
                alunoold = aluno;
            }
            else if (acao == "Consultar Aluno")
            {
                this.Text = "Consultar Aluno";
                textBoxAcaoAlunoID.Text = aluno.AlunoID.ToString();
                textBoxAcaoAlunoNome.Text = aluno.AlunoNome;
                textBoxAcaoAlunoMatricula.Text = aluno.AlunoMatricula;
                maskedTextBoxAcaoAlunoTelefone.Text = aluno.AlunoTelefone;
                textBoxAcaoAlunoCursoID.Text = aluno.AlunoCursoID.ToString();
                textBoxAcaoAlunoCursoNome.Text = aluno.AlunoCursoNome;
                textBoxAcaoAlunoCursoNome.Width = 314;
                textBoxAcaoAlunoUnidade.Text = aluno.AlunoUnidadeNome;
                buttonAcaoAlunoCursoSelecionar.Visible = false;

                buttonAcaoAlunoConfirmar.Hide();
                buttonAcaoAlunoCancelar.Hide();
                textBoxAcaoAlunoNome.ReadOnly = true;
                textBoxAcaoAlunoMatricula.ReadOnly = true;
                maskedTextBoxAcaoAlunoTelefone.ReadOnly = true;

                labelAcaoAlunoCO.Hide();
            }
        }
Пример #2
0
        private void buttonAcaoAlunoConfirmar_Click(object sender, EventArgs e)
        {
            if (this.Text == "Inserir Aluno")
            {
                Aluno aluno = new Aluno();
                AlunoNegocios alunoNegocios = new AlunoNegocios();

                aluno.AlunoNome = textBoxAcaoAlunoNome.Text;
                aluno.AlunoMatricula = textBoxAcaoAlunoMatricula.Text;
                aluno.AlunoTelefone = maskedTextBoxAcaoAlunoTelefone.Text;
                if (textBoxAcaoAlunoCursoID.Text != "")
                {
                    aluno.AlunoCursoID = Convert.ToInt32(textBoxAcaoAlunoCursoID.Text);
                }
                aluno.AlunoCursoNome = textBoxAcaoAlunoCursoNome.Text;
                aluno.AlunoUnidadeNome = textBoxAcaoAlunoUnidade.Text;

                if (aluno.AlunoNome == "" || aluno.AlunoMatricula == "" || aluno.AlunoCursoID.ToString() == ""
                    || aluno.AlunoCursoNome == "")
                {
                    MessageBox.Show("Favor preencher todos os campos!");
                }
                else
                {
                    int alunoid = 0;
                    int verificacao = alunoNegocios.VerificarAlunoExistente(textBoxAcaoAlunoMatricula.Text, alunoid);

                    if (verificacao != 0)
                    {
                        MessageBox.Show("Já existe aluno cadastrado com esta matrícula!");
                    }
                    else
                    {
                        string retorno = alunoNegocios.Inserir(aluno);
                        try
                        {
                            int alunoID = Convert.ToInt32(retorno);

                            MessageBox.Show("Registro inserido com sucesso! Código cadastrado: " + alunoID.ToString());
                            this.DialogResult = DialogResult.Yes;
                        }
                        catch
                        {
                            MessageBox.Show("Não foi possível completar a operação! Detalhes: " + retorno, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            this.DialogResult = DialogResult.No;
                        }
                    }
                }
            }

            if (this.Text == "Alterar Aluno")
            {
                Aluno aluno = new Aluno();
                AlunoNegocios alunoNegocios = new AlunoNegocios();

                aluno.AlunoID = Convert.ToInt32(textBoxAcaoAlunoID.Text);
                aluno.AlunoNome = textBoxAcaoAlunoNome.Text;
                aluno.AlunoMatricula = textBoxAcaoAlunoMatricula.Text;
                aluno.AlunoTelefone = maskedTextBoxAcaoAlunoTelefone.Text;
                aluno.AlunoCursoID = Convert.ToInt32(textBoxAcaoAlunoCursoID.Text);
                aluno.AlunoCursoNome = textBoxAcaoAlunoCursoNome.Text;
                aluno.AlunoUnidadeNome = textBoxAcaoAlunoUnidade.Text;

                if (aluno.AlunoNome == alunoold.AlunoNome
                    && aluno.AlunoMatricula == alunoold.AlunoMatricula
                    && aluno.AlunoTelefone == alunoold.AlunoTelefone
                    && aluno.AlunoCursoID == alunoold.AlunoCursoID
                    && aluno.AlunoCursoNome == alunoold.AlunoCursoNome)
                {
                    MessageBox.Show("Os campos não foram alterados!");
                }
                else
                {

                    if (aluno.AlunoNome == "" || aluno.AlunoMatricula == "" || aluno.AlunoCursoID.ToString() == ""
                    || aluno.AlunoCursoNome == "")
                    {
                        MessageBox.Show("Favor preencher todos os campos!");
                    }
                    else
                    {
                        int verificacao = alunoNegocios.VerificarAlunoExistente(textBoxAcaoAlunoMatricula.Text, Convert.ToInt32(textBoxAcaoAlunoID.Text));

                        if (verificacao != 0)
                        {
                            MessageBox.Show("Já existe aluno cadastrado com esta matrícula!");
                        }
                        else
                        {
                            string retorno = alunoNegocios.Alterar(aluno);
                            try
                            {
                                int alunoID = Convert.ToInt32(retorno);

                                MessageBox.Show("Registro alterado com sucesso! Código: " + alunoID.ToString());
                                this.DialogResult = DialogResult.Yes;
                            }
                            catch
                            {
                                MessageBox.Show("Não foi possível completar a operação! Detalhes: " + retorno, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                this.DialogResult = DialogResult.No;
                            }
                        }
                    }
                }
            }
        }