feat: add format=jpgEnc support (filename from rpt_CertificatesChartsAlias SP)
This commit is contained in:
@@ -112,8 +112,10 @@ public class ChartController : ControllerBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isJpeg = format.Equals("jpg", StringComparison.OrdinalIgnoreCase)
|
bool isJpegEnc = format.Equals("jpgEnc", StringComparison.OrdinalIgnoreCase);
|
||||||
|| format.Equals("jpeg", StringComparison.OrdinalIgnoreCase);
|
bool isJpeg = isJpegEnc
|
||||||
|
|| format.Equals("jpg", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| format.Equals("jpeg", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
byte[] imgBytes = SkiaChartRendererV2.RenderToPng(chartData, width, height, jpeg: isJpeg);
|
byte[] imgBytes = SkiaChartRendererV2.RenderToPng(chartData, width, height, jpeg: isJpeg);
|
||||||
|
|
||||||
@@ -124,6 +126,15 @@ public class ChartController : ControllerBase
|
|||||||
return File(pdfBytes, "application/pdf");
|
return File(pdfBytes, "application/pdf");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isJpegEnc)
|
||||||
|
{
|
||||||
|
// Nome file codificato da SP rpt_CertificatesChartsAlias (come vecchio jpgEnc DevExpress)
|
||||||
|
string? alias = await _chartDataServiceV2.GetChartAliasAsync(isin);
|
||||||
|
string fileName = string.IsNullOrEmpty(alias) ? $"chart_v2_{isin}" : alias;
|
||||||
|
Response.Headers.Append("Content-Disposition", $"inline; filename={fileName}.jpg");
|
||||||
|
return File(imgBytes, "image/jpeg");
|
||||||
|
}
|
||||||
|
|
||||||
if (isJpeg)
|
if (isJpeg)
|
||||||
{
|
{
|
||||||
Response.Headers.Append("Content-Disposition", $"inline; filename=chart_v2_{isin}.jpg");
|
Response.Headers.Append("Content-Disposition", $"inline; filename=chart_v2_{isin}.jpg");
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ namespace CertReports.Syncfusion.Services.Implementations;
|
|||||||
public interface IChartDataServiceV2
|
public interface IChartDataServiceV2
|
||||||
{
|
{
|
||||||
Task<ChartDataV2?> GetChartDataV2Async(string isin);
|
Task<ChartDataV2?> GetChartDataV2Async(string isin);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ritorna l'AliasID codificato per il grafico (SP rpt_CertificatesChartsAlias).
|
||||||
|
/// Usato dal formato jpgEnc per impostare il nome file nella risposta HTTP.
|
||||||
|
/// </summary>
|
||||||
|
Task<string?> GetChartAliasAsync(string isin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ChartDataServiceV2 : IChartDataServiceV2
|
public class ChartDataServiceV2 : IChartDataServiceV2
|
||||||
@@ -104,6 +110,19 @@ public class ChartDataServiceV2 : IChartDataServiceV2
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<string?> GetChartAliasAsync(string isin)
|
||||||
|
{
|
||||||
|
await using var conn = new SqlConnection(_connectionString);
|
||||||
|
await conn.OpenAsync();
|
||||||
|
|
||||||
|
await using var cmd = new SqlCommand("rpt_CertificatesChartsAlias", conn)
|
||||||
|
{ CommandType = CommandType.StoredProcedure };
|
||||||
|
cmd.Parameters.AddWithValue("@isin", isin);
|
||||||
|
|
||||||
|
var result = await cmd.ExecuteScalarAsync();
|
||||||
|
return result == null || result == DBNull.Value ? null : result.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Legge un campo numerico come decimal indipendentemente dal tipo SQL
|
/// Legge un campo numerico come decimal indipendentemente dal tipo SQL
|
||||||
/// (decimal, float, real, int). Necessario perché cedlab_Chart_UL1 ritorna
|
/// (decimal, float, real, int). Necessario perché cedlab_Chart_UL1 ritorna
|
||||||
|
|||||||
Reference in New Issue
Block a user