commit cliente importazioni provicnie comuni
This commit is contained in:
13
TecniStamp/TecniStamp.Service/ComuneIstatService.cs
Normal file
13
TecniStamp/TecniStamp.Service/ComuneIstatService.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using OAService.Service.Servizi.Implementazioni;
|
||||||
|
using TecniStamp.Domain;
|
||||||
|
using TecniStamp.Service.Interfaces;
|
||||||
|
using TecniStamp.Service.Repository;
|
||||||
|
|
||||||
|
namespace TecniStamp.Service;
|
||||||
|
|
||||||
|
public class ComuneIstatService : TService<ComuneIstat>, IComuneIstatService
|
||||||
|
{
|
||||||
|
public ComuneIstatService(ITecniStampUnitOfWork unitOfWork) : base(unitOfWork)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
using OAService.Service.Servizi.Interfacce;
|
||||||
|
using TecniStamp.Domain;
|
||||||
|
|
||||||
|
namespace TecniStamp.Service.Interfaces;
|
||||||
|
|
||||||
|
public interface IComuneIstatService : ITService<ComuneIstat>
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -13,4 +13,6 @@ public interface IManagerService
|
|||||||
IUserService UtenteService { get; set; }
|
IUserService UtenteService { get; set; }
|
||||||
IMacchinarioService MacchinarioService { get; set; }
|
IMacchinarioService MacchinarioService { get; set; }
|
||||||
ILavorazioneService LavorazioneService { get; set; }
|
ILavorazioneService LavorazioneService { get; set; }
|
||||||
|
IComuneIstatService ComuneIstatService { get; set; }
|
||||||
|
IProvinciaIstatService ProvinciaIstatService { get; set; }
|
||||||
}
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
using OAService.Service.Servizi.Interfacce;
|
||||||
|
using TecniStamp.Domain;
|
||||||
|
|
||||||
|
namespace TecniStamp.Service.Interfaces;
|
||||||
|
|
||||||
|
public interface IProvinciaIstatService : ITService<ProvinciaIstat> {}
|
||||||
@ -6,7 +6,8 @@ public class ManagerService : IManagerService
|
|||||||
{
|
{
|
||||||
public ManagerService(IUserService userService, ISezioneService sezioneService, IPermissionService permissionService, IRuoloService ruoloService,
|
public ManagerService(IUserService userService, ISezioneService sezioneService, IPermissionService permissionService, IRuoloService ruoloService,
|
||||||
IFeatureService featureService, IMacchinarioService macchinarioService, ICommessaService commessaService, ILavorazioneService lavorazioneService,
|
IFeatureService featureService, IMacchinarioService macchinarioService, ICommessaService commessaService, ILavorazioneService lavorazioneService,
|
||||||
IClienteService clienteService, ICommessaPosizioneService commessaPosizioneService, ICommessaPosizioneLavorazioneService commessaPosizioneLavorazioneService)
|
IClienteService clienteService, ICommessaPosizioneService commessaPosizioneService, ICommessaPosizioneLavorazioneService commessaPosizioneLavorazioneService,
|
||||||
|
IComuneIstatService comuneIstatService, IProvinciaIstatService provinciaIstatService)
|
||||||
{
|
{
|
||||||
UtenteService = userService;
|
UtenteService = userService;
|
||||||
SezioneService = sezioneService;
|
SezioneService = sezioneService;
|
||||||
@ -19,6 +20,8 @@ public class ManagerService : IManagerService
|
|||||||
ClienteService = clienteService;
|
ClienteService = clienteService;
|
||||||
CommessaPosizioneService = commessaPosizioneService;
|
CommessaPosizioneService = commessaPosizioneService;
|
||||||
CommessaPosizioneLavorazioneService = commessaPosizioneLavorazioneService;
|
CommessaPosizioneLavorazioneService = commessaPosizioneLavorazioneService;
|
||||||
|
ComuneIstatService = comuneIstatService;
|
||||||
|
ProvinciaIstatService = provinciaIstatService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IClienteService ClienteService { get; set; }
|
public IClienteService ClienteService { get; set; }
|
||||||
@ -32,4 +35,6 @@ public class ManagerService : IManagerService
|
|||||||
public IUserService UtenteService { get; set; }
|
public IUserService UtenteService { get; set; }
|
||||||
public IMacchinarioService MacchinarioService { get; set; }
|
public IMacchinarioService MacchinarioService { get; set; }
|
||||||
public ILavorazioneService LavorazioneService { get; set; }
|
public ILavorazioneService LavorazioneService { get; set; }
|
||||||
|
public IComuneIstatService ComuneIstatService { get; set; }
|
||||||
|
public IProvinciaIstatService ProvinciaIstatService { get; set; }
|
||||||
}
|
}
|
||||||
14
TecniStamp/TecniStamp.Service/ProvinciaIstatService.cs
Normal file
14
TecniStamp/TecniStamp.Service/ProvinciaIstatService.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using OAService.Service.Servizi.Implementazioni;
|
||||||
|
using TecniStamp.Domain;
|
||||||
|
using TecniStamp.Service.Interfaces;
|
||||||
|
using TecniStamp.Service.Repository;
|
||||||
|
|
||||||
|
namespace StandManager.Service;
|
||||||
|
|
||||||
|
public class ProvinciaIstatService : TService<ProvinciaIstat>, IProvinciaIstatService
|
||||||
|
{
|
||||||
|
public ProvinciaIstatService(ITecniStampUnitOfWork unitOfWork) : base(unitOfWork)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,6 +17,10 @@
|
|||||||
<div class="row row-cards">
|
<div class="row row-cards">
|
||||||
<div class="col-auto ms-auto">
|
<div class="col-auto ms-auto">
|
||||||
<div class="btn-list">
|
<div class="btn-list">
|
||||||
|
<RadzenUpload class="btn-5 d-none d-sm-inline-block" Change=@onUploadComuni ChooseText="Importa comuni da excel" />
|
||||||
|
|
||||||
|
<RadzenUpload class="btn-5 d-none d-sm-inline-block" Change=@onUploadProvince ChooseText="Importa province da excel" />
|
||||||
|
|
||||||
<a href="/Anagrafiche/Clienti/Modifica" class="btn btn-primary btn-5 d-none d-sm-inline-block">
|
<a href="/Anagrafiche/Clienti/Modifica" class="btn btn-primary btn-5 d-none d-sm-inline-block">
|
||||||
Nuovo Cliente
|
Nuovo Cliente
|
||||||
</a>
|
</a>
|
||||||
@ -95,4 +99,46 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task onUploadComuni(UploadChangeEventArgs args)
|
||||||
|
{
|
||||||
|
var file = args.Files.FirstOrDefault();
|
||||||
|
if (file == null ||
|
||||||
|
!file.Name.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
await _dialogService.Alert("Sono supportati solo file Excel .xlsx", "Errore");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// await using var uploadStream = file.OpenReadStream(10_000_000);
|
||||||
|
await _dialogService.OpenAsync<Comuni_Import>("Importazione comuni", new Dictionary<string, object>() { { "args", args } });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var er = ex.Message;
|
||||||
|
await _dialogService.Alert("Si è verificato un errore durante l'importazione del file.", "Errore");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task onUploadProvince(UploadChangeEventArgs args)
|
||||||
|
{
|
||||||
|
var file = args.Files.FirstOrDefault();
|
||||||
|
if (file == null ||
|
||||||
|
!file.Name.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
await _dialogService.Alert("Sono supportati solo file Excel .xlsx", "Errore");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// await using var uploadStream = file.OpenReadStream(10_000_000);
|
||||||
|
await _dialogService.OpenAsync<Province_Import>("Importazione province", new Dictionary<string, object>() { { "args", args } });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var er = ex.Message;
|
||||||
|
await _dialogService.Alert("Si è verificato un errore durante l'importazione del file.", "Errore");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
@using ClosedXML.Excel
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using TecniStamp.Model
|
||||||
|
@using TecniStamp.Domain
|
||||||
|
@using TecniStamp.Utils
|
||||||
|
@attribute [Authorize]
|
||||||
|
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
|
@inject AuthenticationStateProvider auth
|
||||||
|
|
||||||
|
<RadzenStack Gap="1rem" class="rz-m-12">
|
||||||
|
<RadzenProgressBar Value="@counter" Max="@comuniTotali" Unit="@counterLabel" AriaLabel="" />
|
||||||
|
</RadzenStack>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[CascadingParameter] private Dialog _dialog { get; set; }
|
||||||
|
[Parameter] public UploadChangeEventArgs args { get; set; }
|
||||||
|
|
||||||
|
private int comuniTotali { get; set; } = 0;
|
||||||
|
private int counter { get; set; } = 0;
|
||||||
|
private string counterLabel { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
base.OnInitializedAsync();
|
||||||
|
var file = args.Files.FirstOrDefault();
|
||||||
|
await using var uploadStream = file.OpenReadStream(10_000_000);
|
||||||
|
var idClaim = await MembershipUtils.GetUserId(auth);
|
||||||
|
|
||||||
|
await using var ms = new MemoryStream();
|
||||||
|
await uploadStream.CopyToAsync(ms);
|
||||||
|
ms.Position = 0;
|
||||||
|
|
||||||
|
using var workbook = new XLWorkbook(ms);
|
||||||
|
var ws = workbook.Worksheet(1);
|
||||||
|
var usedRange = ws.RangeUsed();
|
||||||
|
var rows = new List<ComuneIstatExcelViewModel>(usedRange.RowCount() - 1);
|
||||||
|
|
||||||
|
foreach (var row in usedRange.RowsUsed().Skip(1))
|
||||||
|
rows.Add(new ComuneIstatExcelViewModel(row));
|
||||||
|
|
||||||
|
|
||||||
|
var comuni = rows.ToList();
|
||||||
|
comuniTotali = comuni.Count;
|
||||||
|
counterLabel = " di " + comuniTotali;
|
||||||
|
|
||||||
|
foreach (var comune in comuni)
|
||||||
|
{
|
||||||
|
var comuneDb = await _managerService.ComuneIstatService.RicercaPer(
|
||||||
|
x => x.Istat == comune.Istat && x.Eliminato == false,
|
||||||
|
solaLettura: false) ?? new ComuneIstat();
|
||||||
|
|
||||||
|
comuneDb = await mapComune(comuneDb, comune);
|
||||||
|
await _managerService.ComuneIstatService.Salva(comuneDb, idClaim);
|
||||||
|
counter += 1;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
ms.Close();
|
||||||
|
_dialogService.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ComuneIstat> mapComune(ComuneIstat model, ComuneIstatExcelViewModel row)
|
||||||
|
{
|
||||||
|
model.Istat = row.Istat;
|
||||||
|
model.Comune = row.Comune;
|
||||||
|
model.Regione = row.Regione;
|
||||||
|
model.Provincia = row.Provincia;
|
||||||
|
model.Prefisso = row.Prefisso;
|
||||||
|
model.CodFisco = row.CodFisco;
|
||||||
|
model.ProvinciaIstatId = (await _managerService.ProvinciaIstatService.RicercaPer(filtro: x => x.Sigla == row.Provincia))?.Id;
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
@using ClosedXML.Excel
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
|
@using TecniStamp.Domain
|
||||||
|
@using TecniStamp.Model
|
||||||
|
@using TecniStamp.Utils
|
||||||
|
@attribute [Authorize]
|
||||||
|
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
|
@inject AuthenticationStateProvider auth
|
||||||
|
|
||||||
|
<RadzenStack Gap="1rem" class="rz-m-12">
|
||||||
|
<RadzenProgressBar Value="@counter" Max="@provinceTotali" Unit="@counterLabel" AriaLabel="" />
|
||||||
|
</RadzenStack>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[CascadingParameter] private Dialog _dialog { get; set; }
|
||||||
|
[Parameter] public UploadChangeEventArgs args { get; set; }
|
||||||
|
|
||||||
|
private int provinceTotali { get; set; } = 0;
|
||||||
|
private int counter { get; set; } = 0;
|
||||||
|
private string counterLabel { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
base.OnInitializedAsync();
|
||||||
|
var file = args.Files.FirstOrDefault();
|
||||||
|
await using var uploadStream = file.OpenReadStream(10_000_000);
|
||||||
|
var idClaim = await MembershipUtils.GetUserId(auth);
|
||||||
|
|
||||||
|
await using var ms = new MemoryStream();
|
||||||
|
await uploadStream.CopyToAsync(ms);
|
||||||
|
ms.Position = 0;
|
||||||
|
|
||||||
|
using var workbook = new XLWorkbook(ms);
|
||||||
|
var ws = workbook.Worksheet(1);
|
||||||
|
var usedRange = ws.RangeUsed();
|
||||||
|
var rows = new List<ProvinciaIstatExcelViewModel>(usedRange.RowCount() - 1);
|
||||||
|
|
||||||
|
foreach (var row in usedRange.RowsUsed().Skip(1))
|
||||||
|
rows.Add(new ProvinciaIstatExcelViewModel(row));
|
||||||
|
|
||||||
|
|
||||||
|
var province = rows.ToList();
|
||||||
|
provinceTotali = province.Count;
|
||||||
|
counterLabel = " di " + provinceTotali;
|
||||||
|
|
||||||
|
foreach (var provincia in province)
|
||||||
|
{
|
||||||
|
var provinciaDb = await _managerService.ProvinciaIstatService.RicercaPer(
|
||||||
|
x => x.Sigla == provincia.Sigla && x.Eliminato == false,
|
||||||
|
solaLettura: false) ?? new ProvinciaIstat();
|
||||||
|
|
||||||
|
provinciaDb = await mapProvincia(provinciaDb, provincia);
|
||||||
|
await _managerService.ProvinciaIstatService.Salva(provinciaDb, idClaim);
|
||||||
|
counter += 1;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
ms.Close();
|
||||||
|
_dialogService.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ProvinciaIstat> mapProvincia(ProvinciaIstat model, ProvinciaIstatExcelViewModel row)
|
||||||
|
{
|
||||||
|
model.Sigla = row.Sigla;
|
||||||
|
model.Provincia = row.Provincia;
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
40
TecniStamp/TecniStamp/Model/ComuneIstatExcelViewModel.cs
Normal file
40
TecniStamp/TecniStamp/Model/ComuneIstatExcelViewModel.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using ClosedXML.Excel;
|
||||||
|
using TecniStamp.Domain;
|
||||||
|
|
||||||
|
namespace TecniStamp.Model;
|
||||||
|
|
||||||
|
public class ComuneIstatExcelViewModel
|
||||||
|
{
|
||||||
|
public ComuneIstatExcelViewModel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public ComuneIstatExcelViewModel(IXLRangeRow row)
|
||||||
|
{
|
||||||
|
Istat = row.Cell(1).GetString();
|
||||||
|
Comune = row.Cell(2).GetString();
|
||||||
|
Regione = row.Cell(3).GetString();
|
||||||
|
Provincia = row.Cell(4).GetString();
|
||||||
|
Prefisso = row.Cell(5).GetString();
|
||||||
|
CodFisco = row.Cell(6).GetString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Istat { get; set; }
|
||||||
|
public string Comune { get; set; }
|
||||||
|
public string Regione { get; set; }
|
||||||
|
public string Provincia { get; set; }
|
||||||
|
public string Prefisso { get; set; }
|
||||||
|
public string CodFisco { get; set; }
|
||||||
|
|
||||||
|
public static implicit operator ComuneIstatExcelViewModel(ComuneIstat model)
|
||||||
|
{
|
||||||
|
return model == null
|
||||||
|
? null
|
||||||
|
: new ComuneIstatExcelViewModel
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Comune = model.Comune
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
31
TecniStamp/TecniStamp/Model/ComuneIstatViewModel.cs
Normal file
31
TecniStamp/TecniStamp/Model/ComuneIstatViewModel.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using TecniStamp.Domain;
|
||||||
|
|
||||||
|
namespace TecniStamp.Model;
|
||||||
|
|
||||||
|
public class ComuneIstatViewModel
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Istat { get; set; }
|
||||||
|
public string Comune { get; set; }
|
||||||
|
public string Regione { get; set; }
|
||||||
|
public string Provincia { get; set; }
|
||||||
|
public string Prefisso { get; set; }
|
||||||
|
public string CodFisco { get; set; }
|
||||||
|
public string Info => $"{Comune}";
|
||||||
|
|
||||||
|
public static implicit operator ComuneIstatViewModel(ComuneIstat model)
|
||||||
|
{
|
||||||
|
return model == null
|
||||||
|
? null
|
||||||
|
: new ComuneIstatViewModel()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Comune = model.Comune,
|
||||||
|
Istat = model.Istat,
|
||||||
|
Regione = model.Regione,
|
||||||
|
Provincia = model.Provincia,
|
||||||
|
Prefisso = model.Prefisso,
|
||||||
|
CodFisco = model.CodFisco
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
15
TecniStamp/TecniStamp/Model/ProvinciaIstatExcelViewModel.cs
Normal file
15
TecniStamp/TecniStamp/Model/ProvinciaIstatExcelViewModel.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using ClosedXML.Excel;
|
||||||
|
|
||||||
|
namespace TecniStamp.Model;
|
||||||
|
|
||||||
|
public class ProvinciaIstatExcelViewModel
|
||||||
|
{
|
||||||
|
public ProvinciaIstatExcelViewModel(IXLRangeRow row)
|
||||||
|
{
|
||||||
|
Sigla = row.Cell(1).GetString();
|
||||||
|
Provincia = row.Cell(2).GetString();
|
||||||
|
}
|
||||||
|
public string Sigla { get; set; }
|
||||||
|
public string Provincia { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
23
TecniStamp/TecniStamp/Model/ProvinciaViewModel.cs
Normal file
23
TecniStamp/TecniStamp/Model/ProvinciaViewModel.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using TecniStamp.Domain;
|
||||||
|
|
||||||
|
namespace TecniStamp.Model;
|
||||||
|
|
||||||
|
public class ProvinciaViewModel
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Sigla { get; set; }
|
||||||
|
public string Provincia { get; set; }
|
||||||
|
public string Info => $"{Sigla} - {Provincia}";
|
||||||
|
|
||||||
|
public static implicit operator ProvinciaViewModel(ProvinciaIstat model)
|
||||||
|
{
|
||||||
|
return model == null
|
||||||
|
? null
|
||||||
|
: new ProvinciaViewModel()
|
||||||
|
{
|
||||||
|
Provincia = model.Provincia,
|
||||||
|
Sigla = model.Sigla,
|
||||||
|
Id = model.Id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ClosedXML" Version="0.105.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.23" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.23" />
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.1.4" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.1.4" />
|
||||||
<PackageReference Include="Radzen.Blazor" Version="8.7.3" />
|
<PackageReference Include="Radzen.Blazor" Version="8.7.3" />
|
||||||
|
|||||||
Reference in New Issue
Block a user