Esempio n. 1
0
        private async void Valider_Click(object sender, RoutedEventArgs e)
        {
            int completed = 0;

            if (ClientName.Text.Count() == 0)
            {
                ClientName.Background = new SolidColorBrush(Colors.Red);
                completed++;
            }
            if (Phone.Text.Count() == 0)
            {
                Phone.Background = new SolidColorBrush(Colors.Red);
                completed++;
            }
            if (ProductsList.Items.Count() == 0)
            {
                ClientName.Background = new SolidColorBrush(Colors.Red);
                completed++;
            }
            if (completed == 0)
            {
                if (LocalClient != null)
                {
                    //Modify
                    await DataHolder.ModifyClient(
                        new Client()
                    {
                        Name     = ClientName.Text,
                        Phone    = Phone.Text,
                        Remarks  = Remarks.Text,
                        Day      = Day.Date,
                        Hour     = Day.Hour,
                        State    = Remarks.Text == string.Empty ? 1 : 2,
                        Products = OrderedProducts,
                        Number   = LocalClient.Number
                    });
                }
                else
                {
                    //new client
                    await DataHolder.SaveNewClient(new Client()
                    {
                        Name     = ClientName.Text,
                        Phone    = Phone.Text,
                        Remarks  = Remarks.Text,
                        Day      = Day.Date,
                        Hour     = Day.Hour,
                        State    = Remarks.Text == string.Empty ? 1 : 2,
                        Products = OrderedProducts,
                        Number   = DataHolder.Clients.Any() ? DataHolder.Clients.Last().Number + 1 : 0
                    });
                }
                ClientName.Text = "";
                Phone.Text      = "";
                Remarks.Text    = "";
                OrderedProducts.Clear();
                ProductsMenu.ItemsSource = Categories;
                ((Grid)this.Parent).Children.Remove(this);
            }
        }
Esempio n. 2
0
        private void RefreshProducts(ICollection <Product> products)
        {
            OrderedProducts.Clear();

            foreach (var item in products)
            {
                OrderedProducts.Add(item);
            }
        }
Esempio n. 3
0
        private async void FinalizeSale()
        {
            if (TotalPrice <= ScannedCustomer.Balance)
            {
                foreach (Product p in OrderedProducts)
                {
                    Transfer t = new Transfer();
                    Sales    s = new Sales();
                    s.Amount     = 1;
                    s.CustomerId = ScannedCustomer.Barcode;
                    s.ProductId  = p.Id;
                    s.RegisterId = 5;
                    s.Timestamp  = DateTime.Now;
                    s.TotalPrice = p.Price;

                    t.Sender   = ScannedCustomer;
                    t.Receiver = s;

                    try
                    { string input = JsonConvert.SerializeObject(t);
                      using (HttpClient client = new HttpClient())
                      {
                          HttpResponseMessage response = await client.PutAsync("http://localhost:41983/api/ProductRegister/", new StringContent(input, Encoding.UTF8, "application/json"));

                          if (response.IsSuccessStatusCode)
                          {
                          }
                          else
                          {
                              MessageBox.Show("There were no transactions");
                          }
                      } }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Order failed");
                    }
                }
                ScannedCustomer = null;
                CustomerScanned = false;
                OrderedProducts.Clear();
                Customers.Clear();
                GetCustomers();
                TotalPrice             = 0;
                DifferenceTotalBalance = 0;
            }
            else
            {
                MessageBox.Show("Customers balance is insufficient");
            }
        }
Esempio n. 4
0
        public void ProcessOrderedItems()
        {
            if (OrderedProducts.Any())
            {
                var sales = new List <Sale>();

                foreach (var item in OrderedProducts)
                {
                    var sale = new Sale
                    {
                        Amount          = item.Quantity * item.Price,
                        Name            = item.Name,
                        TransactionDate = DateTime.UtcNow,
                        UomType         = item.UomType,
                        Quantity        = item.Quantity
                    };

                    sales.Add(sale);
                }

                _context.Sales.AddRange(sales);

                _context.SaveChanges();

                var receiptView = new ReceiptView();
                var viewModel   = new ReceiptViewModel();
                receiptView.DataContext = viewModel;
                if (viewModel.CloseAction == null)
                {
                    viewModel.CloseAction = new Action(receiptView.Close);
                }

                ((ReceiptViewModel)receiptView.DataContext).LoadOrderedProducts(OrderedProducts.ToModelObservableCollection());
                receiptView.ShowDialog();

                OrderedProducts.Clear();
                RaisePropertyChanged("OrderedProducts");
            }
            else
            {
                MessageBox.Show("There is no item to order", "Exception", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
        }
Esempio n. 5
0
 private void RemoveProduct(Product obj)
 {
     try
     {
         if (OrderedProducts.Count == 1)
         {
             OrderedProducts.Clear();
             TotalPrice            -= obj.Price;
             DifferenceTotalBalance = 0;
         }
         else
         {
             OrderedProducts.Remove(obj);
             TotalPrice            -= obj.Price;
             DifferenceTotalBalance = ScannedCustomer.Balance - TotalPrice;
         }
     }
     catch (Exception)
     {
         MessageBox.Show("You have to select a product to return");
     }
 }
Esempio n. 6
0
 public void Clear()
 {
     OrderedProducts.Clear();
 }