Beispiel #1
0
        private void btnIncluir_Click(object sender, EventArgs e)
        {
            if (btnIncluir.Text.Equals("Incluir"))
            {
                btnIncluir.Text = "Salvar";
                LimpaFormulario();
                txtID.Enabled = false;
                txtNome.Focus();
            }
            else if (btnIncluir.Text.Equals("Salvar"))
            {
                btnIncluir.Text = "Incluir";
                txtID.Enabled   = true;
                try
                {
                    alunoEnt aluno = new alunoEnt();

                    aluno.Nome     = txtNome.Text;
                    aluno.Endereco = txtEndereco.Text;
                    aluno.Email    = txtEmail.Text;

                    alunoModel.Add(aluno);
                    CarregaDados();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro: " + ex.Message);
                }
            }
        }
Beispiel #2
0
        public static alunoEnt GetAluno(int id)
        {
            SqlDataAdapter da    = null;
            DataTable      dt    = new DataTable();
            alunoEnt       aluno = new alunoEnt();

            try
            {
                using (var cmd = DbConnection().CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM alunos Where id_aluno=" + id;
                    da = new SqlDataAdapter(cmd.CommandText, DbConnection());
                    da.Fill(dt);
                    aluno.IdAluno  = Convert.ToInt32(dt.Rows[0]["id_aluno"]);
                    aluno.Nome     = dt.Rows[0]["Nome"].ToString();
                    aluno.Endereco = dt.Rows[0]["Endereco"].ToString();
                    aluno.Email    = dt.Rows[0]["Email"].ToString();
                    aluno.Telefone = dt.Rows[0]["Telefone"].ToString();
                    return(aluno);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
 private void PreencheDados(alunoEnt aluno)
 {
     txtID.Text       = aluno.IdAluno.ToString();
     txtNome.Text     = aluno.Nome;
     txtEndereco.Text = aluno.Email;
     txtTelefone.Text = aluno.Telefone;
 }
Beispiel #4
0
        private void cboAlunos_SelectedIndexChanged(object sender, EventArgs e)
        {
            alunoEnt aluno = new alunoEnt();

            codigoAluno = Convert.ToInt32(((DataRowView)cboAlunos.SelectedItem)["id_aluno"]);

            aluno = alunoModel.GetAluno(codigoAluno);
            PreencheDados(aluno);
        }
Beispiel #5
0
 public static void Add(alunoEnt aluno)
 {
     try
     {
         using (var cmd = DbConnection().CreateCommand())
         {
             cmd.CommandText = "INSERT INTO alunos(Nome, Endereco,Email,Telefone ) values(@nome, @endereco, @email, @telefone)";
             cmd.Parameters.AddWithValue("@nome", aluno.Nome);
             cmd.Parameters.AddWithValue("@endereco", aluno.Endereco);
             cmd.Parameters.AddWithValue("@email", aluno.Email);
             cmd.Parameters.AddWithValue("@telefone", aluno.Telefone);
             cmd.ExecuteNonQuery();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #6
0
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            try
            {
                alunoEnt aluno = new alunoEnt();

                aluno.IdAluno  = Convert.ToInt32(txtID.Text);
                aluno.Nome     = txtNome.Text;
                aluno.Endereco = txtEndereco.Text;
                aluno.Email    = txtEmail.Text;
                aluno.Telefone = txtTelefone.Text;

                alunoModel.Update(aluno);
                CarregaDados();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
        }
Beispiel #7
0
 public static void Update(alunoEnt aluno)
 {
     try
     {
         using (var cmd = DbConnection().CreateCommand())
         {
             if (aluno != null)
             {
                 cmd.CommandText = "UPDATE alunos SET Nome=@Nome,Email=@Email,Endereco=@Endereco,Telefone = @Telefone WHERE id_aluno = @Id";
                 cmd.Parameters.AddWithValue("@Id", aluno.IdAluno);
                 cmd.Parameters.AddWithValue("@Nome", aluno.Nome);
                 cmd.Parameters.AddWithValue("@Endereco", aluno.Endereco);
                 cmd.Parameters.AddWithValue("@Email", aluno.Email);
                 cmd.Parameters.AddWithValue("@Telefone", aluno.Telefone);
                 cmd.ExecuteNonQuery();
             }
         };
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }