private void btnExcluir_Click(object sender, EventArgs e) { int id = int.Parse(txtIdPaciente.Text); if (MessageBox.Show("Deseja realmente excluir?", "Cuidado!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No) { MessageBox.Show("Operação Cancelada!"); } else { try { GestaoPacienteService.VOL.Database db = new GestaoPacienteService.VOL.Database(); SqlConnection con = new SqlConnection(db.connenctionString); con.Open(); SqlCommand cmmd = new SqlCommand("DELETE FROM Pacientes WHERE IdPaciente = '" + id + "'", con); cmmd.ExecuteNonQuery(); con.Close(); this.Close(); } catch (Exception) { MessageBox.Show("Erro na exclusão do paciente!"); } } }
private void btnAlterar_Click(object sender, EventArgs e) { string sexo; if (rdbMasc.Checked) { sexo = "Masculino"; } else { sexo = "Feminino"; } int id = int.Parse(txtIdPaciente.Text); int idade; if (validaForm() != false) { try { int.TryParse(txtIdade.Text, out idade); GestaoPacienteService.VOL.Database db = new GestaoPacienteService.VOL.Database(); SqlConnection con = new SqlConnection(db.connenctionString); con.Open(); SqlCommand cmmd = new SqlCommand("UPDATE Pacientes SET NomePaciente = @Nome ,IdadePaciente = '" + idade + "', SexoPaciente = '" + sexo + "', TelefonePaciente = '" + txtTel.Text + "', CelularPaciente = '" + txtCel.Text + "', EmailPaciente = '" + txtEmail.Text + "', RespPaciente = '" + txtResp.Text + "' WHERE IdPaciente = '" + id + "' ", con); cmmd.Parameters.Add("@Nome", SqlDbType.Char); cmmd.Parameters["@Nome"].Value = txtNome.Text; cmmd.ExecuteNonQuery(); con.Close(); this.Close(); } catch (Exception) { MessageBox.Show("Erro na alteração de dados do paciente!"); } } }