@page "/database-schema" @using DataConnection.Interfaces @using DataConnection.Enums @inject Data.DatabaseConnectionService DatabaseService @inject IJSRuntime JSRuntime @inject NavigationManager NavigationManager Schema del Database

Schema del Database

@if (!DatabaseService.IsConnected || string.IsNullOrEmpty(DatabaseService.SelectedDatabase)) {

Non sei connesso a nessun database. Devi prima stabilire una connessione.

} else {
Dettagli del Database: @DatabaseService.SelectedDatabase
@if (databaseInfo != null) {
Nome: @databaseInfo.Name
Dimensione: @databaseInfo.SizeMB.ToString("N2") MB
Creato il: @databaseInfo.CreationDate.ToString("dd/MM/yyyy HH:mm")
Stato: @databaseInfo.Status
}
Tabelle
@if (schemaInfo != null && schemaInfo.Count > 0) { @foreach (var table in filteredTables) { } } else if (isLoading) {
Caricamento...
} else {
Nessuna tabella disponibile
}
@if (!string.IsNullOrEmpty(selectedTable)) { Struttura della tabella: @selectedTable } else { Seleziona una tabella }
@if (!string.IsNullOrEmpty(selectedTable) && schemaInfo != null && schemaInfo.ContainsKey(selectedTable)) {
@foreach (var column in schemaInfo[selectedTable]) { }
Nome Colonna Tipo Dati Nullable Chiave Relazioni
@column.Name @column.DataType @if (column.IsNullable) { NULL } else { NOT NULL } @if (column.IsPrimaryKey) { PK } @if (column.IsForeignKey) { FK → @column.ReferencedTable.@column.ReferencedColumn }
} else if (string.IsNullOrEmpty(selectedTable)) {
Seleziona una tabella dal menu a sinistra per visualizzarne la struttura.
} else if (isLoading) {
Caricamento...
} else {
Impossibile trovare informazioni sulla tabella selezionata.
}
} @code { private bool isLoading = false; private string selectedTable = ""; private string tableFilter = ""; private DatabaseInfo databaseInfo; private IDictionary> schemaInfo; private IDictionary> filteredTables; protected override async Task OnInitializedAsync() { if (DatabaseService.IsConnected && !string.IsNullOrEmpty(DatabaseService.SelectedDatabase)) { await LoadDatabaseSchema(); } } private async Task LoadDatabaseSchema() { try { isLoading = true; selectedTable = ""; // Ottieni informazioni sul database selezionato if (DatabaseService.DatabasesInfo.TryGetValue(DatabaseService.SelectedDatabase, out var dbInfo)) { databaseInfo = dbInfo; } // Crea il database manager e connettiti al database selezionato var databaseManager = DatabaseService.GetDatabaseManager(); // Verifica la connessione al database specifico if (await databaseManager.TestConnectionAsync()) { // Recupera le informazioni sullo schema (tabelle e colonne) schemaInfo = await databaseManager.GetDatabaseSchemaAsync(); filteredTables = schemaInfo; } else { throw new Exception($"Non è possibile connettersi al database {DatabaseService.SelectedDatabase}"); } } catch (Exception ex) { await JSRuntime.InvokeVoidAsync("console.error", "Errore caricamento schema:", ex.Message); //DatabaseService.ErrorMessage = $"Errore nel caricamento dello schema: {ex.Message}"; schemaInfo = null; } finally { isLoading = false; } } private void SelectTable(string tableName) { selectedTable = tableName; } private void FilterTables(ChangeEventArgs e) { tableFilter = e.Value?.ToString() ?? ""; if (string.IsNullOrWhiteSpace(tableFilter)) { filteredTables = schemaInfo; } else { filteredTables = schemaInfo .Where(t => t.Key.Contains(tableFilter, StringComparison.OrdinalIgnoreCase)) .ToDictionary(t => t.Key, t => t.Value); } } private async Task RefreshSchema() { await LoadDatabaseSchema(); } private void NavigateToConnection() { NavigationManager.NavigateTo("/database-connection"); } }