public void Alterar(PrescriçaoDTO presBllCrud) { if (presBllCrud.Pres_prescriçao.Trim().Length == 0) //verifica se foi informado { throw new Exception("O tipo de prescrição é obrigatório"); } PrescriçaoDAL dalObj = new PrescriçaoDAL(conexao); dalObj.Alterar(presBllCrud); }
}//incluir public void Alterar(PrescriçaoDTO presDalCrud) { SqlCommand cmd = new SqlCommand(); cmd.Connection = conexao.Conexao; cmd.CommandText = "update tbPrescriçao set pre_descriçao = @pre_descriçao where pre_id = @pre_id;"; cmd.Parameters.AddWithValue("@pre_id", presDalCrud.Pres_id); cmd.Parameters.AddWithValue("@pre_descriçao", presDalCrud.Pres_prescriçao); cmd.Parameters.AddWithValue("@pre_atendimento", presDalCrud.Pres_atendimento); conexao.Conectar(); cmd.ExecuteNonQuery(); //não retorna parametro algum conexao.Desconectar(); }//alterar
public void Incluir(PrescriçaoDTO presDalCrud) { SqlCommand cmd = new SqlCommand(); cmd.Connection = conexao.Conexao; cmd.CommandText = "insert into tbPrescriçao(pre_descriçao, pre_atendimento) values (@pre_descriçao, @pre_atendimento);select @@identity;"; cmd.Parameters.AddWithValue("@pre_descriçao", presDalCrud.Pres_prescriçao); cmd.Parameters.AddWithValue("@pre_atendimento", presDalCrud.Pres_atendimento); conexao.Conectar(); presDalCrud.Pres_id = Convert.ToInt32(cmd.ExecuteScalar()); conexao.Desconectar(); }//incluir
}//pesquisar public PrescriçaoDTO CarregaPrescriçaoDTO(int pre_id) //tipo + o campo do banco { PrescriçaoDTO tpProtocolo = new PrescriçaoDTO(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conexao.Conexao; cmd.CommandText = "select * from tbPrescriçao where pre_id = @pre_id;"; cmd.Parameters.AddWithValue("@pre_id", pre_id); conexao.Conectar(); SqlDataReader registro = cmd.ExecuteReader(); if (registro.HasRows) { registro.Read(); tpProtocolo.Pres_id = Convert.ToInt32(registro["pre_id"]); tpProtocolo.Pres_prescriçao = Convert.ToString(registro["pre_descriçao"]); tpProtocolo.Pres_atendimento = Convert.ToInt32(registro["pre_atendimento"]); // parei aqui } conexao.Desconectar(); return tpProtocolo; }//carrega
private void btnSalvarPM_Click(object sender, EventArgs e) { try { //leitura dos dados PrescriçaoDTO pres = new PrescriçaoDTO(); pres.Pres_atendimento = Convert.ToInt32(pre_atendimentoTextBox.Text); pres.Pres_prescriçao = pre_prescriçaoTextBox.Text; //obj para gravar dados no bd ConexaoDAL conexao = new ConexaoDAL(DadosConexaoDAL.StringDeConexão); PrescriçaoBLL bll = new PrescriçaoBLL(conexao); if (this.operacao == "inserir") /// alterar salvar para inserir { bll.Incluir(pres); MessageBox.Show("Cadastrado com Sucesso: Código: " + pres.Pres_id.ToString()); pnInfo.Show(); } else { pres.Pres_id = Convert.ToInt32(pre_idTextBox.Text); bll.Alterar(pres); MessageBox.Show("Cadastrado Alterado com Sucesso: Código: " + pres.Pres_id.ToString()); } this.LimpaTelaPM(); this.alterarBotoesPM(1); } //try catch (Exception erro) { MessageBox.Show(erro.Message); } }