Ejemplo n.º 1
0
        public void KeyReturn()
        {
            var barcode = xProduct.Text.Trim();

            if (barcode.Length > 0)
            {
                var count = barcode.Split('-').Length;
                lrendu.Content = "Rendu: " + RepositoryCurrencyRelations.Residue().ToString("0.00") + " €";

                if (count != 4)
                {
                    decimal qty = 1;

                    // Сток
                    if (BlockStock.Visibility == Visibility.Visible)
                    {
                        var product = RepositoryProduct.GetByBarcode(barcode);
                        if (product != null)
                        {
                            qty = GetQtyFromBarcode(product.CodeBare, barcode);
                            var resultQty = qty != 1 ? qty : FunctionsService.GetQty(qty_label);
                            var productBc = new ProductBc(product, resultQty);
                            _stocks.Add(productBc);

                            xProduct.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
                            xProduct.Text       = "";
                        }
                        else
                        {
                            FunctionsService.ShowMessageTime(Properties.Resources.LabelProductNotFind);
                        }
                    }
                    else
                    {
                        var xP = RepositoryProduct.GetXElementByBarcode(barcode);

                        if (xP != null)
                        {
                            qty = GetQtyFromBarcode(xP.GetXElementValue("CodeBare"), barcode);
                        }

                        if (xP != null)
                        {
                            try
                            {
                                CheckService.AddProductCheck(xP, qty != 1 ? qty : FunctionsService.GetQty(qty_label));
                                xProduct.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
                                xProduct.Text       = "";
                            }
                            catch (System.Exception ex)
                            {
                                LogService.Log(TraceLevel.Error, 3, "Barcode :" + barcode + " " + ex.Message + ".");
                            }
                        }
                        else
                        {
                            if (count == 10)
                            {
                                var cent = int.Parse(barcode.Substring(barcode.Length - 2, 2));
                                var sd   = barcode.Substring(barcode.Length - 11, 8).Replace("-", "");
                                var euro = int.Parse(sd);
                                var m    = ((decimal)(euro * 100 + cent)) / 100;
                                qty_label.Text = m.ToString();
                            }
                            else
                            {
                                if (barcode.Length == 13)
                                {
                                    xP = RepositoryProduct.GetXElementByBarcode(barcode.Substring(0, 7));

                                    if (xP != null)
                                    {
                                        var qtyCurrent = decimal.Parse(barcode.Substring(7, 5)) / 1000;
                                        CheckService.AddProductCheck(xP, qtyCurrent);
                                        xProduct.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
                                        xProduct.Text       = "";
                                    }
                                }

                                if (xP == null && barcode.Length == 13)
                                {
                                    xP = RepositoryProduct.GetXElementByBarcode(barcode.Substring(0, 8));

                                    if (xP != null)
                                    {
                                        var qtyCurrent = decimal.Parse(barcode.Substring(8, 4)) / 1000;
                                        CheckService.AddProductCheck(xP, qtyCurrent);
                                        xProduct.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
                                        xProduct.Text       = "";
                                    }
                                }

                                if (xP == null)
                                {
                                    try
                                    {
                                        xProduct.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                                        xProduct.Text       = "";
                                        ClassEtcFun.WmSound(@"Data\Computer_Error.wav");
                                        var result = FunctionsService.ShowMessage(Properties.Resources.BtnAdd,
                                                                                  "Cet article n'existe pas! Ajouter un article?", Properties.Resources.BtnAdd);
                                        if (result)
                                        {
                                            var windowAddProduct = new WAddProduct {
                                                xCodeBar = { Text = barcode }
                                            };
                                            windowAddProduct.ShowDialog();
                                        }
                                    }
                                    catch (System.Exception ex)
                                    {
                                        LogService.Log(TraceLevel.Error, 4,
                                                       "Barcode :" + barcode + " " + ex.Message + ".");
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (RepositoryDiscount.Client.Barcode == barcode)
                    {
                        RepositoryDiscount.RestoreDiscount();
                        CheckService.DiscountCalc();
                        FunctionsService.WriteTotal();
                    }
                    else
                    {
                        var discountCard = RepositoryDiscount.GetDiscount(barcode);
                        if (discountCard == null)
                        {
                            FunctionsService.ShowMessageSb("La carte n'existe pas ");
                        }
                        else if (discountCard.IsActive)
                        {
                            FunctionsService.WriteTotal();
                        }
                        else
                        {
                            FunctionsService.ShowMessageSb(" La carte est bloquée ");
                        }

                        RepositoryDiscount.GetClientInfoById(RepositoryDiscount.Client.InfoClientsCustomerId);
                    }

                    xProduct.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
                    xProduct.Text       = "";
                }
            }
        }