コード例 #1
0
        private async Task OnRemoveInventory(object param)
        {
            if (param is Inventory)
            {
                await inventoryRepo.DeleteInventoryAsync((param as Inventory).Id);

                InventoryList.Remove(InventoryList.FirstOrDefault(x => x.Id == (param as Inventory).Id));
                alertService.Show("Usuwanie towaru", $"Usunięto towar {(param as Inventory).Name}", "Zamknij");
            }
        }
コード例 #2
0
        private async Task OnQRScanResult()
        {
            IsAnalyzing = false;
            Inventory inventory;

            inventory = await inventRepo.GetInventoryByBarcodeAsync(ScannedBarcode.Text);

            if (inventory == null)
            {
                UserDialogs.Instance.Toast($"Nie odnaleziono towaru o kodzie kreskowym {ScannedBarcode.Text}");
            }
            else
            {
                PromptResult result = await UserDialogs.Instance.PromptAsync("Podaj ilość towaru do wydania", "Wydanie towaru", "Wydaj", "Anuluj", "Ilość", InputType.Number);

                if (result.Ok)
                {
                    int quantity = Convert.ToInt32(result.Value);

                    if (quantity <= 0)
                    {
                        alertService.Show("Błąd", $"Nie można wydać towaru w ilości mniejsze lub równej 0", "Zamknij");
                    }
                    else if (quantity > inventory.Quantity)
                    {
                        alertService.Show("Błąd", $"Nie można wydać więcej towaru niż jest na magazynie", "Zamknij");
                    }
                    else
                    {
                        inventory.Quantity -= quantity;
                        bool updateResult = false;
                        try
                        {
                            updateResult = await inventRepo.UpdateInventoryAsync(inventory);

                            if (updateResult)
                            {
                                UserDialogs.Instance.Toast($"Wydano towar {inventory.Name} w ilości {quantity}", TimeSpan.FromSeconds(3));
                            }
                            else
                            {
                                UserDialogs.Instance.Toast($"Nie udało się wydać towaru {inventory.Name} w ilości {quantity}", TimeSpan.FromSeconds(3));
                            }
                        }
                        catch (Exception e)
                        {
                            alertService.Show("Błąd", $"W czasie wydawania towaru {inventory.Name} wystąpił błąd. Szczegóły: {e.Message}", "Zamknij");
                        }

                        if (inventory.Quantity == 0)
                        {
                            bool confirmResult = await UserDialogs.Instance.ConfirmAsync("Brak towaru w magazynie. Czy usunąć towar?", "Brak towaru", "Usuń", "Zamknij");

                            if (confirmResult)
                            {
                                try
                                {
                                    bool deleteResult = await inventRepo.DeleteInventoryAsync(inventory.Id);

                                    if (deleteResult)
                                    {
                                        UserDialogs.Instance.Toast($"Usunięto towar {inventory.Name}", TimeSpan.FromSeconds(3));
                                    }
                                    else
                                    {
                                        UserDialogs.Instance.Toast($"Nie udało się usunąć towaru {inventory.Name}", TimeSpan.FromSeconds(3));
                                    }
                                }
                                catch (Exception e)
                                {
                                    alertService.Show("Błąd", $"W czasie usuwania towaru wystąpił błąd. Szczegóły: {e.Message}", "Zamknij");
                                }
                            }
                        }
                    }
                }
            }

            IsAnalyzing = true;
        }