adding of products to a list of lineitems is possible

pull/3/head
DJh2o2 2023-08-09 16:54:30 +07:00
parent a6f8e447b0
commit 6c39f5ed81
11 changed files with 201 additions and 103 deletions

@ -1,45 +1,45 @@
namespace Gremlin_BlazorServer.Data.EntityClasses;
public class LineItem : IMetadata {
//primary key:
public uint LineItemId { get; set; }
//primary key:
public uint LineItemId { get; set; }
//foreign keys:
public uint QuoteId { get; set; }
//foreign keys:
public uint QuoteId { get; set; }
// public uint? ProductId { get; set; }
public uint CustomDescriptionId { get; set; }
// public uint? ProductId { get; set; }
public uint CustomDescriptionId { get; set; }
//navigation properties:
// public Quote? Quote { get; set; }
// public Product? Product { get; set; }
// public CustomDescription? CustomDescription { get; set; }
//navigation properties:
// public Quote? Quote { get; set; }
// public Product? Product { get; set; }
// public CustomDescription? CustomDescription { get; set; }
//class properties:
public ushort Position { get; set; }
public ushort Amount { get; set; }
public string ProductNumber { get; set; } = string.Empty;
public string OptionNumber { get; set; } = string.Empty;
public string? SapShortDescription { get; set; }
public string? SapLongDescription { get; set; }
public string? ProductLine { get; set; }
public decimal TotalDiscount { get; set; }
public decimal SalesDiscount { get; set; }
public decimal PromotionalDiscount { get; set; }
public decimal ContractualDiscount { get; set; }
public decimal DemoDiscount { get; set; }
public decimal ListPrice { get; set; }
public decimal ExtendedListPrice { get; set; }
public decimal NetPrice { get; set; }
public decimal Total { get; set; }
//class properties:
public ushort Position { get; set; }
public ushort Amount { get; set; } = 1;
public string ProductNumber { get; set; } = string.Empty;
public string OptionNumber { get; set; } = string.Empty;
public string? SapShortDescription { get; set; }
public string? SapLongDescription { get; set; }
public string? ProductLine { get; set; }
public decimal TotalDiscount { get; set; }
public decimal SalesDiscount { get; set; }
public decimal PromotionalDiscount { get; set; }
public decimal ContractualDiscount { get; set; }
public decimal DemoDiscount { get; set; }
public decimal ListPrice { get; set; }
public decimal ExtendedListPrice { get; set; }
public decimal NetPrice { get; set; }
public decimal Total { get; set; }
//metadata:
public DateTime DataCreationDate { get; set; } = DateTime.Now;
public string DataModificationByUser { get; set; } = "Gremlin_BlazorServer";
public DateTime DataModificationDate { get; set; } = DateTime.Now;
public string DataStatus { get; set; } = "Active";
public DateTime DataValidFrom { get; set; } = DateTime.Now;
public DateTime DataValidUntil { get; set; } = DateTime.MaxValue;
public string? DataVersionComment { get; set; }
public uint DataVersionNumber { get; set; }
//metadata:
public DateTime DataCreationDate { get; set; } = DateTime.Now;
public string DataModificationByUser { get; set; } = "Gremlin_BlazorServer";
public DateTime DataModificationDate { get; set; } = DateTime.Now;
public string DataStatus { get; set; } = "Active";
public DateTime DataValidFrom { get; set; } = DateTime.Now;
public DateTime DataValidUntil { get; set; } = DateTime.MaxValue;
public string? DataVersionComment { get; set; }
public uint DataVersionNumber { get; set; }
}

@ -1,39 +1,39 @@
namespace Gremlin_BlazorServer.Data.EntityClasses;
public class Product : IMetadata {
//primary key:
public uint ProductId { get; set; }
//primary key:
public uint ProductId { get; set; }
//navigation properties:
public ProductLine? ProductLine { get; set; }
//navigation properties:
public ProductLine? ProductLine { get; set; }
// public List<LineItem>? LineItems { get; set; }
public CustomDescription? CustomDescription { get; set; }
// public List<LineItem>? LineItems { get; set; }
public CustomDescription? CustomDescription { get; set; }
//foreign keys
public string ProductLineCode { get; set; } = string.Empty;
public uint CustomDescriptionId { get; set; }
//foreign keys
public string ProductLineCode { get; set; } = string.Empty;
public uint CustomDescriptionId { get; set; }
//Agilent-specific properties:
public string? ProductNumber { get; set; }
public string? OptionNumber { get; set; }
public string? SapShortDescription { get; set; }
public string? SapLongDescription { get; set; }
public float? Weight { get; set; }
public string? ProductStatus { get; set; }
public DateTime IntroductionDate { get; set; } = DateTime.Now;
public decimal? ListPrice { get; set; }
public bool? HasBreakPrices { get; set; }
public int? BreakRangeFrom { get; set; }
public int? BreakRangeTo { get; set; }
//Agilent-specific properties:
public string? ProductNumber { get; set; }
public string? OptionNumber { get; set; }
public string? SapShortDescription { get; set; }
public string? SapLongDescription { get; set; }
public float Weight { get; set; }
public string? ProductStatus { get; set; }
public DateTime IntroductionDate { get; set; } = DateTime.Now;
public decimal ListPrice { get; set; }
public bool? HasBreakPrices { get; set; }
public int BreakRangeFrom { get; set; }
public int BreakRangeTo { get; set; }
//metadata:
public DateTime DataCreationDate { get; set; } = DateTime.Now;
public DateTime DataModificationDate { get; set; } = DateTime.Now;
public DateTime DataValidFrom { get; set; } = DateTime.Now;
public DateTime DataValidUntil { get; set; } = DateTime.MaxValue;
public string DataModificationByUser { get; set; } = "Gremlin_BlazorServer";
public uint DataVersionNumber { get; set; }
public string? DataVersionComment { get; set; }
public string DataStatus { get; set; } = "Active";
//metadata:
public DateTime DataCreationDate { get; set; } = DateTime.Now;
public DateTime DataModificationDate { get; set; } = DateTime.Now;
public DateTime DataValidFrom { get; set; } = DateTime.Now;
public DateTime DataValidUntil { get; set; } = DateTime.MaxValue;
public string DataModificationByUser { get; set; } = "Gremlin_BlazorServer";
public uint DataVersionNumber { get; set; }
public string? DataVersionComment { get; set; }
public string DataStatus { get; set; } = "Active";
}

@ -25,10 +25,10 @@
<DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>

@ -1,6 +1,5 @@
@page "/Accounts"
@inject GenericController GenericController
@using Gremlin_BlazorServer.Services
@using Gremlin_BlazorServer.Data.EntityClasses
@inherits LayoutComponentBase
@ -26,15 +25,15 @@
RowRemoved="@OnRowRemovedAsync"
CommandMode="DataGridCommandMode.ButtonRow"
EditMode="DataGridEditMode.Popup"
UseValidation Narrow Editable ShowPager Bordered Hoverable Sortable Filterable Striped Responsive FixedHeader>
UseValidation Narrow Editable ShowPager Bordered Hoverable Sortable Filterable Striped Responsive>
<DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate>
<Button ElementId="btnSave" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnSave" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>
@ -65,7 +64,7 @@
<NumericEdit TValue="uint" Value="Convert.ToUInt32(context.CellValue)" ValueChanged="v => context.CellValue = v"/>
</EditTemplate>
</DataGridColumn>
<DataGridColumn Field="@nameof(Account.DataModificationDate)" Caption="DataModificationDate" Filterable Sortable/>
</DataGridColumns>
@ -117,7 +116,7 @@
</Paragraph>
</Div>
</Authorized>
<NotAuthorized>
<Div Margin="Margin.Is3"
Border="Border.Dark.OnAll"

@ -28,10 +28,10 @@
<DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>

@ -30,10 +30,10 @@
<DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>

@ -28,10 +28,10 @@
<DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>

@ -23,10 +23,10 @@
<DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate>
<Button ElementId="btnSave" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnSave" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>

@ -223,10 +223,10 @@
<DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">context.LocalizationString</Button>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>

@ -2,41 +2,95 @@
@using Gremlin_BlazorServer.Data.EntityClasses
<AuthorizeView>
<Authorized>
<Authorized Context="auth">
<Div Margin="Margin.Is3"
Border="Border.Dark.OnAll"
Padding="Padding.Is3"
style="box-shadow: 10px 10px #343A40">
<Heading Size="HeadingSize.Is4">Quote Creation</Heading>
<Paragraph>
<Fields>
<Field>
<FieldLabel>ProductNumber</FieldLabel>
<TextEdit Text="@productNumber" TextChanged="@OnSearchChanged"/>
<TextEdit @bind-Text="@productNumber"/>
</Field>
<Field>
<FieldLabel>OptionNumber</FieldLabel>
<TextEdit>
<TextEdit Text="@optionNumber" TextChanged="@OnSearchChanged"/>
</TextEdit>
<TextEdit @bind-Text="@optionNumber"/>
</Field>
<Button Color="Color.Primary" Clicked="@OnSearchProductClicked">Search</Button>
</Fields>
</Paragraph>
<Paragraph>
<DataGrid TItem="Product" Data="@foundProducts" SelectedRow="@selectedProduct" SelectedRowChanged="@OnSelectedProductChanged" Narrow FixedHeader ShowPager Bordered Hoverable Sortable Striped Responsive>
<DataGrid TItem="Product" Data="@foundProducts" SelectedRow="@selectedProduct" SelectedRowChanged="@OnSelectedProductChanged" ShowPager Narrow Hoverable Sortable Striped Responsive>
<DataGridColumns>
<DataGridColumn Field="@nameof(Product.ProductId)" Caption="ProductId" Sortable/>
<DataGridColumn Field="@nameof(Product.ProductNumber)" Caption="ProductNumber" Sortable/>
<DataGridColumn Field="@nameof(Product.OptionNumber)" Caption="OptionNumber" Sortable/>
<DataGridColumn Field="@nameof(Product.SapShortDescription)" Caption="SapShortDescription" Sortable/>
<DataGridColumn Field="@nameof(Product.SapLongDescription)" Caption="SapLongDescription" Sortable/>
<DataGridColumn Field="@nameof(Product.Weight)" Caption="Weight" DisplayFormat="{0:n2} kg" Sortable/>
<DataGridColumn Field="@nameof(Product.ListPrice)" Caption="ListPrice" DisplayFormat="{0:C}" Sortable/>
<DataGridColumn Field="@nameof(Product.ProductLineCode)" Caption="ProductLineCode" Sortable/>
<DataGridColumn Field="@nameof(Product.ProductId)" Caption="ProductId"/>
<DataGridColumn Field="@nameof(Product.ProductNumber)" Caption="ProductNumber" SortDirection="SortDirection.Ascending"/>
<DataGridColumn Field="@nameof(Product.OptionNumber)" Caption="OptionNumber" SortDirection="SortDirection.Ascending"/>
<DataGridColumn Field="@nameof(Product.SapShortDescription)" Caption="SapShortDescription"/>
<DataGridColumn Field="@nameof(Product.SapLongDescription)" Caption="SapLongDescription"/>
<DataGridColumn Field="@nameof(Product.ListPrice)" Caption="ListPrice" DisplayFormat="{0:C}"/>
<DataGridColumn Field="@nameof(Product.ProductLineCode)" Caption="ProductLineCode"/>
</DataGridColumns>
</DataGrid>
</Paragraph>
<Button Color="Color.Primary" Clicked="@OnAddProductClicked">Add selected product</Button>
</Div>
<Div Margin="Margin.Is3"
Border="Border.Dark.OnAll"
Padding="Padding.Is3"
style="box-shadow: 10px 10px #343A40">
<Heading Size="HeadingSize.Is4">LineItems</Heading>
<Paragraph>
<DataGrid TItem="LineItem"
Data="@lineItems"
SelectedRows="@selectedLineItems"
SelectedRowsChanged="@OnSelectionChanged"
SelectionMode="DataGridSelectionMode.Multiple"
RowInserted="@OnLineItemInsertedAsync"
RowUpdated="@OnLineItemUpdatedAsync"
RowRemoved="@OnLineItemRemovedAsync"
CommandMode="DataGridCommandMode.ButtonRow"
EditMode="DataGridEditMode.Popup"
Narrow Editable Striped Hoverable Responsive UseValidation ShowPager>
<DataGridColumns>
<DataGridMultiSelectColumn Width="30px"></DataGridMultiSelectColumn>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate>
<Button ElementId="btnSave" Type="ButtonType.Submit" PreventDefaultOnSubmit Color="Color.Primary" Clicked="@context.Clicked">@context.LocalizationString</Button>
</SaveCommandTemplate>
<CancelCommandTemplate>
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="@context.Clicked">@context.LocalizationString</Button>
</CancelCommandTemplate>
</DataGridCommandColumn>
<DataGridColumn Field="@nameof(LineItem.Position)" Caption="Position"/>
<DataGridColumn Field="@nameof(LineItem.Amount)" Caption="Amount"/>
<DataGridColumn Field="@nameof(LineItem.ProductNumber)" Caption="ProductNumber"/>
<DataGridColumn Field="@nameof(LineItem.OptionNumber)" Caption="OptionNumber"/>
<DataGridColumn Field="@nameof(LineItem.SapShortDescription)" Caption="SapShortDescription"/>
<DataGridColumn Field="@nameof(LineItem.ListPrice)" DisplayFormat="{0:C}" DisplayFormatProvider="cultureInfo" Caption="ListPrice"/>
<DataGridColumn Field="@nameof(LineItem.SalesDiscount)" DisplayFormat="{0:n2}%" Caption="SalesDiscount"/>
<DataGridColumn Field="@nameof(LineItem.PromotionalDiscount)" DisplayFormat="{0:n2}%" Caption="PromotionalDiscount"/>
<DataGridColumn Field="@nameof(LineItem.ContractualDiscount)" DisplayFormat="{0:n2}%" Caption="ContractualDiscount"/>
<DataGridColumn Field="@nameof(LineItem.DemoDiscount)" DisplayFormat="{0:n2}%" Caption="DemoDiscount"/>
<DataGridColumn Field="@nameof(LineItem.TotalDiscount)" DisplayFormat="{0:n2}%" Caption="TotalDiscount"/>
<DataGridColumn Field="@nameof(LineItem.NetPrice)" DisplayFormat="{0:C}" DisplayFormatProvider="cultureInfo" Caption="NetPrice"/>
<DataGridColumn Field="@nameof(LineItem.Total)" DisplayFormat="{0:C}" DisplayFormatProvider="cultureInfo" Caption="Total"/>
</DataGridColumns>
<ButtonRowTemplate>
<Button Color="Color.Success" Clicked="context.NewCommand.Clicked">New</Button>
<Button Color="Color.Primary" Disabled="selectedLineItems is null" Clicked="context.EditCommand.Clicked">Edit</Button>
<Button Color="Color.Danger" Disabled="selectedLineItems is null" Clicked="context.DeleteCommand.Clicked">Delete</Button>
<Button Color="Color.Secondary" Clicked="context.ClearFilterCommand.Clicked">Clear Filter</Button>
</ButtonRowTemplate>
</DataGrid>
</Paragraph>
</Div>
</Authorized>

@ -1,4 +1,6 @@
using System.Globalization;
using System.Security.Claims;
using Blazorise.DataGrid;
using Gremlin_BlazorServer.Data.EntityClasses;
using Gremlin_BlazorServer.Services;
using Microsoft.AspNetCore.Components;
@ -7,10 +9,12 @@ using Microsoft.AspNetCore.Components.Authorization;
namespace Gremlin_BlazorServer.Pages.Quotes;
public partial class QuoteCreate {
private readonly CultureInfo cultureInfo = new("de-DE");
private IList<Product>? foundProducts;
private IList<LineItem>? lineItems;
private IList<LineItem> lineItems;
private string optionNumber = "";
private string productNumber = "";
private List<LineItem> selectedLineItems;
private Product selectedProduct;
[CascadingParameter] private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
@ -18,14 +22,55 @@ public partial class QuoteCreate {
if (AuthenticationStateTask != null) {
ClaimsPrincipal user = (await AuthenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) {
// quotes = await GenericController.GetAllAsync<Quote>();
foundProducts = new List<Product>();
lineItems = new List<LineItem>();
}
}
await base.OnInitializedAsync();
}
private async Task OnSearchChanged() => foundProducts = await GenericController.GetAllAsync<Product>(p => p.ProductNumber.Contains(productNumber) && p.OptionNumber.Contains(optionNumber));
private async Task OnSearchProductClicked() {
foundProducts = await GenericController.GetAllAsync<Product>(p => p.ProductNumber.Contains(productNumber) && p.OptionNumber.Contains(optionNumber));
Console.WriteLine($"Found {foundProducts.Count} products with ProductNumber '{productNumber}' and OptionNumber '{optionNumber}'.");
}
private Task OnSelectedProductChanged(Product product) {
selectedProduct = product;
return Task.CompletedTask;
}
private Task OnAddProductClicked() {
int position = lineItems.Count + 1;
LineItem newLineItem = new() {
Position = ushort.Parse(position.ToString()),
ProductNumber = selectedProduct.ProductNumber,
OptionNumber = selectedProduct.OptionNumber,
SapShortDescription = selectedProduct.SapShortDescription,
SapLongDescription = selectedProduct.SapLongDescription,
ListPrice = selectedProduct.ListPrice,
NetPrice = selectedProduct.ListPrice,
Total = selectedProduct.ListPrice
};
lineItems.Add(newLineItem);
Console.WriteLine($"Added {newLineItem.ProductNumber}#{newLineItem.OptionNumber} to LineItems as position {newLineItem.Position}.");
return Task.CompletedTask;
}
private Task OnSelectionChanged(List<LineItem> listOfLineItems) {
selectedLineItems = listOfLineItems;
return Task.CompletedTask;
}
private Task OnLineItemInsertedAsync(SavedRowItem<LineItem, Dictionary<string, object>> arg) {
throw new NotImplementedException();
}
private void OnSelectedProductChanged(Product product) => selectedProduct = product;
private Task OnLineItemUpdatedAsync(SavedRowItem<LineItem, Dictionary<string, object>> arg) {
throw new NotImplementedException();
}
private Task OnLineItemRemovedAsync(LineItem arg) {
throw new NotImplementedException();
}
}