Commit 2ece5fe5 authored by islater's avatar islater
Browse files

asdf

parent 56f9c4c3
......@@ -10,6 +10,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{938FDA09-9346-4837-A3AE-EA1B3485B73F}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
CashRegister.dll = CashRegister.dll
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PointOfSale", "PointOfSale\PointOfSale.csproj", "{4358B429-68E7-41CA-9A21-3DCD273149A5}"
......
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using CashRegister;
namespace MVVMDataBinding
{
public class CashRegisterModelView : INotifyPropertyChanged
{
/// <summary>
/// event changed handler
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// cash drawer for the project
/// </summary>
CashDrawer drawer = new CashDrawer();
/// <summary>
/// public getter for private drawer variable
/// </summary>
public double TotalValue => drawer.TotalValue;
/// <summary>
/// helper method for invoking property changed
/// </summary>
/// <param name="changed"></param>
void InvokePropertyChanger(string changed)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(changed));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TotalValue"));
}
public int Pennies
{
get => drawer.Pennies;
set
{
if (drawer.Pennies == value || value < 0)
return;
var quantity = value - drawer.Pennies;
if (quantity > 0)
drawer.AddCoin(Coins.Penny, quantity);
else
drawer.RemoveCoin(Coins.Penny, -quantity);
InvokePropertyChanger("Pennies");
}
}
public int Nickles
{
get => drawer.Nickels;
set
{
if (drawer.Nickels == value || value < 0)
return;
var quantity = value - drawer.Nickels;
if (quantity > 0)
drawer.AddCoin(Coins.Nickel, quantity);
else
drawer.RemoveCoin(Coins.Nickel, -quantity);
InvokePropertyChanger("Nickels");
}
}
public int Dimes
{
get => drawer.Dimes;
set
{
if (drawer.Dimes == value || value < 0)
return;
var quantity = value - drawer.Dimes;
if (quantity > 0)
drawer.AddCoin(Coins.Dime, quantity);
else
drawer.RemoveCoin(Coins.Dime, -quantity);
InvokePropertyChanger("Dimes");
}
}
public int Quarters
{
get => drawer.Quarters;
set
{
if (drawer.Quarters == value || value < 0)
return;
var quantity = value - drawer.Quarters;
if (quantity > 0)
drawer.AddCoin(Coins.Quarter, quantity);
else
drawer.RemoveCoin(Coins.Quarter, -quantity);
InvokePropertyChanger("Quarters");
}
}
public int HalfDollers
{
get => drawer.HalfDollars;
set
{
if (drawer.HalfDollars == value || value < 0)
return;
var quantity = value - drawer.HalfDollars;
if (quantity > 0)
drawer.AddCoin(Coins.HalfDollar, quantity);
else
drawer.RemoveCoin(Coins.HalfDollar, -quantity);
InvokePropertyChanger("HalfDollars");
}
}
public int Dollars
{
get => drawer.Dollars;
set
{
if (drawer.Dollars == value || value < 0)
return;
var quantity = value - drawer.Dollars;
if (quantity > 0)
drawer.AddCoin(Coins.Dollar, quantity);
else
drawer.RemoveCoin(Coins.Dollar, -quantity);
InvokePropertyChanger("Dollars");
}
}
public int Ones
{
get => drawer.Ones;
set
{
if (drawer.Ones == value || value < 0)
return;
var quantity = value - drawer.Ones;
if (quantity > 0)
drawer.AddBill(Bills.One, quantity);
else
drawer.RemoveBill(Bills.One, -quantity);
InvokePropertyChanger("Ones");
}
}
public int Twos
{
get => drawer.Twos;
set
{
if (drawer.Twos == value || value < 0)
return;
var quantity = value - drawer.Twos;
if (quantity > 0)
drawer.AddBill(Bills.Two, quantity);
else
drawer.RemoveBill(Bills.Two, -quantity);
InvokePropertyChanger("Twos");
}
}
public int Fives
{
get => drawer.Fives;
set
{
if (drawer.Fives == value || value < 0)
return;
var quantity = value - drawer.Fives;
if (quantity > 0)
drawer.AddBill(Bills.Five, quantity);
else
drawer.RemoveBill(Bills.Five, -quantity);
InvokePropertyChanger("Fives");
}
}
public int Tens
{
get => drawer.Tens;
set
{
if (drawer.Tens == value || value < 0)
return;
var quantity = value - drawer.Tens;
if (quantity > 0)
drawer.AddBill(Bills.Ten, quantity);
else
drawer.RemoveBill(Bills.Ten, -quantity);
InvokePropertyChanger("Tens");
}
}
public int Twenties
{
get => drawer.Twenties;
set
{
if (drawer.Twenties == value || value < 0)
return;
var quantity = value - drawer.Twenties;
if (quantity > 0)
drawer.AddBill(Bills.Twenty, quantity);
else
drawer.RemoveBill(Bills.Twenty, -quantity);
InvokePropertyChanger("Twenties");
}
}
public int Fifties
{
get => drawer.Fifties;
set
{
if (drawer.Fifties == value || value < 0)
return;
var quantity = value - drawer.Fifties;
if (quantity > 0)
drawer.AddBill(Bills.Fifty, quantity);
else
drawer.RemoveBill(Bills.Fifty, -quantity);
InvokePropertyChanger("Fifties");
}
}
public int Hundreds
{
get => drawer.Hundreds;
set
{
if (drawer.Hundreds == value || value < 0)
return;
var quantity = value - drawer.Hundreds;
if (quantity > 0)
drawer.AddBill(Bills.Hundred, quantity);
else
drawer.RemoveBill(Bills.Hundred, -quantity);
InvokePropertyChanger("Hundreds");
}
}
}
}
......@@ -6,4 +6,10 @@
<RootNamespace>CowboyCafe.Data</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Reference Include="CashRegister">
<HintPath>..\..\mvvm-data-binding-IJSlater\MVVMDataBinding\CashRegister.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
......@@ -41,7 +41,14 @@ namespace CowboyCafe.Data
public static uint OrderNumber = 1;
public double Total
{
get
{
double sub = Subtotal;
return (sub + (sub * .16));
}
}
private List<IOrderItem> items = new List<IOrderItem>();
......
......@@ -22,4 +22,10 @@
<ProjectReference Include="..\PointOfSale\PointOfSale.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="CashRegister">
<HintPath>..\..\mvvm-data-binding-IJSlater\MVVMDataBinding\CashRegister.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
......@@ -132,23 +132,6 @@ namespace CowboyCafe.DataTests
}
[Fact]
public void ChangingBreadPropertyShouldInvokePropertyChangedForBread()
{
Object chicken = new AngryChicken();
Assert.PropertyChanged(chicken, "Bread", () => {
chicken.Bread = false;
});
}
[Fact]
public void ShouldBeAbleToGetEnumerationOfItems()
{
......
<UserControl x:Class="PointOfSale.BillControll"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:PointOfSale"
mc:Ignorable="d"
Width="120" Height="120"
d:DesignHeight="120" d:DesignWidth="120">
<Border BorderBrush="Gray" BorderThickness="1" Padding="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<Border BorderThickness="10" BorderBrush="ForestGreen" Grid.ColumnSpan="3" Background="Green" Grid.Column="0">
<!--<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:BillControll}}}"/>-->
</Border>
<Button Grid.Row="1" Grid.Column="0" Click="OnDecreaseClicked" Content="-"/>
<!--<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:BillControll}}, Path=Quantity}"/>-->
<Button Grid.Row="1" Grid.Column="2" Click="OnIncreaseClicked" Content="+"/>
</Grid>
</Border>
</UserControl>
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CashRegister;
namespace PointOfSale
{
/// <summary>
/// Interaction logic for ConiControll.xaml
/// </summary>
public partial class BillControll : UserControl
{
public BillControll()
{
InitializeComponent();
}
public static readonly DependencyProperty DenominationProperty = DependencyProperty.Register(
"Denomination", typeof(Bills), typeof(BillControll), new PropertyMetadata(Bills.One)
);
public Bills Denomination
{
get
{
return (Bills)GetValue(DenominationProperty);
}
set
{
SetValue(DenominationProperty, value);
}
}
public static readonly DependencyProperty QuantityProperty = DependencyProperty.Register(
"Quantity", typeof(int), typeof(BillControll), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)
);
public int Quantity
{
get
{
return (int)GetValue(QuantityProperty);
}
set
{
SetValue(QuantityProperty, value);
}
}
public void OnDecreaseClicked(object sender, RoutedEventArgs e)
{
Quantity--;
}
public void OnIncreaseClicked(object sender, RoutedEventArgs e)
{
Quantity++;
}
}
}
<Window x:Class="PointOfSale.CashControll"
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:PointOfSale"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
<local:BillControll Denomination="One" Quantity="{Binding Path=Ones}"/>
<local:BillControll Denomination="Two" Quantity="{Binding Path=Twos}"/>
<local:BillControll Denomination="Five" Quantity="{Binding Path=Fives}"/>
<local:BillControll Denomination="Ten" Quantity="{Binding Path=Tens}"/>
<local:BillControll Denomination="Twenty" Quantity="{Binding Path=Twenties}"/>
<local:BillControll Denomination="Fifty" Quantity="{Binding Path=Fifties}"/>
<local:BillControll Denomination="Hundred" Quantity="{Binding Path=Hundreds}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Center">
<local:CoinControll Denomination="Penny" Quantity="{Binding Path=Pennies}"/>
<local:CoinControll Denomination="Nickel" Quantity="{Binding Path=Nickels}"/>
<local:CoinControll Denomination="Dime" Quantity="{Binding Path=Dimes}"/>
<local:CoinControll Denomination="Quarter" Quantity="{Binding Path=Quarters}"/>
<local:CoinControll Denomination="HalfDollar" Quantity="{Binding Path=HalfDollars}"/>
<local:CoinControll Denomination="Dollar" Quantity="{Binding Path=Dollars}"/>
</StackPanel>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CashRegister;
namespace PointOfSale
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class CashControll : Window
{
public CashControll()
{
InitializeComponent();
}
}
}
<UserControl x:Class="PointOfSale.CoinControll"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:PointOfSale"
mc:Ignorable="d"
Width="120" Height="120"
d:DesignHeight="120" d:DesignWidth="120">
<Border BorderBrush="Gray" BorderThickness="1" Padding="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<Border BorderThickness="1" BorderBrush="Goldenrod" CornerRadius="50" Background="Gold" Margin="-8 0" Grid.Column="1">
<!--<TextBlock VerticalAlignment="Center" TextAlignment="Center" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:CoinControll}}}"/>-->
</Border>
<Button Grid.Row="1" Grid.Column="0" Click="OnDecreaseClicked" Content="-"/>
<!--<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:CoinControll}}, Path=Quantity}"/>-->
<Button Grid.Row="1" Grid.Column="2" Click="OnIncreaseClicked" Content="+"/>
</Grid>
</Border>
</UserControl>
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CashRegister;
namespace PointOfSale
{
/// <summary>
/// Interaction logic for ConiControll.xaml
/// </summary>
public partial class CoinControll : UserControl
{
public CoinControll()
{
InitializeComponent();
}
public static readonly DependencyProperty DenominationProperty = DependencyProperty.Register(
"Denomination", typeof(Coins), typeof(CoinControll), new PropertyMetadata(Coins.Penny)
);
public Coins Denomination
{
get
{
return (Coins)GetValue(DenominationProperty);
}
set
{
SetValue(DenominationProperty, value);
}
}
public static readonly DependencyProperty QuantityProperty = DependencyProperty.Register(
"Quantity", typeof(int), typeof(CoinControll), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)
);
public int Quantity
{
get
{
return (int)GetValue(QuantityProperty);
}
set
{
SetValue(QuantityProperty, value);
}
}
public void OnDecreaseClicked(object sender, RoutedEventArgs e)
{
Quantity--;
}
public void OnIncreaseClicked(object sender, RoutedEventArgs e)
{
Quantity++;
}
}
}