Exemple #1
0
        protected override async void HandlingBarcode(string barcode)
        {
            if (string.IsNullOrEmpty(barcode))
            {
                return;
            }
            try
            {
                IRepository <Product> productRepository = new SqlProductRepository();
                Product product = await productRepository.GetItemAsync(
                    where : ProductSpecification.GetProductsByBarcode(barcode), include : (p => p.UnitStorage, null));

                MovementGoodsInfo temp = MovementGoodsInfosList
                                         .FirstOrDefault(m => m.Product.SerialNumbersCollection.Any(s => string.IsNullOrEmpty(s.Value)));

                if (temp != null && product == null)
                {
                    temp.Product.SerialNumbersCollection.FirstOrDefault(s => string.IsNullOrEmpty(s.Value)).Value =
                        barcode;
                    return;
                }

                if (product == null)
                {
                    throw new Exception("Товар не найден");
                }

                MovementGoodsInfo movementGoodsInfo = MovementGoodsInfosList.FirstOrDefault(m => m.IdProduct == product.Id);
                if (movementGoodsInfo == null)
                {
                    movementGoodsInfo = await CreateMovementGoodInfoAsync(product);

                    MovementGoodsInfosList.Add(movementGoodsInfo);
                }
                if (!product.UnitStorage.IsWeightGoods)
                {
                    movementGoodsInfo.Count++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #2
0
        protected override async void HandlingBarcode(string barcode)
        {
            if (string.IsNullOrEmpty(barcode))
            {
                return;
            }
            try
            {
                IRepository <SerialNumber> serialNumberRepository = new SqlSerialNumberRepository();
                bool isSerialNumber =
                    await serialNumberRepository.AnyAsync(
                        where : SerialNumberSpecification.GetSerialNumbersValue(barcode));

                MovementGoodsInfo temp = MovementGoodsInfosList
                                         .FirstOrDefault(m => m.Product.SerialNumbersCollection.Any(s => string.IsNullOrEmpty(s.Value)));

                if (temp != null && !isSerialNumber)
                {
                    throw new Exception("Сначала нужно указать серийный номер к товару: \"" +
                                        temp.Product.Title +
                                        "\".\nЕсли это был серийный номер попробуйте указать его еще раз, использовать другой серийный номер, или ввести вручную");
                }

                if (temp != null)
                {
                    temp.Product.SerialNumbersCollection.FirstOrDefault(s => string.IsNullOrEmpty(s.Value)).Value =
                        barcode;
                    return;
                }

                MovementGoodsInfo movementGoodsInfo;

                if (isSerialNumber)
                {
                    SerialNumberViewModel serialNumber = new SerialNumberViewModel(
                        await serialNumberRepository.GetItemAsync(
                            where : SerialNumberSpecification.GetSerialNumbersValue(barcode), include: (s => s.Product, new Expression <Func <object, object> >[] { p => ((Product)p).UnitStorage })), MovementGoodsReport.IdDisposalStore);
                    serialNumber.Product.SerialNumbersCollection.Clear();
                    movementGoodsInfo =
                        MovementGoodsInfosList.FirstOrDefault(m => m.IdProduct == serialNumber.IdProduct);
                    if (movementGoodsInfo == null)
                    {
                        movementGoodsInfo = await CreateMovementGoodInfoAsync(serialNumber.Product);

                        MovementGoodsInfosList.Add(movementGoodsInfo);
                    }
                    serialNumber.Product =
                        movementGoodsInfo.Product;
                    movementGoodsInfo.Product.SerialNumbersCollection.Add(serialNumber);
                    movementGoodsInfo.Count++;
                    movementGoodsInfo.Product.SerialNumbersCollection.Last().Value =
                        movementGoodsInfo.Product.SerialNumbersCollection.Last().Value;
                    return;
                }
                IRepository <Product> productRepository = new SqlProductRepository();
                Product product = await productRepository.GetItemAsync(
                    where : ProductSpecification.GetProductsByBarcode(barcode), include : (p => p.UnitStorage, null));

                if (product == null)
                {
                    throw new Exception("Товар не найден");
                }

                movementGoodsInfo =
                    MovementGoodsInfosList.FirstOrDefault(m => m.IdProduct == product.Id);
                if (movementGoodsInfo == null)
                {
                    movementGoodsInfo = await CreateMovementGoodInfoAsync(product);

                    MovementGoodsInfosList.Add(movementGoodsInfo);
                }
                if (!product.UnitStorage.IsWeightGoods)
                {
                    movementGoodsInfo.Count++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }