Commit bfc145cd authored by Ian Slater's avatar Ian Slater
Browse files

added data binding

parent 848c6e30
......@@ -9,7 +9,7 @@ using System.Text;
namespace CowboyCafe.Data
{
public abstract class Entree
public abstract class Entree : IOrderItem
{
......
......@@ -6,9 +6,9 @@ namespace CowboyCafe.Data
{
public interface IOrderItem
{
double Price { get; }
double Calories { get; }
List<String> SpecialIstructions { get; }
double Price { get; }
uint Calories { get; }
List<String> SpecialInstructions { get; }
}
......
......@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Text;
using CowboyCafe.Data;
namespace CowboyCafe.Data
{
public class Order :INotifyPropertyChanged
......@@ -11,12 +12,21 @@ namespace CowboyCafe.Data
public event PropertyChangedEventHandler PropertyChanged;
public double Subtotal { get; set; }
public IEnumerable<IOrderItem> Items {get;set;}
public double Subtotal { get; set; } = 10.0;
private List<IOrderItem> items = new List<IOrderItem>();
public IEnumerable<IOrderItem> Items {get => items;}
public void Add(IOrderItem i)
{
{
items.Add(i);
this.Subtotal += i.Price;
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Subtotal"));
}
public void Remove(IOrderItem i)
......
......@@ -5,15 +5,17 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PointOfSale"
mc:Ignorable="d"
Title="MainWindow" Height="570" Width="1000">
Title="MainWindow" Height="600" Width="1000">
<Grid RenderTransformOrigin="0.568,0.499">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="1" Grid.RowSpan="4" BorderBrush="Black"
BorderThickness="1,0,0,0" Background="{x:Null}" />
<local:OrderControl Height="420" Grid.Column="0" Margin="0,84,0,0" />
<local:OrderSummaryControl Grid.Column="1"/>
<local:OrderControl x:Name="ordercontrol" Height="420" Grid.Column="0" Margin="0,84,0,0" />
<local:OrderSummaryControl x:Name="ordersummarycontrol" Grid.Column="1"/>
</Grid>
</Window>
......@@ -17,6 +17,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CowboyCafe.Data;
namespace PointOfSale
{
......@@ -28,6 +29,9 @@ namespace PointOfSale
public MainWindow()
{
InitializeComponent();
Order currentOrder = new Order();
currentOrder.PropertyChanged += ordersummarycontrol.OnItemChanged;
DataContext = currentOrder;
}
private void OrderControl_Loaded(object sender, RoutedEventArgs e)
......
......@@ -17,6 +17,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace PointOfSale
{
/// <summary>
......@@ -32,7 +33,11 @@ namespace PointOfSale
private void AngryChickenButton_Click(object sender, RoutedEventArgs e)
{
AngryChicken ac = new AngryChicken();
ticket.Items.Add(ac.ToString());
if (DataContext is Order order)
{
order.Add(ac);
}
}
private void CowpokeChiliButton_Click(object sender, RoutedEventArgs e)
......
......@@ -6,29 +6,25 @@
xmlns:local="clr-namespace:PointOfSale"
mc:Ignorable="d"
d:DesignHeight="570" d:DesignWidth="300">
<Grid>
<Separator HorizontalAlignment="Center" Margin="0,500,0,0" VerticalAlignment="Top" Height="1" RenderTransformOrigin="0.5,0.5" Width="300">
<Separator.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="-1"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Separator.RenderTransform>
</Separator>
<TextBlock Name="SubtotalTextBox" HorizontalAlignment="Right" Margin="0,515,10,0" FontSize="20" TextWrapping="Wrap" VerticalAlignment="Top" Height="45" Width="84">100.60</TextBlock>
<Grid>
<Border BorderThickness="1" BorderBrush="Black" Margin="10,38,10,60">
<ListBox Name="ticket"/>
</Border>
<TextBlock Name="SubtotalTextBox" HorizontalAlignment="Right" Margin="0,515,10,0" FontSize="20" Text="{Binding Path=Subtotal, StringFormat=c}" TextWrapping="Wrap" VerticalAlignment="Top" Height="45" Width="84"/>
<TextBlock HorizontalAlignment="Left" Margin="10,515,0,0" FontSize="20" TextWrapping="Wrap" VerticalAlignment="Top" Height="45" Width="90">Subtotal</TextBlock>
<TextBlock Name="TicketTextBox" HorizontalAlignment="Center" Margin="0,25,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="463" Width="280">
</TextBlock>
<TextBlock HorizontalAlignment="Left" Margin="10,-2,0,0" Text="Ticket" FontSize="20" TextWrapping="Wrap" VerticalAlignment="Top" Width="70"/>
<ScrollBar HorizontalAlignment="Left" Margin="273,38,0,0" VerticalAlignment="Top" Height="439"/>
</Grid>
<TextBlock HorizontalAlignment="Left" Margin="10,-2,0,0" Text="Ticket" FontSize="20" TextWrapping="Wrap" VerticalAlignment="Top" Width="70"/>
<ScrollBar HorizontalAlignment="Left" Margin="263,63,0,0" VerticalAlignment="Top" Height="427"/>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
......@@ -10,6 +11,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CowboyCafe.Data;
namespace PointOfSale
{
......@@ -21,6 +23,17 @@ namespace PointOfSale
public OrderSummaryControl()
{
InitializeComponent();
}
public void OnItemChanged(object sender, PropertyChangedEventArgs e)
{
if (sender is Order order)
{
ticket.Items.Add("Angry Chicken");
}
}
private void ScrollBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment