Skip to content

Instantly share code, notes, and snippets.

@skiwi2
Created June 30, 2016 18:57
Show Gist options
  • Save skiwi2/2055200d2689771a39a48e9ebd8b7186 to your computer and use it in GitHub Desktop.
Save skiwi2/2055200d2689771a39a48e9ebd8b7186 to your computer and use it in GitHub Desktop.
AddPurchase
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArbitrageClient
{
class AddPurchaseModel
{
private DateTime purchaseDate;
private string sellerName;
private string sellerStreet;
private string sellerCity;
private string sellerTelephoneNumber;
private string sellerComments;
private decimal sellingPrice;
private decimal fuelCost;
private decimal shippingCost;
private bool shippingIncluded;
private decimal totalPrice;
public DateTime PurchaseDate
{
get
{
return purchaseDate;
}
set
{
purchaseDate = value;
}
}
public string SellerName
{
get
{
return sellerName;
}
set
{
sellerName = value;
}
}
public string SellerStreet
{
get
{
return sellerStreet;
}
set
{
sellerStreet = value;
}
}
public string SellerCity
{
get
{
return sellerCity;
}
set
{
sellerCity = value;
}
}
public string SellerTelephoneNumber
{
get
{
return sellerTelephoneNumber;
}
set
{
sellerTelephoneNumber = value;
}
}
public string SellerComments
{
get
{
return sellerComments;
}
set
{
sellerComments = value;
}
}
public decimal SellingPrice
{
get
{
return sellingPrice;
}
set
{
sellingPrice = value;
}
}
public decimal FuelCost
{
get
{
return fuelCost;
}
set
{
fuelCost = value;
}
}
public decimal ShippingCost
{
get
{
return shippingCost;
}
set
{
shippingCost = value;
}
}
public bool ShippingIncluded
{
get
{
return shippingIncluded;
}
set
{
shippingIncluded = value;
}
}
public decimal TotalPrice
{
get
{
return totalPrice;
}
set
{
totalPrice = value;
}
}
}
}
<UserControl x:Class="ArbitrageClient.AddPurchaseUserControl"
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:ArbitrageClient"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800">
<UserControl.DataContext>
<local:AddPurchaseViewModel />
</UserControl.DataContext>
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,2,0,2" />
</Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Margin" Value="0,2,0,2" />
</Style>
<Style TargetType="{x:Type DatePicker}">
<Setter Property="Margin" Value="0,2,0,2" />
</Style>
</Grid.Resources>
<Label Grid.Row="0" Grid.ColumnSpan="2" FontWeight="Bold" HorizontalContentAlignment="Center">General</Label>
<Label Grid.Row="1" Grid.Column="0">Purchase date: </Label>
<DatePicker Grid.Row="1" Grid.Column="1" Text="{Binding PurchaseDate}" />
<Label Grid.Row="2" Grid.ColumnSpan="2" Visibility="Hidden">Placeholder</Label>
<Label Grid.Row="3" Grid.ColumnSpan="2" FontWeight="Bold" HorizontalContentAlignment="Center">Seller</Label>
<Label Grid.Row="4" Grid.Column="0">Name: </Label>
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding SellerName}" />
<Label Grid.Row="5" Grid.Column="0">Street: </Label>
<TextBox Grid.Row="5" Grid.Column="1" Text="{Binding SellerStreet}" />
<Label Grid.Row="6" Grid.Column="0">City: </Label>
<TextBox Grid.Row="6" Grid.Column="1" Text="{Binding SellerCity}" />
<Label Grid.Row="7" Grid.Column="0">Tel. number: </Label>
<TextBox Grid.Row="7" Grid.Column="1" Text="{Binding SellerTelephoneNumber}" />
<Label Grid.Row="8" Grid.Column="0">Comments: </Label>
<TextBox Grid.Row="8" Grid.Column="1" Text="{Binding SellerComments}" />
<Label Grid.Row="9" Grid.ColumnSpan="2" Visibility="Hidden">Placeholder</Label>
<Label Grid.Row="10" Grid.ColumnSpan="2" FontWeight="Bold" HorizontalContentAlignment="Center">Pricing</Label>
<Label Grid.Row="11" Grid.Column="0">Selling price: </Label>
<TextBox Grid.Row="11" Grid.Column="1" Text="{Binding SellingPrice}" />
<Label Grid.Row="12" Grid.Column="0">Extra cost: </Label>
<ComboBox Grid.Row="12" Grid.Column="1" x:Name="extraCost">
<ComboBoxItem Tag="FuelCost">Fuel cost</ComboBoxItem>
<ComboBoxItem Tag="ShippingCost">Shipping cost</ComboBoxItem>
<ComboBoxItem Tag="ShippingIncluded">Shipping included</ComboBoxItem>
</ComboBox>
<Label Grid.Row="13" Grid.Column="0">Cost: </Label>
<TextBox Grid.Row="13" Grid.Column="1" Text="{Binding FuelCost}">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="TextBlock.Visibility" Value="Collapsed"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=extraCost, Path=SelectedItem.Tag}" Value="FuelCost">
<Setter Property="TextBlock.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<TextBox Grid.Row="13" Grid.Column="1" Text="{Binding ShippingCost}">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="TextBlock.Visibility" Value="Collapsed"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=extraCost, Path=SelectedItem.Tag}" Value="ShippingCost">
<Setter Property="TextBlock.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<TextBox Grid.Row="13" Grid.Column="1" IsEnabled="False">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="TextBox.Visibility" Value="Collapsed"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=extraCost, Path=SelectedItem.Tag}" Value="ShippingIncluded">
<Setter Property="TextBox.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Label Grid.Row="14" Grid.Column="0">Total price:</Label>
<TextBox Grid.Row="14" Grid.Column="1" IsEnabled="False" Text="{Binding TotalPrice}" />
</Grid>
</UserControl>
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;
namespace ArbitrageClient
{
/// <summary>
/// Interaction logic for AddPurchaseUserControl.xaml
/// </summary>
public partial class AddPurchaseUserControl : UserControl
{
public AddPurchaseUserControl()
{
InitializeComponent();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArbitrageClient
{
class AddPurchaseViewModel : INotifyPropertyChanged
{
private AddPurchaseModel addPurchaseModel;
public AddPurchaseViewModel()
{
AddPurchaseModel = new AddPurchaseModel { };
}
public AddPurchaseModel AddPurchaseModel
{
get
{
return addPurchaseModel;
}
set
{
addPurchaseModel = value;
}
}
public DateTime PurchaseDate
{
get
{
return AddPurchaseModel.PurchaseDate;
}
set
{
if (AddPurchaseModel.PurchaseDate != value)
{
AddPurchaseModel.PurchaseDate = value;
RaisePropertyChanged("PurchaseDate");
}
}
}
public string SellerName
{
get
{
return AddPurchaseModel.SellerName;
}
set
{
if (AddPurchaseModel.SellerName != value)
{
AddPurchaseModel.SellerName = value;
RaisePropertyChanged("SellerName");
}
}
}
public string SellerStreet
{
get
{
return AddPurchaseModel.SellerStreet;
}
set
{
if (AddPurchaseModel.SellerStreet != value)
{
AddPurchaseModel.SellerStreet = value;
RaisePropertyChanged("SellerStreet");
}
}
}
public string SellerCity
{
get
{
return AddPurchaseModel.SellerCity;
}
set
{
if (AddPurchaseModel.SellerCity != value)
{
AddPurchaseModel.SellerCity = value;
RaisePropertyChanged("SellerCity");
}
}
}
public string SellerTelephoneNumber
{
get
{
return AddPurchaseModel.SellerTelephoneNumber;
}
set
{
if (AddPurchaseModel.SellerTelephoneNumber != value)
{
AddPurchaseModel.SellerTelephoneNumber = value;
RaisePropertyChanged("SellerTelephoneNumber");
}
}
}
public string SellerComments
{
get
{
return AddPurchaseModel.SellerComments;
}
set
{
if (AddPurchaseModel.SellerComments != value)
{
AddPurchaseModel.SellerComments = value;
RaisePropertyChanged("SellerComments");
}
}
}
public decimal SellingPrice
{
get
{
return AddPurchaseModel.SellingPrice;
}
set
{
if (AddPurchaseModel.SellingPrice != value)
{
AddPurchaseModel.SellingPrice = value;
RaisePropertyChanged("SellingPrice");
}
}
}
public decimal FuelCost
{
get
{
return AddPurchaseModel.FuelCost;
}
set
{
if (AddPurchaseModel.FuelCost != value)
{
AddPurchaseModel.FuelCost = value;
RaisePropertyChanged("FuelCost");
}
}
}
public decimal ShippingCost
{
get
{
return AddPurchaseModel.ShippingCost;
}
set
{
if (AddPurchaseModel.ShippingCost != value)
{
AddPurchaseModel.ShippingCost = value;
RaisePropertyChanged("ShippingCost");
}
}
}
public bool ShippingIncluded
{
get
{
return AddPurchaseModel.ShippingIncluded;
}
set
{
if (AddPurchaseModel.ShippingIncluded != value)
{
AddPurchaseModel.ShippingIncluded = value;
RaisePropertyChanged("ShippingIncluded");
}
}
}
public decimal TotalPrice
{
get
{
return AddPurchaseModel.TotalPrice;
}
set
{
if (AddPurchaseModel.TotalPrice != value)
{
AddPurchaseModel.TotalPrice = value;
RaisePropertyChanged("TotalPrice");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment