private void btn_del_Click(object sender, EventArgs e) { if (txt_name.Text == "") { MessageBox.Show("Debe seleccionar una profesion para poder eliminarla"); this.Profesion_Load(); } else { try { int ProId = Convert.ToInt32(dgv_Profesion.CurrentRow.Cells[0].Value); DataBase.Profesione ProDelete = ch.Profesiones.Single(w => w.Profesion_Id == ProId); ch.Profesiones.DeleteOnSubmit(ProDelete); MessageBox.Show("La profesion seleccionada ha sido eliminada correctamente"); this.Profesion_Load(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("No se ha podido eliminar la profesion seleccionada"); this.Profesion_Load(); } } }
private void btn_confirm_Click(object sender, EventArgs e) { Validacion.Clear(); if (ValidarNombre()) { switch (Operacion) { case "agregar": try { DataBase.Profesione newPro = new DataBase.Profesione(); newPro.Profesion_Nom = txt_name.Text.Trim(); ch.Profesiones.InsertOnSubmit(newPro); ch.SubmitChanges(); MessageBox.Show("Nueva profesion cargada"); break; } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("La profesion no se ha podido cargar, por favor vuelva a intentar"); break; } case "modificar": try { int ProId = Convert.ToInt32(dgv_Profesion.CurrentRow.Cells[0].Value); var query = ch.Profesiones.Where(w => w.Profesion_Id == ProId).FirstOrDefault(); query.Profesion_Nom = txt_name.Text.Trim(); ch.SubmitChanges(); MessageBox.Show("La profesion ha sido modificada"); break; } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("La profesion no se ha podido actualizar, por favor vuelva a intentar"); break; } } this.Profesion_Load(); } }