public static void DelProductCheck(string barcode) { var selectedIndex = ((MainWindow)ClassEtcFun.FindWindow("MainWindow_")).GridProducts.SelectedIndex; var productElements = RepositoryCheck.DocumentProductCheck.GetXElements("check", "product").Where(p => p.GetXElementValue("CodeBare").Trim() == barcode.Trim()).ToList(); if (productElements.Count > 0) { var firstQty = productElements.First().GetXElementValue("qty").ToDecimal(); if (RepositoryProduct.Products.Find(l => l.CustomerId == productElements.First().GetXElementValue("id").ToGuid()).Balance || (firstQty == 0)) { productElements.First().Remove(); } else { productElements.First().GetXElement("qty").Value = (firstQty - 1).ToString(); } } else { RepositoryDiscount.RestoreDiscount(); DiscountCalc(); FunctionsService.WriteTotal(); } FunctionsService.WriteToatl(selectedIndex); RepositoryCheck.DocumentProductCheck.Save(RepositoryCheck.PathProductCheck); }
private static void WorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { SyncData.SetSunc(false); new ClassPrintCheck(RepositoryCheck.DocumentProductCheck, false); RepositoryCheck.DocumentProductCheck = null; CassieService.OpenProductsCheck(); Pro = null; Ndevis = -1; Nfact = -1; Check = null; Devis = false; ModePro = false; RepositoryDiscount.RestoreDiscount(); CheckService.DiscountCalc(); FunctionsService.WriteTotal(); var de = ClassEtcFun.FindWindow("_W_Message"); if (de != null) { de.Close(); } var mw = ClassEtcFun.FindWindow("MainWindow_"); if (mw != null) { mw.IsEnabled = true; } }
public static void BufAddXElm(XElement element) { RepositoryCheck.DocumentProductCheck = new XDocument(); RepositoryCheck.DocumentProductCheck.Add(element); RepositoryDiscount.RestoreDiscount(); DiscountCalc(); FunctionsService.WriteTotal(); }
public static void DelProductCheck(int id) { RepositoryCheck.C = null; var selectedIndex = ((MainWindow)ClassEtcFun.FindWindow("MainWindow_")).GridProducts.SelectedIndex; var productElements = RepositoryCheck.DocumentProductCheck.GetXElements("check", "product").ToList(); if (productElements.Count == 0) { RepositoryDiscount.RestoreDiscount(); DiscountCalc(); FunctionsService.WriteTotal(); } else { var curElement = productElements.FirstOrDefault(l => l.GetXElementValue("ii").ToInt() == id); curElement?.Remove(); } FunctionsService.WriteToatl(selectedIndex); RepositoryCheck.DocumentProductCheck.Save(RepositoryCheck.PathProductCheck); }
public static void Bay() { RepositoryCheck.GetDucument(); if (RepositoryCheck.Document.Element("checks") != null && RepositoryCheck.DocumentProductCheck.GetXElements("check", "product").Any()) { RepositoryCheck.DocumentProductCheck = RepositoryActionHashBox.MergeProductsInCheck(RepositoryCheck.DocumentProductCheck); try { foreach (var type in RepositoryTypePay.TypePays) { var money = RepositoryCurrencyRelations.GetMoneyFromType(type); RepositoryCheck.DocumentProductCheck.GetXElement("check").Add(new XAttribute(type.NameCourt.TrimEnd(), money)); } } catch (System.Exception ex) { var text = ex.Message; FunctionsService.ShowMessageSb(text); LogService.Log(TraceLevel.Error, 1, text + RepositoryCheck.DocumentProductCheck); } var rendu = ClassEtcFun.RenduCalc(); try { RepositoryCheck.DocumentProductCheck.GetXElement("check").Add(new XAttribute("Rendu", rendu.ToString("0.00"))); } catch (System.Exception ex) { var text = ex.Message; FunctionsService.ShowMessageSb(text); LogService.Log(TraceLevel.Error, 2, text + RepositoryCheck.DocumentProductCheck + "."); } try { RepositoryCheck.DocumentProductCheck.GetXElement("check").Add( new XAttribute("sum", RepositoryCurrencyRelations.GetSumMoney()), new XAttribute("date", DateTime.Now)); } catch (System.Exception ex) { var text = ex.Message; FunctionsService.ShowMessageSb(text); LogService.Log(TraceLevel.Error, 3, text + RepositoryCheck.DocumentProductCheck + "."); } try { if (RepositoryDiscount.Client.Barcode != null && !ClassProMode.ModePro) { AddSetDiscountCardBareCode( RepositoryDiscount.Client.Barcode, RepositoryDiscount.Client.Points - (RepositoryDiscount.Client.AddPoints ? 1 : 0) + (RepositoryDiscount.Client.DiscountSet ? RepositoryDiscount.Client.MaxPoints : 0), RepositoryDiscount.Client.AddPoints ? 1 : 0, RepositoryDiscount.Client.DiscountSet ? 8 : 0, RepositoryDiscount.Client.NameFirst + " " + RepositoryDiscount.Client.NameLast); } } catch (System.Exception ex) { var text = ex.Message; FunctionsService.ShowMessageSb(text); LogService.Log(TraceLevel.Error, 4, text + RepositoryCheck.DocumentProductCheck + "."); } if (ClassProMode.ModePro || ClassProMode.Devis) { ClassProMode.Move(ClassProMode.Devis); } else { var element = RepositoryCheck.DocumentProductCheck.Element("check"); element.GetXAttribute("barcodeCheck").SetValue(RepositoryCheck.GetBarCodeCheck()); RepositoryCheck.Document.GetXElement("checks").Add(element); } if (!ClassProMode.ModePro && !ClassProMode.Devis) { new ClassPrintCheck(RepositoryCheck.DocumentProductCheck, false); } try { var worker = new BackgroundWorker(); if (!ClassProMode.ModePro && !ClassProMode.Devis) { worker.DoWork += WorkerDoWork; worker.RunWorkerCompleted += WorkerRunWorkerCompleted; worker.RunWorkerAsync(); } } catch (System.Exception ex) { var text = ex.Message; LogService.Log(TraceLevel.Error, 7, text + RepositoryCheck.DocumentProductCheck + "."); } try { if (!ClassProMode.ModePro && !ClassProMode.Devis) { RepositoryCheck.Document.Save(RepositoryCheck.Path); RepositoryCheck.DocumentProductCheck = null; CassieService.OpenProductsCheck(); RepositoryDiscount.RestoreDiscount(); DiscountCalc(); FunctionsService.WriteTotal(); } } catch (System.Exception ex) { var text = ex.Message; FunctionsService.ShowMessageSb(text); LogService.Log(TraceLevel.Error, 8, text + RepositoryCheck.DocumentProductCheck + "."); } } else { FunctionsService.ShowMessageSb("файл check.xml отсутвует или структура не правильная"); } }
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 = ""; } } }