MeasuringIn improvements

This commit is contained in:
Loretta 2025-09-20 05:39:20 +02:00
parent 4410d662d8
commit c4061dae6f
2 changed files with 112 additions and 46 deletions

View File

@ -1,4 +1,5 @@
@page "/MeasuringIn" @page "/MeasuringIn"
@using AyCode.Utils.Extensions
@using DevExpress.Blazor @using DevExpress.Blazor
@using DevExpress.Blazor.Internal @using DevExpress.Blazor.Internal
@using FruitBank.Common.Entities @using FruitBank.Common.Entities
@ -9,50 +10,78 @@
<div style="margin-top: 50px;"> <div style="margin-top: 50px;">
<DxFormLayout CaptionPosition="CaptionPosition.Vertical" CssClass="w-100"> <DxFormLayout CaptionPosition="CaptionPosition.Vertical" CssClass="w-100">
<DxFormLayoutItem ColSpanMd="12"> <DxFormLayoutItem Caption="Érkezés dátuma" ColSpanMd="2">
<DxCheckBox CheckedChanged="@((bool t) => OnChkAllShippingChanged(t))">Összes szállítmány listázása</DxCheckBox> <DxDateEdit CssClass="cw-320"
DisplayFormat="m"
Format="m"
Context="ctxShippingDate"
Date="@(SelectedShipping?.ShippingDate.Date ?? DateTime.Now.Date)"
CustomDisabledDate="@OnCustomDisabledDate"
DateChanged="@((DateTime newValue) => OnSelectedShippingDateChanged(newValue))"
InputId="deDisabledDates">
<DayCellTemplate>
@{
var cssClass = GetCssClassNames(ctxShippingDate);
if (!cssClass.IsNullOrWhiteSpace())
{
<a class="@GetCssClassNames(ctxShippingDate)">@ctxShippingDate.Day.ToString()</a>
}
else
{
<a>@ctxShippingDate.Day.ToString()</a>
}
}
</DayCellTemplate>
</DxDateEdit>
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem Caption="Szállítmány:" ColSpanMd="4" BeginRow="true"> <DxFormLayoutItem Caption="Kamion rendszáma:" ColSpanMd="2">
<DxComboBox Data="@NotMeasuredShippings" <DxComboBox Data="@NotMeasuredShippings"
@bind-Value="@SelectedShipping" @bind-Value="@SelectedShipping"
Text="Select shipping" Text="Select licence plate"
ValueFieldName="@nameof(Shipping.Id)" ValueFieldName="@nameof(Shipping.Id)"
TextFieldName="@nameof(Shipping.ShippingDate)" TextFieldName="@nameof(Shipping.LicencePlate)"
CssClass="cw-480" CssClass="cw-480"
SelectedDataItemChanged="@((SelectedDataItemChangedEventArgs<Shipping> args) => OnSelectedShippingChanged(args))" Context="ctxShipping"
InputId="cbNotMeasuredShippings"> SelectedDataItemChanged="@((SelectedDataItemChangedEventArgs<Shipping> args) => OnSelectedShippingChanged(args))"
<ItemDisplayTemplate Context="ctxCombo"> InputId="cbNotMeasuredShippings">
<div class="combobox-item-template"> <ItemDisplayTemplate>
<div class="combobox-item-template-text"> <span class="@(ctxShipping.DataItem.IsAllMeasured ? "text-success" : "")">@ctxShipping.DisplayText</span>
<span>@($"{ctxCombo.DataItem.ShippingDate} [{ctxCombo.DataItem.LicencePlate}]")</span>
@* <span class="combobox-item-template-employee-phone">@(string.Join("; ", context.DataItem?.ShippingDocuments?.Select(x => x.Partner?.Name ?? string.Empty)))</span> *@
</div>
</div>
</ItemDisplayTemplate> </ItemDisplayTemplate>
</DxComboBox> </DxComboBox>
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem Caption="Dokumentum:" ColSpanMd="4"> <DxFormLayoutItem Caption="Partner:" ColSpanMd="3">
<DxComboBox Data="@SelectedShipping?.ShippingDocuments" <DxComboBox Data="@SelectedShipping?.ShippingDocuments"
@bind-Value="@SelectedShippingDocument" @bind-Value="@SelectedShippingDocument"
Text="Select document" Text="Select partner"
ValueFieldName="@nameof(ShippingDocument.Id)" ValueFieldName="@nameof(ShippingDocument.Id)"
TextFieldName="@(nameof(ShippingDocument.Partner) + '.' + nameof(Partner.Name))" TextFieldName="@(nameof(ShippingDocument.Partner) + '.' + nameof(Partner.Name))"
CssClass="cw-480" CssClass="cw-480"
Context="ctxShippingDocument"
SelectedDataItemChanged="@((SelectedDataItemChangedEventArgs<ShippingDocument> args) => OnSelectedShippingDocumentChanged(args))" SelectedDataItemChanged="@((SelectedDataItemChangedEventArgs<ShippingDocument> args) => OnSelectedShippingDocumentChanged(args))"
InputId="cbShippingDocument"/> InputId="cbShippingDocument">
<ItemDisplayTemplate>
<span class="@(ctxShippingDocument.DataItem.IsAllMeasured ? "text-success" : "")">@ctxShippingDocument.DisplayText</span>
</ItemDisplayTemplate>
</DxComboBox>
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem Caption="Termék:" ColSpanMd="4"> <DxFormLayoutItem Caption="Termék:" ColSpanMd="5">
<DxComboBox Data="@SelectedShippingDocument?.ShippingItems" <DxComboBox Data="@SelectedShippingDocument?.ShippingItems"
@bind-Value="@SelectedShippingItem" @bind-Value="@SelectedShippingItem"
Text="Select item" Text="Select item"
ValueFieldName="@nameof(ShippingItem.Id)" ValueFieldName="@nameof(ShippingItem.Id)"
TextFieldName="@(nameof(ShippingItem.Name))" TextFieldName="@(nameof(ShippingItem.Name))"
CssClass="cw-480" CssClass="cw-480"
Context="ctxShippingitem"
SelectedDataItemChanged="@((SelectedDataItemChangedEventArgs<ShippingItem> args) => OnSelectedShippingItemChanged(args))" SelectedDataItemChanged="@((SelectedDataItemChangedEventArgs<ShippingItem> args) => OnSelectedShippingItemChanged(args))"
InputId="cbShippingItem"/> InputId="cbShippingItem">
<ItemDisplayTemplate>
<span class="@(ctxShippingitem.DataItem.IsMeasured ? "text-success" : "")">@ctxShippingitem.DisplayText)</span>
</ItemDisplayTemplate>
</DxComboBox>
</DxFormLayoutItem> </DxFormLayoutItem>
</DxFormLayout> </DxFormLayout>
</div> </div>
@ -61,23 +90,23 @@
@if (SelectedShippingItem != null) @if (SelectedShippingItem != null)
{ {
<EditForm Model="@SelectedShippingItem" Context="FrmContext" <EditForm Model="@SelectedShippingItem" Context="FrmContext"
OnValidSubmit="@HandleValidSubmit" OnValidSubmit="@HandleValidSubmit"
OnInvalidSubmit="@HandleInvalidSubmit"> OnInvalidSubmit="@HandleInvalidSubmit">
<DataAnnotationsValidator/> <DataAnnotationsValidator />
<DxFormLayout Data="@SelectedShippingItem" CaptionPosition="CaptionPosition.Vertical" CssClass="w-100" ItemUpdating="@((pair) => OnItemUpdating(pair.Key, pair.Value))"> <DxFormLayout Data="@SelectedShippingItem" CaptionPosition="CaptionPosition.Vertical" CssClass="w-100" ItemUpdating="@((pair) => OnItemUpdating(pair.Key, pair.Value))">
<DxFormLayoutItem Field="@nameof(ShippingItem.Name)" Caption="Item Name:" ColSpanMd="4" /> <DxFormLayoutItem Field="@nameof(ShippingItem.Name)" Caption="Item Name:" Enabled="false" ColSpanMd="6" />
<DxFormLayoutItem Field="@nameof(ShippingItem.GrossWeight)" Caption="GrossWeight:" ColSpanMd="4" /> <DxFormLayoutItem Field="@nameof(ShippingItem.GrossWeight)" Caption="GrossWeight:" Enabled="false" ColSpanMd="3" />
<DxFormLayoutItem Field="@nameof(ShippingItem.NetWeight)" Caption="NetWeight:" ColSpanMd="4" /> <DxFormLayoutItem Field="@nameof(ShippingItem.NetWeight)" Caption="NetWeight:" Enabled="false" ColSpanMd="3" />
<DxFormLayoutItem Field="@nameof(ShippingItem.MeasuredGrossWeight)" Caption="MeasuredGrossWeight:" ColSpanMd="4"> <DxFormLayoutItem Field="@nameof(ShippingItem.MeasuredGrossWeight)" Caption="MeasuredGrossWeight:" ColSpanMd="3" BeginRow="true">
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem Field="@nameof(ShippingItem.MeasuredNetWeight)" Caption="MeasuredNetWeight:" ColSpanMd="4"> <DxFormLayoutItem Field="@nameof(ShippingItem.MeasuredNetWeight)" Caption="MeasuredNetWeight:" ColSpanMd="3">
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem Field="@nameof(ShippingItem.IsMeasured)" Caption="IsMeasured:" ColSpanMd="4"> <DxFormLayoutItem Field="@nameof(ShippingItem.IsMeasured)" Enabled="false" Caption="IsMeasured:" ColSpanMd="6">
</DxFormLayoutItem> </DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="12" BeginRow="true"> <DxFormLayoutItem ColSpanMd="12" BeginRow="true">
<ValidationSummary /> <ValidationSummary />
</DxFormLayoutItem> </DxFormLayoutItem>

View File

@ -17,6 +17,7 @@ using System.Linq;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using DevExpress.Data.Mask.Internal;
using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Forms;
using static System.Net.Mime.MediaTypeNames; using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType; using static System.Runtime.InteropServices.JavaScript.JSType;
@ -24,6 +25,17 @@ using ILogger = FruitBank.Common.Loggers.ILogger;
namespace FruitBankHybrid.Shared.Pages namespace FruitBankHybrid.Shared.Pages
{ {
public class ShippingDateModel
{
public DateTime DateTime { get; set; }
public bool IsMeasured { get; set; }
public ShippingDateModel(DateTime dateTime, bool isMeasured)
{
DateTime = dateTime;
IsMeasured = isMeasured;
}
}
public partial class MeasuringIn : ComponentBase public partial class MeasuringIn : ComponentBase
{ {
[Inject] public required IEnumerable<IAcLogWriterClientBase> LogWriters { get; set; } [Inject] public required IEnumerable<IAcLogWriterClientBase> LogWriters { get; set; }
@ -36,8 +48,10 @@ namespace FruitBankHybrid.Shared.Pages
private ShippingDocument? SelectedShippingDocument { get; set; } private ShippingDocument? SelectedShippingDocument { get; set; }
private ShippingItem? SelectedShippingItem { get; set; } private ShippingItem? SelectedShippingItem { get; set; }
DateTime DateTimeValue { get; set; } = DateTime.Today;
protected bool BtnSaveEnabled { get; set; } protected bool BtnSaveEnabled { get; set; }
protected bool ChkAllShipping { get; set; }
private List<ShippingDateModel> _shippingDates = null!;
private string _userName = "Partner name"; private string _userName = "Partner name";
private string _message = string.Empty; private string _message = string.Empty;
@ -48,24 +62,47 @@ namespace FruitBankHybrid.Shared.Pages
_logger = new LoggerClient<MeasuringIn>(LogWriters.ToArray()); _logger = new LoggerClient<MeasuringIn>(LogWriters.ToArray());
_logger.Info("OnInitializedAsync"); _logger.Info("OnInitializedAsync");
await RefreshShippingsFromDb(ChkAllShipping); await RefreshShippingsFromDb(DateTime.Now);
await base.OnInitializedAsync(); await base.OnInitializedAsync();
} }
private async Task RefreshShippingsFromDb(bool getAllShipping) private async Task RefreshShippingsFromDb(DateTime dateTime)
{ {
if (getAllShipping) NotMeasuredShippings = await FruitBankSignalRClient.GetShippings() ?? []; var shippings = await FruitBankSignalRClient.GetShippings() ?? [];
else NotMeasuredShippings = await FruitBankSignalRClient.GetNotMeasuredShippings() ?? [];
_shippingDates = shippings.Select(x => new ShippingDateModel(x.ShippingDate.Date, x.IsAllMeasured)).ToList();
NotMeasuredShippings = shippings.Where(x => DaysEqual(x.ShippingDate.Date, dateTime)).ToList();
//if (getAllShipping) NotMeasuredShippings = await FruitBankSignalRClient.GetShippings() ?? [];
//else NotMeasuredShippings = await FruitBankSignalRClient.GetNotMeasuredShippings() ?? [];
SelectedShipping = NotMeasuredShippings.FirstOrDefault(); SelectedShipping = NotMeasuredShippings.FirstOrDefault();
} }
private async Task OnChkAllShippingChanged(bool value) private async Task OnSelectedShippingDateChanged(DateTime selectedDateTime)
=> await RefreshShippingsFromDb(selectedDateTime);
private void OnCustomDisabledDate(CalendarCustomDisabledDateEventArgs args)
=> args.IsDisabled = !_shippingDates.Exists(shippingDateModel => DaysEqual(shippingDateModel.DateTime, args.Date));
private string GetCssClassNames(DateTime date)
{ {
ChkAllShipping = value; if (_shippingDates.Exists(shipping => !shipping.IsMeasured && shipping.DateTime.Date <= DateTime.Now.Date && DaysEqual(shipping.DateTime, date)))
await RefreshShippingsFromDb(ChkAllShipping); return "fw-bold text-danger";
if (_shippingDates.Exists(shipping => shipping.IsMeasured && DaysEqual(shipping.DateTime, date)))
return "fw-bold text-success";
if (_shippingDates.Exists(shipping => !shipping.IsMeasured && DaysEqual(shipping.DateTime, date)))
return "fw-bold";
return string.Empty;
} }
private static bool DaysEqual(DateTime date1, DateTime date2)
=> (date1.Year == date2.Year && date1.DayOfYear == date2.DayOfYear);
private void OnSelectedShippingChanged(SelectedDataItemChangedEventArgs<Shipping> eventArgs) private void OnSelectedShippingChanged(SelectedDataItemChangedEventArgs<Shipping> eventArgs)
{ {
SelectedShippingDocument = eventArgs.DataItem?.ShippingDocuments?.FirstOrDefault(); SelectedShippingDocument = eventArgs.DataItem?.ShippingDocuments?.FirstOrDefault();
@ -102,11 +139,11 @@ namespace FruitBankHybrid.Shared.Pages
SelectedShippingItem.MeasuredGrossWeight = shippingItemFromDb.MeasuredGrossWeight; SelectedShippingItem.MeasuredGrossWeight = shippingItemFromDb.MeasuredGrossWeight;
SelectedShippingItem.IsMeasured = shippingItemFromDb.IsMeasured; SelectedShippingItem.IsMeasured = shippingItemFromDb.IsMeasured;
if (SelectedShippingItem is { IsMeasured: true }) //if (SelectedShippingItem is { IsMeasured: true })
{ //{
SelectedShippingDocument?.ShippingItems?.Remove(SelectedShippingItem); // SelectedShippingDocument?.ShippingItems?.Remove(SelectedShippingItem);
SelectedShippingItem = SelectedShippingDocument?.ShippingItems?.FirstOrDefault(); // SelectedShippingItem = SelectedShippingDocument?.ShippingItems?.FirstOrDefault();
} //}
StateHasChanged(); StateHasChanged();
} }