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

@ -17,7 +17,7 @@ public class LineItem : IMetadata {
//class properties: //class properties:
public ushort Position { get; set; } public ushort Position { get; set; }
public ushort Amount { get; set; } public ushort Amount { get; set; } = 1;
public string ProductNumber { get; set; } = string.Empty; public string ProductNumber { get; set; } = string.Empty;
public string OptionNumber { get; set; } = string.Empty; public string OptionNumber { get; set; } = string.Empty;
public string? SapShortDescription { get; set; } public string? SapShortDescription { get; set; }

@ -19,13 +19,13 @@ public class Product : IMetadata {
public string? OptionNumber { get; set; } public string? OptionNumber { get; set; }
public string? SapShortDescription { get; set; } public string? SapShortDescription { get; set; }
public string? SapLongDescription { get; set; } public string? SapLongDescription { get; set; }
public float? Weight { get; set; } public float Weight { get; set; }
public string? ProductStatus { get; set; } public string? ProductStatus { get; set; }
public DateTime IntroductionDate { get; set; } = DateTime.Now; public DateTime IntroductionDate { get; set; } = DateTime.Now;
public decimal? ListPrice { get; set; } public decimal ListPrice { get; set; }
public bool? HasBreakPrices { get; set; } public bool? HasBreakPrices { get; set; }
public int? BreakRangeFrom { get; set; } public int BreakRangeFrom { get; set; }
public int? BreakRangeTo { get; set; } public int BreakRangeTo { get; set; }
//metadata: //metadata:
public DateTime DataCreationDate { get; set; } = DateTime.Now; public DateTime DataCreationDate { get; set; } = DateTime.Now;

@ -25,10 +25,10 @@
<DataGridColumns> <DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false"> <DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate> <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> </SaveCommandTemplate>
<CancelCommandTemplate> <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> </CancelCommandTemplate>
</DataGridCommandColumn> </DataGridCommandColumn>

@ -1,6 +1,5 @@
@page "/Accounts" @page "/Accounts"
@inject GenericController GenericController @inject GenericController GenericController
@using Gremlin_BlazorServer.Services @using Gremlin_BlazorServer.Services
@using Gremlin_BlazorServer.Data.EntityClasses @using Gremlin_BlazorServer.Data.EntityClasses
@inherits LayoutComponentBase @inherits LayoutComponentBase
@ -26,15 +25,15 @@
RowRemoved="@OnRowRemovedAsync" RowRemoved="@OnRowRemovedAsync"
CommandMode="DataGridCommandMode.ButtonRow" CommandMode="DataGridCommandMode.ButtonRow"
EditMode="DataGridEditMode.Popup" 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> <DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false"> <DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate> <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> </SaveCommandTemplate>
<CancelCommandTemplate> <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> </CancelCommandTemplate>
</DataGridCommandColumn> </DataGridCommandColumn>

@ -28,10 +28,10 @@
<DataGridColumns> <DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false"> <DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate> <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> </SaveCommandTemplate>
<CancelCommandTemplate> <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> </CancelCommandTemplate>
</DataGridCommandColumn> </DataGridCommandColumn>

@ -30,10 +30,10 @@
<DataGridColumns> <DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false"> <DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate> <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> </SaveCommandTemplate>
<CancelCommandTemplate> <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> </CancelCommandTemplate>
</DataGridCommandColumn> </DataGridCommandColumn>

@ -28,10 +28,10 @@
<DataGridColumns> <DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false"> <DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate> <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> </SaveCommandTemplate>
<CancelCommandTemplate> <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> </CancelCommandTemplate>
</DataGridCommandColumn> </DataGridCommandColumn>

@ -23,10 +23,10 @@
<DataGridColumns> <DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false"> <DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate> <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> </SaveCommandTemplate>
<CancelCommandTemplate> <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> </CancelCommandTemplate>
</DataGridCommandColumn> </DataGridCommandColumn>

@ -223,10 +223,10 @@
<DataGridColumns> <DataGridColumns>
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false"> <DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
<SaveCommandTemplate> <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> </SaveCommandTemplate>
<CancelCommandTemplate> <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> </CancelCommandTemplate>
</DataGridCommandColumn> </DataGridCommandColumn>

@ -2,41 +2,95 @@
@using Gremlin_BlazorServer.Data.EntityClasses @using Gremlin_BlazorServer.Data.EntityClasses
<AuthorizeView> <AuthorizeView>
<Authorized> <Authorized Context="auth">
<Div Margin="Margin.Is3" <Div Margin="Margin.Is3"
Border="Border.Dark.OnAll" Border="Border.Dark.OnAll"
Padding="Padding.Is3" Padding="Padding.Is3"
style="box-shadow: 10px 10px #343A40"> style="box-shadow: 10px 10px #343A40">
<Heading Size="HeadingSize.Is4">Quote Creation</Heading> <Heading Size="HeadingSize.Is4">Quote Creation</Heading>
<Paragraph> <Paragraph>
<Fields> <Fields>
<Field> <Field>
<FieldLabel>ProductNumber</FieldLabel> <FieldLabel>ProductNumber</FieldLabel>
<TextEdit Text="@productNumber" TextChanged="@OnSearchChanged"/> <TextEdit @bind-Text="@productNumber"/>
</Field> </Field>
<Field> <Field>
<FieldLabel>OptionNumber</FieldLabel> <FieldLabel>OptionNumber</FieldLabel>
<TextEdit> <TextEdit @bind-Text="@optionNumber"/>
<TextEdit Text="@optionNumber" TextChanged="@OnSearchChanged"/>
</TextEdit>
</Field> </Field>
<Button Color="Color.Primary" Clicked="@OnSearchProductClicked">Search</Button>
</Fields> </Fields>
</Paragraph> </Paragraph>
<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> <DataGridColumns>
<DataGridColumn Field="@nameof(Product.ProductId)" Caption="ProductId" Sortable/> <DataGridColumn Field="@nameof(Product.ProductId)" Caption="ProductId"/>
<DataGridColumn Field="@nameof(Product.ProductNumber)" Caption="ProductNumber" Sortable/> <DataGridColumn Field="@nameof(Product.ProductNumber)" Caption="ProductNumber" SortDirection="SortDirection.Ascending"/>
<DataGridColumn Field="@nameof(Product.OptionNumber)" Caption="OptionNumber" Sortable/> <DataGridColumn Field="@nameof(Product.OptionNumber)" Caption="OptionNumber" SortDirection="SortDirection.Ascending"/>
<DataGridColumn Field="@nameof(Product.SapShortDescription)" Caption="SapShortDescription" Sortable/> <DataGridColumn Field="@nameof(Product.SapShortDescription)" Caption="SapShortDescription"/>
<DataGridColumn Field="@nameof(Product.SapLongDescription)" Caption="SapLongDescription" Sortable/> <DataGridColumn Field="@nameof(Product.SapLongDescription)" Caption="SapLongDescription"/>
<DataGridColumn Field="@nameof(Product.Weight)" Caption="Weight" DisplayFormat="{0:n2} kg" Sortable/> <DataGridColumn Field="@nameof(Product.ListPrice)" Caption="ListPrice" DisplayFormat="{0:C}"/>
<DataGridColumn Field="@nameof(Product.ListPrice)" Caption="ListPrice" DisplayFormat="{0:C}" Sortable/> <DataGridColumn Field="@nameof(Product.ProductLineCode)" Caption="ProductLineCode"/>
<DataGridColumn Field="@nameof(Product.ProductLineCode)" Caption="ProductLineCode" Sortable/>
</DataGridColumns> </DataGridColumns>
</DataGrid> </DataGrid>
</Paragraph> </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> </Div>
</Authorized> </Authorized>

@ -1,4 +1,6 @@
using System.Globalization;
using System.Security.Claims; using System.Security.Claims;
using Blazorise.DataGrid;
using Gremlin_BlazorServer.Data.EntityClasses; using Gremlin_BlazorServer.Data.EntityClasses;
using Gremlin_BlazorServer.Services; using Gremlin_BlazorServer.Services;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
@ -7,10 +9,12 @@ using Microsoft.AspNetCore.Components.Authorization;
namespace Gremlin_BlazorServer.Pages.Quotes; namespace Gremlin_BlazorServer.Pages.Quotes;
public partial class QuoteCreate { public partial class QuoteCreate {
private readonly CultureInfo cultureInfo = new("de-DE");
private IList<Product>? foundProducts; private IList<Product>? foundProducts;
private IList<LineItem>? lineItems; private IList<LineItem> lineItems;
private string optionNumber = ""; private string optionNumber = "";
private string productNumber = ""; private string productNumber = "";
private List<LineItem> selectedLineItems;
private Product selectedProduct; private Product selectedProduct;
[CascadingParameter] private Task<AuthenticationState>? AuthenticationStateTask { get; set; } [CascadingParameter] private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
@ -18,14 +22,55 @@ public partial class QuoteCreate {
if (AuthenticationStateTask != null) { if (AuthenticationStateTask != null) {
ClaimsPrincipal user = (await AuthenticationStateTask).User; ClaimsPrincipal user = (await AuthenticationStateTask).User;
if (user.Identity is { IsAuthenticated: true }) { if (user.Identity is { IsAuthenticated: true }) {
// quotes = await GenericController.GetAllAsync<Quote>(); foundProducts = new List<Product>();
lineItems = new List<LineItem>();
} }
} }
await base.OnInitializedAsync(); 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();
}
} }