private void minusButton_Click(object sender, EventArgs e) { var rowsSelected = productsGridView.SelectedRows; if (rowsSelected.Count > 1 || rowsSelected.Count < 1) { MessageForm.ShowWarning("Only 1 row can be edited!"); return; } var productName = GetSelectedRowProductName(); var product = Session.Products.FirstOrDefault(x => x.Key.Name == productName).Key; Session.Products[product] -= 1; _totalPrice -= product.Price; if (Session.Products[product] < 0) { Session.Products[product] = 0; _totalPrice += product.Price; var result = PromptMessage.ConfirmationMessage("Are you sure you want to remove the selected product?"); if (result) { Session.Products.Remove(product); } } else { var resultFromDb = CheckProductInDatabase(product.ProductID, "minus"); } LoadDatagridView(); }
private void deleteCategory_Click(object sender, EventArgs e) { var result = PromptMessage.ConfirmationMessage("Are you sure you want to delete this record?"); if (result) { var categoryName = categoryComboBox.Text; if (categoryName == "") { MessageForm.ShowError("You haven't selected category name"); return; } using (var context = new CandyStoreDbContext()) { try { var categoryToDelete = context.Categories.FirstOrDefault(p => p.Name == categoryName); context.Categories.Remove(categoryToDelete); context.SaveChanges(); } catch (Exception ex) { MessageForm.ShowError(ex.Message); } } MessageForm.ShowSuccess("Category deleted"); FillProductsAndCategoriesComboBoxes(); } }
protected async Task <PromptResult <T> > Prompt <T>(string text, string[] buttons, T promptForm) { WaitingContext <PromptResult <T> > waitingContext = new WaitingContext <PromptResult <T> >() { WaitId = Guid.NewGuid().ToString() }; PromptMessage msg = new PromptMessage() { WaitId = waitingContext.WaitId, Text = text, PromptForm = promptForm }; waitingContext.DialogMessage = msg; RuntimeContexts.Waits.TryAdd(waitingContext.WaitId, waitingContext); if (Response.ContentType == String.Empty) { Response.StatusCode = 200; Response.ContentType = "application/json"; } // await Json(msg).ExecuteResultAsync(ControllerContext); // await ControllerContext.HttpContext.Response.Body.FlushAsync(); await SigRHub.Clients.Client(ControllerContext.HttpContext.Request.Headers["SignalRId"].SingleOrDefault()).SendAsync("Prompt", msg); Task task = Task.Factory.StartNew(async() => { await keepConnectionAlive(waitingContext.DialogResultSource.Task); }, TaskCreationOptions.LongRunning); return(await waitingContext.DialogResultSource.Task); }
protected override void Execute(CodeActivityContext context) { // TODO: VALIDATE ENTITY OR THROW EXCEPTION Mercury.Server.Workflows.UserInteractions.Request.PromptUserRequest request; request = new Mercury.Server.Workflows.UserInteractions.Request.PromptUserRequest( PromptType.Get(context), PromptImage.Get(context), PromptTitle.Get(context), PromptMessage.Get(context) ); request.AllowCancel = AllowCancel.Get(context); if (PromptSelectionItems.Get(context) != null) { request.SelectionItems = PromptSelectionItems.Get(context); } UserInteractionRequest.Set(context, request); return; }
private async void submitOrderBtn_Click(object sender, EventArgs e) { var selectedProductBoxesAndQuantitiesHash = _productsQuantityHash .Where(x => x.Key.SelectedValue != null) .ToDictionary(x => x.Key, x => x.Value); if (!selectedProductBoxesAndQuantitiesHash.Any()) { NotifyMessageBox.ShowWarning("No products selected."); return; } var selectedSupplierDto = suppliersComboBox.SelectedValue as SupplierDto; var products = new Dictionary <int, ProductDto>(); foreach (var item in selectedProductBoxesAndQuantitiesHash) { int quantity; var parsed = int.TryParse(item.Value.Text, out quantity); if (!parsed || quantity < 1) { NotifyMessageBox.ShowError("Quantity must be a whole positive number."); return; } var currentProduct = item.Key.SelectedValue as ProductDto; if (!products.ContainsKey(currentProduct.Id)) { currentProduct.Quantity = quantity; products.Add(currentProduct.Id, currentProduct); } else { products[currentProduct.Id].Quantity += quantity; } } var totalPrice = products.Sum(x => x.Value.Price * x.Value.Quantity); var confirmation = PromptMessage.ConfirmationMessage($"Are you sure you want to order? Your total price is: ${totalPrice}"); if (!confirmation) { return; } await Presenter.PlaceOrder( Mapper.Map <CustomerModel>(Constants.Customer), selectedSupplierDto.Name, Mapper.Map <ProductModel[]>(products.Values.ToArray())); NotifyMessageBox.ShowSuccess("Order request sent."); ClearProductsQuantityAndPrice(); }
private void addToCartBtn_Click(object sender, EventArgs e) { var productQuantity = productQuantityBox.Text; int quantityToNumber; bool result = int.TryParse(productQuantity, out quantityToNumber); if (result) { if (quantityToNumber <= 0) { MessageForm.ShowError("Quantity must be a positive number."); return; } var confirmationResult = PromptMessage.ConfirmationMessage("Are you sure you want to add these records to the shopping cart?"); if (!confirmationResult) { return; } using (var context = new CandyStoreDbContext()) { var productId = int.Parse(productsList.SelectedValue.ToString()); var product = context.Products.FirstOrDefault(p => p.ProductID == productId); if (product.Count < quantityToNumber) { MessageForm.ShowError("Not enough quantity on stock"); return; } else { product.Count -= quantityToNumber; if (Session.Products.ContainsKey(product)) { Session.Products[product] += quantityToNumber; } else { Session.Products.Add(product, quantityToNumber); } } context.SaveChanges(); productQuantityBox.Clear(); onStock.Text = product.Count.ToString(); } } else { MessageForm.ShowError("Quantity must be a whole positive number"); return; } }
private async Task <bool> OnPromptAsync(PromptMessage msg) { var dialog = new ContentDialog { Title = msg.Title, Content = msg.Message, PrimaryButtonText = msg.PositiveAction, DefaultButton = ContentDialogButton.Secondary, SecondaryButtonText = "Cancel" }; var result = await dialog.ShowAsync(); return(result == ContentDialogResult.Primary); }
public bool Test(T source) { bool response = _rememberChoice; if (_ask && Consoul.Ask(PromptMessage.Compile()(source))) { response = true; } if (!_asked) { if (Consoul.Ask(RememberMessage.Compile()(response))) { _rememberChoice = response; _ask = false; } _asked = true; } return(response); }
private async void closeOrderButton_Click(object sender, EventArgs e) { var selectedOrder = ordersGridView.SelectedRows[0].DataBoundItem as OrderDto; if (selectedOrder == null) { MessageForm.ShowError("No orders selected."); return; } var result = PromptMessage.ConfirmationMessage("Are you sure you want to close this order"); if (!result) { return; } await _orderService.CloseOrderAsync(selectedOrder.OrderId); MessageForm.ShowSuccess("Order close successfully."); InitializeOrdersGridView(); }
/// <summary> /// 输出之前 /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { if (string.IsNullOrWhiteSpace(this.CssClass)) { this.CssClass = "MyButton"; } else { this.CssClass += " MyButton"; } if (!string.IsNullOrEmpty(PromptMessage)) { PromptMessage = PromptMessage.Replace("\'", "\""); PromptMessage = PromptMessage.Replace("\n", ""); PromptMessage = PromptMessage.Replace("\r", ""); PromptMessage = PromptMessage.Replace("\t", ""); PromptMessage = PromptMessage.Trim(); } string validaJs; if (this.CausesValidation) //如果启动了验证 //生成脚本 { if (!string.IsNullOrWhiteSpace(PromptMessage)) { validaJs = string.Format("javascript:return Phhc_data_check_for_page_on_submit({0}, '{1}') && Show_My_Confirm('{1}')", (IsOnlyShowFirstError) ? "true" : "false", PromptMessage, TargetControlID.Trim()); } else { validaJs = string.Format("javascript:return Phhc_data_check_for_page_on_submit({0}, '{1}')", (IsOnlyShowFirstError) ? "true" : "false", TargetControlID.Trim()); } //添加脚本 if (string.IsNullOrWhiteSpace(this.OnClientClick)) { this.OnClientClick = string.Format("{0};", validaJs); } else if (this.OnClientClick.IndexOf("return Phhc_data_check_for_page_on_submit") == -1) { if (this.OnClientClick.ToUpper().IndexOf("RETURN ") != -1) { throw new Exception("您自定义的OnClientClick中不能包含return。"); } this.OnClientClick = string.Format("{0} && {1}", validaJs, this.OnClientClick); } } else if (!string.IsNullOrWhiteSpace(PromptMessage)) //如果没有启用验证并且有确认信息,那么 //生成脚本 { validaJs = string.Format("javascript:return Show_My_Confirm('{0}')", PromptMessage); //添加脚本 if (string.IsNullOrWhiteSpace(this.OnClientClick)) { this.OnClientClick = string.Format("{0};", validaJs); } else if (this.OnClientClick.IndexOf("return Show_My_Confirm") == -1) { if (this.OnClientClick.ToUpper().IndexOf("RETURN ") != -1) { throw new Exception("您自定义的OnClientClick中不能包含return。"); } this.OnClientClick = string.Format("{0} && {1}", validaJs, this.OnClientClick); } } base.OnPreRender(e); }
public async Task EnsurePresentAsync(FileSample sample, IProgress <double> progress = null, CancellationToken cancellationToken = default) { if (sample is null) { throw new ArgumentNullException(nameof(sample)); } if (await this.storage.GetIsPresentAsync(sample.Id, sample.ContentHash)) { progress?.Report(1); return; } if (!this.settings.DownloadInBackground) { Task <bool> downloadQuestionTask; if (this.downloadInBackground != null) { downloadQuestionTask = this.downloadInBackground; } else { lock (this.settings) { if (this.downloadInBackground == null) { // TODO: Localize var prompt = new PromptMessage("Download missing files", "Some of the files for these elements are missing. Would you like to download them now?", "Download"); Messenger.Default.Send(prompt); this.downloadInBackground = prompt.Result; downloadQuestionTask = this.downloadInBackground; } else { downloadQuestionTask = this.downloadInBackground; } } } if (!await downloadQuestionTask) { progress?.Report(1); return; } } IContentProviderService[] providers = await this.services.GetServicesAsync <IContentProviderService> ().ConfigureAwait(false); IContentProviderService handler = providers.FirstOrDefault(c => c.CanAcquire(sample)); ManagedDownload download = null; if (handler != null) { string id = handler.GetEntryIdFromUrl(sample.SourceUrl); if (id != null) { ContentEntry entry = await handler.GetEntryAsync(id, cancellationToken); download = QueueDownload(sample.Id, sample.Name, handler.DownloadEntryAsync(id), entry.Size, sample.ContentHash, progress, cancellationToken); } } if (download == null) { if (!Uri.TryCreate(sample.SourceUrl, UriKind.Absolute, out Uri uri)) { progress?.Report(1); throw new ArgumentException(); } if (uri.IsFile) { if (await this.storage.GetIsPresentAsync(uri)) { progress?.Report(1); return; } else { progress?.Report(1); throw new FileNotFoundException(); } } download = QueueDownload(sample.Id, sample.Name, new Uri(sample.SourceUrl), sample.ContentHash, progress, cancellationToken); } await download.Task; }
public bool GetConfirmationResult() { return(PromptMessage.ConfirmationMessage("Are you sure you want to delete this record?")); }
public bool ConfirmShoppingCartProductRemoval() { return(PromptMessage.ConfirmationMessage("Are you sure you want to remove the selected product?")); }
public bool GetProductAddToCartConfirmationResult() { return(PromptMessage.ConfirmationMessage("Are you sure you want to add these records to the shopping cart?")); }