diff --git a/FruitBank.Common.Server/FruitBank.Common.Server.csproj b/FruitBank.Common.Server/FruitBank.Common.Server.csproj index 2b4c5279..a14e5ec2 100644 --- a/FruitBank.Common.Server/FruitBank.Common.Server.csproj +++ b/FruitBank.Common.Server/FruitBank.Common.Server.csproj @@ -25,6 +25,9 @@ ..\..\..\..\Aycode\Source\AyCode.Core\AyCode.Services.Server\bin\FruitBank\Debug\net9.0\AyCode.Core.dll + + ..\..\..\..\Aycode\Source\AyCode.Core\AyCode.Services.Server\bin\FruitBank\Debug\net9.0\AyCode.Interfaces.dll + ..\..\..\..\Aycode\Source\AyCode.Core\AyCode.Services.Server\bin\FruitBank\Debug\net9.0\AyCode.Models.Server.dll diff --git a/FruitBank.Common/Databases/DatabaseLocalBase.cs b/FruitBank.Common/Databases/DatabaseLocalBase.cs new file mode 100644 index 00000000..bbbf1b60 --- /dev/null +++ b/FruitBank.Common/Databases/DatabaseLocalBase.cs @@ -0,0 +1,70 @@ +using System.Collections.Concurrent; +using AyCode.Core.Extensions; +using AyCode.Interfaces.Entities; + +namespace FruitBank.Common.Databases; + +public abstract class DatabaseLocalBase +{ + //private ObservableCollection a = new ObservableCollection(); + private readonly ConcurrentDictionary _database = new(); + + protected void AddTable(IList table)where TEntity: class, IEntityInt + { + if (GetTableObject() == null) + { + if (!_database.TryAdd(typeof(TEntity), table)) + return; + } + + return; + } + + protected IList? GetTableObject() where T : class, IEntityInt + { + return _database.GetValueOrDefault(typeof(T)) as IList; + } + + public IEnumerable? GetRows() where T : class, IEntityInt + { + return GetTableObject(); + } + + public T? GetRow(int id) where T : class, IEntityInt + { + return GetTableObject()?.FirstOrDefault(x => x.Id == id) as T; + } + + public T AddRow(T entity) where T : class, IEntityInt + => AddRow(GetTableObject()!, entity); + + protected T AddRow(in IList table, T entity) where T : class, IEntityInt + { + table.Add(entity); + return entity; + } + + public void AddRows(IEnumerable entities) where T : class, IEntityInt + { + var table = GetTableObject()!; + + foreach (var entity in entities) + { + AddRow(table, entity); + } + } + + public T? DeleteRow(int id) where T : class, IEntityInt + { + var table = GetTableObject(); + if (table == null) return null; + + var index = table.FindIndex(x => x.Id == id); + if (index < 0) return null; + + var entity = table[index]; + table.RemoveAt(index); + + return entity as T; + } +} \ No newline at end of file diff --git a/FruitBank.Common/Entities/ShippingDocument.cs b/FruitBank.Common/Entities/ShippingDocument.cs index 7bf36838..f9119ee2 100644 --- a/FruitBank.Common/Entities/ShippingDocument.cs +++ b/FruitBank.Common/Entities/ShippingDocument.cs @@ -1,4 +1,5 @@ -using FruitBank.Common.Interfaces; +using System.Collections.ObjectModel; +using FruitBank.Common.Interfaces; using LinqToDB.Mapping; using Mango.Nop.Core.Entities; diff --git a/FruitBank.Common/Interfaces/IPartner.cs b/FruitBank.Common/Interfaces/IPartner.cs index 2c81851c..24d5a552 100644 --- a/FruitBank.Common/Interfaces/IPartner.cs +++ b/FruitBank.Common/Interfaces/IPartner.cs @@ -1,5 +1,6 @@ using AyCode.Interfaces.Entities; using AyCode.Interfaces.TimeStampInfo; +using FruitBank.Common.Entities; namespace FruitBank.Common.Interfaces; @@ -14,4 +15,6 @@ public interface IPartner : IEntityInt, ITimeStampInfo string County { get; set; } string City { get; set; } string Street { get; set; } + + List? ShippingDocuments { get; set; } } \ No newline at end of file diff --git a/FruitBank.Common/Interfaces/IShippingDocument.cs b/FruitBank.Common/Interfaces/IShippingDocument.cs index 0ac34a4b..0030acd8 100644 --- a/FruitBank.Common/Interfaces/IShippingDocument.cs +++ b/FruitBank.Common/Interfaces/IShippingDocument.cs @@ -1,6 +1,7 @@ using AyCode.Interfaces.Entities; using AyCode.Interfaces.TimeStampInfo; using FruitBank.Common.Entities; +using System.Collections.ObjectModel; namespace FruitBank.Common.Interfaces; @@ -22,6 +23,7 @@ public interface IShippingDocument: IEntityInt, ITimeStampInfo//, IMeasured public Partner? Partner { get; set; } public Shipping? Shipping{ get; set; } public List? ShippingItems { get; set; } + public List? ShippingDocumentToFiles { get; set; } } diff --git a/FruitBankHybrid.Shared/Components/FileUploads/FileUpload.razor b/FruitBankHybrid.Shared/Components/FileUploads/FileUpload.razor new file mode 100644 index 00000000..88665cb9 --- /dev/null +++ b/FruitBankHybrid.Shared/Components/FileUploads/FileUpload.razor @@ -0,0 +1,56 @@ +@inject NavigationManager NavigationManager + +
+ + Drag and Drop File Hereor + +
+ + + +
+ Uploads are limited to a single file up to 15 MB. +
+ +@code { + [Parameter] public Func? OnFileUploaded { get; set; } + + bool UploadVisible { get; set; } = false; + + readonly List _allowedExtensions = new List { ".jpg", ".jpeg", ".gif", ".png", ".pdf", ".json" }; + readonly List _acceptedFileTypes = new List { "application/json", "application/pdf", "application/jpeg" }; + + byte[] FileBytes { get; set; } + + protected void SelectedFilesChanged(IEnumerable files) + { + //InvokeAsync(StateHasChanged); + } + + protected async Task FilesUploading(FilesUploadingEventArgs args) + { + foreach (var file in args.Files) + { + using var stream = new System.IO.MemoryStream(); + await file.OpenReadStream(file.Size).CopyToAsync(stream); + + if (OnFileUploaded != null) await OnFileUploaded(stream.ToArray()); + } + } + protected string GetUploadUrl(string url) + { + return NavigationManager.ToAbsoluteUri(url).AbsoluteUri; + } +} \ No newline at end of file diff --git a/FruitBankHybrid.Shared/Components/GridDetailOrderDto.razor b/FruitBankHybrid.Shared/Components/GridDetailOrderDto.razor index 96f4831c..72e38427 100644 --- a/FruitBankHybrid.Shared/Components/GridDetailOrderDto.razor +++ b/FruitBankHybrid.Shared/Components/GridDetailOrderDto.razor @@ -42,21 +42,6 @@ } - @* - - - - - - - - *@ ? _currentOrderDtos; @@ -59,13 +62,15 @@ private readonly Dictionary> _orderItemDtosByProductId = new(); [Parameter] public bool IsMasterGrid { get; set; } = false; - [Parameter] public List? ProductDtos { get; set; } + [Parameter] public IEnumerable? ProductDtos { get; set; } //[Parameter] public List? OrderDtos { get; set; } //[Parameter] public List? OrderItemDtos { get; set; } protected override async Task OnInitializedAsync() { - ProductDtos ??= await FruitBankSignalRClient.GetProductDtos(); + ProductDtos ??= await Database.ProductDtoTable.LoadDataAsync(true); + + //ProductDtos ??= await FruitBankSignalRClient.GetProductDtos(); // if (ProductDtos is { Count: > 0 }) // _currentOrderDtos = await GetOrderDtosFromDbAsync(ProductDtos[0].Id); diff --git a/FruitBankHybrid.Shared/Components/GridShipping.razor b/FruitBankHybrid.Shared/Components/GridShipping.razor new file mode 100644 index 00000000..e3ae6e41 --- /dev/null +++ b/FruitBankHybrid.Shared/Components/GridShipping.razor @@ -0,0 +1,157 @@ +@using FruitBank.Common.Dtos +@using FruitBank.Common.Entities +@using FruitBankHybrid.Shared.Services.SignalRs + +@inject FruitBankSignalRClient FruitBankSignalRClient + + + + + + + + + + + + + + + @if (IsMasterGrid) + { + var shipping = ((Shipping)context.DataItem); + var shippingDocuments = shipping?.ShippingDocuments?.ToList() ?? []; + + + + @{ + + + } + + + + + + + } + + + + + + + + + + + + + + + + @* + + + *@ + + + + + + + + +@code { + [Parameter] public bool IsMasterGrid { get; set; } = false; + //[Parameter] public OrderDto? OrderDto { get; set; } + [Parameter] public List? Shippings{ get; set; } + + const string ExportFileName = "ExportResult"; + string GridSearchText = ""; + bool EditItemsEnabled { get; set; } + int FocusedRowVisibleIndex { get; set; } + IGrid Grid { get; set; } + + private int _activeTabIndex; + protected override async Task OnInitializedAsync() + { + Shippings ??= (await FruitBankSignalRClient.GetShippings()) ?? []; + // OrderItemDtos = OrderDto.OrderItemDtos; + } + + async Task Grid_DataItemDeleting(GridDataItemDeletingEventArgs e) { + // await NwindDataService.RemoveEmployeeAsync((EditableEmployee)e.DataItem); + // await LoadGridDataAsync(); + // if(Data.Length == 0) + // UpdateEditItemsEnabled(false); + } + async Task Grid_EditModelSaving(GridEditModelSavingEventArgs e) { + // if(e.IsNew) { + // await NwindDataService.InsertEmployeeAsync((EditableEmployee)e.EditModel); + // UpdateEditItemsEnabled(true); + // } else + // await NwindDataService.UpdateEmployeeAsync((EditableEmployee)e.DataItem, (EditableEmployee)e.EditModel); + // await LoadGridDataAsync(); + } + async Task NewItem_Click() { + await Grid.StartEditNewRowAsync(); + } + async Task EditItem_Click() { + await Grid.StartEditRowAsync(FocusedRowVisibleIndex); + } + void DeleteItem_Click() { + Grid.ShowRowDeleteConfirmation(FocusedRowVisibleIndex); + } + void ColumnChooserItem_Click(ToolbarItemClickEventArgs e) { + Grid.ShowColumnChooser(); + } + async Task ExportXlsxItem_Click() { + await Grid.ExportToXlsxAsync(ExportFileName); + } + async Task ExportXlsItem_Click() { + await Grid.ExportToXlsAsync(ExportFileName); + } + async Task ExportCsvItem_Click() { + await Grid.ExportToCsvAsync(ExportFileName); + } + async Task ExportPdfItem_Click() { + await Grid.ExportToPdfAsync(ExportFileName); + } + protected async Task OnActiveTabChanged(int activeTabIndex) + { + _activeTabIndex = activeTabIndex; + return; + + // switch (_activeTabIndex) + // { + // case 0: + // if(ProductDtos == null) + // ProductDtos = (await FruitBankSignalRClient.GetProductDtos() ?? []); //.Where(o => o.HasMeasuringAccess(LoggedInModel.CustomerDto?.Id, LoggedInModel.IsRevisor)).OrderBy(o => o.DateOfReceipt).ToList(); + // break; + // case 1: + // if(OrderDtos == null) + // OrderDtos = (await FruitBankSignalRClient.GetAllOrderDtos() ?? []).OrderByDescending(o => o.Id).ToList(); //.Where(o => o.HasMeasuringAccess(LoggedInModel.CustomerDto?.Id, LoggedInModel.IsRevisor)).OrderBy(o => o.DateOfReceipt).ToList(); + // break; + // case 2: + // if (OrderItemDtos == null) + // OrderItemDtos = (await FruitBankSignalRClient.GetAllOrderItemDtos() ?? []).OrderByDescending(o => o.Id).ToList(); //.Where(o => o.HasMeasuringAccess(LoggedInModel.CustomerDto?.Id, LoggedInModel.IsRevisor)).OrderBy(o => o.DateOfReceipt).ToList(); + // break; + // } + } +} + diff --git a/FruitBankHybrid.Shared/Components/GridShippingDocument.razor b/FruitBankHybrid.Shared/Components/GridShippingDocument.razor index fdc76b28..895568d2 100644 --- a/FruitBankHybrid.Shared/Components/GridShippingDocument.razor +++ b/FruitBankHybrid.Shared/Components/GridShippingDocument.razor @@ -1,17 +1,37 @@ @using FruitBank.Common.Dtos @using FruitBank.Common.Entities +@using FruitBankHybrid.Shared.Components.FileUploads +@using FruitBankHybrid.Shared.Databases @using FruitBankHybrid.Shared.Services.SignalRs +@using System.Text +@using AyCode.Core.Extensions @inject FruitBankSignalRClient FruitBankSignalRClient + EditOnKeyPress="true" + ValidationEnabled="false" + EditModelSaving="Grid_EditModelSaving"> - - + + + + + + + + + + @@ -30,7 +50,7 @@ var shippingDocument = ((ShippingDocument)context.DataItem); - + @@ -57,6 +77,17 @@ + + + @*