public GeneratorBarcodePageViewModel() { SetBarcodeTypeCommand = new Command(barcodeType => BarcodeGenerator.SetBarcodeType((BarcodeType)barcodeType)); GenerateCommand = new Command( () => { try { RefreshPage(BarcodeGenerator.Generate(InputWidth, InputHeight, InputMessage)); IsValid = true; GenerationResultText = $"Success:"; } catch (Exception e) { IsValid = false; GenerationResultText = $"Failure : {e.Message}. \nCheck type is valid or not"; } }); }
private void btnGenerateBarcode_Clicked(object sender, EventArgs e) { if (btnBarcodeOptions.Active) { try { SetGeneratedBarcodeValue(BarcodeGenerator.GenerateCustom((GeneratedBarcodeType)cboBarcodeType.GetSelectedValue(), txtBarcodeFormat.Text)); } catch (InvalidDataException ex) { MessageError.ShowDialog(ex.Message, ErrorSeverity.Error, ex); } } else { try { SetGeneratedBarcodeValue(BarcodeGenerator.Generate(BusinessDomain.AppConfiguration.GeneratedBarcodeType)); } catch (InvalidDataException ex) { MessageError.ShowDialog(Translator.GetString("Barcode cannot be generated with the current settings. All barcode numbers with the specified prefix and type are in use."), ErrorSeverity.Error, ex); } } }
public async Task <ProductViewModel> Handle(AddNewProductCommand request, CancellationToken cancellationToken) { try { var newProduct = mapper.Map <Product>(request); newProduct.AssignToUser(currentUser.Id); if (request.Barcodes?.Count() > 0) { var barcodes = new HashSet <string>(request.Barcodes); foreach (var barcode in barcodes) { newProduct.BarCodes.Add(new BarCode(barcode)); } } await db.Products.AddAsync(newProduct); await db.SaveChangesAsync(cancellationToken); await db.Entry(newProduct).Reference(r => r.Category).LoadAsync(); await db.Entry(newProduct).Reference(r => r.User).LoadAsync(); newProduct.BarCodes.Add(new BarCode(BarcodeGenerator.Generate(newProduct.Category.BarcodeFriendlyId, newProduct.BarcodeFriendlyId, newProduct.User.BarcodeFriendlyId))); await db.SaveChangesAsync(cancellationToken); return(mapper.Map <ProductViewModel>(newProduct)); } catch (Exception ex) { throw; } }