Question

The programming language is C# we are using wpf forms.

Hello, I would like to get my clear button to work. So when clear is click everything is clear not only the total, tax or subtotal but also the combox and the data grid. For the Delete button if the user selects a specific item it will be deleted and for the receipt button, it should create a pdf that contains the Name, Price, quantity, tax, total and subtotal. it is WPF forms. Also if you can create the user login part of the homework I would really like that.

I can upload the project to google drive if you would like.



Rubric Question 1 Marks 1+1 3+2+3+1+2 Functionality WPF GUI (XAML) Data Binding + ObseverableCollection<T> Status Bar Functio
(Restaurant Bill Calculator) A restaurant wants a WPF app that calculates a tables bill. The app should display all followin
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(Restaurant Bill Calculator) A restaurant wants a WPF app that calculates a tables bill. The app should display all followinPotato Skins Appetizer Nachos Mushroom Caps Appetizer $10.95 Carrot Cake Dessert Shrimp Cocktail Appetizer Chips and Salsa Ap
Show transcribed image text
Expert Answer
Vishal Jain's Avatar
Vishal Jain answered this Was this answer helpful?

3
0
213 answers
//MainWindow.xaml

<Window x:Class="RestaurantBillCalculator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RestaurantBillCalculator"
mc:Ignorable="d"
Title="MainWindow" Height="550" Width="900">
<Window.Resources>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Style TargetType="{x:Type TextBox}">
<Setter Property="TextAlignment" Value="Right"/>
<Setter Property="IsEnabled" Value="False"/>
</Style>

<Style TargetType="{x:Type ComboBox}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} - ${1}">
<Binding Path="ItemName"/>
<Binding Path="ItemPrice"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Window.Resources>
<Grid>

<ComboBox ItemsSource="{Binding Beverages}" SelectionChanged="ComboBox_SelectionChanged" HorizontalAlignment="Left" Margin="103,25,0,0" VerticalAlignment="Top" Width="120"/>
<ComboBox ItemsSource="{Binding MainCourse}" SelectionChanged="ComboBox_SelectionChanged" HorizontalAlignment="Left" Margin="320,25,0,0" VerticalAlignment="Top" Width="126"/>
<ComboBox ItemsSource="{Binding Appetizer}" SelectionChanged="ComboBox_SelectionChanged" HorizontalAlignment="Left" Margin="511,25,0,0" VerticalAlignment="Top" Width="130"/>
<ComboBox ItemsSource="{Binding Dessert}" SelectionChanged="ComboBox_SelectionChanged" HorizontalAlignment="Left" Margin="718,25,0,0" VerticalAlignment="Top" Width="135"/>
<DataGrid ItemsSource="{Binding Order}" HorizontalAlignment="Left" Height="237" Margin="29,89,0,0" VerticalAlignment="Top" Width="824"/>
<Label Content="Total:" HorizontalAlignment="Left" Margin="29,353,0,0" VerticalAlignment="Top"/>
<Label Content="Tax:" HorizontalAlignment="Left" Margin="329,353,0,0" VerticalAlignment="Top"/>
<Label Content="Subtotal:" HorizontalAlignment="Left" Margin="644,360,0,0" VerticalAlignment="Top"/>
<TextBox Text="{Binding Total}" HorizontalAlignment="Left" Height="23" Margin="118,357,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox Text="{Binding Tax}" HorizontalAlignment="Left" Height="23" Margin="418,357,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<TextBox Text="{Binding SubTotal}" HorizontalAlignment="Left" Height="23" Margin="733,364,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Label Content="$" HorizontalAlignment="Left" Margin="103,357,0,0" VerticalAlignment="Top"/>
<Label Content="$" HorizontalAlignment="Left" Margin="403,357,0,0" VerticalAlignment="Top"/>
<Label Content="$" HorizontalAlignment="Left" Margin="718,361,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.699,4.1"/>
<Button Content="Clear Bill" HorizontalAlignment="Left" Margin="32,407,0,0" VerticalAlignment="Top" Width="821" RenderTransformOrigin="0.5,0.5" Height="31"/>
<Label Content="Beverages" HorizontalAlignment="Left" Margin="26,21,0,0" VerticalAlignment="Top"/>
<Label Content="MainCourse" HorizontalAlignment="Left" Margin="237,23,0,0" VerticalAlignment="Top"/>
<Label Content="Appetizer" HorizontalAlignment="Left" Margin="446,22,0,0" VerticalAlignment="Top"/>
<Label Content="Dessert" HorizontalAlignment="Left" Margin="657,22,0,0" VerticalAlignment="Top"/>
<StatusBar HorizontalAlignment="Left" Height="35" Margin="32,460,0,0" VerticalAlignment="Top" Width="821">
<Label Content="Student Name Here" Width="312"/>
<TextBlock HorizontalAlignment="Right">
<Hyperlink NavigateUri="https://www.centennialcollege.com">
Centennial College
</Hyperlink>
</TextBlock>
</StatusBar>
</Grid>
</Window>

//MainWindow.xaml.cs

using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;

namespace RestaurantBillCalculator
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new Model();
}

private void ComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
var dataContext = DataContext as Model;
var item = e.AddedItems[0] as MenuItem;
if (dataContext == null || item == null)
return;

if(dataContext.Order.Any(o => o.ItemName == item.ItemName))
{
var orderItem = dataContext.Order.First(o => o.ItemName == item.ItemName);
orderItem.Quantity++;
}
else
{
dataContext.Order.Add(new OrderedItem(item.ItemName, item.ItemPrice));
}

dataContext.RecalculateBill();
}

private void ClearBill_Executed(object sender, ExecutedRoutedEventArgs e)
{
var dataContext = DataContext as Model;
dataContext.ClearBill();
}
}
}

//Model.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace RestaurantBillCalculator
{
public class MenuItem
{
public MenuItem(string name, double price)
{
ItemName = name;
ItemPrice = price;
}

public string ItemName { get; set; }
public double ItemPrice { get; set; }
}


public class OrderedItem : MenuItem, INotifyPropertyChanged
{
public OrderedItem(string name, double price) : base(name, price)
{
Quantity = 1;
}

private int quantity;

public event PropertyChangedEventHandler PropertyChanged;

public int Quantity
{
get
{
return quantity;
}
set
{
quantity = value;
}
}

protected void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

}

public class Model : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

public Model()
{
Total = Tax = SubTotal = 0.0;
Beverages = new ObservableCollection<MenuItem>()
{
new MenuItem("Soda", 1.95),
new MenuItem("Tea", 1.50),
new MenuItem("Coffee", 1.25),
new MenuItem("Mineral Water", 2.95),
new MenuItem("Juice", 2.50),
new MenuItem("Milk", 1.50)
};

MainCourse = new ObservableCollection<MenuItem>()
{
new MenuItem("Chicken Alfredo", 13.95),
new MenuItem("Chicken Picatta", 13.95),
new MenuItem("Turkey Club", 11.95),
new MenuItem("Lobster Pie", 19.95),
new MenuItem("Prime Rib", 20.95),
new MenuItem("Shrimp Scampi", 18.95),
new MenuItem("Turkey Dinner", 13.95),
new MenuItem("Stuffed Chicken", 14.95)
};

Appetizer = new ObservableCollection<MenuItem>()
{
new MenuItem("Buffalo Wings", 5.95),
new MenuItem("Buffalo Fingers", 6.95),
new MenuItem("Potato Skins", 8.95),
new MenuItem("Nachos", 8.95),
new MenuItem("Mushroom Caps", 10.95),
new MenuItem("Chips and Salsa", 6.95)
};

Dessert = new ObservableCollection<MenuItem>()
{
new MenuItem("Apple Pie", 5.95),
new MenuItem("Sundae", 3.95),
new MenuItem("Carrot Cake", 5.95),
new MenuItem("Mud Pie", 4.95),
new MenuItem("Apple Crisp", 5.95)
};

Order = new ObservableCollection<OrderedItem>();
}

public ObservableCollection<MenuItem> Beverages { get; set; }

public ObservableCollection<MenuItem> MainCourse { get; set; }

public ObservableCollection<MenuItem> Appetizer { get; set; }

public ObservableCollection<MenuItem> Dessert { get; set; }

public ObservableCollection<OrderedItem> Order { get; set; }

private double total;

public double Total
{
get { return total; }
set
{
total = value;
RaisePropertyChanged(nameof(Total));
}
}

private double tax;

public double Tax
{
get { return tax; }
set
{
tax = value;
RaisePropertyChanged(nameof(Tax));
}
}

private double subTotal;

public double SubTotal
{
get { return subTotal; }
set
{
subTotal = value;
RaisePropertyChanged(nameof(SubTotal));
}
}

protected void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public void RecalculateBill()
{
Total = Tax = SubTotal = 0.0;
foreach (var item in Order)
{
Total += item.ItemPrice * item.Quantity;
}
Tax = Total * 0.10; //Calculating tax @ 10%. Change accordingly
SubTotal = Total + Tax;
}

public void ClearBill()
{
Total = Tax = SubTotal = 0.0;
}
}
}as HOMEWORKLIB RULES records I solved this

Add a comment
Know the answer?
Add Answer to:
The programming language is C# we are using wpf forms. Hello, I would like to get...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • *****************USING JAVA AND JAVA FX ************** PLEASE READ THE INSTRUCTIONS BEFORE YOU GO AND DO IT...

    *****************USING JAVA AND JAVA FX ************** PLEASE READ THE INSTRUCTIONS BEFORE YOU GO AND DO IT SOME OTHER WAY... home / study / engineering / computer science / questions and answers / *****in java & java fx***** a restaurant wants ... Your question has been answered! Rate it below. Let us know if you got a helpful answer. Question *****IN JAVA & JAVA FX***** A restaurant wants an application that calculates a table’s bill. The design should include: Group Boxes,...

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT