public ActionResult DeleteConfirmed(int clienteId) { Cliente cliente = unitOfWork.Cliente.GetClienteActivo(clienteId); if (cliente == null) { TempData["mensaje"] = ItemMensaje.ErrorDatosNoValidosDesactivar(Cliente.GetNombreModelo()); return(RedirectToAction("Index")); } // Verifica que el cliente tenga pólizas en vigor. var polizasVigor = context.Poliza.Where(c => c.clienteId == clienteId && c.activo == 1).Select(c => c.polizaId).ToList(); if (polizasVigor.Any()) { TempData["mensaje"] = ItemMensaje.ErrorPolizaVigorDesactivarCondicionado(Cliente.GetNombreModelo(), polizasVigor); return(RedirectToAction("Details", new { id = cliente.clienteId })); } else { try { clienteBll.DeleteCliente(cliente); TempData["mensaje"] = ItemMensaje.SuccessDesactivar(Cliente.GetNombreModelo(), cliente.apellido1Cliente); return(RedirectToAction("Index")); } catch (Exception ex) { TempData["mensaje"] = ItemMensaje.ErrorExcepcionDesactivar(Cliente.GetNombreModelo(), ex.GetType().ToString()); return(RedirectToAction("Index")); } } }
protected void GridCliente_RowCommand(object sender, GridViewCommandEventArgs e) { int clienteId = 0; try { clienteId = Convert.ToInt32(e.CommandArgument); } catch (Exception ex) { } if (clienteId <= 0) { return; } Cliente obj = ClienteBLL.GetClienteById(clienteId); if (obj == null) { return; } if (e.CommandName == "Eliminar") { try { ClienteBLL.DeleteCliente(clienteId); Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "ShowMensaje('success', 'Eliminación Exitosa.')", true); CargarClientes(Convert.ToInt32(VistaHD.Value)); } catch (Exception ex) { Console.Write(ex.Message); throw new Exception("Error al eliminar"); } } if (e.CommandName == "Editar") { Session["CLIENTE_ID"] = clienteId.ToString(); Response.Redirect("FormCliente.aspx"); } }
public void tipoBotonClic(DataGridViewCellEventArgs e) { //si el click es en el boton actualizar if (e.RowIndex >= 0) { if (e.ColumnIndex == btnUpdate.Index) { frmInsertarPersonas frm = new frmInsertarPersonas(); frm.MdiParent = this.MdiParent; frm.WindowState = FormWindowState.Maximized; frm.Show(); frm.BoxTipoPersona.SelectedItem = "Cliente"; frm.BoxTipoPersona.Enabled = false; frm.TipoInsercion = 1; frm.TxtFkPersonas.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[0].Value); frm.TxtFkGlobal.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[1].Value); frm.TxtNit.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[2].Value); frm.TxtNombre.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[3].Value); frm.TxtDireccion.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[4].Value); frm.TxtTelefono.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[5].Value); frm.TxtCelular.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[6].Value); frm.TxtCorreo.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[7].Value); frm.BoxTipoCliente.Text = Convert.ToString(tblClientes.Rows[e.RowIndex].Cells[8].Value); this.Dispose(); } //si el click es en el boton eliminar if (e.ColumnIndex == btnEliminar.Index) { if (MessageBox.Show("Esta seguro de eliminar este registro?", "Eliminar Registro", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (MessageBox.Show("Esta totalmente seguro?", "Eliminar Registro", MessageBoxButtons.YesNo) == DialogResult.Yes) { int codigo = Convert.ToInt32(tblClientes.Rows[e.RowIndex].Cells[0].Value); ClienteBLL.DeleteCliente(codigo); MessageBox.Show("Registro eliminado"); this.cargarDatosClientes(); } } } } }