/// <summary> /// Tries to convert <paramref name="newValue"/> to <typeparamref name="TFirst"/> and invoke the specified <paramref name="callback"/>. /// </summary> /// <param name="newValue">The new value.</param> /// <param name="callback">The callback to invoke.</param> /// <exception cref="InvalidOperationException" /> protected async Task TriggerValueCallbackAsync(TSecond?newValue, EventCallback <TFirst> callback) { if (Converter == null) { if (newValue is TFirst castedValue) { await callback.InvokeAsync(castedValue); return; } throw new InvalidOperationException($"Cannot convert value of type '{typeof(TSecond).FullName}' to '{typeof(TFirst).FullName}'. Consider to use an converter."); } // Check whether the value can be converted if (!Converter.CanConvertBackTypeSafe <TSecond>(newValue)) { HasInvalidValue = true; return; } // Reset flag if value can be converted now if (HasInvalidValue) { HasInvalidValue = false; } // Trigger passed callback await callback.InvokeAsync( Converter.ConvertBackTypeSafe <TFirst>(newValue)); }
private void HandleCommandArgs(CommandEventArgs args) { switch (args.CommandName.ToLowerInvariant()) { case "cancel": ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = DefaultMode }).GetAwaiter().GetResult(); CurrentMode = DefaultMode; break; case "edit": ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = FormViewMode.Edit }).GetAwaiter().GetResult(); CurrentMode = FormViewMode.Edit; break; case "update": OnItemUpdating.InvokeAsync(new FormViewUpdateEventArgs("update")).GetAwaiter().GetResult(); ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = DefaultMode }).GetAwaiter().GetResult(); OnItemUpdated.InvokeAsync(new FormViewUpdatedEventArgs(0, null)).GetAwaiter().GetResult(); CurrentMode = DefaultMode; break; } StateHasChanged(); }
private void HandleCommandArgs(CommandEventArgs args) { switch (args.CommandName.ToLowerInvariant()) { case "cancel": ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = DefaultMode }).GetAwaiter().GetResult(); CurrentMode = DefaultMode; break; case "edit": ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = FormViewMode.Edit }).GetAwaiter().GetResult(); CurrentMode = FormViewMode.Edit; break; case "delete": Exception caughtException = null; try { OnItemDeleting.InvokeAsync(new FormViewDeleteEventArgs(Position)).GetAwaiter().GetResult(); } catch (Exception ex) { caughtException = ex; } // do we do the deletion? OnItemDeleted.InvokeAsync(new FormViewDeletedEventArgs(Position, caughtException)).GetAwaiter().GetResult(); CurrentMode = DefaultMode; Position = (Position == 0) ? 0 : Position - 1; break; case "insert": OnItemInserting.InvokeAsync(new FormViewInsertEventArgs("insert") { }).GetAwaiter().GetResult(); ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = FormViewMode.Insert }).GetAwaiter().GetResult(); OnItemInserted.InvokeAsync(new FormViewInsertEventArgs("insert") { }).GetAwaiter().GetResult(); CurrentMode = FormViewMode.Insert; break; case "update": OnItemUpdating.InvokeAsync(new FormViewUpdateEventArgs("update")).GetAwaiter().GetResult(); ModeChanging.InvokeAsync(new FormViewModeEventArgs() { NewMode = DefaultMode }).GetAwaiter().GetResult(); OnItemUpdated.InvokeAsync(new FormViewUpdatedEventArgs(0, null)).GetAwaiter().GetResult(); CurrentMode = DefaultMode; break; } StateHasChanged(); }
public async Task Confirmar() { try { if (accion == "Crear") { await http.PostJsonAsync("api/tipoListaPrecio", tipoListaPrecio); toastService.ShowSuccess($"Se creó correctamente el Tipo de Lista de precio {tipoListaPrecio.nombre}"); } if (accion == "Editar") { await http.PutJsonAsync($"api/tipoListaPrecio/{tipoListaPrecio.Id}", tipoListaPrecio); toastService.ShowSuccess($"Se editó correctamente el Tipo de Lista de precio {tipoListaPrecio.nombre}"); } } catch (Exception ex) { toastService.ShowError($"Ocurrió un error: {ex.Message}"); } await CloseAllModals(); await callback.InvokeAsync(new Object()); }
/// <summary> /// Handles the <see cref="E:Click" /> event. /// </summary> /// <param name="args">The <see cref="MouseEventArgs"/> instance containing the event data.</param> public async System.Threading.Tasks.Task OnClick(MouseEventArgs args) { if (!Disabled) { await Click.InvokeAsync(null); } }
public async Task CrearMovimiento() { #line default #line hidden #line 42 "C:\Users\agust\source\repos\SurcosBlazor\Client\Pages\BackOffice\Tesoreria\MovimientoInventarioForm.razor" if (!(movimiento.entra && movimiento.sale) && !(!movimiento.entra && !movimiento.sale)) { var result = await repositorio.Post("api/movimientoinventario", movimiento); if (result.Error) { toastService.ShowError(result.HttpResponseMessage.Content.ReadAsStringAsync().Result); } else { await callback.InvokeAsync(movimiento.Inventario); toastService.ShowSuccess("Se creó el movimiento correctamente"); await CloseAllModals(); } } else { toastService.ShowError("Debes seleccionar si el movimiento es de entrada o salida"); } #line default #line hidden #line 63 "C:\Users\agust\source\repos\SurcosBlazor\Client\Pages\BackOffice\Tesoreria\MovimientoInventarioForm.razor" }
public async void OnCardClick() { if (OnCard.HasDelegate) { await OnCard.InvokeAsync(Item); } }
private async Task OnValueChanged(ChangeEventArgs e) { var value = (bool)e.Value; Value = value; await ValueChanged.InvokeAsync(Value); }
public async Task SubmitCode() { var currentCode = await Editor.GetValue(); Console.WriteLine($"code submitted: {currentCode}"); await OnCodeSubmit.InvokeAsync(currentCode); }
private async Task ChangeHandle(ChangeEventArgs e) { Checked = !Checked; await CheckedChanged.InvokeAsync(Checked); await OnChanged.InvokeAsync(Checked); }
internal async Task CloseTabAsync(BTabPanelBase tab) { if (OnTabClosing.HasDelegate) { var arg = new BClosingEventArgs <BTabPanelBase>(); arg.Target = tab; await OnTabClosing.InvokeAsync(arg); if (arg.Cancel) { return; } } ResetActiveTab(tab); RequireRender = true; if (OnTabClose.HasDelegate) { _ = OnTabClose.InvokeAsync(tab); } else { StateHasChanged(); } }
//private EventCallback<ChartMouseEventArgs> OnBarElementClick { get; set;} private async Task OnBarElementClickedHandler(ChartMouseEventArgs args) { DashboardChartMouseEventArgs chartMouseEventArgs = new DashboardChartMouseEventArgs(args.DatasetIndex, args.Index, args.Model); chartMouseEventArgs.DatasetElement = CurrentDataset.Data[args.Index]; await OnDashboardChartElementClick.InvokeAsync(chartMouseEventArgs); }
private async Task InvokeOnActionBegin(ActionEventArgs <DataRow> args) { if (args.RequestType == Action.Add || args.RequestType == Action.BeginEdit) { if (args.RequestType == Action.BeginEdit) { args.Data = new DataRow(args.RowData); await args.Data.CopyFromAsync(args.RowData); } else { args.Data = new DataRow(List); } args.EditContext = new EditContext(args.Data); validationStores[args.EditContext] = new ValidationMessageStore(args.EditContext); args.EditContext.OnValidationRequested += OnValidationRequested; args.EditContext.OnFieldChanged += OnFieldChanged; } if (args.RequestType == Action.Save || args.RequestType == Action.Cancel) { var ectx = validationStores.Keys.Where(k => k.Model == args.Data).FirstOrDefault(); if (ectx != null) { validationStores.Remove(ectx); } } if (customActionBegin.HasDelegate) { await customActionBegin.InvokeAsync(args); } }
public async void OnStarClick() { if (OnStar.HasDelegate) { await OnStar.InvokeAsync(Item); } }
public async void OnDelClick() { if (OnDel.HasDelegate) { await OnDel.InvokeAsync(Item); } }
protected async Task OnInternalEachTabRenderCompleted(ITab tab) { if (OnEachTabRenderCompleted.HasDelegate) { await OnEachTabRenderCompleted.InvokeAsync(tab); } }
private async void DoOnClick(MouseEventArgs e) { if (OnClick.HasDelegate) { await OnClick.InvokeAsync(e); } }
/// <summary> /// Create anchor tag. /// </summary> /// <param name="builder"></param> /// <param name="seq"></param> /// <param name="linkType"></param> /// <param name="url"></param> /// <param name="cssClass"></param> /// <param name="receiver"></param> /// <param name="onLinkClicked"></param> /// <param name="openInNewTab"></param> /// <returns>Current sequence number</returns> public static int CreateAnchorTag(this RenderTreeBuilder builder, int seq, LinkType linkType, string url, string cssClass, object receiver, EventCallback <ClickEventArgs> onLinkClicked, bool openInNewTab = true) { builder.OpenElement(seq++, "a"); builder.AddAttribute(seq++, "class", cssClass); builder.AddAttribute(seq++, "href", url); if (openInNewTab) { builder.AddAttribute(seq++, "target", "_blank"); } if (onLinkClicked.HasDelegate) { builder.AddAttribute(seq++, "onclick", EventCallback.Factory.Create(receiver, async() => { await onLinkClicked.InvokeAsync(new ClickEventArgs { Type = linkType, Value = url }); })); } if (linkType == LinkType.Email) { var emailAddress = url.Split("mailto:").Last(); builder.AddContent(seq++, emailAddress); } else { builder.AddContent(seq++, url); } builder.CloseElement(); return(seq); }
public async void OnFinishClick() { if (OnFinish.HasDelegate) { await OnFinish.InvokeAsync(Item); } }
protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); if (firstRender) { if (Config == null) { Config = new TConfig(); } if (Config is IViewConfig viewConfig) { SetIViewConfig(viewConfig); } if (Data != null || IsNoDataRender == true) { await Create(); } if (OnFirstRender.HasDelegate) { await OnFirstRender.InvokeAsync(this); } } }
private void OnNameChanged(string value) { if (_name.NotEqualsIgnoreCase(value)) { _name = value; NameChanged.InvokeAsync(_name); } }
public async Task CustomerSelected(ChangeEventArgs args) { SelectedCustomer = (from x in Customers where x.CustomerId.ToString() == args.Value.ToString() select x).First(); await CustomerSelectEvent.InvokeAsync(SelectedCustomer); }
private Task OnIndeterminateChanged() { if (Indeterminate) { Indeterminate = false; } return(IndeterminateChanged.InvokeAsync(Indeterminate)); }
protected async Task OnInternalTabCloseAsync(MouseEventArgs e) { isCloseClicked = true; if (!OnTabClose.HasDelegate) { return; } await OnTabClose.InvokeAsync(this); }
public async Task MessageDialogResult(int value) { if (value == 1) { await EmployeeService.DeleteEmployee(Employee.EmployeeId); await OnDeleteEmployee.InvokeAsync(Employee.EmployeeId); } }
public static void SetCurrentFen(string fen) { if (_forwardFens.Count > 0) { _forwardFens.Clear(); } _previousFens.Push(_fen); _fen = fen; _fenChanged.InvokeAsync(_fen); }
protected async Task List2SearchChanged(string keywords) { list2KeyWords = keywords; if (OnList2Search.HasDelegate) { await OnList2Search.InvokeAsync(keywords); return; } }
/// <summary> /// Updates the time and notifies the subscribers outside of this component /// </summary> private void UpdateTime() { //If the time picker is disabled for picking dates, set the selected time to NULL TimeSpan?newTime = !IsEnabled ? null : new TimeSpan(Hour + (_mode == TimeMode.PM ? 12 : 0), Minute, Second); //Consider AM/PM SelectedTime = newTime; //Notify everyone using the time from the component SelectedTimeChanged.InvokeAsync(newTime); }
protected void ChangeStatus(ChangeEventArgs uIMouseEvent) { if (IsDisabled) { return; } var oldValue = new CheckBoxValue() { Status = Status }; var newValue = new CheckBoxValue(); switch (Status) { case Status.UnChecked: newValue.Status = Status.Checked; break; case Status.Checked: newValue.Status = Status.UnChecked; break; case Status.Indeterminate: newValue.Status = Status.Checked; break; } if (newValue.Status == Status.Checked) { CheckBoxGroup?.SelectedItems?.Add(Value); Value = originValue; } else { CheckBoxGroup?.SelectedItems?.Remove(Value); Value = default; } Status = newValue.Status; //有 CheckBoxGroup 时,视整个CheckBoxGroup为一个字段 if (CheckBoxGroup == null) { SetFieldValue(Value); } if (ValueChanged.HasDelegate) { _ = ValueChanged.InvokeAsync(Value); } if (StatusChanged.HasDelegate) { var args = new BChangeEventArgs <CheckBoxValue>(); args.OldValue = oldValue; args.NewValue = newValue; _ = StatusChanged.InvokeAsync(newValue.Status); } }
private async Task OnRowDeselected(RowDeselectEventArgs <DataRow> args) { if (!customRowSelected.HasDelegate && !UseListSelection) { UpdateListSelection(); } else { await customRowDeselected.InvokeAsync(args); } }