308 lines
10 KiB
Plaintext
308 lines
10 KiB
Plaintext
@inject NavigationManager Navigation
|
|
@layout ConfiguracionLayout
|
|
@using BlazorBootstrap
|
|
@using System.Globalization
|
|
@using bdHerramientaCACOA.db
|
|
|
|
<Toasts class="p-3 font-weight-bold" Style="color:white;" AutoHide="true" Delay="4000" Messages="mensajes" Placement="ToastsPlacement.BottomCenter" />
|
|
|
|
<Modal @ref="popupConfirmarBorrado" title="" IsVerticallyCentered="true" UseStaticBackdrop="true" CloseOnEscape="false">
|
|
<BodyTemplate>
|
|
<div class="col-12 formatoCampos">
|
|
¿Estás seguro que desea eliminarlo?
|
|
</div>
|
|
</BodyTemplate>
|
|
<FooterTemplate>
|
|
<Button Color="ButtonColor.Secondary" @onclick="cerrarPopupConfirmarBorrado">Cerrar</Button>
|
|
<Button @onclick="@(() => BorrarItem())" Color="ButtonColor.Danger">Eliminar</Button>
|
|
</FooterTemplate>
|
|
</Modal>
|
|
|
|
<EditForm EditContext="@editContext" OnValidSubmit="guardarFormulario" OnInvalidSubmit="@MostrarErrores" FormName="costeIndiForm">
|
|
<DataAnnotationsValidator></DataAnnotationsValidator>
|
|
<Modal @ref="popupGestionDatos" title="@tituloPopup" IsVerticallyCentered="true" UseStaticBackdrop="true" CloseOnEscape="false">
|
|
<BodyTemplate>
|
|
<div class="row">
|
|
<div class="col-12 formatoCampos pt-2">
|
|
<label class="tituloLbl">Descripción:</label>
|
|
<InputText MaxLength="40" @bind-Value="descripcionItem" @oninput="e => ValidarYActualizar(e, nameof(descripcionItem))" class="inputForm"></InputText>
|
|
</div>
|
|
<div class="validation-message">@GetExternalValidationMessage(nameof(descripcionItem))</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-12 formatoCampos pt-2">
|
|
<label class="tituloLbl">Orden:</label>
|
|
<InputNumber TValue="int?" @bind-Value="ordenItem"
|
|
step="any"
|
|
class="inputForm" />
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</BodyTemplate>
|
|
<FooterTemplate>
|
|
<Button Color="ButtonColor.Secondary" @onclick="cerrarPopupGestionDatos">Cerrar</Button>
|
|
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary">@(nuevoElemento ? "Añadir" : "Modificar")</Button>
|
|
</FooterTemplate>
|
|
</Modal>
|
|
</EditForm>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<div class="d-flex justify-content-between mt-3">
|
|
<p><b class="Fuente2"></b> </p>
|
|
<button @onclick="@(() => abrirPopupGestionDatos(new enumeraciones(),true))" class="btnBlue d-flex align-items-center"> <i class="fas fa-plus-square pe-1"></i> Nuevo trabajo</button>
|
|
</div>
|
|
|
|
<Grid TItem="enumeraciones"
|
|
Class="tablaCACOA table"
|
|
Data="listadoOtrosTrabajos"
|
|
AllowFiltering="false"
|
|
PageSize="10"
|
|
FixedHeader="true"
|
|
Height="750"
|
|
Unit="Unit.Px"
|
|
EmptyText="No hay registros."
|
|
PageSizeSelectorVisible="false"
|
|
Responsive="true">
|
|
<GridColumns>
|
|
<GridColumn TItem="enumeraciones" HeaderTextAlignment="Alignment.Center" HeaderText="Descripción">
|
|
<span>@context.ValorAlfabetico1</span>
|
|
</GridColumn>
|
|
<GridColumn TItem="enumeraciones" HeaderTextAlignment="Alignment.Center" Class="columna10Ancho text-end" HeaderText="Orden">
|
|
<span>@context.Orden</span>
|
|
</GridColumn>
|
|
<GridColumn TItem="enumeraciones" Class="botonesTabla" HeaderText="">
|
|
<div class="btnTablasEspaciado">
|
|
<span @onclick="@(() => abrirPopupGestionDatos(@context,false))" class="btnBorrarGuardar">
|
|
<Icon CustomIconName="fas fa-edit"></Icon>
|
|
</span>
|
|
<span @onclick="@(() => abrirPopupConfirmarBorrado(@context))" class="btnBorrarGuardar">
|
|
<Icon CustomIconName="fas fa-trash"></Icon>
|
|
</span>
|
|
</div>
|
|
</GridColumn>
|
|
</GridColumns>
|
|
</Grid>
|
|
</div>
|
|
|
|
@code {
|
|
|
|
public List<enumeraciones> listadoOtrosTrabajos { get; set; } = new List<enumeraciones>();
|
|
|
|
[SupplyParameterFromForm]
|
|
private enumeraciones itemSeleccionado { get; set; } = new enumeraciones();
|
|
|
|
private string tituloPopup = "";
|
|
private Modal popupGestionDatos = default!;
|
|
private Modal popupConfirmarBorrado = default!;
|
|
|
|
private bool nuevoElemento;
|
|
|
|
private string descripcionItem = "";
|
|
private int? ordenItem = 0;
|
|
|
|
List<ToastMessage> mensajes = new List<ToastMessage>();
|
|
|
|
private EditContext? editContext;
|
|
private ValidationMessageStore? messageStore;
|
|
public tsHerramientasCACOA bd;
|
|
private string codigoEnumeracion = "OTROSTRAB";
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false);
|
|
|
|
editContext = new EditContext(itemSeleccionado);
|
|
messageStore = new ValidationMessageStore(editContext);
|
|
|
|
listadoOtrosTrabajos = UtilidadesCASA.devolverListadoOrdenadoEnumeracion(bd, codigoEnumeracion);
|
|
}
|
|
|
|
|
|
private async Task abrirPopupGestionDatos(enumeraciones objeto, bool esNuevo)
|
|
{
|
|
itemSeleccionado = objeto;
|
|
|
|
if (esNuevo)
|
|
{
|
|
nuevoElemento = true;
|
|
|
|
descripcionItem = "";
|
|
ordenItem = 0;
|
|
}
|
|
else
|
|
{
|
|
nuevoElemento = false;
|
|
|
|
descripcionItem = objeto.ValorAlfabetico1;
|
|
ordenItem = objeto.Orden;
|
|
}
|
|
|
|
if (!nuevoElemento)
|
|
{
|
|
tituloPopup = "Modificar trabajo";
|
|
}
|
|
else
|
|
{
|
|
tituloPopup = "Nuevo trabajo";
|
|
}
|
|
|
|
await popupGestionDatos.ShowAsync();
|
|
}
|
|
private async Task cerrarPopupGestionDatos()
|
|
{
|
|
await popupGestionDatos.HideAsync();
|
|
}
|
|
|
|
private void ValidarYActualizar(ChangeEventArgs e, string fieldName)
|
|
{
|
|
var value = e.Value?.ToString();
|
|
var field = new FieldIdentifier(itemSeleccionado, fieldName);
|
|
|
|
switch (fieldName)
|
|
{
|
|
case nameof(descripcionItem):
|
|
if (!string.IsNullOrEmpty(value))
|
|
{
|
|
|
|
descripcionItem = value;
|
|
}
|
|
else
|
|
{
|
|
descripcionItem = "";
|
|
}
|
|
break;
|
|
}
|
|
|
|
messageStore?.Clear(field);
|
|
if (fieldName == nameof(descripcionItem) && descripcionItem == "")
|
|
{
|
|
messageStore?.Add(field, "La descripción no puede estar vacía.");
|
|
}
|
|
|
|
editContext?.NotifyValidationStateChanged();
|
|
}
|
|
|
|
private void ValidarTodo()
|
|
{
|
|
ValidarYActualizar(new ChangeEventArgs { Value = descripcionItem }, nameof(descripcionItem));
|
|
}
|
|
|
|
private string GetExternalValidationMessage(string fieldName)
|
|
{
|
|
var field = new FieldIdentifier(itemSeleccionado, fieldName);
|
|
return messageStore?[field].FirstOrDefault() ?? string.Empty;
|
|
}
|
|
|
|
private async Task GestionarDatos(string accion)
|
|
{
|
|
|
|
var enumObtenido = bd.enumeraciones.Where(x => x.idEnumeracion == itemSeleccionado.idEnumeracion).FirstOrDefault();
|
|
|
|
itemSeleccionado.ValorAlfabetico1 = descripcionItem;
|
|
itemSeleccionado.Orden = ordenItem;
|
|
|
|
switch (accion)
|
|
{
|
|
case "update":
|
|
UtilidadesCASA.guardarEnumeracion(bd, itemSeleccionado, codigoEnumeracion, nuevoElemento, enumObtenido);
|
|
|
|
await cerrarPopupGestionDatos();
|
|
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Primary,
|
|
Message = $"Actualizado correctamente.",
|
|
});
|
|
|
|
break;
|
|
|
|
case "create":
|
|
UtilidadesCASA.guardarEnumeracion(bd, itemSeleccionado, codigoEnumeracion, nuevoElemento);
|
|
|
|
await cerrarPopupGestionDatos();
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Primary,
|
|
Message = $"Guardado correctamente.",
|
|
});
|
|
break;
|
|
|
|
case "delete":
|
|
UtilidadesCASA.eliminarEnumeracion(bd, enumObtenido);
|
|
await cerrarPopupConfirmarBorrado();
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Primary,
|
|
Message = $"Eliminado correctamente.",
|
|
});
|
|
break;
|
|
}
|
|
bd.SaveChanges();
|
|
listadoOtrosTrabajos = UtilidadesCASA.devolverListadoOrdenadoEnumeracion(bd, codigoEnumeracion);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
|
|
private async Task BorrarItem()
|
|
{
|
|
await GestionarDatos("delete");
|
|
}
|
|
//////// PopUp eliminar registro
|
|
private async Task abrirPopupConfirmarBorrado(enumeraciones objeto)
|
|
{
|
|
itemSeleccionado = objeto;
|
|
await popupConfirmarBorrado.ShowAsync();
|
|
}
|
|
private async Task cerrarPopupConfirmarBorrado()
|
|
{
|
|
await popupConfirmarBorrado.HideAsync();
|
|
}
|
|
|
|
// GUARDAR
|
|
private async Task guardarFormulario()
|
|
{
|
|
try
|
|
{
|
|
ValidarTodo();
|
|
|
|
if (!editContext!.GetValidationMessages().Any())
|
|
{
|
|
string accion = nuevoElemento ? "create" : "update";
|
|
await GestionarDatos(accion);
|
|
}
|
|
else
|
|
{
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Warning,
|
|
Message = $"Debe rellenar los campos obligatorios.",
|
|
});
|
|
}
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Danger,
|
|
Message = $"Error al guardar.",
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
private void MostrarErrores()
|
|
{
|
|
messageStore?.Clear();
|
|
foreach (var field in new[] { nameof(descripcionItem ) })
|
|
{
|
|
ValidarYActualizar(new ChangeEventArgs { Value = typeof(enumeraciones).GetProperty(field)?.GetValue(itemSeleccionado) }, field);
|
|
}
|
|
}
|
|
|
|
} |