Primo sviluppo sincronizzazione e migliorie ui
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using Template.Shared.Interfaces;
|
||||
using Template.Shared.Core.Interface;
|
||||
|
||||
namespace Template.Maui.Services;
|
||||
namespace Template.Maui.Core.Services;
|
||||
|
||||
public class FormFactor : IFormFactor
|
||||
{
|
||||
76
Template.Maui/Core/Services/LocalDbService.cs
Normal file
76
Template.Maui/Core/Services/LocalDbService.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Linq.Expressions;
|
||||
using SQLite;
|
||||
using Template.Shared.Core.Entity;
|
||||
|
||||
namespace Template.Maui.Core.Services;
|
||||
|
||||
public class LocalDbService
|
||||
{
|
||||
private const string DB_NAME = "task_db.db3";
|
||||
private readonly SQLiteAsyncConnection _connection;
|
||||
|
||||
public LocalDbService()
|
||||
{
|
||||
_connection = new SQLiteAsyncConnection(Path.Combine(FileSystem.AppDataDirectory, DB_NAME));
|
||||
|
||||
//Creazione tabelle database
|
||||
_connection.CreateTableAsync<AnagClie>();
|
||||
_connection.CreateTableAsync<JtbComt>();
|
||||
_connection.CreateTableAsync<PtbPros>();
|
||||
_connection.CreateTableAsync<PtbProsRif>();
|
||||
_connection.CreateTableAsync<StbActivity>();
|
||||
_connection.CreateTableAsync<VtbCliePersRif>();
|
||||
_connection.CreateTableAsync<VtbDest>();
|
||||
}
|
||||
|
||||
public async Task ResetDb()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS anag_clie;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS jtb_comt;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS ptb_pros;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS ptb_pros_rif;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS stb_activity;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS vtb_clie_pers_rif;");
|
||||
await _connection.ExecuteAsync("DROP TABLE IF EXISTS vtb_dest;");
|
||||
|
||||
await _connection.CreateTableAsync<AnagClie>();
|
||||
await _connection.CreateTableAsync<JtbComt>();
|
||||
await _connection.CreateTableAsync<PtbPros>();
|
||||
await _connection.CreateTableAsync<PtbProsRif>();
|
||||
await _connection.CreateTableAsync<StbActivity>();
|
||||
await _connection.CreateTableAsync<VtbCliePersRif>();
|
||||
await _connection.CreateTableAsync<VtbDest>();
|
||||
|
||||
Console.WriteLine("Database resettato con successo.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Errore durante il reset del database: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Task Insert<T>(List<T> entityList) =>
|
||||
_connection.InsertAllAsync(entityList, typeof(T));
|
||||
|
||||
public async Task InsertOrUpdate<T>(List<T> entityList)
|
||||
{
|
||||
foreach (var entity in entityList)
|
||||
{
|
||||
var result = await _connection.UpdateAsync(entity);
|
||||
if (result == 0)
|
||||
{
|
||||
await _connection.InsertAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task<List<T>> Get<T>(Expression<Func<T, bool>>? whereCond = null) where T : new() =>
|
||||
whereCond is null
|
||||
? _connection.Table<T>().ToListAsync()
|
||||
: _connection.Table<T>().Where(whereCond).ToListAsync();
|
||||
|
||||
public List<T> Get<T>(string sql) where T : new() => _connection.QueryAsync<T>(sql).Result;
|
||||
}
|
||||
72
Template.Maui/Core/Services/ManageDataService.cs
Normal file
72
Template.Maui/Core/Services/ManageDataService.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using AutoMapper;
|
||||
using System.Linq.Expressions;
|
||||
using Template.Shared.Core.Dto;
|
||||
using Template.Shared.Core.Entity;
|
||||
using Template.Shared.Core.Helpers.Enum;
|
||||
using Template.Shared.Core.Interface;
|
||||
|
||||
namespace Template.Maui.Core.Services;
|
||||
|
||||
public class ManageDataService(LocalDbService localDb, IMapper mapper) : IManageDataService
|
||||
{
|
||||
public Task<List<AnagClie>> GetAnagClie(Expression<Func<AnagClie, bool>>? whereCond = null) =>
|
||||
localDb.Get(whereCond);
|
||||
|
||||
public Task<List<JtbComt>> GetJtbComt(Expression<Func<JtbComt, bool>>? whereCond = null) =>
|
||||
localDb.Get(whereCond);
|
||||
|
||||
public Task<List<PtbPros>> GetPtbPros(Expression<Func<PtbPros, bool>>? whereCond = null) =>
|
||||
localDb.Get(whereCond);
|
||||
|
||||
public Task<List<PtbProsRif>> GetPtbProsRif(Expression<Func<PtbProsRif, bool>>? whereCond = null) =>
|
||||
localDb.Get(whereCond);
|
||||
|
||||
public Task<List<StbActivity>> GetStbActivity(Expression<Func<StbActivity, bool>>? whereCond = null) =>
|
||||
localDb.Get(whereCond);
|
||||
|
||||
public Task<List<VtbCliePersRif>> GetVtbCliePersRif(Expression<Func<VtbCliePersRif, bool>>? whereCond = null) =>
|
||||
localDb.Get(whereCond);
|
||||
|
||||
public Task<List<VtbDest>> GetVtbDest(Expression<Func<VtbDest, bool>>? whereCond = null) =>
|
||||
localDb.Get(whereCond);
|
||||
|
||||
public async Task<List<ActivityDTO>> GetActivity(Expression<Func<StbActivity, bool>>? whereCond = null)
|
||||
{
|
||||
var activities = await localDb.Get(whereCond);
|
||||
|
||||
var codJcomList = activities
|
||||
.Select(x => x.CodJcom)
|
||||
.Where(x => !string.IsNullOrEmpty(x))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var jtbComtList = await localDb.Get<JtbComt>(x => codJcomList.Contains(x.CodJcom));
|
||||
var commesseDict = jtbComtList.ToDictionary(x => x.CodJcom, x => x.Descrizione);
|
||||
|
||||
var returnDto = activities
|
||||
.Select(activity =>
|
||||
{
|
||||
var dto = mapper.Map<ActivityDTO>(activity);
|
||||
|
||||
if (activity.CodJcom != null)
|
||||
{
|
||||
dto.Category = ActivityCategoryEnum.Commessa;
|
||||
}
|
||||
else
|
||||
{
|
||||
dto.Category = activity.CodAnag != null ? ActivityCategoryEnum.Interna : ActivityCategoryEnum.Memo;
|
||||
}
|
||||
|
||||
dto.Commessa = activity.CodJcom != null && commesseDict.TryGetValue(activity.CodJcom, out var descr)
|
||||
? descr
|
||||
: null;
|
||||
return dto;
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return returnDto;
|
||||
}
|
||||
|
||||
public async Task ClearDb() =>
|
||||
await localDb.ResetDb();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Template.Shared.Core.Interface;
|
||||
|
||||
namespace Template.Maui.Services;
|
||||
namespace Template.Maui.Core.Services;
|
||||
|
||||
public class NetworkService : INetworkService
|
||||
{
|
||||
69
Template.Maui/Core/Services/SyncDbService.cs
Normal file
69
Template.Maui/Core/Services/SyncDbService.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Template.Shared.Core.Interface;
|
||||
|
||||
namespace Template.Maui.Core.Services;
|
||||
|
||||
public class SyncDbService(IIntegryApiService integryApiService, LocalDbService localDb) : ISyncDbService
|
||||
{
|
||||
public async Task GetAndSaveActivity(string? dateFilter)
|
||||
{
|
||||
var allActivity = await integryApiService.GetActivity(dateFilter);
|
||||
|
||||
if (allActivity is not null)
|
||||
if (dateFilter is null)
|
||||
await localDb.Insert(allActivity);
|
||||
else
|
||||
await localDb.InsertOrUpdate(allActivity);
|
||||
}
|
||||
|
||||
public async Task GetAndSaveCommesse(string? dateFilter)
|
||||
{
|
||||
var allCommesse = await integryApiService.GetAllCommesse(dateFilter);
|
||||
|
||||
if (allCommesse is not null)
|
||||
if (dateFilter is null)
|
||||
await localDb.Insert(allCommesse);
|
||||
else
|
||||
await localDb.InsertOrUpdate(allCommesse);
|
||||
}
|
||||
|
||||
public async Task GetAndSaveProspect(string? dateFilter)
|
||||
{
|
||||
var taskSyncResponseDto = await integryApiService.GetProspect(dateFilter);
|
||||
|
||||
if (taskSyncResponseDto.PtbPros is not null)
|
||||
if (dateFilter is null)
|
||||
await localDb.Insert(taskSyncResponseDto.PtbPros);
|
||||
else
|
||||
await localDb.InsertOrUpdate(taskSyncResponseDto.PtbPros);
|
||||
|
||||
if (taskSyncResponseDto.PtbProsRif is not null)
|
||||
if (dateFilter is null)
|
||||
await localDb.Insert(taskSyncResponseDto.PtbProsRif);
|
||||
else
|
||||
await localDb.InsertOrUpdate(taskSyncResponseDto.PtbProsRif);
|
||||
}
|
||||
|
||||
public async Task GetAndSaveClienti(string? dateFilter)
|
||||
{
|
||||
var taskSyncResponseDto = await integryApiService.GetAnagClie(dateFilter);
|
||||
|
||||
if (taskSyncResponseDto.AnagClie is not null)
|
||||
if (dateFilter is null)
|
||||
await localDb.Insert(taskSyncResponseDto.AnagClie);
|
||||
else
|
||||
await localDb.InsertOrUpdate(taskSyncResponseDto.AnagClie);
|
||||
|
||||
if (taskSyncResponseDto.VtbDest is not null)
|
||||
if (dateFilter is null)
|
||||
await localDb.Insert(taskSyncResponseDto.VtbDest);
|
||||
else
|
||||
await localDb.InsertOrUpdate(taskSyncResponseDto.VtbDest);
|
||||
|
||||
if (taskSyncResponseDto.VtbCliePersRif is not null)
|
||||
if (dateFilter is null)
|
||||
await localDb.Insert(taskSyncResponseDto.VtbCliePersRif);
|
||||
else
|
||||
await localDb.InsertOrUpdate(taskSyncResponseDto.VtbCliePersRif);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Template.Shared.Core.Messages;
|
||||
|
||||
namespace Template.Maui
|
||||
{
|
||||
public partial class MainPage : ContentPage
|
||||
@@ -6,5 +9,12 @@ namespace Template.Maui
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override bool OnBackButtonPressed()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new HardwareBackMessage("back"));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@ using IntegryApiClient.MAUI;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MudBlazor.Services;
|
||||
using Template.Maui.Services;
|
||||
using Template.Maui.Core.Services;
|
||||
using Template.Shared;
|
||||
using Template.Shared.Core.Helpers;
|
||||
using Template.Shared.Core.Interface;
|
||||
using Template.Shared.Core.Messages;
|
||||
using Template.Shared.Core.Services;
|
||||
using Template.Shared.Interfaces;
|
||||
|
||||
namespace Template.Maui
|
||||
{
|
||||
@@ -30,12 +31,18 @@ namespace Template.Maui
|
||||
builder.Services.AddMauiBlazorWebView();
|
||||
builder.Services.AddMudServices();
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(MappingProfile));
|
||||
|
||||
builder.Services.AddAuthorizationCore();
|
||||
builder.Services.AddScoped<AppAuthenticationStateProvider>();
|
||||
builder.Services.AddScoped<AuthenticationStateProvider>(provider =>
|
||||
provider.GetRequiredService<AppAuthenticationStateProvider>());
|
||||
|
||||
builder.Services.AddScoped<INetworkService, NetworkService>();
|
||||
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
|
||||
builder.Services.AddScoped<ISyncDbService, SyncDbService>();
|
||||
builder.Services.AddScoped<IManageDataService, ManageDataService>();
|
||||
builder.Services.AddScoped<BackNavigationService>();
|
||||
|
||||
#if DEBUG
|
||||
builder.Services.AddBlazorWebViewDeveloperTools();
|
||||
@@ -43,6 +50,7 @@ namespace Template.Maui
|
||||
#endif
|
||||
|
||||
builder.Services.AddSingleton<IFormFactor, FormFactor>();
|
||||
builder.Services.AddSingleton<LocalDbService>();
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:usesCleartextTraffic="true" android:supportsRtl="true"></application>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using Android.App;
|
||||
using Android.Content.PM;
|
||||
using Android.OS;
|
||||
|
||||
namespace Template.Maui
|
||||
{
|
||||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
|
||||
[Activity(Theme = "@style/Maui.SplashTheme",
|
||||
MainLauncher = true,
|
||||
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode |
|
||||
ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
|
||||
public class MainActivity : MauiAppCompatActivity
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,5 +28,12 @@
|
||||
</array>
|
||||
<key>XSAppIconAssets</key>
|
||||
<string>Assets.xcassets/appicon.appiconset</string>
|
||||
<key>NSLocalNetworkUsageDescription</key>
|
||||
<string>This app requires access to the local network to communicate with the server.</string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(TargetFramework)'=='net9.0-ios'">
|
||||
<CodesignKey>Apple Development: Massimo Fausto Morelli (6C2CUM53BT)</CodesignKey>
|
||||
<CodesignKey>Apple Development: Created via API (5B7B69P4JY)</CodesignKey>
|
||||
<CodesignProvision>VS: WildCard Development</CodesignProvision>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -111,12 +111,14 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Maui" Version="11.2.0" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||
<PackageReference Include="IntegryApiClient.MAUI" Version="1.1.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.60" />
|
||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.60" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.60" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.4" />
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,200..1000;1,200..1000&display=swap" rel="stylesheet">
|
||||
|
||||
|
||||
<link href="_content/Template.Shared/css/bootstrap/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<link href="_content/Template.Shared/css/bootstrap/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="_content/Template.Shared/css/bootstrap/bootstrap-icons.min.css" rel="stylesheet" />
|
||||
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user