|
|
@ -8,14 +8,19 @@ import com.vaadin.flow.component.html.H5; |
|
|
|
import com.vaadin.flow.component.icon.Icon; |
|
|
|
import com.vaadin.flow.component.icon.VaadinIcon; |
|
|
|
import com.vaadin.flow.component.notification.Notification; |
|
|
|
import com.vaadin.flow.component.notification.NotificationVariant; |
|
|
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; |
|
|
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
|
|
|
import com.vaadin.flow.component.textfield.TextField; |
|
|
|
import com.vaadin.flow.component.upload.Upload; |
|
|
|
import com.vaadin.flow.component.upload.receivers.MemoryBuffer; |
|
|
|
import com.vaadin.flow.router.PageTitle; |
|
|
|
import com.vaadin.flow.router.Route; |
|
|
|
import jakarta.annotation.security.PermitAll; |
|
|
|
import mx.gob.jumapacelaya.models.PlanAnual; |
|
|
|
import mx.gob.jumapacelaya.services.DatabaseService; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.lang.reflect.Array; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.util.Arrays; |
|
|
@ -30,6 +35,7 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
HorizontalLayout header = new HorizontalLayout(); |
|
|
|
H4 titulo = new H4(); |
|
|
|
H5 titulo1 = new H5(); |
|
|
|
DatabaseService databaseService = new DatabaseService(); |
|
|
|
|
|
|
|
public PlanAnualView() { |
|
|
|
VerticalLayout headerLayout = new VerticalLayout(); |
|
|
@ -50,6 +56,25 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
headerLayout.add(titulo, titulo1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Componente UPLOAD para subir archivos |
|
|
|
MemoryBuffer buffer = new MemoryBuffer(); |
|
|
|
Upload upload = new Upload(buffer); |
|
|
|
upload.setAcceptedFileTypes(".xls", ".xlsx"); |
|
|
|
upload.setMaxFiles(1); |
|
|
|
upload.setDropLabel(new com.vaadin.flow.component.html.Span("Arrastra un archivo Excel aquí o selecciona uno")); |
|
|
|
|
|
|
|
upload.addSucceededListener(event -> { |
|
|
|
try { |
|
|
|
InputStream inputStream = buffer.getInputStream(); |
|
|
|
databaseService.insertarDesdeExcel(inputStream); |
|
|
|
Notification.show("Archivo insertado correctamente").addThemeVariants(NotificationVariant.LUMO_SUCCESS); |
|
|
|
} catch (Exception e) { |
|
|
|
Notification.show("Error al insertar el archivo: " + e.getMessage()).addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Grid<PlanAnual> planAnualGrid = new Grid<>(); |
|
|
|
planAnualGrid.addColumn(PlanAnual::getNumero).setHeader("No."); |
|
|
|
planAnualGrid.addColumn(PlanAnual::getNomEquipo).setHeader("Equipo").setAutoWidth(true); |
|
|
@ -100,7 +125,7 @@ public class PlanAnualView extends VerticalLayout { |
|
|
|
this.setPadding(false); |
|
|
|
this.setMargin(false); |
|
|
|
this.setSpacing(false); |
|
|
|
add(headerLayout, gridLayout); |
|
|
|
add(headerLayout, gridLayout, upload); |
|
|
|
} |
|
|
|
|
|
|
|
private Icon getIcon(String value) { |
|
|
|