127 lines
4.4 KiB
Plaintext
127 lines
4.4 KiB
Plaintext
@page "/"
|
|
@using Blazor.IndexedDB
|
|
@using DBTest.DB
|
|
@using Microsoft.Data.SqlClient
|
|
|
|
@inject IIndexedDbFactory DbFactory
|
|
|
|
<PageTitle>Home</PageTitle>
|
|
|
|
<h1>Artikelliste</h1>
|
|
|
|
@if (artikelliste == null)
|
|
{
|
|
<div class="d-flex justify-content-center align-items-center">
|
|
<p class="text-muted fs-4">Loading...</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="container">
|
|
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
|
|
@foreach (var quote in artikelliste)
|
|
{
|
|
<div class="col">
|
|
<div class="card shadow-sm h-100">
|
|
<div class="card-body d-flex flex-column">
|
|
<blockquote class="blockquote mb-4">
|
|
<p class="fs-5">"@quote.Barcode"</p>
|
|
</blockquote>
|
|
<footer class="blockquote-footer mt-auto text-end">
|
|
<cite title="Author">@quote.Bezeichnung</cite>
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
<div class="text-center mt-5">
|
|
<button class="btn btn-primary btn-lg" @onclick="ForceRefresh">Force Refresh</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private List<Artikel> artikelliste;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadQuotesAsync();
|
|
}
|
|
|
|
private async Task LoadQuotesAsync()
|
|
{
|
|
using (var db = await DbFactory.Create<ArtikelDB>())
|
|
{
|
|
// Load quotes from IndexedDB
|
|
artikelliste = db.ArtikelListe.ToList();
|
|
// If no quotes exist in IndexedDB, fetch from API
|
|
if (artikelliste == null || artikelliste.Count == 0)
|
|
{
|
|
await FetchAndStoreQuotesFromDBAsync();
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task FetchAndStoreQuotesFromDBAsync()
|
|
{
|
|
try
|
|
{
|
|
using (var db = await DbFactory.Create<ArtikelDB>())
|
|
{
|
|
//Läuft nicht auf dem Client !!!!
|
|
// using (SqlConnection con = new SqlConnection("Data Source=APP03AC;Initial Catalog=KassenSystem;User Id=KassenManager;Password=ks;Max Pool Size=600;Connection Timeout=3000;encrypt=true;"))
|
|
// {
|
|
// con.Open();
|
|
|
|
// 0 1 2 3 4 5
|
|
// string sql = "SELECT [ArtikelMA].[ArtikelId], [ArtikelNummer], [ArtikelMA].[Barcode], [Bontext], [Mengeneinheit], isnull([Farbe], '') FROM [Kassensystem].[KS].[ArtikelMA] left join [Kassensystem].[KS].[ArtikelVariantenMA] on [ArtikelMA].[ArtikelId] = [ArtikelVariantenMA].[ArtikelId] where [ArtikelMA].GeloeschtAm is null and istAusgeblendet = 0 and [ArtikelVariantenMA].GeloeschtAm is null order by ArtikelId, Farbe";
|
|
|
|
// using (SqlCommand cmd = new SqlCommand(sql, con))
|
|
// {
|
|
// using (SqlDataReader reader = cmd.ExecuteReader())
|
|
// {
|
|
// while (reader.Read())
|
|
// {
|
|
// Artikel a1 = new Artikel();
|
|
// a1.Key = reader.GetString(0);
|
|
// a1.ArtikelNummer = reader.GetString(1);
|
|
// a1.Variante = reader.GetString(5);
|
|
// a1.Bezeichnung = reader.GetString(3);
|
|
|
|
// db.ArtikelListe.Add(a1);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
Artikel a1 = new Artikel();
|
|
a1.Key = "1";
|
|
a1.ArtikelNummer = "0815";
|
|
a1.Variante = "";
|
|
a1.Bezeichnung = "Testartikel";
|
|
|
|
db.ArtikelListe.Add(a1);
|
|
await db.SaveChanges(); // Save changes
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
|
|
private async Task ForceRefresh()
|
|
{
|
|
using (var db = await DbFactory.Create<ArtikelDB>())
|
|
{
|
|
db.ArtikelListe.Clear(); // Clear existing data from IndexedDB
|
|
await db.SaveChanges();
|
|
}
|
|
await FetchAndStoreQuotesFromDBAsync(); // Fetch fresh data from API
|
|
}
|
|
|
|
}
|
|
|
|
|