private void Button_Click(object sender, RoutedEventArgs e) { BCategoria Bcategoria = null; bool result = true; try { Bcategoria = new BCategoria(); if (ID > 0) { result = Bcategoria.Actualizar(new Categoria { IdCategoria = ID, NombreCategoria = txtNombre.Text, Descripcion = txtDescripcion.Text }); } else { result = Bcategoria.Insertar(new Categoria { IdCategoria = Bcategoria.GetMaxId(ID), NombreCategoria = txtNombre.Text, Descripcion = txtDescripcion.Text }); } if (!result) { MessageBox.Show("Comunicarse con el administrador " + Bcategoria.GetMaxId(ID)); } Close(); } catch (Exception ex) { MessageBox.Show("Comunicarse con el administrador " + ex); } finally { Bcategoria = null; } }