Testato esportazione in html

Test degli spunti ottenuti da una chat con Gemini.
- [ ] Test della classe cRac.cs
- [ ] Test della funzione di salvataggio sul DB
- [ ] Test della funzione di lettura dal DB
- [ ] Test della funzione di ricerca nel DB
- [ ] Test funzione di cancellazione nel DB
- [ ] Test nella ricerca di duplicati
- [X] Test della funzione di esportazione in html con stile

Riepilogo della chat:
- connesso a gemini con chrome e utente mirko
- dato in pasto il file *ATDB Database Schema.sql* con la struttura del DB
- richiesto la classe cRac per rappresentare un racconto.
- ottenuto *cRac.cs*
- richiesto come salvare un cRac sul DB con diagnostica errori ed evitando spurie sul DB
- ottenuto *Salvataggio cRac su DB.cs*
- richiesto come leggere un racconto
- ottenuto *GetRaccontoById.cs*
- richiesto: ragruppiamo le funzioni di helper su un file Helper.cs e quelle di lettura/scrittura sul DB sul file DB.cs
- ottenuto *Helper.cs* e *DB.cs*
- richiesto: facciamo le ricerche avanzate per titolo, tag, autore, data di creazione, sorgente
- ottenuta la nuova versione di *Aggiornamento 1 di DB.cs*
- richiesto come eliminare un racconto dal DB
- ottenuta la nuova versione di *Aggiornamento 2 di DB.cs*
- richiesto: come ricercare racconti duplicati
- ottenuto spunti di ricerca salvati in *Ricerca duplicati.cs*
- richiesto come fare il merge di racconti duplicati
- ottenuto *merge.cs*
- richiesto delle idee per la UI
- ottenuto il file *UI_idee.md*
- richiesto un esempio di esportazione di un racconto in html con stile
- ottenuto: *export.cs*
This commit is contained in:
CSiCoAlm committed 2025-12-28 13:52:05 +01:00
1 parent d748536041
commit 1cc4528295
4 files changed
+130 -2

No files matched your search

+97
View File
@@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace A69WD.Data { namespace A69WD.Data {
@@ -825,6 +827,101 @@ namespace A69WD.Data {
} }
} }
public static string EsportaInHtml(cRac racconto, string cartellaDestinazione) {
// Crea il nome del file pulendo il titolo da caratteri non validi
string nomeFile = string.Join("_", racconto.Title.Split(Path.GetInvalidFileNameChars()));
string pathCompleto = Path.Combine(cartellaDestinazione, $"{racconto.strIDrac}_{nomeFile}.html");
StringBuilder sb = new StringBuilder();
try {
// Inizio Documento HTML
sb.AppendLine("<!DOCTYPE html>");
sb.AppendLine("<html lang='it'>");
sb.AppendLine("<head>");
sb.AppendLine(" <meta charset='UTF-8'>");
sb.AppendLine($" <title>{racconto.Title}</title>");
// CSS Incorporato per uno stile elegante (Bookish Style)
sb.AppendLine(" <style>");
sb.AppendLine(" body { font-family: 'Georgia', serif; line-height: 1.6; color: #333; max-width: 800px; margin: 40px auto; padding: 20px; background-color: #f4f1ea; }");
sb.AppendLine(" .container { background: white; padding: 50px; box-shadow: 0 0 10px rgba(0,0,0,0.1); border-radius: 5px; }");
sb.AppendLine(" h1 { color: #2c3e50; text-align: center; margin-bottom: 5px; font-variant: small-caps; }");
sb.AppendLine(" .subtitle { text-align: center; font-style: italic; color: #7f8c8d; margin-bottom: 30px; }");
sb.AppendLine(" .metadata { border-top: 1px solid #eee; border-bottom: 1px solid #eee; padding: 15px 0; margin-bottom: 30px; font-size: 0.9em; display: flex; flex-wrap: wrap; gap: 20px; }");
sb.AppendLine(" .meta-item { color: #555; }");
sb.AppendLine(" .meta-label { font-weight: bold; color: #2c3e50; }");
sb.AppendLine(" .trama { white-space: pre-wrap; text-align: justify; font-size: 1.1em; }");
sb.AppendLine(" .tags { margin-top: 40px; }");
sb.AppendLine(" .tag { background: #e0e0e0; padding: 3px 10px; border-radius: 15px; font-size: 0.8em; margin-right: 5px; display: inline-block; }");
sb.AppendLine(" .footer { margin-top: 50px; font-size: 0.8em; text-align: center; color: #bdc3c7; border-top: 1px solid #eee; padding-top: 10px; }");
sb.AppendLine(" @media print { body { background: white; } .container { box-shadow: none; } }");
sb.AppendLine(" </style>");
sb.AppendLine("</head>");
sb.AppendLine("<body>");
sb.AppendLine(" <div class='container'>");
// Intestazione
sb.AppendLine($" <h1>{racconto.Title}</h1>");
if (!string.IsNullOrEmpty(racconto.SubTitle))
sb.AppendLine($" <p class='subtitle'>{racconto.SubTitle}</p>");
// Metadata (Autori, Voto, Origini)
sb.AppendLine(" <div class='metadata'>");
sb.AppendLine($" <div class='meta-item'><span class='meta-label'>Autore:</span> {string.Join(", ", racconto.Autori)}</div>");
sb.AppendLine($" <div class='meta-item'><span class='meta-label'>Data:</span> {racconto.Creato}</div>");
sb.AppendLine($" <div class='meta-item'><span class='meta-label'>Voto:</span> {racconto.Voto})</div>");
if (racconto.Origini.Any())
sb.AppendLine($" <div class='meta-item'><span class='meta-label'>Sorgente:</span> {string.Join(", ", racconto.Origini)}</div>");
sb.AppendLine(" </div>");
// Corpo del racconto (Trama)
sb.AppendLine(" <div class='trama'>");
sb.AppendLine(racconto.Trama); // Preserva i ritorni a capo grazie a white-space: pre-wrap
sb.AppendLine(" </div>");
// Note (se presenti)
if (racconto.Notes.Any()) {
sb.AppendLine(" <div style='margin-top: 30px; padding: 15px; background: #f9f9f9; border-left: 5px solid #2c3e50;'>");
sb.AppendLine(" <h3 style='margin-top:0;'>Note</h3>");
foreach (var nota in racconto.Notes)
sb.AppendLine($" <p><strong>{nota.Key}:</strong> {nota.Description}</p>");
sb.AppendLine(" </div>");
}
// Tags
if (racconto.Tags.Any()) {
sb.AppendLine(" <div class='tags'>");
racconto.Tags.Sort();
//foreach (var tag in racconto.Tags)
// sb.AppendLine($" <span class='tag'>#{tag}</span>");
racconto.Tags.ForEach(t => sb.AppendLine($" <span class='tag'>#{t}</span>"));
sb.AppendLine(" </div>");
}
// Footer
sb.AppendLine(" <div class='footer'>");
sb.AppendLine($" Esportato da ATDB Collection - {DateTime.Now:dd/MM/yyyy HH:mm}");
sb.AppendLine(" </div>");
sb.AppendLine(" </div>"); // Fine container
sb.AppendLine("</body>");
sb.AppendLine("</html>");
// Scrittura su file
File.WriteAllText(pathCompleto, sb.ToString());
} catch (Exception ex) { Logger.Error("A69 Export - " + ex.Message); }
return pathCompleto;
}
} // class cRac } // class cRac
}//namespace A69WD.Data }//namespace A69WD.Data
+2 -2
View File
@@ -83,8 +83,8 @@ namespace A69WD.Service {
if (rac != null) { if (rac != null) {
// Racconto estratto correttamente, lo salvo sul DB // Racconto estratto correttamente, lo salvo sul DB
Logger.Warning($"Import - estrazione corretta: {name}"); Logger.Warning($"Import - estrazione corretta: {name}");
int res = App.DB.ImportRac(rac); int res = App.DB.ImportRac(rac); // res=id del racconto nel DB
if (res != 1) { if (res < 1) {
// errore nel salvataggio // errore nel salvataggio
Logger.Warning($"Import - errore nel salvataggio: {name}"); Logger.Warning($"Import - errore nel salvataggio: {name}");
Interlocked.Increment(ref _errori); Interlocked.Increment(ref _errori);
+13
View File
@@ -31,6 +31,7 @@
this.btnShowLog = new System.Windows.Forms.Button(); this.btnShowLog = new System.Windows.Forms.Button();
this.pbST = new System.Windows.Forms.ProgressBar(); this.pbST = new System.Windows.Forms.ProgressBar();
this.btnImport = new System.Windows.Forms.Button(); this.btnImport = new System.Windows.Forms.Button();
this.btnTest = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// btnClose // btnClose
@@ -108,11 +109,22 @@
this.btnImport.UseVisualStyleBackColor = true; this.btnImport.UseVisualStyleBackColor = true;
this.btnImport.Click += new System.EventHandler(this.btnImport_Click); this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
// //
// btnTest
//
this.btnTest.Location = new System.Drawing.Point(121, -1);
this.btnTest.Name = "btnTest";
this.btnTest.Size = new System.Drawing.Size(55, 33);
this.btnTest.TabIndex = 20;
this.btnTest.Text = "Test";
this.btnTest.UseVisualStyleBackColor = true;
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
//
// frmDownloader // frmDownloader
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(433, 95); this.ClientSize = new System.Drawing.Size(433, 95);
this.Controls.Add(this.btnTest);
this.Controls.Add(this.btnImport); this.Controls.Add(this.btnImport);
this.Controls.Add(this.pbST); this.Controls.Add(this.pbST);
this.Controls.Add(this.btnShowLog); this.Controls.Add(this.btnShowLog);
@@ -136,5 +148,6 @@
private System.Windows.Forms.Button btnShowLog; private System.Windows.Forms.Button btnShowLog;
private System.Windows.Forms.ProgressBar pbST; private System.Windows.Forms.ProgressBar pbST;
private System.Windows.Forms.Button btnImport; private System.Windows.Forms.Button btnImport;
private System.Windows.Forms.Button btnTest;
} }
} }
+18
View File
@@ -183,6 +183,24 @@ namespace A69WD {
} }
private Service_Importer serviceImporter = null; private Service_Importer serviceImporter = null;
private void btnTest_Click(object sender, EventArgs e) {
int MaxRac = 60;
pbST.Maximum = MaxRac;
pbST.Minimum = 0;
pbST.Value = 0;
lblST.Text = "Inizio esportazione racconti";
for (int i = 0; i < 61; i++) {
cRac rac = App.DB.GetRacById(i);
cRac.EsportaInHtml(rac, Cfg.Settings.PathDownloadWorking);
pbST.Value = i;
lblST.Text = $"Esportato racconto ID={rac.strIDrac}";
}
lblST.Text = $"Fine esportazione {MaxRac.ToString("000")} racconti";
}
}//class frmDownloader }//class frmDownloader