Primera versión
This commit is contained in:
157
HerramientaCASA/Components/Pages/Comun/ClonarDespacho.razor
Normal file
157
HerramientaCASA/Components/Pages/Comun/ClonarDespacho.razor
Normal file
@@ -0,0 +1,157 @@
|
||||
@using HerramientaCASA.Components.Pages.HerramientaCASATabs.DespachoProfesionalComponents
|
||||
@using HerramientaCASA.Model
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using bdHerramientaCACOA
|
||||
@using bdHerramientaCACOA.HerramientaURBAN
|
||||
@using bdHerramientaCACOA.db
|
||||
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
@inject ProtectedSessionStorage ProtectedSessionStore
|
||||
@inject NavigationManager Navigation
|
||||
@inject UserState UserState
|
||||
|
||||
|
||||
@if (listadoSimulaciones.Count > 0)
|
||||
{
|
||||
<Modal @ref="popupGestionDatos" title="Copiar Despacho de otra Simulación" IsVerticallyCentered="false" UseStaticBackdrop="true" CloseOnEscape="false">
|
||||
<BodyTemplate>
|
||||
<div class="row">
|
||||
<p>
|
||||
Esta opción le permite copiar <b>sólo los datos de la pestaña despacho profesional</b> de una simulacion existente.
|
||||
</p>
|
||||
<p>
|
||||
<b>Se reemplazarán los datos</b> del despacho profesional <b>de la simulación actual</b>.<br />Los cambios no se almacenarán hasta que pulse en el botón Guardar/Modificar.
|
||||
</p>
|
||||
</div>
|
||||
<div class="row mt-2 mb-3">
|
||||
|
||||
<div class="col-12 formatoCampos">
|
||||
<label class="tituloLbl mb-2">¿De que simulación desea obtener los datos?</label>
|
||||
<InputSelect @bind-Value="@idFicheroObtenido" class="inputForm selectTabla">
|
||||
@foreach (var simulacion in listadoSimulaciones)
|
||||
{
|
||||
<option value="@simulacion.idFicheroJSON">@simulacion.Descripcion</option>
|
||||
}
|
||||
</InputSelect>
|
||||
</div>
|
||||
</div>
|
||||
</BodyTemplate>
|
||||
<FooterTemplate>
|
||||
<Button Color="ButtonColor.Secondary" @onclick="cerrarPopupGestionDatos">Cerrar</Button>
|
||||
<Button @onclick="clonarDespacho" Color="ButtonColor.Primary">Copiar Despacho</Button>
|
||||
</FooterTemplate>
|
||||
</Modal>
|
||||
|
||||
|
||||
<div>
|
||||
<div>
|
||||
<button @onclick="@(() => abrirPopupGestionDatos())" class="btnBlue ms-auto" style="background-color: #65b7c3 !important;"><i class="fas fa-file-import me-2"></i> Copiar despacho de otra simulación</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public ClonarDespachoVM datosDespachoClonado { get; set; } = new ClonarDespachoVM();
|
||||
|
||||
[CascadingParameter]
|
||||
public HerramientaCASA.Components.Pages.HerramientaCASATabs.DespachoProfesional _Parent { get; set; }
|
||||
|
||||
|
||||
// CAMBIAR POR LA OTRA PAGINA QUE LLAMA A CLONAR DESPACHO Y CAMBIAR ABAJO EN LA FUNCION
|
||||
[CascadingParameter]
|
||||
public HerramientaCASA.Components.Pages.HerramientaURBANTabs.DespachoProfesionalURBAN _OtroParent { get; set; }
|
||||
|
||||
private List<simulaciones> listadoSimulaciones = new List<simulaciones>();
|
||||
private int idFicheroObtenido;
|
||||
private Modal popupGestionDatos = default!;
|
||||
|
||||
public tsHerramientasCACOA bd;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false);
|
||||
|
||||
cargarListaSimulaciones();
|
||||
|
||||
idFicheroObtenido = listadoSimulaciones.Count > 0 ? listadoSimulaciones.First().idFicheroJSON : 0;
|
||||
}
|
||||
|
||||
private async void cargarListaSimulaciones()
|
||||
{
|
||||
|
||||
var idUser = await ProtectedSessionStore.GetAsync<int>("idUsuario");
|
||||
|
||||
listadoSimulaciones = bd.simulaciones.Include(x => x.idTipoSimulacionNavigation).Where(x => x.idCodigo == idUser.Value && (x.idTipoSimulacionNavigation.Codigo == "TIPOHERRAMIENTA.CASA" || x.idTipoSimulacionNavigation.Codigo == "TIPOHERRAMIENTA.URBAND") && x.idSimulacion != datosDespachoClonado.idSimulacion).ToList();
|
||||
|
||||
}
|
||||
public void RefreshState()
|
||||
{
|
||||
this.StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task cerrarPopupGestionDatos()
|
||||
{
|
||||
await popupGestionDatos.HideAsync();
|
||||
}
|
||||
private async Task abrirPopupGestionDatos()
|
||||
{
|
||||
StateHasChanged();
|
||||
await popupGestionDatos.ShowAsync();
|
||||
}
|
||||
|
||||
private void clonarDespacho()
|
||||
{
|
||||
if (_Parent != null)
|
||||
{
|
||||
var byteFichero = bd.ficheros.First(x => x.idFichero == idFicheroObtenido).Fichero;
|
||||
|
||||
string CASAJson = System.Text.Encoding.UTF8.GetString(byteFichero);
|
||||
|
||||
var casaCopiada = System.Text.Json.JsonSerializer.Deserialize<CASA>(CASAJson);
|
||||
|
||||
datosDespachoClonado.despachoProf.Trabajadores = casaCopiada.DespachoProfesional.Trabajadores;
|
||||
datosDespachoClonado.despachoProf.CostesIndirectos = casaCopiada.DespachoProfesional.CostesIndirectos;
|
||||
datosDespachoClonado.despachoProf.CostesPersonal = casaCopiada.DespachoProfesional.CostesPersonal;
|
||||
|
||||
refrescarPadre();
|
||||
StateHasChanged();
|
||||
cerrarPopupGestionDatos();
|
||||
// Navigation.NavigateTo("/HerramientaCASAS?idClonado=" + tsUtilidades.crypt.FEncS(idFicheroObtenido.ToString(), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/-*", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/-*", 875421649), true);
|
||||
|
||||
}
|
||||
else if (_OtroParent != null)
|
||||
{
|
||||
|
||||
var byteFichero = bd.ficheros.First(x => x.idFichero == idFicheroObtenido).Fichero;
|
||||
|
||||
string CASAURBANJson = System.Text.Encoding.UTF8.GetString(byteFichero);
|
||||
|
||||
var casaCopiada = System.Text.Json.JsonSerializer.Deserialize<URBAN>(CASAURBANJson);
|
||||
|
||||
datosDespachoClonado.despachoProf.Trabajadores = casaCopiada.DespachoProfesional.Trabajadores;
|
||||
datosDespachoClonado.despachoProf.CostesIndirectos = casaCopiada.DespachoProfesional.CostesIndirectos;
|
||||
datosDespachoClonado.despachoProf.CostesPersonal = casaCopiada.DespachoProfesional.CostesPersonal;
|
||||
|
||||
|
||||
refrescarPadre();
|
||||
StateHasChanged();
|
||||
cerrarPopupGestionDatos();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void refrescarPadre()
|
||||
{
|
||||
if (_Parent != null)
|
||||
{
|
||||
_Parent.hacerCalculos();
|
||||
_Parent.RefreshState();
|
||||
}
|
||||
else if (_OtroParent != null)
|
||||
{
|
||||
_OtroParent.hacerCalculos();
|
||||
_OtroParent.RefreshState();
|
||||
}
|
||||
}
|
||||
}
|
||||
505
HerramientaCASA/Components/Pages/Comun/OtrosTrabajos.razor
Normal file
505
HerramientaCASA/Components/Pages/Comun/OtrosTrabajos.razor
Normal file
@@ -0,0 +1,505 @@
|
||||
@using System.Globalization
|
||||
@using HerramientaCASA.Components.Pages.HerramientaCASATabs.CostesProduccionComponents
|
||||
@using bdHerramientaCACOA.db
|
||||
@using static bdHerramientaCACOA.CASA
|
||||
|
||||
|
||||
|
||||
<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="tiposForm">
|
||||
<DataAnnotationsValidator></DataAnnotationsValidator>
|
||||
<Modal @ref="popupGestionDatos" title="@tituloPopup" IsVerticallyCentered="true" UseStaticBackdrop="true" CloseOnEscape="false">
|
||||
<BodyTemplate>
|
||||
<div class="col-12 formatoCampos pt-2">
|
||||
<label class="tituloLbl">Trabajo:</label>
|
||||
<InputSelect @bind-Value="@itemSeleccionadoTemporal.idTrabajo" class="inputForm" @oninput="e => ValidarYActualizar(e, nameof(itemSeleccionadoTemporal.idTrabajo))">
|
||||
@foreach (var grupoTipologia in enumeracionOtrosTrabajos)
|
||||
{
|
||||
<option value="@grupoTipologia.idEnumeracion">@grupoTipologia.ValorAlfabetico1</option>
|
||||
}
|
||||
</InputSelect>
|
||||
<div class="validation-message">@GetExternalValidationMessage(nameof(itemSeleccionadoTemporal.idTrabajo))</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 formatoCampos pt-2">
|
||||
<label class="tituloLbl">Coste:</label>
|
||||
<div class="d-flex" style="gap:3px;">
|
||||
<InputNumber TValue="double" @bind-Value="itemSeleccionadoTemporal.Coste"
|
||||
step="any"
|
||||
@oninput="e => ValidarYActualizar(e, nameof(itemSeleccionadoTemporal.Coste))"
|
||||
class="inputForm text-end" /> €
|
||||
</div>
|
||||
</div>
|
||||
<div class="validation-message">@GetExternalValidationMessage(nameof(itemSeleccionadoTemporal.Coste))</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 class="mt-3">
|
||||
<div style="height: 24px;">
|
||||
<b>Otros trabajos incluidos en el Encargo</b>
|
||||
</div>
|
||||
<div style="position:relative;margin-bottom: 15px;">
|
||||
<Grid TItem="CASA.OtrosTrabajos"
|
||||
Class="tablaCACOA table"
|
||||
Data="listOtrosTrabajos"
|
||||
AllowFiltering="false"
|
||||
PageSize="10"
|
||||
Height="100"
|
||||
PageSizeSelectorVisible="false"
|
||||
EmptyText="No hay registros."
|
||||
Responsive="true">
|
||||
|
||||
<GridColumns>
|
||||
<GridColumn TItem="CASA.OtrosTrabajos" HeaderTextAlignment="Alignment.Center" HeaderText="Encargo" Class="colorA">
|
||||
@context.Denominacion
|
||||
</GridColumn>
|
||||
<GridColumn TItem="CASA.OtrosTrabajos" HeaderTextAlignment="Alignment.Center" Class="text-end" HeaderText="Precio">
|
||||
@context.Coste.MilesYDecimales() €
|
||||
</GridColumn>
|
||||
<GridColumn TItem="CASA.OtrosTrabajos" 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>
|
||||
<table class="table tablaCACOA mb-0" style="position:absolute;bottom:-33px;">
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2" class="text-end fw-bold colorC">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="mt-1">
|
||||
<button @onclick="@(() => abrirPopupGestionDatos(new CASA.OtrosTrabajos(),true))" class="btnBlue d-flex align-items-center"> <i class="fas fa-plus-square pe-1"></i> Añadir Trabajo</button>
|
||||
</div>
|
||||
<div style="align-self: center;">
|
||||
Total Otros trabajos:
|
||||
|
||||
@if (_LicitacionPadre != null)
|
||||
{
|
||||
<span> @objetoLicitaciones.TotalOtrosTrabajos.MilesYDecimales() €</span>
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
<span> @objetoCASA.CostesProduccion.TotalOtrosTrabajos.MilesYDecimales() €</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public LICITACIONES objetoLicitaciones { get; set; } = new LICITACIONES();
|
||||
|
||||
[Parameter]
|
||||
public CASA objetoCASA { get; set; } = new CASA();
|
||||
|
||||
List<CASA.OtrosTrabajos> listOtrosTrabajos = new List<CASA.OtrosTrabajos>();
|
||||
|
||||
List<enumeracionesCASA> enumeracionOtrosTrabajos = new List<enumeracionesCASA>();
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
private CASA.OtrosTrabajos itemSeleccionado { get; set; } = new CASA.OtrosTrabajos();
|
||||
|
||||
private CASA.OtrosTrabajos itemSeleccionadoTemporal { get; set; } = new CASA.OtrosTrabajos();
|
||||
|
||||
private string tituloPopup = "";
|
||||
private Modal popupGestionDatos = default!;
|
||||
private Modal popupConfirmarBorrado = default!;
|
||||
|
||||
private bool nuevoElemento;
|
||||
private ValidationMessageStore? messageStore;
|
||||
|
||||
private EditContext editContext;
|
||||
|
||||
|
||||
List<ToastMessage> mensajes = new List<ToastMessage>();
|
||||
|
||||
// PADRE LICITACIONES
|
||||
[CascadingParameter]
|
||||
public Licitaciones _LicitacionPadre { get; set; }
|
||||
|
||||
// PADRE LICITACIONES
|
||||
[CascadingParameter]
|
||||
public CostesTrabajo _HerramientaCASAPadre { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
editContext = new EditContext(itemSeleccionado);
|
||||
messageStore = new ValidationMessageStore(editContext);
|
||||
|
||||
@if (_LicitacionPadre != null)
|
||||
{
|
||||
enumeracionOtrosTrabajos = objetoLicitaciones.Enumerados.ListaOtrosTrabajos;
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
enumeracionOtrosTrabajos = objetoCASA.Enumerados.ListaOtrosTrabajos;
|
||||
}
|
||||
|
||||
cargarListado();
|
||||
}
|
||||
|
||||
private void cargarListado()
|
||||
{
|
||||
if (_LicitacionPadre != null)
|
||||
{
|
||||
listOtrosTrabajos = objetoLicitaciones.OtrosTrabajos.ToList();
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
listOtrosTrabajos = objetoCASA.CostesProduccion.OtrosTrabajos.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// CALCULOS PARA LICITACIONES
|
||||
private async void OtroTrabajoCambiadoLicitaciones(double e, CASA.OtrosTrabajos objeto)
|
||||
{
|
||||
objeto.Coste = (double)e;
|
||||
objetoLicitaciones.ActualizarOtrosTrabajos(objeto);
|
||||
objetoLicitaciones.CalcularCostesProduccion();
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
_LicitacionPadre.RefreshState();
|
||||
}
|
||||
|
||||
// CALCULOS PARA CASA
|
||||
private async void OtroTrabajoCambiadoCASA(double e, CASA.OtrosTrabajos objeto)
|
||||
{
|
||||
objeto.Coste = (double)e;
|
||||
objetoCASA.ActualizarOtrosTrabajos(objeto);
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
_HerramientaCASAPadre.RefreshState();
|
||||
}
|
||||
|
||||
|
||||
private void refrescarPadre()
|
||||
{
|
||||
if (_LicitacionPadre != null)
|
||||
{
|
||||
_LicitacionPadre.RefreshState();
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
_HerramientaCASAPadre.RefreshState();
|
||||
}
|
||||
}
|
||||
|
||||
private void comprobarPadre(string accion)
|
||||
{
|
||||
switch (accion)
|
||||
{
|
||||
case "update":
|
||||
|
||||
|
||||
if (_LicitacionPadre != null)
|
||||
{
|
||||
objetoLicitaciones.ActualizarOtrosTrabajos(itemSeleccionado);
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
objetoCASA.ActualizarOtrosTrabajos(itemSeleccionado);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "create":
|
||||
|
||||
|
||||
if (_LicitacionPadre != null)
|
||||
{
|
||||
objetoLicitaciones.InsertarOtrosTrabajos(itemSeleccionado);
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
objetoCASA.InsertarOtrosTrabajos(itemSeleccionado);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
|
||||
|
||||
if (_LicitacionPadre != null)
|
||||
{
|
||||
objetoLicitaciones.EliminarOtrosTrabajos(itemSeleccionado);
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
objetoCASA.EliminarOtrosTrabajos(itemSeleccionado);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////// PARTE DE GESTIONAR DATOS POPUP ///////////
|
||||
|
||||
private async Task GestionarDatos(string accion)
|
||||
{
|
||||
|
||||
|
||||
switch (accion)
|
||||
{
|
||||
case "update":
|
||||
|
||||
rellenarItem();
|
||||
|
||||
if (_LicitacionPadre != null)
|
||||
{
|
||||
itemSeleccionado.Denominacion = objetoLicitaciones.Enumerados.ListaOtrosTrabajos.First(x => x.idEnumeracion == itemSeleccionado.idTrabajo).ValorAlfabetico1;
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
itemSeleccionado.Denominacion = objetoCASA.Enumerados.ListaOtrosTrabajos.First(x => x.idEnumeracion == itemSeleccionado.idTrabajo).ValorAlfabetico1;
|
||||
}
|
||||
|
||||
comprobarPadre(accion);
|
||||
await cerrarPopupGestionDatos();
|
||||
|
||||
mensajes.Add(new ToastMessage
|
||||
{
|
||||
Type = ToastType.Primary,
|
||||
Message = $"Actualizado correctamente.",
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case "create":
|
||||
|
||||
rellenarItem();
|
||||
|
||||
if (_LicitacionPadre != null)
|
||||
{
|
||||
itemSeleccionado.Denominacion = objetoLicitaciones.Enumerados.ListaOtrosTrabajos.First(x => x.idEnumeracion == itemSeleccionado.idTrabajo).ValorAlfabetico1;
|
||||
}
|
||||
else if (_HerramientaCASAPadre != null)
|
||||
{
|
||||
itemSeleccionado.Denominacion = objetoCASA.Enumerados.ListaOtrosTrabajos.First(x => x.idEnumeracion == itemSeleccionado.idTrabajo).ValorAlfabetico1;
|
||||
}
|
||||
|
||||
comprobarPadre(accion);
|
||||
await cerrarPopupGestionDatos();
|
||||
mensajes.Add(new ToastMessage
|
||||
{
|
||||
Type = ToastType.Primary,
|
||||
Message = $"Guardado correctamente.",
|
||||
});
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
comprobarPadre(accion);
|
||||
await cerrarPopupConfirmarBorrado();
|
||||
mensajes.Add(new ToastMessage
|
||||
{
|
||||
Type = ToastType.Primary,
|
||||
Message = $"Eliminado correctamente.",
|
||||
});
|
||||
break;
|
||||
}
|
||||
cargarListado();
|
||||
await InvokeAsync(StateHasChanged);
|
||||
refrescarPadre();
|
||||
}
|
||||
private async Task BorrarItem()
|
||||
{
|
||||
await GestionarDatos("delete");
|
||||
}
|
||||
|
||||
private async Task abrirPopupGestionDatos(CASA.OtrosTrabajos objeto, bool esNuevo)
|
||||
{
|
||||
itemSeleccionado = objeto;
|
||||
|
||||
if (esNuevo)
|
||||
{
|
||||
nuevoElemento = true;
|
||||
itemSeleccionadoTemporal = new CASA.OtrosTrabajos();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
nuevoElemento = false;
|
||||
itemSeleccionadoTemporal = new CASA.OtrosTrabajos()
|
||||
{
|
||||
idTrabajo = objeto.idTrabajo,
|
||||
Coste = objeto.Coste,
|
||||
Denominacion = objeto.Denominacion
|
||||
};
|
||||
}
|
||||
|
||||
if (!nuevoElemento)
|
||||
{
|
||||
tituloPopup = "Modificar Trabajo";
|
||||
}
|
||||
else
|
||||
{
|
||||
tituloPopup = "Añadir 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(itemSeleccionadoTemporal, fieldName);
|
||||
|
||||
switch (fieldName)
|
||||
{
|
||||
case nameof(itemSeleccionadoTemporal.Coste):
|
||||
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
|
||||
string parseado = value.Replace(",", ".");
|
||||
itemSeleccionadoTemporal.Coste = double.Parse(parseado, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
break;
|
||||
case nameof(itemSeleccionadoTemporal.idTrabajo):
|
||||
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
|
||||
itemSeleccionadoTemporal.idTrabajo = int.Parse(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemSeleccionadoTemporal.idTrabajo = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
messageStore?.Clear(field);
|
||||
if (fieldName == nameof(itemSeleccionadoTemporal.Coste) && itemSeleccionadoTemporal.Coste <= 0)
|
||||
{
|
||||
messageStore?.Add(field, "El coste debe ser mayor que 0.");
|
||||
}
|
||||
|
||||
if (fieldName == nameof(itemSeleccionadoTemporal.idTrabajo) && itemSeleccionadoTemporal.idTrabajo == 0)
|
||||
{
|
||||
messageStore?.Add(field, "Seleccione un trabajo.");
|
||||
}
|
||||
|
||||
editContext?.NotifyValidationStateChanged();
|
||||
}
|
||||
|
||||
private void ValidarTodo()
|
||||
{
|
||||
ValidarYActualizar(new ChangeEventArgs { Value = itemSeleccionadoTemporal.Coste }, nameof(itemSeleccionadoTemporal.Coste));
|
||||
ValidarYActualizar(new ChangeEventArgs { Value = itemSeleccionadoTemporal.idTrabajo }, nameof(itemSeleccionadoTemporal.idTrabajo));
|
||||
}
|
||||
|
||||
private string GetExternalValidationMessage(string fieldName)
|
||||
{
|
||||
var field = new FieldIdentifier(itemSeleccionadoTemporal, fieldName);
|
||||
return messageStore?[field].FirstOrDefault() ?? string.Empty;
|
||||
}
|
||||
|
||||
|
||||
// GUARDAR
|
||||
private async Task guardarFormulario()
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidarTodo();
|
||||
|
||||
if (!editContext!.GetValidationMessages().Any())
|
||||
{
|
||||
string accion = nuevoElemento ? "create" : "update";
|
||||
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(itemSeleccionadoTemporal.Coste), nameof(itemSeleccionadoTemporal.idTrabajo) })
|
||||
{
|
||||
ValidarYActualizar(new ChangeEventArgs { Value = typeof(CASA.OtrosTrabajos).GetProperty(field)?.GetValue(itemSeleccionadoTemporal) }, field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////// PopUp eliminar registro
|
||||
private async Task abrirPopupConfirmarBorrado(CASA.OtrosTrabajos objeto)
|
||||
{
|
||||
itemSeleccionado = objeto;
|
||||
await popupConfirmarBorrado.ShowAsync();
|
||||
}
|
||||
private async Task cerrarPopupConfirmarBorrado()
|
||||
{
|
||||
await popupConfirmarBorrado.HideAsync();
|
||||
}
|
||||
|
||||
private async Task OnRowClick(GridRowEventArgs<CASA.OtrosTrabajos> objeto)
|
||||
{
|
||||
itemSeleccionado = objeto.Item;
|
||||
}
|
||||
|
||||
|
||||
private void rellenarItem()
|
||||
{
|
||||
itemSeleccionado.idTrabajo = itemSeleccionadoTemporal.idTrabajo;
|
||||
itemSeleccionado.Coste = itemSeleccionadoTemporal.Coste;
|
||||
itemSeleccionado.Denominacion = itemSeleccionadoTemporal.Denominacion;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user