private void BillBtn_Click(object sender, RoutedEventArgs e) { try { var newEventArgs = new RoutedEventArgs(Button.ClickEvent); FinishBtn.RaiseEvent(newEventArgs); Hide(); new BillWindow(ProductsForBill, dBContext, sale).ShowDialog(); ShowDialog(); } catch (Exception ex) { log.Error(ex.InnerException); } }
private void AddBtn_Click(object sender, RoutedEventArgs e) { try { CheckoutProductViewModel viewModel; var textBoxContent = CodeAndQuantityTxt.Text; //Добавяне на продукт if (Regex.Match(textBoxContent, @"^\d+\*{1}\d+$").Success&& textBoxContent != "*+") { var splittedText = textBoxContent.Split('*').ToList(); bool n = false; foreach (var text in splittedText) { if (String.IsNullOrEmpty(text)) { n = true; } } if (!n) { var itemIdOrBarcode = 0; int length = (int)(Math.Log10(int.MaxValue) + 1); if (splittedText[1].Length < length) { itemIdOrBarcode = int.Parse(splittedText[1]); } var item = dBContext.Products.AsNoTracking().FirstOrDefault(p => p.Id == itemIdOrBarcode || p.Barcode == splittedText[1]); if (item == null || item.IsDeleted) { SystemSounds.Hand.Play(); MessageBox.Show($"Няма такъв продукт с id/barcode {itemIdOrBarcode}!"); throw new Exception($"Няма такъв продукт с id/barcode {itemIdOrBarcode}!"); } var itemQuantity = decimal.Parse(splittedText[0]); totalPrice = item.Price * itemQuantity; viewModel = new CheckoutProductViewModel() { Barcode = item.Barcode, Id = item.Id, Measure = item.Measure, Name = item.Name, Price = item.Price, Quantity = itemQuantity, TotalPrice = totalPrice }; Products.Add(item); ProductsList.Add(viewModel); ProductsListGrid.ItemsSource = ProductsList; totalPrice = ProductsList.Sum(x => x.TotalPrice); TotalPriceTxt.Text = totalPrice.ToString(); log.Info($"Product {viewModel.Name} with quantity {viewModel.Quantity} added to the bill."); } else { SystemSounds.Hand.Play(); } } //Изтриване на последен добавен продукт else if (textBoxContent == "--") { var newEventArgs = new RoutedEventArgs(Button.ClickEvent); ClearLastBtn.RaiseEvent(newEventArgs); } //Завършване на продажба else if (textBoxContent == "*+") { var newEventArgs = new RoutedEventArgs(Button.ClickEvent); FinishBtn.RaiseEvent(newEventArgs); } //Дневен отчет else if (textBoxContent == "/////") { DailyFile.SaveDailyFile(); } else if (textBoxContent == "*+*") { var newEventArgs = new RoutedEventArgs(Button.ClickEvent); BillBtn.RaiseEvent(newEventArgs); } else { SystemSounds.Hand.Play(); } } catch (Exception ex) { log.Error(ex.InnerException); } finally { CodeAndQuantityTxt.Text = string.Empty; } }