Files
lux/Lux.Report.Manager/Components/Compo/RepoFileList.razor.cs
T
2026-04-08 17:53:28 +02:00

101 lines
3.0 KiB
C#

using DevExpress.XtraRichEdit.Import.OpenXml;
using Lux.Report.Data.DbModel;
using Lux.Report.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Lux.Report.Manager.Components.Compo
{
public partial class RepoFileList
{
#region Public Properties
[Parameter]
public ReportModel CurrReport { get; set; } = null!;
[Parameter]
public EventCallback<string> EC_ReqEdit { get; set; }
[Parameter]
public EventCallback<bool> EC_ReqUpdate { get; set; }
#endregion Public Properties
#region Protected Methods
protected override void OnParametersSet()
{
ReloadData();
}
private void ReloadData()
{
//base.OnParametersSet();
string repPath = Path.Combine("reports", CurrReport.Name);
// elenco file esclusi quelli nascosti (template)
ListReports = FService.ListFile(repPath, "*.repx", true);
}
#endregion Protected Methods
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
/// <summary>
/// Creazione nuovo report duplicando il file template
/// </summary>
private async Task DoAddNew()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler creare un nuovo modello report di tipo {CurrReport.Name} ?"))
return;
string tplPathFrom = Path.Combine("reports", CurrReport.Name, ".template.repx");
// se esiste lo duplica
if (FService.FileExists(tplPathFrom))
{
string newName = $"{CurrReport.Name}_{DateTime.Now:yyyyMMdd-HHmmss}.repx";
string tplPathTo = Path.Combine("reports", CurrReport.Name, newName);
FService.FileCopy(tplPathFrom, tplPathTo);
ReloadData();
await EC_ReqUpdate.InvokeAsync(true);
}
}
/// <summary>
/// Creazione nuovo report duplicando il file template
/// </summary>
private async Task DoDelete(string item)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler eliminare il report {item} ?"))
return;
string fullPath = Path.Combine("reports", CurrReport.Name, item);
FService.FileDelete(fullPath);
ReloadData();
await EC_ReqUpdate.InvokeAsync(true);
}
#region Private Fields
private List<string> ListReports = new List<string>();
#endregion Private Fields
protected string FileName(string fullName)
{
return Path.GetFileName(fullName);
}
private async Task ReqEdit(string fullPath)
{
await EC_ReqEdit.InvokeAsync(fullPath);
}
#region Private Properties
[Inject]
private IFileService FService { get; set; } = null!;
#endregion Private Properties
}
}