Skip to content

Commit

Permalink
Optimize:: Implementasi Dispose di Pagination Handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
bachtiarpanjaitan committed Sep 28, 2024
1 parent ec7a348 commit a7adc41
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 91 deletions.
23 changes: 8 additions & 15 deletions Bepe/Helpers/Pagination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public sealed class Pagination<T> : IDisposable
public Pagination(IDataService<T> dataService, Type typeHeader, Type form = null){
ResetDataPagination(); //keep on top
var settings = AppSettingConfig.LoadSettings();
DatagridProvider.Indicator.IsRunning = true;
DatagridProvider.Indicator.IsVisible = true;
DatagridProvider.ShowLoader();
_typeHeader = typeHeader;
_form = form;
_dataService = dataService;
Expand All @@ -45,16 +44,13 @@ public Pagination(IDataService<T> dataService, Type typeHeader, Type form = null

public void RefreshData()
{
DatagridProvider.Indicator.IsRunning = true;
DatagridProvider.Indicator.IsVisible = true;
UpdatePagedData().ConfigureAwait(true);
UpdatePagedData().ConfigureAwait(false);
}

private void OnPrevButtonClicked(object sender, EventArgs e)
{
if (_pageIndex <= 0) return;
DatagridProvider.Indicator.IsRunning = true;
DatagridProvider.Indicator.IsVisible = true;
DatagridProvider.ShowLoader();
_pageIndex--;
UpdatePagedData().ConfigureAwait(true);

Expand All @@ -63,8 +59,7 @@ private void OnPrevButtonClicked(object sender, EventArgs e)
private void OnNextButtonClicked(object sender, EventArgs e)
{
if ((_pageIndex + 1) >= _pageCount) return;
DatagridProvider.Indicator.IsRunning = true;
DatagridProvider.Indicator.IsVisible = true;
DatagridProvider.ShowLoader();
_pageIndex++;
UpdatePagedData().ConfigureAwait(true);

Expand All @@ -91,10 +86,9 @@ private async Task UpdatePagedData()
}
finally
{
DatagridProvider.Indicator.IsRunning = false;
DatagridProvider.Indicator.IsVisible = false;
DatagridProvider.HideLoader();
}
}
} else DatagridProvider.HideLoader();
}

private void GetComponentHandler()
Expand All @@ -118,8 +112,7 @@ private void OnAddFormClicked(object sender, EventArgs e)

private void OnSearchHandler(object sender, TextChangedEventArgs e)
{
DatagridProvider.Indicator.IsRunning = true;
DatagridProvider.Indicator.IsVisible = true;
DatagridProvider.ShowLoader();
_search = e.NewTextValue;
UpdatePagedData().ConfigureAwait(true);
}
Expand Down Expand Up @@ -151,7 +144,7 @@ private void Dispose(bool disposing)
{
// Hapus event handler
DatagridProvider.RemovePaginationClickHandlers();
// if (_typeHeader == typeof(FilterOne))FilterOne.RemoveEventHandlers();
FilterOne.RemoveEventHandlers();

_dataService = null;
_form = null;
Expand Down
4 changes: 2 additions & 2 deletions IhandCashier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<Copyright>HMP Basapadi</Copyright>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>basapadi.snk</AssemblyOriginatorKeyFile>
<Configurations>Debug;Release;Relaase Core</Configurations>
<Configurations>Debug;Release;Release Core</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>

Expand Down Expand Up @@ -154,7 +154,7 @@
</ItemGroup>
<ItemGroup>
<Reference Include="IhandCashier.Core">
<HintPath>..\IhandCashier.Core\bin\Release\net8.0-maccatalyst\IhandCashier.Core.dll</HintPath>
<HintPath>..\IhandCashier.Core\bin\Release Core\net8.0-maccatalyst\IhandCashier.Core.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions IhandCashier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Relaase Core|Any CPU = Relaase Core|Any CPU
Release Core|Any CPU = Release Core|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release|Any CPU.Build.0 = Release|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release|Any CPU.Deploy.0 = Release|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Relaase Core|Any CPU.ActiveCfg = Relaase Core|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release Core|Any CPU.ActiveCfg = Debug|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Release|Any CPU.Build.0 = Release|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Relaase Core|Any CPU.ActiveCfg = Relaase Core|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Relaase Core|Any CPU.Build.0 = Relaase Core|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Debug|Any CPU.ActiveCfg = Release Core|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Release Core|Any CPU.ActiveCfg = Release Core|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Release Core|Any CPU.Build.0 = Release Core|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 8 additions & 14 deletions Pages/Views/GridDataBarang.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace IhandCashier.Pages.Views
public partial class GridDataBarang
{
private const string ModuleName = "Data Barang";
private Pagination<ProductDto> _pagination;
ProductService _service = ServiceLocator.ServiceProvider.GetService<ProductService>();
ProductDto _selectedProduct;

Expand All @@ -25,12 +24,6 @@ public GridDataBarang()
InitializeComponent();
FilterOne.Initialize(ModuleName);
ResetView();
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
EditHandler = OnEditClicked,
RefreshHandler = OnRefreshClicked
});
List<ColumnType> columns = [
new () { Type = ColumnTypes.Numeric,MappingName = "id", TextAlignment = TextAlignment.Center,ColumnMode = ColumnWidthMode.FitByCell ,HeaderText = "ID", Format = "N0" },
new() { Type = ColumnTypes.Text, MappingName = "kode", HeaderText = "KODE" },
Expand All @@ -43,7 +36,14 @@ public GridDataBarang()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
_pagination = new Pagination<ProductDto>(_service, typeof(FilterOne), typeof(FormBarang));
using var _pagination = new Pagination<ProductDto>(_service, typeof(FilterOne), typeof(FormBarang));
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
EditHandler = OnEditClicked,
RefreshHandler = (sender, args) => _pagination.RefreshData()
});

DatagridProvider.AddDatagridCellHandler(OnClick,OnEditClicked);
DatagridProvider.HideLoader();
});
Expand All @@ -64,7 +64,6 @@ private async void OnDeleteClicked(object sender, EventArgs e)
{
await _service.DeleteAsync(_selectedProduct.ToEntity());
Application.Current.MainPage.DisplayAlert("Berhasil", "Barang berhasil dihapus", "OK");
_pagination.RefreshData();
}
catch (Exception ex)
{
Expand All @@ -86,11 +85,6 @@ private void OnEditClicked(object sender, EventArgs e)

}
}

private void OnRefreshClicked(object sender, EventArgs e)
{
_pagination.RefreshData();
}
}
}

20 changes: 8 additions & 12 deletions Pages/Views/GridDataHargaBarang.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace IhandCashier.Pages.Views;
public partial class GridDataHargaBarang
{
private const string ModuleName = "Data Harga Barang";
private Pagination<ProductPriceDto> _pagination;
ProductPriceService _service = ServiceLocator.ServiceProvider.GetService<ProductPriceService>();
ProductPriceDto _selectedProduct;

Expand All @@ -27,12 +26,7 @@ public GridDataHargaBarang()
InitializeComponent();
FilterOne.Initialize(ModuleName);
ResetView();
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
EditHandler = OnEditClicked,
RefreshHandler = OnRefreshClicked
});

List<ColumnType> columns = [
new() { Type = ColumnTypes.Numeric,MappingName = "id", TextAlignment = TextAlignment.Center,ColumnMode = ColumnWidthMode.FitByCell ,HeaderText = "ID", Format = "N0" },
new() { Type = ColumnTypes.Text, MappingName = "kode", HeaderText = "KODE",ColumnMode = ColumnWidthMode.FitByCell },
Expand All @@ -50,7 +44,13 @@ public GridDataHargaBarang()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
_pagination = new Pagination<ProductPriceDto>(_service, typeof(FilterOne));
using var _pagination = new Pagination<ProductPriceDto>(_service, typeof(FilterOne));
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
EditHandler = OnEditClicked,
RefreshHandler = (sender, args) => _pagination.RefreshData()
});
DatagridProvider.AddDatagridCellHandler(OnClick);
DatagridProvider.HideLoader();
});
Expand All @@ -61,10 +61,6 @@ private void OnClick(object sender, DataGridCellTappedEventArgs e)
_selectedProduct = e.RowData as ProductPriceDto;
if (_selectedProduct != null) Console.WriteLine($"Barang : {_selectedProduct.kode}");
}
private void OnRefreshClicked(object sender, EventArgs e)
{

}

private void OnDeleteClicked(object sender, EventArgs e)
{
Expand Down
3 changes: 1 addition & 2 deletions Pages/Views/GridDataKasir.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public partial class GridDataKasir
{
private const string ModuleName = "Data Kasir";
UserService _service = ServiceLocator.ServiceProvider.GetService<UserService>();
private Pagination<UserDto> _pagination;
UserDto _selectedProduct;
public GridDataKasir()
{
Expand All @@ -37,7 +36,7 @@ public GridDataKasir()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
_pagination = new Pagination<UserDto>(_service, typeof(FilterOne));
using var _pagination = new Pagination<UserDto>(_service, typeof(FilterOne));
DatagridProvider.AddDatagridCellHandler(OnClick);
DatagridProvider.HideLoader();
});
Expand Down
3 changes: 1 addition & 2 deletions Pages/Views/GridDataPelanggan.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public partial class GridDataPelanggan
{
private const string ModuleName = "Data Pelanggan";
CustomerService _service = ServiceLocator.ServiceProvider.GetService<CustomerService>();
private Pagination<Customer> _pagination;
Customer _selectedProduct;
public GridDataPelanggan()
{
Expand All @@ -36,7 +35,7 @@ public GridDataPelanggan()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
_pagination = new Pagination<Customer>(_service, typeof(FilterOne));
using var _pagination = new Pagination<Customer>(_service, typeof(FilterOne));
DatagridProvider.AddDatagridCellHandler(OnClick);
DatagridProvider.HideLoader();
});
Expand Down
3 changes: 1 addition & 2 deletions Pages/Views/GridDataPemasok.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public partial class GridDataPemasok
{
private const string ModuleName = "Data Pemasok";
SupplierService _service = ServiceLocator.ServiceProvider.GetService<SupplierService>();
private Pagination<Supplier> _pagination;
Supplier _selectedProduct;
public GridDataPemasok()
{
Expand All @@ -36,7 +35,7 @@ public GridDataPemasok()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
_pagination = new Pagination<Supplier>(_service, typeof(FilterOne));
using var _pagination = new Pagination<Supplier>(_service, typeof(FilterOne));
DatagridProvider.AddDatagridCellHandler(OnClick);
DatagridProvider.HideLoader();
});
Expand Down
14 changes: 7 additions & 7 deletions Pages/Views/GridDataSatuanBarang.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public GridDataSatuanBarang()
InitializeComponent();
FilterOne.Initialize(ModuleName);
ResetView();
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
EditHandler = OnEditClicked,
RefreshHandler = OnRefreshClicked
});
List<ColumnType> columns = [
new ColumnType { Type = ColumnTypes.Numeric,TextAlignment = TextAlignment.Center, MappingName = "id",ColumnMode = ColumnWidthMode.FitByCell , HeaderText = "ID", Format = "N0" },
new ColumnType { Type = ColumnTypes.Text, MappingName = "kode_satuan", HeaderText = "KODE SATUAN"},
Expand All @@ -43,7 +37,13 @@ public GridDataSatuanBarang()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
_pagination = new Pagination<UnitDto>(_service, typeof(FilterOne), typeof(FormSatuanBarang));
using var _pagination = new Pagination<UnitDto>(_service, typeof(FilterOne), typeof(FormSatuanBarang));
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
EditHandler = OnEditClicked,
RefreshHandler = (sender, args) => _pagination.RefreshData()
});
DatagridProvider.AddDatagridCellHandler(OnClick,OnEditClicked);
DatagridProvider.HideLoader();
});
Expand Down
22 changes: 8 additions & 14 deletions Pages/Views/GridDataSatuanDasarBarang.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@ public sealed partial class GridDataSatuanDasarBarang

private const string ModuleName = "Data Satuan Dasar Barang";
BasicUnitService _service = ServiceLocator.ServiceProvider.GetService<BasicUnitService>();
private Pagination<BasicUnitDto> _pagination;
BasicUnitDto _selected;
public GridDataSatuanDasarBarang()
{
InitializeComponent();
FilterOne.Initialize(ModuleName);
ResetView();
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
EditHandler = OnEditClicked,
RefreshHandler = OnRefreshClicked
});

List<ColumnType> columns = [
new() { Type = ColumnTypes.Numeric,TextAlignment = TextAlignment.Center, MappingName = "id", ColumnMode = ColumnWidthMode.FitByCell , HeaderText = "ID", Format = "N0" },
new() { Type = ColumnTypes.Text, MappingName = "nama", HeaderText = "NAMA SATUAN"},
Expand All @@ -41,7 +35,13 @@ public GridDataSatuanDasarBarang()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
_pagination = new Pagination<BasicUnitDto>(_service, typeof(FilterOne), typeof(FormSatuanDasarBarang));
using var _pagination = new Pagination<BasicUnitDto>(_service, typeof(FilterOne), typeof(FormSatuanDasarBarang));
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
EditHandler = OnEditClicked,
RefreshHandler = (sender, args) => _pagination.RefreshData()
});
DatagridProvider.AddDatagridCellHandler(OnClicked, OnEditClicked);
DatagridProvider.HideLoader();
});
Expand All @@ -56,7 +56,6 @@ private async void OnDeleteClicked(object sender, EventArgs e)
{
await _service.DeleteAsync(_selected.ToEntity());
Application.Current.MainPage.DisplayAlert("Berhasil", "Satuan dasar berhasil dihapus", "OK");
_pagination.RefreshData();
}
catch (Exception ex)
{
Expand All @@ -66,11 +65,6 @@ private async void OnDeleteClicked(object sender, EventArgs e)
}
}

private void OnRefreshClicked(object sender, EventArgs e)
{
_pagination.RefreshData();
}

private void OnEditClicked(object sender, EventArgs e)
{
if (Application.Current != null && Application.Current.MainPage != null)
Expand Down
Loading

0 comments on commit a7adc41

Please sign in to comment.