167 lines
6.5 KiB
Plaintext
167 lines
6.5 KiB
Plaintext
@inject IMRBService mrbService
|
|
@inject ISnackbar snackbar
|
|
|
|
<MudDialog>
|
|
<DialogContent>
|
|
<MudPaper Class="p-2">
|
|
<MudForm @bind-Errors="@errors">
|
|
<MudSelect T="string"
|
|
Label="Action"
|
|
Required="true"
|
|
RequiredError="You must select an action!"
|
|
@bind-Value="@mrbAction.Action"
|
|
Text="@mrbAction.Action">
|
|
<MudSelectItem Value="@("Block")" />
|
|
<MudSelectItem Value="@("Convert")" />
|
|
<MudSelectItem Value="@("Other")" />
|
|
<MudSelectItem Value="@("Recall")" />
|
|
<MudSelectItem Value="@("Scrap")" />
|
|
<MudSelectItem Value="@("Unblock")" />
|
|
<MudSelectItem Value="@("Waiver")" />
|
|
</MudSelect>
|
|
<MudTextField T="string"
|
|
Label="Customer / Vendor"
|
|
Required="true"
|
|
RequiredError="Customer / Vendor required!"
|
|
@bind-Value="@mrbAction.Customer"
|
|
Text="@mrbAction.Customer" />
|
|
<MudTextField T="int"
|
|
Label="Qty"
|
|
Required="true"
|
|
RequiredError="You must supply a quantity!"
|
|
@bind-Value=mrbAction.Quantity
|
|
Text="@mrbAction.Quantity.ToString()" />
|
|
<MudTextField T="string"
|
|
Label="Part Number"
|
|
Required="true"
|
|
RequiredError="Part number required!"
|
|
@bind-Value="@mrbAction.PartNumber"
|
|
Text="@mrbAction.PartNumber" />
|
|
<MudTextField T="string"
|
|
Label="Batch Number / Lot Number"
|
|
Required="true"
|
|
RequiredError="Batch number / Lot number required!"
|
|
@bind-Value="@mrbAction.LotNumber"
|
|
Text="@mrbAction.LotNumber" />
|
|
</MudForm>
|
|
</MudPaper>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Tertiary"
|
|
Class="m1-auto"
|
|
OnClick=SaveMRBAction>
|
|
@if (processingSave) {
|
|
<MudProgressCircular Class="m-1" Size="Size.Small" Indeterminate="true" />
|
|
<MudText>Processing</MudText>
|
|
} else {
|
|
<MudText>Save</MudText>
|
|
}
|
|
</MudButton>
|
|
@if (mrbAction is not null && mrbAction.ActionID > 0) {
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Secondary"
|
|
Disabled="@(mrbAction is null || (mrbAction is not null && mrbAction.ActionID <= 0))"
|
|
Class="m1-auto"
|
|
OnClick=DeleteMRBAction>
|
|
@if (processingDelete) {
|
|
<MudProgressCircular Class="m-1" Size="Size.Small" Indeterminate="true" />
|
|
<MudText>Processing</MudText>
|
|
} else {
|
|
<MudText>Delete</MudText>
|
|
}
|
|
</MudButton>
|
|
}
|
|
<MudButton Variant="Variant.Filled"
|
|
Class="grey text-black m1-auto"
|
|
OnClick=Cancel>
|
|
Cancel
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter] MudDialogInstance MudDialog { get; set; }
|
|
|
|
[Parameter]
|
|
public MRBAction mrbAction { get; set; }
|
|
|
|
private bool isVisible { get; set; }
|
|
private string[] errors = { };
|
|
private bool processingSave = false;
|
|
private bool processingDelete = false;
|
|
|
|
protected override async Task OnParametersSetAsync() {
|
|
isVisible = true;
|
|
|
|
if (mrbAction is null) {
|
|
mrbAction = new() {
|
|
Action = "",
|
|
Customer = "",
|
|
Quantity = 0,
|
|
PartNumber = "",
|
|
LotNumber = "",
|
|
MRBNumber = 0
|
|
};
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
|
|
private bool FormIsValid() {
|
|
bool actionIsValid = mrbAction.Action.Equals("Block") || mrbAction.Action.Equals("Convert") ||
|
|
mrbAction.Action.Equals("Other") || mrbAction.Action.Equals("Recall") || mrbAction.Action.Equals("Scrap") ||
|
|
mrbAction.Action.Equals("Unblock") || mrbAction.Action.Equals("Waiver");
|
|
return actionIsValid && !string.IsNullOrWhiteSpace(mrbAction.Customer) &&
|
|
!string.IsNullOrWhiteSpace(mrbAction.PartNumber) &&
|
|
!string.IsNullOrWhiteSpace(mrbAction.LotNumber);
|
|
}
|
|
|
|
private async void SaveMRBAction() {
|
|
processingSave = true;
|
|
try {
|
|
if (!FormIsValid()) throw new Exception("You must complete the form before saving!");
|
|
|
|
if (mrbAction.MRBNumber > 0) {
|
|
if (mrbAction.ActionID <= 0) {
|
|
await mrbService.CreateMRBAction(mrbAction);
|
|
snackbar.Add("MRB action created", Severity.Success);
|
|
} else {
|
|
await mrbService.UpdateMRBAction(mrbAction);
|
|
snackbar.Add("MRB action updated", Severity.Success);
|
|
}
|
|
} else {
|
|
snackbar.Add("MRB action saved", Severity.Success);
|
|
}
|
|
|
|
MudDialog.Close(DialogResult.Ok(mrbAction));
|
|
} catch (Exception ex) {
|
|
snackbar.Add(ex.Message, Severity.Error);
|
|
}
|
|
processingSave = false;
|
|
}
|
|
|
|
private async void DeleteMRBAction() {
|
|
processingDelete = true;
|
|
try {
|
|
if (mrbAction is null) throw new Exception("MRB action cannot be null!");
|
|
if (mrbAction.ActionID <= 0)
|
|
throw new Exception("You cannot delete an action before creating it!");
|
|
if (mrbAction.MRBNumber <= 0)
|
|
throw new Exception("Invalid MRB number!");
|
|
|
|
await mrbService.DeleteMRBAction(mrbAction);
|
|
snackbar.Add("MRB action successfully deleted", Severity.Success);
|
|
|
|
MudDialog.Close(DialogResult.Ok<MRBAction>(null));
|
|
} catch (Exception ex) {
|
|
snackbar.Add(ex.Message, Severity.Error);
|
|
}
|
|
processingDelete = false;
|
|
}
|
|
|
|
private void Cancel() {
|
|
MudDialog.Cancel();
|
|
}
|
|
}
|