private void btnEliminar_Click_1(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNombre.Text) || string.IsNullOrEmpty(txtDireccion.Text) || string.IsNullOrEmpty(txtCelular.Text) || string.IsNullOrEmpty(txtDUI.Text)) { MessageBox.Show("Debe de llenar los campos", "Completar", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { try { using (SICOVE1Entities2 db = new SICOVE1Entities2()) { string Id = dgvEmpleados.CurrentRow.Cells[0].Value.ToString(); empleados = db.tb_Empleados.Find(int.Parse(Id)); db.tb_Empleados.Remove(empleados); db.SaveChanges(); } MessageBox.Show("El Empleado se ha Eliminado con éxito"); dgvEmpleados.Rows.Clear(); cargardatos(); limpiartxt(); } catch (Exception ex) { MessageBox.Show("Algo salio mal... Intente de nuevo " + ex.ToString()); } } }
private void btnEditar_Click_1(object sender, EventArgs e) { try { using (SICOVE1Entities db = new SICOVE1Entities()) { string Id = dgvEmpleados.CurrentRow.Cells[0].Value.ToString(); int IdC = int.Parse(Id); empleados = db.tb_Empleados.Where(VerificarId => VerificarId.IdEmpleado == IdC).First(); empleados.Nombre = txtNombre.Text; empleados.Direccion = txtDireccion.Text; empleados.Celular = txtCelular.Text; empleados.DUI = txtDUI.Text; empleados.FechaRegistro = Convert.ToDateTime(dtpFechaReg.Text); db.Entry(empleados).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } MessageBox.Show("El Cliente se ha Actualizado con éxito"); dgvEmpleados.Rows.Clear(); cargardatos(); limpiartxt(); btnGuardar.Enabled = true; btnNuevo.Enabled = true; } catch (Exception ex) { MessageBox.Show("Algo salio mal... Intente de nuevo"); } }
private void btnEliminar_Click_1(object sender, EventArgs e) { try { using (SICOVE1Entities db = new SICOVE1Entities()) { string Id = dgvEmpleados.CurrentRow.Cells[0].Value.ToString(); empleados = db.tb_Empleados.Find(int.Parse(Id)); db.tb_Empleados.Remove(empleados); db.SaveChanges(); } MessageBox.Show("El Cliente se ha Eliminado con éxito"); dgvEmpleados.Rows.Clear(); cargardatos(); limpiartxt(); } catch (Exception ex) { MessageBox.Show("Algo salio mal... Intente de nuevo " + ex.ToString()); } }