示例#1
0
 private void BtnRemover_Click(object sender, EventArgs e)
 {
     if (dgvListaChamada.CurrentRow != null && dgvListaChamada.Rows.Count > 0)
     {
         int selectedIndex = dgvListaChamada.CurrentCell.RowIndex;
         if (selectedIndex > -1)
         {
             if (MessageBox.Show("Você tem certeza que deseja remover este aluno?", "Removendo..", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 ulong ra = (ulong)dgvListaChamada.Rows[selectedIndex].Cells[0].Value;
                 foreach (var item in _Alunos)
                 {
                     if (item.RA == ra)
                     {
                         _Alunos.Remove(item);
                         _ListaChamada.ListaRA.Remove(item.RA);
                         ModuloBanco.ListaChamadaEdit(_ListaChamada.Id, _ListaChamada);
                         break;
                     }
                 }
             }
             else
             {
                 return;
             }
         }
     }
 }
示例#2
0
        private void BtnAdicionar_Click(object sender, EventArgs e)
        {
            #region Checks
            if (CheckTextBox(txtNomeLista))
            {
                MessageBox.Show("Você precisa adicionar um nome a lista de chamda antes!");
                return;
            }

            if (CheckTextBox(txtRa))
            {
                MessageBox.Show("Você precisa colocar um RA!");
                return;
            }

            if (CheckTextBox(txtNome))
            {
                MessageBox.Show("Você precisa colocar um nome!");
                return;
            }
            #endregion
            this.UseWaitCursor = true;
            Aluno aluno = new Aluno()
            {
                Nome = txtNome.Text,
                RA   = Convert.ToUInt64(txtRa.Text)
            };
            foreach (var item in _Alunos)
            {
                if (item.RA == aluno.RA)
                {
                    this.UseWaitCursor = false;
                    MessageBox.Show("RA já adicionado na lista!");
                    return;
                }
            }
            Aluno nomeAlunoSalvo = ModuloBanco.AlunoGet(aluno.RA);
            if (nomeAlunoSalvo != null)
            {
                string nomef = nomeAlunoSalvo.Nome;
                if (aluno.Nome != nomef)
                {
                    this.UseWaitCursor = false;
                    if (MessageBox.Show($"O nome: '{aluno.Nome}' é diferente de '{nomef}'. Deseja salvar mesmo assim?", "Atenção, o nome é diferente!", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        this.UseWaitCursor = true;
                        _Alunos.Add(aluno);
                        _ListaChamada.ListaRA.Add(aluno.RA);
                        ModuloBanco.AlunoAdd(aluno);
                        ModuloBanco.ListaChamadaEdit(_ListaChamada.Id, _ListaChamada);
                        txtNome.Clear();
                        txtRa.Focus();
                        txtRa.Clear();
                        this.UseWaitCursor = false;
                        return;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            _Alunos.Add(aluno);
            _ListaChamada.ListaRA.Add(aluno.RA);
            ModuloBanco.AlunoAdd(aluno);
            ModuloBanco.ListaChamadaEdit(_ListaChamada.Id, _ListaChamada);
            txtNome.Clear();
            txtRa.Focus();
            txtRa.Clear();
            this.UseWaitCursor = false;
        }