Added first draft of Exercise 4 and 5

This commit is contained in:
Matteo Pagani 2019-01-14 18:52:40 +01:00
Родитель 8b47ef2770
Коммит 6ce80d6603
101 изменённых файлов: 2689 добавлений и 2336 удалений

Просмотреть файл

@ -1,344 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
// Type
// DependencyProperty, RoutedEventArgs, DependencyObject, FrameworkElement
// Control
// Debug
// AdornerLayer
// MouseEventArgs, MouseEventButtonArgs, KeyEventArgs, KeyboardFocusChangedEventArgs
// VisualTreeHelper
namespace EditBoxControlLibrary
{
/// <summary>
/// EditBox is a custom cotrol that can switch between two modes:
/// editing and normal. When it is in editing mode, the content is
/// displayed in a TextBox that provides editing capbability. When
/// the EditBox is in normal, its content is displayed in a TextBlock
/// that is not editable.
/// This control is designed to be used in with a GridView View.
/// </summary>
public class EditBox : Control
{
#region Static Constructor
/// <summary>
/// Static constructor
/// </summary>
static EditBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof (EditBox),
new FrameworkPropertyMetadata(typeof (EditBox)));
}
#endregion
#region Public Methods
/// <summary>
/// Called when the tree for the EditBox has been generated.
/// </summary>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var textBlock = GetTemplateChild("PART_TextBlockPart") as TextBlock;
Debug.Assert(textBlock != null, "No TextBlock!");
_textBox = new TextBox();
_adorner = new EditBoxAdorner(textBlock, _textBox);
var layer = AdornerLayer.GetAdornerLayer(textBlock);
layer.Add(_adorner);
_textBox.KeyDown += OnTextBoxKeyDown;
_textBox.LostKeyboardFocus +=
OnTextBoxLostKeyboardFocus;
//Receive notification of the event to handle the column
//resize.
HookTemplateParentResizeEvent();
//Capture the resize event to handle ListView resize cases.
HookItemsControlEvents();
_listViewItem = GetDependencyObjectFromVisualTree(this,
typeof (ListViewItem)) as ListViewItem;
Debug.Assert(_listViewItem != null, "No ListViewItem found");
}
#endregion
#region Protected Methods
/// <summary>
/// If the ListViewItem that contains the EditBox is selected,
/// when the mouse pointer moves over the EditBox, the corresponding
/// MouseEnter event is the first of two events (MouseUp is the second)
/// that allow the EditBox to change to editing mode.
/// </summary>
protected override void OnMouseEnter(MouseEventArgs e)
{
base.OnMouseEnter(e);
if (!IsEditing && IsParentSelected)
{
_canBeEdit = true;
}
}
/// <summary>
/// If the MouseLeave event occurs for an EditBox control that
/// is in normal mode, the mode cannot be changed to editing mode
/// until a MouseEnter event followed by a MouseUp event occurs.
/// </summary>
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
_isMouseWithinScope = false;
_canBeEdit = false;
}
/// <summary>
/// An EditBox switches to editing mode when the MouseUp event occurs
/// for that EditBox and the following conditions are satisfied:
/// 1. A MouseEnter event for the EditBox occurred before the
/// MouseUp event.
/// 2. The mouse did not leave the EditBox between the
/// MouseEnter and MouseUp events.
/// 3. The ListViewItem that contains the EditBox was selected
/// when the MouseEnter event occurred.
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(MouseButtonEventArgs e)
{
base.OnMouseUp(e);
if (e.ChangedButton == MouseButton.Right ||
e.ChangedButton == MouseButton.Middle)
return;
if (!IsEditing)
{
if (!e.Handled && (_canBeEdit || _isMouseWithinScope))
{
IsEditing = true;
}
//If the first MouseUp event selects the parent ListViewItem,
//then the second MouseUp event puts the EditBox in editing
//mode
if (IsParentSelected)
_isMouseWithinScope = true;
}
}
#endregion
#region Public Properties
#region Value
/// <summary>
/// ValueProperty DependencyProperty.
/// </summary>
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register(
"Value",
typeof (object),
typeof (EditBox),
new FrameworkPropertyMetadata(null));
/// <summary>
/// Gets or sets the value of the EditBox
/// </summary>
public object Value
{
get { return GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
#endregion
#region IsEditing
/// <summary>
/// IsEditingProperty DependencyProperty
/// </summary>
public static DependencyProperty IsEditingProperty =
DependencyProperty.Register(
"IsEditing",
typeof (bool),
typeof (EditBox),
new FrameworkPropertyMetadata(false));
/// <summary>
/// Returns true if the EditBox control is in editing mode.
/// </summary>
public bool IsEditing
{
get { return (bool) GetValue(IsEditingProperty); }
private set
{
SetValue(IsEditingProperty, value);
_adorner.UpdateVisibilty(value);
}
}
#endregion
#region IsParentSelected
/// <summary>
/// Gets whether the ListViewItem that contains the
/// EditBox is selected.
/// </summary>
private bool IsParentSelected
{
get
{
if (_listViewItem == null)
return false;
return _listViewItem.IsSelected;
}
}
#endregion
#endregion
#region Private Methods
/// <summary>
/// When an EditBox is in editing mode, pressing the ENTER or F2
/// keys switches the EditBox to normal mode.
/// </summary>
private void OnTextBoxKeyDown(object sender, KeyEventArgs e)
{
if (IsEditing && (e.Key == Key.Enter || e.Key == Key.F2))
{
IsEditing = false;
_canBeEdit = false;
}
}
/// <summary>
/// If an EditBox loses focus while it is in editing mode,
/// the EditBox mode switches to normal mode.
/// </summary>
private void OnTextBoxLostKeyboardFocus(object sender,
KeyboardFocusChangedEventArgs e)
{
IsEditing = false;
}
/// <summary>
/// Sets IsEditing to false when the ListViewItem that contains an
/// EditBox changes its size
/// </summary>
private void OnCouldSwitchToNormalMode(object sender,
RoutedEventArgs e)
{
IsEditing = false;
}
/// <summary>
/// Walk the visual tree to find the ItemsControl and
/// hook its some events on it.
/// </summary>
private void HookItemsControlEvents()
{
_itemsControl = GetDependencyObjectFromVisualTree(this,
typeof (ItemsControl)) as ItemsControl;
if (_itemsControl != null)
{
//Handle the Resize/ScrollChange/MouseWheel
//events to determine whether to switch to Normal mode
_itemsControl.SizeChanged +=
OnCouldSwitchToNormalMode;
_itemsControl.AddHandler(ScrollViewer.ScrollChangedEvent,
new RoutedEventHandler(OnScrollViewerChanged));
_itemsControl.AddHandler(MouseWheelEvent,
new RoutedEventHandler(OnCouldSwitchToNormalMode), true);
}
}
/// <summary>
/// If an EditBox is in editing mode and the content of a ListView is
/// scrolled, then the EditBox switches to normal mode.
/// </summary>
private void OnScrollViewerChanged(object sender, RoutedEventArgs args)
{
if (IsEditing && Mouse.PrimaryDevice.LeftButton ==
MouseButtonState.Pressed)
{
IsEditing = false;
}
}
/// <summary>
/// Walk visual tree to find the first DependencyObject
/// of the specific type.
/// </summary>
private DependencyObject
GetDependencyObjectFromVisualTree(DependencyObject startObject,
Type type)
{
//Walk the visual tree to get the parent(ItemsControl)
//of this control
var parent = startObject;
while (parent != null)
{
if (type.IsInstanceOfType(parent))
break;
parent = VisualTreeHelper.GetParent(parent);
}
return parent;
}
/// <summary>
/// When the size of the column containing the EditBox changes
/// and the EditBox is in editing mode, switch the mode to normal mode
/// </summary>
private void HookTemplateParentResizeEvent()
{
var parent = TemplatedParent as FrameworkElement;
if (parent != null)
{
parent.SizeChanged +=
OnCouldSwitchToNormalMode;
}
}
#endregion
#region private variable
private EditBoxAdorner _adorner;
//A TextBox in the visual tree
private FrameworkElement _textBox;
//Specifies whether an EditBox can switch to editing mode.
//Set to true if the ListViewItem that contains the EditBox is
//selected, when the mouse pointer moves over the EditBox
private bool _canBeEdit;
//Specifies whether an EditBox can switch to editing mode.
//Set to true when the ListViewItem that contains the EditBox is
//selected when the mouse pointer moves over the EditBox.
private bool _isMouseWithinScope;
//The ListView control that contains the EditBox
private ItemsControl _itemsControl;
//The ListViewItem control that contains the EditBox
private ListViewItem _listViewItem;
#endregion
}
}

Просмотреть файл

@ -1,90 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{558EEE03-6927-4FE6-AEB6-972769960849}</ProjectGuid>
<OutputType>library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EditBoxControlLibrary</RootNamespace>
<AssemblyName>EditBoxControlLibrary</AssemblyName>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Page Include="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="EditBox.cs" />
<Compile Include="EditboxAdorner.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -1,84 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
<Reference Include="Accessibility" />
<Reference Include="UIAutomationClient" />
<Reference Include="UIAutomationProvider" />
<Reference Include="UIAutomationTypes" />
</ItemGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{558EEE03-6927-4FE6-AEB6-972769960849}</ProjectGuid>
<OutputType>library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EditBoxControlLibrary</RootNamespace>
<AssemblyName>EditBoxControlLibrary</AssemblyName>
<FileAlignment>512</FileAlignment>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<Page Include="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="EditBox.cs" />
<Compile Include="EditboxAdorner.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -1,170 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
// EventArgs
// Debug
// UIElement, Size
// TextBox, Canvas
// Binding, BindingMode, UpdateSourceTrigger
// Adorner
// Visual, VisualCollection
namespace EditBoxControlLibrary
{
/// <summary>
/// An adorner class that contains a TextBox to provide editing capability
/// for an EditBox control. The editable TextBox resides in the
/// AdornerLayer. When the EditBox is in editing mode, the TextBox is given a size
/// it with desired size; otherwise, arrange it with size(0,0,0,0).
/// </summary>
internal sealed class EditBoxAdorner : Adorner
{
/// <summary>
/// Inialize the EditBoxAdorner.
/// </summary>
public EditBoxAdorner(UIElement adornedElement, UIElement adorningElement) : base(adornedElement)
{
var textBox = adorningElement as TextBox;
if (textBox == null) throw new ArgumentException("adorningElement is not a TextBox.");
_textBox = textBox;
_visualChildren = new VisualCollection(this);
BuildTextBox();
}
#region Public Methods
/// <summary>
/// Specifies whether a TextBox is visible
/// when the IsEditing property changes.
/// </summary>
/// <param name="isVisible"></param>
public void UpdateVisibilty(bool isVisible)
{
_isVisible = isVisible;
InvalidateMeasure();
}
#endregion
#region Protected Methods
/// <summary>
/// Override to measure elements.
/// </summary>
protected override Size MeasureOverride(Size constraint)
{
_textBox.IsEnabled = _isVisible;
//if in editing mode, measure the space the adorner element
//should cover.
if (_isVisible)
{
AdornedElement.Measure(constraint);
_textBox.Measure(constraint);
//since the adorner is to cover the EditBox, it should return
//the AdornedElement.Width, the extra 15 is to make it more
//clear.
return new Size(AdornedElement.DesiredSize.Width + ExtraWidth,
_textBox.DesiredSize.Height);
}
return new Size(0, 0);
}
/// <summary>
/// override function to arrange elements.
/// </summary>
protected override Size ArrangeOverride(Size finalSize)
{
if (_isVisible)
{
_textBox.Arrange(new Rect(0, 0, finalSize.Width,
finalSize.Height));
}
else // if is not is editable mode, no need to show elements.
{
_textBox.Arrange(new Rect(0, 0, 0, 0));
}
return finalSize;
}
/// <summary>
/// override property to return infomation about visual tree.
/// </summary>
protected override int VisualChildrenCount => _visualChildren.Count;
/// <summary>
/// override function to return infomation about visual tree.
/// </summary>
protected override Visual GetVisualChild(int index) => _visualChildren[index];
#endregion
#region Private Methods
/// <summary>
/// Inialize necessary properties and hook necessary events on TextBox,
/// then add it into tree.
/// </summary>
private void BuildTextBox()
{
_canvas = new Canvas();
_canvas.Children.Add(_textBox);
_visualChildren.Add(_canvas);
//Bind Text onto AdornedElement.
var binding = new Binding("Text")
{
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
Source = AdornedElement
};
_textBox.SetBinding(TextBox.TextProperty, binding);
// when layout finishes.
_textBox.LayoutUpdated += OnTextBoxLayoutUpdated;
}
/// <summary>
/// When Layout finish, if in editable mode, update focus status
/// on TextBox.
/// </summary>
private void OnTextBoxLayoutUpdated(object sender, EventArgs e)
{
if (_isVisible) _textBox.Focus();
}
#endregion
#region Private Variables
// Visual children
private readonly VisualCollection _visualChildren;
// The TextBox that this adorner covers.
private readonly TextBox _textBox;
// Whether the EditBox is in editing mode which means the Adorner is visible.
private bool _isVisible;
// Canvas that contains the TextBox that provides the ability for it to
// display larger than the current size of the cell so that the entire
// contents of the cell can be edited
private Canvas _canvas;
// Extra padding for the content when it is displayed in the TextBox
private const double ExtraWidth = 15;
#endregion
}
}

Просмотреть файл

@ -1,6 +0,0 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:EditBoxControlLibrary">
</ResourceDictionary>

Просмотреть файл

@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExpenseItDemo", "ExpenseItDemo\ExpenseItDemo.csproj", "{D1729F17-99A5-45AF-AB38-72FA6ECCE609}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditBoxControlLibrary", "EditBoxControlLibrary\EditBoxControlLibrary.csproj", "{558EEE03-6927-4FE6-AEB6-972769960849}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D1729F17-99A5-45AF-AB38-72FA6ECCE609}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1729F17-99A5-45AF-AB38-72FA6ECCE609}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1729F17-99A5-45AF-AB38-72FA6ECCE609}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1729F17-99A5-45AF-AB38-72FA6ECCE609}.Release|Any CPU.Build.0 = Release|Any CPU
{558EEE03-6927-4FE6-AEB6-972769960849}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{558EEE03-6927-4FE6-AEB6-972769960849}.Debug|Any CPU.Build.0 = Debug|Any CPU
{558EEE03-6927-4FE6-AEB6-972769960849}.Release|Any CPU.ActiveCfg = Release|Any CPU
{558EEE03-6927-4FE6-AEB6-972769960849}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {75B248BA-8AF5-4FC7-9247-8471EFB2C767}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

Просмотреть файл

@ -1,14 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Windows;
namespace ExpenseItDemo
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

Просмотреть файл

@ -1,245 +0,0 @@
<Application x:Class="ExpenseItDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ExpenseItDemo"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ExpenseReport x:Key="ExpenseData"
xmlns="clr-namespace:ExpenseItDemo"
Alias="Someone@example.com"
EmployeeNumber="57304"
CostCenter="4032">
<ExpenseReport.LineItems>
<LineItem Type="Meal" Description="Mexican Lunch" Cost="12" />
<LineItem Type="Meal" Description="Italian Dinner" Cost="45" />
<LineItem Type="Education" Description="Developer Conference" Cost="90" />
<LineItem Type="Travel" Description="Taxi" Cost="70" />
<LineItem Type="Travel" Description="Hotel" Cost="60" />
</ExpenseReport.LineItems>
</ExpenseReport>
<XmlDataProvider x:Key="CostCenters" XPath="/CostCenters/*">
<x:XData>
<CostCenters xmlns="">
<CostCenter Number="4032" Name="Sales" />
<CostCenter Number="4034" Name="Marketing" />
<CostCenter Number="5061" Name="Human Resources" />
<CostCenter Number="5062" Name="Research and Development" />
</CostCenters>
</x:XData>
</XmlDataProvider>
<XmlDataProvider x:Key="Employees" XPath="/Employees/*">
<x:XData>
<Employees xmlns="">
<Employee Name="Terry Adams" Type="FTE" EmployeeNumber="1" />
<Employee Name="Claire O&apos;Donnell" Type="FTE" EmployeeNumber="12345" />
<Employee Name="Palle Peterson" Type="FTE" EmployeeNumber="5678" />
<Employee Name="Amy E. Alberts" Type="CSG" EmployeeNumber="99222" />
<Employee Name="Stefan Hesse" Type="Vendor" EmployeeNumber="-" />
</Employees>
</x:XData>
</XmlDataProvider>
<Style x:Key="WatermarkImage" TargetType="{x:Type Image}">
<Setter Property="Source" Value="watermark.png" />
<Setter Property="HorizontalAlignment" Value="left" />
<Setter Property="VerticalAlignment" Value="top" />
<Setter Property="Width" Value="230" />
<Setter Property="Opacity" Value="0.5" />
</Style>
<Style x:Key="CommandButton" TargetType="{x:Type Button}">
<Setter Property="Margin" Value="0,10,5,5" />
<Setter Property="Padding" Value="5,2,5,2" />
<Setter Property="MinWidth" Value="80" />
</Style>
<Style x:Key="WindowContentGrid" TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="5" />
</Style>
<Style x:Key="Label" TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="DarkSlateBlue" />
<Setter Property="FontSize" Value="10pt" />
<Setter Property="Margin" Value="0,3,0,0" />
<Setter Property="FontFamily" Value="Trebuchet MS" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
<Style x:Key="ExpenseChart" TargetType="{x:Type ItemsControl}">
<Setter Property="DataContext" Value="{DynamicResource ExpenseData}" />
<Setter Property="ItemsSource" Value="{Binding Path=LineItems}" />
<Setter Property="ItemTemplate" Value="{DynamicResource ExpenseChartBar}" />
<Setter Property="Margin" Value="5,5,5,0" />
<Setter Property="MinWidth" Value="80" />
<Setter Property="MinHeight" Value="50" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ItemsControl}">
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<Rectangle StrokeThickness="1" RadiusX="10" RadiusY="10">
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#4E87D4" Offset="0" />
<GradientStop Color="#73B2F5" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#73B2F5" Offset="0" />
<GradientStop Color="#4E87D4" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Viewbox Margin="1"
Stretch="Uniform">
<StackPanel Orientation="Horizontal"
IsItemsHost="True" />
</Viewbox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="TotalExpenses" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="18pt" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Margin" Value="0,10,15,10" />
</Style>
<Style x:Key="TotalExpensesFlow" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
<Style x:Key="TotalHeaderGrid" TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="10,10,10,0" />
</Style>
<Style x:Key="TotalRectangle" TargetType="{x:Type Rectangle}">
<Setter Property="Margin" Value="5,5,5,0" />
<Setter Property="StrokeThickness" Value="1" />
<Setter Property="RadiusX" Value="10" />
<Setter Property="RadiusY" Value="10" />
<Setter Property="Stroke">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#4E87D4" Offset="0" />
<GradientStop Color="#73B2F5" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Fill">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#73B2F5" Offset="0" />
<GradientStop Color="#4E87D4" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="ExpenseChartBar">
<Grid VerticalAlignment="Bottom" Width="40">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="10" />
</Grid.RowDefinitions>
<Rectangle Grid.Row="0"
Height="{Binding Path=Cost}"
Margin="10,10,10,0"
Fill="#33000000"
RadiusX="2"
RadiusY="2">
<Rectangle.RenderTransform>
<TranslateTransform X="1"
Y="1" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Grid.Row="0"
Height="{Binding Path=Cost}"
Margin="10,10,10,0"
RadiusX="2"
RadiusY="2"
Stroke="black"
StrokeThickness="0.5">
<Rectangle.Fill>
<RadialGradientBrush>
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="LimeGreen"
Offset="0" />
<GradientStop Color="DarkGreen"
Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="0"
Height="{Binding Path=Cost}"
Margin="11,12,11,0"
RadiusX="1"
RadiusY="1">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0"
EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#aaffffff"
Offset="0" />
<GradientStop Color="transparent"
Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Viewbox Grid.Row="1"
Width="30"
Margin="2">
<TextBlock Grid.Row="1"
Width="100"
FontSize="10pt"
FontFamily="Arial"
TextAlignment="center"
TextTrimming="WordEllipsis"
Text="{Binding Path=Description}" />
</Viewbox>
<TextBlock Margin="0,5,0,3"
FontSize="4pt"
FontFamily="Arial"
TextAlignment="center"
Foreground="white"
Text="{Binding Path=Cost}" />
</Grid>
</DataTemplate>
</Application.Resources>
</Application>

Просмотреть файл

@ -1,47 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Windows;
namespace ExpenseItDemo
{
/// <summary>
/// Interaction logic for CreateExpenseReportDialogBox.xaml
/// </summary>
public partial class CreateExpenseReportDialogBox : Window
{
public CreateExpenseReportDialogBox()
{
InitializeComponent();
}
private void addExpenseButton_Click(object sender, RoutedEventArgs e)
{
var app = Application.Current;
var expenseReport = (ExpenseReport) app.FindResource("ExpenseData");
expenseReport?.LineItems.Add(new LineItem());
}
private void viewChartButton_Click(object sender, RoutedEventArgs e)
{
var dlg = new ViewChartWindow {Owner = this};
dlg.Show();
}
private void okButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"Expense Report Created!",
"ExpenseIt Standalone",
MessageBoxButton.OK,
MessageBoxImage.Information);
DialogResult = true;
}
private void cancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
}
}

Просмотреть файл

@ -1,298 +0,0 @@
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ExpenseItDemo.CreateExpenseReportDialogBox"
xmlns:localValidation="clr-namespace:ExpenseItDemo.Validation"
DataContext="{StaticResource ExpenseData}"
Icon="Watermark.png"
Title="Create Expense Report"
MinWidth="600" MinHeight="500"
SizeToContent="WidthAndHeight"
ShowInTaskbar="False"
WindowStartupLocation="CenterOwner">
<Window.Resources>
<Style x:Key="ReadOnlyText" TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,5,5,0" />
<Setter Property="IsReadOnly" Value="True" />
</Style>
<Style x:Key="FunctionButton" TargetType="{x:Type Button}">
<Setter Property="Margin" Value="5,5,5,0" />
<Setter Property="Padding" Value="5,2,5,2" />
<Setter Property="MinWidth" Value="80" />
</Style>
<Style x:Key="TableLabel" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="White" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="10pt" />
<Setter Property="Padding" Value="5,0,5,0" />
</Style>
<Style x:Key="TableLabelRightAligned" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TableLabel}">
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
<Style x:Key="CommandButtonPanel" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
<Style x:Key="SeparatorRectangle" TargetType="{x:Type Rectangle}" BasedOn="{StaticResource TotalRectangle}">
<Setter Property="Height" Value="3" />
<Setter Property="RadiusX" Value="2" />
<Setter Property="RadiusY" Value="2" />
</Style>
<Style x:Key="TopSeparatorRectangle" TargetType="{x:Type Rectangle}"
BasedOn="{StaticResource SeparatorRectangle}">
<Setter Property="Margin" Value="5,10,5,5" />
</Style>
<Style x:Key="BottomSeparatorRectangle" TargetType="{x:Type Rectangle}"
BasedOn="{StaticResource SeparatorRectangle}">
<Setter Property="Margin" Value="5,10,5,0" />
</Style>
<Style x:Key="ExpenseScroller" TargetType="{x:Type ItemsControl}">
<Setter Property="Margin" Value="10,0,10,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ItemsControl}">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel IsItemsHost="True" />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ExpenseChartSmall" TargetType="{x:Type ItemsControl}" BasedOn="{StaticResource ExpenseChart}">
<Setter Property="MinWidth" Value="100" />
<Setter Property="MinHeight" Value="70" />
<Setter Property="MaxWidth" Value="100" />
<Setter Property="MaxHeight" Value="70" />
<Setter Property="Margin" Value="5,5,5,5" />
</Style>
<DataTemplate x:Key="ExpenseTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
</Grid.ColumnDefinitions>
<TextBox Text="{Binding Path=Type}" Grid.Column="0" />
<TextBox Text="{Binding Path=Description}" Grid.Column="1" />
<TextBox Grid.Column="2" TextAlignment="Right">
<TextBox.Text>
<Binding Path="Cost" UpdateSourceTrigger="PropertyChanged">
<!-- SECURITY: Cost must be an int -->
<Binding.ValidationRules>
<localValidation:NumberValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<!-- Watermark -->
<Image Style="{StaticResource WatermarkImage}" />
<Grid Style="{StaticResource WindowContentGrid}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="50" />
<RowDefinition />
<RowDefinition Height="50" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Report Details -->
<Grid Grid.Row="0" Grid.ColumnSpan="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Alias -->
<Label Style="{StaticResource Label}" Target="{Binding ElementName=Alias}" Grid.Column="2" Grid.Row="0">
Email _Alias:
</Label>
<TextBox Name="aliasTextBox" Style="{StaticResource ReadOnlyText}" Grid.Column="3" Grid.Row="0"
Text="{Binding Path=Alias}">
<TextBox.ToolTip>
<TextBlock>email alias</TextBlock>
</TextBox.ToolTip>
</TextBox>
<!-- Employee Number -->
<Label Style="{StaticResource Label}" Target="{Binding ElementName=Number}" Grid.Column="2"
Grid.Row="1">
Employee _Number:
</Label>
<TextBox Name="employeeNumberTextBox" Style="{StaticResource ReadOnlyText}" Grid.Column="3"
Grid.Row="1" Text="{Binding Path=EmployeeNumber}">
<TextBox.ToolTip>
<TextBlock>employee number</TextBlock>
</TextBox.ToolTip>
</TextBox>
<!-- Cost Center -->
<Label Style="{StaticResource Label}" Target="{Binding ElementName=costCenter}" Grid.Column="2"
Grid.Row="2">
_Cost Center:
</Label>
<TextBox Name="costCenterTextBox" Style="{StaticResource ReadOnlyText}" Grid.Column="3" Grid.Row="2"
Text="{Binding Path=CostCenter}">
<TextBox.ToolTip>
<TextBlock>cost center</TextBlock>
</TextBox.ToolTip>
</TextBox>
</Grid>
<!-- Separator Rectangle -->
<Rectangle Style="{StaticResource TopSeparatorRectangle}" Grid.Row="1" Grid.ColumnSpan="3" />
<!-- Function Buttons -->
<StackPanel Grid.Row="2" Grid.Column="2" Grid.RowSpan="2">
<!-- Add Expense Button -->
<Button Style="{StaticResource FunctionButton}" Click="addExpenseButton_Click">
Add _Expense
<Button.ToolTip>
<TextBlock>add expense</TextBlock>
</Button.ToolTip>
</Button>
<!-- View Chart Button-->
<Button Style="{StaticResource FunctionButton}" Click="viewChartButton_Click">
<Button.ToolTip>
<TextBlock>View chart</TextBlock>
</Button.ToolTip>
<DockPanel>
<TextBlock DockPanel.Dock="Top" TextAlignment="Center">View Chart</TextBlock>
<ItemsControl Style="{StaticResource ExpenseChartSmall}" />
</DockPanel>
</Button>
</StackPanel>
<!-- Expense Report List -->
<Rectangle Style="{StaticResource TotalRectangle}" Grid.Row="2" Grid.RowSpan="2" Grid.ColumnSpan="2" />
<Grid Style="{StaticResource TotalHeaderGrid}" Grid.Row="2" Grid.ColumnSpan="2">
<Grid.ToolTip>
<TextBlock>Expense Report</TextBlock>
</Grid.ToolTip>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
<ColumnDefinition Width="33*" />
</Grid.ColumnDefinitions>
<Grid.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#73B2F5" Offset="0" />
<GradientStop Color="#4E87D4" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<!-- Expense Type Column Header -->
<TextBlock Style="{StaticResource TableLabel}" Grid.Column="0">
Expense Type
<TextBlock.ToolTip>
<TextBlock>Expense type</TextBlock>
</TextBlock.ToolTip>
</TextBlock>
<!-- Description Column Header -->
<TextBlock Style="{StaticResource TableLabel}" Grid.Column="1">
Description
<TextBlock.ToolTip>
<TextBlock>Desription</TextBlock>
</TextBlock.ToolTip>
</TextBlock>
<!-- Amount Column Header -->
<TextBlock Style="{StaticResource TableLabelRightAligned}" Grid.Column="2">
Amount
<TextBlock.ToolTip>
<TextBlock>Amount</TextBlock>
</TextBlock.ToolTip>
</TextBlock>
</Grid>
<ItemsControl Name="expensesItemsControl"
Style="{StaticResource ExpenseScroller}"
Grid.Row="3" Grid.ColumnSpan="2"
ItemTemplate="{StaticResource ExpenseTemplate}"
ItemsSource="{Binding Path=LineItems}" />
<!-- Total Expenses -->
<Rectangle Style="{StaticResource TotalRectangle}" Grid.Row="4" Grid.ColumnSpan="2" />
<StackPanel Style="{StaticResource TotalExpensesFlow}" Grid.Row="4" Grid.ColumnSpan="2">
<TextBlock Style="{StaticResource TotalExpenses}">
Total Expenses ($):
<TextBlock.ToolTip>
<TextBlock>Total expenses</TextBlock>
</TextBlock.ToolTip>
</TextBlock>
<TextBlock Style="{StaticResource TotalExpenses}"
Text="{Binding Path=TotalExpenses, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<!-- Separator Rectangle -->
<Rectangle Style="{StaticResource BottomSeparatorRectangle}" Grid.Row="5" Grid.ColumnSpan="3" />
<!-- Command Buttons -->
<StackPanel Style="{StaticResource CommandButtonPanel}" Grid.Row="6" Grid.ColumnSpan="3">
<!-- Ok Button -->
<Button Style="{StaticResource CommandButton}" Click="okButton_Click" IsDefault="True">
_OK
<Button.ToolTip>
<TextBlock>OK</TextBlock>
</Button.ToolTip>
</Button>
<!-- Cancel Button -->
<Button Style="{StaticResource CommandButton}" Click="cancelButton_Click" IsCancel="True">
_Cancel
<Button.ToolTip>
<TextBlock>Cancel</TextBlock>
</Button.ToolTip>
</Button>
</StackPanel>
</Grid>
</Grid>
</Window>

Просмотреть файл

@ -1,122 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
<Reference Include="Accessibility" />
<Reference Include="UIAutomationClient" />
<Reference Include="UIAutomationProvider" />
<Reference Include="UIAutomationTypes" />
</ItemGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D1729F17-99A5-45AF-AB38-72FA6ECCE609}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ExpenseItDemo</RootNamespace>
<AssemblyName>ExpenseItDemo</AssemblyName>
<FileAlignment>512</FileAlignment>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="CreateExpenseReportDialogBox.cs">
<DependentUpon>CreateExpenseReportDialogBox.xaml</DependentUpon>
</Compile>
<Compile Include="ExpenseReport.cs" />
<Compile Include="LineItem.cs" />
<Compile Include="LineItemCollection.cs" />
<Compile Include="Validation\EmailValidationrule.cs" />
<Compile Include="Validation\NumberValidationrule.cs" />
<Compile Include="ViewChartWindow.cs">
<DependentUpon>ViewChartWindow.xaml</DependentUpon>
</Compile>
<Page Include="CreateExpenseReportDialogBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="ViewChartWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EditBoxControlLibrary\EditBoxControlLibrary.netcore.csproj">
<Project>{558eee03-6927-4fe6-aeb6-972769960849}</Project>
<Name>EditBoxControlLibrary</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Watermark.png" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,87 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.ComponentModel;
// EventHandler
// ObservableCollection
// INotifyPropertyChanged, PropertyChangedEventArgs
namespace ExpenseItDemo
{
public class ExpenseReport : INotifyPropertyChanged
{
private string _alias;
private string _costCenter;
private string _employeeNumber;
private int _totalExpenses;
public ExpenseReport()
{
LineItems = new LineItemCollection();
LineItems.LineItemCostChanged += OnLineItemCostChanged;
}
public string Alias
{
get { return _alias; }
set
{
_alias = value;
OnPropertyChanged("Alias");
}
}
public string CostCenter
{
get { return _costCenter; }
set
{
_costCenter = value;
OnPropertyChanged("CostCenter");
}
}
public string EmployeeNumber
{
get { return _employeeNumber; }
set
{
_employeeNumber = value;
OnPropertyChanged("EmployeeNumber");
}
}
public int TotalExpenses
{
// calculated property, no setter
get
{
RecalculateTotalExpense();
return _totalExpenses;
}
}
public LineItemCollection LineItems { get; }
public event PropertyChangedEventHandler PropertyChanged;
private void OnLineItemCostChanged(object sender, EventArgs e)
{
OnPropertyChanged("TotalExpenses");
}
private void RecalculateTotalExpense()
{
_totalExpenses = 0;
foreach (var item in LineItems)
_totalExpenses += item.Cost;
}
private void OnPropertyChanged(string propName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
}
}

Просмотреть файл

@ -1,51 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.ComponentModel;
namespace ExpenseItDemo
{
public class LineItem : INotifyPropertyChanged
{
private int _cost;
private string _description = "(Description)";
private string _type = "(Expense type)";
public string Type
{
get { return _type; }
set
{
_type = value;
OnPropertyChanged("Type");
}
}
public string Description
{
get { return _description; }
set
{
_description = value;
OnPropertyChanged("Description");
}
}
public int Cost
{
get { return _cost; }
set
{
_cost = value;
OnPropertyChanged("Cost");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
}
}

Просмотреть файл

@ -1,36 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace ExpenseItDemo
{
public class LineItemCollection : ObservableCollection<LineItem>
{
public event EventHandler LineItemCostChanged;
public new void Add(LineItem item)
{
if (item != null)
{
item.PropertyChanged += LineItemPropertyChanged;
}
base.Add(item);
}
private void LineItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Cost")
{
OnLineItemCostChanged(this, new EventArgs());
}
}
private void OnLineItemCostChanged(object sender, EventArgs args)
{
LineItemCostChanged?.Invoke(sender, args);
}
}
}

Просмотреть файл

@ -1,116 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace ExpenseItDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
static MainWindow()
{
// Define CreateExpenseReportCommand
CreateExpenseReportCommand = new RoutedUICommand("_Create Expense Report...", "CreateExpenseReport",
typeof (MainWindow));
CreateExpenseReportCommand.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Shift));
// Define ExitCommand
ExitCommand = new RoutedUICommand("E_xit", "Exit", typeof (MainWindow));
// Define AboutCommand
AboutCommand = new RoutedUICommand("_About ExpenseIt Standalone", "About", typeof (MainWindow));
}
public MainWindow()
{
Initialized += MainWindow_Initialized;
InitializeComponent();
employeeTypeRadioButtons.SelectionChanged += employeeTypeRadioButtons_SelectionChanged;
// Bind CreateExpenseReportCommand
var commandBindingCreateExpenseReport = new CommandBinding(CreateExpenseReportCommand);
commandBindingCreateExpenseReport.Executed += commandBindingCreateExpenseReport_Executed;
CommandBindings.Add(commandBindingCreateExpenseReport);
// Bind ExitCommand
var commandBindingExitCommand = new CommandBinding(ExitCommand);
commandBindingExitCommand.Executed += commandBindingExitCommand_Executed;
CommandBindings.Add(commandBindingExitCommand);
// Bind AboutCommand
var commandBindingAboutCommand = new CommandBinding(AboutCommand);
commandBindingAboutCommand.Executed += commandBindingAboutCommand_Executed;
CommandBindings.Add(commandBindingAboutCommand);
}
private void MainWindow_Initialized(object sender, EventArgs e)
{
// Select the first employee type radio button
employeeTypeRadioButtons.SelectedIndex = 0;
RefreshEmployeeList();
}
private void commandBindingCreateExpenseReport_Executed(object sender, ExecutedRoutedEventArgs e)
{
var dlg = new CreateExpenseReportDialogBox {Owner = this};
dlg.ShowDialog();
}
private void commandBindingExitCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Close();
}
private void commandBindingAboutCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show(
"ExpenseIt Standalone Sample Application, by the WPF SDK",
"ExpenseIt Standalone",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
private void employeeTypeRadioButtons_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
RefreshEmployeeList();
}
/// <summary>
/// Select the employees who have the employment type that is specified
/// by the currently checked employee type radio button
/// </summary>
private void RefreshEmployeeList()
{
var selectedItem = (ListBoxItem) employeeTypeRadioButtons.SelectedItem;
// Get employees data source
var employeesDataSrc = (XmlDataProvider) FindResource("Employees");
// Select the employees who have of the specified employment type
var query = string.Format(CultureInfo.InvariantCulture, "/Employees/Employee[@Type='{0}']",
selectedItem.Content);
employeesDataSrc.XPath = query;
// Apply the selection
employeesDataSrc.Refresh();
}
#region Commands
public static RoutedUICommand CreateExpenseReportCommand;
public static RoutedUICommand ExitCommand;
public static RoutedUICommand AboutCommand;
#endregion
}
}

Просмотреть файл

@ -1,232 +0,0 @@
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ExpenseItDemo"
xmlns:localValidation="clr-namespace:ExpenseItDemo.Validation"
x:Class="ExpenseItDemo.MainWindow"
DataContext="{StaticResource ExpenseData}"
Title="ExpenseIt Standalone"
MinWidth="480" MinHeight="260"
SizeToContent="WidthAndHeight"
Icon="Watermark.png"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="EmployeeList" TargetType="{x:Type ListBox}">
<Setter Property="Margin" Value="0,5,5,0" />
<Setter Property="MinHeight" Value="50" />
</Style>
<Style x:Key="CostCenterList" TargetType="{x:Type ComboBox}">
<Setter Property="Margin" Value="0,5,5,0" />
</Style>
<Style x:Key="HorizontalRadio" TargetType="{x:Type ListBoxItem}">
<Setter Property="Margin" Value="0,5,5,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<RadioButton Focusable="false"
Content="{TemplateBinding ContentPresenter.Content}"
VerticalAlignment="Center"
IsChecked="{Binding Path=IsSelected,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="HorizontalRadioList" TargetType="{x:Type ListBox}">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Margin" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<StackPanel KeyboardNavigation.TabNavigation="Once" IsItemsHost="True" Orientation="Horizontal"
Height="25" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="InputText" TargetType="{x:Type TextBox}">
<Setter Property="FontFamily" Value="Trebuchet MS" />
<Setter Property="Foreground" Value="#0066CC" />
<Setter Property="FontSize" Value="10pt" />
<Setter Property="Margin" Value="0,5,5,0" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
</Trigger>
<Trigger Property="Validation.HasError" Value="false">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=ToolTip.Content}" />
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="EmployeeItemTemplate">
<TextBlock Text="{Binding XPath=@Name}" />
</DataTemplate>
<DataTemplate x:Key="CostCenterTemplate">
<TextBlock Text="{Binding XPath=@Name}" />
</DataTemplate>
</Window.Resources>
<Grid>
<!-- Watermark -->
<Image Style="{StaticResource WatermarkImage}" />
<DockPanel>
<!-- Menu Bar-->
<Menu DockPanel.Dock="Top">
<!-- File Menu-->
<MenuItem Header="_File">
<MenuItem Command="local:MainWindow.CreateExpenseReportCommand" />
<Separator />
<MenuItem Command="local:MainWindow.ExitCommand" />
</MenuItem>
<!-- Help Menu-->
<MenuItem Header="_Help">
<MenuItem Command="local:MainWindow.AboutCommand" />
</MenuItem>
</Menu>
<!-- Data Entry -->
<Grid Style="{StaticResource WindowContentGrid}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Email Address -->
<Label Style="{StaticResource Label}" Target="{Binding ElementName=emailTextBox}" Grid.Column="0"
Grid.Row="0">
_Email:
</Label>
<TextBox Name="emailTextBox" Style="{StaticResource InputText}" Grid.Column="1" Grid.Row="0">
<TextBox.Text>
<Binding Path="Alias" UpdateSourceTrigger="PropertyChanged">
<!-- SECURITY: Email alias must be valid email address eg xxx@xxx.com -->
<Binding.ValidationRules>
<localValidation:EmailValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
<TextBox.ToolTip>Enter email.</TextBox.ToolTip>
</TextBox>
<!-- Employee Number -->
<Label Style="{StaticResource Label}" Target="{Binding ElementName=employeeNumberTextBox}"
Grid.Column="0" Grid.Row="1">
Employee _Number:
</Label>
<TextBox Name="employeeNumberTextBox" Style="{StaticResource InputText}" Grid.Column="1" Grid.Row="1">
<TextBox.Text>
<Binding Path="EmployeeNumber" UpdateSourceTrigger="PropertyChanged">
<!-- SECURITY: EmployeeNumber must be an int and 5 digits long -->
<Binding.ValidationRules>
<localValidation:NumberValidationRule IsFixedLength="True" Length="5" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
<TextBox.ToolTip>Enter employee number.</TextBox.ToolTip>
</TextBox>
<!-- Cost Center -->
<Label Style="{StaticResource Label}" Target="{Binding ElementName=costCenterTextBox}" Grid.Column="0"
Grid.Row="2">
_Cost Center:
</Label>
<ComboBox Name="costCenterTextBox"
Style="{StaticResource CostCenterList}"
Grid.Column="1" Grid.Row="2"
ItemTemplate="{StaticResource CostCenterTemplate}"
ItemsSource="{Binding Source={StaticResource CostCenters}}"
SelectedValue="{Binding Path=CostCenter}"
SelectedValuePath="@Number">
<ComboBox.ToolTip>
<TextBlock>Choose cost center.</TextBlock>
</ComboBox.ToolTip>
<ComboBox.ItemContainerStyle>
<Style>
<Setter Property="AutomationProperties.Name" Value="{Binding XPath=@Name}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
<!-- Employee Type List -->
<Label Style="{StaticResource Label}" Target="{Binding ElementName=employeeTypeRadioButtons}"
Grid.Column="0" Grid.Row="3">
E_mployees:
</Label>
<ListBox Name="employeeTypeRadioButtons" Style="{StaticResource HorizontalRadioList}" Grid.Column="1"
Grid.Row="3">
<ListBoxItem Style="{StaticResource HorizontalRadio}">
FTE
<ListBoxItem.ToolTip>
<TextBlock>FTE employee type</TextBlock>
</ListBoxItem.ToolTip>
</ListBoxItem>
<ListBoxItem Style="{StaticResource HorizontalRadio}">
CSG
<ListBoxItem.ToolTip>
<TextBlock>CSG employee type</TextBlock>
</ListBoxItem.ToolTip>
</ListBoxItem>
<ListBoxItem Style="{StaticResource HorizontalRadio}">
Vendor
<ListBoxItem.ToolTip>
<TextBlock>Vendor employee type</TextBlock>
</ListBoxItem.ToolTip>
</ListBoxItem>
</ListBox>
<!-- Employee List -->
<ListBox Style="{StaticResource EmployeeList}"
Grid.Column="1" Grid.Row="4"
ItemTemplate="{StaticResource EmployeeItemTemplate}"
ItemsSource="{Binding Source={StaticResource Employees}}">
<ListBox.ToolTip>
<TextBlock>Choose employee name.</TextBlock>
</ListBox.ToolTip>
<ListBox.ItemContainerStyle>
<Style>
<Setter Property="AutomationProperties.Name" Value="{Binding XPath=@Name}" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<!-- Create Expense Report -->
<Button Name="createExpenseReportButton" Style="{StaticResource CommandButton}" Grid.Column="1"
Grid.Row="5" Command="local:MainWindow.CreateExpenseReportCommand">
Create Expense _Report
<Button.ToolTip>
<TextBlock>Create Expense Report.</TextBlock>
</Button.ToolTip>
</Button>
</Grid>
</DockPanel>
</Grid>
</Window>

Просмотреть файл

@ -1,71 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ExpenseItDemo.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ExpenseItDemo.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

Просмотреть файл

@ -1,30 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ExpenseItDemo.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

Просмотреть файл

@ -1,32 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Globalization;
using System.Text.RegularExpressions;
using System.Windows.Controls;
// ValidationRule
// CultureInfo
namespace ExpenseItDemo.Validation
{
// Email Validation Rule
public class EmailValidationRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
// Is a valid email address?
var pattern =
@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*";
if (!Regex.IsMatch((string) value, pattern))
{
var msg = $"{value} is not a valid email address.";
return new ValidationResult(false, msg);
}
// Email address is valid
return new ValidationResult(true, null);
}
}
}

Просмотреть файл

@ -1,47 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Globalization;
using System.Windows.Controls;
// ValidationRule
// CultureInfo
namespace ExpenseItDemo.Validation
{
// Number Validation Rule
public class NumberValidationRule : ValidationRule
{
/// <summary>
/// Must the number be a specific length
/// </summary>
public bool IsFixedLength { get; set; }
/// <summary>
/// The required length of the number, if IsFixedLength is true
/// </summary>
public int Length { get; set; }
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
// Is the value a number?
int number;
if (!int.TryParse((string) value, out number))
{
var msg = $"{value} is not a number.";
return new ValidationResult(false, msg);
}
// Does value contain the number of digits specified by Length?
if (IsFixedLength && (((string) value).Length != Length))
{
var msg = $"Number must be {Length} digits long.";
return new ValidationResult(false, msg);
}
// Number is valid
return new ValidationResult(true, null);
}
}
}

Просмотреть файл

@ -1,23 +0,0 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Windows;
namespace ExpenseItDemo
{
/// <summary>
/// Interaction logic for ViewChartWindow.xaml
/// </summary>
public partial class ViewChartWindow : Window
{
public ViewChartWindow()
{
InitializeComponent();
}
private void closeButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}

Просмотреть файл

@ -1,57 +0,0 @@
<Window x:Class="ExpenseItDemo.ViewChartWindow"
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:ExpenseItDemo"
mc:Ignorable="d"
Title="ViewChartWindow" Height="300" Width="300">
<Grid Style="{StaticResource WindowContentGrid}">
<Grid>
<Grid.ToolTip>
<TextBlock>Chart view</TextBlock>
</Grid.ToolTip>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Expenses Chart -->
<ItemsControl Style="{DynamicResource ExpenseChart}" Grid.Row="0" Grid.ColumnSpan="2" />
<!-- Total Expenses -->
<Rectangle Style="{StaticResource TotalRectangle}" Grid.Row="1" Grid.ColumnSpan="2" />
<StackPanel Style="{StaticResource TotalExpensesFlow}" Grid.Row="1" Grid.ColumnSpan="2">
<TextBlock Style="{StaticResource TotalExpenses}">
Total Expenses ($):
<TextBlock.ToolTip>
<TextBlock>Total expenses</TextBlock>
</TextBlock.ToolTip>
</TextBlock>
<TextBlock Style="{StaticResource TotalExpenses}"
Text="{Binding Path=TotalExpenses, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<!-- Close Button -->
<Button Style="{StaticResource CommandButton}" Grid.Row="2" Grid.Column="1" Click="closeButton_Click"
IsCancel="True">
<Button.ToolTip>
<TextBlock>
Close Expense Report Chart
</TextBlock>
</Button.ToolTip>
_Close
</Button>
</Grid>
</Grid>
</Window>

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 95 KiB

Просмотреть файл

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup>
<WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
</PropertyGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>2d8fd114-a304-45b1-bca2-16949103603e</ProjectGuid>
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<PackageCertificateKeyFile>ContosoExpenses.Package_TemporaryKey.pfx</PackageCertificateKeyFile>
<EntryPointProjectUniqueName>..\ContosoExpenses\ContosoExpenses.csproj</EntryPointProjectUniqueName>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<None Include="ContosoExpenses.Package_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\LockScreenLogo.scale-200.png" />
<Content Include="Images\Square150x150Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ContosoExpenses\ContosoExpenses.csproj" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.9 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.1 KiB

Просмотреть файл

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity
Name="5dde7e45-3be3-4273-a57d-93a49bbb14b2"
Publisher="CN=mpagani"
Version="1.0.0.0" />
<Properties>
<DisplayName>ContosoExpenses.Package</DisplayName>
<PublisherDisplayName>mpagani</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="ContosoExpenses.Package"
Description="ContosoExpenses.Package"
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile
Wide310x150Logo="Images\Wide310x150Logo.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>

Просмотреть файл

@ -0,0 +1,57 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28407.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContosoExpenses", "ContosoExpenses\ContosoExpenses.csproj", "{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}"
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "ContosoExpenses.Package", "ContosoExpenses.Package\ContosoExpenses.Package.wapproj", "{2D8FD114-A304-45B1-BCA2-16949103603E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x64.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x64.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x86.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x86.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|Any CPU.Build.0 = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x64.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x64.Build.0 = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x86.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x86.Build.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.ActiveCfg = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.Build.0 = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.Deploy.0 = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.ActiveCfg = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.Build.0 = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.Deploy.0 = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.Build.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.Deploy.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.ActiveCfg = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.Build.0 = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.Deploy.0 = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.ActiveCfg = Release|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.Build.0 = Release|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3BADFBD9-C57F-40A7-B058-D6B067196030}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,35 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.AboutView"
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"
mc:Ignorable="d" MinHeight="500" MinWidth="700" Height="500" Width="700">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" Margin="10">
Contoso Expenses is a 'modern application of yesterday tomorrow' from Contoso Corp.
</TextBlock>
<WebBrowser Grid.Row="1"
Source="https://contosocorpwebsite.azurewebsites.net/" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,27 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System.Linq;
using System.Linq.Expressions;
namespace ContosoExpenses
{
public partial class AboutView
{
public AboutView()
{
InitializeComponent();
}
}
}

Просмотреть файл

@ -0,0 +1,72 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.AddNewExpense"
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:xamlhost="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
xmlns:local="clr-namespace:ContosoExpenses"
Closed="Window_Closed"
mc:Ignorable="d"
Title="Add new expense" Height="800" Width="800"
Background="{StaticResource AddNewExpenseBackground}">
<Grid Margin="12">
<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"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock FontSize="24" Text="Add new expense" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
<TextBlock Text="Type:" FontSize="16" FontWeight="Bold" Grid.Row="1" Grid.Column="0" />
<TextBox x:Name="txtType" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Description:" FontSize="16" FontWeight="Bold" Grid.Row="2" Grid.Column="0" />
<TextBox x:Name="txtDescription" FontSize="16" Margin="5, 0, 0, 0" Width="400" Height="200" AcceptsReturn="True" Grid.Row="2" Grid.Column="1" />
<TextBlock Text="Amount:" FontSize="16" FontWeight="Bold" Grid.Row="3" Grid.Column="0" />
<TextBox x:Name="txtAmount" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="3" Grid.Column="1" />
<TextBlock Text="Location:" FontSize="16" FontWeight="Bold" Grid.Row="4" Grid.Column="0" />
<TextBox x:Name="txtLocation" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="4" Grid.Column="1" />
<TextBlock Text="City:" FontSize="16" FontWeight="Bold" Grid.Row="5" Grid.Column="0" />
<TextBox x:Name="txtCity" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="5" Grid.Column="1" />
<TextBlock Text="Choose a date:" FontSize="16" FontWeight="Bold" Grid.Row="6" Grid.Column="0" />
<xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.CalendarView" Grid.Column="1" Grid.Row="6" Margin="5, 0, 0, 0" x:Name="CalendarUwp"
ChildChanged="CalendarUwp_ChildChanged" />
<TextBlock Text="Selected date:" FontSize="16" FontWeight="Bold" Grid.Row="7" Grid.Column="0" />
<TextBlock x:Name="txtDate" FontSize="16" Grid.Row="7" Grid.Column="1" />
<Button Content="Save" Grid.Row="8" Grid.Column="0" Click="OnSaveExpense" Margin="5, 12, 0, 0" HorizontalAlignment="Left" Width="180" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,91 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using ContosoExpenses.Models;
using ContosoExpenses.Services;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using System;
using System.Linq;
using System.Threading;
using System.Windows;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for AddNewExpense.xaml
/// </summary>
public partial class AddNewExpense : Window
{
public int EmployeeId { get; set; }
private DateTime SelectedDate;
public AddNewExpense()
{
InitializeComponent();
}
private void OnSaveExpense(object sender, RoutedEventArgs e)
{
try
{
Expense expense = new Expense
{
Address = txtAmount.Text,
City = txtCity.Text,
Cost = Convert.ToDouble(txtAmount.Text),
Description = txtDescription.Text,
Type = txtType.Text,
Date = SelectedDate,
EmployeeId = EmployeeId
};
DatabaseService service = new DatabaseService();
service.SaveExpense(expense);
this.Close();
}
catch (Exception exc)
{
MessageBox.Show("Validation error. Please check your data.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void CalendarUwp_ChildChanged(object sender, EventArgs e)
{
WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender;
Windows.UI.Xaml.Controls.CalendarView calendarView =
(Windows.UI.Xaml.Controls.CalendarView)windowsXamlHost.Child;
if (calendarView!= null)
{
calendarView.SelectedDatesChanged += (obj, args) =>
{
if (calendarView.SelectedDates.Count > 0)
{
SelectedDate = calendarView.SelectedDates.FirstOrDefault().DateTime;
txtDate.Text = SelectedDate.ToShortDateString();
}
};
calendarView.SetDisplayDate(DateTime.Now);
}
}
private void Window_Closed(object sender, EventArgs e)
{
CalendarUwp.Dispose();
}
}
}

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

Просмотреть файл

@ -0,0 +1,55 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Application x:Class="ContosoExpenses.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ContosoExpenses"
StartupUri="MainWindow.xaml">
<Application.Resources>
<!--Background images-->
<ImageBrush x:Key="MainBackground"
ImageSource="Images\ExpensesBackground.jpg"
Stretch="UniformToFill" />
<ImageBrush x:Key="HorizontalBackground"
ImageSource="Images\HorizontalBackground.png"
Stretch="UniformToFill" />
<ImageBrush x:Key="ExpensesListBackground"
ImageSource="Images\ExpensesListBackground.png"
Stretch="Fill" />
<ImageBrush x:Key="AddNewExpenseBackground"
ImageSource="Images\AddNewExpense.png"
Stretch="UniformToFill" />
<!--Styles for DataGrid-->
<Style x:Key="DataGridHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="Foreground" Value="Black" />
</Style>
<Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
<Setter Property="Cursor" Value="Hand" />
</Style>
<SolidColorBrush x:Key="SemiTransparentBackground"
Color="#0073CF"
Opacity=".6" />
</Application.Resources>
</Application>

Просмотреть файл

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

Просмотреть файл

@ -1,19 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D1729F17-99A5-45AF-AB38-72FA6ECCE609}</ProjectGuid>
<ProjectGuid>{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ExpenseItDemo</RootNamespace>
<AssemblyName>ExpenseItDemo</AssemblyName>
<RootNamespace>ContosoExpenses</RootNamespace>
<AssemblyName>ContosoExpenses</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -34,11 +36,34 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Images\contoso.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Bogus, Version=25.0.3.0, Culture=neutral, PublicKeyToken=fa1bb3f3f218129a, processorArchitecture=MSIL">
<HintPath>..\packages\Bogus.25.0.3\lib\net40\Bogus.dll</HintPath>
</Reference>
<Reference Include="LiteDB, Version=4.1.4.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
<HintPath>..\packages\LiteDB.4.1.4\lib\net40\LiteDB.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Toolkit.Wpf.UI.Controls, Version=5.0.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Toolkit.Wpf.UI.Controls.5.0.1\lib\net462\Microsoft.Toolkit.Wpf.UI.Controls.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Toolkit.Wpf.UI.XamlHost, Version=5.0.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Toolkit.Wpf.UI.XamlHost.5.0.1\lib\net462\Microsoft.Toolkit.Wpf.UI.XamlHost.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net" />
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@ -46,6 +71,10 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="Windows">
<HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
@ -55,18 +84,26 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="CreateExpenseReportDialogBox.cs">
<DependentUpon>CreateExpenseReportDialogBox.xaml</DependentUpon>
<Compile Include="AddNewExpense.xaml.cs">
<DependentUpon>AddNewExpense.xaml</DependentUpon>
</Compile>
<Compile Include="ExpenseReport.cs" />
<Compile Include="LineItem.cs" />
<Compile Include="LineItemCollection.cs" />
<Compile Include="Validation\EmailValidationrule.cs" />
<Compile Include="Validation\NumberValidationrule.cs" />
<Compile Include="ViewChartWindow.cs">
<DependentUpon>ViewChartWindow.xaml</DependentUpon>
<Compile Include="ExpensesList.xaml.cs">
<DependentUpon>ExpensesList.xaml</DependentUpon>
</Compile>
<Page Include="CreateExpenseReportDialogBox.xaml">
<Compile Include="Services\DatabaseService.cs" />
<Page Include="AboutView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="AddNewExpense.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ExpenseDetail.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ExpensesList.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@ -74,20 +111,24 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.cs">
<Compile Include="AboutView.xaml.cs">
<DependentUpon>AboutView.xaml</DependentUpon>
</Compile>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.cs">
<Compile Include="ExpenseDetail.xaml.cs">
<DependentUpon>ExpenseDetail.xaml</DependentUpon>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="ViewChartWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Models\Employee.cs" />
<Compile Include="Models\Expense.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
@ -105,30 +146,31 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EditBoxControlLibrary\EditBoxControlLibrary.csproj">
<Project>{558eee03-6927-4fe6-aeb6-972769960849}</Project>
<Name>EditBoxControlLibrary</Name>
</ProjectReference>
<Resource Include="Images\contoso.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Watermark.png" />
<Content Include="Images\HorizontalBackground.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\AddNewExpense.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\ExpensesBackground.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\ExpensesListBackground.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -0,0 +1,146 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.ExpenseDetail"
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:toolkit="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
Loaded="Window_Loaded"
Closed="Window_Closed"
xmlns:local="clr-namespace:ContosoExpenses"
mc:Ignorable="d"
Title="Expense Detail" Height="500" Width="800"
Background="{StaticResource HorizontalBackground}">
<Grid Margin="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- Expense detail -->
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock FontSize="24" Text="Expense" Grid.Row="0" />
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="Type:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtType" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<TextBlock Text="Description:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtDescription" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<TextBlock Text="Amount:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtAmount" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4">
<TextBlock Text="Location:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtLocation" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<toolkit:MapControl Grid.Row="5" x:Name="ExpenseMap" />
<TextBlock Text="Signature:" FontSize="16" FontWeight="Bold" Grid.Row="6" />
<toolkit:InkCanvas x:Name="Signature" Grid.Row="7" />
</Grid>
<!-- Chart -->
<DockPanel Grid.Column="1" VerticalAlignment="Bottom" Margin="20,0,0,0" MinHeight="420">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="Chart" Width="50" VerticalAlignment="Bottom">
<Rectangle StrokeThickness="1" RadiusX="2" RadiusY="2">
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#4E87D4" Offset="0" />
<GradientStop Color="#73B2F5" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFFFFF" Offset="0" />
<GradientStop Color="#4E87D4" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
<Grid Grid.Column="1" Width="20" Height="400" VerticalAlignment="Bottom">
<Rectangle StrokeThickness="1" RadiusX="2" RadiusY="2">
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF0000" Offset="0" />
<GradientStop Color="#4CFF00" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF0000" Offset="0" />
<GradientStop Color="#4CFF00" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Grid>
<TextBlock Grid.Column="2" Text="1000$ limit" Margin="0,20,0,0"></TextBlock>
</DockPanel>
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,61 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System;
using System.Linq;
using System.Windows;
using ContosoExpenses.Models;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
using Windows.Services.Maps;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for ExpenseDetail.xaml
/// </summary>
public partial class ExpenseDetail : Window
{
public Expense SelectedExpense { get; set; }
public ExpenseDetail()
{
InitializeComponent();
Signature.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen;
MapService.ServiceToken = "IFFAI5SFOtHV9VBKF8Ea~3FS1XamCV2NM0IqlfoQo6A~AguqcUboJvnqWU1H9E-6MVThouJoCrM4wpv_1R_KX_oQLV_e59vyoK42470JvLsU";
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
txtType.Text = SelectedExpense.Type;
txtDescription.Text = SelectedExpense.Description;
txtLocation.Text = SelectedExpense.Address;
txtAmount.Text = SelectedExpense.Cost.ToString();
Chart.Height = (SelectedExpense.Cost * 400) / 1000;
var result = await MapLocationFinder.FindLocationsAsync(SelectedExpense.Address, null);
var location = result.Locations.FirstOrDefault();
if (location != null)
{
await ExpenseMap.TrySetViewAsync(location.Point, 13);
}
}
private void Window_Closed(object sender, EventArgs e)
{
Signature.Dispose();
ExpenseMap.Dispose();
}
}
}

Просмотреть файл

@ -0,0 +1,80 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.ExpensesList"
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:ContosoExpenses"
mc:Ignorable="d"
Loaded="Window_Loaded"
Activated="Window_Activated"
Title="Expenses List" Height="450" Width="800"
Background="{StaticResource ExpensesListBackground}">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="24" Text="Expenses List" Grid.Row="0" />
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="Employee Id:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtEmployeeId" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<TextBlock Text="Full name:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtFullName" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<TextBlock Text="E-mail:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtEmail" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<DataGrid x:Name="ExpensesGrid"
Grid.Row="4"
SelectionChanged="OnSelectedExpense"
AutoGenerateColumns="False"
IsReadOnly="True"
Margin="0, 12, 0, 0"
SelectionMode="Single"
Background="{StaticResource SemiTransparentBackground}"
RowBackground="{StaticResource SemiTransparentBackground}"
ColumnHeaderStyle="{StaticResource DataGridHeaderStyle}"
RowStyle="{StaticResource DataGridRowStyle}"
Foreground="White"
FontSize="14">
<DataGrid.Columns>
<DataGridTextColumn Header="Date" Binding="{Binding Path=Date}" />
<DataGridTextColumn Header="Type" Binding="{Binding Path=Type}" />
<DataGridTextColumn Header="Description" Binding="{Binding Path=Description}" />
<DataGridTextColumn Header="Cost" Binding="{Binding Path=Cost}" />
<DataGridTextColumn Header="City" Binding="{Binding Path=City}" />
</DataGrid.Columns>
</DataGrid>
<Button Content="Add new expense" Click="OnAddNewExpense" Grid.Row="5" HorizontalAlignment="Left" Margin="0, 12, 0, 0" Width="180" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,89 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
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.Shapes;
using ContosoExpenses.Models;
using ContosoExpenses.Services;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for ExpensesList.xaml
/// </summary>
public partial class ExpensesList : Window
{
public int EmployeeId { get; set; }
private Employee selectedEmployee;
public ExpensesList()
{
InitializeComponent();
}
private void OnSelectedExpense(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var expense = e.AddedItems[0] as Expense;
if (expense != null && expense.ExpenseId != 0)
{
ExpenseDetail detail = new ExpenseDetail();
detail.SelectedExpense = expense;
detail.ShowDialog();
}
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DatabaseService databaseService = new DatabaseService();
selectedEmployee = databaseService.GetEmployee(EmployeeId);
txtEmployeeId.Text = selectedEmployee.EmployeeId.ToString();
txtFullName.Text = $"{selectedEmployee.FirstName} {selectedEmployee.LastName}";
txtEmail.Text = selectedEmployee.Email;
}
private void OnAddNewExpense(object sender, RoutedEventArgs e)
{
AddNewExpense newExpense = new AddNewExpense();
newExpense.EmployeeId = EmployeeId;
newExpense.ShowDialog();
}
public void LoadData()
{
DatabaseService databaseService = new DatabaseService();
ExpensesGrid.ItemsSource = databaseService.GetExpenses(EmployeeId);
}
private void Window_Activated(object sender, EventArgs e)
{
LoadData();
}
}
}

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 320 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 65 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 133 KiB

Просмотреть файл

@ -0,0 +1,62 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.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:ContosoExpenses"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="Contoso Expenses" Height="450" Width="800"
Background="{StaticResource MainBackground}">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Menu IsMainMenu="True" Grid.Row="0">
<MenuItem Header="_About" FontSize="12" Click="OnOpenAbout" />
</Menu>
<DataGrid x:Name="CustomersGrid"
Grid.Row="1"
SelectionChanged="OnSelectedEmployee"
AutoGenerateColumns="False"
SelectionMode="Single"
IsReadOnly="True"
Background="{StaticResource SemiTransparentBackground}"
RowBackground="{StaticResource SemiTransparentBackground}"
ColumnHeaderStyle="{StaticResource DataGridHeaderStyle}"
RowStyle="{StaticResource DataGridRowStyle}"
Foreground="White"
FontSize="14">
<DataGrid.Columns>
<DataGridTextColumn Header="Employee Id" Binding="{Binding Path=EmployeeId}" />
<DataGridTextColumn Header="Name" Binding="{Binding Path=FirstName}" />
<DataGridTextColumn Header="Surname" Binding="{Binding Path=LastName}" />
<DataGridTextColumn Header="E-mail" Binding="{Binding Path=Email}" />
</DataGrid.Columns>
</DataGrid>
<!--<xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.DataGrid" Grid.Row="2" x:Name="UwpGrid" />-->
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,67 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ContosoExpenses.Models;
using ContosoExpenses.Services;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadData();
}
private void LoadData()
{
List<Employee> customers = new List<Employee>();
DatabaseService db = new DatabaseService();
db.InitializeDatabase();
CustomersGrid.ItemsSource = db.GetEmployees();
}
private void OnSelectedEmployee(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var employee = e.AddedItems[0] as Employee;
if (employee != null && employee.EmployeeId != 0)
{
ExpensesList detail = new ExpensesList();
detail.EmployeeId = employee.EmployeeId;
detail.Show();
}
}
}
private void OnOpenAbout(object sender, RoutedEventArgs e)
{
AboutView about = new AboutView();
about.ShowDialog();
}
}
}

Просмотреть файл

@ -0,0 +1,11 @@

namespace ContosoExpenses.Models
{
public class Employee
{
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,16 @@
using System;
namespace ContosoExpenses.Models
{
public class Expense
{
public int ExpenseId { get; set; }
public string Type { get; set; }
public string Description { get; set; }
public double Cost { get; set; }
public string Address { get; set; }
public string City { get; set; }
public DateTime Date { get; set; }
public int EmployeeId { get; set; }
}
}

Просмотреть файл

@ -1,30 +1,27 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Reflection;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EditBoxControlLibrary")]
[assembly: AssemblyTitle("XamlIslandDemo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EditBoxControlLibrary")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyProduct("XamlIslandDemo")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
@ -36,24 +33,23 @@ using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -8,7 +8,8 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace EditBoxControlLibrary.Properties {
namespace ContosoExpenses.Properties {
using System;
/// <summary>
@ -18,7 +19,7 @@ namespace EditBoxControlLibrary.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@ -37,8 +38,8 @@ namespace EditBoxControlLibrary.Properties {
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if ((resourceMan == null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("EditBoxControlLibrary.Properties.Resources", typeof(Resources).Assembly);
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ContosoExpenses.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;

Просмотреть файл

@ -8,21 +8,17 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace EditBoxControlLibrary.Properties
{
namespace ContosoExpenses.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
public static Settings Default {
get {
return defaultInstance;
}
}

Просмотреть файл

@ -1,5 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />

Просмотреть файл

@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Bogus;
using LiteDB;
using ContosoExpenses.Models;
namespace ContosoExpenses.Services
{
public class DatabaseService
{
readonly int numberOfEmployees = 10;
readonly int numberOfExpenses = 5;
string filePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\ExpenseIt\\data.db";
string directoryPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\ExpenseIt\\";
public Employee GetEmployee(int employeeId)
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
return employees.FindById(employeeId);
}
}
public List<Employee> GetEmployees()
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
return employees.FindAll().ToList();
}
}
public List<Expense> GetExpenses(int employeedId)
{
using (var connection = new LiteDatabase(filePath))
{
var expenses = connection.GetCollection<Expense>();
return expenses.Find(x => x.EmployeeId == employeedId).ToList();
}
}
public void SaveExpense(Expense expense)
{
using (var connection = new LiteDatabase(filePath))
{
var expenses = connection.GetCollection<Expense>();
expenses.Insert(expense);
}
}
public void InitializeDatabase()
{
if (!File.Exists(filePath))
{
Directory.CreateDirectory(directoryPath);
}
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
var expenses = connection.GetCollection<Expense>();
int result = employees.Count();
if (result == 0)
{
GenerateFakeData(numberOfEmployees, numberOfExpenses);
}
}
}
private void GenerateFakeData(int numberOfEmployees, int numberOfExpenses)
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
var expenses = connection.GetCollection<Expense>();
for (int cont = 0; cont < numberOfEmployees; cont++)
{
var employee = new Faker<Employee>()
.RuleFor(x => x.FirstName, (f, u) => f.Name.FirstName())
.RuleFor(x => x.LastName, (f, u) => f.Name.LastName())
.RuleFor(x => x.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName, "contoso.com"))
.Generate();
int employeeId = employees.Insert(employee).AsInt32;
for (int contExpenses = 0; contExpenses < numberOfExpenses; contExpenses++)
{
var expense = new Faker<Expense>()
.RuleFor(x => x.Description, (f, u) => f.Commerce.ProductName())
.RuleFor(x => x.Type, (f, u) => f.Finance.TransactionType())
.RuleFor(x => x.Cost, (f, u) => (double)f.Finance.Amount())
.RuleFor(x => x.Address, (f, u) => f.Address.FullAddress())
.RuleFor(x => x.City, (f, u) => f.Address.City())
.RuleFor(x => x.Date, (f, u) => f.Date.Past())
.Generate();
expense.EmployeeId = employeeId;
expenses.Insert(expense);
}
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bogus" version="25.0.3" targetFramework="net472" />
<package id="LiteDB" version="4.1.4" targetFramework="net472" />
<package id="Microsoft.Toolkit.Wpf.UI.Controls" version="5.0.1" targetFramework="net472" />
<package id="Microsoft.Toolkit.Wpf.UI.XamlHost" version="5.0.1" targetFramework="net472" />
</packages>

Просмотреть файл

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup>
<WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
</PropertyGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>2d8fd114-a304-45b1-bca2-16949103603e</ProjectGuid>
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<PackageCertificateKeyFile>ContosoExpenses.Package_TemporaryKey.pfx</PackageCertificateKeyFile>
<EntryPointProjectUniqueName>..\ContosoExpenses\ContosoExpenses.csproj</EntryPointProjectUniqueName>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<None Include="ContosoExpenses.Package_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\LockScreenLogo.scale-200.png" />
<Content Include="Images\Square150x150Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ContosoExpenses\ContosoExpenses.csproj" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.9 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.1 KiB

Просмотреть файл

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity
Name="5dde7e45-3be3-4273-a57d-93a49bbb14b2"
Publisher="CN=mpagani"
Version="1.0.0.0" />
<Properties>
<DisplayName>ContosoExpenses.Package</DisplayName>
<PublisherDisplayName>mpagani</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="ContosoExpenses.Package"
Description="ContosoExpenses.Package"
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile
Wide310x150Logo="Images\Wide310x150Logo.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>

Просмотреть файл

@ -0,0 +1,57 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28407.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContosoExpenses", "ContosoExpenses\ContosoExpenses.csproj", "{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}"
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "ContosoExpenses.Package", "ContosoExpenses.Package\ContosoExpenses.Package.wapproj", "{2D8FD114-A304-45B1-BCA2-16949103603E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x64.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x64.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x86.ActiveCfg = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Debug|x86.Build.0 = Debug|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|Any CPU.Build.0 = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x64.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x64.Build.0 = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x86.ActiveCfg = Release|Any CPU
{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}.Release|x86.Build.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.ActiveCfg = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.Build.0 = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x64.Deploy.0 = Debug|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.ActiveCfg = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.Build.0 = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Debug|x86.Deploy.0 = Debug|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.Build.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|Any CPU.Deploy.0 = Release|Any CPU
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.ActiveCfg = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.Build.0 = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x64.Deploy.0 = Release|x64
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.ActiveCfg = Release|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.Build.0 = Release|x86
{2D8FD114-A304-45B1-BCA2-16949103603E}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3BADFBD9-C57F-40A7-B058-D6B067196030}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,35 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.AboutView"
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"
mc:Ignorable="d" MinHeight="500" MinWidth="700" Height="500" Width="700">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" Margin="10">
Contoso Expenses is a 'modern application of yesterday tomorrow' from Contoso Corp.
</TextBlock>
<WebBrowser Grid.Row="1"
Source="https://contosocorpwebsite.azurewebsites.net/" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,27 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System.Linq;
using System.Linq.Expressions;
namespace ContosoExpenses
{
public partial class AboutView
{
public AboutView()
{
InitializeComponent();
}
}
}

Просмотреть файл

@ -0,0 +1,71 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.AddNewExpense"
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:xamlhost="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
xmlns:local="clr-namespace:ContosoExpenses"
Closed="Window_Closed"
mc:Ignorable="d"
Title="Add new expense" Height="800" Width="800"
Background="{StaticResource AddNewExpenseBackground}">
<Grid Margin="12">
<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"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock FontSize="24" Text="Add new expense" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
<TextBlock Text="Type:" FontSize="16" FontWeight="Bold" Grid.Row="1" Grid.Column="0" />
<TextBox x:Name="txtType" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="1" Grid.Column="1" />
<TextBlock Text="Description:" FontSize="16" FontWeight="Bold" Grid.Row="2" Grid.Column="0" />
<TextBox x:Name="txtDescription" FontSize="16" Margin="5, 0, 0, 0" Width="400" Height="200" AcceptsReturn="True" Grid.Row="2" Grid.Column="1" />
<TextBlock Text="Amount:" FontSize="16" FontWeight="Bold" Grid.Row="3" Grid.Column="0" />
<TextBox x:Name="txtAmount" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="3" Grid.Column="1" />
<TextBlock Text="Location:" FontSize="16" FontWeight="Bold" Grid.Row="4" Grid.Column="0" />
<TextBox x:Name="txtLocation" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="4" Grid.Column="1" />
<TextBlock Text="City:" FontSize="16" FontWeight="Bold" Grid.Row="5" Grid.Column="0" />
<TextBox x:Name="txtCity" FontSize="16" Margin="5, 0, 0, 0" Width="400" Grid.Row="5" Grid.Column="1" />
<TextBlock Text="Date:" FontSize="16" FontWeight="Bold" Grid.Row="6" Grid.Column="0" />
<local:CalendarViewWrapper Grid.Column="1" Grid.Row="6" x:Name="CalendarUwp" SelectedDatesChanged="CalendarUwp_SelectedDatesChanged" />
<TextBlock Text="Selected date:" FontSize="16" FontWeight="Bold" Grid.Row="7" Grid.Column="0" />
<TextBlock x:Name="txtDate" FontSize="16" Grid.Row="7" Grid.Column="1" />
<Button Content="Save" Grid.Row="8" Grid.Column="0" Click="OnSaveExpense" Margin="5, 12, 0, 0" HorizontalAlignment="Left" Width="180" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,72 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using ContosoExpenses.Models;
using ContosoExpenses.Services;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using System;
using System.Linq;
using System.Threading;
using System.Windows;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for AddNewExpense.xaml
/// </summary>
public partial class AddNewExpense : Window
{
public int EmployeeId { get; set; }
public AddNewExpense()
{
InitializeComponent();
}
private void OnSaveExpense(object sender, RoutedEventArgs e)
{
try
{
Expense expense = new Expense
{
Address = txtAmount.Text,
City = txtCity.Text,
Cost = Convert.ToDouble(txtAmount.Text),
Description = txtDescription.Text,
Type = txtType.Text,
Date = CalendarUwp.SelectedDates.FirstOrDefault().DateTime,
EmployeeId = EmployeeId
};
DatabaseService service = new DatabaseService();
service.SaveExpense(expense);
this.Close();
}
catch (Exception exc)
{
MessageBox.Show("Validation error. Please check your data.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void Window_Closed(object sender, EventArgs e)
{
CalendarUwp.Dispose();
}
private void CalendarUwp_SelectedDatesChanged(object sender, SelectedDatesChangedEventArgs e)
{
txtDate.Text = e.SelectedDates.FirstOrDefault().DateTime.ToShortDateString();
}
}
}

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

Просмотреть файл

@ -0,0 +1,55 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Application x:Class="ContosoExpenses.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ContosoExpenses"
StartupUri="MainWindow.xaml">
<Application.Resources>
<!--Background images-->
<ImageBrush x:Key="MainBackground"
ImageSource="Images\ExpensesBackground.jpg"
Stretch="UniformToFill" />
<ImageBrush x:Key="HorizontalBackground"
ImageSource="Images\HorizontalBackground.png"
Stretch="UniformToFill" />
<ImageBrush x:Key="ExpensesListBackground"
ImageSource="Images\ExpensesListBackground.png"
Stretch="Fill" />
<ImageBrush x:Key="AddNewExpenseBackground"
ImageSource="Images\AddNewExpense.png"
Stretch="UniformToFill" />
<!--Styles for DataGrid-->
<Style x:Key="DataGridHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="Foreground" Value="Black" />
</Style>
<Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
<Setter Property="Cursor" Value="Hand" />
</Style>
<SolidColorBrush x:Key="SemiTransparentBackground"
Color="#0073CF"
Opacity=".6" />
</Application.Resources>
</Application>

Просмотреть файл

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

Просмотреть файл

@ -0,0 +1,55 @@
using Microsoft.Toolkit.Win32.UI.XamlHost;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContosoExpenses
{
public class CalendarViewWrapper: WindowsXamlHostBase
{
public CalendarViewWrapper(): base()
{
}
public event EventHandler<SelectedDatesChangedEventArgs> SelectedDatesChanged;
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
this.ChildInternal = UWPTypeFactory.CreateXamlContentByType("Windows.UI.Xaml.Controls.CalendarView");
SetContent();
global::Windows.UI.Xaml.Controls.CalendarView calendarView = this.ChildInternal as global::Windows.UI.Xaml.Controls.CalendarView;
calendarView.SelectedDatesChanged += CalendarView_SelectedDatesChanged;
}
private void CalendarView_SelectedDatesChanged(Windows.UI.Xaml.Controls.CalendarView sender, Windows.UI.Xaml.Controls.CalendarViewSelectedDatesChangedEventArgs args)
{
OnSelectedDatesChanged(new SelectedDatesChangedEventArgs(args.AddedDates));
}
public IList<DateTimeOffset> SelectedDates
{
get
{
if (this.ChildInternal != null)
{
global::Windows.UI.Xaml.Controls.CalendarView calendarView = this.ChildInternal as global::Windows.UI.Xaml.Controls.CalendarView;
return calendarView.SelectedDates;
}
return null;
}
}
protected virtual void OnSelectedDatesChanged(SelectedDatesChangedEventArgs e)
{
SelectedDatesChanged?.Invoke(this, e);
}
}
}

Просмотреть файл

@ -0,0 +1,178 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A3E7CBAC-2DFE-463B-B7F9-0B6477EA7A37}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ContosoExpenses</RootNamespace>
<AssemblyName>ContosoExpenses</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Images\contoso.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Bogus, Version=25.0.3.0, Culture=neutral, PublicKeyToken=fa1bb3f3f218129a, processorArchitecture=MSIL">
<HintPath>..\packages\Bogus.25.0.3\lib\net40\Bogus.dll</HintPath>
</Reference>
<Reference Include="LiteDB, Version=4.1.4.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
<HintPath>..\packages\LiteDB.4.1.4\lib\net40\LiteDB.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Toolkit.Wpf.UI.Controls, Version=5.0.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Toolkit.Wpf.UI.Controls.5.0.1\lib\net462\Microsoft.Toolkit.Wpf.UI.Controls.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Toolkit.Wpf.UI.XamlHost, Version=5.0.0.0, Culture=neutral, PublicKeyToken=4aff67a105548ee2, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Toolkit.Wpf.UI.XamlHost.5.0.1\lib\net462\Microsoft.Toolkit.Wpf.UI.XamlHost.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net" />
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="Windows">
<HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AddNewExpense.xaml.cs">
<DependentUpon>AddNewExpense.xaml</DependentUpon>
</Compile>
<Compile Include="CalendarViewWrapper.cs" />
<Compile Include="ExpensesList.xaml.cs">
<DependentUpon>ExpensesList.xaml</DependentUpon>
</Compile>
<Compile Include="SelectedDatesChangedEventArgs.cs" />
<Compile Include="Services\DatabaseService.cs" />
<Page Include="AboutView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="AddNewExpense.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ExpenseDetail.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ExpensesList.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="AboutView.xaml.cs">
<DependentUpon>AboutView.xaml</DependentUpon>
</Compile>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="ExpenseDetail.xaml.cs">
<DependentUpon>ExpenseDetail.xaml</DependentUpon>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Models\Employee.cs" />
<Compile Include="Models\Expense.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\contoso.ico" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\HorizontalBackground.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\AddNewExpense.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\ExpensesBackground.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\ExpensesListBackground.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,146 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.ExpenseDetail"
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:toolkit="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
Loaded="Window_Loaded"
Closed="Window_Closed"
xmlns:local="clr-namespace:ContosoExpenses"
mc:Ignorable="d"
Title="Expense Detail" Height="500" Width="800"
Background="{StaticResource HorizontalBackground}">
<Grid Margin="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- Expense detail -->
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock FontSize="24" Text="Expense" Grid.Row="0" />
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="Type:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtType" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<TextBlock Text="Description:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtDescription" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<TextBlock Text="Amount:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtAmount" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4">
<TextBlock Text="Location:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtLocation" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<toolkit:MapControl Grid.Row="5" x:Name="ExpenseMap" />
<TextBlock Text="Signature:" FontSize="16" FontWeight="Bold" Grid.Row="6" />
<toolkit:InkCanvas x:Name="Signature" Grid.Row="7" />
</Grid>
<!-- Chart -->
<DockPanel Grid.Column="1" VerticalAlignment="Bottom" Margin="20,0,0,0" MinHeight="420">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="Chart" Width="50" VerticalAlignment="Bottom">
<Rectangle StrokeThickness="1" RadiusX="2" RadiusY="2">
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#4E87D4" Offset="0" />
<GradientStop Color="#73B2F5" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFFFFF" Offset="0" />
<GradientStop Color="#4E87D4" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
<Grid Grid.Column="1" Width="20" Height="400" VerticalAlignment="Bottom">
<Rectangle StrokeThickness="1" RadiusX="2" RadiusY="2">
<Rectangle.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF0000" Offset="0" />
<GradientStop Color="#4CFF00" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF0000" Offset="0" />
<GradientStop Color="#4CFF00" Offset="1" />
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Grid>
<TextBlock Grid.Column="2" Text="1000$ limit" Margin="0,20,0,0"></TextBlock>
</DockPanel>
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,61 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System;
using System.Linq;
using System.Windows;
using ContosoExpenses.Models;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
using Windows.Services.Maps;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for ExpenseDetail.xaml
/// </summary>
public partial class ExpenseDetail : Window
{
public Expense SelectedExpense { get; set; }
public ExpenseDetail()
{
InitializeComponent();
Signature.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen;
MapService.ServiceToken = "IFFAI5SFOtHV9VBKF8Ea~3FS1XamCV2NM0IqlfoQo6A~AguqcUboJvnqWU1H9E-6MVThouJoCrM4wpv_1R_KX_oQLV_e59vyoK42470JvLsU";
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
txtType.Text = SelectedExpense.Type;
txtDescription.Text = SelectedExpense.Description;
txtLocation.Text = SelectedExpense.Address;
txtAmount.Text = SelectedExpense.Cost.ToString();
Chart.Height = (SelectedExpense.Cost * 400) / 1000;
var result = await MapLocationFinder.FindLocationsAsync(SelectedExpense.Address, null);
var location = result.Locations.FirstOrDefault();
if (location != null)
{
await ExpenseMap.TrySetViewAsync(location.Point, 13);
}
}
private void Window_Closed(object sender, EventArgs e)
{
Signature.Dispose();
ExpenseMap.Dispose();
}
}
}

Просмотреть файл

@ -0,0 +1,80 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.ExpensesList"
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:ContosoExpenses"
mc:Ignorable="d"
Loaded="Window_Loaded"
Activated="Window_Activated"
Title="Expenses List" Height="450" Width="800"
Background="{StaticResource ExpensesListBackground}">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock FontSize="24" Text="Expenses List" Grid.Row="0" />
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="Employee Id:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtEmployeeId" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<TextBlock Text="Full name:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtFullName" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<TextBlock Text="E-mail:" FontSize="16" FontWeight="Bold" />
<TextBlock x:Name="txtEmail" FontSize="16" Margin="5, 0, 0, 0" />
</StackPanel>
<DataGrid x:Name="ExpensesGrid"
Grid.Row="4"
SelectionChanged="OnSelectedExpense"
AutoGenerateColumns="False"
IsReadOnly="True"
Margin="0, 12, 0, 0"
SelectionMode="Single"
Background="{StaticResource SemiTransparentBackground}"
RowBackground="{StaticResource SemiTransparentBackground}"
ColumnHeaderStyle="{StaticResource DataGridHeaderStyle}"
RowStyle="{StaticResource DataGridRowStyle}"
Foreground="White"
FontSize="14">
<DataGrid.Columns>
<DataGridTextColumn Header="Date" Binding="{Binding Path=Date}" />
<DataGridTextColumn Header="Type" Binding="{Binding Path=Type}" />
<DataGridTextColumn Header="Description" Binding="{Binding Path=Description}" />
<DataGridTextColumn Header="Cost" Binding="{Binding Path=Cost}" />
<DataGridTextColumn Header="City" Binding="{Binding Path=City}" />
</DataGrid.Columns>
</DataGrid>
<Button Content="Add new expense" Click="OnAddNewExpense" Grid.Row="5" HorizontalAlignment="Left" Margin="0, 12, 0, 0" Width="180" />
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,89 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
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.Shapes;
using ContosoExpenses.Models;
using ContosoExpenses.Services;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for ExpensesList.xaml
/// </summary>
public partial class ExpensesList : Window
{
public int EmployeeId { get; set; }
private Employee selectedEmployee;
public ExpensesList()
{
InitializeComponent();
}
private void OnSelectedExpense(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var expense = e.AddedItems[0] as Expense;
if (expense != null && expense.ExpenseId != 0)
{
ExpenseDetail detail = new ExpenseDetail();
detail.SelectedExpense = expense;
detail.ShowDialog();
}
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DatabaseService databaseService = new DatabaseService();
selectedEmployee = databaseService.GetEmployee(EmployeeId);
txtEmployeeId.Text = selectedEmployee.EmployeeId.ToString();
txtFullName.Text = $"{selectedEmployee.FirstName} {selectedEmployee.LastName}";
txtEmail.Text = selectedEmployee.Email;
}
private void OnAddNewExpense(object sender, RoutedEventArgs e)
{
AddNewExpense newExpense = new AddNewExpense();
newExpense.EmployeeId = EmployeeId;
newExpense.ShowDialog();
}
public void LoadData()
{
DatabaseService databaseService = new DatabaseService();
ExpensesGrid.ItemsSource = databaseService.GetExpenses(EmployeeId);
}
private void Window_Activated(object sender, EventArgs e)
{
LoadData();
}
}
}

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 320 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 65 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 133 KiB

Просмотреть файл

@ -0,0 +1,62 @@
<!--
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
-->
<Window x:Class="ContosoExpenses.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:ContosoExpenses"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="Contoso Expenses" Height="450" Width="800"
Background="{StaticResource MainBackground}">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Menu IsMainMenu="True" Grid.Row="0">
<MenuItem Header="_About" FontSize="12" Click="OnOpenAbout" />
</Menu>
<DataGrid x:Name="CustomersGrid"
Grid.Row="1"
SelectionChanged="OnSelectedEmployee"
AutoGenerateColumns="False"
SelectionMode="Single"
IsReadOnly="True"
Background="{StaticResource SemiTransparentBackground}"
RowBackground="{StaticResource SemiTransparentBackground}"
ColumnHeaderStyle="{StaticResource DataGridHeaderStyle}"
RowStyle="{StaticResource DataGridRowStyle}"
Foreground="White"
FontSize="14">
<DataGrid.Columns>
<DataGridTextColumn Header="Employee Id" Binding="{Binding Path=EmployeeId}" />
<DataGridTextColumn Header="Name" Binding="{Binding Path=FirstName}" />
<DataGridTextColumn Header="Surname" Binding="{Binding Path=LastName}" />
<DataGridTextColumn Header="E-mail" Binding="{Binding Path=Email}" />
</DataGrid.Columns>
</DataGrid>
<!--<xamlhost:WindowsXamlHost InitialTypeName="Windows.UI.Xaml.Controls.DataGrid" Grid.Row="2" x:Name="UwpGrid" />-->
</Grid>
</Window>

Просмотреть файл

@ -0,0 +1,67 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ContosoExpenses.Models;
using ContosoExpenses.Services;
namespace ContosoExpenses
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadData();
}
private void LoadData()
{
List<Employee> customers = new List<Employee>();
DatabaseService db = new DatabaseService();
db.InitializeDatabase();
CustomersGrid.ItemsSource = db.GetEmployees();
}
private void OnSelectedEmployee(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var employee = e.AddedItems[0] as Employee;
if (employee != null && employee.EmployeeId != 0)
{
ExpensesList detail = new ExpensesList();
detail.EmployeeId = employee.EmployeeId;
detail.Show();
}
}
}
private void OnOpenAbout(object sender, RoutedEventArgs e)
{
AboutView about = new AboutView();
about.ShowDialog();
}
}
}

Просмотреть файл

@ -0,0 +1,11 @@

namespace ContosoExpenses.Models
{
public class Employee
{
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,16 @@
using System;
namespace ContosoExpenses.Models
{
public class Expense
{
public int ExpenseId { get; set; }
public string Type { get; set; }
public string Description { get; set; }
public double Cost { get; set; }
public string Address { get; set; }
public string City { get; set; }
public DateTime Date { get; set; }
public int EmployeeId { get; set; }
}
}

Просмотреть файл

@ -1,30 +1,27 @@
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Reflection;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ExpenseItDemo")]
[assembly: AssemblyTitle("XamlIslandDemo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExpenseItDemo")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyProduct("XamlIslandDemo")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
@ -36,24 +33,23 @@ using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ContosoExpenses.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ContosoExpenses.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

Просмотреть файл

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ContosoExpenses.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

Просмотреть файл

@ -1,5 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />

Просмотреть файл

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ContosoExpenses
{
public class SelectedDatesChangedEventArgs: EventArgs
{
public IReadOnlyList<DateTimeOffset> SelectedDates { get; set; }
public SelectedDatesChangedEventArgs(IReadOnlyList<DateTimeOffset> selectedDates)
{
this.SelectedDates = selectedDates;
}
}
}

Просмотреть файл

@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Bogus;
using LiteDB;
using ContosoExpenses.Models;
namespace ContosoExpenses.Services
{
public class DatabaseService
{
readonly int numberOfEmployees = 10;
readonly int numberOfExpenses = 5;
string filePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\ExpenseIt\\data.db";
string directoryPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\ExpenseIt\\";
public Employee GetEmployee(int employeeId)
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
return employees.FindById(employeeId);
}
}
public List<Employee> GetEmployees()
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
return employees.FindAll().ToList();
}
}
public List<Expense> GetExpenses(int employeedId)
{
using (var connection = new LiteDatabase(filePath))
{
var expenses = connection.GetCollection<Expense>();
return expenses.Find(x => x.EmployeeId == employeedId).ToList();
}
}
public void SaveExpense(Expense expense)
{
using (var connection = new LiteDatabase(filePath))
{
var expenses = connection.GetCollection<Expense>();
expenses.Insert(expense);
}
}
public void InitializeDatabase()
{
if (!File.Exists(filePath))
{
Directory.CreateDirectory(directoryPath);
}
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
var expenses = connection.GetCollection<Expense>();
int result = employees.Count();
if (result == 0)
{
GenerateFakeData(numberOfEmployees, numberOfExpenses);
}
}
}
private void GenerateFakeData(int numberOfEmployees, int numberOfExpenses)
{
using (var connection = new LiteDatabase(filePath))
{
var employees = connection.GetCollection<Employee>();
var expenses = connection.GetCollection<Expense>();
for (int cont = 0; cont < numberOfEmployees; cont++)
{
var employee = new Faker<Employee>()
.RuleFor(x => x.FirstName, (f, u) => f.Name.FirstName())
.RuleFor(x => x.LastName, (f, u) => f.Name.LastName())
.RuleFor(x => x.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName, "contoso.com"))
.Generate();
int employeeId = employees.Insert(employee).AsInt32;
for (int contExpenses = 0; contExpenses < numberOfExpenses; contExpenses++)
{
var expense = new Faker<Expense>()
.RuleFor(x => x.Description, (f, u) => f.Commerce.ProductName())
.RuleFor(x => x.Type, (f, u) => f.Finance.TransactionType())
.RuleFor(x => x.Cost, (f, u) => (double)f.Finance.Amount())
.RuleFor(x => x.Address, (f, u) => f.Address.FullAddress())
.RuleFor(x => x.City, (f, u) => f.Address.City())
.RuleFor(x => x.Date, (f, u) => f.Date.Past())
.Generate();
expense.EmployeeId = employeeId;
expenses.Insert(expense);
}
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bogus" version="25.0.3" targetFramework="net472" />
<package id="LiteDB" version="4.1.4" targetFramework="net472" />
<package id="Microsoft.Toolkit.Wpf.UI.Controls" version="5.0.1" targetFramework="net472" />
<package id="Microsoft.Toolkit.Wpf.UI.XamlHost" version="5.0.1" targetFramework="net472" />
</packages>

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше