private void plusButton_Click(object sender, RoutedEventArgs e) { if (dataGrid.SelectedIndex >= 0) { DishInfo dishInfo = (DishInfo)dataGrid.Items[dataGrid.SelectedIndex]; dishInfo.Quantity++; dishInfo.Price = dishInfo.Quantity * dishInfo.UnitPrice; dataGrid.Items.Refresh(); } UpdatePrice(); }
public void SetData(ItemCollection itemCollection, int table) { listDishes = new List <DishInfo>(); foreach (DishInfo dish in itemCollection.SourceCollection.Cast <DishInfo>()) { DishInfo monan = new DishInfo { DishName = dish.DishName, Quantity = dish.Quantity, UnitPrice = dish.UnitPrice, Price = dish.Price }; listDishes.Add(monan); } tableNumber = table.ToString("D2"); }
private void dishButton_Click(object sender, RoutedEventArgs e) { //Get info Button dishButton = (Button)sender; Grid grid = (Grid)(dishButton.Content); TextBlock dishNameTextBlock = (TextBlock)grid.Children[1]; TextBlock priceTextBlock = (TextBlock)(((StackPanel)grid.Children[0]).Children[0]); DishInfo dishInfo = null; if (tables.ContainsKey(ComboBoxTableNumber.SelectedItem.ToString())) { dishInfo = GetDishInfo(tables[ComboBoxTableNumber.SelectedItem.ToString()], dishButton.Uid); } //if existed if (dishInfo != null) { dishInfo.Quantity++; dishInfo.Price = dishInfo.Quantity * dishInfo.UnitPrice; dataGrid.Items.Refresh(); } else //new { Decimal unitPrice = Decimal.Parse(priceTextBlock.Text.Remove(priceTextBlock.Text.Length - 1).Trim()); dishInfo = new DishInfo(dishButton.Uid, dishNameTextBlock.Text, 1, unitPrice, unitPrice); dataGrid.Items.Add(dishInfo); if (!tables.ContainsKey(ComboBoxTableNumber.SelectedItem.ToString())) { tables[ComboBoxTableNumber.SelectedItem.ToString()] = new ObservableCollection <DishInfo>(); } tables[ComboBoxTableNumber.SelectedItem.ToString()].Add(dishInfo); } UpdatePrice(); if (ComboBoxTableNumber.SelectedIndex != 0) { MainWindow.Instance.UCTableChart.SetTableStatus(int.Parse(ComboBoxTableNumber.SelectedItem.ToString()), UserControlTableChart.TableStatus.Occupied); } }
private void MinusButton_Click(object sender, RoutedEventArgs e) { if (dataGrid.SelectedIndex >= 0) { DishInfo dishInfo = (DishInfo)dataGrid.Items[dataGrid.SelectedIndex]; dishInfo.Quantity--; if (dishInfo.Quantity == 0) { dataGrid.Items.Remove(dishInfo); tables[ComboBoxTableNumber.SelectedItem.ToString()].Remove(dishInfo); } else { dishInfo.Price = dishInfo.Quantity * dishInfo.UnitPrice; } dataGrid.Items.Refresh(); } UpdatePrice(); }