public void FpuDelete(DTO_Aluno aluno) { string Delete = "Delete from tb_Aluno where ID == @id"; if (!(aluno is null)) { FprSqlMetodo(aluno, Delete); } }
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); } }
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); } }
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(); } } }
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"); } }