private void btn_del_Click(object sender, EventArgs e) { if (txt_name.Text == "") { MessageBox.Show("Debe seleccionar un terapeuta para poder eliminarlo"); this.Terapeuta_Load(); } else { try { int TerId = Convert.ToInt32(dgv_Ter.CurrentRow.Cells[0].Value); DataBase.Terapeuta TerDelete = ch.Terapeutas.Single(w => w.Terapeuta_Id == TerId); ch.Terapeutas.DeleteOnSubmit(TerDelete); MessageBox.Show("El terapeuta seleccionada ha sido eliminada correctamente"); this.Terapeuta_Load(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("No se ha podido eliminar el terapeuta seleccionado"); this.Terapeuta_Load(); } } }
private void btn_confirm_Click(object sender, EventArgs e) { Validaciones.Clear(); if (ValidarCampos()) { switch (Operacion) { case "agregar": try { DataBase.Terapeuta newTer = new DataBase.Terapeuta { Terapeuta_Nom = txt_name.Text.Trim(), Terapeuta_Ape = txt_ape.Text.Trim(), Terapeuta_Doc = txt_doc.Text.Trim(), Terapeuta_Dom = txt_dom.Text.Trim(), Terapeuta_Mail = txt_mail.Text.Trim(), Terapeuta_Mat = txt_mat.Text.Trim(), Terapeuta_Tel = txt_tel.Text.Trim(), Terapeuta_Prof = (Int32)cmb_prof.SelectedValue }; ch.Terapeutas.InsertOnSubmit(newTer); ch.SubmitChanges(); MessageBox.Show("Se ha cargado un nuevo terapeuta"); break; } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("El terapeuta no se ha podido cargar, por favor vuelva a intentar"); break; } case "modificar": try { int TerId = Convert.ToInt32(dgv_Ter.CurrentRow.Cells[0].Value); DataBase.Terapeuta terapeuta = ch.Terapeutas.Where(w => w.Terapeuta_Id == TerId).FirstOrDefault(); terapeuta.Terapeuta_Nom = txt_name.Text.Trim(); terapeuta.Terapeuta_Ape = txt_ape.Text.Trim(); terapeuta.Terapeuta_Doc = txt_doc.Text.Trim(); terapeuta.Terapeuta_Dom = txt_dom.Text.Trim(); terapeuta.Terapeuta_Mail = txt_mail.Text.Trim(); terapeuta.Terapeuta_Mat = txt_mat.Text.Trim(); terapeuta.Terapeuta_Tel = txt_tel.Text.Trim(); terapeuta.Terapeuta_Prof = (Int32)cmb_prof.SelectedValue; ch.SubmitChanges(); MessageBox.Show("El terapeuta ha sido modificado"); break; } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("El terapeuta no se ha podido actualizar, por favor vuelva a intentar"); break; } } this.Terapeuta_Load(); } }