Ejemplo n.º 1
0
        private void btnListar_Click(object sender, EventArgs e)
        {
            using (Context context = new Context())
            {
                disciplinaBindingSource.DataSource = context.Disciplinas.ToList();
                pnlCover.Hide();
                btnNovo.Enabled   = false;
                btnListar.Enabled = false;
                btnLimpar.Enabled = true;
                Models.Disciplina disciplina = disciplinaBindingSource.Current as Models.Disciplina;

                if (disciplina != null)
                {
                    if (disciplina.Nome != null && disciplina.Id != 0)
                    {
                        btnEditar.Enabled  = true;
                        btnDeletar.Enabled = true;
                        disciplinaBindingSource.MoveFirst();
                        //disciplinaBindingSource.RemoveCurrent();
                    }
                    else
                    {
                        btnEditar.Enabled  = false;
                        btnDeletar.Enabled = false;
                        MessageBox.Show("Não há disciplinas cadastrados", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        btnLimpar_Click(sender, e);
                    }
                }

                _pnlCoverEnable = false;
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            Models.Disciplina disciplinaModel = new Models.Disciplina();
            disciplinaModel.Descricao = tbDescricao.Text;

            disciplinaModel.Salvar();

            MessageBox.Show("Operação completada com sucesso");

            Close();
        }
Ejemplo n.º 3
0
        private void btnDeletar_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show(this, "Tem certeza que deseja deletar este disciplina?", "Atenção!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    using (Context context = new Context())
                    {
                        Models.Disciplina disciplina = disciplinaBindingSource.Current as Models.Disciplina;

                        if (disciplina != null)
                        {
                            if (context.Entry(disciplina).State == EntityState.Detached)
                            {
                                context.Set <Models.Disciplina>().Attach(disciplina);
                            }

                            context.Entry(disciplina).State = EntityState.Deleted;
                            context.SaveChanges();
                            //MessageBox.Show(this, "Disciplina deletado com sucesso!", ";)", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            disciplinaBindingSource.RemoveCurrent();
                            dgvDisciplina.Refresh();
                            Disciplina_Load(sender, e);
                            pnlCadastro.Enabled = false;
                            btnNovo.Enabled     = false;
                            disciplinaBindingSource.MoveLast();
                            disciplinaBindingSource.RemoveCurrent();
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Não é possível deletar uma linha vazia", "Falha ao deletar", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Models.Disciplina disciplinaAux = disciplinaBindingSource.Current as Models.Disciplina;

            if (disciplinaAux == null)
            {
                btnEditar.Enabled  = false;
                btnDeletar.Enabled = false;
            }
        }
Ejemplo n.º 4
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (Services.Services.CheckEmptyField(txtNomeDisciplina, errDisciplina))
            {
                return;
            }
            if (Services.Services.CheckEmptyField(txtNomeDisciplina, errDisciplina))
            {
                return;
            }
            if (Services.Services.CheckEmptyField(txtCargaHoraria, errDisciplina))
            {
                return;
            }

            using (Context context = new Context())
            {
                Models.Disciplina disciplina = disciplinaBindingSource.Current as Models.Disciplina;
                disciplina.TurmaId = ((Models.Avaliacao)cboTurma.SelectedItem).Id;

                if (disciplina != null)
                {
                    if (context.Entry(disciplina).State == EntityState.Detached)
                    {
                        context.Set <Models.Disciplina>().Attach(disciplina);

                        if (disciplina.Id == 0)
                        {
                            context.Entry(disciplina).State = EntityState.Added;
                        }
                        else
                        {
                            context.Entry(disciplina).State = EntityState.Modified;
                        }

                        context.SaveChanges();
                        MessageBox.Show(this, "Disciplina adicionada com sucesso!", ";)", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        dgvDisciplina.Refresh();
                        Disciplina_Load(new object(), new EventArgs());
                        pnlCadastro.Enabled = false;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void btnPesquisar_Click(object sender, EventArgs e)
        {
            using (Context context = new Context())
            {
                List <Models.Disciplina> pesquisa   = context.Disciplinas.Where(x => x.Nome.Contains(txtPesquisa.Text) || x.Nome.Contains(txtPesquisa.Text)).ToList();
                Models.Disciplina        disciplina = disciplinaBindingSource.Current as Models.Disciplina;

                if (disciplina != null && !string.IsNullOrEmpty(txtPesquisa.Text) && pesquisa.Count() != 0)
                {
                    disciplinaBindingSource.DataSource = pesquisa;
                    btnNovo.Enabled   = false;
                    btnLimpar.Enabled = true;
                    pnlCover.Hide();
                }
                else
                {
                    MessageBox.Show("Termo não encontrado ou campo vazio", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    btnCancelar_Click(sender, e);
                }
            }

            Models.Disciplina disciplinaAux = disciplinaBindingSource.Current as Models.Disciplina;

            if (!_pnlCoverEnable)
            {
                btnLimpar.Enabled = true;
                disciplinaBindingSource.MoveLast();

                if (disciplinaAux.Id == 0)
                {
                    disciplinaBindingSource.RemoveCurrent();
                    btnNovo.Enabled    = false;
                    btnEditar.Enabled  = false;
                    btnDeletar.Enabled = false;
                }
            }
            else
            {
                disciplinaBindingSource.MoveLast();
            }
        }