Sistemato editing counters
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
@using SHERPA.BBM.UI.Data
|
||||
@using SHERPA.BBM.UI.Components;
|
||||
@using DatabaseModels
|
||||
@inject BBM_EFService BBMService
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-info text-light">
|
||||
<b>Modifica</b>
|
||||
</div>
|
||||
<div class="card-body small">
|
||||
<EditForm Model="@_currItem">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
<div class="row">
|
||||
<div class="col-8 col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="codNeg">Codice:</label>
|
||||
<InputText id="codNeg" @bind-Value="_currItem.CodCounter" class="form-control form-control-sm" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4 col-lg-2">
|
||||
<label for="dataIns">Last num:</label>
|
||||
<InputNumber id="NumDoc" @bind-Value="_currItem.LastNum" class="form-control form-control-sm" />
|
||||
</div>
|
||||
<div class="col-6 col-lg-3">
|
||||
<input type="submit" class="btn btn-success btn-block" value="Save" @onclick="saveUpdate" />
|
||||
</div>
|
||||
<div class="col-6 col-lg-3">
|
||||
<button type="button" class="btn btn-warning btn-block" value="Cancel" @onclick="cancelUpdate">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
protected DatabaseModels.FluxCountersModel _currItem = new FluxCountersModel();
|
||||
|
||||
[Parameter]
|
||||
public DatabaseModels.FluxCountersModel currItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return _currItem = null;
|
||||
}
|
||||
set
|
||||
{
|
||||
_currItem = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<int> DataReset { get; set; }
|
||||
[Parameter]
|
||||
public EventCallback<int> DataUpdated { get; set; }
|
||||
|
||||
private async Task saveUpdate()
|
||||
{
|
||||
if (_currItem != null)
|
||||
{
|
||||
BBMService.CounterUpdate(_currItem);
|
||||
await DataUpdated.InvokeAsync(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Counter null!");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task cancelUpdate()
|
||||
{
|
||||
await DataReset.InvokeAsync(0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,11 +94,27 @@ namespace SHERPA.BBM.UI.Data
|
||||
}
|
||||
}
|
||||
|
||||
public Task<DatabaseModels.FluxCountersModel[]> CounterGetAll()
|
||||
{
|
||||
return Task.FromResult(dbController.ContersGetAll().ToArray());
|
||||
}
|
||||
|
||||
public string CounterGetNext(string CodCounter, int numZeros)
|
||||
{
|
||||
return dbController.CounterGetNext(CodCounter, numZeros);
|
||||
}
|
||||
|
||||
public void CounterUpdate(DatabaseModels.FluxCountersModel currItem)
|
||||
{
|
||||
try
|
||||
{
|
||||
dbController.CounterUpdate(currItem);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public Task<DatabaseModels.DocsModel> DocGetByKeyAsync(int DocId)
|
||||
{
|
||||
return Task.FromResult(dbController.DocGetByKey(DocId));
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
@page "/counter"
|
||||
|
||||
<h1>Counter</h1>
|
||||
|
||||
<p>Current count: @currentCount</p>
|
||||
|
||||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
|
||||
|
||||
@code {
|
||||
private int currentCount = 0;
|
||||
|
||||
private void IncrementCount()
|
||||
{
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
@page "/counters"
|
||||
|
||||
@using SHERPA.BBM.UI.Data
|
||||
@using SHERPA.BBM.UI.Components
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject BBM_EFService BBMService
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="row">
|
||||
<div class="col-6 col-lg-3">
|
||||
<h3><span class="oi oi-key" aria-hidden="true"></span> Contatori</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@if (currItem != null)
|
||||
{
|
||||
<CountersEditor currItem="@currItem" DataReset="ResetData" DataUpdated="UpdateData"></CountersEditor>
|
||||
}
|
||||
@if (itemsList == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Cod</th>
|
||||
<th>LastNum</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var record in itemsList)
|
||||
{
|
||||
<tr class="@checkSelect(@record.CodCounter)">
|
||||
<td><button class="btn btn-sm btn-info" @onclick="() => Edit(record)"><span class="oi oi-pencil"></span></button></td>
|
||||
<td>@record.CodCounter</td>
|
||||
<td>@record.LastNum</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@*<div class="card-footer">
|
||||
<div class="row">
|
||||
<div class="col-8 col-lg-10">
|
||||
</div>
|
||||
<div class="col-4 col-lg-2">
|
||||
<DataPager numRecord="@numRecord" numRecordChanged="ForceReload" />
|
||||
</div>
|
||||
</div>
|
||||
</div>*@
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
private DatabaseModels.FluxCountersModel currItem = null;
|
||||
private DatabaseModels.FluxCountersModel[] itemsList;
|
||||
|
||||
protected async Task updateTable()
|
||||
{
|
||||
itemsList = await BBMService.CounterGetAll();
|
||||
}
|
||||
|
||||
protected async Task ReloadAllData()
|
||||
{
|
||||
await updateTable();
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await ReloadAllData();
|
||||
}
|
||||
|
||||
protected void ResetData()
|
||||
{
|
||||
BBMService.rollBackEdit(currItem);
|
||||
currItem = null;
|
||||
}
|
||||
|
||||
protected async Task UpdateData()
|
||||
{
|
||||
currItem = null;
|
||||
await ReloadAllData();
|
||||
}
|
||||
|
||||
protected void Edit(SHERPA.BBM.DatabaseModels.FluxCountersModel currRecord)
|
||||
{
|
||||
currItem = currRecord;
|
||||
}
|
||||
|
||||
public string checkSelect(string CodCounter)
|
||||
{
|
||||
string answ = "";
|
||||
if (currItem != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
answ = (currItem.CodCounter == CodCounter) ? "table-info" : "";
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
@page "/utility"
|
||||
|
||||
@using SHERPA.BBM.UI.Components
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="row">
|
||||
<div class="col-6 col-lg-3">
|
||||
<h3><span class="oi oi-wrench" aria-hidden="true"></span> Utility</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="shortcuts mt-2">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<HomeButton NavLink="counters" Icon="oi-key" Descript="Contatori" />
|
||||
@*<HomeButton NavLink="negotiations" Icon="oi-cart" Descript="Negoziazioni" />*@
|
||||
@*<HomeButton NavLink="docs" Icon="oi-document" Descript="Documenti" />*@
|
||||
@*<HomeButton NavLink="resources" Icon="oi-puzzle-piece" Descript="Risorse" />*@
|
||||
@*<HomeButton NavLink="items" Icon="oi-badge" Descript="Items" />*@
|
||||
@*<HomeButton NavLink="items" Icon="oi-wrench" Descript="Utility" />*@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
||||
@@ -131,6 +131,24 @@ namespace SHERPA.BBM.Controllers
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Conunters
|
||||
/// </summary>
|
||||
/// <param name="searchVal"></param>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.FluxCountersModel> ContersGetAll(string searchVal = "")
|
||||
{
|
||||
List<DatabaseModels.FluxCountersModel> dbResult = new List<DatabaseModels.FluxCountersModel>();
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetCounters
|
||||
.Where(x => x.CodCounter.Contains(searchVal) || string.IsNullOrEmpty(searchVal))
|
||||
.OrderBy(x => x.CodCounter)
|
||||
.ToList();
|
||||
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public string CounterGetNext(string CodCounter, int numZeros)
|
||||
{
|
||||
string answ = $"{CodCounter}.0000";
|
||||
@@ -163,6 +181,38 @@ namespace SHERPA.BBM.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna un FluxCounter
|
||||
/// </summary>
|
||||
/// <param name="updItem"></param>
|
||||
/// <returns></returns>
|
||||
public bool CounterUpdate(DatabaseModels.FluxCountersModel updItem)
|
||||
{
|
||||
bool done = false;
|
||||
try
|
||||
{
|
||||
var currData = dbCtx
|
||||
.DbSetCounters
|
||||
.Where(x => x.CodCounter == updItem.CodCounter)
|
||||
.FirstOrDefault();
|
||||
if (currData != null)
|
||||
{
|
||||
dbCtx.Entry(updItem).State = System.Data.Entity.EntityState.Modified;
|
||||
}
|
||||
else
|
||||
{
|
||||
dbCtx
|
||||
.DbSetCounters
|
||||
.Add(updItem);
|
||||
}
|
||||
dbCtx.SaveChanges();
|
||||
done = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{ }
|
||||
return done;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
|
||||
@@ -32,12 +32,13 @@ namespace SHERPA.BBM
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
// Aggiungere DbSet per ogni tipo di entità che si desidera includere nel modello. Per ulteriori informazioni
|
||||
// sulla configurazione e sull'utilizzo di un modello Code, vedere http://go.microsoft.com/fwlink/?LinkId=390109.
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public virtual DbSet<DatabaseModels.BasketsModel> DbSetBaskets { get; set; }
|
||||
|
||||
// Aggiungere DbSet per ogni tipo di entità che si desidera includere nel modello. Per ulteriori informazioni
|
||||
// sulla configurazione e sull'utilizzo di un modello Code, vedere http://go.microsoft.com/fwlink/?LinkId=390109.
|
||||
public virtual DbSet<DatabaseModels.FluxCountersModel> DbSetCounters { get; set; }
|
||||
|
||||
public virtual DbSet<DatabaseModels.DocsModel> DbSetDocs { get; set; }
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace SHERPA.BBM
|
||||
/// <summary>
|
||||
/// The Precision class allows us to decorate our Entity Models with a Precision attribute
|
||||
/// to specify decimal precision values for the database column
|
||||
/// https://github.com/CypressNorth/.NET-EF6-PrecisionAnnotation
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
public class Precision : Attribute
|
||||
|
||||
Reference in New Issue
Block a user