Exemplo n.º 1
0
        public void FpuDelete(DTO_Aluno aluno)
        {
            string Delete = "Delete from tb_Aluno where ID == @id";

            if (!(aluno is null))
            {
                FprSqlMetodo(aluno, Delete);
            }
        }
Exemplo n.º 2
0
        public void FpuInsert(DTO_Aluno aluno)
        {
            string Insert = "Insert into tb_Aluno (ID, Nome, Escola) values (@matricula, @nome, @nome_escola)";

            if (!(aluno is null))
            {
                FprSqlMetodo(aluno, Insert);
            }
        }
Exemplo n.º 3
0
        public void FpuUpdate(DTO_Aluno aluno)
        {
            string Update = "Update tb_Aluno set ID = @matricula, Nome = @nome, Escola = @nome_escola where ID == @id";

            if (!(aluno is null))
            {
                FprSqlMetodo(aluno, Update);
            }
        }
Exemplo n.º 4
0
        private void FprSqlMetodo(DTO_Aluno aluno, string str_Command)
        {
            using (SqlConnection sqlConnection = new DTO.ConexaoSQL().Conectar)
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    SqlConnection Connection = sqlCommand.Connection = sqlConnection;
                    Connection.Open();

                    _ = sqlCommand.Parameters.AddWithValue("@nome", aluno.str_Nome);
                    _ = sqlCommand.Parameters.AddWithValue("@matricula", aluno.dec_Matriula);
                    _ = sqlCommand.Parameters.AddWithValue("@nome_escola", aluno.str_Nome_Escola);

                    _ = sqlCommand.CommandText = str_Command;

                    sqlCommand.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 5
0
        private void btn_Cadastrar_Click(object sender, EventArgs e)
        {
            if (Validar() == true)
            {
                // cria um modelo para ser usado pela dto
                DTO_Aluno aluno_modelo = new DTO_Aluno();
                aluno_modelo.str_Nome        = txt_Nome.Text;
                aluno_modelo.dec_Matriula    = Convert.ToDecimal(txt_Matricula.Text);
                aluno_modelo.str_Nome_Escola = txt_Escola.Text;

                //Insere no banco usando a bll
                Aluno aluno1 = new Aluno();
                aluno1.FpuInsert(aluno_modelo);
            }
            else
            {
                MessageBox.Show("Erro campo não prenchido");
            }
        }