private void LlenarTabla(string Busqueda) { using (var context = new PARKING_DBEntities(CadenaConexion)) { var listabusqueda = (from cl in context.cliente join vh in context.vehiculo on cl.Id_Vehiculo equals vh.Id_Vehiculo select new Modelos.ModeloBusquedaCliente { ID = cl.Id_cliente, Nombre = cl.Nombre + " " + cl.Apellido_paterno + " " + cl.Apellido_materno, Direccion = cl.Direccion, Tel1 = cl.Tel1, CantidadPensiones = (from bp in context.banco_pension where (bp.Id_cliente == cl.Id_cliente) select bp.ID).Count(), RFC = cl.RFC, Placa = vh.Placa }).AsQueryable(); switch (Busqueda) { case "Nombre": listabusqueda = listabusqueda.Where(f => f.Nombre.Contains(txtNombre.Text.Trim())); dataGridView.DataSource = listabusqueda.ToList(); break; case "Todo": dataGridView.DataSource = listabusqueda.ToList(); break; } } }
private void btnEliminar_Click(object sender, EventArgs e) { int?id = GetID(); if (id != null) { DialogResult resultado = MessageBox.Show("¿Desea eliminar el Cliente con el id: " + id.ToString() + "? \n Este Cambio es irreversible todos los datos relacionados al cliente serán eliminados", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (resultado == DialogResult.Yes) { using (var context = new PARKING_DBEntities(CadenaConexion)) { var a = context.banco_pension.Where(n => n.Id_cliente == id); context.banco_pension.RemoveRange(a); var b = context.cliente.Where(n => n.Id_cliente == id); var tcliente = b.ToList().LastOrDefault(); var idvh = tcliente.Id_Vehiculo; context.cliente.RemoveRange(b); var c = context.vehiculo.Where(n => n.Id_Vehiculo == idvh).FirstOrDefault(); context.vehiculo.Remove(c); context.SaveChanges(); } LlenarTabla("Todas"); } } }